Marco Zecchini
/
Example_RTOS
Rtos API example
Embed:
(wiki syntax)
Show/hide line numbers
pem.h
Go to the documentation of this file.
00001 /** 00002 * \file pem.h 00003 * 00004 * \brief Privacy Enhanced Mail (PEM) decoding 00005 * 00006 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 00007 * SPDX-License-Identifier: Apache-2.0 00008 * 00009 * Licensed under the Apache License, Version 2.0 (the "License"); you may 00010 * not use this file except in compliance with the License. 00011 * You may obtain a copy of the License at 00012 * 00013 * http://www.apache.org/licenses/LICENSE-2.0 00014 * 00015 * Unless required by applicable law or agreed to in writing, software 00016 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 00017 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00018 * See the License for the specific language governing permissions and 00019 * limitations under the License. 00020 * 00021 * This file is part of mbed TLS (https://tls.mbed.org) 00022 */ 00023 #ifndef MBEDTLS_PEM_H 00024 #define MBEDTLS_PEM_H 00025 00026 #include <stddef.h> 00027 00028 /** 00029 * \name PEM Error codes 00030 * These error codes are returned in case of errors reading the 00031 * PEM data. 00032 * \{ 00033 */ 00034 #define MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT -0x1080 /**< No PEM header or footer found. */ 00035 #define MBEDTLS_ERR_PEM_INVALID_DATA -0x1100 /**< PEM string is not as expected. */ 00036 #define MBEDTLS_ERR_PEM_ALLOC_FAILED -0x1180 /**< Failed to allocate memory. */ 00037 #define MBEDTLS_ERR_PEM_INVALID_ENC_IV -0x1200 /**< RSA IV is not in hex-format. */ 00038 #define MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG -0x1280 /**< Unsupported key encryption algorithm. */ 00039 #define MBEDTLS_ERR_PEM_PASSWORD_REQUIRED -0x1300 /**< Private key password can't be empty. */ 00040 #define MBEDTLS_ERR_PEM_PASSWORD_MISMATCH -0x1380 /**< Given private key password does not allow for correct decryption. */ 00041 #define MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE -0x1400 /**< Unavailable feature, e.g. hashing/encryption combination. */ 00042 #define MBEDTLS_ERR_PEM_BAD_INPUT_DATA -0x1480 /**< Bad input parameters to function. */ 00043 /* \} name */ 00044 00045 #ifdef __cplusplus 00046 extern "C" { 00047 #endif 00048 00049 #if defined(MBEDTLS_PEM_PARSE_C) 00050 /** 00051 * \brief PEM context structure 00052 */ 00053 typedef struct 00054 { 00055 unsigned char *buf ; /*!< buffer for decoded data */ 00056 size_t buflen ; /*!< length of the buffer */ 00057 unsigned char *info ; /*!< buffer for extra header information */ 00058 } 00059 mbedtls_pem_context; 00060 00061 /** 00062 * \brief PEM context setup 00063 * 00064 * \param ctx context to be initialized 00065 */ 00066 void mbedtls_pem_init( mbedtls_pem_context *ctx ); 00067 00068 /** 00069 * \brief Read a buffer for PEM information and store the resulting 00070 * data into the specified context buffers. 00071 * 00072 * \param ctx context to use 00073 * \param header header string to seek and expect 00074 * \param footer footer string to seek and expect 00075 * \param data source data to look in (must be nul-terminated) 00076 * \param pwd password for decryption (can be NULL) 00077 * \param pwdlen length of password 00078 * \param use_len destination for total length used (set after header is 00079 * correctly read, so unless you get 00080 * MBEDTLS_ERR_PEM_BAD_INPUT_DATA or 00081 * MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT, use_len is 00082 * the length to skip) 00083 * 00084 * \note Attempts to check password correctness by verifying if 00085 * the decrypted text starts with an ASN.1 sequence of 00086 * appropriate length 00087 * 00088 * \return 0 on success, or a specific PEM error code 00089 */ 00090 int mbedtls_pem_read_buffer( mbedtls_pem_context *ctx, const char *header, const char *footer, 00091 const unsigned char *data, 00092 const unsigned char *pwd, 00093 size_t pwdlen, size_t *use_len ); 00094 00095 /** 00096 * \brief PEM context memory freeing 00097 * 00098 * \param ctx context to be freed 00099 */ 00100 void mbedtls_pem_free( mbedtls_pem_context *ctx ); 00101 #endif /* MBEDTLS_PEM_PARSE_C */ 00102 00103 #if defined(MBEDTLS_PEM_WRITE_C) 00104 /** 00105 * \brief Write a buffer of PEM information from a DER encoded 00106 * buffer. 00107 * 00108 * \param header header string to write 00109 * \param footer footer string to write 00110 * \param der_data DER data to write 00111 * \param der_len length of the DER data 00112 * \param buf buffer to write to 00113 * \param buf_len length of output buffer 00114 * \param olen total length written / required (if buf_len is not enough) 00115 * 00116 * \return 0 on success, or a specific PEM or BASE64 error code. On 00117 * MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL olen is the required 00118 * size. 00119 */ 00120 int mbedtls_pem_write_buffer( const char *header, const char *footer, 00121 const unsigned char *der_data, size_t der_len, 00122 unsigned char *buf, size_t buf_len, size_t *olen ); 00123 #endif /* MBEDTLS_PEM_WRITE_C */ 00124 00125 #ifdef __cplusplus 00126 } 00127 #endif 00128 00129 #endif /* pem.h */
Generated on Sun Jul 17 2022 08:25:29 by 1.7.2