Skip to content

Commit d074371

Browse files
committed
Remove padding when doing ECDSA signing via pkcs11
1 parent 31ba4d5 commit d074371

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

Diff for: pkcs11/util_pkcs11.c

+13-8
Original file line numberDiff line numberDiff line change
@@ -3225,16 +3225,21 @@ CK_RV apply_sign_mechanism_finalize(yubihsm_pkcs11_op_info *op_info) {
32253225
}
32263226

32273227
if (is_ECDSA_sign_mechanism(op_info->mechanism.mechanism)) {
3228-
if (op_info->buffer_length < op_info->op.sign.sig_len / 2) {
3229-
uint16_t padding =
3230-
(op_info->op.sign.sig_len / 2) - op_info->buffer_length;
3231-
memmove(op_info->buffer + padding, op_info->buffer,
3232-
op_info->buffer_length);
3233-
memset(op_info->buffer, 0, padding);
3234-
op_info->buffer_length += padding;
3235-
} else if (op_info->buffer_length > op_info->op.sign.sig_len / 2) {
3228+
3229+
if (op_info->buffer_length > op_info->op.sign.sig_len / 2) {
32363230
op_info->buffer_length = op_info->op.sign.sig_len / 2;
32373231
}
3232+
3233+
// if (op_info->buffer_length < op_info->op.sign.sig_len / 2) {
3234+
// uint16_t padding =
3235+
// (op_info->op.sign.sig_len / 2) - op_info->buffer_length;
3236+
// memmove(op_info->buffer + padding, op_info->buffer,
3237+
// op_info->buffer_length);
3238+
// memset(op_info->buffer, 0, padding);
3239+
// op_info->buffer_length += padding;
3240+
// } else if (op_info->buffer_length > op_info->op.sign.sig_len / 2) {
3241+
// op_info->buffer_length = op_info->op.sign.sig_len / 2;
3242+
// }
32383243
}
32393244

32403245
// TODO(adma): check if more steps are need for PSS or ECDSA

Diff for: resources/tests/bash/opensc_test.sh

+12-2
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,15 @@ echo "this is test data" > data.txt
3737
### because it will not look for a key by label/alias. However, specifying an object to delete by its label/alias seems
3838
### to work just fine.
3939

40-
EC_CURVES=("secp224r1" "secp256r1" "secp384r1" "secp256k1" "brainpoolP256r1" "brainpoolP384r1" "brainpoolP512r1")
41-
#EC_CURVES=("secp224r1" "secp256r1" "secp384r1" "secp521r1" "secp256k1" "brainpoolP256r1" "brainpoolP384r1" "brainpoolP512r1")
40+
#EC_CURVES=("secp224r1" "secp256r1" "secp384r1" "secp256k1" "brainpoolP256r1" "brainpoolP384r1" "brainpoolP512r1")
41+
EC_CURVES=("secp224r1" "secp256r1" "secp384r1" "secp521r1" "secp256k1" "brainpoolP256r1" "brainpoolP384r1" "brainpoolP512r1")
4242

4343
for curve in "${EC_CURVES[@]}"; do
44+
45+
echo "**********************************"
46+
echo " $curve"
47+
echo "**********************************"
48+
4449
# # Generate key
4550
test "pkcs11-tool --module $MODULE --login --pin 0001password --keypairgen --id 1 --key-type EC:$curve" " Generate EC key with curve $curve"
4651
test "pkcs11-tool --module $MODULE --login --pin 0001password --read-object --id 1 --type pubkey --output-file pubkey.der" " Get public key of generated key"
@@ -93,6 +98,11 @@ test "openssl dgst -sha384 -binary -out data.sha384 data.txt" " Hash data with
9398
test "openssl dgst -sha512 -binary -out data.sha512 data.txt" " Hash data with SHA512 and OpenSSL"
9499

95100
for len in "${RSA_LENGTHS[@]}"; do
101+
102+
echo "**********************************"
103+
echo " RSA$len"
104+
echo "**********************************"
105+
96106
# Generate key
97107
test "pkcs11-tool --module $MODULE --login --pin 0001password --keypairgen --id 1 --key-type rsa:$len --usage-sign --usage-decrypt" " Generate RSA$len key"
98108
test "pkcs11-tool --module $MODULE --login --pin 0001password --read-object --id 1 --type pubkey --output-file pubkey.der" " Get public key of generated key"

0 commit comments

Comments
 (0)