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