Commit 1ed62628 authored by Davide Galassi's avatar Davide Galassi

RSA test suite improvement

parent 4581eeae
Pipeline #52143392 passed with stages
in 1 minute and 21 seconds
......@@ -121,11 +121,81 @@ static void sign_verify(void)
cry_mpi_clear_list(&rsa.m, &rsa.e, &rsa.d, NULL);
}
struct rsa_param {
unsigned int mlen;
unsigned int elen;
unsigned int clrlen;
unsigned int ciplen;
unsigned char *mraw;
unsigned char *eraw;
unsigned char *clrraw;
unsigned char *cipraw;
};
/*
* Params:
* p0 : M
* p1 : E
* p2 : cleartext
* p3 : ciphertext
*/
static void rsa_param_init(struct rsa_param *par, int argc, char *argv[])
{
memset(par, 0, sizeof(*par));
ASSERT(argc == 4);
par->mlen = strlen(argv[0]) >> 1;
par->elen = strlen(argv[1]) >> 1;
par->clrlen = strlen(argv[2]) >> 1;
par->ciplen = strlen(argv[3]) >> 1;
par->mraw = malloc(par->mlen + par->elen + par->clrlen + par->ciplen);
par->eraw = par->mraw + par->mlen;
par->clrraw = par->eraw + par->elen;
par->cipraw = par->clrraw + par->clrlen;
raw_init(par->mraw, par->mlen, argv[0]);
raw_init(par->eraw, par->elen, argv[1]);
raw_init(par->clrraw, par->clrlen, argv[2]);
raw_init(par->cipraw, par->ciplen, argv[3]);
}
static void rsa_pkcs1_encrypt(int argc, char *argv[])
{
struct rsa_param par;
cry_rsa_ctx rsa;
size_t outlen;
unsigned char *cipher_buf;
cry_prng_init(NULL, 0);
rsa_param_init(&par, argc, argv);
cry_mpi_init_bin(&rsa.m, par.mraw, par.mlen);
cry_mpi_init_bin(&rsa.e, par.eraw, par.elen);
rsa.flags = 0;
ASSERT_OK(cry_rsa_encrypt(&rsa, &cipher_buf, &outlen,
par.clrraw, par.clrlen));
}
static void dispatch(int argc, char *argv[])
{
char *test = *argv;
argv++;
argc--;
if (strcmp(test, "rsa_pkcs1_encrypt") == 0)
rsa_pkcs1_encrypt(argc, argv);
else
printf("Test '%s' not defined\n", test);
}
void rsa_test(void)
{
printf("* RSA Test\n");
run("Keygen 512", keygen, NULL, NULL);
run("Encrypt-Decrypt", encrypt_decrypt, NULL, NULL);
run("Sign-Verify", sign_verify, NULL, NULL);
func_test("rsa_test.data", dispatch);
printf("\n");
}
################################################################################
#
# RSA validation vectos
#
# Borrowed by MbedTLS library test data
#
################################################################################
################################################################################
# RSA-PKCS1 encrypt
# p0 : M
# p1 : E
# p2 : cleartext
# p3 : ciphertext
################################################################################
RSA PKCS1 Encrypt #1
rsa_pkcs1_encrypt
b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f
03
4E636AF98E40F3ADCFCCB698F4E80B9F
b0c0b193ba4a5b4502bfacd1a9c2697da5510f3e3ab7274cf404418afd2c62c89b98d83bbc21c8c1bf1afe6d8bf40425e053e9c03e03a3be0edbe1eda073fade1cc286cc0305a493d98fe795634c3cad7feb513edb742d66d910c87d07f6b0055c3488bb262b5fd1ce8747af64801fb39d2d3a3e57086ffe55ab8d0a2ca86975629a0f85767a4990c532a7c2dab1647997ebb234d0b28a0008bfebfc905e7ba5b30b60566a5e0190417465efdbf549934b8f0c5c9f36b7c5b6373a47ae553ced0608a161b1b70dfa509375cf7a3598223a6d7b7a1d1a06ac74d345a9bb7c0e44c8388858a4f1d8115f2bd769ffa69020385fa286302c80e950f9e2751308666c
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment