| 1 |
// Copyright (c) 2015, Google Inc. |
| 2 |
// SPDX-License-Identifier: ISC |
| 3 |
|
| 4 |
#ifndef OPENSSL_HEADER_CMAC_H |
| 5 |
#define OPENSSL_HEADER_CMAC_H |
| 6 |
|
| 7 |
#include <openssl/base.h> |
| 8 |
|
| 9 |
#if defined(__cplusplus) |
| 10 |
extern "C" { |
| 11 |
#endif |
| 12 |
|
| 13 |
|
| 14 |
// CMAC. |
| 15 |
// |
| 16 |
// CMAC is a MAC based on AES-CBC and defined in |
| 17 |
// https://tools.ietf.org/html/rfc4493#section-2.3. |
| 18 |
|
| 19 |
|
| 20 |
// One-shot functions. |
| 21 |
|
| 22 |
// AES_CMAC calculates the 16-byte, CMAC authenticator of |in_len| bytes of |
| 23 |
// |in| and writes it to |out|. The |key_len| may be 16 or 32 bytes to select |
| 24 |
// between AES-128 and AES-256. It returns one on success or zero on error. |
| 25 |
OPENSSL_EXPORT int AES_CMAC(uint8_t out[16], const uint8_t *key, size_t key_len, |
| 26 |
const uint8_t *in, size_t in_len); |
| 27 |
|
| 28 |
|
| 29 |
// Incremental interface. |
| 30 |
|
| 31 |
// CMAC_CTX_new allocates a fresh |CMAC_CTX| and returns it, or NULL on |
| 32 |
// error. |
| 33 |
OPENSSL_EXPORT CMAC_CTX *CMAC_CTX_new(void); |
| 34 |
|
| 35 |
// CMAC_CTX_free frees a |CMAC_CTX|. |
| 36 |
OPENSSL_EXPORT void CMAC_CTX_free(CMAC_CTX *ctx); |
| 37 |
|
| 38 |
// CMAC_CTX_copy sets |out| to be a duplicate of the current state |in|. It |
| 39 |
// returns one on success and zero on error. |
| 40 |
OPENSSL_EXPORT int CMAC_CTX_copy(CMAC_CTX *out, const CMAC_CTX *in); |
| 41 |
|
| 42 |
// CMAC_Init configures |ctx| to use the given |key| and |cipher|. The CMAC RFC |
| 43 |
// only specifies the use of AES-128 thus |key_len| should be 16 and |cipher| |
| 44 |
// should be |EVP_aes_128_cbc()|. However, this implementation also supports |
| 45 |
// AES-256 by setting |key_len| to 32 and |cipher| to |EVP_aes_256_cbc()|. The |
| 46 |
// |engine| argument is ignored. |
| 47 |
// |
| 48 |
// It returns one on success or zero on error. |
| 49 |
OPENSSL_EXPORT int CMAC_Init(CMAC_CTX *ctx, const void *key, size_t key_len, |
| 50 |
const EVP_CIPHER *cipher, ENGINE *engine); |
| 51 |
|
| 52 |
|
| 53 |
// CMAC_Reset resets |ctx| so that a fresh message can be authenticated. |
| 54 |
OPENSSL_EXPORT int CMAC_Reset(CMAC_CTX *ctx); |
| 55 |
|
| 56 |
// CMAC_Update processes |in_len| bytes of message from |in|. It returns one on |
| 57 |
// success or zero on error. |
| 58 |
OPENSSL_EXPORT int CMAC_Update(CMAC_CTX *ctx, const uint8_t *in, size_t in_len); |
| 59 |
|
| 60 |
// CMAC_Final sets |*out_len| to 16 and, if |out| is not NULL, writes 16 bytes |
| 61 |
// of authenticator to it. It returns one on success or zero on error. |
| 62 |
OPENSSL_EXPORT int CMAC_Final(CMAC_CTX *ctx, uint8_t *out, size_t *out_len); |
| 63 |
|
| 64 |
|
| 65 |
// Deprecated functions. |
| 66 |
|
| 67 |
// CMAC_CTX_get0_cipher_ctx returns a pointer to the |EVP_CIPHER_CTX| from |ctx|. |
| 68 |
OPENSSL_EXPORT EVP_CIPHER_CTX *CMAC_CTX_get0_cipher_ctx(CMAC_CTX *ctx); |
| 69 |
|
| 70 |
|
| 71 |
#if defined(__cplusplus) |
| 72 |
} // extern C |
| 73 |
|
| 74 |
extern "C++" { |
| 75 |
|
| 76 |
BSSL_NAMESPACE_BEGIN |
| 77 |
|
| 78 |
BORINGSSL_MAKE_DELETER(CMAC_CTX, CMAC_CTX_free) |
| 79 |
|
| 80 |
BSSL_NAMESPACE_END |
| 81 |
|
| 82 |
} // extern C++ |
| 83 |
|
| 84 |
#endif |
| 85 |
|
| 86 |
#endif // OPENSSL_HEADER_CMAC_H |