Merge pull request #8915 from philljj/linuxkm_rsa_fix_sig_callbacks

linuxkm rsa: set sig_alg max_size and digest_size callbacks.
pull/8924/head
Daniel Pouzzner 2025-06-25 08:28:04 -05:00 committed by GitHub
commit 1c1c556e5e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 22 additions and 7 deletions

View File

@ -1254,12 +1254,9 @@ pkcs1pad_verify_out:
}
#else
/* note on sig_alg callbacks:
* crypto_register_sig() errors out if alg->key_size is not set.
*
* alg->key_size: required
* alg->max_size: optional (alg->max_size = alg->key_size)
* alg->digest_size: optional (alg->digest_size = alg->key_size)
/* Returns the rsa key size:
* linux kernel version < 6.16: returns key size in bytes.
* linux kernel version >= 6.16: returns key size in bits.
* */
static unsigned int km_pkcs1_key_size(struct crypto_sig *tfm)
{
@ -1267,7 +1264,11 @@ static unsigned int km_pkcs1_key_size(struct crypto_sig *tfm)
ctx = crypto_sig_ctx(tfm);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 16, 0)
return (unsigned int) ctx->key_len * WOLFSSL_BIT_SIZE;
#else
return (unsigned int) ctx->key_len;
#endif /* linux >= 6.16 */
}
/*
@ -3091,10 +3092,24 @@ static int linuxkm_test_pkcs1_driver(const char * driver, int nbits,
}
{
/* all three of these should return the same value for pkcs1. */
/* The behavior of crypto_sig_Xsize (X= max, key, digest) changed
* at linux kernel v6.16:
* < 6.16: all three should return the same value (in bytes).
* >= 6.16: keysize is in bits, maxsize and digestsize in bytes. */
unsigned int maxsize = crypto_sig_maxsize(tfm);
unsigned int keysize = crypto_sig_keysize(tfm);
unsigned int digestsize = crypto_sig_digestsize(tfm);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 16, 0)
keysize = ((keysize + WOLFSSL_BIT_SIZE - 1) / WOLFSSL_BIT_SIZE);
#endif /* linux >= 6.16 */
#ifdef WOLFKM_DEBUG_RSA
pr_info("info: crypto_sig_{max, key, digest}size: "
"{%d, %d, %d}\n",
maxsize, keysize, digestsize);
#endif /* WOLFKM_DEBUG_RSA */
if (maxsize != key_len ||
keysize != key_len ||
digestsize != key_len) {