Commit ae43b5a9 authored by Davide Galassi's avatar Davide Galassi

MPI exponentiation tests

parent 7640fd2c
Pipeline #57666144 failed with stages
in 1 minute and 25 seconds
......@@ -2,6 +2,7 @@ libcry.a
build
src/config.h
test/test
test/out
doc/html
.scannerwork
*.o
......
......@@ -11,11 +11,15 @@ int cry_mpi_mod_exp(cry_mpi *r, const cry_mpi *b, const cry_mpi *e,
int i, j, res = 0;
cry_mpi exp, tmp;
if ((res = cry_mpi_init_int(&exp, 1)) != 0)
return res;
if ((res = cry_mpi_init_copy(&tmp, b)) != 0) {
cry_mpi_clear(&exp);
if (cry_mpi_is_neg(e) || (m != NULL && cry_mpi_is_neg(m)))
return -1;
if ((res = cry_mpi_init_list(&tmp, &exp, NULL)) != 0)
return res;
if ((res = cry_mpi_set_int(&exp, 1)) != 0 ||
(res = cry_mpi_copy(&tmp, b)) != 0) {
goto e;
}
/* For each block */
......
......@@ -95,7 +95,6 @@ static void mpi_shl(int argc, char *argv[])
ASSERT_EQ(argc, 3);
bits = atoi(argv[1]);
ASSERT(cry_mpi_load_str(g_mpi0, 16, argv[0]) == 0);
ASSERT(cry_mpi_shl(g_mpi1, g_mpi0, bits) == 0);
......@@ -110,7 +109,6 @@ static void mpi_shr(int argc, char *argv[])
ASSERT_EQ(argc, 3);
bits = atoi(argv[1]);
ASSERT(cry_mpi_load_str(g_mpi0, 16, argv[0]) == 0);
ASSERT(cry_mpi_shr(g_mpi1, g_mpi0, bits) == 0);
......@@ -131,23 +129,30 @@ static void mpi_abs(int argc, char *argv[])
ASSERT(strcmp((char *)g_buf, argv[1]) == 0);
}
#define ERROR_FLAG 'Z'
typedef int (* binary_op_f)(cry_mpi *r, const cry_mpi *a, const cry_mpi *b);
static void mpi_binary_op(int argc, char *argv[], binary_op_f op)
{
int res;
ASSERT_EQ(argc, 3);
ASSERT(cry_mpi_load_str(g_mpi0, 16, argv[0]) == 0);
ASSERT(cry_mpi_load_str(g_mpi1, 16, argv[1]) == 0);
ASSERT(op(g_mpi2, g_mpi0, g_mpi1) == 0);
res = op(g_mpi2, g_mpi0, g_mpi1);
ASSERT(cry_mpi_store_str(g_mpi2, 16, (char *)g_buf) == 0);
ASSERT(strcmp((char *)g_buf, argv[2]) == 0);
if (*argv[2] != ERROR_FLAG) {
cry_mpi_print(g_mpi2, 16);
ASSERT(res == 0);
ASSERT(cry_mpi_store_str(g_mpi2, 16, (char *)g_buf) == 0);
ASSERT(strcmp((char *)g_buf, argv[2]) == 0);
} else {
ASSERT(atoi(argv[2] + 1) == res);
}
}
static void mpi_dispatch(int argc, char *argv[])
{
char *test = *argv;
......@@ -186,6 +191,8 @@ static void mpi_dispatch(int argc, char *argv[])
mpi_binary_op(argc, argv, cry_mpi_mul_karatsuba);
else if (strcmp(test, "mpi_mul_toom3") == 0)
mpi_binary_op(argc, argv, cry_mpi_mul_toom3);
else if (strcmp(test, "mpi_exp") == 0)
mpi_binary_op(argc, argv, cry_mpi_exp);
else
printf("Test '%s' not defined\n", test);
......
......@@ -436,3 +436,59 @@ c92e20b990846a1037594736fd02ce34f1776d4c019b0d31c4b5bdb0df568ea2292223e70d6dad39
2b6cc14a427b833f583b1f5fab69855ed61a0ae3518a7e51743d9568f05a90797edafaeae6fdd2c6eb401b743b8c5ad434bf4189e2de8dedabdcdf9379ab71692d0f3f9658e92dfe07d4a05f11224c35c14bc83b0344b8fe352943a082ee06ce888489bf6fc0256dcbec020b717c369e6ea872562fa8736dee1413d6c6dd9531c7364b994c27b26480a4328a9bb9a4404fbe7726c854068e108f86338bd5f1a4534fadd1d15972effccb0b90e575fd8153480d1991395f490c01e8b6dad9f69a17d1a310170b15f75759a3d21c209b15c390478e053987323ee022d7804852e17bb1a6798d21976c3c5ee4312644b28b6f974eac6ff1d1db834426d0aa8618ac95054c1c1b085769a8c298d1e0abb499e761d11e56ff07bad43c4ae78c53a95a8dc2a730dfc7bbb9d7c759170c83b831b1640737081badc6f66874842d21858b412b05d62e3ac566d37bd8770195e34826fb4c351fd1075472f4e743255c4b1b9ec1c9d3d6aedfbd25c3fb7772592c3d2935e41c2807913ca9575c9c9c155de2c70debf1166cc6b06cadfbbe707d7ea3eb804359db08d78be557c5bbffe75c084be5a019bb282acdaa201ab8f44bed03da090bf83e39fa0567331d0afe0d31aa1ccf22fb407fc229584f81442b56fc83181af65a1488a5d6a232b4777f0203100385e7236d5e3cc456cee6397ca6420636a9848b33ba6092a2f2a45f68b88b8ffb4c9db8baa12dc53018aa74eacf61c8266bfb9433fe31be22c21caa6a16583c1dc15de08e82e4b73413794ee950b93938063e502641243e0bf794c5d2c4690c3ff78b295dc2dd40a446a74671b093b110f18e6eb5d2a40b545c6a5a5a60494e93ecde73d63730b1b34d534c9ab0aaa25c58a07a138bae78849b8edcb1ac360e544ae5c0880b5fc8adda26255862fc0365dd676affd379cb0b46a01550270010b611affd035d775cf81165c05edae63379dc0b4dbd25a7a4a1820e3ee18199051273c8fa17ab85301013d6b7354f34eccbe49b94174530aad38d59066bebbde95786e6266e574f38d077e162e5d36a20e99b34fbc60e4f3bfb0861a23d68d4386a8b988c56a4e727e10ad6c84774adc76d6ba6cde16032ccd30b24ec6baaa628
222036db1bcf8603053a222926586ff562cf5759e1d165383ee41b505fc2998a6731dd7cb8ac391040026bf0e8178540ddb9ec30cb988da176cd33b2eeb5c61006b535a488e88948d0b845166fdff383073b11d68c529dc89a06a250f4b3bc7119b05f4cd5c95e19fbb04ee7ce1ae003743a428897b5c5768617ddf2662e198984167c669a32474e14964c1c75b034d007a978a4ea4518c52657408a142b60aa52fe3ed21636701485e82e8753337f942ff060c42429c6a8ab3a9fcdea6a27f7ef76f2d1809a18bfd43b1f5da74a273f51c06507f5945d6fa9a273db883a8636f5feb52e353db15f4418bf94c2ae733999e7edf4ef5ea7d9b8f00cc67574e9d9860412cd6b5ca85ee1bc00ffda5c2d2f74aec2e0363b7509cbf22594e008120599d7f8d4a938e5fbc6d813fde2b650278c439aa8556fd5d6560a274c976e2b79bca16fab4d1ca96a6cbbd8d6cf67ca0a79a1280f1471da2e3ee8b7e63b61babec83493ff4425c1c434cd3926e18baf03962d446d440507c6a49f17cebabb5774a833588991ead6ed9da9645fafd8d70bac704ddfbfc4133310c8a6eedbe89b8fcd1ec518c73dc2262f0a6f6bc5f6d1d04fa350aad1f0d92accdcf1464732060a6a4ac7c920bf5f73dbb843eeb829904b9e46977d0fc54923747cc0debb7000f0b0c1c679bf92a80e441b4bf4a0ae21a64b60d3b7f44f607413e5b30833a5b75c9ebc014c7b981c1acff1b0bafcc16bd0c590c09f245cab89c625bc03fb4843a597d25b878613f575853fc4c58ce68a8d3041306d717952df3fbb3bd2e23c604ddfc5afe632ba39bcda0f322555d84806c52c35831909901b0642897e8ab71267304e78be30bb60e32ea16645f7a04f2dc0e6cd6a98b4dfa4103d26c4248c458f4db9f6a015c5bc784b667b6eb473ae232e3174879d17f66e5fccfac905b262810ce49602a7c07851938fd500f1d8376b0ea537d643460129aba2b0fb8de862428b0c6cc49129118673e0cb57e9ef685326d5e4b31498599446b1653ffa4726964b56861e2c561f7184343ba353c4673d92a85c6fa5201fcb60be6d4c5fc8d60c8ab75fb49183e81fee77df86fd7a3d68bdeea1f210b2cf8c278de2704205218744caaaa580343856579bbe93a2235281bf9998e9fd45117dc25f2b33b89cc36ea2a6143c0b16a5a71055dd8e942913429b20facebfde81102caa232410ef52c4c23b79c9292862adf3e2810dfae324e65334ca74f7fe569893af2e91aa8c512788f2ad985e5e6b7ef5932c389b7f72ee5a75dd6f9756437fd00ee6b29b3f93dc4898190591abf65ac1557e71019e37c5dfa8f6d60378c941ab2427d9c2a7a3355dd808ba41ff861bdba0308f1f7932d67fd2ce1784b6b2b777e8226688ac607c11f97097a90ce50239d1c43b69c2cbabb0083624f63e4848e295eb49e6a4d2442b849ce53984a8274bce38d22ff544e02f5da0d03c42f3591003f8c1536204350b829ec06602351e95d74a20d416e766a07d7a31b7c75c12cabf74be61fac0ae21d97052a61d034ad372a58b0ad8bfeb9c24f03a3cb4e59741c42c951b6bf3c1fe4c212b0959b095d62794560a4d754ea8b57789bc791a20b2d5f8b6915f3b83166eb8e66400a3e28ab679c256899f821016e8701851cd0095aa625dcf0a4ef028035d095c6f75f7dc7f60f06974cb57091b706ef28da05646f4eba1c1df4fee4e0c0585a2024c11288c7acd19e38bd78dd7692b9fb826e992042efbd7faba78084d18d83f81ac86bd4907ca1a4574ae9456f19d6a5a8845e15bf7cfefe7a92b20eb8d666c4e1a18e809e6d9f7fc611678ed67f84ff7aac987522aaf76a947ca6745133c5fa1e86b183c83ca7aeff86e854c78e36d960b3a0ad1390d47b92d3b16e08b36e7ed35160dbfbf44f1bbcc583405fdffcf0f59cea599b31adbd5eccdb74e8753290cd7adea2d1716031dcebecc32db55c6a47e2c926ef3848e3d8c72beb03c9096d35470f9610fb4e4a0293b7f99af165967c90bc7372032c2edb133a19fa97c05b3368c3c302058fc059706d0c3e17ab338a53b10606972307ef8401da23ad1672b4e4d596bf45728ed12eb8268d4f297e78416ba394ad3aff037dd510769caf4bd501be168d1fdf1457cbc7b84b69329c0da70e60dfcdbd85d32d6500f67ce1b9947b29c6cfa75794303eab5a7c9ff0629036aa3e745857ca5769e4f093f41b77aa6fdfb83e2438080483f7f2b79d4530638c991521785e73226c8
################################################################################
# Exponentiation (Binary)
# p0 : base
# p1 : exponent
# p2 : result
# p3 : return value
################################################################################
Exp 0^0
mpi_exp
0
0
1
Exp 0^3
mpi_exp
0
3
0
Exp 1^0
mpi_exp
1
0
1
Exp 1^0
mpi_exp
1
0
1
Exp negative exponent
mpi_exp
aa
-bb
Z-1
Exp test negative base (even pow)
mpi_exp
-a229253d93c944fc43566ac26a1986
4
293738e921395f1204f786c8e86f03fad2b6bf6bc61101234fd3e26154abee5a1d1808711603c9c44cd65ecebe43eb9aeef6f7251b74fce32bbc1510
Exp test negative base (odd pow)
mpi_exp
-a229253d93c944fc43566ac26a1986
3
-411102b83b971ddfd122b9130ba8d96c89237b8355d3572affead9633d22b36321cc6203f57db0c7b693db42d8
Exp test huge
mpi_exp
a229253d93c944fc43566ac26a1986
30
14d7bb1fdade0b6777acca09ce7a6c8eb05712d6d5095f32a72e676c74457a9505b6edffa669aa76dd44e9cc0227ff05e7a4deca7373e6f0277c433779953d9601600789abb903d348546908216ffee0ef49bd009869746314a8938510b8dd0ff577d9f2328736d063ef2db26efc2ba08fea3a3dc7420234f0eee96aca616c8f32c70739a62f8acdd124988185cd2a8cfc676a77283d91fe224ac2ba210b9be462f965bd31de90da961da4e76f493d65623e53245a06ed05a879376551eb891cb94c7b2d1b0f204c3fd24edae77151e09e66079e4692038b18feffe37fb0690d4589703e2e904c431d4e6310aa4131e31ec1835435c900d8e4e6c7b68b61b9ada4af220bb27c68e07ad6bb738d1c40f50ee21cf9b170699fc5324ca78c00d0bcf0d3b96fca607ea3d860d4c5a1d36ae31bf1576638c40b07924aa434400d296e1d15eb757f0459a25d704e7d1fe310f26f1e87f41fed31ef29974ebf68b1324a8f3dea7ff596bd7b5cd68bfc9a802fb2e88eced504195822078167e1abd29818b8af6b5a2ec79b29060b14a57acc3223f0855608f0cadc138aafc347253cb9efded0f79cfe4e1254b4ea7c5029b81318315d49bd31b132a6d919721e5015c389471d377b15bedf10288f978bdc0c49318420c1ed3c75b6e69aa3099c947be90d6b0a491a97f8f3baec64c75bdac33f89291b56cde1d033a6b4305ba739d534818d37daae5d38a63bc9983774da903c20b45bd4443599f6e05c43aa62e474194f0b1802cb0a6400682c2cd8fc204f21dfdeb81d44bcd818b85a87ed3c9e1b17ea7a88531f77eb3a2a693679ab8b93688fc362798380540c3efe50a82aa7a5d62e401e9944b6641f8f3e644446873cc477182670ec282e9c824377c9d8e02f8150a75f2eaf2fbbf14b60b4f66b62798d59b55ae2cd4f4c7ddf87a737ff05c9f531e1445388fc18400346074704bf136ba6ffc9e857f6fc9aa398c92d3bc77754565d0e3681881c1000000000000
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