Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PKCS#1 encoding function to correctly detect padding type #3075

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/tools/pkcs15-crypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,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 @@ -238,7 +238,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 @@ -270,7 +271,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 @@ -286,7 +287,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
Loading