@pulse-compute/crypto 1.0.0-beta.4 → 1.0.0-beta.6

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.
Files changed (95) hide show
  1. package/README.md +89 -8
  2. package/as/digest-text.as.ts +34 -0
  3. package/as/pulse-hmac-as.ts +7 -1
  4. package/conformance/digest-text.json +38 -0
  5. package/conformance/hs256.json +85 -0
  6. package/dist/contracts.d.ts +34 -12
  7. package/dist/contracts.d.ts.map +1 -1
  8. package/dist/contracts.js +9 -3
  9. package/dist/contracts.js.map +1 -1
  10. package/dist/digest.d.ts +14 -0
  11. package/dist/digest.d.ts.map +1 -0
  12. package/dist/digest.js +17 -0
  13. package/dist/digest.js.map +1 -0
  14. package/dist/index.d.ts +6 -0
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +20 -0
  17. package/dist/index.js.map +1 -1
  18. package/dist/internal/rsa.d.ts +58 -0
  19. package/dist/internal/rsa.d.ts.map +1 -0
  20. package/dist/internal/rsa.js +185 -0
  21. package/dist/internal/rsa.js.map +1 -0
  22. package/dist/internal/verification.d.ts +3 -3
  23. package/dist/internal/verification.d.ts.map +1 -1
  24. package/dist/internal/verification.js +2 -2
  25. package/dist/internal/verification.js.map +1 -1
  26. package/guests/es256-rustcrypto/README.md +43 -0
  27. package/guests/es256-rustcrypto/build.cjs +297 -0
  28. package/guests/es256-rustcrypto/prebuilt/es256-verifier.unoptimized.wasm +0 -0
  29. package/guests/es256-rustcrypto/prebuilt/es256-verifier.wasm +0 -0
  30. package/guests/es256-rustcrypto/probe/.cargo/config.toml +18 -0
  31. package/guests/es256-rustcrypto/probe/Cargo.lock +238 -0
  32. package/guests/es256-rustcrypto/probe/Cargo.toml +26 -0
  33. package/guests/es256-rustcrypto/probe/README.md +35 -0
  34. package/guests/es256-rustcrypto/probe/rust-toolchain.toml +5 -0
  35. package/guests/es256-rustcrypto/probe/src/lib.rs +108 -0
  36. package/guests/es256-rustcrypto/pulse.guest-unit.json +119 -0
  37. package/guests/es256-rustcrypto/source/.cargo/config.toml +18 -0
  38. package/guests/es256-rustcrypto/source/Cargo.lock +265 -0
  39. package/guests/es256-rustcrypto/source/Cargo.toml +23 -0
  40. package/guests/es256-rustcrypto/source/README.md +26 -0
  41. package/guests/es256-rustcrypto/source/bearssl/LICENSE.txt +21 -0
  42. package/guests/es256-rustcrypto/source/bearssl/UPSTREAM.json +49 -0
  43. package/guests/es256-rustcrypto/source/bearssl/inc/bearssl.h +170 -0
  44. package/guests/es256-rustcrypto/source/bearssl/inc/bearssl_aead.h +1059 -0
  45. package/guests/es256-rustcrypto/source/bearssl/inc/bearssl_block.h +2618 -0
  46. package/guests/es256-rustcrypto/source/bearssl/inc/bearssl_ec.h +883 -0
  47. package/guests/es256-rustcrypto/source/bearssl/inc/bearssl_hash.h +1346 -0
  48. package/guests/es256-rustcrypto/source/bearssl/inc/bearssl_hmac.h +241 -0
  49. package/guests/es256-rustcrypto/source/bearssl/inc/bearssl_kdf.h +185 -0
  50. package/guests/es256-rustcrypto/source/bearssl/inc/bearssl_pem.h +294 -0
  51. package/guests/es256-rustcrypto/source/bearssl/inc/bearssl_prf.h +150 -0
  52. package/guests/es256-rustcrypto/source/bearssl/inc/bearssl_rand.h +397 -0
  53. package/guests/es256-rustcrypto/source/bearssl/inc/bearssl_rsa.h +1366 -0
  54. package/guests/es256-rustcrypto/source/bearssl/inc/bearssl_ssl.h +4296 -0
  55. package/guests/es256-rustcrypto/source/bearssl/inc/bearssl_x509.h +1397 -0
  56. package/guests/es256-rustcrypto/source/bearssl/src/codec/ccopy.c +44 -0
  57. package/guests/es256-rustcrypto/source/bearssl/src/codec/dec32be.c +38 -0
  58. package/guests/es256-rustcrypto/source/bearssl/src/codec/enc32be.c +38 -0
  59. package/guests/es256-rustcrypto/source/bearssl/src/config.h +229 -0
  60. package/guests/es256-rustcrypto/source/bearssl/src/inner.h +2532 -0
  61. package/guests/es256-rustcrypto/source/bearssl/src/int/i31_add.c +46 -0
  62. package/guests/es256-rustcrypto/source/bearssl/src/int/i31_bitlen.c +44 -0
  63. package/guests/es256-rustcrypto/source/bearssl/src/int/i31_decmod.c +124 -0
  64. package/guests/es256-rustcrypto/source/bearssl/src/int/i31_decode.c +57 -0
  65. package/guests/es256-rustcrypto/source/bearssl/src/int/i31_decred.c +103 -0
  66. package/guests/es256-rustcrypto/source/bearssl/src/int/i31_encode.c +79 -0
  67. package/guests/es256-rustcrypto/source/bearssl/src/int/i31_fmont.c +60 -0
  68. package/guests/es256-rustcrypto/source/bearssl/src/int/i31_iszero.c +39 -0
  69. package/guests/es256-rustcrypto/source/bearssl/src/int/i31_moddiv.c +488 -0
  70. package/guests/es256-rustcrypto/source/bearssl/src/int/i31_modpow.c +65 -0
  71. package/guests/es256-rustcrypto/source/bearssl/src/int/i31_modpow2.c +160 -0
  72. package/guests/es256-rustcrypto/source/bearssl/src/int/i31_montmul.c +93 -0
  73. package/guests/es256-rustcrypto/source/bearssl/src/int/i31_mulacc.c +61 -0
  74. package/guests/es256-rustcrypto/source/bearssl/src/int/i31_muladd.c +157 -0
  75. package/guests/es256-rustcrypto/source/bearssl/src/int/i31_ninv31.c +39 -0
  76. package/guests/es256-rustcrypto/source/bearssl/src/int/i31_reduce.c +66 -0
  77. package/guests/es256-rustcrypto/source/bearssl/src/int/i31_rshift.c +47 -0
  78. package/guests/es256-rustcrypto/source/bearssl/src/int/i31_sub.c +46 -0
  79. package/guests/es256-rustcrypto/source/bearssl/src/int/i31_tmont.c +36 -0
  80. package/guests/es256-rustcrypto/source/bearssl/src/int/i32_div32.c +56 -0
  81. package/guests/es256-rustcrypto/source/bearssl/src/rsa/rsa_i31_priv.c +203 -0
  82. package/guests/es256-rustcrypto/source/bearssl/src/rsa/rsa_i31_pub.c +106 -0
  83. package/guests/es256-rustcrypto/source/bearssl/src/rsa/rsa_pkcs1_sig_pad.c +100 -0
  84. package/guests/es256-rustcrypto/source/build.rs +38 -0
  85. package/guests/es256-rustcrypto/source/freestanding/string.h +8 -0
  86. package/guests/es256-rustcrypto/source/rs256.c +103 -0
  87. package/guests/es256-rustcrypto/source/rust-toolchain.toml +5 -0
  88. package/guests/es256-rustcrypto/source/src/lib.rs +308 -0
  89. package/package.json +22 -4
  90. package/pulse.package.json +64 -0
  91. package/pulsewasm.compiler.cjs +89 -0
  92. package/pulsewasm.manifest.cjs +15 -0
  93. package/pulsewasm.native.cjs +79 -7
  94. package/src/provider.cjs +141 -2
  95. package/src/provider.d.cts +6 -0
