crypto: export rsa with pkcs1.5 and pss mode

Add support for exporting RSA operations with PKCS#1 v1.5 and PSS padding schemes through the cryptodev interface.

This enables both traditional and modern RSA signature schemes:
- CRK_RSA_PKCS15_SIGN/VERIFY for PKCS#1 v1.5 padding
- CRK_RSA_PSS_SIGN/VERIFY for PSS padding

Signed-off-by: makejian <makejian@xiaomi.com>
This commit is contained in:
makejian 2024-11-05 16:06:59 +08:00 committed by Xiang Xiao
parent f3e2a7029d
commit 2878fa3c38
2 changed files with 44 additions and 17 deletions

View file

@ -558,6 +558,13 @@ static int cryptodev_key(FAR struct fcrypt *fcr, FAR struct crypt_kop *kop)
break;
}
return -EINVAL;
case CRK_RSA_PKCS15_SIGN:
if (in == 4 && out == 1)
{
break;
}
return -EINVAL;
case CRK_RSA_PKCS15_VERIFY:
if (in == 5 && out == 0)
@ -565,6 +572,20 @@ static int cryptodev_key(FAR struct fcrypt *fcr, FAR struct crypt_kop *kop)
break;
}
return -EINVAL;
case CRK_RSA_PSS_SIGN:
if (in == 3 && out == 1)
{
break;
}
return -EINVAL;
case CRK_RSA_PSS_VERIFY:
if (in == 4 && out == 0)
{
break;
}
return -EINVAL;
case CRK_ECDSA_SECP256R1_SIGN:
if (in == 2 && out == 2)

View file

@ -270,33 +270,39 @@ struct crypt_kop
#define CRK_DSA_VERIFY 3
#define CRK_DH_MAKE_PUBLIC 4
#define CRK_DH_COMPUTE_KEY 5
#define CRK_RSA_PKCS15_VERIFY 6
#define CRK_ECDSA_SECP256R1_SIGN 7
#define CRK_ECDSA_SECP256R1_VERIFY 8
#define CRK_ECDSA_SECP256R1_GENKEY 9
#define CRK_RSA_PKCS15_SIGN 6
#define CRK_RSA_PKCS15_VERIFY 7
#define CRK_RSA_PSS_SIGN 8
#define CRK_RSA_PSS_VERIFY 10
#define CRK_ECDSA_SECP256R1_SIGN 11
#define CRK_ECDSA_SECP256R1_VERIFY 12
#define CRK_ECDSA_SECP256R1_GENKEY 13
/* key management */
#define CRK_ALLOCATE_KEY 10 /* Request an available keyid from the driver */
#define CRK_VALIDATE_KEYID 11 /* Check the specified keyid is available */
#define CRK_IMPORT_KEY 12 /* Import key data into driver */
#define CRK_DELETE_KEY 13 /* Request to remove key with specified keyid */
#define CRK_EXPORT_KEY 14 /* Export raw data or private key if keypair */
#define CRK_EXPORT_PUBLIC_KEY 15 /* Export public key of keypair */
#define CRK_GENERATE_AES_KEY 16 /* Generate key data for AES with specified keyid */
#define CRK_GENERATE_RSA_KEY 17 /* Generate keypair for RSA with specified keyid */
#define CRK_GENERATE_SECP256R1_KEY 18 /* Generate keypair for ECC256 with specified keyid */
#define CRK_SAVE_KEY 19 /* Save key data into FLASH */
#define CRK_LOAD_KEY 20 /* Load key data from FLASH into RAM */
#define CRK_UNLOAD_KEY 21 /* Unload key data from RAM */
#define CRK_ALGORITHM_MAX 21 /* Keep updated */
#define CRK_ALLOCATE_KEY 14 /* Request an available keyid from the driver */
#define CRK_VALIDATE_KEYID 15 /* Check the specified keyid is available */
#define CRK_IMPORT_KEY 16 /* Import key data into driver */
#define CRK_DELETE_KEY 17 /* Request to remove key with specified keyid */
#define CRK_EXPORT_KEY 18 /* Export raw data or private key if keypair */
#define CRK_EXPORT_PUBLIC_KEY 19 /* Export public key of keypair */
#define CRK_GENERATE_AES_KEY 20 /* Generate key data for AES with specified keyid */
#define CRK_GENERATE_RSA_KEY 21 /* Generate keypair for RSA with specified keyid */
#define CRK_GENERATE_SECP256R1_KEY 22 /* Generate keypair for ECC256 with specified keyid */
#define CRK_SAVE_KEY 23 /* Save key data into FLASH */
#define CRK_LOAD_KEY 24 /* Load key data from FLASH into RAM */
#define CRK_UNLOAD_KEY 25 /* Unload key data from RAM */
#define CRK_ALGORITHM_MAX 25 /* Keep updated */
#define CRF_MOD_EXP (1 << CRK_MOD_EXP)
#define CRF_MOD_EXP_CRT (1 << CRK_MOD_EXP_CRT)
#define CRF_DSA_SIGN (1 << CRK_DSA_SIGN)
#define CRF_DSA_VERIFY (1 << CRK_DSA_VERIFY)
#define CRF_DH_COMPUTE_KEY (1 << CRK_DH_COMPUTE_KEY)
#define CRF_RSA_PKCS15_SIGN (1 << CRK_RSA_PKCS15_SIGN)
#define CRF_RSA_PKCS15_VERIFY (1 << CRK_RSA_PKCS15_VERIFY)
#define CRF_RSA_PSS_SIGN (1 << CRK_RSA_PSS_SIGN)
#define CRF_RSA_PSS_VERIFY (1 << CRK_RSA_PSS_VERIFY)
#define CRF_ECDSA_SECP256R1_SIGN (1 << CRK_ECDSA_SECP256R1_SIGN)
#define CRF_ECDSA_SECP256R1_VERIFY (1 << CRK_ECDSA_SECP256R1_VERIFY)
#define CRF_ECDSA_SECP256R1_GENKEY (1 << CRK_ECDSA_SECP256R1_GENKEY)