Skip to content

Commit 3bfe619

Browse files
jallisonciqbmastbergen
authored andcommitted
Add fips_approved flag to SHA384 and HMAC-SHA384 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 18ee516 commit 3bfe619

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
@@ -569,6 +569,7 @@ void __hmac_sha512_init(struct __hmac_sha512_ctx *ctx,
569569
*/
570570
struct sha384_ctx {
571571
struct __sha512_ctx ctx;
572+
bool fips_approved;
572573
};
573574

574575
/**
@@ -624,6 +625,7 @@ void sha384(const u8 *data, size_t len, u8 out[SHA384_DIGEST_SIZE]);
624625
*/
625626
struct hmac_sha384_key {
626627
struct __hmac_sha512_key key;
628+
bool fips_approved;
627629
};
628630

629631
/**
@@ -632,6 +634,7 @@ struct hmac_sha384_key {
632634
*/
633635
struct hmac_sha384_ctx {
634636
struct __hmac_sha512_ctx ctx;
637+
bool fips_approved;
635638
};
636639

637640
/**
@@ -661,6 +664,7 @@ static inline void hmac_sha384_init(struct hmac_sha384_ctx *ctx,
661664
const struct hmac_sha384_key *key)
662665
{
663666
__hmac_sha512_init(&ctx->ctx, &key->key);
667+
ctx->fips_approved = key->fips_approved;
664668
}
665669

666670
/**

lib/crypto/sha512.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ static void __sha512_init(struct __sha512_ctx *ctx,
151151
void sha384_init(struct sha384_ctx *ctx)
152152
{
153153
__sha512_init(&ctx->ctx, &sha384_iv, 0);
154+
ctx->fips_approved = fips_enabled;
154155
}
155156
EXPORT_SYMBOL_GPL(sha384_init);
156157

@@ -288,6 +289,9 @@ void hmac_sha384_preparekey(struct hmac_sha384_key *key,
288289
{
289290
__hmac_sha512_preparekey(&key->key.istate, &key->key.ostate,
290291
raw_key, raw_key_len, &sha384_iv);
292+
key->fips_approved = fips_enabled;
293+
if (fips_enabled && raw_key_len < 112 / 8)
294+
key->fips_approved = false;
291295
}
292296
EXPORT_SYMBOL_GPL(hmac_sha384_preparekey);
293297

@@ -314,6 +318,9 @@ void hmac_sha384_init_usingrawkey(struct hmac_sha384_ctx *ctx,
314318
raw_key, raw_key_len, &sha384_iv);
315319
ctx->ctx.sha_ctx.bytecount_lo = SHA512_BLOCK_SIZE;
316320
ctx->ctx.sha_ctx.bytecount_hi = 0;
321+
ctx->fips_approved = fips_enabled;
322+
if (fips_enabled && raw_key_len < 112 / 8)
323+
ctx->fips_approved = false;
317324
}
318325
EXPORT_SYMBOL_GPL(hmac_sha384_init_usingrawkey);
319326

0 commit comments

Comments
 (0)