summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjulien.pierre.bugs%sun.com <devnull@localhost>2005-04-05 00:14:07 +0000
committerjulien.pierre.bugs%sun.com <devnull@localhost>2005-04-05 00:14:07 +0000
commit006a09819e0fbf53c766bc07ff4cf870c9a48652 (patch)
tree030f5fab58cdaa42adc7da0193924abd7dcf286c
parent3dcabedc0afdce2734358fe630e98e880c731bd9 (diff)
downloadnss-hg-006a09819e0fbf53c766bc07ff4cf870c9a48652.tar.gz
Fix for bug 287654 - check message value against RSA modulus. r=nelson
-rw-r--r--security/nss/lib/freebl/rsa.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/security/nss/lib/freebl/rsa.c b/security/nss/lib/freebl/rsa.c
index f04afdd88..d1ec6cfc5 100644
--- a/security/nss/lib/freebl/rsa.c
+++ b/security/nss/lib/freebl/rsa.c
@@ -315,7 +315,7 @@ RSA_PublicKeyOp(RSAPublicKey *key,
unsigned char *output,
const unsigned char *input)
{
- unsigned int modLen, expLen;
+ unsigned int modLen, expLen, offset;
mp_int n, e, m, c;
mp_err err = MP_OKAY;
SECStatus rv = SECSuccess;
@@ -348,7 +348,14 @@ RSA_PublicKeyOp(RSAPublicKey *key,
rv = SECFailure;
goto cleanup;
}
- /* 2. Represent message as integer in range [0..n-1] */
+ /* 2. check input out of range (needs to be in range [0..n-1]) */
+ offset = (key->modulus.data[0] == 0) ? 1 : 0; /* may be leading 0 */
+ if (memcmp(input, key->modulus.data + offset, modLen) >= 0) {
+ PORT_SetError(SEC_ERROR_INPUT_LEN);
+ rv = SECFailure;
+ goto cleanup;
+ }
+ /* 2 bis. Represent message as integer in range [0..n-1] */
CHECK_MPI_OK( mp_read_unsigned_octets(&m, input, modLen) );
/* 3. Compute c = m**e mod n */
#ifdef USE_MPI_EXPT_D