Skip to content

Commit 1c1c556

Browse files
authored
Merge pull request #8915 from philljj/linuxkm_rsa_fix_sig_callbacks
linuxkm rsa: set sig_alg max_size and digest_size callbacks.
2 parents e223da4 + 1e0e493 commit 1c1c556

1 file changed

Lines changed: 22 additions & 7 deletions

File tree

linuxkm/lkcapi_rsa_glue.c

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,20 +1254,21 @@ static int km_pkcs1pad_verify(struct akcipher_request *req)
12541254
}
12551255
#else
12561256

1257-
/* note on sig_alg callbacks:
1258-
* crypto_register_sig() errors out if alg->key_size is not set.
1259-
*
1260-
* alg->key_size: required
1261-
* alg->max_size: optional (alg->max_size = alg->key_size)
1262-
* alg->digest_size: optional (alg->digest_size = alg->key_size)
1257+
/* Returns the rsa key size:
1258+
* linux kernel version < 6.16: returns key size in bytes.
1259+
* linux kernel version >= 6.16: returns key size in bits.
12631260
* */
12641261
static unsigned int km_pkcs1_key_size(struct crypto_sig *tfm)
12651262
{
12661263
struct km_rsa_ctx * ctx = NULL;
12671264

12681265
ctx = crypto_sig_ctx(tfm);
12691266

1267+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 16, 0)
1268+
return (unsigned int) ctx->key_len * WOLFSSL_BIT_SIZE;
1269+
#else
12701270
return (unsigned int) ctx->key_len;
1271+
#endif /* linux >= 6.16 */
12711272
}
12721273

12731274
/*
@@ -3091,10 +3092,24 @@ static int linuxkm_test_pkcs1_driver(const char * driver, int nbits,
30913092
}
30923093

30933094
{
3094-
/* all three of these should return the same value for pkcs1. */
3095+
/* The behavior of crypto_sig_Xsize (X= max, key, digest) changed
3096+
* at linux kernel v6.16:
3097+
* < 6.16: all three should return the same value (in bytes).
3098+
* >= 6.16: keysize is in bits, maxsize and digestsize in bytes. */
30953099
unsigned int maxsize = crypto_sig_maxsize(tfm);
30963100
unsigned int keysize = crypto_sig_keysize(tfm);
30973101
unsigned int digestsize = crypto_sig_digestsize(tfm);
3102+
3103+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 16, 0)
3104+
keysize = ((keysize + WOLFSSL_BIT_SIZE - 1) / WOLFSSL_BIT_SIZE);
3105+
#endif /* linux >= 6.16 */
3106+
3107+
#ifdef WOLFKM_DEBUG_RSA
3108+
pr_info("info: crypto_sig_{max, key, digest}size: "
3109+
"{%d, %d, %d}\n",
3110+
maxsize, keysize, digestsize);
3111+
#endif /* WOLFKM_DEBUG_RSA */
3112+
30983113
if (maxsize != key_len ||
30993114
keysize != key_len ||
31003115
digestsize != key_len) {

0 commit comments

Comments
 (0)