License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 15:07:57 +01:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2007-10-09 22:43:13 +08:00
|
|
|
/*
|
2020-11-12 21:20:21 -08:00
|
|
|
* Common values for SHA-2 algorithms
|
2007-10-09 22:43:13 +08:00
|
|
|
*/
|
|
|
|
|
2020-11-12 21:20:21 -08:00
|
|
|
#ifndef _CRYPTO_SHA2_H
|
|
|
|
#define _CRYPTO_SHA2_H
|
2007-10-09 22:43:13 +08:00
|
|
|
|
2009-07-09 21:27:13 +08:00
|
|
|
#include <linux/types.h>
|
|
|
|
|
2007-11-10 20:08:25 +08:00
|
|
|
#define SHA224_DIGEST_SIZE 28
|
|
|
|
#define SHA224_BLOCK_SIZE 64
|
|
|
|
|
2007-10-09 22:43:13 +08:00
|
|
|
#define SHA256_DIGEST_SIZE 32
|
|
|
|
#define SHA256_BLOCK_SIZE 64
|
2025-04-28 10:00:26 -07:00
|
|
|
#define SHA256_STATE_WORDS 8
|
2007-10-09 22:43:13 +08:00
|
|
|
|
|
|
|
#define SHA384_DIGEST_SIZE 48
|
|
|
|
#define SHA384_BLOCK_SIZE 128
|
|
|
|
|
|
|
|
#define SHA512_DIGEST_SIZE 64
|
|
|
|
#define SHA512_BLOCK_SIZE 128
|
2025-04-18 11:00:20 +08:00
|
|
|
#define SHA512_STATE_SIZE 80
|
2007-10-09 22:43:13 +08:00
|
|
|
|
2007-11-10 20:08:25 +08:00
|
|
|
#define SHA224_H0 0xc1059ed8UL
|
|
|
|
#define SHA224_H1 0x367cd507UL
|
|
|
|
#define SHA224_H2 0x3070dd17UL
|
|
|
|
#define SHA224_H3 0xf70e5939UL
|
|
|
|
#define SHA224_H4 0xffc00b31UL
|
|
|
|
#define SHA224_H5 0x68581511UL
|
|
|
|
#define SHA224_H6 0x64f98fa7UL
|
|
|
|
#define SHA224_H7 0xbefa4fa4UL
|
|
|
|
|
2007-10-09 22:43:13 +08:00
|
|
|
#define SHA256_H0 0x6a09e667UL
|
|
|
|
#define SHA256_H1 0xbb67ae85UL
|
|
|
|
#define SHA256_H2 0x3c6ef372UL
|
|
|
|
#define SHA256_H3 0xa54ff53aUL
|
|
|
|
#define SHA256_H4 0x510e527fUL
|
|
|
|
#define SHA256_H5 0x9b05688cUL
|
|
|
|
#define SHA256_H6 0x1f83d9abUL
|
|
|
|
#define SHA256_H7 0x5be0cd19UL
|
|
|
|
|
|
|
|
#define SHA384_H0 0xcbbb9d5dc1059ed8ULL
|
|
|
|
#define SHA384_H1 0x629a292a367cd507ULL
|
|
|
|
#define SHA384_H2 0x9159015a3070dd17ULL
|
|
|
|
#define SHA384_H3 0x152fecd8f70e5939ULL
|
|
|
|
#define SHA384_H4 0x67332667ffc00b31ULL
|
|
|
|
#define SHA384_H5 0x8eb44a8768581511ULL
|
|
|
|
#define SHA384_H6 0xdb0c2e0d64f98fa7ULL
|
|
|
|
#define SHA384_H7 0x47b5481dbefa4fa4ULL
|
|
|
|
|
|
|
|
#define SHA512_H0 0x6a09e667f3bcc908ULL
|
|
|
|
#define SHA512_H1 0xbb67ae8584caa73bULL
|
|
|
|
#define SHA512_H2 0x3c6ef372fe94f82bULL
|
|
|
|
#define SHA512_H3 0xa54ff53a5f1d36f1ULL
|
|
|
|
#define SHA512_H4 0x510e527fade682d1ULL
|
|
|
|
#define SHA512_H5 0x9b05688c2b3e6c1fULL
|
|
|
|
#define SHA512_H6 0x1f83d9abfb41bd6bULL
|
|
|
|
#define SHA512_H7 0x5be0cd19137e2179ULL
|
|
|
|
|
2015-12-17 13:45:39 +01:00
|
|
|
extern const u8 sha224_zero_message_hash[SHA224_DIGEST_SIZE];
|
|
|
|
|
|
|
|
extern const u8 sha256_zero_message_hash[SHA256_DIGEST_SIZE];
|
|
|
|
|
2018-05-29 14:13:49 +02:00
|
|
|
extern const u8 sha384_zero_message_hash[SHA384_DIGEST_SIZE];
|
|
|
|
|
2018-05-29 14:13:45 +02:00
|
|
|
extern const u8 sha512_zero_message_hash[SHA512_DIGEST_SIZE];
|
|
|
|
|
2025-04-18 10:59:41 +08:00
|
|
|
struct crypto_sha256_state {
|
2025-04-28 10:00:26 -07:00
|
|
|
u32 state[SHA256_STATE_WORDS];
|
2025-04-18 10:59:41 +08:00
|
|
|
u64 count;
|
|
|
|
};
|
|
|
|
|
2025-06-30 09:06:34 -07:00
|
|
|
static inline void sha224_block_init(struct crypto_sha256_state *sctx)
|
|
|
|
{
|
|
|
|
sctx->state[0] = SHA224_H0;
|
|
|
|
sctx->state[1] = SHA224_H1;
|
|
|
|
sctx->state[2] = SHA224_H2;
|
|
|
|
sctx->state[3] = SHA224_H3;
|
|
|
|
sctx->state[4] = SHA224_H4;
|
|
|
|
sctx->state[5] = SHA224_H5;
|
|
|
|
sctx->state[6] = SHA224_H6;
|
|
|
|
sctx->state[7] = SHA224_H7;
|
|
|
|
sctx->count = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void sha256_block_init(struct crypto_sha256_state *sctx)
|
|
|
|
{
|
|
|
|
sctx->state[0] = SHA256_H0;
|
|
|
|
sctx->state[1] = SHA256_H1;
|
|
|
|
sctx->state[2] = SHA256_H2;
|
|
|
|
sctx->state[3] = SHA256_H3;
|
|
|
|
sctx->state[4] = SHA256_H4;
|
|
|
|
sctx->state[5] = SHA256_H5;
|
|
|
|
sctx->state[6] = SHA256_H6;
|
|
|
|
sctx->state[7] = SHA256_H7;
|
|
|
|
sctx->count = 0;
|
|
|
|
}
|
|
|
|
|
2009-07-10 13:00:27 +08:00
|
|
|
struct sha256_state {
|
2025-04-28 12:56:05 +08:00
|
|
|
union {
|
|
|
|
struct crypto_sha256_state ctx;
|
|
|
|
struct {
|
2025-04-28 10:00:26 -07:00
|
|
|
u32 state[SHA256_STATE_WORDS];
|
2025-04-28 12:56:05 +08:00
|
|
|
u64 count;
|
|
|
|
};
|
|
|
|
};
|
2009-07-10 13:00:27 +08:00
|
|
|
u8 buf[SHA256_BLOCK_SIZE];
|
|
|
|
};
|
|
|
|
|
2009-07-22 11:48:18 +08:00
|
|
|
struct sha512_state {
|
2009-07-22 12:22:43 +08:00
|
|
|
u64 state[SHA512_DIGEST_SIZE / 8];
|
2015-04-09 12:55:35 +02:00
|
|
|
u64 count[2];
|
2009-07-22 12:22:43 +08:00
|
|
|
u8 buf[SHA512_BLOCK_SIZE];
|
2009-07-22 11:48:18 +08:00
|
|
|
};
|
|
|
|
|
2025-06-30 09:06:37 -07:00
|
|
|
/* State for the SHA-256 (and SHA-224) compression function */
|
|
|
|
struct sha256_block_state {
|
|
|
|
u32 h[SHA256_STATE_WORDS];
|
|
|
|
};
|
2025-06-30 09:06:36 -07:00
|
|
|
|
2025-06-30 09:06:37 -07:00
|
|
|
/*
|
|
|
|
* Context structure, shared by SHA-224 and SHA-256. The sha224_ctx and
|
|
|
|
* sha256_ctx structs wrap this one so that the API has proper typing and
|
|
|
|
* doesn't allow mixing the SHA-224 and SHA-256 functions arbitrarily.
|
|
|
|
*/
|
|
|
|
struct __sha256_ctx {
|
|
|
|
struct sha256_block_state state;
|
|
|
|
u64 bytecount;
|
|
|
|
u8 buf[SHA256_BLOCK_SIZE] __aligned(__alignof__(__be64));
|
|
|
|
};
|
|
|
|
void __sha256_update(struct __sha256_ctx *ctx, const u8 *data, size_t len);
|
|
|
|
|
2025-06-30 09:06:39 -07:00
|
|
|
/*
|
|
|
|
* HMAC key and message context structs, shared by HMAC-SHA224 and HMAC-SHA256.
|
|
|
|
* The hmac_sha224_* and hmac_sha256_* structs wrap this one so that the API has
|
|
|
|
* proper typing and doesn't allow mixing the functions arbitrarily.
|
|
|
|
*/
|
|
|
|
struct __hmac_sha256_key {
|
|
|
|
struct sha256_block_state istate;
|
|
|
|
struct sha256_block_state ostate;
|
|
|
|
};
|
|
|
|
struct __hmac_sha256_ctx {
|
|
|
|
struct __sha256_ctx sha_ctx;
|
|
|
|
struct sha256_block_state ostate;
|
|
|
|
};
|
|
|
|
void __hmac_sha256_init(struct __hmac_sha256_ctx *ctx,
|
|
|
|
const struct __hmac_sha256_key *key);
|
|
|
|
|
2025-06-30 09:06:37 -07:00
|
|
|
/**
|
|
|
|
* struct sha224_ctx - Context for hashing a message with SHA-224
|
|
|
|
* @ctx: private
|
|
|
|
*/
|
|
|
|
struct sha224_ctx {
|
|
|
|
struct __sha256_ctx ctx;
|
|
|
|
};
|
|
|
|
|
2025-06-30 09:06:45 -07:00
|
|
|
/**
|
|
|
|
* sha224_init() - Initialize a SHA-224 context for a new message
|
|
|
|
* @ctx: the context to initialize
|
|
|
|
*
|
|
|
|
* If you don't need incremental computation, consider sha224() instead.
|
|
|
|
*
|
|
|
|
* Context: Any context.
|
|
|
|
*/
|
2025-06-30 09:06:37 -07:00
|
|
|
void sha224_init(struct sha224_ctx *ctx);
|
2025-06-30 09:06:45 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* sha224_update() - Update a SHA-224 context with message data
|
|
|
|
* @ctx: the context to update; must have been initialized
|
|
|
|
* @data: the message data
|
|
|
|
* @len: the data length in bytes
|
|
|
|
*
|
|
|
|
* This can be called any number of times.
|
|
|
|
*
|
|
|
|
* Context: Any context.
|
|
|
|
*/
|
2025-06-30 09:06:37 -07:00
|
|
|
static inline void sha224_update(struct sha224_ctx *ctx,
|
2025-06-30 09:06:36 -07:00
|
|
|
const u8 *data, size_t len)
|
|
|
|
{
|
2025-06-30 09:06:37 -07:00
|
|
|
__sha256_update(&ctx->ctx, data, len);
|
2025-06-30 09:06:36 -07:00
|
|
|
}
|
2025-06-30 09:06:45 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* sha224_final() - Finish computing a SHA-224 message digest
|
|
|
|
* @ctx: the context to finalize; must have been initialized
|
|
|
|
* @out: (output) the resulting SHA-224 message digest
|
|
|
|
*
|
|
|
|
* After finishing, this zeroizes @ctx. So the caller does not need to do it.
|
|
|
|
*
|
|
|
|
* Context: Any context.
|
|
|
|
*/
|
2025-06-30 09:06:37 -07:00
|
|
|
void sha224_final(struct sha224_ctx *ctx, u8 out[SHA224_DIGEST_SIZE]);
|
2025-06-30 09:06:45 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* sha224() - Compute SHA-224 message digest in one shot
|
|
|
|
* @data: the message data
|
|
|
|
* @len: the data length in bytes
|
|
|
|
* @out: (output) the resulting SHA-224 message digest
|
|
|
|
*
|
|
|
|
* Context: Any context.
|
|
|
|
*/
|
2025-06-30 09:06:36 -07:00
|
|
|
void sha224(const u8 *data, size_t len, u8 out[SHA224_DIGEST_SIZE]);
|
2025-05-02 13:30:56 +08:00
|
|
|
|
2025-06-30 09:06:39 -07:00
|
|
|
/**
|
|
|
|
* struct hmac_sha224_key - Prepared key for HMAC-SHA224
|
|
|
|
* @key: private
|
|
|
|
*/
|
|
|
|
struct hmac_sha224_key {
|
|
|
|
struct __hmac_sha256_key key;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct hmac_sha224_ctx - Context for computing HMAC-SHA224 of a message
|
|
|
|
* @ctx: private
|
|
|
|
*/
|
|
|
|
struct hmac_sha224_ctx {
|
|
|
|
struct __hmac_sha256_ctx ctx;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hmac_sha224_preparekey() - Prepare a key for HMAC-SHA224
|
|
|
|
* @key: (output) the key structure to initialize
|
|
|
|
* @raw_key: the raw HMAC-SHA224 key
|
|
|
|
* @raw_key_len: the key length in bytes. All key lengths are supported.
|
|
|
|
*
|
|
|
|
* Note: the caller is responsible for zeroizing both the struct hmac_sha224_key
|
|
|
|
* and the raw key once they are no longer needed.
|
|
|
|
*
|
|
|
|
* Context: Any context.
|
|
|
|
*/
|
|
|
|
void hmac_sha224_preparekey(struct hmac_sha224_key *key,
|
|
|
|
const u8 *raw_key, size_t raw_key_len);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hmac_sha224_init() - Initialize an HMAC-SHA224 context for a new message
|
|
|
|
* @ctx: (output) the HMAC context to initialize
|
|
|
|
* @key: the prepared HMAC key
|
|
|
|
*
|
|
|
|
* If you don't need incremental computation, consider hmac_sha224() instead.
|
|
|
|
*
|
|
|
|
* Context: Any context.
|
|
|
|
*/
|
|
|
|
static inline void hmac_sha224_init(struct hmac_sha224_ctx *ctx,
|
|
|
|
const struct hmac_sha224_key *key)
|
|
|
|
{
|
|
|
|
__hmac_sha256_init(&ctx->ctx, &key->key);
|
|
|
|
}
|
|
|
|
|
2025-07-11 14:58:43 -07:00
|
|
|
/**
|
|
|
|
* hmac_sha224_init_usingrawkey() - Initialize an HMAC-SHA224 context for a new
|
|
|
|
* message, using a raw key
|
|
|
|
* @ctx: (output) the HMAC context to initialize
|
|
|
|
* @raw_key: the raw HMAC-SHA224 key
|
|
|
|
* @raw_key_len: the key length in bytes. All key lengths are supported.
|
|
|
|
*
|
|
|
|
* If you don't need incremental computation, consider hmac_sha224_usingrawkey()
|
|
|
|
* instead.
|
|
|
|
*
|
|
|
|
* Context: Any context.
|
|
|
|
*/
|
|
|
|
void hmac_sha224_init_usingrawkey(struct hmac_sha224_ctx *ctx,
|
|
|
|
const u8 *raw_key, size_t raw_key_len);
|
|
|
|
|
2025-06-30 09:06:39 -07:00
|
|
|
/**
|
|
|
|
* hmac_sha224_update() - Update an HMAC-SHA224 context with message data
|
|
|
|
* @ctx: the HMAC context to update; must have been initialized
|
|
|
|
* @data: the message data
|
|
|
|
* @data_len: the data length in bytes
|
|
|
|
*
|
|
|
|
* This can be called any number of times.
|
|
|
|
*
|
|
|
|
* Context: Any context.
|
|
|
|
*/
|
|
|
|
static inline void hmac_sha224_update(struct hmac_sha224_ctx *ctx,
|
|
|
|
const u8 *data, size_t data_len)
|
|
|
|
{
|
|
|
|
__sha256_update(&ctx->ctx.sha_ctx, data, data_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hmac_sha224_final() - Finish computing an HMAC-SHA224 value
|
|
|
|
* @ctx: the HMAC context to finalize; must have been initialized
|
|
|
|
* @out: (output) the resulting HMAC-SHA224 value
|
|
|
|
*
|
|
|
|
* After finishing, this zeroizes @ctx. So the caller does not need to do it.
|
|
|
|
*
|
|
|
|
* Context: Any context.
|
|
|
|
*/
|
|
|
|
void hmac_sha224_final(struct hmac_sha224_ctx *ctx, u8 out[SHA224_DIGEST_SIZE]);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hmac_sha224() - Compute HMAC-SHA224 in one shot, using a prepared key
|
|
|
|
* @key: the prepared HMAC key
|
|
|
|
* @data: the message data
|
|
|
|
* @data_len: the data length in bytes
|
|
|
|
* @out: (output) the resulting HMAC-SHA224 value
|
|
|
|
*
|
|
|
|
* If you're using the key only once, consider using hmac_sha224_usingrawkey().
|
|
|
|
*
|
|
|
|
* Context: Any context.
|
|
|
|
*/
|
|
|
|
void hmac_sha224(const struct hmac_sha224_key *key,
|
|
|
|
const u8 *data, size_t data_len, u8 out[SHA224_DIGEST_SIZE]);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hmac_sha224_usingrawkey() - Compute HMAC-SHA224 in one shot, using a raw key
|
|
|
|
* @raw_key: the raw HMAC-SHA224 key
|
|
|
|
* @raw_key_len: the key length in bytes. All key lengths are supported.
|
|
|
|
* @data: the message data
|
|
|
|
* @data_len: the data length in bytes
|
|
|
|
* @out: (output) the resulting HMAC-SHA224 value
|
|
|
|
*
|
|
|
|
* If you're using the key multiple times, prefer to use
|
|
|
|
* hmac_sha224_preparekey() followed by multiple calls to hmac_sha224() instead.
|
|
|
|
*
|
|
|
|
* Context: Any context.
|
|
|
|
*/
|
|
|
|
void hmac_sha224_usingrawkey(const u8 *raw_key, size_t raw_key_len,
|
|
|
|
const u8 *data, size_t data_len,
|
|
|
|
u8 out[SHA224_DIGEST_SIZE]);
|
|
|
|
|
2025-06-30 09:06:37 -07:00
|
|
|
/**
|
|
|
|
* struct sha256_ctx - Context for hashing a message with SHA-256
|
|
|
|
* @ctx: private
|
|
|
|
*/
|
|
|
|
struct sha256_ctx {
|
|
|
|
struct __sha256_ctx ctx;
|
|
|
|
};
|
|
|
|
|
2025-06-30 09:06:45 -07:00
|
|
|
/**
|
|
|
|
* sha256_init() - Initialize a SHA-256 context for a new message
|
|
|
|
* @ctx: the context to initialize
|
|
|
|
*
|
|
|
|
* If you don't need incremental computation, consider sha256() instead.
|
|
|
|
*
|
|
|
|
* Context: Any context.
|
|
|
|
*/
|
2025-06-30 09:06:37 -07:00
|
|
|
void sha256_init(struct sha256_ctx *ctx);
|
2025-06-30 09:06:45 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* sha256_update() - Update a SHA-256 context with message data
|
|
|
|
* @ctx: the context to update; must have been initialized
|
|
|
|
* @data: the message data
|
|
|
|
* @len: the data length in bytes
|
|
|
|
*
|
|
|
|
* This can be called any number of times.
|
|
|
|
*
|
|
|
|
* Context: Any context.
|
|
|
|
*/
|
2025-06-30 09:06:37 -07:00
|
|
|
static inline void sha256_update(struct sha256_ctx *ctx,
|
|
|
|
const u8 *data, size_t len)
|
2025-05-02 13:30:56 +08:00
|
|
|
{
|
2025-06-30 09:06:37 -07:00
|
|
|
__sha256_update(&ctx->ctx, data, len);
|
2025-05-02 13:30:56 +08:00
|
|
|
}
|
2025-06-30 09:06:45 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* sha256_final() - Finish computing a SHA-256 message digest
|
|
|
|
* @ctx: the context to finalize; must have been initialized
|
|
|
|
* @out: (output) the resulting SHA-256 message digest
|
|
|
|
*
|
|
|
|
* After finishing, this zeroizes @ctx. So the caller does not need to do it.
|
|
|
|
*
|
|
|
|
* Context: Any context.
|
|
|
|
*/
|
2025-06-30 09:06:37 -07:00
|
|
|
void sha256_final(struct sha256_ctx *ctx, u8 out[SHA256_DIGEST_SIZE]);
|
2025-06-30 09:06:45 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* sha256() - Compute SHA-256 message digest in one shot
|
|
|
|
* @data: the message data
|
|
|
|
* @len: the data length in bytes
|
|
|
|
* @out: (output) the resulting SHA-256 message digest
|
|
|
|
*
|
|
|
|
* Context: Any context.
|
|
|
|
*/
|
2025-04-28 10:00:38 -07:00
|
|
|
void sha256(const u8 *data, size_t len, u8 out[SHA256_DIGEST_SIZE]);
|
2019-09-01 22:35:31 +02:00
|
|
|
|
2025-06-30 09:06:39 -07:00
|
|
|
/**
|
|
|
|
* struct hmac_sha256_key - Prepared key for HMAC-SHA256
|
|
|
|
* @key: private
|
|
|
|
*/
|
|
|
|
struct hmac_sha256_key {
|
|
|
|
struct __hmac_sha256_key key;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct hmac_sha256_ctx - Context for computing HMAC-SHA256 of a message
|
|
|
|
* @ctx: private
|
|
|
|
*/
|
|
|
|
struct hmac_sha256_ctx {
|
|
|
|
struct __hmac_sha256_ctx ctx;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hmac_sha256_preparekey() - Prepare a key for HMAC-SHA256
|
|
|
|
* @key: (output) the key structure to initialize
|
|
|
|
* @raw_key: the raw HMAC-SHA256 key
|
|
|
|
* @raw_key_len: the key length in bytes. All key lengths are supported.
|
|
|
|
*
|
|
|
|
* Note: the caller is responsible for zeroizing both the struct hmac_sha256_key
|
|
|
|
* and the raw key once they are no longer needed.
|
|
|
|
*
|
|
|
|
* Context: Any context.
|
|
|
|
*/
|
|
|
|
void hmac_sha256_preparekey(struct hmac_sha256_key *key,
|
|
|
|
const u8 *raw_key, size_t raw_key_len);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hmac_sha256_init() - Initialize an HMAC-SHA256 context for a new message
|
|
|
|
* @ctx: (output) the HMAC context to initialize
|
|
|
|
* @key: the prepared HMAC key
|
|
|
|
*
|
|
|
|
* If you don't need incremental computation, consider hmac_sha256() instead.
|
|
|
|
*
|
|
|
|
* Context: Any context.
|
|
|
|
*/
|
|
|
|
static inline void hmac_sha256_init(struct hmac_sha256_ctx *ctx,
|
|
|
|
const struct hmac_sha256_key *key)
|
|
|
|
{
|
|
|
|
__hmac_sha256_init(&ctx->ctx, &key->key);
|
|
|
|
}
|
|
|
|
|
2025-07-11 14:58:43 -07:00
|
|
|
/**
|
|
|
|
* hmac_sha256_init_usingrawkey() - Initialize an HMAC-SHA256 context for a new
|
|
|
|
* message, using a raw key
|
|
|
|
* @ctx: (output) the HMAC context to initialize
|
|
|
|
* @raw_key: the raw HMAC-SHA256 key
|
|
|
|
* @raw_key_len: the key length in bytes. All key lengths are supported.
|
|
|
|
*
|
|
|
|
* If you don't need incremental computation, consider hmac_sha256_usingrawkey()
|
|
|
|
* instead.
|
|
|
|
*
|
|
|
|
* Context: Any context.
|
|
|
|
*/
|
|
|
|
void hmac_sha256_init_usingrawkey(struct hmac_sha256_ctx *ctx,
|
|
|
|
const u8 *raw_key, size_t raw_key_len);
|
|
|
|
|
2025-06-30 09:06:39 -07:00
|
|
|
/**
|
|
|
|
* hmac_sha256_update() - Update an HMAC-SHA256 context with message data
|
|
|
|
* @ctx: the HMAC context to update; must have been initialized
|
|
|
|
* @data: the message data
|
|
|
|
* @data_len: the data length in bytes
|
|
|
|
*
|
|
|
|
* This can be called any number of times.
|
|
|
|
*
|
|
|
|
* Context: Any context.
|
|
|
|
*/
|
|
|
|
static inline void hmac_sha256_update(struct hmac_sha256_ctx *ctx,
|
|
|
|
const u8 *data, size_t data_len)
|
|
|
|
{
|
|
|
|
__sha256_update(&ctx->ctx.sha_ctx, data, data_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hmac_sha256_final() - Finish computing an HMAC-SHA256 value
|
|
|
|
* @ctx: the HMAC context to finalize; must have been initialized
|
|
|
|
* @out: (output) the resulting HMAC-SHA256 value
|
|
|
|
*
|
|
|
|
* After finishing, this zeroizes @ctx. So the caller does not need to do it.
|
|
|
|
*
|
|
|
|
* Context: Any context.
|
|
|
|
*/
|
|
|
|
void hmac_sha256_final(struct hmac_sha256_ctx *ctx, u8 out[SHA256_DIGEST_SIZE]);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hmac_sha256() - Compute HMAC-SHA256 in one shot, using a prepared key
|
|
|
|
* @key: the prepared HMAC key
|
|
|
|
* @data: the message data
|
|
|
|
* @data_len: the data length in bytes
|
|
|
|
* @out: (output) the resulting HMAC-SHA256 value
|
|
|
|
*
|
|
|
|
* If you're using the key only once, consider using hmac_sha256_usingrawkey().
|
|
|
|
*
|
|
|
|
* Context: Any context.
|
|
|
|
*/
|
|
|
|
void hmac_sha256(const struct hmac_sha256_key *key,
|
|
|
|
const u8 *data, size_t data_len, u8 out[SHA256_DIGEST_SIZE]);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hmac_sha256_usingrawkey() - Compute HMAC-SHA256 in one shot, using a raw key
|
|
|
|
* @raw_key: the raw HMAC-SHA256 key
|
|
|
|
* @raw_key_len: the key length in bytes. All key lengths are supported.
|
|
|
|
* @data: the message data
|
|
|
|
* @data_len: the data length in bytes
|
|
|
|
* @out: (output) the resulting HMAC-SHA256 value
|
|
|
|
*
|
|
|
|
* If you're using the key multiple times, prefer to use
|
|
|
|
* hmac_sha256_preparekey() followed by multiple calls to hmac_sha256() instead.
|
|
|
|
*
|
|
|
|
* Context: Any context.
|
|
|
|
*/
|
|
|
|
void hmac_sha256_usingrawkey(const u8 *raw_key, size_t raw_key_len,
|
|
|
|
const u8 *data, size_t data_len,
|
|
|
|
u8 out[SHA256_DIGEST_SIZE]);
|
|
|
|
|
2025-06-30 09:03:06 -07:00
|
|
|
/* State for the SHA-512 (and SHA-384) compression function */
|
|
|
|
struct sha512_block_state {
|
|
|
|
u64 h[8];
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Context structure, shared by SHA-384 and SHA-512. The sha384_ctx and
|
|
|
|
* sha512_ctx structs wrap this one so that the API has proper typing and
|
|
|
|
* doesn't allow mixing the SHA-384 and SHA-512 functions arbitrarily.
|
|
|
|
*/
|
|
|
|
struct __sha512_ctx {
|
|
|
|
struct sha512_block_state state;
|
|
|
|
u64 bytecount_lo;
|
|
|
|
u64 bytecount_hi;
|
|
|
|
u8 buf[SHA512_BLOCK_SIZE] __aligned(__alignof__(__be64));
|
|
|
|
};
|
|
|
|
void __sha512_update(struct __sha512_ctx *ctx, const u8 *data, size_t len);
|
|
|
|
|
2025-06-30 09:03:07 -07:00
|
|
|
/*
|
|
|
|
* HMAC key and message context structs, shared by HMAC-SHA384 and HMAC-SHA512.
|
|
|
|
* The hmac_sha384_* and hmac_sha512_* structs wrap this one so that the API has
|
|
|
|
* proper typing and doesn't allow mixing the functions arbitrarily.
|
|
|
|
*/
|
|
|
|
struct __hmac_sha512_key {
|
|
|
|
struct sha512_block_state istate;
|
|
|
|
struct sha512_block_state ostate;
|
|
|
|
};
|
|
|
|
struct __hmac_sha512_ctx {
|
|
|
|
struct __sha512_ctx sha_ctx;
|
|
|
|
struct sha512_block_state ostate;
|
|
|
|
};
|
|
|
|
void __hmac_sha512_init(struct __hmac_sha512_ctx *ctx,
|
|
|
|
const struct __hmac_sha512_key *key);
|
|
|
|
|
2025-06-30 09:03:06 -07:00
|
|
|
/**
|
|
|
|
* struct sha384_ctx - Context for hashing a message with SHA-384
|
|
|
|
* @ctx: private
|
|
|
|
*/
|
|
|
|
struct sha384_ctx {
|
|
|
|
struct __sha512_ctx ctx;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sha384_init() - Initialize a SHA-384 context for a new message
|
|
|
|
* @ctx: the context to initialize
|
|
|
|
*
|
|
|
|
* If you don't need incremental computation, consider sha384() instead.
|
|
|
|
*
|
|
|
|
* Context: Any context.
|
|
|
|
*/
|
|
|
|
void sha384_init(struct sha384_ctx *ctx);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sha384_update() - Update a SHA-384 context with message data
|
|
|
|
* @ctx: the context to update; must have been initialized
|
|
|
|
* @data: the message data
|
|
|
|
* @len: the data length in bytes
|
|
|
|
*
|
|
|
|
* This can be called any number of times.
|
|
|
|
*
|
|
|
|
* Context: Any context.
|
|
|
|
*/
|
|
|
|
static inline void sha384_update(struct sha384_ctx *ctx,
|
|
|
|
const u8 *data, size_t len)
|
|
|
|
{
|
|
|
|
__sha512_update(&ctx->ctx, data, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sha384_final() - Finish computing a SHA-384 message digest
|
|
|
|
* @ctx: the context to finalize; must have been initialized
|
|
|
|
* @out: (output) the resulting SHA-384 message digest
|
|
|
|
*
|
|
|
|
* After finishing, this zeroizes @ctx. So the caller does not need to do it.
|
|
|
|
*
|
|
|
|
* Context: Any context.
|
|
|
|
*/
|
|
|
|
void sha384_final(struct sha384_ctx *ctx, u8 out[SHA384_DIGEST_SIZE]);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sha384() - Compute SHA-384 message digest in one shot
|
|
|
|
* @data: the message data
|
|
|
|
* @len: the data length in bytes
|
|
|
|
* @out: (output) the resulting SHA-384 message digest
|
|
|
|
*
|
|
|
|
* Context: Any context.
|
|
|
|
*/
|
|
|
|
void sha384(const u8 *data, size_t len, u8 out[SHA384_DIGEST_SIZE]);
|
|
|
|
|
2025-06-30 09:03:07 -07:00
|
|
|
/**
|
|
|
|
* struct hmac_sha384_key - Prepared key for HMAC-SHA384
|
|
|
|
* @key: private
|
|
|
|
*/
|
|
|
|
struct hmac_sha384_key {
|
|
|
|
struct __hmac_sha512_key key;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct hmac_sha384_ctx - Context for computing HMAC-SHA384 of a message
|
|
|
|
* @ctx: private
|
|
|
|
*/
|
|
|
|
struct hmac_sha384_ctx {
|
|
|
|
struct __hmac_sha512_ctx ctx;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hmac_sha384_preparekey() - Prepare a key for HMAC-SHA384
|
|
|
|
* @key: (output) the key structure to initialize
|
|
|
|
* @raw_key: the raw HMAC-SHA384 key
|
|
|
|
* @raw_key_len: the key length in bytes. All key lengths are supported.
|
|
|
|
*
|
|
|
|
* Note: the caller is responsible for zeroizing both the struct hmac_sha384_key
|
|
|
|
* and the raw key once they are no longer needed.
|
|
|
|
*
|
|
|
|
* Context: Any context.
|
|
|
|
*/
|
|
|
|
void hmac_sha384_preparekey(struct hmac_sha384_key *key,
|
|
|
|
const u8 *raw_key, size_t raw_key_len);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hmac_sha384_init() - Initialize an HMAC-SHA384 context for a new message
|
|
|
|
* @ctx: (output) the HMAC context to initialize
|
|
|
|
* @key: the prepared HMAC key
|
|
|
|
*
|
|
|
|
* If you don't need incremental computation, consider hmac_sha384() instead.
|
|
|
|
*
|
|
|
|
* Context: Any context.
|
|
|
|
*/
|
|
|
|
static inline void hmac_sha384_init(struct hmac_sha384_ctx *ctx,
|
|
|
|
const struct hmac_sha384_key *key)
|
|
|
|
{
|
|
|
|
__hmac_sha512_init(&ctx->ctx, &key->key);
|
|
|
|
}
|
|
|
|
|
2025-07-11 14:58:43 -07:00
|
|
|
/**
|
|
|
|
* hmac_sha384_init_usingrawkey() - Initialize an HMAC-SHA384 context for a new
|
|
|
|
* message, using a raw key
|
|
|
|
* @ctx: (output) the HMAC context to initialize
|
|
|
|
* @raw_key: the raw HMAC-SHA384 key
|
|
|
|
* @raw_key_len: the key length in bytes. All key lengths are supported.
|
|
|
|
*
|
|
|
|
* If you don't need incremental computation, consider hmac_sha384_usingrawkey()
|
|
|
|
* instead.
|
|
|
|
*
|
|
|
|
* Context: Any context.
|
|
|
|
*/
|
|
|
|
void hmac_sha384_init_usingrawkey(struct hmac_sha384_ctx *ctx,
|
|
|
|
const u8 *raw_key, size_t raw_key_len);
|
|
|
|
|
2025-06-30 09:03:07 -07:00
|
|
|
/**
|
|
|
|
* hmac_sha384_update() - Update an HMAC-SHA384 context with message data
|
|
|
|
* @ctx: the HMAC context to update; must have been initialized
|
|
|
|
* @data: the message data
|
|
|
|
* @data_len: the data length in bytes
|
|
|
|
*
|
|
|
|
* This can be called any number of times.
|
|
|
|
*
|
|
|
|
* Context: Any context.
|
|
|
|
*/
|
|
|
|
static inline void hmac_sha384_update(struct hmac_sha384_ctx *ctx,
|
|
|
|
const u8 *data, size_t data_len)
|
|
|
|
{
|
|
|
|
__sha512_update(&ctx->ctx.sha_ctx, data, data_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hmac_sha384_final() - Finish computing an HMAC-SHA384 value
|
|
|
|
* @ctx: the HMAC context to finalize; must have been initialized
|
|
|
|
* @out: (output) the resulting HMAC-SHA384 value
|
|
|
|
*
|
|
|
|
* After finishing, this zeroizes @ctx. So the caller does not need to do it.
|
|
|
|
*
|
|
|
|
* Context: Any context.
|
|
|
|
*/
|
|
|
|
void hmac_sha384_final(struct hmac_sha384_ctx *ctx, u8 out[SHA384_DIGEST_SIZE]);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hmac_sha384() - Compute HMAC-SHA384 in one shot, using a prepared key
|
|
|
|
* @key: the prepared HMAC key
|
|
|
|
* @data: the message data
|
|
|
|
* @data_len: the data length in bytes
|
|
|
|
* @out: (output) the resulting HMAC-SHA384 value
|
|
|
|
*
|
|
|
|
* If you're using the key only once, consider using hmac_sha384_usingrawkey().
|
|
|
|
*
|
|
|
|
* Context: Any context.
|
|
|
|
*/
|
|
|
|
void hmac_sha384(const struct hmac_sha384_key *key,
|
|
|
|
const u8 *data, size_t data_len, u8 out[SHA384_DIGEST_SIZE]);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hmac_sha384_usingrawkey() - Compute HMAC-SHA384 in one shot, using a raw key
|
|
|
|
* @raw_key: the raw HMAC-SHA384 key
|
|
|
|
* @raw_key_len: the key length in bytes. All key lengths are supported.
|
|
|
|
* @data: the message data
|
|
|
|
* @data_len: the data length in bytes
|
|
|
|
* @out: (output) the resulting HMAC-SHA384 value
|
|
|
|
*
|
|
|
|
* If you're using the key multiple times, prefer to use
|
|
|
|
* hmac_sha384_preparekey() followed by multiple calls to hmac_sha384() instead.
|
|
|
|
*
|
|
|
|
* Context: Any context.
|
|
|
|
*/
|
|
|
|
void hmac_sha384_usingrawkey(const u8 *raw_key, size_t raw_key_len,
|
|
|
|
const u8 *data, size_t data_len,
|
|
|
|
u8 out[SHA384_DIGEST_SIZE]);
|
|
|
|
|
2025-06-30 09:03:06 -07:00
|
|
|
/**
|
|
|
|
* struct sha512_ctx - Context for hashing a message with SHA-512
|
|
|
|
* @ctx: private
|
|
|
|
*/
|
|
|
|
struct sha512_ctx {
|
|
|
|
struct __sha512_ctx ctx;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sha512_init() - Initialize a SHA-512 context for a new message
|
|
|
|
* @ctx: the context to initialize
|
|
|
|
*
|
|
|
|
* If you don't need incremental computation, consider sha512() instead.
|
|
|
|
*
|
|
|
|
* Context: Any context.
|
|
|
|
*/
|
|
|
|
void sha512_init(struct sha512_ctx *ctx);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sha512_update() - Update a SHA-512 context with message data
|
|
|
|
* @ctx: the context to update; must have been initialized
|
|
|
|
* @data: the message data
|
|
|
|
* @len: the data length in bytes
|
|
|
|
*
|
|
|
|
* This can be called any number of times.
|
|
|
|
*
|
|
|
|
* Context: Any context.
|
|
|
|
*/
|
|
|
|
static inline void sha512_update(struct sha512_ctx *ctx,
|
|
|
|
const u8 *data, size_t len)
|
|
|
|
{
|
|
|
|
__sha512_update(&ctx->ctx, data, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sha512_final() - Finish computing a SHA-512 message digest
|
|
|
|
* @ctx: the context to finalize; must have been initialized
|
|
|
|
* @out: (output) the resulting SHA-512 message digest
|
|
|
|
*
|
|
|
|
* After finishing, this zeroizes @ctx. So the caller does not need to do it.
|
|
|
|
*
|
|
|
|
* Context: Any context.
|
|
|
|
*/
|
|
|
|
void sha512_final(struct sha512_ctx *ctx, u8 out[SHA512_DIGEST_SIZE]);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sha512() - Compute SHA-512 message digest in one shot
|
|
|
|
* @data: the message data
|
|
|
|
* @len: the data length in bytes
|
|
|
|
* @out: (output) the resulting SHA-512 message digest
|
|
|
|
*
|
|
|
|
* Context: Any context.
|
|
|
|
*/
|
|
|
|
void sha512(const u8 *data, size_t len, u8 out[SHA512_DIGEST_SIZE]);
|
|
|
|
|
2025-06-30 09:03:07 -07:00
|
|
|
/**
|
|
|
|
* struct hmac_sha512_key - Prepared key for HMAC-SHA512
|
|
|
|
* @key: private
|
|
|
|
*/
|
|
|
|
struct hmac_sha512_key {
|
|
|
|
struct __hmac_sha512_key key;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct hmac_sha512_ctx - Context for computing HMAC-SHA512 of a message
|
|
|
|
* @ctx: private
|
|
|
|
*/
|
|
|
|
struct hmac_sha512_ctx {
|
|
|
|
struct __hmac_sha512_ctx ctx;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hmac_sha512_preparekey() - Prepare a key for HMAC-SHA512
|
|
|
|
* @key: (output) the key structure to initialize
|
|
|
|
* @raw_key: the raw HMAC-SHA512 key
|
|
|
|
* @raw_key_len: the key length in bytes. All key lengths are supported.
|
|
|
|
*
|
|
|
|
* Note: the caller is responsible for zeroizing both the struct hmac_sha512_key
|
|
|
|
* and the raw key once they are no longer needed.
|
|
|
|
*
|
|
|
|
* Context: Any context.
|
|
|
|
*/
|
|
|
|
void hmac_sha512_preparekey(struct hmac_sha512_key *key,
|
|
|
|
const u8 *raw_key, size_t raw_key_len);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hmac_sha512_init() - Initialize an HMAC-SHA512 context for a new message
|
|
|
|
* @ctx: (output) the HMAC context to initialize
|
|
|
|
* @key: the prepared HMAC key
|
|
|
|
*
|
|
|
|
* If you don't need incremental computation, consider hmac_sha512() instead.
|
|
|
|
*
|
|
|
|
* Context: Any context.
|
|
|
|
*/
|
|
|
|
static inline void hmac_sha512_init(struct hmac_sha512_ctx *ctx,
|
|
|
|
const struct hmac_sha512_key *key)
|
|
|
|
{
|
|
|
|
__hmac_sha512_init(&ctx->ctx, &key->key);
|
|
|
|
}
|
|
|
|
|
2025-07-11 14:58:43 -07:00
|
|
|
/**
|
|
|
|
* hmac_sha512_init_usingrawkey() - Initialize an HMAC-SHA512 context for a new
|
|
|
|
* message, using a raw key
|
|
|
|
* @ctx: (output) the HMAC context to initialize
|
|
|
|
* @raw_key: the raw HMAC-SHA512 key
|
|
|
|
* @raw_key_len: the key length in bytes. All key lengths are supported.
|
|
|
|
*
|
|
|
|
* If you don't need incremental computation, consider hmac_sha512_usingrawkey()
|
|
|
|
* instead.
|
|
|
|
*
|
|
|
|
* Context: Any context.
|
|
|
|
*/
|
|
|
|
void hmac_sha512_init_usingrawkey(struct hmac_sha512_ctx *ctx,
|
|
|
|
const u8 *raw_key, size_t raw_key_len);
|
|
|
|
|
2025-06-30 09:03:07 -07:00
|
|
|
/**
|
|
|
|
* hmac_sha512_update() - Update an HMAC-SHA512 context with message data
|
|
|
|
* @ctx: the HMAC context to update; must have been initialized
|
|
|
|
* @data: the message data
|
|
|
|
* @data_len: the data length in bytes
|
|
|
|
*
|
|
|
|
* This can be called any number of times.
|
|
|
|
*
|
|
|
|
* Context: Any context.
|
|
|
|
*/
|
|
|
|
static inline void hmac_sha512_update(struct hmac_sha512_ctx *ctx,
|
|
|
|
const u8 *data, size_t data_len)
|
|
|
|
{
|
|
|
|
__sha512_update(&ctx->ctx.sha_ctx, data, data_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hmac_sha512_final() - Finish computing an HMAC-SHA512 value
|
|
|
|
* @ctx: the HMAC context to finalize; must have been initialized
|
|
|
|
* @out: (output) the resulting HMAC-SHA512 value
|
|
|
|
*
|
|
|
|
* After finishing, this zeroizes @ctx. So the caller does not need to do it.
|
|
|
|
*
|
|
|
|
* Context: Any context.
|
|
|
|
*/
|
|
|
|
void hmac_sha512_final(struct hmac_sha512_ctx *ctx, u8 out[SHA512_DIGEST_SIZE]);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hmac_sha512() - Compute HMAC-SHA512 in one shot, using a prepared key
|
|
|
|
* @key: the prepared HMAC key
|
|
|
|
* @data: the message data
|
|
|
|
* @data_len: the data length in bytes
|
|
|
|
* @out: (output) the resulting HMAC-SHA512 value
|
|
|
|
*
|
|
|
|
* If you're using the key only once, consider using hmac_sha512_usingrawkey().
|
|
|
|
*
|
|
|
|
* Context: Any context.
|
|
|
|
*/
|
|
|
|
void hmac_sha512(const struct hmac_sha512_key *key,
|
|
|
|
const u8 *data, size_t data_len, u8 out[SHA512_DIGEST_SIZE]);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hmac_sha512_usingrawkey() - Compute HMAC-SHA512 in one shot, using a raw key
|
|
|
|
* @raw_key: the raw HMAC-SHA512 key
|
|
|
|
* @raw_key_len: the key length in bytes. All key lengths are supported.
|
|
|
|
* @data: the message data
|
|
|
|
* @data_len: the data length in bytes
|
|
|
|
* @out: (output) the resulting HMAC-SHA512 value
|
|
|
|
*
|
|
|
|
* If you're using the key multiple times, prefer to use
|
|
|
|
* hmac_sha512_preparekey() followed by multiple calls to hmac_sha512() instead.
|
|
|
|
*
|
|
|
|
* Context: Any context.
|
|
|
|
*/
|
|
|
|
void hmac_sha512_usingrawkey(const u8 *raw_key, size_t raw_key_len,
|
|
|
|
const u8 *data, size_t data_len,
|
|
|
|
u8 out[SHA512_DIGEST_SIZE]);
|
|
|
|
|
2020-11-12 21:20:21 -08:00
|
|
|
#endif /* _CRYPTO_SHA2_H */
|