Make sure we detect corruption.

This commit is contained in:
Ben Laurie 2007-04-04 12:50:13 +00:00
parent 2ac061e487
commit 84dd04e761
2 changed files with 23 additions and 5 deletions

View file

@ -219,6 +219,7 @@ int main(int argc, char *argv[])
int plen; int plen;
int clen = 0; int clen = 0;
int num; int num;
int n;
CRYPTO_malloc_debug_init(); CRYPTO_malloc_debug_init();
CRYPTO_dbg_set_options(V_CRYPTO_MDEBUG_ALL); CRYPTO_dbg_set_options(V_CRYPTO_MDEBUG_ALL);
@ -278,7 +279,7 @@ int main(int argc, char *argv[])
err=1; err=1;
goto next; goto next;
} }
num = RSA_private_decrypt(num, ctext, ptext, key, num = RSA_private_decrypt(num, ctext, ptext, key,
RSA_PKCS1_OAEP_PADDING); RSA_PKCS1_OAEP_PADDING);
if (num != plen || memcmp(ptext, ptext_ex, num) != 0) if (num != plen || memcmp(ptext, ptext_ex, num) != 0)
@ -287,10 +288,7 @@ int main(int argc, char *argv[])
err=1; err=1;
} }
else if (memcmp(ctext, ctext_ex, num) == 0) else if (memcmp(ctext, ctext_ex, num) == 0)
{
printf("OAEP test vector %d passed!\n", v); printf("OAEP test vector %d passed!\n", v);
goto next;
}
/* Different ciphertexts (rsa_oaep.c without -DPKCS_TESTVECT). /* Different ciphertexts (rsa_oaep.c without -DPKCS_TESTVECT).
Try decrypting ctext_ex */ Try decrypting ctext_ex */
@ -305,6 +303,26 @@ int main(int argc, char *argv[])
} }
else else
printf("OAEP encryption/decryption ok\n"); printf("OAEP encryption/decryption ok\n");
/* Try decrypting corrupted ciphertexts */
for(n = 0 ; n < clen ; ++n)
{
int b;
unsigned char saved = ctext[n];
for(b = 0 ; b < 256 ; ++b)
{
if(b == saved)
continue;
ctext[n] = b;
num = RSA_private_decrypt(num, ctext, ptext, key,
RSA_PKCS1_OAEP_PADDING);
if(num > 0)
{
printf("Corrupt data decrypted!\n");
err = 1;
}
}
}
next: next:
RSA_free(key); RSA_free(key);
} }

View file

@ -195,7 +195,7 @@ test_x509:
echo test second x509v3 certificate echo test second x509v3 certificate
sh ./tx509 v3-cert2.pem 2>/dev/null sh ./tx509 v3-cert2.pem 2>/dev/null
test_rsa: test_rsa: $(RSATEST)$(EXE_EXT)
@sh ./trsa 2>/dev/null @sh ./trsa 2>/dev/null
../util/shlib_wrap.sh ./$(RSATEST) ../util/shlib_wrap.sh ./$(RSATEST)