Skip to content

Commit 35f8c3b

Browse files
committed
linuxkm ecdsa: fix ecdsa fips define guards, and fix names.
1 parent 69688c2 commit 35f8c3b

2 files changed

Lines changed: 55 additions & 27 deletions

File tree

linuxkm/lkcapi_ecdsa_glue.c

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,24 @@
2929
#include <wolfssl/wolfcrypt/asn.h>
3030
#include <wolfssl/wolfcrypt/ecc.h>
3131

32-
#define WOLFKM_ECDSA_NAME "ecdsa"
33-
#define WOLFKM_ECDSA_DRIVER ("ecdsa" WOLFKM_DRIVER_SUFFIX)
32+
#define WOLFKM_ECDSA_DRIVER ("ecdsa-wolfcrypt")
33+
34+
#define WOLFKM_ECDSA_P192_NAME ("ecdsa-nist-p192")
35+
#define WOLFKM_ECDSA_P192_DRIVER ("ecdsa-nist-p192" WOLFKM_DRIVER_FIPS \
36+
"-wolfcrypt")
37+
38+
#define WOLFKM_ECDSA_P256_NAME ("ecdsa-nist-p256")
39+
#define WOLFKM_ECDSA_P256_DRIVER ("ecdsa-nist-p256" WOLFKM_DRIVER_FIPS \
40+
"-wolfcrypt")
41+
42+
#define WOLFKM_ECDSA_P384_NAME ("ecdsa-nist-p384")
43+
#define WOLFKM_ECDSA_P384_DRIVER ("ecdsa-nist-p384" WOLFKM_DRIVER_FIPS \
44+
"-wolfcrypt")
45+
46+
#define WOLFKM_ECDSA_P521_NAME ("ecdsa-nist-p521")
47+
#define WOLFKM_ECDSA_P521_DRIVER ("ecdsa-nist-p521" WOLFKM_DRIVER_FIPS \
48+
"-wolfcrypt")
49+
3450

