From: Loup Vaillant Date: Sat, 3 Dec 2022 11:26:17 +0000 (+0100) Subject: Fix tis-ci X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=9ce463c4c2456ab3695fca5efbb8a687a5995f9c;p=Monocypher.git Fix tis-ci Also integrated tis-ci tests into github CI --- diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3a5df1d..756e817 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -98,6 +98,9 @@ jobs: - name: Run tests run: make clean && make test -j4 + - name: Run tis-ci tests + run: make clean && make tis-ci -j4 + - name: Run speed tests run: | make clean && make speed -j4 diff --git a/makefile b/makefile index ce00b4d..0eb0c3f 100644 --- a/makefile +++ b/makefile @@ -68,7 +68,7 @@ endif .PHONY: all library static-library dynamic-library \ install install-doc pkg-config-libhydrogen \ - check test ctgrind \ + check test tis-ci ctgrind \ speed speed-sodium speed-tweetnacl speed-hydrogen speed-c25519 \ speed-donna \ clean uninstall \ @@ -116,13 +116,16 @@ uninstall: check: test test : test.out +tis-ci : tis-ci.out speed : speed.out speed-sodium : speed-sodium.out speed-tweetnacl: speed-tweetnacl.out speed-hydrogen : speed-hydrogen.out speed-c25519 : speed-c25519.out speed-donna : speed-donna.out -test speed speed-sodium speed-tweetnacl speed-hydrogen speed-c25519 speed-donna: +test tis-ci: + ./$< +speed speed-sodium speed-tweetnacl speed-hydrogen speed-c25519 speed-donna: ./$< ctgrind: ctgrind.out @@ -150,11 +153,12 @@ lib/monocypher.o lib/monocypher-ed25519.o lib/chacha20.o lib/aead-incr.o: TEST_COMMON = tests/utils.h src/monocypher.h src/optional/monocypher-ed25519.h SPEED = tests/speed lib/utils.o :tests/utils.c +lib/tis-ci.o :tests/tis-ci.c $(TEST_COMMON) tests/tis-ci-vectors.h lib/test.o :tests/test.c $(TEST_COMMON) tests/vectors.h lib/ctgrind.o :tests/ctgrind.c $(TEST_COMMON) lib/speed.o :$(SPEED)/speed.c $(TEST_COMMON) $(SPEED)/speed.h lib/speed-tweetnacl.o:$(SPEED)/speed-tweetnacl.c $(TEST_COMMON) $(SPEED)/speed.h -lib/utils.o lib/test.o lib/speed.o: +lib/utils.o lib/test.o lib/tis-ci.o lib/speed.o: @mkdir -p $(@D) $(CC) $(CFLAGS) \ -I src -I src/optional -I tests \ @@ -223,11 +227,12 @@ lib/speed-ed25519.o: tests/externals/ed25519-donna/ed25519.c \ -DED25519_FORCE_32BIT # test & speed executables -TEST_OBJ= lib/utils.o lib/monocypher.o -test.out : lib/test.o $(TEST_OBJ) lib/monocypher-ed25519.o -ctgrind.out : lib/ctgrind.o $(TEST_OBJ) lib/monocypher-ed25519.o -speed.out : lib/speed.o $(TEST_OBJ) lib/monocypher-ed25519.o -test.out speed.out: +TEST_OBJ= lib/utils.o lib/monocypher.o lib/monocypher-ed25519.o +test.out : lib/test.o $(TEST_OBJ) +tis-ci.out : lib/tis-ci.o $(TEST_OBJ) +ctgrind.out : lib/ctgrind.o $(TEST_OBJ) +speed.out : lib/speed.o $(TEST_OBJ) +test.out speed.out tis-ci.out: $(CC) $(CFLAGS) -I src -I src/optional -o $@ $^ ctgrind.out: $(CC) $(CFLAGS) -O0 -I src -I src/optional -o $@ $^ diff --git a/tests/test.sh b/tests/test.sh index 42f2a98..7d2207d 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -53,6 +53,8 @@ set -e +make clean; make tis-ci +make clean; make test make clean; make test CFLAGS="-DBLAKE2_NO_UNROLLING -O3" make clean; make test CC="clang -std=c99" CFLAGS="-g -fsanitize=address" make clean; make test CC="clang -std=c99" CFLAGS="-g -fsanitize=memory" diff --git a/tests/tis-ci-vectors.h b/tests/tis-ci-vectors.h index f3146a3..04f5a10 100644 --- a/tests/tis-ci-vectors.h +++ b/tests/tis-ci-vectors.h @@ -390,13 +390,6 @@ static const char *ed_25519_check_vectors[]={ "ff", }; static size_t nb_ed_25519_check_vectors=12; -static const char *x25519_pk_vectors[]={ - "e4e4c4054fe35a75d9c0f679ad8770d8227e68e4c1e68ce67ee88e6be251a207", - "e5410cf8d4524fe8b010158cf7c541420e996b6b1378d4ed88deaaee29263b12", - "0000000000000000000000000000000000000000000000000000000000000000", - "2fe57da347cd62431528daac5fbb290730fff684afc4cfc2ed90995f58cb3b74", -}; -static size_t nb_x25519_pk_vectors=4; static const char *key_exchange_vectors[]={ "77076d0a7318a57d3c16c17251b26645df4c2f87ebc0992ab177fba51db92c2a", "de9edb7d7b7dc1b4d35b61c2ece435373f8343c85b78674dadfc7e146f882b4f", diff --git a/tests/tis-ci.c b/tests/tis-ci.c index b434054..c936b1b 100644 --- a/tests/tis-ci.c +++ b/tests/tis-ci.c @@ -191,17 +191,10 @@ static void edDSA(vector_reader *reader) vector public_k = next_input(reader); vector msg = next_input(reader); vector out = next_output(reader); - u8 out2[64]; - - // Sign with cached public key, then by reconstructing the key - crypto_sign(out.buf, secret_k.buf, public_k.buf, msg.buf, msg.size); - crypto_sign(out2 , secret_k.buf, 0 , msg.buf, msg.size); - // Compare signatures (must be the same) - if (memcmp(out.buf, out2, out.size)) { - printf("FAILURE: reconstructing public key" - " yields different signature\n"); - exit(1); - } + u8 fat_secret_key[64]; + memcpy(fat_secret_key , secret_k.buf, 32); + memcpy(fat_secret_key + 32, public_k.buf, 32); + crypto_eddsa_sign(out.buf, fat_secret_key, msg.buf, msg.size); } static void ed_25519(vector_reader *reader) @@ -210,17 +203,10 @@ static void ed_25519(vector_reader *reader) vector public_k = next_input(reader); vector msg = next_input(reader); vector out = next_output(reader); - u8 out2[64]; - - // Sign with cached public key, then by reconstructing the key - crypto_ed25519_sign(out.buf, secret_k.buf, public_k.buf, msg.buf, msg.size); - crypto_ed25519_sign(out2 , secret_k.buf, 0 , msg.buf, msg.size); - // Compare signatures (must be the same) - if (memcmp(out.buf, out2, out.size)) { - printf("FAILURE: reconstructing public key" - " yields different signature\n"); - exit(1); - } + u8 fat_secret_key[64]; + memcpy(fat_secret_key , secret_k.buf, 32); + memcpy(fat_secret_key + 32, public_k.buf, 32); + crypto_ed25519_sign(out.buf, fat_secret_key, msg.buf, msg.size); } static void ed_25519_check(vector_reader *reader) @@ -260,10 +246,11 @@ static void elligator_inv(vector_reader *reader) static int p_from_eddsa() { int status = 0; - RANDOM_INPUT(ed_private, 32); - u8 ed_public[32]; crypto_sign_public_key (ed_public, ed_private); - u8 x_private[32]; crypto_from_eddsa_private(x_private, ed_private); - u8 x_public1[32]; crypto_from_eddsa_public (x_public1, ed_public); + RANDOM_INPUT(ed_seed, 32); + u8 secret [64]; + u8 public [32]; crypto_eddsa_key_pair(secret, public, ed_seed); + u8 x_private[32]; crypto_from_eddsa_private(x_private, secret); + u8 x_public1[32]; crypto_from_eddsa_public (x_public1, public); u8 x_public2[32]; crypto_x25519_public_key (x_public2, x_private); status |= memcmp(x_public1, x_public2, 32); printf("%s: from_eddsa\n", status != 0 ? "FAILED" : "OK"); @@ -274,11 +261,12 @@ static int p_from_eddsa() static int p_from_ed25519() { int status = 0; - RANDOM_INPUT(ed_private, 32); - u8 ed_public[32]; crypto_ed25519_public_key (ed_public, ed_private); - u8 x_private[32]; crypto_from_ed25519_private(x_private, ed_private); - u8 x_public1[32]; crypto_from_ed25519_public (x_public1, ed_public); - u8 x_public2[32]; crypto_x25519_public_key (x_public2, x_private); + RANDOM_INPUT(ed_seed, 32); + u8 secret [64]; + u8 public [32]; crypto_ed25519_key_pair(secret, public, ed_seed); + u8 x_private[32]; crypto_from_ed25519_private(x_private, secret); + u8 x_public1[32]; crypto_from_ed25519_public (x_public1, public); + u8 x_public2[32]; crypto_x25519_public_key (x_public2, x_private); status |= memcmp(x_public1, x_public2, 32); printf("%s: from_ed25519\n", status != 0 ? "FAILED" : "OK"); return status;