2015-05-06 00:36:32 +01:00
|
|
|
/* Copyright (c) 2015, Google Inc.
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
|
|
|
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
|
|
|
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
|
|
|
|
|
|
|
#ifndef OPENSSL_HEADER_CMAC_H
|
|
|
|
#define OPENSSL_HEADER_CMAC_H
|
|
|
|
|
|
|
|
#include <openssl/base.h>
|
|
|
|
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// CMAC.
|
|
|
|
//
|
|
|
|
// CMAC is a MAC based on AES-CBC and defined in
|
|
|
|
// https://tools.ietf.org/html/rfc4493#section-2.3.
|
2015-05-06 00:36:32 +01:00
|
|
|
|
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// One-shot functions.
|
2015-05-06 00:36:32 +01:00
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// 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.
|
2015-05-06 00:36:32 +01:00
|
|
|
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);
|
|
|
|
|
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// Incremental interface.
|
2015-05-06 00:36:32 +01:00
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// CMAC_CTX_new allocates a fresh |CMAC_CTX| and returns it, or NULL on
|
|
|
|
// error.
|
2015-05-06 00:36:32 +01:00
|
|
|
OPENSSL_EXPORT CMAC_CTX *CMAC_CTX_new(void);
|
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// CMAC_CTX_free frees a |CMAC_CTX|.
|
2015-05-06 00:36:32 +01:00
|
|
|
OPENSSL_EXPORT void CMAC_CTX_free(CMAC_CTX *ctx);
|
|
|
|
|
2018-05-08 21:07:00 +01:00
|
|
|
// 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);
|
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// 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.
|
2015-05-06 00:36:32 +01:00
|
|
|
OPENSSL_EXPORT int CMAC_Init(CMAC_CTX *ctx, const void *key, size_t key_len,
|
|
|
|
const EVP_CIPHER *cipher, ENGINE *engine);
|
|
|
|
|
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// CMAC_Reset resets |ctx| so that a fresh message can be authenticated.
|
2015-05-06 00:36:32 +01:00
|
|
|
OPENSSL_EXPORT int CMAC_Reset(CMAC_CTX *ctx);
|
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// CMAC_Update processes |in_len| bytes of message from |in|. It returns one on
|
|
|
|
// success or zero on error.
|
2015-05-06 00:36:32 +01:00
|
|
|
OPENSSL_EXPORT int CMAC_Update(CMAC_CTX *ctx, const uint8_t *in, size_t in_len);
|
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// 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.
|
2015-05-06 00:36:32 +01:00
|
|
|
OPENSSL_EXPORT int CMAC_Final(CMAC_CTX *ctx, uint8_t *out, size_t *out_len);
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(__cplusplus)
|
2017-08-19 00:21:50 +01:00
|
|
|
} // extern C
|
2016-08-18 04:10:28 +01:00
|
|
|
|
|
|
|
extern "C++" {
|
|
|
|
|
Support symbol prefixes
- In base.h, if BORINGSSL_PREFIX is defined, include
boringssl_prefix_symbols.h
- In all .S files, if BORINGSSL_PREFIX is defined, include
boringssl_prefix_symbols_asm.h
- In base.h, BSSL_NAMESPACE_BEGIN and BSSL_NAMESPACE_END are
defined with appropriate values depending on whether
BORINGSSL_PREFIX is defined; these macros are used in place
of 'namespace bssl {' and '}'
- Add util/make_prefix_headers.go, which takes a list of symbols
and auto-generates the header files mentioned above
- In CMakeLists.txt, if BORINGSSL_PREFIX and BORINGSSL_PREFIX_SYMBOLS
are defined, run util/make_prefix_headers.go to generate header
files
- In various CMakeLists.txt files, add "global_target" that all
targets depend on to give us a place to hook logic that must run
before all other targets (in particular, the header file generation
logic)
- Document this in BUILDING.md, including the fact that it is
the caller's responsibility to provide the symbol list and keep it
up to date
- Note that this scheme has not been tested on Windows, and likely
does not work on it; Windows support will need to be added in a
future commit
Change-Id: If66a7157f46b5b66230ef91e15826b910cf979a2
Reviewed-on: https://boringssl-review.googlesource.com/31364
Commit-Queue: David Benjamin <davidben@google.com>
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
Reviewed-by: David Benjamin <davidben@google.com>
2018-08-27 02:53:36 +01:00
|
|
|
BSSL_NAMESPACE_BEGIN
|
2016-08-18 04:10:28 +01:00
|
|
|
|
|
|
|
BORINGSSL_MAKE_DELETER(CMAC_CTX, CMAC_CTX_free)
|
|
|
|
|
Support symbol prefixes
- In base.h, if BORINGSSL_PREFIX is defined, include
boringssl_prefix_symbols.h
- In all .S files, if BORINGSSL_PREFIX is defined, include
boringssl_prefix_symbols_asm.h
- In base.h, BSSL_NAMESPACE_BEGIN and BSSL_NAMESPACE_END are
defined with appropriate values depending on whether
BORINGSSL_PREFIX is defined; these macros are used in place
of 'namespace bssl {' and '}'
- Add util/make_prefix_headers.go, which takes a list of symbols
and auto-generates the header files mentioned above
- In CMakeLists.txt, if BORINGSSL_PREFIX and BORINGSSL_PREFIX_SYMBOLS
are defined, run util/make_prefix_headers.go to generate header
files
- In various CMakeLists.txt files, add "global_target" that all
targets depend on to give us a place to hook logic that must run
before all other targets (in particular, the header file generation
logic)
- Document this in BUILDING.md, including the fact that it is
the caller's responsibility to provide the symbol list and keep it
up to date
- Note that this scheme has not been tested on Windows, and likely
does not work on it; Windows support will need to be added in a
future commit
Change-Id: If66a7157f46b5b66230ef91e15826b910cf979a2
Reviewed-on: https://boringssl-review.googlesource.com/31364
Commit-Queue: David Benjamin <davidben@google.com>
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
Reviewed-by: David Benjamin <davidben@google.com>
2018-08-27 02:53:36 +01:00
|
|
|
BSSL_NAMESPACE_END
|
2016-08-18 04:10:28 +01:00
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
} // extern C++
|
2016-08-18 04:10:28 +01:00
|
|
|
|
2015-05-06 00:36:32 +01:00
|
|
|
#endif
|
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
#endif // OPENSSL_HEADER_CMAC_H
|