From 9b7605ff3ceb6e799e106ff718465626e739486f Mon Sep 17 00:00:00 2001 From: alegon01 Date: Fri, 1 Feb 2019 15:27:55 +0100 Subject: [PATCH] Add support for CKM_RSA_PKCS_OAEP in encrypt_decrypt(). Only set the OAEP params for CKM_RSA_PKCS_OAEP, I had an issue with a variable not initialized. --- src/tools/pkcs11-tool.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/tools/pkcs11-tool.c b/src/tools/pkcs11-tool.c index 2f4497f3..aa986ff4 100644 --- a/src/tools/pkcs11-tool.c +++ b/src/tools/pkcs11-tool.c @@ -5334,18 +5334,6 @@ static int encrypt_decrypt(CK_SESSION_HANDLE session, oaep_params.mgf = CKG_MGF1_SHA1; break; } - break; - case CKM_RSA_PKCS: - mech.pParameter = NULL; - mech.ulParameterLen = 0; - break; - default: - util_fatal("Mechanism %s illegal or not supported\n", p11_mechanism_to_name(mech_type)); - } - - - /* If an RSA-OAEP mechanism, it needs parameters */ - if (oaep_params.hashAlg) { if (opt_mgf != 0) oaep_params.mgf = opt_mgf; @@ -5354,6 +5342,7 @@ static int encrypt_decrypt(CK_SESSION_HANDLE session, oaep_params.pSourceData = NULL; /* PKCS#11 standard: this must be NULLPTR */ oaep_params.ulSourceDataLen = 0; /* PKCS#11 standard: this must be 0 */ + /* If an RSA-OAEP mechanism, it needs parameters */ mech.pParameter = &oaep_params; mech.ulParameterLen = sizeof(oaep_params); @@ -5363,10 +5352,15 @@ static int encrypt_decrypt(CK_SESSION_HANDLE session, oaep_params.source, oaep_params.pSourceData, oaep_params.ulSourceDataLen); - + break; + case CKM_RSA_PKCS: + mech.pParameter = NULL; + mech.ulParameterLen = 0; + break; + default: + util_fatal("Mechanism %s illegal or not supported\n", p11_mechanism_to_name(mech_type)); } - mech.mechanism = mech_type; rv = p11->C_DecryptInit(session, &mech, privKeyObject); if (rv == CKR_MECHANISM_INVALID || rv == CKR_MECHANISM_PARAM_INVALID) {