Skip to content

Commit bfab68f

Browse files
authored
Merge pull request wolfSSL#8646 from philljj/register_rsa
linuxkm: register rsa
2 parents 91cd0e9 + ff93e6d commit bfab68f

File tree

5 files changed

+1904
-16
lines changed

5 files changed

+1904
-16
lines changed

configure.ac

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9424,6 +9424,8 @@ then
94249424
'ecdsa') test "$ENABLED_ECC" != "no" || AC_MSG_ERROR([linuxkm-lkcapi-register ${lkcapi_alg}: ECDSA implementation not enabled.])
94259425
AM_CFLAGS="$AM_CFLAGS -DLINUXKM_LKCAPI_REGISTER_ECDSA" ;;
94269426
'ecdh') AM_CFLAGS="$AM_CFLAGS -DLINUXKM_LKCAPI_REGISTER_ECDH" ;;
9427+
'rsa') test "$ENABLED_RSA" != "no" || AC_MSG_ERROR([linuxkm-lkcapi-register ${lkcapi_alg}: RSA implementation not enabled.])
9428+
AM_CFLAGS="$AM_CFLAGS -DLINUXKM_LKCAPI_REGISTER_RSA" ;;
94279429
# disable options
94289430
'-cbc(aes)') AM_CFLAGS="$AM_CFLAGS -DLINUXKM_LKCAPI_DONT_REGISTER_AESCBC" ;;
94299431
'-cfb(aes)') AM_CFLAGS="$AM_CFLAGS -DLINUXKM_LKCAPI_DONT_REGISTER_AESCFB" ;;
@@ -9436,6 +9438,7 @@ then
94369438
'-ecb(aes)') AM_CFLAGS="$AM_CFLAGS -DLINUXKM_LKCAPI_DONT_REGISTER_AESECB" ;;
94379439
'-ecdsa') AM_CFLAGS="$AM_CFLAGS -DLINUXKM_LKCAPI_DONT_REGISTER_ECDSA" ;;
94389440
'-ecdh') AM_CFLAGS="$AM_CFLAGS -DLINUXKM_LKCAPI_DONT_REGISTER_ECDH" ;;
9441+
'-rsa') AM_CFLAGS="$AM_CFLAGS -DLINUXKM_LKCAPI_DONT_REGISTER_RSA" ;;
94399442
*) AC_MSG_ERROR([Unsupported LKCAPI algorithm "$lkcapi_alg".]) ;;
94409443
esac
94419444
done

linuxkm/include.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ EXTRA_DIST += m4/ax_linuxkm.m4 \
1616
linuxkm/lkcapi_glue.c \
1717
linuxkm/lkcapi_ecdsa_glue.c \
1818
linuxkm/lkcapi_ecdh_glue.c \
19+
linuxkm/lkcapi_rsa_glue.c \
1920
linuxkm/x86_vector_register_glue.c

linuxkm/linuxkm_wc_port.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -294,14 +294,9 @@
294294
#include <crypto/scatterwalk.h>
295295
#include <crypto/internal/aead.h>
296296
#include <crypto/internal/skcipher.h>
297+
#include <crypto/internal/akcipher.h>
297298
#include <crypto/internal/kpp.h>
298299

299-
#if defined(HAVE_ECC) && \
300-
(defined(LINUXKM_LKCAPI_REGISTER_ALL) || \
301-
defined(LINUXKM_LKCAPI_REGISTER_ECDSA))
302-
#include <crypto/internal/akcipher.h>
303-
#endif /* HAVE_ECC && (REGISTER_ALL || REGISTER_ECDSA) */
304-
305300
/* the LKCAPI assumes that expanded encrypt and decrypt keys will stay
306301
* loaded simultaneously, and the Linux in-tree implementations have two
307302
* AES key structs in each context, one for each direction. in

linuxkm/lkcapi_glue.c

Lines changed: 65 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4231,17 +4231,19 @@ static int linuxkm_test_aesecb(void) {
42314231
#undef LINUXKM_LKCAPI_REGISTER_ECDH
42324232
#endif /* HAVE_ECC */
42334233

4234-
#if defined (LINUXKM_LKCAPI_REGISTER_ECDSA)
4235-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 13, 0)
4236-
/**
4237-
* note: ecdsa supported with linux 6.12 and earlier for now, only.
4238-
* In linux 6.13, ecdsa changed from a struct akcipher_alg type to
4239-
* struct sig_alg type, and the sign/verify callbacks were removed
4240-
* from akcipher_alg.
4241-
* */
4242-
#undef LINUXKM_LKCAPI_REGISTER_ECDSA
4243-
#endif /* linux >= 6.13.0 */
4234+
#if !defined(NO_RSA)
4235+
#if (defined(LINUXKM_LKCAPI_REGISTER_ALL) && !defined(LINUXKM_LKCAPI_DONT_REGISTER_RSA)) && \
4236+
!defined(LINUXKM_LKCAPI_REGISTER_RSA)
4237+
#define LINUXKM_LKCAPI_REGISTER_RSA
4238+
#endif
4239+
#else
4240+
#undef LINUXKM_LKCAPI_REGISTER_RSA
4241+
#endif /* !NO_RSA */
42444242

