Skip to content

Commit

Permalink
pkcs15-crypt: Use correct PKCS#1 v1.5 padding type
Browse files Browse the repository at this point in the history
  • Loading branch information
xhanulik authored and frankmorgner committed Mar 20, 2024
1 parent d1d0aed commit 03b7969
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/tools/pkcs15-crypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ static int sign(struct sc_pkcs15_object *obj)
{
u8 buf[1024], out[1024];
struct sc_pkcs15_prkey_info *key = (struct sc_pkcs15_prkey_info *) obj->data;
int r;
int r, flags;
size_t c, len;

if (opt_input == NULL) {
Expand All @@ -233,7 +233,8 @@ static int sign(struct sc_pkcs15_object *obj)
return SC_ERROR_NOT_SUPPORTED;
}

r = sc_pkcs15_compute_signature(p15card, obj, opt_crypt_flags, buf, c, out, len, NULL);
flags = opt_crypt_flags & ~SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02;
r = sc_pkcs15_compute_signature(p15card, obj, flags, buf, c, out, len, NULL);
if (r < 0) {
fprintf(stderr, "Compute signature failed: %s\n", sc_strerror(r));
return 1;
Expand Down Expand Up @@ -265,7 +266,7 @@ static int sign(struct sc_pkcs15_object *obj)
static int decipher(struct sc_pkcs15_object *obj)
{
u8 buf[1024], out[1024];
int r, len;
int r, len, flags;
size_t c;

if (opt_input == NULL) {
Expand All @@ -281,7 +282,8 @@ static int decipher(struct sc_pkcs15_object *obj)
return SC_ERROR_NOT_SUPPORTED;
}

r = sc_pkcs15_decipher(p15card, obj, opt_crypt_flags & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02, buf, c, out, len, NULL);
flags = opt_crypt_flags & ~SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01;
r = sc_pkcs15_decipher(p15card, obj, flags, buf, c, out, len, NULL);
if (r < 0) {
fprintf(stderr, "Decrypt failed: %s\n", sc_strerror(r));
return 1;
Expand Down

0 comments on commit 03b7969

Please sign in to comment.