@@ -0,0 +1,44 @@
1
+ /*
2
+ * Copyright (c) 2016 Thomas Pornin <pornin@bolet.org>
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining
5
+ * a copy of this software and associated documentation files (the
6
+ * "Software"), to deal in the Software without restriction, including
7
+ * without limitation the rights to use, copy, modify, merge, publish,
8
+ * distribute, sublicense, and/or sell copies of the Software, and to
9
+ * permit persons to whom the Software is furnished to do so, subject to
10
+ * the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be
13
+ * included in all copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ #include "inner.h"
26
+
27
+ /* see inner.h */
28
+ void
29
+ br_ccopy(uint32_t ctl, void *dst, const void *src, size_t len)
30
+ {
31
+ unsigned char *d;
32
+ const unsigned char *s;
33
+
34
+ d = dst;
35
+ s = src;
36
+ while (len -- > 0) {
37
+ uint32_t x, y;
38
+
39
+ x = *s ++;
40
+ y = *d;
41
+ *d = MUX(ctl, x, y);
42
+ d ++;
43
+ }
44
+ }
@@ -0,0 +1,38 @@
1
+ /*
2
+ * Copyright (c) 2016 Thomas Pornin <pornin@bolet.org>
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining
5
+ * a copy of this software and associated documentation files (the
6
+ * "Software"), to deal in the Software without restriction, including
7
+ * without limitation the rights to use, copy, modify, merge, publish,
8
+ * distribute, sublicense, and/or sell copies of the Software, and to
9
+ * permit persons to whom the Software is furnished to do so, subject to
10
+ * the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be
13
+ * included in all copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ #include "inner.h"
26
+
27
+ /* see inner.h */
28
+ void
29
+ br_range_dec32be(uint32_t *v, size_t num, const void *src)
30
+ {
31
+ const unsigned char *buf;
32
+
33
+ buf = src;
34
+ while (num -- > 0) {
35
+ *v ++ = br_dec32be(buf);
36
+ buf += 4;
37
+ }
38
+ }
@@ -0,0 +1,38 @@
1
+ /*
2
+ * Copyright (c) 2016 Thomas Pornin <pornin@bolet.org>
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining
5
+ * a copy of this software and associated documentation files (the
6
+ * "Software"), to deal in the Software without restriction, including
7
+ * without limitation the rights to use, copy, modify, merge, publish,
8
+ * distribute, sublicense, and/or sell copies of the Software, and to
9
+ * permit persons to whom the Software is furnished to do so, subject to
10
+ * the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be
13
+ * included in all copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ #include "inner.h"
26
+
27
+ /* see inner.h */
28
+ void
29
+ br_range_enc32be(void *dst, const uint32_t *v, size_t num)
30
+ {
31
+ unsigned char *buf;
32
+
33
+ buf = dst;
34
+ while (num -- > 0) {
35
+ br_enc32be(buf, *v ++);
36
+ buf += 4;
37
+ }
38
+ }
@@ -0,0 +1,229 @@
1
+ /*
2
+ * Copyright (c) 2016 Thomas Pornin <pornin@bolet.org>
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining
5
+ * a copy of this software and associated documentation files (the
6
+ * "Software"), to deal in the Software without restriction, including
7
+ * without limitation the rights to use, copy, modify, merge, publish,
8
+ * distribute, sublicense, and/or sell copies of the Software, and to
9
+ * permit persons to whom the Software is furnished to do so, subject to
10
+ * the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be
13
+ * included in all copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ #ifndef CONFIG_H__
26
+ #define CONFIG_H__
27
+
28
+ /*
29
+ * This file contains compile-time flags that can override the
30
+ * autodetection performed in relevant files. Each flag is a macro; it
31
+ * deactivates the feature if defined to 0, activates it if defined to a
32
+ * non-zero integer (normally 1). If the macro is not defined, then
33
+ * autodetection applies.
34
+ */
35
+
36
+ /*
37
+ * When BR_64 is enabled, 64-bit integer types are assumed to be
38
+ * efficient (i.e. the architecture has 64-bit registers and can
39
+ * do 64-bit operations as fast as 32-bit operations).
40
+ *
41
+ #define BR_64 1
42
+ */
43
+
44
+ /*
45
+ * When BR_LOMUL is enabled, then multiplications of 32-bit values whose
46
+ * result are truncated to the low 32 bits are assumed to be
47
+ * substantially more efficient than 32-bit multiplications that yield
48
+ * 64-bit results. This is typically the case on low-end ARM Cortex M
49
+ * systems (M0, M0+, M1, and arguably M3 and M4 as well).
50
+ *
51
+ #define BR_LOMUL 1
52
+ */
53
+
54
+ /*
55
+ * When BR_SLOW_MUL is enabled, multiplications are assumed to be
56
+ * substantially slow with regards to other integer operations, thus
57
+ * making it worth to make more operations for a given task if it allows
58
+ * using less multiplications.
59
+ *
60
+ #define BR_SLOW_MUL 1
61
+ */
62
+
63
+ /*
64
+ * When BR_SLOW_MUL15 is enabled, short multplications (on 15-bit words)
65
+ * are assumed to be substantially slow with regards to other integer
66
+ * operations, thus making it worth to make more integer operations if
67
+ * it allows using less multiplications.
68
+ *
69
+ #define BR_SLOW_MUL15 1
70
+ */
71
+
72
+ /*
73
+ * When BR_CT_MUL31 is enabled, multiplications of 31-bit values (used
74
+ * in the "i31" big integer implementation) use an alternate implementation
75
+ * which is slower and larger than the normal multiplication, but should
76
+ * ensure constant-time multiplications even on architectures where the
77
+ * multiplication opcode takes a variable number of cycles to complete.
78
+ *
79
+ #define BR_CT_MUL31 1
80
+ */
81
+
82
+ /*
83
+ * When BR_CT_MUL15 is enabled, multiplications of 15-bit values (held
84
+ * in 32-bit words) use an alternate implementation which is slower and
85
+ * larger than the normal multiplication, but should ensure
86
+ * constant-time multiplications on most/all architectures where the
87
+ * basic multiplication is not constant-time.
88
+ #define BR_CT_MUL15 1
89
+ */
90
+
91
+ /*
92
+ * When BR_NO_ARITH_SHIFT is enabled, arithmetic right shifts (with sign
93
+ * extension) are performed with a sequence of operations which is bigger
94
+ * and slower than a simple right shift on a signed value. This avoids
95
+ * relying on an implementation-defined behaviour. However, most if not
96
+ * all C compilers use sign extension for right shifts on signed values,
97
+ * so this alternate macro is disabled by default.
98
+ #define BR_NO_ARITH_SHIFT 1
99
+ */
100
+
101
+ /*
102
+ * When BR_RDRAND is enabled, the SSL engine will use the RDRAND opcode
103
+ * to automatically obtain quality randomness for seeding its internal
104
+ * PRNG. Since that opcode is present only in recent x86 CPU, its
105
+ * support is dynamically tested; if the current CPU does not support
106
+ * it, then another random source will be used, such as /dev/urandom or
107
+ * CryptGenRandom().
108
+ *
109
+ #define BR_RDRAND 1
110
+ */
111
+
112
+ /*
113
+ * When BR_USE_URANDOM is enabled, the SSL engine will use /dev/urandom
114
+ * to automatically obtain quality randomness for seedings its internal
115
+ * PRNG.
116
+ *
117
+ #define BR_USE_URANDOM 1
118
+ */
119
+
120
+ /*
121
+ * When BR_USE_WIN32_RAND is enabled, the SSL engine will use the Win32
122
+ * (CryptoAPI) functions (CryptAcquireContext(), CryptGenRandom()...) to
123
+ * automatically obtain quality randomness for seedings its internal PRNG.
124
+ *
125
+ * Note: if both BR_USE_URANDOM and BR_USE_WIN32_RAND are defined, the
126
+ * former takes precedence.
127
+ *
128
+ #define BR_USE_WIN32_RAND 1
129
+ */
130
+
131
+ /*
132
+ * When BR_USE_UNIX_TIME is enabled, the X.509 validation engine obtains
133
+ * the current time from the OS by calling time(), and assuming that the
134
+ * returned value (a 'time_t') is an integer that counts time in seconds
135
+ * since the Unix Epoch (Jan 1st, 1970, 00:00 UTC).
136
+ *
137
+ #define BR_USE_UNIX_TIME 1
138
+ */
139
+
140
+ /*
141
+ * When BR_USE_WIN32_TIME is enabled, the X.509 validation engine obtains
142
+ * the current time from the OS by calling the Win32 function
143
+ * GetSystemTimeAsFileTime().
144
+ *
145
+ * Note: if both BR_USE_UNIX_TIME and BR_USE_WIN32_TIME are defined, the
146
+ * former takes precedence.
147
+ *
148
+ #define BR_USE_WIN32_TIME 1
149
+ */
150
+
151
+ /*
152
+ * When BR_ARMEL_CORTEXM_GCC is enabled, some operations are replaced with
153
+ * inline assembly which is shorter and/or faster. This should be used
154
+ * only when all of the following are true:
155
+ * - target architecture is ARM in Thumb mode
156
+ * - target endianness is little-endian
157
+ * - compiler is GCC (or GCC-compatible for inline assembly syntax)
158
+ *
159
+ * This is meant for the low-end cores (Cortex M0, M0+, M1, M3).
160
+ * Note: if BR_LOMUL is not explicitly enabled or disabled, then
161
+ * enabling BR_ARMEL_CORTEXM_GCC also enables BR_LOMUL.
162
+ *
163
+ #define BR_ARMEL_CORTEXM_GCC 1
164
+ */
165
+
166
+ /*
167
+ * When BR_AES_X86NI is enabled, the AES implementation using the x86 "NI"
168
+ * instructions (dedicated AES opcodes) will be compiled. If this is not
169
+ * enabled explicitly, then that AES implementation will be compiled only
170
+ * if a compatible compiler is detected. If set explicitly to 0, the
171
+ * implementation will not be compiled at all.
172
+ *
173
+ #define BR_AES_X86NI 1
174
+ */
175
+
176
+ /*
177
+ * When BR_SSE2 is enabled, SSE2 intrinsics will be used for some
178
+ * algorithm implementations that use them (e.g. chacha20_sse2). If this
179
+ * is not enabled explicitly, then support for SSE2 intrinsics will be
180
+ * automatically detected. If set explicitly to 0, then SSE2 code will
181
+ * not be compiled at all.
182
+ *
183
+ #define BR_SSE2 1
184
+ */
185
+
186
+ /*
187
+ * When BR_POWER8 is enabled, the AES implementation using the POWER ISA
188
+ * 2.07 opcodes (available on POWER8 processors and later) is compiled.
189
+ * If this is not enabled explicitly, then that implementation will be
190
+ * compiled only if a compatible compiler is detected, _and_ the target
191
+ * architecture is POWER8 or later.
192
+ *
193
+ #define BR_POWER8 1
194
+ */
195
+
196
+ /*
197
+ * When BR_INT128 is enabled, then code using the 'unsigned __int64'
198
+ * and 'unsigned __int128' types will be used to leverage 64x64->128
199
+ * unsigned multiplications. This should work with GCC and compatible
200
+ * compilers on 64-bit architectures.
201
+ *
202
+ #define BR_INT128 1
203
+ */
204
+
205
+ /*
206
+ * When BR_UMUL128 is enabled, then code using the '_umul128()' and
207
+ * '_addcarry_u64()' intrinsics will be used to implement 64x64->128
208
+ * unsigned multiplications. This should work on Visual C on x64 systems.
209
+ *
210
+ #define BR_UMUL128 1
211
+ */
212
+
213
+ /*
214
+ * When BR_LE_UNALIGNED is enabled, then the current architecture is
215
+ * assumed to use little-endian encoding for integers, and to tolerate
216
+ * unaligned accesses with no or minimal time penalty.
217
+ *
218
+ #define BR_LE_UNALIGNED 1
219
+ */
220
+
221
+ /*
222
+ * When BR_BE_UNALIGNED is enabled, then the current architecture is
223
+ * assumed to use big-endian encoding for integers, and to tolerate
224
+ * unaligned accesses with no or minimal time penalty.
225
+ *
226
+ #define BR_BE_UNALIGNED 1
227
+ */
228
+
229
+ #endif