Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
ccm_alt.h
00001 /* 00002 * ccm_alt.h 00003 * 00004 * Copyright (C) 2018, Arm Limited, All Rights Reserved 00005 * SPDX-License-Identifier: Apache-2.0 00006 * 00007 * Licensed under the Apache License, Version 2.0 (the "License"); you may 00008 * not use this file except in compliance with the License. 00009 * You may obtain a copy of the License at 00010 * 00011 * http://www.apache.org/licenses/LICENSE-2.0 00012 * 00013 * Unless required by applicable law or agreed to in writing, software 00014 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 00015 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00016 * See the License for the specific language governing permissions and 00017 * limitations under the License. 00018 * 00019 */ 00020 00021 #ifndef __CCM_ALT__ 00022 #define __CCM_ALT__ 00023 00024 #if defined(MBEDTLS_CCM_ALT) 00025 #include "crys_aesccm.h" 00026 00027 #ifdef __cplusplus 00028 extern "C" { 00029 #endif 00030 00031 typedef struct { 00032 CRYS_AESCCM_Key_t cipher_key ; /*!< cipher key used */ 00033 CRYS_AESCCM_KeySize_t keySize_ID; 00034 } 00035 mbedtls_ccm_context; 00036 00037 /** 00038 * \brief Initialize CCM context (just makes references valid) 00039 * Makes the context ready for mbedtls_ccm_setkey() or 00040 * mbedtls_ccm_free(). 00041 * 00042 * \param ctx CCM context to initialize 00043 */ 00044 void mbedtls_ccm_init( mbedtls_ccm_context *ctx ); 00045 00046 /** 00047 * \brief CCM initialization (encryption and decryption) 00048 * 00049 * \param ctx CCM context to be initialized 00050 * \param cipher cipher to use (a 128-bit block cipher) 00051 * \param key encryption key 00052 * \param keybits key size in bits (must be acceptable by the cipher) 00053 * 00054 * \return 0 if successful, or a cipher specific error code 00055 */ 00056 int mbedtls_ccm_setkey( mbedtls_ccm_context *ctx, 00057 mbedtls_cipher_id_t cipher, 00058 const unsigned char *key, 00059 unsigned int keybits ); 00060 00061 /** 00062 * \brief Free a CCM context and underlying cipher sub-context 00063 * 00064 * \param ctx CCM context to free 00065 */ 00066 void mbedtls_ccm_free( mbedtls_ccm_context *ctx ); 00067 00068 /** 00069 * \brief CCM buffer encryption 00070 * 00071 * \param ctx CCM context 00072 * \param length length of the input data in bytes 00073 * \param iv nonce (initialization vector) 00074 * \param iv_len length of IV in bytes 00075 * must be 2, 3, 4, 5, 6, 7 or 8 00076 * \param add additional data 00077 * \param add_len length of additional data in bytes 00078 * must be less than 2^16 - 2^8 00079 * \param input buffer holding the input data 00080 * \param output buffer for holding the output data 00081 * must be at least 'length' bytes wide 00082 * \param tag buffer for holding the tag 00083 * \param tag_len length of the tag to generate in bytes 00084 * must be 4, 6, 8, 10, 14 or 16 00085 * 00086 * \note The tag is written to a separate buffer. To get the tag 00087 * concatenated with the output as in the CCM spec, use 00088 * tag = output + length and make sure the output buffer is 00089 * at least length + tag_len wide. 00090 * 00091 * \return 0 if successful 00092 */ 00093 int mbedtls_ccm_encrypt_and_tag( mbedtls_ccm_context *ctx, size_t length, 00094 const unsigned char *iv, size_t iv_len, 00095 const unsigned char *add, size_t add_len, 00096 const unsigned char *input, unsigned char *output, 00097 unsigned char *tag, size_t tag_len ); 00098 00099 /** 00100 * \brief CCM buffer authenticated decryption 00101 * 00102 * \param ctx CCM context 00103 * \param length length of the input data 00104 * \param iv initialization vector 00105 * \param iv_len length of IV 00106 * \param add additional data 00107 * \param add_len length of additional data 00108 * \param input buffer holding the input data 00109 * \param output buffer for holding the output data 00110 * \param tag buffer holding the tag 00111 * \param tag_len length of the tag 00112 * 00113 * \return 0 if successful and authenticated, 00114 * MBEDTLS_ERR_CCM_AUTH_FAILED if tag does not match 00115 */ 00116 int mbedtls_ccm_auth_decrypt( mbedtls_ccm_context *ctx, size_t length, 00117 const unsigned char *iv, size_t iv_len, 00118 const unsigned char *add, size_t add_len, 00119 const unsigned char *input, unsigned char *output, 00120 const unsigned char *tag, size_t tag_len ); 00121 00122 #ifdef __cplusplus 00123 } 00124 #endif 00125 00126 #endif /* MBEDTLS_CCM_ALT */ 00127 #endif /* __CCM_ALT__ */
Generated on Tue Jul 12 2022 12:43:38 by
