Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

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 /*
00009  *  Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
00010  *  SPDX-License-Identifier: Apache-2.0
00011  *
00012  *  Licensed under the Apache License, Version 2.0 (the "License"); you may
00013  *  not use this file except in compliance with the License.
00014  *  You may obtain a copy of the License at
00015  *
00016  *  http://www.apache.org/licenses/LICENSE-2.0
00017  *
00018  *  Unless required by applicable law or agreed to in writing, software
00019  *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00020  *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00021  *  See the License for the specific language governing permissions and
00022  *  limitations under the License.
00023  *
00024  *  This file is part of mbed TLS (https://tls.mbed.org)
00025  */
00026 #ifndef MBEDTLS_PKCS5_H
00027 #define MBEDTLS_PKCS5_H
00028 
00029 #if !defined(MBEDTLS_CONFIG_FILE)
00030 #include "mbedtls/config.h"
00031 #else
00032 #include MBEDTLS_CONFIG_FILE
00033 #endif
00034 
00035 #include "mbedtls/asn1.h"
00036 #include "mbedtls/md.h"
00037 
00038 #include <stddef.h>
00039 #include <stdint.h>
00040 
00041 #define MBEDTLS_ERR_PKCS5_BAD_INPUT_DATA                  -0x2f80  /**< Bad input parameters to function. */
00042 #define MBEDTLS_ERR_PKCS5_INVALID_FORMAT                  -0x2f00  /**< Unexpected ASN.1 data. */
00043 #define MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE             -0x2e80  /**< Requested encryption or digest alg not available. */
00044 #define MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH               -0x2e00  /**< Given private key password does not allow for correct decryption. */
00045 
00046 #define MBEDTLS_PKCS5_DECRYPT      0
00047 #define MBEDTLS_PKCS5_ENCRYPT      1
00048 
00049 #ifdef __cplusplus
00050 extern "C" {
00051 #endif
00052 
00053 #if defined(MBEDTLS_ASN1_PARSE_C)
00054 
00055 /**
00056  * \brief          PKCS#5 PBES2 function
00057  *
00058  * \param pbe_params the ASN.1 algorithm parameters
00059  * \param mode       either MBEDTLS_PKCS5_DECRYPT or MBEDTLS_PKCS5_ENCRYPT
00060  * \param pwd        password to use when generating key
00061  * \param pwdlen     length of password
00062  * \param data       data to process
00063  * \param datalen    length of data
00064  * \param output     output buffer
00065  *
00066  * \returns        0 on success, or a MBEDTLS_ERR_XXX code if verification fails.
00067  */
00068 int mbedtls_pkcs5_pbes2( const mbedtls_asn1_buf *pbe_params, int mode,
00069                  const unsigned char *pwd,  size_t pwdlen,
00070                  const unsigned char *data, size_t datalen,
00071                  unsigned char *output );
00072 
00073 #endif /* MBEDTLS_ASN1_PARSE_C */
00074 
00075 /**
00076  * \brief          PKCS#5 PBKDF2 using HMAC
00077  *
00078  * \param ctx      Generic HMAC context
00079  * \param password Password to use when generating key
00080  * \param plen     Length of password
00081  * \param salt     Salt to use when generating key
00082  * \param slen     Length of salt
00083  * \param iteration_count       Iteration count
00084  * \param key_length            Length of generated key in bytes
00085  * \param output   Generated key. Must be at least as big as key_length
00086  *
00087  * \returns        0 on success, or a MBEDTLS_ERR_XXX code if verification fails.
00088  */
00089 int mbedtls_pkcs5_pbkdf2_hmac( mbedtls_md_context_t *ctx, const unsigned char *password,
00090                        size_t plen, const unsigned char *salt, size_t slen,
00091                        unsigned int iteration_count,
00092                        uint32_t key_length, unsigned char *output );
00093 
00094 #if defined(MBEDTLS_SELF_TEST)
00095 
00096 /**
00097  * \brief          Checkup routine
00098  *
00099  * \return         0 if successful, or 1 if the test failed
00100  */
00101 int mbedtls_pkcs5_self_test( int verbose );
00102 
00103 #endif /* MBEDTLS_SELF_TEST */
00104 
00105 #ifdef __cplusplus
00106 }
00107 #endif
00108 
00109 #endif /* pkcs5.h */