 Minor
src/include/barrett_field.h:
- Requires review: corrected failure to cast to (mask_t) prior to negation. (Or, if this is wrong; should cast to needed bitwidth explicitly.)
- Changed type of nwords_out to uint32_t to agree with header.
src/include/intrinsics.h:
- Fixed up various preprocessor statements to check for definition rather than value of built-ins.
- Added macro to use Clang’s __builtin_readcyclecounter on platforms on which it’s available. (Which is most platforms these days.)
src/include/magic.h: Preprocessor “if” versus “if defined”.
src/include/word.h: Fixed ifdefs; enabled support for memset_s on Darwin. Added explicit cast to mask_t.
Added void to function definitions and declarations in the following files (not including void is okay in modern C++, but not modern C, IIRC):
include/goldilocks.h, src/crandom.c, src/goldilocks.c, src/include/api.h, src/include/intrinsics.h, test/bench.c, test/test.c, test/test.h, test/test_arithmetic.c, test/test_goldilocks.c, test/test_pointops.c, test/test_scalarmul.c, test/test_sha512.c
10 years ago  Minor
src/include/barrett_field.h:
- Requires review: corrected failure to cast to (mask_t) prior to negation. (Or, if this is wrong; should cast to needed bitwidth explicitly.)
- Changed type of nwords_out to uint32_t to agree with header.
src/include/intrinsics.h:
- Fixed up various preprocessor statements to check for definition rather than value of built-ins.
- Added macro to use Clang’s __builtin_readcyclecounter on platforms on which it’s available. (Which is most platforms these days.)
src/include/magic.h: Preprocessor “if” versus “if defined”.
src/include/word.h: Fixed ifdefs; enabled support for memset_s on Darwin. Added explicit cast to mask_t.
Added void to function definitions and declarations in the following files (not including void is okay in modern C++, but not modern C, IIRC):
include/goldilocks.h, src/crandom.c, src/goldilocks.c, src/include/api.h, src/include/intrinsics.h, test/bench.c, test/test.c, test/test.h, test/test_arithmetic.c, test/test_goldilocks.c, test/test_pointops.c, test/test_scalarmul.c, test/test_sha512.c
10 years ago Big changes for curve flexibility. For details see HISTORY.txt.
Very experimental Ed480-Ridinghood support is now in. It's not fully optimized,
but in general the current build is 8-15% slower than Goldilocks. It only works on
arch_x86_64, though arch_ref64 support ought to be easy. Support on other arches
will be trickier, which is of course why I chose Goldilocks over Ridinghood in the
first place.
Next up, E-521. Hopefully.
The code is starting to get spread out over a lot of files. Some are per field*arch,
some per field, some per curve, some global. It's hard to do much about this, though,
with a rather ugly .c.inc system.
There's currently no way to make a Ridinghood eBAT. In fact, I haven't tested eBAT
support in this commit. I also haven't tested NEON, but at least ARCH_32 works on
Intel.
10 years ago Big changes for curve flexibility. For details see HISTORY.txt.
Very experimental Ed480-Ridinghood support is now in. It's not fully optimized,
but in general the current build is 8-15% slower than Goldilocks. It only works on
arch_x86_64, though arch_ref64 support ought to be easy. Support on other arches
will be trickier, which is of course why I chose Goldilocks over Ridinghood in the
first place.
Next up, E-521. Hopefully.
The code is starting to get spread out over a lot of files. Some are per field*arch,
some per field, some per curve, some global. It's hard to do much about this, though,
with a rather ugly .c.inc system.
There's currently no way to make a Ridinghood eBAT. In fact, I haven't tested eBAT
support in this commit. I also haven't tested NEON, but at least ARCH_32 works on
Intel.
10 years ago |
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- #include "test.h"
-
- #include <stdio.h>
- #include <string.h>
-
- #ifndef LIMBPERM
- #define LIMBPERM(x) (x)
- #endif
-
- int failed_tests, n_tests, failed_this_test, running_a_test;
-
- static void end_test(void) {
- if (!failed_this_test) {
- printf("[PASS]\n");
- }
- n_tests ++;
- running_a_test = 0;
- }
-
- static void begin_test(const char *name) {
- if (running_a_test) end_test();
- printf("%s...%*s",name,(int)(30-strlen(name)),"");
- fflush(stdout);
- failed_this_test = 0;
- running_a_test = 1;
- }
-
- void youfail(void) {
- if (failed_this_test) return;
- failed_this_test = 1;
- failed_tests ++;
- printf("[FAIL]\n");
- }
-
- static int
- hexchar (char c) {
- if (c >= '0' && c <= '9') {
- return c - '0';
- } else if (c >= 'a' && c <= 'f') {
- return 10 + c - 'a';
- } else if (c >= 'A' && c <= 'F') {
- return 10 + c - 'A';
- } else {
- return -1;
- }
- }
-
- int
- hexdecode (
- unsigned char *bytes,
- const char *hex,
- unsigned int nbytes
- ) {
- if (strlen(hex) != nbytes*2) {
- return -1;
- }
-
- unsigned int i;
- for (i=0; i<nbytes; i++) {
- int hi = hexchar(hex[2*i]),
- lo = hexchar(hex[2*i+1]);
- if (hi<0 || lo<0) return -1;
- bytes[i] = hi*16 + lo;
- }
-
- return 0;
- }
-
- void
- hexprint (
- const char *descr,
- const unsigned char *bytes,
- unsigned int nbytes
- ) {
- if (descr) printf("%s = ", descr);
- unsigned int i;
- for (i=0; i<nbytes; i++) {
- printf("%02x", bytes[i]);
- }
- printf("\n");
- }
-
- void field_print (
- const char *descr,
- const field_a_t a
- ) {
- int j;
- unsigned char ser[FIELD_BYTES];
- field_serialize(ser,a);
- printf("%s = 0x", descr);
- for (j=FIELD_BYTES - 1; j>=0; j--) {
- printf("%02x", ser[j]);
- }
- printf("\n");
- }
-
- void scalar_print (
- const char *descr,
- const word_t *scalar,
- int nwords
- ) {
- int j;
- printf("%s = 0x", descr);
- for (j=nwords-1; j>=0; j--) {
- printf(PRIxWORDfull, scalar[j]);
- }
- printf("\n");
- }
-
- int main(int argc, char **argv) {
- (void) argc;
- (void) argv;
-
- n_tests = running_a_test = failed_tests = 0;
-
- begin_test("Arithmetic");
- test_arithmetic();
-
- begin_test("EC point operations");
- test_pointops();
-
- begin_test("Decaf point encoding");
- test_decaf();
-
- begin_test("Decaf pathological cases");
- test_decaf_evil();
-
- begin_test("Scalarmul compatibility");
- test_scalarmul_compatibility();
-
- begin_test("Scalarmul commutativity");
- test_scalarmul_commutativity();
-
- begin_test("Linear combo");
- test_linear_combo();
-
- begin_test("SHA-512 NIST Monte Carlo");
- test_sha512_monte_carlo();
-
- begin_test("Goldilocks complete system");
- test_goldilocks();
-
- if (running_a_test) end_test();
- printf("\n");
- if (failed_tests) {
- printf("Failed %d / %d tests.\n", failed_tests, n_tests);
- } else {
- printf("Passed all %d tests.\n", n_tests);
- }
-
- return failed_tests ? 1 : 0;
- }
|