Hannes Tschofenig
/
aes-gcm-test-program
Example program to test AES-GCM functionality. Used for a workshop
SSL/include/polarssl/pkcs5.h@0:796d0f61a05b, 2018-09-27 (annotated)
- Committer:
- HannesTschofenig
- Date:
- Thu Sep 27 06:34:22 2018 +0000
- Revision:
- 0:796d0f61a05b
Example AES-GCM test program
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
HannesTschofenig | 0:796d0f61a05b | 1 | /** |
HannesTschofenig | 0:796d0f61a05b | 2 | * \file pkcs5.h |
HannesTschofenig | 0:796d0f61a05b | 3 | * |
HannesTschofenig | 0:796d0f61a05b | 4 | * \brief PKCS#5 functions |
HannesTschofenig | 0:796d0f61a05b | 5 | * |
HannesTschofenig | 0:796d0f61a05b | 6 | * \author Mathias Olsson <mathias@kompetensum.com> |
HannesTschofenig | 0:796d0f61a05b | 7 | * |
HannesTschofenig | 0:796d0f61a05b | 8 | * Copyright (C) 2006-2013, Brainspark B.V. |
HannesTschofenig | 0:796d0f61a05b | 9 | * |
HannesTschofenig | 0:796d0f61a05b | 10 | * This file is part of PolarSSL (http://www.polarssl.org) |
HannesTschofenig | 0:796d0f61a05b | 11 | * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org> |
HannesTschofenig | 0:796d0f61a05b | 12 | * |
HannesTschofenig | 0:796d0f61a05b | 13 | * All rights reserved. |
HannesTschofenig | 0:796d0f61a05b | 14 | * |
HannesTschofenig | 0:796d0f61a05b | 15 | * This program is free software; you can redistribute it and/or modify |
HannesTschofenig | 0:796d0f61a05b | 16 | * it under the terms of the GNU General Public License as published by |
HannesTschofenig | 0:796d0f61a05b | 17 | * the Free Software Foundation; either version 2 of the License, or |
HannesTschofenig | 0:796d0f61a05b | 18 | * (at your option) any later version. |
HannesTschofenig | 0:796d0f61a05b | 19 | * |
HannesTschofenig | 0:796d0f61a05b | 20 | * This program is distributed in the hope that it will be useful, |
HannesTschofenig | 0:796d0f61a05b | 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
HannesTschofenig | 0:796d0f61a05b | 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
HannesTschofenig | 0:796d0f61a05b | 23 | * GNU General Public License for more details. |
HannesTschofenig | 0:796d0f61a05b | 24 | * |
HannesTschofenig | 0:796d0f61a05b | 25 | * You should have received a copy of the GNU General Public License along |
HannesTschofenig | 0:796d0f61a05b | 26 | * with this program; if not, write to the Free Software Foundation, Inc., |
HannesTschofenig | 0:796d0f61a05b | 27 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
HannesTschofenig | 0:796d0f61a05b | 28 | */ |
HannesTschofenig | 0:796d0f61a05b | 29 | #ifndef POLARSSL_PKCS5_H |
HannesTschofenig | 0:796d0f61a05b | 30 | #define POLARSSL_PKCS5_H |
HannesTschofenig | 0:796d0f61a05b | 31 | |
HannesTschofenig | 0:796d0f61a05b | 32 | #include <string.h> |
HannesTschofenig | 0:796d0f61a05b | 33 | |
HannesTschofenig | 0:796d0f61a05b | 34 | #include "asn1.h" |
HannesTschofenig | 0:796d0f61a05b | 35 | #include "md.h" |
HannesTschofenig | 0:796d0f61a05b | 36 | |
HannesTschofenig | 0:796d0f61a05b | 37 | #if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32) |
HannesTschofenig | 0:796d0f61a05b | 38 | #include <basetsd.h> |
HannesTschofenig | 0:796d0f61a05b | 39 | typedef UINT32 uint32_t; |
HannesTschofenig | 0:796d0f61a05b | 40 | #else |
HannesTschofenig | 0:796d0f61a05b | 41 | #include <inttypes.h> |
HannesTschofenig | 0:796d0f61a05b | 42 | #endif |
HannesTschofenig | 0:796d0f61a05b | 43 | |
HannesTschofenig | 0:796d0f61a05b | 44 | #define POLARSSL_ERR_PKCS5_BAD_INPUT_DATA -0x3f80 /**< Bad input parameters to function. */ |
HannesTschofenig | 0:796d0f61a05b | 45 | #define POLARSSL_ERR_PKCS5_INVALID_FORMAT -0x3f00 /**< Unexpected ASN.1 data. */ |
HannesTschofenig | 0:796d0f61a05b | 46 | #define POLARSSL_ERR_PKCS5_FEATURE_UNAVAILABLE -0x3e80 /**< Requested encryption or digest alg not available. */ |
HannesTschofenig | 0:796d0f61a05b | 47 | #define POLARSSL_ERR_PKCS5_PASSWORD_MISMATCH -0x3e00 /**< Given private key password does not allow for correct decryption. */ |
HannesTschofenig | 0:796d0f61a05b | 48 | |
HannesTschofenig | 0:796d0f61a05b | 49 | #define PKCS5_DECRYPT 0 |
HannesTschofenig | 0:796d0f61a05b | 50 | #define PKCS5_ENCRYPT 1 |
HannesTschofenig | 0:796d0f61a05b | 51 | |
HannesTschofenig | 0:796d0f61a05b | 52 | #ifdef __cplusplus |
HannesTschofenig | 0:796d0f61a05b | 53 | extern "C" { |
HannesTschofenig | 0:796d0f61a05b | 54 | #endif |
HannesTschofenig | 0:796d0f61a05b | 55 | |
HannesTschofenig | 0:796d0f61a05b | 56 | /** |
HannesTschofenig | 0:796d0f61a05b | 57 | * \brief PKCS#5 PBES2 function |
HannesTschofenig | 0:796d0f61a05b | 58 | * |
HannesTschofenig | 0:796d0f61a05b | 59 | * \param pbe_params the ASN.1 algorithm parameters |
HannesTschofenig | 0:796d0f61a05b | 60 | * \param mode either PKCS5_DECRYPT or PKCS5_ENCRYPT |
HannesTschofenig | 0:796d0f61a05b | 61 | * \param pwd password to use when generating key |
HannesTschofenig | 0:796d0f61a05b | 62 | * \param pwdlen length of password |
HannesTschofenig | 0:796d0f61a05b | 63 | * \param data data to process |
HannesTschofenig | 0:796d0f61a05b | 64 | * \param datalen length of data |
HannesTschofenig | 0:796d0f61a05b | 65 | * \param output output buffer |
HannesTschofenig | 0:796d0f61a05b | 66 | * |
HannesTschofenig | 0:796d0f61a05b | 67 | * \returns 0 on success, or a PolarSSL error code if verification fails. |
HannesTschofenig | 0:796d0f61a05b | 68 | */ |
HannesTschofenig | 0:796d0f61a05b | 69 | int pkcs5_pbes2( asn1_buf *pbe_params, int mode, |
HannesTschofenig | 0:796d0f61a05b | 70 | const unsigned char *pwd, size_t pwdlen, |
HannesTschofenig | 0:796d0f61a05b | 71 | const unsigned char *data, size_t datalen, |
HannesTschofenig | 0:796d0f61a05b | 72 | unsigned char *output ); |
HannesTschofenig | 0:796d0f61a05b | 73 | |
HannesTschofenig | 0:796d0f61a05b | 74 | /** |
HannesTschofenig | 0:796d0f61a05b | 75 | * \brief PKCS#5 PBKDF2 using HMAC |
HannesTschofenig | 0:796d0f61a05b | 76 | * |
HannesTschofenig | 0:796d0f61a05b | 77 | * \param ctx Generic HMAC context |
HannesTschofenig | 0:796d0f61a05b | 78 | * \param password Password to use when generating key |
HannesTschofenig | 0:796d0f61a05b | 79 | * \param plen Length of password |
HannesTschofenig | 0:796d0f61a05b | 80 | * \param salt Salt to use when generating key |
HannesTschofenig | 0:796d0f61a05b | 81 | * \param slen Length of salt |
HannesTschofenig | 0:796d0f61a05b | 82 | * \param iteration_count Iteration count |
HannesTschofenig | 0:796d0f61a05b | 83 | * \param key_length Length of generated key |
HannesTschofenig | 0:796d0f61a05b | 84 | * \param output Generated key. Must be at least as big as key_length |
HannesTschofenig | 0:796d0f61a05b | 85 | * |
HannesTschofenig | 0:796d0f61a05b | 86 | * \returns 0 on success, or a PolarSSL error code if verification fails. |
HannesTschofenig | 0:796d0f61a05b | 87 | */ |
HannesTschofenig | 0:796d0f61a05b | 88 | int pkcs5_pbkdf2_hmac( md_context_t *ctx, const unsigned char *password, |
HannesTschofenig | 0:796d0f61a05b | 89 | size_t plen, const unsigned char *salt, size_t slen, |
HannesTschofenig | 0:796d0f61a05b | 90 | unsigned int iteration_count, |
HannesTschofenig | 0:796d0f61a05b | 91 | uint32_t key_length, unsigned char *output ); |
HannesTschofenig | 0:796d0f61a05b | 92 | |
HannesTschofenig | 0:796d0f61a05b | 93 | /** |
HannesTschofenig | 0:796d0f61a05b | 94 | * \brief Checkup routine |
HannesTschofenig | 0:796d0f61a05b | 95 | * |
HannesTschofenig | 0:796d0f61a05b | 96 | * \return 0 if successful, or 1 if the test failed |
HannesTschofenig | 0:796d0f61a05b | 97 | */ |
HannesTschofenig | 0:796d0f61a05b | 98 | int pkcs5_self_test( int verbose ); |
HannesTschofenig | 0:796d0f61a05b | 99 | |
HannesTschofenig | 0:796d0f61a05b | 100 | #ifdef __cplusplus |
HannesTschofenig | 0:796d0f61a05b | 101 | } |
HannesTschofenig | 0:796d0f61a05b | 102 | #endif |
HannesTschofenig | 0:796d0f61a05b | 103 | |
HannesTschofenig | 0:796d0f61a05b | 104 | #endif /* pkcs5.h */ |
HannesTschofenig | 0:796d0f61a05b | 105 | |
HannesTschofenig | 0:796d0f61a05b | 106 |