3551
static int linuxkm_test_ecdsa_nist_driver(const char * driver,
3652
const byte * pub, word32 pub_len,
@@ -71,8 +87,8 @@ static int km_ecdsa_nist_p521_init(struct crypto_akcipher *tfm);
7187

7288
#if defined(LINUXKM_ECC192)
7389
static struct akcipher_alg ecdsa_nist_p192 = {
74-
.base.cra_name = "ecdsa-nist-p192",
75-
.base.cra_driver_name = "ecdsa-nist-p192-wolfcrypt",
90+
.base.cra_name = WOLFKM_ECDSA_P192_NAME,
91+
.base.cra_driver_name = WOLFKM_ECDSA_P192_DRIVER,
7692
.base.cra_priority = WOLFSSL_LINUXKM_LKCAPI_PRIORITY,
7793
.base.cra_module = THIS_MODULE,
7894
.base.cra_ctxsize = sizeof(struct km_ecdsa_ctx),
@@ -85,8 +101,8 @@ static struct akcipher_alg ecdsa_nist_p192 = {
85101
#endif /* LINUXKM_ECC192 */
86102

87103
static struct akcipher_alg ecdsa_nist_p256 = {
88-
.base.cra_name = "ecdsa-nist-p256",
89-
.base.cra_driver_name = "ecdsa-nist-p256-wolfcrypt",
104+
.base.cra_name = WOLFKM_ECDSA_P256_NAME,
105+
.base.cra_driver_name = WOLFKM_ECDSA_P256_DRIVER,
90106
.base.cra_priority = WOLFSSL_LINUXKM_LKCAPI_PRIORITY,
91107
.base.cra_module = THIS_MODULE,
92108
.base.cra_ctxsize = sizeof(struct km_ecdsa_ctx),
@@ -98,8 +114,8 @@ static struct akcipher_alg ecdsa_nist_p256 = {
98114
};
99115

100116
static struct akcipher_alg ecdsa_nist_p384 = {
101-
.base.cra_name = "ecdsa-nist-p384",
102-
.base.cra_driver_name = "ecdsa-nist-p384-wolfcrypt",
117+
.base.cra_name = WOLFKM_ECDSA_P384_NAME,
118+
.base.cra_driver_name = WOLFKM_ECDSA_P384_DRIVER,
103119
.base.cra_priority = WOLFSSL_LINUXKM_LKCAPI_PRIORITY,
104120
.base.cra_module = THIS_MODULE,
105121
.base.cra_ctxsize = sizeof(struct km_ecdsa_ctx),
@@ -112,8 +128,8 @@ static struct akcipher_alg ecdsa_nist_p384 = {
112128

113129
#if defined(HAVE_ECC521)
114130
static struct akcipher_alg ecdsa_nist_p521 = {
115-
.base.cra_name = "ecdsa-nist-p521",
116-
.base.cra_driver_name = "ecdsa-nist-p521-wolfcrypt",
131+
.base.cra_name = WOLFKM_ECDSA_P521_NAME,
132+
.base.cra_driver_name = WOLFKM_ECDSA_P521_DRIVER,
117133
.base.cra_priority = WOLFSSL_LINUXKM_LKCAPI_PRIORITY,
118134
.base.cra_module = THIS_MODULE,
119135
.base.cra_ctxsize = sizeof(struct km_ecdsa_ctx),
@@ -436,7 +452,7 @@ static int linuxkm_test_ecdsa_nist_p192(void)
436452
hash_len = sizeof(hash);
437453
sig_len = sizeof(sig);
438454

439-
rc = linuxkm_test_ecdsa_nist_driver("ecdsa-nist-p192-wolfcrypt",
455+
rc = linuxkm_test_ecdsa_nist_driver(WOLFKM_ECDSA_P192_DRIVER,
440456
p192_pub, pub_len,
441457
sig, sig_len,
442458
hash, hash_len);
@@ -491,7 +507,7 @@ static int linuxkm_test_ecdsa_nist_p256(void)
491507
hash_len = sizeof(hash);
492508
sig_len = sizeof(sig);
493509

494-
rc = linuxkm_test_ecdsa_nist_driver("ecdsa-nist-p256-wolfcrypt",
510+
rc = linuxkm_test_ecdsa_nist_driver(WOLFKM_ECDSA_P256_DRIVER,
495511
p256_pub, pub_len,
496512
sig, sig_len,
497513
hash, hash_len);
@@ -554,7 +570,7 @@ static int linuxkm_test_ecdsa_nist_p384(void)
554570
hash_len = sizeof(hash);
555571
sig_len = sizeof(sig);
556572

557-
rc = linuxkm_test_ecdsa_nist_driver("ecdsa-nist-p384-wolfcrypt",
573+
rc = linuxkm_test_ecdsa_nist_driver(WOLFKM_ECDSA_P384_DRIVER,
558574
p384_pub, pub_len,
559575
sig, sig_len,
560576
hash, hash_len);
@@ -629,7 +645,7 @@ static int linuxkm_test_ecdsa_nist_p521(void)
629645
hash_len = sizeof(hash);
630646
sig_len = sizeof(sig);
631647

632-
rc = linuxkm_test_ecdsa_nist_driver("ecdsa-nist-p521-wolfcrypt",
648+
rc = linuxkm_test_ecdsa_nist_driver(WOLFKM_ECDSA_P521_DRIVER,
633649
p521_pub, pub_len,
634650
sig, sig_len,
635651
hash, hash_len);

linuxkm/lkcapi_glue.c

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4195,24 +4195,36 @@ static int linuxkm_test_aesecb(void) {
41954195
#undef LINUXKM_LKCAPI_REGISTER_ECDSA
41964196
#endif /* HAVE_ECC */
41974197

4198-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 13, 0) && \
4199-
defined(LINUXKM_LKCAPI_REGISTER_ECDSA)
4200-
/**
4201-
* note: ecdsa only supported with linux 6.12 and earlier for now.
4202-
* In linux 6.13, ecdsa changed from a struct akcipher_alg type to
4203-
* struct sig_alg type, and the sign/verify callbacks were removed
4204-
* from akcipher_alg.
4205-
* */
4206-
#undef LINUXKM_LKCAPI_REGISTER_ECDSA
4207-
#endif
4198+
#if defined (LINUXKM_LKCAPI_REGISTER_ECDSA)
4199+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 13, 0)
4200+
/**
4201+
* note: ecdsa supported with linux 6.12 and earlier for now, only.
4202+
* In linux 6.13, ecdsa changed from a struct akcipher_alg type to
4203+
* struct sig_alg type, and the sign/verify callbacks were removed
4204+
* from akcipher_alg.
4205+
* */
4206+
#undef LINUXKM_LKCAPI_REGISTER_ECDSA
4207+
#endif /* linux >= 6.13.0 */
4208+
4209+
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 3, 0) && \
4210+
defined(CONFIG_CRYPTO_FIPS) && defined(CONFIG_CRYPTO_MANAGER)
4211+
/**
4212+
* note: ecdsa was not recognized as fips_allowed before linux v6.3
4213+
* in kernel crypto/testmgr.c, and will not pass the tests.
4214+
* */
4215+
#undef LINUXKM_LKCAPI_REGISTER_ECDSA
4216+
#endif /* linux < 6.3.0 && CONFIG_CRYPTO_FIPS && CONFIG_CRYPTO_MANAGER */
42084217

4209-
#if defined(LINUXKM_LKCAPI_REGISTER_ECDSA)
42104218
#if (defined(HAVE_ECC192) || defined(HAVE_ALL_CURVES)) && \
4211-
ECC_MIN_KEY_SZ <= 192
4219+
ECC_MIN_KEY_SZ <= 192 && !defined(CONFIG_CRYPTO_FIPS)
4220+
/* only register p192 if specifically enabled, and if not fips. */
42124221
#define LINUXKM_ECC192
42134222
#endif
4223+
#endif /* LINUXKM_LKCAPI_REGISTER_ECDSA */
4224+
4225+
#if defined (LINUXKM_LKCAPI_REGISTER_ECDSA)
42144226
#include "linuxkm/lkcapi_ecdsa_glue.c"
4215-
#endif
4227+
#endif /* LINUXKM_LKCAPI_REGISTER_ECDSA */
42164228

42174229
static int linuxkm_lkcapi_register(void)
42184230
{

0 commit comments

Comments
 (0)