udpate bleichenbacher signature attack

also test for too short padding strings
This commit is contained in:
Steffen Jaeckel 2014-08-19 19:17:47 +02:00
parent e227000578
commit 2b3c603c6c

View File

@ -104,7 +104,7 @@ int rsa_test(void)
{
unsigned char in[1024], out[1024], tmp[1024];
rsa_key key, privKey, pubKey;
int hash_idx, prng_idx, stat, stat2;
int hash_idx, prng_idx, stat, stat2, i;
unsigned long rsa_msgsize, len, len2, len3, cnt, cnt2;
static unsigned char lparam[] = { 0x01, 0x02, 0x03, 0x04 };
@ -361,6 +361,7 @@ for (cnt = 0; cnt < len; ) {
unsigned char* p = in;
unsigned char* p2 = out;
unsigned char* p3 = tmp;
for (i = 0; i < 9; ++i) {
len = sizeof(in);
len2 = sizeof(out);
cnt = rsa_get_size(&key);
@ -391,9 +392,9 @@ for (cnt = 0; cnt < len; ) {
break;
}
/* (4.2) */
memmove(&p3[cnt+1], &p3[cnt2], len3-cnt2);
memmove(&p3[cnt+i], &p3[cnt2], len3-cnt2);
/* (4.3) */
for (cnt = cnt + len3-cnt2+1; cnt < len; ++cnt) {
for (cnt = cnt + len3-cnt2+i; cnt < len; ++cnt) {
do {
p3[cnt] = (unsigned char)rand();
} while (p3[cnt] == 0);
@ -414,8 +415,13 @@ for (cnt = 0; cnt < len; ) {
len3 = sizeof(tmp);
/* (6) */
if (i < 8)
DOX(rsa_verify_hash_ex(p2, len2, p, 20, LTC_PKCS_1_V1_5, hash_idx, -1, &stat, &pubKey)
== CRYPT_INVALID_PACKET ? CRYPT_OK:CRYPT_INVALID_PACKET, "should fail");
else
DOX(rsa_verify_hash_ex(p2, len2, p, 20, LTC_PKCS_1_V1_5, hash_idx, -1, &stat, &pubKey), "should succeed");
DOX(stat == 0?CRYPT_OK:CRYPT_FAIL_TESTVECTOR, "should fail");
}
/* free the key and return */
rsa_free(&key);