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