@pinkparrot/qsafe-mayo-wasm 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitmodules +3 -0
- package/.vscode/launch.json +12 -0
- package/LICENSE +201 -0
- package/bridge/mayo1_bridge.c +26 -0
- package/bridge/mayo2_bridge.c +26 -0
- package/bridge/randombytes_inject.c +44 -0
- package/build_mayo1.ps1 +36 -0
- package/build_mayo2.ps1 +36 -0
- package/dist/mayo.browser.min.js +216 -0
- package/dist/mayo1.js +0 -0
- package/dist/mayo2.js +0 -0
- package/dist/mayo_api.js +139 -0
- package/dist/package.json +1 -0
- package/gitignore +2 -0
- package/index.mjs +1 -0
- package/mayo-c/.astylerc +16 -0
- package/mayo-c/.cmake/flags.cmake +45 -0
- package/mayo-c/.cmake/sanitizers.cmake +81 -0
- package/mayo-c/.cmake/target.cmake +71 -0
- package/mayo-c/.github/workflows/ci_clang.yml +61 -0
- package/mayo-c/.github/workflows/ci_gcc.yml +60 -0
- package/mayo-c/.github/workflows/cmake.yml +160 -0
- package/mayo-c/.github/workflows/macos_m1.yml +68 -0
- package/mayo-c/CMakeLists.txt +35 -0
- package/mayo-c/KAT/PQCsignKAT_24_MAYO_1.req +900 -0
- package/mayo-c/KAT/PQCsignKAT_24_MAYO_1.rsp +902 -0
- package/mayo-c/KAT/PQCsignKAT_24_MAYO_2.req +900 -0
- package/mayo-c/KAT/PQCsignKAT_24_MAYO_2.rsp +902 -0
- package/mayo-c/KAT/PQCsignKAT_32_MAYO_3.req +900 -0
- package/mayo-c/KAT/PQCsignKAT_32_MAYO_3.rsp +902 -0
- package/mayo-c/KAT/PQCsignKAT_40_MAYO_5.req +900 -0
- package/mayo-c/KAT/PQCsignKAT_40_MAYO_5.rsp +902 -0
- package/mayo-c/LICENSE +202 -0
- package/mayo-c/META/MAYO-1_META.yml +52 -0
- package/mayo-c/META/MAYO-2_META.yml +52 -0
- package/mayo-c/META/MAYO-3_META.yml +52 -0
- package/mayo-c/META/MAYO-5_META.yml +52 -0
- package/mayo-c/NOTICE +13 -0
- package/mayo-c/README.md +183 -0
- package/mayo-c/apps/CMakeLists.txt +31 -0
- package/mayo-c/apps/PQCgenKAT_sign.c +281 -0
- package/mayo-c/apps/example.c +151 -0
- package/mayo-c/apps/example_nistapi.c +124 -0
- package/mayo-c/include/mayo.h +442 -0
- package/mayo-c/include/mem.h +25 -0
- package/mayo-c/include/randombytes.h +31 -0
- package/mayo-c/scripts/contstants.py +141 -0
- package/mayo-c/scripts/find_irred_poly.sage +39 -0
- package/mayo-c/src/AVX2/arithmetic_common.h +159 -0
- package/mayo-c/src/AVX2/echelon_form.h +91 -0
- package/mayo-c/src/AVX2/echelon_form_loop.h +58 -0
- package/mayo-c/src/AVX2/shuffle_arithmetic.h +442 -0
- package/mayo-c/src/CMakeLists.txt +98 -0
- package/mayo-c/src/arithmetic.c +128 -0
- package/mayo-c/src/arithmetic.h +124 -0
- package/mayo-c/src/common/aes128ctr.c +293 -0
- package/mayo-c/src/common/aes_c.c +741 -0
- package/mayo-c/src/common/aes_ctr.h +32 -0
- package/mayo-c/src/common/aes_neon.c +201 -0
- package/mayo-c/src/common/debug_bench_tools.h +69 -0
- package/mayo-c/src/common/fips202.c +1093 -0
- package/mayo-c/src/common/fips202.h +12 -0
- package/mayo-c/src/common/mem.c +19 -0
- package/mayo-c/src/common/randombytes_ctrdrbg.c +141 -0
- package/mayo-c/src/common/randombytes_system.c +399 -0
- package/mayo-c/src/generic/arithmetic_dynamic.h +68 -0
- package/mayo-c/src/generic/arithmetic_fixed.h +84 -0
- package/mayo-c/src/generic/echelon_form.h +152 -0
- package/mayo-c/src/generic/ef_inner_loop.h +56 -0
- package/mayo-c/src/generic/generic_arithmetic.h +294 -0
- package/mayo-c/src/mayo.c +675 -0
- package/mayo-c/src/mayo_1/api.c +46 -0
- package/mayo-c/src/mayo_1/api.h +43 -0
- package/mayo-c/src/mayo_2/api.c +46 -0
- package/mayo-c/src/mayo_2/api.h +43 -0
- package/mayo-c/src/mayo_3/api.c +46 -0
- package/mayo-c/src/mayo_3/api.h +43 -0
- package/mayo-c/src/mayo_5/api.c +46 -0
- package/mayo-c/src/mayo_5/api.h +43 -0
- package/mayo-c/src/neon/arithmetic_common.h +132 -0
- package/mayo-c/src/neon/echelon_form.h +55 -0
- package/mayo-c/src/neon/echelon_form_loop.h +58 -0
- package/mayo-c/src/neon/shuffle_arithmetic.h +462 -0
- package/mayo-c/src/params.c +42 -0
- package/mayo-c/src/simple_arithmetic.h +138 -0
- package/mayo-c/test/CMakeLists.txt +51 -0
- package/mayo-c/test/bench.c +166 -0
- package/mayo-c/test/m1cycles.c +155 -0
- package/mayo-c/test/m1cycles.h +13 -0
- package/mayo-c/test/test_kat.c +271 -0
- package/mayo-c/test/test_mayo.c +139 -0
- package/mayo-c/test/test_sample_solution.c +75 -0
- package/mayo-c/test/test_various.c +680 -0
- package/package.json +39 -0
- package/publish.bat +22 -0
- package/readme.md +80 -0
- package/test/test.mjs +42 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
|
|
3
|
+
#include <stdio.h>
|
|
4
|
+
#include <stdlib.h>
|
|
5
|
+
#include <string.h>
|
|
6
|
+
#include <ctype.h>
|
|
7
|
+
#include <randombytes.h>
|
|
8
|
+
#include <mayo.h>
|
|
9
|
+
#include <stdalign.h>
|
|
10
|
+
|
|
11
|
+
#ifdef ENABLE_CT_TESTING
|
|
12
|
+
#include <valgrind/memcheck.h>
|
|
13
|
+
#endif
|
|
14
|
+
|
|
15
|
+
#ifdef ENABLE_CT_TESTING
|
|
16
|
+
static void print_hex(const unsigned char *hex, int len) {
|
|
17
|
+
unsigned char *copy = calloc(len, 1);
|
|
18
|
+
memcpy(copy, hex, len); // make a copy that we can tell valgrind is okay to leak
|
|
19
|
+
VALGRIND_MAKE_MEM_DEFINED(copy, len);
|
|
20
|
+
|
|
21
|
+
for (int i = 0; i < len; ++i) {
|
|
22
|
+
printf("%02x", copy[i]);
|
|
23
|
+
}
|
|
24
|
+
printf("\n");
|
|
25
|
+
free(copy);
|
|
26
|
+
}
|
|
27
|
+
#else
|
|
28
|
+
static void print_hex(const unsigned char *hex, int len) {
|
|
29
|
+
for (int i = 0; i < len; ++i) {
|
|
30
|
+
printf("%02x", hex[i]);
|
|
31
|
+
}
|
|
32
|
+
printf("\n");
|
|
33
|
+
}
|
|
34
|
+
#endif
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
static int test_mayo(const mayo_params_t *p) {
|
|
38
|
+
unsigned char _pk[CPK_BYTES_MAX + 1] = {0};
|
|
39
|
+
unsigned char _sk[CSK_BYTES_MAX + 1] = {0};
|
|
40
|
+
unsigned char _sig[SIG_BYTES_MAX + 32 + 1] = {0};
|
|
41
|
+
unsigned char _msg[32+1] = { 0 };
|
|
42
|
+
|
|
43
|
+
// Enforce unaligned memory addresses
|
|
44
|
+
unsigned char *pk = (unsigned char *) ((uintptr_t)_pk | (uintptr_t)1);
|
|
45
|
+
unsigned char *sk = (unsigned char *) ((uintptr_t)_sk | (uintptr_t)1);
|
|
46
|
+
unsigned char *sig = (unsigned char *) ((uintptr_t)_sig | (uintptr_t)1);
|
|
47
|
+
unsigned char *msg = (unsigned char *) ((uintptr_t)_msg | (uintptr_t)1);
|
|
48
|
+
|
|
49
|
+
for (int i = 0; i < 32; i++) {
|
|
50
|
+
msg[i] = i;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
unsigned char seed[48] = { 0 };
|
|
54
|
+
size_t msglen = 32;
|
|
55
|
+
|
|
56
|
+
randombytes_init(seed, NULL, 256);
|
|
57
|
+
|
|
58
|
+
printf("Testing Keygen, Sign, Open: %s\n", PARAM_name(p));
|
|
59
|
+
|
|
60
|
+
int res = mayo_keypair(p, pk, sk);
|
|
61
|
+
if (res != MAYO_OK) {
|
|
62
|
+
res = -1;
|
|
63
|
+
printf("keygen failed!\n");
|
|
64
|
+
goto err;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
#ifdef ENABLE_CT_TESTING
|
|
68
|
+
VALGRIND_MAKE_MEM_DEFINED(pk, PARAM_cpk_bytes(p));
|
|
69
|
+
#endif
|
|
70
|
+
|
|
71
|
+
size_t smlen = PARAM_sig_bytes(p) + 32;
|
|
72
|
+
|
|
73
|
+
res = mayo_sign(p, sig, &smlen, msg, 32, sk);
|
|
74
|
+
if (res != MAYO_OK) {
|
|
75
|
+
res = -1;
|
|
76
|
+
printf("sign failed!\n");
|
|
77
|
+
goto err;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
printf("pk: ");
|
|
81
|
+
print_hex(pk, PARAM_cpk_bytes(p));
|
|
82
|
+
printf("sk: ");
|
|
83
|
+
print_hex(sk, PARAM_csk_bytes(p));
|
|
84
|
+
printf("sm: ");
|
|
85
|
+
print_hex(sig, smlen);
|
|
86
|
+
|
|
87
|
+
#ifdef ENABLE_CT_TESTING
|
|
88
|
+
VALGRIND_MAKE_MEM_DEFINED(sig, smlen);
|
|
89
|
+
#endif
|
|
90
|
+
|
|
91
|
+
res = mayo_open(p, msg, &msglen, sig, smlen, pk);
|
|
92
|
+
if (res != MAYO_OK) {
|
|
93
|
+
res = -1;
|
|
94
|
+
printf("verify failed!\n");
|
|
95
|
+
goto err;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
printf("verify success!\n");
|
|
99
|
+
|
|
100
|
+
sig[0] = ~sig[0];
|
|
101
|
+
res = mayo_open(p, msg, &msglen, sig, smlen, pk);
|
|
102
|
+
if (res != MAYO_ERR) {
|
|
103
|
+
res = -1;
|
|
104
|
+
printf("wrong signature still verified!\n");
|
|
105
|
+
goto err;
|
|
106
|
+
} else {
|
|
107
|
+
res = MAYO_OK;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
err:
|
|
111
|
+
return res;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
int main(int argc, char *argv[]) {
|
|
115
|
+
int rc = 0;
|
|
116
|
+
|
|
117
|
+
#ifdef ENABLE_PARAMS_DYNAMIC
|
|
118
|
+
if (!strcmp(argv[1], "MAYO-1")) {
|
|
119
|
+
rc = test_mayo(&MAYO_1);
|
|
120
|
+
} else if (!strcmp(argv[1], "MAYO-2")) {
|
|
121
|
+
rc = test_mayo(&MAYO_2);
|
|
122
|
+
} else if (!strcmp(argv[1], "MAYO-3")) {
|
|
123
|
+
rc = test_mayo(&MAYO_3);
|
|
124
|
+
} else if (!strcmp(argv[1], "MAYO-5")) {
|
|
125
|
+
rc = test_mayo(&MAYO_5);
|
|
126
|
+
} else {
|
|
127
|
+
printf("unknown parameter set\n");
|
|
128
|
+
return MAYO_ERR;
|
|
129
|
+
}
|
|
130
|
+
#else
|
|
131
|
+
rc = test_mayo(NULL);
|
|
132
|
+
#endif
|
|
133
|
+
|
|
134
|
+
if (rc != MAYO_OK) {
|
|
135
|
+
printf("test failed for %s\n", argv[1]);
|
|
136
|
+
}
|
|
137
|
+
return rc;
|
|
138
|
+
}
|
|
139
|
+
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Test case for sample_solution failing in crypto_sign.
|
|
5
|
+
*/
|
|
6
|
+
#include <api.h>
|
|
7
|
+
#include <mem.h>
|
|
8
|
+
#include <string.h>
|
|
9
|
+
#include <stdlib.h>
|
|
10
|
+
#include <stdio.h>
|
|
11
|
+
#include <randombytes.h>
|
|
12
|
+
|
|
13
|
+
static int test_sample_solution(void) {
|
|
14
|
+
|
|
15
|
+
#if CRYPTO_BYTES == 454 // MAYO-1
|
|
16
|
+
unsigned char entropy_input[48] = { 0xbf, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
|
17
|
+
#elif CRYPTO_BYTES == 186 // MAYO-2
|
|
18
|
+
unsigned char entropy_input[48] = { 0x33, 0x34, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
|
19
|
+
#elif CRYPTO_BYTES == 681 // MAYO-3
|
|
20
|
+
unsigned char entropy_input[48] = { 0xdb, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
|
21
|
+
#elif CRYPTO_BYTES == 964 // MAYO-5
|
|
22
|
+
unsigned char entropy_input[48] = { 0x87, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
|
23
|
+
#else
|
|
24
|
+
#error "variant not supported"
|
|
25
|
+
#endif
|
|
26
|
+
|
|
27
|
+
size_t msglen = 32;
|
|
28
|
+
size_t smlen = CRYPTO_BYTES + msglen;
|
|
29
|
+
|
|
30
|
+
unsigned char *pk = calloc(CRYPTO_PUBLICKEYBYTES, 1);
|
|
31
|
+
unsigned char *sk = calloc(CRYPTO_SECRETKEYBYTES, 1);
|
|
32
|
+
|
|
33
|
+
unsigned char *sig = calloc(smlen, 1);
|
|
34
|
+
|
|
35
|
+
unsigned char msg[32];
|
|
36
|
+
unsigned char msgOpen[32] = { 0 };
|
|
37
|
+
|
|
38
|
+
int res = 0;
|
|
39
|
+
randombytes_init(entropy_input, NULL, 256);
|
|
40
|
+
|
|
41
|
+
for (int i = 0; i < 32; i++) {
|
|
42
|
+
msg[i] = i;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
res = crypto_sign_keypair(pk, sk);
|
|
46
|
+
if (res) {
|
|
47
|
+
printf("crypto_sign_keypair failed\n");
|
|
48
|
+
goto err;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
res = crypto_sign(sig, &smlen, msg, msglen, sk);
|
|
52
|
+
|
|
53
|
+
if (res) {
|
|
54
|
+
printf("crypto_sign failed\n");
|
|
55
|
+
goto err;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
res = crypto_sign_open(msgOpen, &msglen, sig, smlen, pk);
|
|
59
|
+
if (res || memcmp(msg, msgOpen, msglen)) {
|
|
60
|
+
printf("crypto_sign_open failed\n");
|
|
61
|
+
res = -1;
|
|
62
|
+
goto err;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
err:
|
|
66
|
+
free(pk);
|
|
67
|
+
mayo_secure_free(sk, CRYPTO_SECRETKEYBYTES);
|
|
68
|
+
free(sig);
|
|
69
|
+
return res;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
int main(int argc, char *argv[]) {
|
|
73
|
+
return test_sample_solution();
|
|
74
|
+
}
|
|
75
|
+
|