Skip to content

[fips-9-compliant] Rebase Custom changes to 5.14.0-570.30.1.el9_6 #449

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions configs/kernel-x86_64-debug-rhel.config
Original file line number Diff line number Diff line change
Expand Up @@ -7193,3 +7193,14 @@ CONFIG_ZSWAP=y
# CONFIG_ZSWAP_ZPOOL_DEFAULT_Z3FOLD is not set
CONFIG_ZSWAP_ZPOOL_DEFAULT_ZBUD=y
# CONFIG_ZSWAP_ZPOOL_DEFAULT_ZSMALLOC is not set

CONFIG_X509_CERTIFICATE_PARSER=y
CONFIG_PKCS7_MESSAGE_PARSER=y
ONFIG_FIPS_SIGNATURE_SELFTEST=y
CONFIG_FIPS_SIGNATURE_SELFTEST_RSA=y
CONFIG_FIPS_SIGNATURE_SELFTEST_ECDSA=y
CONFIG_CRYPTO_DRBG=y
CONFIG_CRYPTO_FIPS=y
CONFIG_CRYPTO_FIPS_CUSTOM_VERSION=y
CONFIG_CRYPTO_FIPS_VERSION="rocky9.20250725"
CONFIG_CRYPTO_FIPS_NAME="Rocky Linux 9 Kernel Cryptographic API"
11 changes: 11 additions & 0 deletions configs/kernel-x86_64-rhel.config
Original file line number Diff line number Diff line change
Expand Up @@ -7170,3 +7170,14 @@ CONFIG_ZSWAP=y
# CONFIG_ZSWAP_ZPOOL_DEFAULT_Z3FOLD is not set
CONFIG_ZSWAP_ZPOOL_DEFAULT_ZBUD=y
# CONFIG_ZSWAP_ZPOOL_DEFAULT_ZSMALLOC is not set

CONFIG_X509_CERTIFICATE_PARSER=y
CONFIG_PKCS7_MESSAGE_PARSER=y
CONFIG_FIPS_SIGNATURE_SELFTEST=y
CONFIG_FIPS_SIGNATURE_SELFTEST_RSA=y
CONFIG_FIPS_SIGNATURE_SELFTEST_ECDSA=y
CONFIG_CRYPTO_DRBG=y
CONFIG_CRYPTO_FIPS=y
CONFIG_CRYPTO_FIPS_CUSTOM_VERSION=y
CONFIG_CRYPTO_FIPS_VERSION="rocky9.20250725"
CONFIG_CRYPTO_FIPS_NAME="Rocky Linux 9 Kernel Cryptographic API"
1 change: 1 addition & 0 deletions crypto/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2019,6 +2019,7 @@ config CRYPTO_ANSI_CPRNG
tristate "Pseudo Random Number Generation for Cryptographic modules"
select CRYPTO_AES
select CRYPTO_RNG
select CRYPTO_SHA3
help
This option enables the generic pseudo random number generator
for cryptographic modules. Uses the Algorithm specified in
Expand Down
3 changes: 1 addition & 2 deletions crypto/aead.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ static int setkey_unaligned(struct crypto_aead *tfm, const u8 *key,
alignbuffer = (u8 *)ALIGN((unsigned long)buffer, alignmask + 1);
memcpy(alignbuffer, key, keylen);
ret = crypto_aead_alg(tfm)->setkey(tfm, alignbuffer, keylen);
memset(alignbuffer, 0, keylen);
kfree(buffer);
kfree_sensitive(buffer);
return ret;
}

