mbed TLS library
Dependents: HTTPClient-SSL WS_SERVER
ccm.h
00001 /** 00002 * \file ccm.h 00003 * 00004 * \brief Counter with CBC-MAC (CCM) for 128-bit block ciphers 00005 * 00006 * Copyright (C) 2014, ARM Limited, All Rights Reserved 00007 * 00008 * This file is part of mbed TLS (https://tls.mbed.org) 00009 * 00010 * This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU General Public License along 00021 * with this program; if not, write to the Free Software Foundation, Inc., 00022 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00023 */ 00024 #ifndef POLARSSL_CCM_H 00025 #define POLARSSL_CCM_H 00026 00027 #include "cipher.h" 00028 00029 #define POLARSSL_ERR_CCM_BAD_INPUT -0x000D /**< Bad input parameters to function. */ 00030 #define POLARSSL_ERR_CCM_AUTH_FAILED -0x000F /**< Authenticated decryption failed. */ 00031 00032 #ifdef __cplusplus 00033 extern "C" { 00034 #endif 00035 00036 /** 00037 * \brief CCM context structure 00038 */ 00039 typedef struct { 00040 cipher_context_t cipher_ctx ; /*!< cipher context used */ 00041 } 00042 ccm_context; 00043 00044 /** 00045 * \brief CCM initialization (encryption and decryption) 00046 * 00047 * \param ctx CCM context to be initialized 00048 * \param cipher cipher to use (a 128-bit block cipher) 00049 * \param key encryption key 00050 * \param keysize key size in bits (must be acceptable by the cipher) 00051 * 00052 * \return 0 if successful, or a cipher specific error code 00053 */ 00054 int ccm_init( ccm_context *ctx, cipher_id_t cipher, 00055 const unsigned char *key, unsigned int keysize ); 00056 00057 /** 00058 * \brief Free a CCM context and underlying cipher sub-context 00059 * 00060 * \param ctx CCM context to free 00061 */ 00062 void ccm_free( ccm_context *ctx ); 00063 00064 /** 00065 * \brief CCM buffer encryption 00066 * 00067 * \param ctx CCM context 00068 * \param length length of the input data in bytes 00069 * \param iv nonce (initialization vector) 00070 * \param iv_len length of IV in bytes 00071 * must be 2, 3, 4, 5, 6, 7 or 8 00072 * \param add additional data 00073 * \param add_len length of additional data in bytes 00074 * must be less than 2^16 - 2^8 00075 * \param input buffer holding the input data 00076 * \param output buffer for holding the output data 00077 * must be at least 'length' bytes wide 00078 * \param tag buffer for holding the tag 00079 * \param tag_len length of the tag to generate in bytes 00080 * must be 4, 6, 8, 10, 14 or 16 00081 * 00082 * \note The tag is written to a separate buffer. To get the tag 00083 * concatenated with the output as in the CCM spec, use 00084 * tag = output + length and make sure the output buffer is 00085 * at least length + tag_len wide. 00086 * 00087 * \return 0 if successful 00088 */ 00089 int ccm_encrypt_and_tag( ccm_context *ctx, size_t length, 00090 const unsigned char *iv, size_t iv_len, 00091 const unsigned char *add, size_t add_len, 00092 const unsigned char *input, unsigned char *output, 00093 unsigned char *tag, size_t tag_len ); 00094 00095 /** 00096 * \brief CCM buffer authenticated decryption 00097 * 00098 * \param ctx CCM context 00099 * \param length length of the input data 00100 * \param iv initialization vector 00101 * \param iv_len length of IV 00102 * \param add additional data 00103 * \param add_len length of additional data 00104 * \param input buffer holding the input data 00105 * \param output buffer for holding the output data 00106 * \param tag buffer holding the tag 00107 * \param tag_len length of the tag 00108 * 00109 * \return 0 if successful and authenticated, 00110 * POLARSSL_ERR_CCM_AUTH_FAILED if tag does not match 00111 */ 00112 int ccm_auth_decrypt( ccm_context *ctx, size_t length, 00113 const unsigned char *iv, size_t iv_len, 00114 const unsigned char *add, size_t add_len, 00115 const unsigned char *input, unsigned char *output, 00116 const unsigned char *tag, size_t tag_len ); 00117 00118 #if defined(POLARSSL_SELF_TEST) && defined(POLARSSL_AES_C) 00119 /** 00120 * \brief Checkup routine 00121 * 00122 * \return 0 if successful, or 1 if the test failed 00123 */ 00124 int ccm_self_test( int verbose ); 00125 #endif /* POLARSSL_SELF_TEST && POLARSSL_AES_C */ 00126 00127 #ifdef __cplusplus 00128 } 00129 #endif 00130 00131 #endif /* POLARSSL_CGM_H */ 00132
Generated on Tue Jul 12 2022 13:50:36 by 1.7.2