mbed TLS Build

Dependents:   Slave-prot-prod

Committer:
williequesada
Date:
Tue Jun 04 16:03:38 2019 +0000
Revision:
1:1a219dea6cb5
Parent:
0:cdf462088d13
compartir a Pablo

Who changed what in which revision?

UserRevisionLine numberNew contents of line
markrad 0:cdf462088d13 1 /**
markrad 0:cdf462088d13 2 * \file ccm.h
markrad 0:cdf462088d13 3 *
markrad 0:cdf462088d13 4 * \brief Counter with CBC-MAC (CCM) for 128-bit block ciphers
markrad 0:cdf462088d13 5 *
markrad 0:cdf462088d13 6 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
markrad 0:cdf462088d13 7 * SPDX-License-Identifier: Apache-2.0
markrad 0:cdf462088d13 8 *
markrad 0:cdf462088d13 9 * Licensed under the Apache License, Version 2.0 (the "License"); you may
markrad 0:cdf462088d13 10 * not use this file except in compliance with the License.
markrad 0:cdf462088d13 11 * You may obtain a copy of the License at
markrad 0:cdf462088d13 12 *
markrad 0:cdf462088d13 13 * http://www.apache.org/licenses/LICENSE-2.0
markrad 0:cdf462088d13 14 *
markrad 0:cdf462088d13 15 * Unless required by applicable law or agreed to in writing, software
markrad 0:cdf462088d13 16 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
markrad 0:cdf462088d13 17 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
markrad 0:cdf462088d13 18 * See the License for the specific language governing permissions and
markrad 0:cdf462088d13 19 * limitations under the License.
markrad 0:cdf462088d13 20 *
markrad 0:cdf462088d13 21 * This file is part of mbed TLS (https://tls.mbed.org)
markrad 0:cdf462088d13 22 */
markrad 0:cdf462088d13 23 #ifndef MBEDTLS_CCM_H
markrad 0:cdf462088d13 24 #define MBEDTLS_CCM_H
markrad 0:cdf462088d13 25
markrad 0:cdf462088d13 26 #include "cipher.h"
markrad 0:cdf462088d13 27
markrad 0:cdf462088d13 28 #define MBEDTLS_ERR_CCM_BAD_INPUT -0x000D /**< Bad input parameters to function. */
markrad 0:cdf462088d13 29 #define MBEDTLS_ERR_CCM_AUTH_FAILED -0x000F /**< Authenticated decryption failed. */
markrad 0:cdf462088d13 30
markrad 0:cdf462088d13 31 #ifdef __cplusplus
markrad 0:cdf462088d13 32 extern "C" {
markrad 0:cdf462088d13 33 #endif
markrad 0:cdf462088d13 34
markrad 0:cdf462088d13 35 /**
markrad 0:cdf462088d13 36 * \brief CCM context structure
markrad 0:cdf462088d13 37 */
markrad 0:cdf462088d13 38 typedef struct {
markrad 0:cdf462088d13 39 mbedtls_cipher_context_t cipher_ctx; /*!< cipher context used */
markrad 0:cdf462088d13 40 }
markrad 0:cdf462088d13 41 mbedtls_ccm_context;
markrad 0:cdf462088d13 42
markrad 0:cdf462088d13 43 /**
markrad 0:cdf462088d13 44 * \brief Initialize CCM context (just makes references valid)
markrad 0:cdf462088d13 45 * Makes the context ready for mbedtls_ccm_setkey() or
markrad 0:cdf462088d13 46 * mbedtls_ccm_free().
markrad 0:cdf462088d13 47 *
markrad 0:cdf462088d13 48 * \param ctx CCM context to initialize
markrad 0:cdf462088d13 49 */
markrad 0:cdf462088d13 50 void mbedtls_ccm_init( mbedtls_ccm_context *ctx );
markrad 0:cdf462088d13 51
markrad 0:cdf462088d13 52 /**
markrad 0:cdf462088d13 53 * \brief CCM initialization (encryption and decryption)
markrad 0:cdf462088d13 54 *
markrad 0:cdf462088d13 55 * \param ctx CCM context to be initialized
markrad 0:cdf462088d13 56 * \param cipher cipher to use (a 128-bit block cipher)
markrad 0:cdf462088d13 57 * \param key encryption key
markrad 0:cdf462088d13 58 * \param keybits key size in bits (must be acceptable by the cipher)
markrad 0:cdf462088d13 59 *
markrad 0:cdf462088d13 60 * \return 0 if successful, or a cipher specific error code
markrad 0:cdf462088d13 61 */
markrad 0:cdf462088d13 62 int mbedtls_ccm_setkey( mbedtls_ccm_context *ctx,
markrad 0:cdf462088d13 63 mbedtls_cipher_id_t cipher,
markrad 0:cdf462088d13 64 const unsigned char *key,
markrad 0:cdf462088d13 65 unsigned int keybits );
markrad 0:cdf462088d13 66
markrad 0:cdf462088d13 67 /**
markrad 0:cdf462088d13 68 * \brief Free a CCM context and underlying cipher sub-context
markrad 0:cdf462088d13 69 *
markrad 0:cdf462088d13 70 * \param ctx CCM context to free
markrad 0:cdf462088d13 71 */
markrad 0:cdf462088d13 72 void mbedtls_ccm_free( mbedtls_ccm_context *ctx );
markrad 0:cdf462088d13 73
markrad 0:cdf462088d13 74 /**
markrad 0:cdf462088d13 75 * \brief CCM buffer encryption
markrad 0:cdf462088d13 76 *
markrad 0:cdf462088d13 77 * \param ctx CCM context
markrad 0:cdf462088d13 78 * \param length length of the input data in bytes
markrad 0:cdf462088d13 79 * \param iv nonce (initialization vector)
markrad 0:cdf462088d13 80 * \param iv_len length of IV in bytes
markrad 0:cdf462088d13 81 * must be 2, 3, 4, 5, 6, 7 or 8
markrad 0:cdf462088d13 82 * \param add additional data
markrad 0:cdf462088d13 83 * \param add_len length of additional data in bytes
markrad 0:cdf462088d13 84 * must be less than 2^16 - 2^8
markrad 0:cdf462088d13 85 * \param input buffer holding the input data
markrad 0:cdf462088d13 86 * \param output buffer for holding the output data
markrad 0:cdf462088d13 87 * must be at least 'length' bytes wide
markrad 0:cdf462088d13 88 * \param tag buffer for holding the tag
markrad 0:cdf462088d13 89 * \param tag_len length of the tag to generate in bytes
markrad 0:cdf462088d13 90 * must be 4, 6, 8, 10, 14 or 16
markrad 0:cdf462088d13 91 *
markrad 0:cdf462088d13 92 * \note The tag is written to a separate buffer. To get the tag
markrad 0:cdf462088d13 93 * concatenated with the output as in the CCM spec, use
markrad 0:cdf462088d13 94 * tag = output + length and make sure the output buffer is
markrad 0:cdf462088d13 95 * at least length + tag_len wide.
markrad 0:cdf462088d13 96 *
markrad 0:cdf462088d13 97 * \return 0 if successful
markrad 0:cdf462088d13 98 */
markrad 0:cdf462088d13 99 int mbedtls_ccm_encrypt_and_tag( mbedtls_ccm_context *ctx, size_t length,
markrad 0:cdf462088d13 100 const unsigned char *iv, size_t iv_len,
markrad 0:cdf462088d13 101 const unsigned char *add, size_t add_len,
markrad 0:cdf462088d13 102 const unsigned char *input, unsigned char *output,
markrad 0:cdf462088d13 103 unsigned char *tag, size_t tag_len );
markrad 0:cdf462088d13 104
markrad 0:cdf462088d13 105 /**
markrad 0:cdf462088d13 106 * \brief CCM buffer authenticated decryption
markrad 0:cdf462088d13 107 *
markrad 0:cdf462088d13 108 * \param ctx CCM context
markrad 0:cdf462088d13 109 * \param length length of the input data
markrad 0:cdf462088d13 110 * \param iv initialization vector
markrad 0:cdf462088d13 111 * \param iv_len length of IV
markrad 0:cdf462088d13 112 * \param add additional data
markrad 0:cdf462088d13 113 * \param add_len length of additional data
markrad 0:cdf462088d13 114 * \param input buffer holding the input data
markrad 0:cdf462088d13 115 * \param output buffer for holding the output data
markrad 0:cdf462088d13 116 * \param tag buffer holding the tag
markrad 0:cdf462088d13 117 * \param tag_len length of the tag
markrad 0:cdf462088d13 118 *
markrad 0:cdf462088d13 119 * \return 0 if successful and authenticated,
markrad 0:cdf462088d13 120 * MBEDTLS_ERR_CCM_AUTH_FAILED if tag does not match
markrad 0:cdf462088d13 121 */
markrad 0:cdf462088d13 122 int mbedtls_ccm_auth_decrypt( mbedtls_ccm_context *ctx, size_t length,
markrad 0:cdf462088d13 123 const unsigned char *iv, size_t iv_len,
markrad 0:cdf462088d13 124 const unsigned char *add, size_t add_len,
markrad 0:cdf462088d13 125 const unsigned char *input, unsigned char *output,
markrad 0:cdf462088d13 126 const unsigned char *tag, size_t tag_len );
markrad 0:cdf462088d13 127
markrad 0:cdf462088d13 128 #if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_AES_C)
markrad 0:cdf462088d13 129 /**
markrad 0:cdf462088d13 130 * \brief Checkup routine
markrad 0:cdf462088d13 131 *
markrad 0:cdf462088d13 132 * \return 0 if successful, or 1 if the test failed
markrad 0:cdf462088d13 133 */
markrad 0:cdf462088d13 134 int mbedtls_ccm_self_test( int verbose );
markrad 0:cdf462088d13 135 #endif /* MBEDTLS_SELF_TEST && MBEDTLS_AES_C */
markrad 0:cdf462088d13 136
markrad 0:cdf462088d13 137 #ifdef __cplusplus
markrad 0:cdf462088d13 138 }
markrad 0:cdf462088d13 139 #endif
markrad 0:cdf462088d13 140
markrad 0:cdf462088d13 141 #endif /* MBEDTLS_CCM_H */