4243+
/**
4244+
* extra checks on kernel version, and ecc sizes.
4245+
* */
4246+
#if defined (LINUXKM_LKCAPI_REGISTER_ECDSA)
42454247
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 3, 0) && \
42464248
defined(CONFIG_CRYPTO_FIPS) && defined(CONFIG_CRYPTO_MANAGER)
42474249
/**
@@ -4265,6 +4267,29 @@ static int linuxkm_test_aesecb(void) {
42654267
#endif
42664268
#endif
42674269

4270+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 13, 0)
4271+
/**
4272+
* notes:
4273+
* - ecdsa supported with linux 6.12 and earlier for now, only.
4274+
* - pkcs1pad rsa supported both before and after linux 6.13, but
4275+
* without sign/verify after linux 6.13.
4276+
*
4277+
* In linux 6.13 the sign/verify callbacks were removed from
4278+
* akcipher_alg, and ecdsa changed from a struct akcipher_alg type to
4279+
* struct sig_alg type.
4280+
*
4281+
* pkcs1pad rsa remained a struct akcipher_alg, but without sign/verify
4282+
* functionality.
4283+
* */
4284+
#if defined (LINUXKM_LKCAPI_REGISTER_ECDSA)
4285+
#undef LINUXKM_LKCAPI_REGISTER_ECDSA
4286+
#endif /* LINUXKM_LKCAPI_REGISTER_ECDSA */
4287+
4288+
#if defined (LINUXKM_LKCAPI_REGISTER_RSA)
4289+
#define LINUXKM_AKCIPHER_NO_SIGNVERIFY
4290+
#endif /* LINUXKM_LKCAPI_REGISTER_RSA */
4291+
#endif /* linux >= 6.13.0 */
4292+
42684293
#if defined (LINUXKM_LKCAPI_REGISTER_ECDSA)
42694294
#include "linuxkm/lkcapi_ecdsa_glue.c"
42704295
#endif /* LINUXKM_LKCAPI_REGISTER_ECDSA */
@@ -4273,6 +4298,10 @@ static int linuxkm_test_aesecb(void) {
42734298
#include "linuxkm/lkcapi_ecdh_glue.c"
42744299
#endif /* LINUXKM_LKCAPI_REGISTER_ECDH */
42754300

4301+
#if defined(LINUXKM_LKCAPI_REGISTER_RSA)
4302+
#include "linuxkm/lkcapi_rsa_glue.c"
4303+
#endif /* LINUXKM_LKCAPI_REGISTER_RSA */
4304+
42764305
static int linuxkm_lkcapi_register(void)
42774306
{
42784307
int ret = 0;
@@ -4388,6 +4417,20 @@ static int linuxkm_lkcapi_register(void)
43884417
linuxkm_test_ecdh_nist_p384);
43894418
#endif /* LINUXKM_LKCAPI_REGISTER_ECDH */
43904419

4420+
#ifdef LINUXKM_LKCAPI_REGISTER_RSA
4421+
#if defined(LINUXKM_DIRECT_RSA)
4422+
REGISTER_ALG(direct_rsa, crypto_register_akcipher, linuxkm_test_rsa);
4423+
#endif /* LINUXKM_DIRECT_RSA */
4424+
#ifndef NO_SHA256
4425+
REGISTER_ALG(pkcs1_sha256, crypto_register_akcipher,
4426+
linuxkm_test_pkcs1_sha256);
4427+
#endif /* !NO_SHA256 */
4428+
#ifdef WOLFSSL_SHA512
4429+
REGISTER_ALG(pkcs1_sha512, crypto_register_akcipher,
4430+
linuxkm_test_pkcs1_sha512);
4431+
#endif /* WOLFSSL_SHA512 */
4432+
#endif
4433+
43914434
#undef REGISTER_ALG
43924435

43934436
out:
@@ -4458,5 +4501,17 @@ static void linuxkm_lkcapi_unregister(void)
44584501
/* no ecdh p521 in kernel. */
44594502
#endif /* LINUXKM_LKCAPI_REGISTER_ECDH */
44604503

4504+
#ifdef LINUXKM_LKCAPI_REGISTER_RSA
4505+
#if defined(LINUXKM_DIRECT_RSA)
4506+
UNREGISTER_ALG(direct_rsa, crypto_unregister_akcipher);
4507+
#endif /* LINUXKM_DIRECT_RSA */
4508+
#ifndef NO_SHA256
4509+
UNREGISTER_ALG(pkcs1_sha256, crypto_unregister_akcipher);
4510+
#endif /* !NO_SHA256 */
4511+
#ifdef WOLFSSL_SHA512
4512+
UNREGISTER_ALG(pkcs1_sha512, crypto_unregister_akcipher);
4513+
#endif /* WOLFSSL_SHA512 */
4514+
#endif /* LINUXKM_LKCAPI_REGISTER_RSA */
4515+
44614516
#undef UNREGISTER_ALG
44624517
}

0 commit comments

Comments
 (0)