forked from sphincs/sphincsplus
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
470573f
commit 09bd874
Showing
9 changed files
with
299 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ jobs: | |
- thash_4x | ||
- hash4x | ||
- forsx4 | ||
- wots | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Compile tests | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,6 @@ jobs: | |
- thash | ||
- hash | ||
- fors | ||
- wotsx | ||
- merkle | ||
- sign | ||
steps: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
#include <assert.h> | ||
#include <inttypes.h> | ||
#include <stdbool.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#include "address.h" | ||
#include "api.h" | ||
#include "context.h" | ||
#include "hash.h" | ||
#include "hashx4.h" | ||
#include "print.h" | ||
#include "utils.h" | ||
#include "utilsx4.h" | ||
#include "wots.h" | ||
#include "wotsx4.h" | ||
|
||
#ifndef TESTS | ||
#define TESTS 10000 | ||
#endif | ||
|
||
extern void wots_checksum_jazz(uint32_t *csum_base_w, const uint32_t *msg_base_w); | ||
extern void chain_lengths_jazz(uint32_t *lengths, const uint8_t *msg); | ||
|
||
void test_wots_checksum(void) { | ||
bool debug = true; | ||
|
||
uint32_t csum_base_w_ref[SPX_WOTS_LEN2], csum_base_w_jazz[SPX_WOTS_LEN2]; | ||
uint32_t msg_base_w[SPX_WOTS_LEN]; | ||
|
||
for (int i = 0; i < TESTS; i++) { | ||
if (debug) { | ||
printf("[%s]: Wots Checksum: Test %d/%d\n", xstr(PARAMS), i, TESTS); | ||
} | ||
|
||
memset((uint8_t *)csum_base_w_ref, 0, SPX_WOTS_LEN2 * sizeof(uint32_t)); | ||
memset((uint8_t *)csum_base_w_jazz, 0, SPX_WOTS_LEN2 * sizeof(uint32_t)); | ||
|
||
randombytes((uint8_t *)msg_base_w, SPX_WOTS_LEN * sizeof(uint32_t)); | ||
|
||
wots_checksum(csum_base_w_ref, msg_base_w); | ||
wots_checksum_jazz(csum_base_w_jazz, msg_base_w); | ||
|
||
if (memcmp(csum_base_w_ref, csum_base_w_jazz, SPX_WOTS_LEN2 * sizeof(uint32_t)) != 0) { | ||
print_str_u8("ref", (uint8_t *)csum_base_w_ref, SPX_WOTS_LEN2 * sizeof(uint32_t)); | ||
print_str_u8("jazz", (uint8_t *)csum_base_w_jazz, SPX_WOTS_LEN2 * sizeof(uint32_t)); | ||
} | ||
|
||
assert(memcmp(csum_base_w_ref, csum_base_w_jazz, SPX_WOTS_LEN2 * sizeof(uint32_t)) == 0); | ||
} | ||
} | ||
|
||
void test_chain_lengths(void) { | ||
bool debug = true; | ||
|
||
unsigned int lengths_ref[SPX_WOTS_LEN]; | ||
uint32_t lengths_jazz[SPX_WOTS_LEN]; | ||
uint8_t msg[SPX_N]; | ||
|
||
for (int t = 0; t < TESTS; t++) { | ||
if (debug) { | ||
printf("[%s]: Chain Lengths: Test %d/%d\n", xstr(PARAMS), t, TESTS); | ||
} | ||
|
||
memset(lengths_ref, 0, SPX_WOTS_LEN * sizeof(unsigned int)); | ||
memset(lengths_jazz, 0, SPX_WOTS_LEN * sizeof(uint32_t)); | ||
randombytes(msg, SPX_N); | ||
|
||
chain_lengths(lengths_ref, msg); | ||
chain_lengths_jazz(lengths_jazz, msg); | ||
|
||
assert(memcmp(lengths_ref, lengths_jazz, SPX_WOTS_LEN * sizeof(uint32_t)) == 0); | ||
} | ||
} | ||
|
||
void test_api(void) { | ||
bool debug = true; | ||
|
||
#define MAX_MESSAGE_LENGTH 1024 | ||
#define TESTS 100 | ||
|
||
uint8_t secret_key[CRYPTO_SECRETKEYBYTES]; | ||
uint8_t public_key[CRYPTO_PUBLICKEYBYTES]; | ||
|
||
uint8_t signature[CRYPTO_BYTES]; | ||
size_t signature_length; | ||
|
||
uint8_t message[MAX_MESSAGE_LENGTH]; | ||
|
||
for (int i = 0; i < TESTS; i++) { | ||
for (size_t message_length = 1; message_length < MAX_MESSAGE_LENGTH; message_length++) { | ||
if (debug) { | ||
printf("[%s]: Test %d/%d [Len=%ld]\n", xstr(PARAMS), i, TESTS, message_length); | ||
} | ||
|
||
randombytes(message, message_length); | ||
crypto_sign_keypair(public_key, secret_key); | ||
crypto_sign_signature(signature, &signature_length, message, message_length, secret_key); | ||
assert(signature_length == CRYPTO_BYTES); | ||
assert(crypto_sign_verify(signature, signature_length, message, message_length, public_key) == 0); | ||
} | ||
} | ||
|
||
#undef MESSAGE_LENGTH | ||
} | ||
|
||
int main(void) { | ||
test_wots_checksum(); // Same as ref-jasmin | ||
test_chain_lengths(); // Same as ref-jasmin | ||
test_api(); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from Sphincs require "wots/wots.jtmpl" | ||
from Sphincs require "generic/utils.jtmpl" | ||
|
||
export fn wots_checksum_jazz(reg u64 _csum_base_w _msg_base_w) | ||
{ | ||
stack u32[SPX_WOTS_LEN2] csum_base_w; | ||
stack u32[SPX_WOTS_LEN] msg_base_w; | ||
|
||
reg ptr u32[SPX_WOTS_LEN2] csum_base_w_p; | ||
reg ptr u32[SPX_WOTS_LEN] msg_base_w_p; | ||
|
||
stack u64 s_csum_base_w s_msg_base_w; | ||
|
||
csum_base_w_p = csum_base_w; | ||
csum_base_w_p = __load_u32_array<SPX_WOTS_LEN2>(csum_base_w_p, _csum_base_w); | ||
|
||
msg_base_w_p = msg_base_w; | ||
msg_base_w_p = __load_u32_array<SPX_WOTS_LEN>(msg_base_w_p, _msg_base_w); | ||
|
||
s_csum_base_w = _csum_base_w; // spill | ||
|
||
csum_base_w_p = __wots_checksum(csum_base_w_p, msg_base_w_p); | ||
|
||
_csum_base_w = s_csum_base_w; // unspill | ||
|
||
__store_u32_array<SPX_WOTS_LEN2>(csum_base_w_p, _csum_base_w); | ||
} | ||
|
||
export fn chain_lengths_jazz(reg u64 _lengths _msg) | ||
{ | ||
stack u32[SPX_WOTS_LEN] lengths; | ||
stack u8[SPX_N] msg; | ||
|
||
reg ptr u32[SPX_WOTS_LEN] lengths_p; | ||
reg ptr u8[SPX_N] msg_p; | ||
|
||
stack u64 s_lengths s_msg; | ||
|
||
lengths_p = lengths; | ||
lengths_p = __load_u32_array<SPX_WOTS_LEN>(lengths_p, _lengths); | ||
|
||
msg_p = msg; | ||
msg_p = __load_u8_array<SPX_N>(msg_p, _msg); | ||
|
||
s_lengths = _lengths; s_msg = _msg; // spill | ||
|
||
lengths_p = __chain_lengths(lengths_p, msg_p); | ||
msg = msg_p; | ||
|
||
s_lengths = _lengths; // spill | ||
__store_u32_array<SPX_WOTS_LEN>(lengths_p, _lengths); | ||
} |
Oops, something went wrong.