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.
Fork of mbedtls by
include/mbedtls/cmac.h@2:bbdeda018a3c, 2017-09-29 (annotated)
- Committer:
- Jasper Wallace
- Date:
- Fri Sep 29 19:50:30 2017 +0100
- Revision:
- 2:bbdeda018a3c
- Parent:
- 0:cdf462088d13
Update to mbedtls 2.6.0, many changes.
Changes to mbedtls sources made:
in include/mbedtls/config.h comment out:
#define MBEDTLS_FS_IO
#define MBEDTLS_NET_C
#define MBEDTLS_TIMING_C
uncomment:
#define MBEDTLS_NO_PLATFORM_ENTROPY
remove the following directorys:
programs
yotta
visualc
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| markrad | 0:cdf462088d13 | 1 | /** |
| markrad | 0:cdf462088d13 | 2 | * \file cmac.h |
| markrad | 0:cdf462088d13 | 3 | * |
| markrad | 0:cdf462088d13 | 4 | * \brief Cipher-based Message Authentication Code (CMAC) Mode for |
| markrad | 0:cdf462088d13 | 5 | * Authentication |
| markrad | 0:cdf462088d13 | 6 | * |
| markrad | 0:cdf462088d13 | 7 | * Copyright (C) 2015-2016, ARM Limited, All Rights Reserved |
| markrad | 0:cdf462088d13 | 8 | * SPDX-License-Identifier: Apache-2.0 |
| markrad | 0:cdf462088d13 | 9 | * |
| markrad | 0:cdf462088d13 | 10 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| markrad | 0:cdf462088d13 | 11 | * not use this file except in compliance with the License. |
| markrad | 0:cdf462088d13 | 12 | * You may obtain a copy of the License at |
| markrad | 0:cdf462088d13 | 13 | * |
| markrad | 0:cdf462088d13 | 14 | * http://www.apache.org/licenses/LICENSE-2.0 |
| markrad | 0:cdf462088d13 | 15 | * |
| markrad | 0:cdf462088d13 | 16 | * Unless required by applicable law or agreed to in writing, software |
| markrad | 0:cdf462088d13 | 17 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| markrad | 0:cdf462088d13 | 18 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| markrad | 0:cdf462088d13 | 19 | * See the License for the specific language governing permissions and |
| markrad | 0:cdf462088d13 | 20 | * limitations under the License. |
| markrad | 0:cdf462088d13 | 21 | * |
| markrad | 0:cdf462088d13 | 22 | * This file is part of mbed TLS (https://tls.mbed.org) |
| markrad | 0:cdf462088d13 | 23 | */ |
| markrad | 0:cdf462088d13 | 24 | #ifndef MBEDTLS_CMAC_H |
| markrad | 0:cdf462088d13 | 25 | #define MBEDTLS_CMAC_H |
| markrad | 0:cdf462088d13 | 26 | |
| markrad | 0:cdf462088d13 | 27 | #include "mbedtls/cipher.h" |
| markrad | 0:cdf462088d13 | 28 | |
| markrad | 0:cdf462088d13 | 29 | #ifdef __cplusplus |
| markrad | 0:cdf462088d13 | 30 | extern "C" { |
| markrad | 0:cdf462088d13 | 31 | #endif |
| markrad | 0:cdf462088d13 | 32 | |
| markrad | 0:cdf462088d13 | 33 | #define MBEDTLS_AES_BLOCK_SIZE 16 |
| markrad | 0:cdf462088d13 | 34 | #define MBEDTLS_DES3_BLOCK_SIZE 8 |
| markrad | 0:cdf462088d13 | 35 | |
| markrad | 0:cdf462088d13 | 36 | #if defined(MBEDTLS_AES_C) |
| markrad | 0:cdf462088d13 | 37 | #define MBEDTLS_CIPHER_BLKSIZE_MAX 16 /* longest used by CMAC is AES */ |
| markrad | 0:cdf462088d13 | 38 | #else |
| markrad | 0:cdf462088d13 | 39 | #define MBEDTLS_CIPHER_BLKSIZE_MAX 8 /* longest used by CMAC is 3DES */ |
| markrad | 0:cdf462088d13 | 40 | #endif |
| markrad | 0:cdf462088d13 | 41 | |
| markrad | 0:cdf462088d13 | 42 | /** |
| markrad | 0:cdf462088d13 | 43 | * CMAC context structure - Contains internal state information only |
| markrad | 0:cdf462088d13 | 44 | */ |
| markrad | 0:cdf462088d13 | 45 | struct mbedtls_cmac_context_t |
| markrad | 0:cdf462088d13 | 46 | { |
| markrad | 0:cdf462088d13 | 47 | /** Internal state of the CMAC algorithm */ |
| markrad | 0:cdf462088d13 | 48 | unsigned char state[MBEDTLS_CIPHER_BLKSIZE_MAX]; |
| markrad | 0:cdf462088d13 | 49 | |
| markrad | 0:cdf462088d13 | 50 | /** Unprocessed data - either data that was not block aligned and is still |
| markrad | 0:cdf462088d13 | 51 | * pending to be processed, or the final block */ |
| markrad | 0:cdf462088d13 | 52 | unsigned char unprocessed_block[MBEDTLS_CIPHER_BLKSIZE_MAX]; |
| markrad | 0:cdf462088d13 | 53 | |
| markrad | 0:cdf462088d13 | 54 | /** Length of data pending to be processed */ |
| markrad | 0:cdf462088d13 | 55 | size_t unprocessed_len; |
| markrad | 0:cdf462088d13 | 56 | }; |
| markrad | 0:cdf462088d13 | 57 | |
| markrad | 0:cdf462088d13 | 58 | /** |
| markrad | 0:cdf462088d13 | 59 | * \brief Set the CMAC key and prepare to authenticate the input |
| markrad | 0:cdf462088d13 | 60 | * data. |
| markrad | 0:cdf462088d13 | 61 | * Should be called with an initialized cipher context. |
| markrad | 0:cdf462088d13 | 62 | * |
| markrad | 0:cdf462088d13 | 63 | * \param ctx Cipher context. This should be a cipher context, |
| markrad | 0:cdf462088d13 | 64 | * initialized to be one of the following types: |
| markrad | 0:cdf462088d13 | 65 | * MBEDTLS_CIPHER_AES_128_ECB, MBEDTLS_CIPHER_AES_192_ECB, |
| markrad | 0:cdf462088d13 | 66 | * MBEDTLS_CIPHER_AES_256_ECB or |
| markrad | 0:cdf462088d13 | 67 | * MBEDTLS_CIPHER_DES_EDE3_ECB. |
| markrad | 0:cdf462088d13 | 68 | * \param key CMAC key |
| markrad | 0:cdf462088d13 | 69 | * \param keybits length of the CMAC key in bits |
| markrad | 0:cdf462088d13 | 70 | * (must be acceptable by the cipher) |
| markrad | 0:cdf462088d13 | 71 | * |
| markrad | 0:cdf462088d13 | 72 | * \return 0 if successful, or a cipher specific error code |
| markrad | 0:cdf462088d13 | 73 | */ |
| markrad | 0:cdf462088d13 | 74 | int mbedtls_cipher_cmac_starts( mbedtls_cipher_context_t *ctx, |
| markrad | 0:cdf462088d13 | 75 | const unsigned char *key, size_t keybits ); |
| markrad | 0:cdf462088d13 | 76 | |
| markrad | 0:cdf462088d13 | 77 | /** |
| markrad | 0:cdf462088d13 | 78 | * \brief Generic CMAC process buffer. |
| markrad | 0:cdf462088d13 | 79 | * Called between mbedtls_cipher_cmac_starts() or |
| markrad | 0:cdf462088d13 | 80 | * mbedtls_cipher_cmac_reset() and |
| markrad | 0:cdf462088d13 | 81 | * mbedtls_cipher_cmac_finish(). |
| markrad | 0:cdf462088d13 | 82 | * May be called repeatedly. |
| markrad | 0:cdf462088d13 | 83 | * |
| markrad | 0:cdf462088d13 | 84 | * \param ctx CMAC context |
| markrad | 0:cdf462088d13 | 85 | * \param input buffer holding the data |
| markrad | 0:cdf462088d13 | 86 | * \param ilen length of the input data |
| markrad | 0:cdf462088d13 | 87 | * |
| markrad | 0:cdf462088d13 | 88 | * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter |
| markrad | 0:cdf462088d13 | 89 | * verification fails. |
| markrad | 0:cdf462088d13 | 90 | */ |
| markrad | 0:cdf462088d13 | 91 | int mbedtls_cipher_cmac_update( mbedtls_cipher_context_t *ctx, |
| markrad | 0:cdf462088d13 | 92 | const unsigned char *input, size_t ilen ); |
| markrad | 0:cdf462088d13 | 93 | |
| markrad | 0:cdf462088d13 | 94 | /** |
| markrad | 0:cdf462088d13 | 95 | * \brief Output CMAC. |
| markrad | 0:cdf462088d13 | 96 | * Called after mbedtls_cipher_cmac_update(). |
| markrad | 0:cdf462088d13 | 97 | * Usually followed by mbedtls_cipher_cmac_reset(), then |
| markrad | 0:cdf462088d13 | 98 | * mbedtls_cipher_cmac_starts(), or mbedtls_cipher_free(). |
| markrad | 0:cdf462088d13 | 99 | * |
| markrad | 0:cdf462088d13 | 100 | * \param ctx CMAC context |
| markrad | 0:cdf462088d13 | 101 | * \param output Generic CMAC checksum result |
| markrad | 0:cdf462088d13 | 102 | * |
| markrad | 0:cdf462088d13 | 103 | * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter |
| markrad | 0:cdf462088d13 | 104 | * verification fails. |
| markrad | 0:cdf462088d13 | 105 | */ |
| markrad | 0:cdf462088d13 | 106 | int mbedtls_cipher_cmac_finish( mbedtls_cipher_context_t *ctx, |
| markrad | 0:cdf462088d13 | 107 | unsigned char *output ); |
| markrad | 0:cdf462088d13 | 108 | |
| markrad | 0:cdf462088d13 | 109 | /** |
| markrad | 0:cdf462088d13 | 110 | * \brief Prepare to authenticate a new message with the same key. |
| markrad | 0:cdf462088d13 | 111 | * Called after mbedtls_cipher_cmac_finish() and before |
| markrad | 0:cdf462088d13 | 112 | * mbedtls_cipher_cmac_update(). |
| markrad | 0:cdf462088d13 | 113 | * |
| markrad | 0:cdf462088d13 | 114 | * \param ctx CMAC context to be reset |
| markrad | 0:cdf462088d13 | 115 | * |
| markrad | 0:cdf462088d13 | 116 | * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter |
| markrad | 0:cdf462088d13 | 117 | * verification fails. |
| markrad | 0:cdf462088d13 | 118 | */ |
| markrad | 0:cdf462088d13 | 119 | int mbedtls_cipher_cmac_reset( mbedtls_cipher_context_t *ctx ); |
| markrad | 0:cdf462088d13 | 120 | |
| markrad | 0:cdf462088d13 | 121 | /** |
| markrad | 0:cdf462088d13 | 122 | * \brief Output = Generic_CMAC( cmac key, input buffer ) |
| markrad | 0:cdf462088d13 | 123 | * |
| markrad | 0:cdf462088d13 | 124 | * \param cipher_info message digest info |
| markrad | 0:cdf462088d13 | 125 | * \param key CMAC key |
| markrad | 0:cdf462088d13 | 126 | * \param keylen length of the CMAC key in bits |
| markrad | 0:cdf462088d13 | 127 | * \param input buffer holding the data |
| markrad | 0:cdf462088d13 | 128 | * \param ilen length of the input data |
| markrad | 0:cdf462088d13 | 129 | * \param output Generic CMAC-result |
| markrad | 0:cdf462088d13 | 130 | * |
| markrad | 0:cdf462088d13 | 131 | * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter |
| markrad | 0:cdf462088d13 | 132 | * verification fails. |
| markrad | 0:cdf462088d13 | 133 | */ |
| markrad | 0:cdf462088d13 | 134 | int mbedtls_cipher_cmac( const mbedtls_cipher_info_t *cipher_info, |
| markrad | 0:cdf462088d13 | 135 | const unsigned char *key, size_t keylen, |
| markrad | 0:cdf462088d13 | 136 | const unsigned char *input, size_t ilen, |
| markrad | 0:cdf462088d13 | 137 | unsigned char *output ); |
| markrad | 0:cdf462088d13 | 138 | |
| markrad | 0:cdf462088d13 | 139 | #if defined(MBEDTLS_AES_C) |
| markrad | 0:cdf462088d13 | 140 | /** |
| markrad | 0:cdf462088d13 | 141 | * \brief AES-CMAC-128-PRF |
| markrad | 0:cdf462088d13 | 142 | * Implementation of (AES-CMAC-PRF-128), as defined in RFC 4615 |
| markrad | 0:cdf462088d13 | 143 | * |
| markrad | 0:cdf462088d13 | 144 | * \param key PRF key |
| markrad | 0:cdf462088d13 | 145 | * \param key_len PRF key length in bytes |
| markrad | 0:cdf462088d13 | 146 | * \param input buffer holding the input data |
| markrad | 0:cdf462088d13 | 147 | * \param in_len length of the input data in bytes |
| markrad | 0:cdf462088d13 | 148 | * \param output buffer holding the generated pseudorandom output (16 bytes) |
| markrad | 0:cdf462088d13 | 149 | * |
| markrad | 0:cdf462088d13 | 150 | * \return 0 if successful |
| markrad | 0:cdf462088d13 | 151 | */ |
| markrad | 0:cdf462088d13 | 152 | int mbedtls_aes_cmac_prf_128( const unsigned char *key, size_t key_len, |
| markrad | 0:cdf462088d13 | 153 | const unsigned char *input, size_t in_len, |
| markrad | 0:cdf462088d13 | 154 | unsigned char output[16] ); |
| markrad | 0:cdf462088d13 | 155 | #endif /* MBEDTLS_AES_C */ |
| markrad | 0:cdf462088d13 | 156 | |
| markrad | 0:cdf462088d13 | 157 | #if defined(MBEDTLS_SELF_TEST) && ( defined(MBEDTLS_AES_C) || defined(MBEDTLS_DES_C) ) |
| markrad | 0:cdf462088d13 | 158 | /** |
| markrad | 0:cdf462088d13 | 159 | * \brief Checkup routine |
| markrad | 0:cdf462088d13 | 160 | * |
| markrad | 0:cdf462088d13 | 161 | * \return 0 if successful, or 1 if the test failed |
| markrad | 0:cdf462088d13 | 162 | */ |
| markrad | 0:cdf462088d13 | 163 | int mbedtls_cmac_self_test( int verbose ); |
| markrad | 0:cdf462088d13 | 164 | #endif /* MBEDTLS_SELF_TEST && ( MBEDTLS_AES_C || MBEDTLS_DES_C ) */ |
| markrad | 0:cdf462088d13 | 165 | |
| markrad | 0:cdf462088d13 | 166 | #ifdef __cplusplus |
| markrad | 0:cdf462088d13 | 167 | } |
| markrad | 0:cdf462088d13 | 168 | #endif |
| markrad | 0:cdf462088d13 | 169 | |
| markrad | 0:cdf462088d13 | 170 | #endif /* MBEDTLS_CMAC_H */ |
