cryptodev: move RSA padding into separate struct

- move RSA padding into separate struct.
More padding members should be added into padding,
therefore having separate struct for padding parameters will
make this more readable.

Signed-off-by: Arek Kusztal <arkadiuszx.kusztal@intel.com>
Acked-by: Fan Zhang <roy.fan.zhang@intel.com>
Acked-by: Akhil Goyal <gakhil@marvell.com>
This commit is contained in:
Arek Kusztal 2022-06-01 10:02:47 +01:00 committed by Akhil Goyal
parent 7d89af1dad
commit db8d2a2c99
7 changed files with 63 additions and 57 deletions

View File

@ -94,7 +94,7 @@ queue_ops_rsa_sign_verify(void *sess)
asym_op->rsa.message.length = rsaplaintext.len;
asym_op->rsa.sign.length = 0;
asym_op->rsa.sign.data = output_buf;
asym_op->rsa.pad = RTE_CRYPTO_RSA_PADDING_PKCS1_5;
asym_op->rsa.padding.type = RTE_CRYPTO_RSA_PADDING_PKCS1_5;
debug_hexdump(stdout, "message", asym_op->rsa.message.data,
asym_op->rsa.message.length);
@ -126,7 +126,7 @@ queue_ops_rsa_sign_verify(void *sess)
/* Verify sign */
asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
asym_op->rsa.pad = RTE_CRYPTO_RSA_PADDING_PKCS1_5;
asym_op->rsa.padding.type = RTE_CRYPTO_RSA_PADDING_PKCS1_5;
/* Process crypto operation */
if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
@ -185,7 +185,7 @@ queue_ops_rsa_enc_dec(void *sess)
asym_op->rsa.cipher.data = cipher_buf;
asym_op->rsa.cipher.length = 0;
asym_op->rsa.message.length = rsaplaintext.len;
asym_op->rsa.pad = RTE_CRYPTO_RSA_PADDING_PKCS1_5;
asym_op->rsa.padding.type = RTE_CRYPTO_RSA_PADDING_PKCS1_5;
debug_hexdump(stdout, "message", asym_op->rsa.message.data,
asym_op->rsa.message.length);
@ -217,7 +217,7 @@ queue_ops_rsa_enc_dec(void *sess)
asym_op = result_op->asym;
asym_op->rsa.message.length = 0;
asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_DECRYPT;
asym_op->rsa.pad = RTE_CRYPTO_RSA_PADDING_PKCS1_5;
asym_op->rsa.padding.type = RTE_CRYPTO_RSA_PADDING_PKCS1_5;
/* Process crypto operation */
if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
@ -414,7 +414,7 @@ test_cryptodev_asym_op(struct crypto_testsuite_params_asym *ts_params,
}
xform_tc.rsa.key_type = key_type;
op->asym->rsa.pad = data_tc->rsa_data.padding;
op->asym->rsa.padding.type = data_tc->rsa_data.padding;
if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_ENCRYPT) {
asym_op->rsa.message.data = data_tc->rsa_data.pt.data;

View File

@ -327,7 +327,7 @@ cpt_rsa_prep(struct asym_op_params *rsa_params,
/* Result buffer */
rlen = mod_len;
if (rsa_op.pad == RTE_CRYPTO_RSA_PADDING_NONE) {
if (rsa_op.padding.type == RTE_CRYPTO_RSA_PADDING_NONE) {
/* Use mod_exp operation for no_padding type */
vq_cmd_w0.s.opcode.minor = CPT_MINOR_OP_MODEX;
vq_cmd_w0.s.param2 = exp_len;
@ -412,7 +412,7 @@ cpt_rsa_crt_prep(struct asym_op_params *rsa_params,
/* Result buffer */
rlen = mod_len;
if (rsa_op.pad == RTE_CRYPTO_RSA_PADDING_NONE) {
if (rsa_op.padding.type == RTE_CRYPTO_RSA_PADDING_NONE) {
/*Use mod_exp operation for no_padding type */
vq_cmd_w0.s.opcode.minor = CPT_MINOR_OP_MODEX_CRT;
} else {

View File

@ -288,7 +288,7 @@ cnxk_ae_rsa_prep(struct rte_crypto_op *op, struct roc_ae_buf_ptr *meta_buf,
dptr += in_size;
dlen = total_key_len + in_size;
if (rsa_op.pad == RTE_CRYPTO_RSA_PADDING_NONE) {
if (rsa_op.padding.type == RTE_CRYPTO_RSA_PADDING_NONE) {
/* Use mod_exp operation for no_padding type */
w4.s.opcode_minor = ROC_AE_MINOR_OP_MODEX;
w4.s.param2 = exp_len;
@ -347,7 +347,7 @@ cnxk_ae_rsa_crt_prep(struct rte_crypto_op *op, struct roc_ae_buf_ptr *meta_buf,
dptr += in_size;
dlen = total_key_len + in_size;
if (rsa_op.pad == RTE_CRYPTO_RSA_PADDING_NONE) {
if (rsa_op.padding.type == RTE_CRYPTO_RSA_PADDING_NONE) {
/*Use mod_exp operation for no_padding type */
w4.s.opcode_minor = ROC_AE_MINOR_OP_MODEX_CRT;
} else {
@ -675,7 +675,7 @@ cnxk_ae_dequeue_rsa_op(struct rte_crypto_op *cop, uint8_t *rptr,
memcpy(rsa->cipher.data, rptr, rsa->cipher.length);
break;
case RTE_CRYPTO_ASYM_OP_DECRYPT:
if (rsa->pad == RTE_CRYPTO_RSA_PADDING_NONE) {
if (rsa->padding.type == RTE_CRYPTO_RSA_PADDING_NONE) {
rsa->message.length = rsa_ctx->n.length;
memcpy(rsa->message.data, rptr, rsa->message.length);
} else {
@ -695,7 +695,7 @@ cnxk_ae_dequeue_rsa_op(struct rte_crypto_op *cop, uint8_t *rptr,
memcpy(rsa->sign.data, rptr, rsa->sign.length);
break;
case RTE_CRYPTO_ASYM_OP_VERIFY:
if (rsa->pad == RTE_CRYPTO_RSA_PADDING_NONE) {
if (rsa->padding.type == RTE_CRYPTO_RSA_PADDING_NONE) {
rsa->sign.length = rsa_ctx->n.length;
memcpy(rsa->sign.data, rptr, rsa->sign.length);
} else {

View File

@ -736,7 +736,7 @@ otx_cpt_asym_rsa_op(struct rte_crypto_op *cop, struct cpt_request_info *req,
memcpy(rsa->cipher.data, req->rptr, rsa->cipher.length);
break;
case RTE_CRYPTO_ASYM_OP_DECRYPT:
if (rsa->pad == RTE_CRYPTO_RSA_PADDING_NONE)
if (rsa->padding.type == RTE_CRYPTO_RSA_PADDING_NONE)
rsa->message.length = rsa_ctx->n.length;
else {
/* Get length of decrypted output */
@ -753,7 +753,7 @@ otx_cpt_asym_rsa_op(struct rte_crypto_op *cop, struct cpt_request_info *req,
memcpy(rsa->sign.data, req->rptr, rsa->sign.length);
break;
case RTE_CRYPTO_ASYM_OP_VERIFY:
if (rsa->pad == RTE_CRYPTO_RSA_PADDING_NONE)
if (rsa->padding.type == RTE_CRYPTO_RSA_PADDING_NONE)
rsa->sign.length = rsa_ctx->n.length;
else {
/* Get length of decrypted output */

View File

@ -1896,7 +1896,7 @@ process_openssl_rsa_op(struct rte_crypto_op *cop,
int ret = 0;
struct rte_crypto_asym_op *op = cop->asym;
RSA *rsa = sess->u.r.rsa;
uint32_t pad = (op->rsa.pad);
uint32_t pad = (op->rsa.padding.type);
uint8_t *tmp;
cop->status = RTE_CRYPTO_OP_STATUS_SUCCESS;

View File

@ -332,7 +332,7 @@ rsa_set_pub_input(struct rte_crypto_asym_op *asym_op,
alg_bytesize = qat_function.bytesize;
if (asym_op->rsa.op_type == RTE_CRYPTO_ASYM_OP_ENCRYPT) {
switch (asym_op->rsa.pad) {
switch (asym_op->rsa.padding.type) {
case RTE_CRYPTO_RSA_PADDING_NONE:
SET_PKE_LN(asym_op->rsa.message, alg_bytesize, 0);
break;
@ -344,7 +344,7 @@ rsa_set_pub_input(struct rte_crypto_asym_op *asym_op,
}
HEXDUMP("RSA Message", cookie->input_array[0], alg_bytesize);
} else {
switch (asym_op->rsa.pad) {
switch (asym_op->rsa.padding.type) {
case RTE_CRYPTO_RSA_PADDING_NONE:
SET_PKE_LN(asym_op->rsa.sign, alg_bytesize, 0);
break;
@ -430,7 +430,7 @@ rsa_set_priv_input(struct rte_crypto_asym_op *asym_op,
if (asym_op->rsa.op_type ==
RTE_CRYPTO_ASYM_OP_DECRYPT) {
switch (asym_op->rsa.pad) {
switch (asym_op->rsa.padding.type) {
case RTE_CRYPTO_RSA_PADDING_NONE:
SET_PKE_LN(asym_op->rsa.cipher, alg_bytesize, 0);
HEXDUMP("RSA ciphertext", cookie->input_array[0],
@ -444,7 +444,7 @@ rsa_set_priv_input(struct rte_crypto_asym_op *asym_op,
} else if (asym_op->rsa.op_type ==
RTE_CRYPTO_ASYM_OP_SIGN) {
switch (asym_op->rsa.pad) {
switch (asym_op->rsa.padding.type) {
case RTE_CRYPTO_RSA_PADDING_NONE:
SET_PKE_LN(asym_op->rsa.message, alg_bytesize, 0);
HEXDUMP("RSA text to be signed", cookie->input_array[0],
@ -503,7 +503,7 @@ rsa_collect(struct rte_crypto_asym_op *asym_op,
} else {
uint8_t *rsa_result = asym_op->rsa.cipher.data;
switch (asym_op->rsa.pad) {
switch (asym_op->rsa.padding.type) {
case RTE_CRYPTO_RSA_PADDING_NONE:
rte_memcpy(rsa_result,
cookie->output_array[0],
@ -521,7 +521,7 @@ rsa_collect(struct rte_crypto_asym_op *asym_op,
if (asym_op->rsa.op_type == RTE_CRYPTO_ASYM_OP_DECRYPT) {
uint8_t *rsa_result = asym_op->rsa.message.data;
switch (asym_op->rsa.pad) {
switch (asym_op->rsa.padding.type) {
case RTE_CRYPTO_RSA_PADDING_NONE:
rte_memcpy(rsa_result,
cookie->output_array[0],

View File

@ -235,6 +235,47 @@ struct rte_crypto_rsa_priv_key_qt {
/**< the CRT coefficient */
};
/**
* RSA padding type
*/
struct rte_crypto_rsa_padding {
enum rte_crypto_rsa_padding_type type;
/**< RSA padding scheme to be used for transform */
enum rte_crypto_auth_algorithm md;
/**<
* RSA padding hash algorithm
* Valid hash algorithms are:
* MD5, SHA1, SHA224, SHA256, SHA384, SHA512
*
* When a specific padding type is selected, the following rules apply:
* - RTE_CRYPTO_RSA_PADDING_NONE:
* This field is ignored by the PMD
*
* - RTE_CRYPTO_RSA_PADDING_PKCS1_5:
* When signing an operation this field is used to determine value
* of the DigestInfo structure, therefore specifying which algorithm
* was used to create the message digest.
* When doing encryption/decryption this field is ignored for this
* padding type.
*
* - RTE_CRYPTO_RSA_PADDING_OAEP
* This field shall be set with the hash algorithm used
* in the padding scheme
*
* - RTE_CRYPTO_RSA_PADDING_PSS
* This field shall be set with the hash algorithm used
* in the padding scheme (and to create the input message digest)
*/
enum rte_crypto_auth_algorithm mgf1md;
/**<
* Hash algorithm to be used for mask generation if the
* padding scheme is either OAEP or PSS. If the padding
* scheme is unspecified a data hash algorithm is used
* for mask generation. Valid hash algorithms are:
* MD5, SHA1, SHA224, SHA256, SHA384, SHA512
*/
};
/**
* Asymmetric RSA transform data
*
@ -391,43 +432,8 @@ struct rte_crypto_rsa_op_param {
* All data is in Octet-string network byte order format.
*/
enum rte_crypto_rsa_padding_type pad;
/**< RSA padding scheme to be used for transform */
enum rte_crypto_auth_algorithm md;
/**<
* RSA padding hash algorithm
* Valid hash algorithms are:
* MD5, SHA1, SHA224, SHA256, SHA384, SHA512
*
* When a specific padding type is selected, the following rule apply:
* - RTE_CRYPTO_RSA_PADDING_NONE:
* This field is ignored by the PMD
*
* - RTE_CRYPTO_RSA_PADDING_PKCS1_5:
* For sign operation, this field is used to determine value
* of the DigestInfo structure, therefore specifying which algorithm
* was used to create the message digest.
* For encryption/decryption, this field is ignored for this
* padding type.
*
* - RTE_CRYPTO_RSA_PADDING_OAEP
* This field shall be set with the hash algorithm used
* in the padding scheme
*
* - RTE_CRYPTO_RSA_PADDING_PSS
* This field shall be set with the hash algorithm used
* in the padding scheme (and to create the input message digest)
*/
enum rte_crypto_auth_algorithm mgf1md;
/**<
* Hash algorithm to be used for mask generation if
* padding scheme is either OAEP or PSS. If padding
* scheme is unspecified data hash algorithm is used
* for mask generation. Valid hash algorithms are:
* MD5, SHA1, SHA224, SHA256, SHA384, SHA512
*/
struct rte_crypto_rsa_padding padding;
/**< RSA padding information */
};
/**