Skip to content
This repository has been archived by the owner on Nov 11, 2024. It is now read-only.

Commit

Permalink
Fix rsa oaep key length check before decryption
Browse files Browse the repository at this point in the history
  • Loading branch information
babelouest committed Aug 20, 2022
1 parent 775a8e8 commit dd528b3
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/jwe.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,11 @@ rsa_oaep_sha1_decrypt(const struct rsa_private_key *key,
int res;
struct sha1_ctx ctx;

if (nettle_mpz_sizeinbase_256_u (gibberish) > key->size ||
key->size < (2*SHA1_DIGEST_SIZE)+2) {
return 0;
}

mpz_init(m);
rsa_compute_root(key, m, gibberish);

Expand All @@ -384,6 +389,11 @@ rsa_oaep_sha256_decrypt(const struct rsa_private_key *key,
int res;
struct sha256_ctx ctx;

if (nettle_mpz_sizeinbase_256_u (gibberish) > key->size ||
key->size < (2*SHA1_DIGEST_SIZE)+2) {
return 0;
}

mpz_init(m);
rsa_compute_root(key, m, gibberish);

Expand Down

0 comments on commit dd528b3

Please sign in to comment.