Example program to test AES-GCM functionality. Used for a workshop

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers pkcs5.h Source File

pkcs5.h

Go to the documentation of this file.
00001 /**
00002  * \file pkcs5.h
00003  *
00004  * \brief PKCS#5 functions
00005  *
00006  * \author Mathias Olsson <mathias@kompetensum.com>
00007  *
00008  *  Copyright (C) 2006-2013, Brainspark B.V.
00009  *
00010  *  This file is part of PolarSSL (http://www.polarssl.org)
00011  *  Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
00012  *
00013  *  All rights reserved.
00014  *
00015  *  This program is free software; you can redistribute it and/or modify
00016  *  it under the terms of the GNU General Public License as published by
00017  *  the Free Software Foundation; either version 2 of the License, or
00018  *  (at your option) any later version.
00019  *
00020  *  This program is distributed in the hope that it will be useful,
00021  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023  *  GNU General Public License for more details.
00024  *
00025  *  You should have received a copy of the GNU General Public License along
00026  *  with this program; if not, write to the Free Software Foundation, Inc.,
00027  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00028  */
00029 #ifndef POLARSSL_PKCS5_H
00030 #define POLARSSL_PKCS5_H
00031 
00032 #include <string.h>
00033 
00034 #include "asn1.h"
00035 #include "md.h"
00036 
00037 #if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
00038 #include <basetsd.h>
00039 typedef UINT32 uint32_t;
00040 #else
00041 #include <inttypes.h>
00042 #endif
00043 
00044 #define POLARSSL_ERR_PKCS5_BAD_INPUT_DATA                  -0x3f80  /**< Bad input parameters to function. */
00045 #define POLARSSL_ERR_PKCS5_INVALID_FORMAT                  -0x3f00  /**< Unexpected ASN.1 data. */
00046 #define POLARSSL_ERR_PKCS5_FEATURE_UNAVAILABLE             -0x3e80  /**< Requested encryption or digest alg not available. */
00047 #define POLARSSL_ERR_PKCS5_PASSWORD_MISMATCH               -0x3e00  /**< Given private key password does not allow for correct decryption. */
00048 
00049 #define PKCS5_DECRYPT      0
00050 #define PKCS5_ENCRYPT      1
00051 
00052 #ifdef __cplusplus
00053 extern "C" {
00054 #endif
00055 
00056 /**
00057  * \brief          PKCS#5 PBES2 function
00058  *
00059  * \param pbe_params the ASN.1 algorithm parameters
00060  * \param mode       either PKCS5_DECRYPT or PKCS5_ENCRYPT
00061  * \param pwd        password to use when generating key
00062  * \param pwdlen     length of password
00063  * \param data       data to process
00064  * \param datalen    length of data
00065  * \param output     output buffer
00066  *
00067  * \returns        0 on success, or a PolarSSL error code if verification fails.
00068  */
00069 int pkcs5_pbes2( asn1_buf *pbe_params, int mode,
00070                  const unsigned char *pwd,  size_t pwdlen,
00071                  const unsigned char *data, size_t datalen,
00072                  unsigned char *output );
00073 
00074 /**
00075  * \brief          PKCS#5 PBKDF2 using HMAC
00076  *
00077  * \param ctx      Generic HMAC context
00078  * \param password Password to use when generating key
00079  * \param plen     Length of password
00080  * \param salt     Salt to use when generating key
00081  * \param slen     Length of salt
00082  * \param iteration_count       Iteration count
00083  * \param key_length            Length of generated key
00084  * \param output   Generated key. Must be at least as big as key_length
00085  *
00086  * \returns        0 on success, or a PolarSSL error code if verification fails.
00087  */
00088 int pkcs5_pbkdf2_hmac( md_context_t *ctx, const unsigned char *password,
00089                        size_t plen, const unsigned char *salt, size_t slen,
00090                        unsigned int iteration_count,
00091                        uint32_t key_length, unsigned char *output );
00092 
00093 /**
00094  * \brief          Checkup routine
00095  *
00096  * \return         0 if successful, or 1 if the test failed
00097  */
00098 int pkcs5_self_test( int verbose );
00099 
00100 #ifdef __cplusplus
00101 }
00102 #endif
00103 
00104 #endif /* pkcs5.h */
00105 
00106