From 09abe501728f06cba25eaa2aae211718c4647d8a Mon Sep 17 00:00:00 2001 From: Alvaro Denis Date: Tue, 21 May 2019 16:52:59 -0400 Subject: [PATCH] TestECDH* tests are not requiered for firmware ref #34 --- lib/cgo/tests/check_cipher.crypto.c | 53 ++++++++++++++++++++++ lib/cgo/tests/check_cipher.crypto.common.c | 53 ---------------------- 2 files changed, 53 insertions(+), 53 deletions(-) diff --git a/lib/cgo/tests/check_cipher.crypto.c b/lib/cgo/tests/check_cipher.crypto.c index 8449668d3..63621e3e9 100644 --- a/lib/cgo/tests/check_cipher.crypto.c +++ b/lib/cgo/tests/check_cipher.crypto.c @@ -469,6 +469,57 @@ START_TEST(TestSecKeyHashTest) } END_TEST +START_TEST(TestECDHonce) +{ + cipher__PubKey pub1, pub2; + cipher__SecKey sec1, sec2; + unsigned char buff1[50], buff2[50]; + GoSlice_ buf1, buf2; + + buf1.data = buff1; + buf1.len = 0; + buf1.cap = 50; + buf2.data = buff2; + buf2.len = 0; + buf2.cap = 50; + + SKY_cipher_GenerateKeyPair(&pub1, &sec1); + SKY_cipher_GenerateKeyPair(&pub2, &sec2); + + SKY_cipher_ECDH(&pub2, &sec1, &buf1); + SKY_cipher_ECDH(&pub1, &sec2, &buf2); + + // ECDH shared secrets are 32 bytes SHA256 hashes in the end + ck_assert(isSecKeyEq(&sec1, &sec2) == 0); + // ck_assert(eq(u8[32], buff1, buff2)); +} +END_TEST + +START_TEST(TestECDHloop) +{ + int i; + cipher__PubKey pub1, pub2; + cipher__SecKey sec1, sec2; + unsigned char buff1[50], buff2[50]; + GoSlice_ buf1, buf2; + + buf1.data = buff1; + buf1.len = 0; + buf1.cap = 50; + buf2.data = buff2; + buf2.len = 0; + buf2.cap = 50; + + for (i = 0; i < 128; i++) { + SKY_cipher_GenerateKeyPair(&pub1, &sec1); + SKY_cipher_GenerateKeyPair(&pub2, &sec2); + SKY_cipher_ECDH(&pub2, &sec1, &buf1); + SKY_cipher_ECDH(&pub1, &sec2, &buf2); + ck_assert_msg(isSecKeyEq(&sec1, &sec2) == 0, "Fail in %d", i); + } +} +END_TEST + Suite* cipher_crypto(void) { Suite* s = suite_create("Load cipher.crypto"); @@ -488,6 +539,8 @@ Suite* cipher_crypto(void) tcase_add_test(tc, TestSecKeTest); tcase_add_test(tc, TestSecKeyHashTest); tcase_add_test(tc, TestGenerateKeyPair); + tcase_add_test(tc, TestECDHonce); + tcase_add_test(tc, TestECDHloop); suite_add_tcase(s, tc); tcase_set_timeout(tc, 150); diff --git a/lib/cgo/tests/check_cipher.crypto.common.c b/lib/cgo/tests/check_cipher.crypto.common.c index de8903fc6..7fa9ca7ad 100644 --- a/lib/cgo/tests/check_cipher.crypto.common.c +++ b/lib/cgo/tests/check_cipher.crypto.common.c @@ -340,57 +340,6 @@ START_TEST(TestPubKeyFromSecKey) } END_TEST -START_TEST(TestECDHonce) -{ - cipher__PubKey pub1, pub2; - cipher__SecKey sec1, sec2; - unsigned char buff1[50], buff2[50]; - GoSlice_ buf1, buf2; - - buf1.data = buff1; - buf1.len = 0; - buf1.cap = 50; - buf2.data = buff2; - buf2.len = 0; - buf2.cap = 50; - - SKY_cipher_GenerateKeyPair(&pub1, &sec1); - SKY_cipher_GenerateKeyPair(&pub2, &sec2); - - SKY_cipher_ECDH(&pub2, &sec1, &buf1); - SKY_cipher_ECDH(&pub1, &sec2, &buf2); - - // ECDH shared secrets are 32 bytes SHA256 hashes in the end - ck_assert(isSecKeyEq(&sec1, &sec2) == 0); - // ck_assert(eq(u8[32], buff1, buff2)); -} -END_TEST - -START_TEST(TestECDHloop) -{ - int i; - cipher__PubKey pub1, pub2; - cipher__SecKey sec1, sec2; - unsigned char buff1[50], buff2[50]; - GoSlice_ buf1, buf2; - - buf1.data = buff1; - buf1.len = 0; - buf1.cap = 50; - buf2.data = buff2; - buf2.len = 0; - buf2.cap = 50; - - for (i = 0; i < 128; i++) { - SKY_cipher_GenerateKeyPair(&pub1, &sec1); - SKY_cipher_GenerateKeyPair(&pub2, &sec2); - SKY_cipher_ECDH(&pub2, &sec1, &buf1); - SKY_cipher_ECDH(&pub1, &sec2, &buf2); - ck_assert_msg(isSecKeyEq(&sec1, &sec2) == 0, "Fail in %d", i); - } -} -END_TEST - // define test suite and cases Suite *common_check_cipher_crypto(void) { @@ -409,8 +358,6 @@ Suite *common_check_cipher_crypto(void) tcase_add_test(tc, TestMustSigFromHex); tcase_add_test(tc, TestSigHex); tcase_add_test(tc, TestPubKeyFromSecKey); - tcase_add_test(tc, TestECDHonce); - tcase_add_test(tc, TestECDHloop); suite_add_tcase(s, tc); tcase_set_timeout(tc, 150);