This reflects some assumptions we have on our headers: - <openssl/foo.h> pulls in <openssl/base.h>. In particular, the canonical FOO typedefs for foo_st all live forward declared in <opessl/base.h>, but including <openssl/foo.h> is sufficient to use FOO. - <openssl/base.h> pulls in <stdint.h> and <stddef.h> so we don't have to keep including it. Add IWYU exports to reflect this so that clang's include cleaner gets less upset. It's a bit of a blunt instrument because it also means that <openssl/foo.h> lets you use the forward-declared BAR typedef, and downstream projects might still prefer to explicit include <stdint.h> when they use it (we use it so much that it would be too much), but I think this is fine. NB: By adding these, we're essentially promising we won't include those transitive includes because downstream code might accidentally start relying on it. Change-Id: I705fe6d1026fbd302ed0f070a0cf7658a70af8ef Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/77687 Reviewed-by: Bob Beck <bbe@google.com> Commit-Queue: David Benjamin <davidben@google.com>
92 lines
2.9 KiB
C
92 lines
2.9 KiB
C
// Copyright 2015 The BoringSSL Authors
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// https://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
#ifndef OPENSSL_HEADER_CMAC_H
|
|
#define OPENSSL_HEADER_CMAC_H
|
|
|
|
#include <openssl/base.h> // IWYU pragma: export
|
|
|
|
#if defined(__cplusplus)
|
|
extern "C" {
|
|
#endif
|
|
|
|
|
|
// CMAC.
|
|
//
|
|
// CMAC is a MAC based on AES-CBC and defined in
|
|
// https://tools.ietf.org/html/rfc4493#section-2.3.
|
|
|
|
|
|
// One-shot functions.
|
|
|
|
// AES_CMAC calculates the 16-byte, CMAC authenticator of |in_len| bytes of
|
|
// |in| and writes it to |out|. The |key_len| may be 16 or 32 bytes to select
|
|
// between AES-128 and AES-256. It returns one on success or zero on error.
|
|
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);
|
|
|
|
|
|
// Incremental interface.
|
|
|
|
// CMAC_CTX_new allocates a fresh |CMAC_CTX| and returns it, or NULL on
|
|
// error.
|
|
OPENSSL_EXPORT CMAC_CTX *CMAC_CTX_new(void);
|
|
|
|
// CMAC_CTX_free frees a |CMAC_CTX|.
|
|
OPENSSL_EXPORT void CMAC_CTX_free(CMAC_CTX *ctx);
|
|
|
|
// CMAC_CTX_copy sets |out| to be a duplicate of the current state |in|. It
|
|
// returns one on success and zero on error.
|
|
OPENSSL_EXPORT int CMAC_CTX_copy(CMAC_CTX *out, const CMAC_CTX *in);
|
|
|
|
// CMAC_Init configures |ctx| to use the given |key| and |cipher|. The CMAC RFC
|
|
// only specifies the use of AES-128 thus |key_len| should be 16 and |cipher|
|
|
// should be |EVP_aes_128_cbc()|. However, this implementation also supports
|
|
// AES-256 by setting |key_len| to 32 and |cipher| to |EVP_aes_256_cbc()|. The
|
|
// |engine| argument is ignored.
|
|
//
|
|
// It returns one on success or zero on error.
|
|
OPENSSL_EXPORT int CMAC_Init(CMAC_CTX *ctx, const void *key, size_t key_len,
|
|
const EVP_CIPHER *cipher, ENGINE *engine);
|
|
|
|
|
|
// CMAC_Reset resets |ctx| so that a fresh message can be authenticated.
|
|
OPENSSL_EXPORT int CMAC_Reset(CMAC_CTX *ctx);
|
|
|
|
// CMAC_Update processes |in_len| bytes of message from |in|. It returns one on
|
|
// success or zero on error.
|
|
OPENSSL_EXPORT int CMAC_Update(CMAC_CTX *ctx, const uint8_t *in, size_t in_len);
|
|
|
|
// CMAC_Final sets |*out_len| to 16 and, if |out| is not NULL, writes 16 bytes
|
|
// of authenticator to it. It returns one on success or zero on error.
|
|
OPENSSL_EXPORT int CMAC_Final(CMAC_CTX *ctx, uint8_t *out, size_t *out_len);
|
|
|
|
|
|
#if defined(__cplusplus)
|
|
} // extern C
|
|
|
|
extern "C++" {
|
|
|
|
BSSL_NAMESPACE_BEGIN
|
|
|
|
BORINGSSL_MAKE_DELETER(CMAC_CTX, CMAC_CTX_free)
|
|
|
|
BSSL_NAMESPACE_END
|
|
|
|
} // extern C++
|
|
|
|
#endif
|
|
|
|
#endif // OPENSSL_HEADER_CMAC_H
|