1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 15:38:11 +00:00

tests: test for ge25519_double_scalarmult_vartime2 added

This commit is contained in:
Dusan Klinec 2018-05-18 18:55:10 +02:00 committed by Pavol Rusnak
parent 10788a82a1
commit 28d1225276

View File

@ -3566,6 +3566,47 @@ START_TEST(test_ed25519_modl_sub)
} }
END_TEST END_TEST
START_TEST(test_ge25519_double_scalarmult_vartime2)
{
char tests[][5][65] = {
{"c537208ed4985e66e9f7a35c9a69448a732ba93960bbbd2823604f7ae9e3ed08", "365233e5af17c8888d5ce508787464f4642e91a6212b1b104e6c3769535601b1", "a84f871580176708b4ac21843cb197ad96e8456034442b50859c83c5807b9901", "f022360d1bce903fa3ac58ae42f997328b31f477b8d576a9f6d26fc1d08f14ea", "bf25da82c6b210948b823ae48422a2dcd205d3c94842e68ac27e5cbeaa704ebc"},
{"4abfabc0dda33588a98127ef3bfe724fed286395fe15932e898b5621661ea102", "e5fd79d03f5df8edfc8def663dcb96bba6cadf857f2ae6f6f51f52f8d14079b7", "4754c286b23e3c1b50054fe3937ebdc4ec01b28da5d05fb6111798b42fc5bf06", "b7e7f9464b98de5bfcf6b02c1b7053cc359df407ad59d943523c6d2ee773b2f6", "6d7d5f729bfa4882dbff8e477cd2b4c354ba347f10e7b178a24f3f16a4e0fec6"},
{"19f2af4d04cb8181f1fe0d01fe9bb9ecc476c67ceb4a9830dae1bc7fe5fe3b04", "d3c462f4f30991220387a1fbbd1ba1dc45ce058c70a8fb1475071e7b4f0fc463", "577790e025c1fd2014db44a8d613c4e2ab1f248a4a6d14b5d39cbbafd7b20f06", "1376c6837f131f6cd1a45b1056297d2314aa0ac5f7d581d2d878261eb3259b4d", "ce790760ada87dd819b59e4f6765d836d346567ec34f02bbcfcae0585c1d758f"},
{"cf209db9e7ee85f1e648924ec97edd86b56a833b25707519d4fbe64fd50e150a", "804f0806087dc665a26230ed5fd44c062980ee182a6bd7dbdb33df018c983778", "30d3c448cb08935309753b3051366f52328ca1d9a0b63c72b989edee0da32b0e", "98e3c973a7e85b5eab8111521c66ca584bed5597f060ab0c6b5cdeece502ac48", "2646276e1305396a1b2473690066011a39789570a09e10ce1a013c8f32cd5bea"},
{"b0a0ffeea67b656c4c585ba58ff528a6f45d2f915db98e4a14a8ff17f27fc105", "4fabe16274f6af526ee053028485db6acd13804e02dcdddccc4183a319ab9e1c", "1e140bb08a936ac6b7437644ca0769f3c165c7aa5501d49f064a0346179b4008", "68fc1be64fb68761542a655b8dbebf50980f1fbc1845528df8d8a06bf89a1495", "7dab86994b47014efe38493fc2b62ffcead806da6e0d73c992db8cb5618a19dc"},
{"0fee422c2294b06ca83bc3704384dffc580e7ff5921881e51a755e5f9b80af03", "4359a663ead3f7ffc3a0ead5c3c2bde348017e7bfa620f21759c32e469a16dfe", "532066e3eec29334fffc37b17178dfbac3bee15f7845f01449ddbaf5e57a7b0c", "32e46c2fb99402837631c8175db31cdd334c145f922be9070d62e6d9c493c3ea", "8c7b7d2d61cdb648960434d894787426a76d16dd46949c7aa4b85dcf1054b4d5"},
{"3a712d5b7ceb5257dcf6e6bb06548de6ef3deba5d456cd91fc305a12b46b5d01", "5e7da62e3ec42cf3e554639dd4d2006754ee6839b720cadba94a26b73b1665ee", "2a518ecab17a2d9dde219c775bcf4f2306b190bef2dea34fb65b8e4dccc13405", "3b5d66a4dfb068923b3bc21cc8b40b59e12f845e0b85a86d394db0fa310bf185", "2ec17f1cc0be093e9cdb741a991c0f417230dea275cd7babdad35e949e250521"},
{"5f815f2d65cef584c5e5d48b2d3d3e4cae310d70b328f88af6e9f63c52b4c90d", "8a539a8c6b2339922b31cf4bc064f1fedeb3912fd89585d79dfcff2a60aee295", "385f7132b72db04146b9e472736b32adfca29556b4775a743c18e2bfab939007", "884aaf96d625968ddb2582922a87abca131272884c47f6b86890ebccf0a79d5b", "a7afdaf24fe8472d8b89e95c3ce4a40bdf700af7cedee44ed3aa5ccca09839bd"},
{"a043340d072df16a8ab5135f8c1d601bff14c5aba01b9212b886ad71fe164506", "52f6de5fa0fae32d4020a54d395319509d6b92092a0bf849fb34e73f8e71fc99", "37d7472d360164da29e6dcb8f9796976022571c5df4ddf7e30e9a579ba13d509", "8c369e3fd5b1112e4437b1f09e987acca4966f2f8c5227eb15ace240a2c64cc7", "fc795fe7baff5c3ac98366e6882f25874ea2b0a649d16f139e5c54ea47042a1e"},
{"97a3268db03fa184c8cba020bf216fc789292fa9615a28962385b86870ffd70f", "a76c215587022bb9252ece4c5afeb0e65b820834cd41ac76e6c062d3eea75dc6", "8310271017154cbddf7005e24eb9a9a86777b3f42fa5e35095eafaac4eb24802", "b822665c2406083c851ecaa91ea67aa740c057e7679b5755cee60a6c63f17fd6", "f83e2444527056eba595d49bde40b2e8da76d2c145f203331d26e94560993fbc"},
{"edaad13efad39f26298e86ba8d06a46e59122232c9529bd22f2f656595421e00", "f38e56a79f5159eb3b581dea537ec12c9c6fac381b2cf6073e27fc621197cb62", "1eea79485954b5958d9d5478f86133af1088806d923535d483b115ab23099a0f", "b32c5e57d57db7a349f4ab845f12a5045c52b4a7a5bce7fd54a1a255b0118185", "3bfb42b4ffd2c6cfc8cce9e4187dc6fbcaecd9d44a4ca1d2b68b97410bb25b81"},
{"b15eaebe0fc83cb11d755a6f067b710204d4a59101078d8286454b652879080a", "4667a2e61d9df1690f5c33c4168e480f7e26d2f0998168ebdc0a39712946f741", "125379da1a88bfdf5b928f8795d3ea5415ef8c3d9106eb16934c3842873fd707", "8727a692a25e38b1afa98e3dd5bf88815dec6d9810c1fd8a31b56b3de8630f1e", "540883dde400b909e9955a276c20e13d99252ebe542750b8bfbbe5c3b87c51e3"},
{"e42bdd4af3121bea644a90a76b2007615621ee5b842b9a74c4334ac309478706", "6dc4ab715d3bb975ebfd0f08e2b6f3f39922d0121ae518a8f8d2952ea2fe0b5d", "0285059b0095c97f4a50d43c7726c64c2830bf2b55dfa934ebba7ad71064dc07", "f738c0a3cee31fd8f438f282aa6c823fccfa49cf7b5c86fbf9d56bf0394b6d8d", "a1bd106841e55010decd95a170a1d0dd11780fd00759819e024b15ea3a83b4be"},
{"5077c30fd08795dbdc7a230c050ca07e316fa3b040fd0dac45907036ab25dd0e", "96f0897f000e49e2439a9166cab40ebc125a31b82851f0541516c19683e7bfaf", "2b67d79a2efdc6451508e7f3c97c4a61b135bb839c02338bb444ef8208dd970b", "7ef4cd7cdc29c2b88ccff49898b5d0b7be5993f93c5772476feec9dc57d7b6e3", "62449b901b25760c964704b28efc184fbd5947e83851ebaf3bbfeb6f742f679f"},
{"a4b3ce6928fe8f77d13e65ae255eee8310ab0d75bca47028b4570f0511a66006", "4e9da8d77ee337e3bcce3730ccfff2121728641c7bb4fdeb2155890f998af09a", "ff01a5075569d0f6afee45da065c72f5841f46ce772917ef75eb4d230473580f", "36ca32da8a10f4083f5a60ee21868d9d448548d49c56f19cbe6005005e34f816", "99df362a3b762cc1cbb70bc5ddff3c8614ed306037013102e387ef32e7f2494f"},
{"074aa76351dceb752aa09887d9aca932d5821f58eedb4988fd64d8548e3f2c09", "588b4552f3b98b2f77aee2ef8cc72f88acd424c4373b3e3626393ed2ea24cbda", "f2d9175633f2e3c661b01172b4b4176850cd5b3098ffb0f927e0a5e19c1c8a02", "a6c34868736b2517fd46f57a4e30805ffd475e44a8b1413078f43d9cb3d6edd6", "46e1e7d7b1e939dd5c07c8363af01f4f9dae7c3d10f237ff9776ddc4a1903771"},
{"ae1c8abd5a542208ee0aa93ffbf0b8e5a957edc4854fe2b48153c5c85bbf3d08", "5e084b9541a70bd5bef400be6525c5a806a5b7fb12de38b07dcd35a22c57edbe", "d95f179a215fb322d81720bf3aecde78d6d676d6f941455d0e0920f1e3619707", "c3e5d43221824de51d8f95705de69c80a2440c0483ca88549d639aee15390429", "df9fea42d3b5ac243244abb4ca4948a69493becddc5d5906f9a4e4c5645b0eab"},
{"2f1c5adedb7341dc7638bafacc6024bd48255197ea2347fc05714b9341dd4403", "47f55263001542f796c928988f641f59d0cd43294fc8d8616b184bfe9dddf368", "aa5e884e782ab116151c609680c37b1a49b52f23bce5e2ebf28dd8532510d20b", "ef2d6d97ad1a18edfce6450c1e70295b2c7ed2bc749ea8b438a523eae078d1f3", "2396a355c6ae8e2ac24da8f55a674c96fc4cc69b38678b2bd8eb91b96f462bca"},
{"0242e14105ced74e91cf4d4dcd22a9c09279018901d2fb8319eb54c2a1c4900a", "fcb62a6c520d31fa46efeb4a1000330653b3402f575c2ddc0c688f527e7b97be", "73a7e2e0602e5345f040dedc4db67f6d8e37c5fca3bbb124fa43963d76dbbb08", "152bf4a3305c656f77e292b1256cc470da4d3f6efc3667199db4316d7f431174", "c21ba2080013dfb225e06378d9ac27df623df552526cfddbf9e71bb1d4705dd9"},
{"07fab4fc7b02fbcf868ffb0326cf60425fef2af1fbad83a8926cc62c2b5dff05", "29ff12c5e052eb5829e8334e0e082c5edde1f293d2b4ed499a79bcca20e48010", "97afb3dd9167877b432a23503aad1ab39188b9be07cc124ceb3fbdbd8d8b890a", "ed121240a2f4591eeedbfd880305ccd17e522673900b03279fb66e73583514ae", "b27f209e88ce5701766565e231e8123adb1df9c9f1dc461920acbc2b38d9f6d7"},
};
unsigned char buff[32];
bignum256modm a={0}, b={0};
ge25519 A, B, R;
for (size_t i = 0; i < (sizeof(tests) / sizeof(*tests)); i++) {
expand256_modm(a, fromhex(tests[i][0]), 32);
expand256_modm(b, fromhex(tests[i][2]), 32);
ge25519_unpack_negative_vartime(&A, fromhex(tests[i][1])); curve25519_neg(A.x, A.x); curve25519_neg(A.t, A.t);
ge25519_unpack_negative_vartime(&B, fromhex(tests[i][3])); curve25519_neg(B.x, B.x); curve25519_neg(B.t, B.t);
ge25519_double_scalarmult_vartime2(&R, &A, a, &B, b);
ge25519_pack(buff, &R);
ck_assert_mem_eq(buff, fromhex(tests[i][4]), 32);
}
}
END_TEST
static void test_bip32_ecdh_init_node(HDNode *node, const char *seed_str, const char *curve_name) { static void test_bip32_ecdh_init_node(HDNode *node, const char *seed_str, const char *curve_name) {
hdnode_from_seed((const uint8_t *)seed_str, strlen(seed_str), curve_name, node); hdnode_from_seed((const uint8_t *)seed_str, strlen(seed_str), curve_name, node);
hdnode_fill_public_key(node); hdnode_fill_public_key(node);
@ -4797,6 +4838,10 @@ Suite *test_suite(void)
tcase_add_test(tc, test_ed25519_modl_sub); tcase_add_test(tc, test_ed25519_modl_sub);
suite_add_tcase(s, tc); suite_add_tcase(s, tc);
tc = tcase_create("ed25519_ge");
tcase_add_test(tc, test_ge25519_double_scalarmult_vartime2);
suite_add_tcase(s, tc);
tc = tcase_create("script"); tc = tcase_create("script");
tcase_add_test(tc, test_output_script); tcase_add_test(tc, test_output_script);
suite_add_tcase(s, tc); suite_add_tcase(s, tc);