Skip to content

Commit d9afdba

Browse files
jallisonciqbmastbergen
authored andcommitted
Add fips_approved flag to SHA512 and HMAC-SHA512 structs.
Ensure this is initialized correctly based on system state and key length. Requested by lab. Signed-off-by: Jeremy Allison <jallison@ciq.com>
1 parent 3bfe619 commit d9afdba

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

include/crypto/sha2.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,7 @@ void hmac_sha384_usingrawkey(const u8 *raw_key, size_t raw_key_len,
746746
*/
747747
struct sha512_ctx {
748748
struct __sha512_ctx ctx;
749+
bool fips_approved;
749750
};
750751

751752
/**
@@ -801,6 +802,7 @@ void sha512(const u8 *data, size_t len, u8 out[SHA512_DIGEST_SIZE]);
801802
*/
802803
struct hmac_sha512_key {
803804
struct __hmac_sha512_key key;
805+
bool fips_approved;
804806
};
805807

806808
/**
@@ -809,6 +811,7 @@ struct hmac_sha512_key {
809811
*/
810812
struct hmac_sha512_ctx {
811813
struct __hmac_sha512_ctx ctx;
814+
bool fips_approved;
812815
};
813816

814817
/**
@@ -838,6 +841,7 @@ static inline void hmac_sha512_init(struct hmac_sha512_ctx *ctx,
838841
const struct hmac_sha512_key *key)
839842
{
840843
__hmac_sha512_init(&ctx->ctx, &key->key);
844+
ctx->fips_approved = key->fips_approved;
841845
}
842846

843847
/**

lib/crypto/sha512.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ EXPORT_SYMBOL_GPL(sha384_init);
158158
void sha512_init(struct sha512_ctx *ctx)
159159
{
160160
__sha512_init(&ctx->ctx, &sha512_iv, 0);
161+
ctx->fips_approved = fips_enabled;
161162
}
162163
EXPORT_SYMBOL_GPL(sha512_init);
163164

@@ -300,6 +301,9 @@ void hmac_sha512_preparekey(struct hmac_sha512_key *key,
300301
{
301302
__hmac_sha512_preparekey(&key->key.istate, &key->key.ostate,
302303
raw_key, raw_key_len, &sha512_iv);
304+
key->fips_approved = fips_enabled;
305+
if (fips_enabled && raw_key_len < 112 / 8)
306+
key->fips_approved = false;
303307
}
304308
EXPORT_SYMBOL_GPL(hmac_sha512_preparekey);
305309

@@ -331,6 +335,9 @@ void hmac_sha512_init_usingrawkey(struct hmac_sha512_ctx *ctx,
331335
raw_key, raw_key_len, &sha512_iv);
332336
ctx->ctx.sha_ctx.bytecount_lo = SHA512_BLOCK_SIZE;
333337
ctx->ctx.sha_ctx.bytecount_hi = 0;
338+
ctx->fips_approved = fips_enabled;
339+
if (fips_enabled && raw_key_len < 112 / 8)
340+
ctx->fips_approved = false;
334341
}
335342
EXPORT_SYMBOL_GPL(hmac_sha512_init_usingrawkey);
336343

0 commit comments

Comments
 (0)