allow input-data pointer to be NULL
If we allow the length to be 0, we should also prepare for the case where the user doesn't want to provide a valid input-data pointer. Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
This commit is contained in:
parent
af5fffb8a7
commit
effe0e8e21
@ -33,7 +33,7 @@ int pkcs_1_oaep_encode(const unsigned char *msg, unsigned long msglen,
|
||||
unsigned long hLen, x, y, modulus_len;
|
||||
int err;
|
||||
|
||||
LTC_ARGCHK(msg != NULL);
|
||||
LTC_ARGCHK((msglen == 0) || (msg != NULL));
|
||||
LTC_ARGCHK(out != NULL);
|
||||
LTC_ARGCHK(outlen != NULL);
|
||||
|
||||
@ -95,9 +95,11 @@ int pkcs_1_oaep_encode(const unsigned char *msg, unsigned long msglen,
|
||||
/* 0x01 byte */
|
||||
DB[x++] = 0x01;
|
||||
|
||||
/* message (length = msglen) */
|
||||
XMEMCPY(DB+x, msg, msglen);
|
||||
x += msglen;
|
||||
if (msglen != 0) {
|
||||
/* message (length = msglen) */
|
||||
XMEMCPY(DB+x, msg, msglen);
|
||||
x += msglen;
|
||||
}
|
||||
|
||||
/* now choose a random seed */
|
||||
if (prng_descriptor[prng_idx].read(seed, hLen, prng) != hLen) {
|
||||
|
@ -35,6 +35,10 @@ int pkcs_1_v1_5_encode(const unsigned char *msg,
|
||||
unsigned char *ps;
|
||||
int result;
|
||||
|
||||
LTC_ARGCHK((msglen == 0) || (msg != NULL));
|
||||
LTC_ARGCHK(out != NULL);
|
||||
LTC_ARGCHK(outlen != NULL);
|
||||
|
||||
/* valid block_type? */
|
||||
if ((block_type != LTC_PKCS_1_EMSA) &&
|
||||
(block_type != LTC_PKCS_1_EME)) {
|
||||
@ -88,7 +92,9 @@ int pkcs_1_v1_5_encode(const unsigned char *msg,
|
||||
out[0] = 0x00;
|
||||
out[1] = (unsigned char)block_type; /* block_type 1 or 2 */
|
||||
out[2 + ps_len] = 0x00;
|
||||
XMEMCPY(&out[2 + ps_len + 1], msg, msglen);
|
||||
if (msglen != 0) {
|
||||
XMEMCPY(&out[2 + ps_len + 1], msg, msglen);
|
||||
}
|
||||
*outlen = modulus_len;
|
||||
|
||||
result = CRYPT_OK;
|
||||
|
@ -34,7 +34,7 @@ int rsa_encrypt_key_ex(const unsigned char *in, unsigned long inlen,
|
||||
unsigned long modulus_bitlen, modulus_bytelen, x;
|
||||
int err;
|
||||
|
||||
LTC_ARGCHK(in != NULL);
|
||||
LTC_ARGCHK((inlen == 0) || (in != NULL));
|
||||
LTC_ARGCHK(out != NULL);
|
||||
LTC_ARGCHK(outlen != NULL);
|
||||
LTC_ARGCHK(key != NULL);
|
||||
|
@ -500,7 +500,7 @@ print_hex("q", tmp, len);
|
||||
|
||||
/* encrypt the key (without lparam) */
|
||||
for (cnt = 0; cnt < 4; cnt++) {
|
||||
for (rsa_msgsize = 1; rsa_msgsize <= 86; rsa_msgsize++) {
|
||||
for (rsa_msgsize = 0; rsa_msgsize <= 86; rsa_msgsize++) {
|
||||
/* make a random key/msg */
|
||||
ENSURE(yarrow_read(in, rsa_msgsize, &yarrow_prng) == rsa_msgsize);
|
||||
|
||||
@ -523,10 +523,10 @@ print_hex("q", tmp, len);
|
||||
}
|
||||
|
||||
/* encrypt the key (with lparam) */
|
||||
for (rsa_msgsize = 1; rsa_msgsize <= 86; rsa_msgsize++) {
|
||||
for (rsa_msgsize = 0; rsa_msgsize <= 86; rsa_msgsize++) {
|
||||
len = sizeof(out);
|
||||
len2 = rsa_msgsize;
|
||||
DO(rsa_encrypt_key(in, rsa_msgsize, out, &len, lparam, sizeof(lparam), &yarrow_prng, prng_idx, hash_idx, &key));
|
||||
DO(rsa_encrypt_key(rsa_msgsize ? in : NULL, rsa_msgsize, out, &len, lparam, sizeof(lparam), &yarrow_prng, prng_idx, hash_idx, &key));
|
||||
/* change a byte */
|
||||
out[8] ^= 1;
|
||||
SHOULD_FAIL(rsa_decrypt_key(out, len, tmp, &len2, lparam, sizeof(lparam), hash_idx, &stat2, &key));
|
||||
@ -542,7 +542,7 @@ print_hex("q", tmp, len);
|
||||
}
|
||||
|
||||
/* encrypt the key PKCS #1 v1.5 (payload from 1 to 117 bytes) */
|
||||
for (rsa_msgsize = 1; rsa_msgsize <= 117; rsa_msgsize++) {
|
||||
for (rsa_msgsize = 0; rsa_msgsize <= 117; rsa_msgsize++) {
|
||||
len = sizeof(out);
|
||||
len2 = rsa_msgsize;
|
||||
/* make a random key/msg */
|
||||
|
Loading…
Reference in New Issue
Block a user