cmac.h
Go to the documentation of this file.
1 /* Copyright (c) 2015, Google Inc.
2  *
3  * Permission to use, copy, modify, and/or distribute this software for any
4  * purpose with or without fee is hereby granted, provided that the above
5  * copyright notice and this permission notice appear in all copies.
6  *
7  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14 
15 #ifndef OPENSSL_HEADER_CMAC_H
16 #define OPENSSL_HEADER_CMAC_H
17 
18 #include <openssl/base.h>
19 
20 #if defined(__cplusplus)
21 extern "C" {
22 #endif
23 
24 
25 // CMAC.
26 //
27 // CMAC is a MAC based on AES-CBC and defined in
28 // https://tools.ietf.org/html/rfc4493#section-2.3.
29 
30 
31 // One-shot functions.
32 
33 // AES_CMAC calculates the 16-byte, CMAC authenticator of |in_len| bytes of
34 // |in| and writes it to |out|. The |key_len| may be 16 or 32 bytes to select
35 // between AES-128 and AES-256. It returns one on success or zero on error.
36 OPENSSL_EXPORT int AES_CMAC(uint8_t out[16], const uint8_t *key, size_t key_len,
37  const uint8_t *in, size_t in_len);
38 
39 
40 // Incremental interface.
41 
42 // CMAC_CTX_new allocates a fresh |CMAC_CTX| and returns it, or NULL on
43 // error.
45 
46 // CMAC_CTX_free frees a |CMAC_CTX|.
48 
49 // CMAC_CTX_copy sets |out| to be a duplicate of the current state |in|. It
50 // returns one on success and zero on error.
52 
53 // CMAC_Init configures |ctx| to use the given |key| and |cipher|. The CMAC RFC
54 // only specifies the use of AES-128 thus |key_len| should be 16 and |cipher|
55 // should be |EVP_aes_128_cbc()|. However, this implementation also supports
56 // AES-256 by setting |key_len| to 32 and |cipher| to |EVP_aes_256_cbc()|. The
57 // |engine| argument is ignored.
58 //
59 // It returns one on success or zero on error.
60 OPENSSL_EXPORT int CMAC_Init(CMAC_CTX *ctx, const void *key, size_t key_len,
61  const EVP_CIPHER *cipher, ENGINE *engine);
62 
63 
64 // CMAC_Reset resets |ctx| so that a fresh message can be authenticated.
66 
67 // CMAC_Update processes |in_len| bytes of message from |in|. It returns one on
68 // success or zero on error.
69 OPENSSL_EXPORT int CMAC_Update(CMAC_CTX *ctx, const uint8_t *in, size_t in_len);
70 
71 // CMAC_Final sets |*out_len| to 16 and, if |out| is not NULL, writes 16 bytes
72 // of authenticator to it. It returns one on success or zero on error.
73 OPENSSL_EXPORT int CMAC_Final(CMAC_CTX *ctx, uint8_t *out, size_t *out_len);
74 
75 
76 #if defined(__cplusplus)
77 } // extern C
78 
79 extern "C++" {
80 
82 
84 
86 
87 } // extern C++
88 
89 #endif
90 
91 #endif // OPENSSL_HEADER_CMAC_H
CMAC_Reset
OPENSSL_EXPORT int CMAC_Reset(CMAC_CTX *ctx)
Definition: cmac.c:200
gen_build_yaml.out
dictionary out
Definition: src/benchmark/gen_build_yaml.py:24
ctx
Definition: benchmark-async.c:30
CMAC_CTX_free
OPENSSL_EXPORT void CMAC_CTX_free(CMAC_CTX *ctx)
Definition: cmac.c:118
CMAC_CTX_copy
OPENSSL_EXPORT int CMAC_CTX_copy(CMAC_CTX *out, const CMAC_CTX *in)
Definition: cmac.c:127
uint8_t
unsigned char uint8_t
Definition: stdint-msvc2008.h:78
CMAC_Final
OPENSSL_EXPORT int CMAC_Final(CMAC_CTX *ctx, uint8_t *out, size_t *out_len)
Definition: cmac.c:252
base.h
in
const char * in
Definition: third_party/abseil-cpp/absl/strings/internal/str_format/parser_test.cc:391
evp_cipher_st
Definition: cipher.h:585
BSSL_NAMESPACE_END
#define BSSL_NAMESPACE_END
Definition: base.h:480
CMAC_Update
OPENSSL_EXPORT int CMAC_Update(CMAC_CTX *ctx, const uint8_t *in, size_t in_len)
Definition: cmac.c:205
cmac_ctx_st
Definition: cmac.c:61
CMAC_CTX_new
OPENSSL_EXPORT CMAC_CTX * CMAC_CTX_new(void)
Definition: cmac.c:110
BSSL_NAMESPACE_BEGIN
Definition: trust_token_test.cc:45
AES_CMAC
OPENSSL_EXPORT int AES_CMAC(uint8_t out[16], const uint8_t *key, size_t key_len, const uint8_t *in, size_t in_len)
Definition: cmac.c:84
key
const char * key
Definition: hpack_parser_table.cc:164
OPENSSL_EXPORT
#define OPENSSL_EXPORT
Definition: base.h:222
BORINGSSL_MAKE_DELETER
#define BORINGSSL_MAKE_DELETER(type, deleter)
Definition: base.h:506
CMAC_Init
OPENSSL_EXPORT int CMAC_Init(CMAC_CTX *ctx, const void *key, size_t key_len, const EVP_CIPHER *cipher, ENGINE *engine)
Definition: cmac.c:174
engine_st
Definition: engine.c:29


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:58:48