1e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley/* Copyright (c) 2015, Google Inc.
2e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley *
3e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley * Permission to use, copy, modify, and/or distribute this software for any
4e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley * purpose with or without fee is hereby granted, provided that the above
5e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley * copyright notice and this permission notice appear in all copies.
6e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley *
7e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley
15e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley#ifndef OPENSSL_HEADER_CMAC_H
16e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley#define OPENSSL_HEADER_CMAC_H
17e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley
18e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley#include <openssl/base.h>
19e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley
20e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley#if defined(__cplusplus)
21e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langleyextern "C" {
22e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley#endif
23e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley
24e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley
25e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley/* CMAC.
26e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley *
27e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley * CMAC is a MAC based on AES-CBC and defined in
28e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley * https://tools.ietf.org/html/rfc4493#section-2.3. */
29e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley
30e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley
31e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley/* One-shot functions. */
32e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley
33e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley/* AES_CMAC calculates the 16-byte, CMAC authenticator of |in_len| bytes of
34e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley * |in| and writes it to |out|. The |key_len| may be 16 or 32 bytes to select
35e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley * between AES-128 and AES-256. It returns one on success or zero on error. */
36e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam LangleyOPENSSL_EXPORT int AES_CMAC(uint8_t out[16], const uint8_t *key, size_t key_len,
37e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley                            const uint8_t *in, size_t in_len);
38e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley
39e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley
40e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley/* Incremental interface. */
41e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley
42e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley/* CMAC_CTX_new allocates a fresh |CMAC_CTX| and returns it, or NULL on
43e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley * error. */
44e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam LangleyOPENSSL_EXPORT CMAC_CTX *CMAC_CTX_new(void);
45e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley
46e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley/* CMAC_CTX_free frees a |CMAC_CTX|. */
47e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam LangleyOPENSSL_EXPORT void CMAC_CTX_free(CMAC_CTX *ctx);
48e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley
49e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley/* CMAC_Init configures |ctx| to use the given |key| and |cipher|. The CMAC RFC
50e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley * only specifies the use of AES-128 thus |key_len| should be 16 and |cipher|
51e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley * should be |EVP_aes_128_cbc()|. However, this implementation also supports
52e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley * AES-256 by setting |key_len| to 32 and |cipher| to |EVP_aes_256_cbc()|. The
53e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley * |engine| argument is ignored.
54e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley *
55e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley * It returns one on success or zero on error. */
56e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam LangleyOPENSSL_EXPORT int CMAC_Init(CMAC_CTX *ctx, const void *key, size_t key_len,
57e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley                             const EVP_CIPHER *cipher, ENGINE *engine);
58e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley
59e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley
60e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley/* CMAC_Reset resets |ctx| so that a fresh message can be authenticated. */
61e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam LangleyOPENSSL_EXPORT int CMAC_Reset(CMAC_CTX *ctx);
62e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley
63e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley/* CMAC_Update processes |in_len| bytes of message from |in|. It returns one on
64e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley * success or zero on error. */
65e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam LangleyOPENSSL_EXPORT int CMAC_Update(CMAC_CTX *ctx, const uint8_t *in, size_t in_len);
66e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley
67e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley/* CMAC_Final sets |*out_len| to 16 and, if |out| is not NULL, writes 16 bytes
68e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley * of authenticator to it. It returns one on success or zero on error. */
69e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam LangleyOPENSSL_EXPORT int CMAC_Final(CMAC_CTX *ctx, uint8_t *out, size_t *out_len);
70e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley
71e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley
72e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley#if defined(__cplusplus)
73e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley}  /* extern C */
74e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley#endif
75e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley
76e99801b603dea8893dcc61c70b327ef2d00b652cKenny Root#endif  /* OPENSSL_HEADER_CMAC_H */
77