Skip to content
Open
Show file tree
Hide file tree
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
7 changes: 4 additions & 3 deletions src/pk/rsa/rsa_import.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ int rsa_import_pkcs1(const unsigned char *in, unsigned long inlen, rsa_key *key)
key->type = PK_PUBLIC;
}
goto LBL_OUT;
} else if (err != CRYPT_INPUT_TOO_LONG) {
} else if (err != CRYPT_OK && err != CRYPT_INPUT_TOO_LONG) {
/* couldn't decode the version, so error out */
goto LBL_OUT;
}
Expand All @@ -70,8 +70,9 @@ int rsa_import_pkcs1(const unsigned char *in, unsigned long inlen, rsa_key *key)
goto LBL_OUT;
}
key->type = PK_PRIVATE;
} else if (version == 1) {
/* we don't support multi-prime RSA */
} else {
/* version 1 is multi-prime RSA, which we don't support,
* any other version is invalid */
err = CRYPT_PK_INVALID_TYPE;
goto LBL_OUT;
}
Expand Down
14 changes: 14 additions & 0 deletions tests/rsa_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,19 @@ static int s_rsa_issue_301(int prng_idx)
return CRYPT_OK;
}

static int s_rsa_issue_803(void)
{
rsa_key key;
/* SEQUENCE { INTEGER 2, INTEGER 0 }, an unknown RSAPrivateKey version */
const unsigned char v2[] = { 0x30, 0x06, 0x02, 0x01, 0x02, 0x02, 0x01, 0x00 };
/* SEQUENCE { INTEGER 0 }, a version without any key components */
const unsigned char v0[] = { 0x30, 0x03, 0x02, 0x01, 0x00 };

SHOULD_FAIL(rsa_import(v2, sizeof(v2), &key));
SHOULD_FAIL(rsa_import(v0, sizeof(v0), &key));
return CRYPT_OK;
}

static int s_rsa_public_ubin_e(int prng_idx)
{
rsa_key key;
Expand Down Expand Up @@ -605,6 +618,7 @@ int rsa_test(void)
DO(s_rsa_macros_test());
DO(s_rsa_cryptx_issue_69());
DO(s_rsa_issue_301(prng_idx));
DO(s_rsa_issue_803());
DO(s_rsa_public_ubin_e(prng_idx));
DO(s_rsa_oaep_small_ciphertext_test(prng_idx));

Expand Down