aboutsummaryrefslogtreecommitdiff
path: root/src/Specific
diff options
context:
space:
mode:
authorGravatar Andres Erbsen <andreser@mit.edu>2017-07-03 16:31:39 -0400
committerGravatar Andres Erbsen <andreser@mit.edu>2017-07-03 22:44:19 -0400
commit189aa1564635ba575439b731d8b638a445b9c7b1 (patch)
tree9aebcaf08d0128db69068f28fa15abfccf517093 /src/Specific
parent8b9c825a7c3d71ee62419d973ea138adec49da4e (diff)
fix mulx argument order using sed, test feadd, femul (fails due to #234)
Diffstat (limited to 'src/Specific')
-rw-r--r--src/Specific/NISTP256/AMD64/measurements.txt2
-rw-r--r--src/Specific/NISTP256/AMD64/test/feadd_test.c46
-rw-r--r--src/Specific/NISTP256/AMD64/test/femul_test.c48
3 files changed, 95 insertions, 1 deletions
diff --git a/src/Specific/NISTP256/AMD64/measurements.txt b/src/Specific/NISTP256/AMD64/measurements.txt
index 1ec583018..d4dca8e54 100644
--- a/src/Specific/NISTP256/AMD64/measurements.txt
+++ b/src/Specific/NISTP256/AMD64/measurements.txt
@@ -1,2 +1,2 @@
1576 ashryn-noht-notb-noac-broadwell 2.60ghz 7.1.1 cac291e0
-1688 ashryn-noht-notb-ac-broadwell 2.50ghz 7.1.1 d7ad9528
+1640 ashryn-noht-notb-ac-broadwell 2.50ghz 7.1.1 6c558bd2
diff --git a/src/Specific/NISTP256/AMD64/test/feadd_test.c b/src/Specific/NISTP256/AMD64/test/feadd_test.c
new file mode 100644
index 000000000..3cdd1fd60
--- /dev/null
+++ b/src/Specific/NISTP256/AMD64/test/feadd_test.c
@@ -0,0 +1,46 @@
+#include <stdint.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include "feadd.h"
+
+static int check(uint64_t out[4], uint64_t ref[4]) {
+ return out[0] == ref[0] && out[1] == ref[1] && out[2] == ref[2] && out[3] == ref[3];
+}
+
+int main() {
+ {
+ uint64_t out[4] = {0};
+ uint64_t in1[4] = {0, 0, 0, 1};
+ uint64_t in2[4] = {0, 0, 0, 1};
+ uint64_t ref[4] = {0, 0, 0, 2};
+ feadd(out, in1[0], in1[1], in1[2], in1[3], in2[0], in2[1], in2[2], in2[3]);
+ if (!check(out, ref)) return 1;
+ }
+ {
+ uint64_t out[4] = {0};
+ uint64_t in1[4] = {0, 0, 0, 0};
+ uint64_t in2[4] = {0, 0, 0, 0};
+ uint64_t ref[4] = {0, 0, 0, 0};
+ feadd(out, in1[0], in1[1], in1[2], in1[3], in2[0], in2[1], in2[2], in2[3]);
+ if (!check(out, ref)) return 2;
+ }
+ {
+ uint64_t out[4] = {0};
+ uint64_t in1[4] = {0xffffffff00000001, 0x0000000000000000, 0x00000000ffffffff, 0xfffffffffffffffe}; // p256-1
+ uint64_t in2[4] = {0, 0, 0, 1};
+ uint64_t ref[4] = {0, 0, 0, 0};
+ feadd(out, in1[0], in1[1], in1[2], in1[3], in2[0], in2[1], in2[2], in2[3]);
+ if (!check(out, ref)) return 3;
+ }
+ {
+ uint64_t out[4] = {0};
+ uint64_t in1[4] = {0xffffffff00000001, 0x0000000000000000, 0x00000000ffffffff, 0xfffffffffffffffe}; // p256-1
+ uint64_t in2[4] = {0, 0, 0, 7};
+ uint64_t ref[4] = {0, 0, 0, 6};
+ feadd(out, in1[0], in1[1], in1[2], in1[3], in2[0], in2[1], in2[2], in2[3]);
+ if (!check(out, ref)) return 4;
+ }
+
+ //printf("0x%016" PRIx64 " 0x%016" PRIx64 " 0x%016" PRIx64 " 0x%016" PRIx64 "\n", out[0], out[1], out[2], out[3]);
+ //printf("((((((0x%016" PRIx64 "<<64)+ 0x%016" PRIx64 ")<<64)+ 0x%016" PRIx64 ")<<64)+ 0x%016" PRIx64 ")\n", out[0], out[1], out[2], out[3]);
+}
diff --git a/src/Specific/NISTP256/AMD64/test/femul_test.c b/src/Specific/NISTP256/AMD64/test/femul_test.c
new file mode 100644
index 000000000..9519399e0
--- /dev/null
+++ b/src/Specific/NISTP256/AMD64/test/femul_test.c
@@ -0,0 +1,48 @@
+#include <stdint.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include "femul.h"
+
+// all arrays big-endian
+static uint64_t Rmodm[4] = {0xfffffffe, 0xffffffffffffffff, 0xffffffff00000000, 0x0000000000000001};
+
+int main() {
+ uint64_t out[4] = {0};
+ if ( femul(out,
+ Rmodm[0], Rmodm[1], Rmodm[2], Rmodm[3],
+ Rmodm[0], Rmodm[1], Rmodm[2], Rmodm[3]),
+ ! (out[0] == Rmodm[0]
+ && out[1] == Rmodm[1]
+ && out[2] == Rmodm[2]
+ && out[3] == Rmodm[3]
+ )) { return 1; }
+ if ( femul(out,
+ 0, 0, 0, 0,
+ Rmodm[0], Rmodm[1], Rmodm[2], Rmodm[3]),
+ ! (out[0] == 0
+ && out[1] == 0
+ && out[2] == 0
+ && out[3] == 0
+ )) { return 2; }
+ if ( femul(out,
+ 0, 0, 0, 1,
+ 0, 0, 0, 1),
+ ! (out[0] == 0xfffffffe00000003 // R^-1
+ && out[1] == 0xfffffffd00000002
+ && out[2] == 0x00000001fffffffe
+ && out[3] == 0x0000000300000000
+ )) { return 3; }
+ if ( femul(out,
+ 0, 0, 0, 1,
+ 0x4fffffffd, 0xfffffffffffffffe, 0xfffffffbffffffff, 0x0000000000000003), // R^2
+ ! (out[0] == Rmodm[0]
+ && out[1] == Rmodm[1]
+ && out[2] == Rmodm[2]
+ && out[3] == Rmodm[3]
+ )) { return 4; }
+
+
+ //printf("0x%016" PRIx64 " 0x%016" PRIx64 " 0x%016" PRIx64 " 0x%016" PRIx64 "\n", out[0], out[1], out[2], out[3]);
+ //printf("((((((0x%016" PRIx64 "<<64)+ 0x%016" PRIx64 ")<<64)+ 0x%016" PRIx64 ")<<64)+ 0x%016" PRIx64 ")\n", out[0], out[1], out[2], out[3]);
+ return 0;
+}