Expand Down
3 changes: 1 addition & 2 deletions crypto/cipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ static int setkey_unaligned(struct crypto_cipher *tfm, const u8 *key,
alignbuffer = (u8 *)ALIGN((unsigned long)buffer, alignmask + 1);
memcpy(alignbuffer, key, keylen);
ret = cia->cia_setkey(crypto_cipher_tfm(tfm), alignbuffer, keylen);
memset(alignbuffer, 0, keylen);
kfree(buffer);
kfree_sensitive(buffer);
return ret;

}
Expand Down
18 changes: 12 additions & 6 deletions crypto/drbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,18 +176,18 @@ static const struct drbg_core drbg_cores[] = {
.blocklen_bytes = 48,
.cra_name = "hmac_sha384",
.backend_cra_name = "hmac(sha384)",
}, {
.flags = DRBG_HMAC | DRBG_STRENGTH256,
.statelen = 32, /* block length of cipher */
.blocklen_bytes = 32,
.cra_name = "hmac_sha256",
.backend_cra_name = "hmac(sha256)",
}, {
.flags = DRBG_HMAC | DRBG_STRENGTH256,
.statelen = 64, /* block length of cipher */
.blocklen_bytes = 64,
.cra_name = "hmac_sha512",
.backend_cra_name = "hmac(sha512)",
}, {
.flags = DRBG_HMAC | DRBG_STRENGTH256,
.statelen = 32, /* block length of cipher */
.blocklen_bytes = 32,
.cra_name = "hmac_sha256",
.backend_cra_name = "hmac(sha256)",
},
#endif /* CONFIG_CRYPTO_DRBG_HMAC */
};
Expand Down Expand Up @@ -1283,6 +1283,12 @@ static inline int drbg_alloc_state(struct drbg_state *drbg)
if (ret < 0)
goto err;

/*
* Align to at least a cache line for better performance. This also
* prevents false sharing of cache lines between different instances.
*/
ret = max(ret, L1_CACHE_BYTES - 1);

drbg->Vbuf = kmalloc(drbg_statelen(drbg) + ret, GFP_KERNEL);
if (!drbg->Vbuf) {
ret = -ENOMEM;
Expand Down
33 changes: 33 additions & 0 deletions crypto/ecdh.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <crypto/kpp.h>
#include <crypto/ecdh.h>
#include <linux/scatterlist.h>
#include <linux/fips.h>
#include "ecc.h"

struct ecdh_ctx {
Expand All @@ -33,6 +34,8 @@ static int ecdh_set_secret(struct crypto_kpp *tfm, const void *buf,
params.key_size > sizeof(u64) * ctx->ndigits)
return -EINVAL;

memset(ctx->private_key, 0, sizeof(ctx->private_key));

if (!params.key || !params.key_size)
return ecc_gen_privkey(ctx->curve_id, ctx->ndigits,
ctx->private_key);
Expand Down Expand Up @@ -94,6 +97,36 @@ static int ecdh_compute_value(struct kpp_request *req)
ctx->private_key, public_key);
buf = public_key;
nbytes = public_key_sz;

/*
* SP800-56Arev3, 5.6.2.1.4: ("Owner Assurance of
* Pair-wise Consistency"): recompute the public key
* and check if the results match.
*/
if (fips_enabled) {
u64 *public_key_pct;

if (ret < 0)
goto free_all;

public_key_pct = kmalloc(public_key_sz, GFP_KERNEL);
if (!public_key_pct) {
ret = -ENOMEM;
goto free_all;
}

ret = ecc_make_pub_key(ctx->curve_id, ctx->ndigits,
ctx->private_key,
public_key_pct);
if (ret < 0) {
kfree(public_key_pct);
goto free_all;
}

if (memcmp(public_key, public_key_pct, public_key_sz))
panic("ECDH PCT failed in FIPS mode");
kfree(public_key_pct);
}
}

if (ret < 0)
Expand Down
9 changes: 6 additions & 3 deletions crypto/essiv.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,16 @@ static int essiv_aead_setkey(struct crypto_aead *tfm, const u8 *key,
crypto_shash_update(desc, keys.enckey, keys.enckeylen) ?:
crypto_shash_finup(desc, keys.authkey, keys.authkeylen, salt);
if (err)
return err;
goto out;

crypto_cipher_clear_flags(tctx->essiv_cipher, CRYPTO_TFM_REQ_MASK);
crypto_cipher_set_flags(tctx->essiv_cipher, crypto_aead_get_flags(tfm) &
CRYPTO_TFM_REQ_MASK);
return crypto_cipher_setkey(tctx->essiv_cipher, salt,
crypto_shash_digestsize(tctx->hash));
err = crypto_cipher_setkey(tctx->essiv_cipher, salt,
crypto_shash_digestsize(tctx->hash));
out:
memzero_explicit(&keys, sizeof(keys));
return err;
}

static int essiv_aead_setauthsize(struct crypto_aead *tfm,
Expand Down
Loading