-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchanges.patch
More file actions
444 lines (418 loc) · 14.4 KB
/
Copy pathchanges.patch
File metadata and controls
444 lines (418 loc) · 14.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
diff -ruaN unzip/Optimized_Implementation/include/csprng_hash.h tmp/Optimized_Implementation/include/csprng_hash.h
--- unzip/Optimized_Implementation/include/csprng_hash.h 2025-08-22 02:46:26.446223685 +0200
+++ tmp/Optimized_Implementation/include/csprng_hash.h 2025-08-22 00:30:43.455627803 +0200
@@ -34,6 +34,7 @@
#ifndef CSPRNG_HASH_H
#define CSPRNG_HASH_H
+#include "crypto_declassify.h"
#include "parameters.h"
#include "sha3.h"
@@ -271,6 +272,10 @@
pos_remaining -= refresh_amount;
}
res[placed] = sub_buffer & mask;
+
+ /* SUPERCOP edit: tell TIMECOP to ignore non-constant-time behavior in rejection sampling. */
+ crypto_declassify(&res[placed], sizeof(FP_ELEM));
+
if (res[placed] < P) {
placed++;
}
@@ -316,6 +321,10 @@
}
/* draw from 0 ... P-2, then add 1*/
res[placed] = (sub_buffer & mask)+1;
+
+ /* SUPERCOP edit: tell TIMECOP to ignore non-constant-time behavior in rejection sampling. */
+ crypto_declassify(&res[placed], sizeof(FP_ELEM));
+
if (res[placed] < P) {
placed++;
}
@@ -358,6 +367,11 @@
pos_remaining -= refresh_amount;
}
*((FP_ELEM*)res+placed) = sub_buffer & mask;
+
+ /* SUPERCOP edit: tell TIMECOP to ignore non-constant-time behavior in rejection sampling. */
+ FP_ELEM *target = ((FP_ELEM*)res + placed);
+ crypto_declassify(target, sizeof(FP_ELEM));
+
if (*((FP_ELEM*)res+placed) < P) {
placed++;
}
@@ -401,6 +415,10 @@
pos_remaining -= refresh_amount;
}
res[placed] = sub_buffer & mask;
+
+ /* SUPERCOP edit: tell TIMECOP to ignore non-constant-time behavior in rejection sampling. */
+ crypto_declassify(&res[placed], sizeof(FZ_ELEM));
+
if (res[placed] < Z) {
placed++;
}
@@ -443,6 +461,10 @@
pos_remaining -= refresh_amount;
}
res[placed] = sub_buffer & mask;
+
+ /* SUPERCOP edit: tell TIMECOP to ignore non-constant-time behavior in rejection sampling. */
+ crypto_declassify(&res[placed], sizeof(FZ_ELEM));
+
if (res[placed] < Z) {
placed++;
}
@@ -486,6 +508,11 @@
pos_remaining -= refresh_amount;
}
*((FZ_ELEM*)res+placed) = sub_buffer & mask;
+
+ /* SUPERCOP edit: tell TIMECOP to ignore non-constant-time behavior in rejection sampling. */
+ FZ_ELEM *target = ((FZ_ELEM*)res + placed);
+ crypto_declassify(target, sizeof(FZ_ELEM));
+
if (*((FZ_ELEM*)res+placed) < Z) {
placed++;
}
diff -ruaN unzip/Optimized_Implementation/include/fp_arith.h tmp/Optimized_Implementation/include/fp_arith.h
--- unzip/Optimized_Implementation/include/fp_arith.h 2025-08-22 02:46:26.446223685 +0200
+++ tmp/Optimized_Implementation/include/fp_arith.h 2025-08-22 02:47:18.674575661 +0200
@@ -472,7 +472,7 @@
/* res: expand, align */
alignas(32) FP_ELEM res_x[ROUND_UP(N,EPI16_PER_REG)];
/* e: convert from uint8 to uint16, expand, align */
- alignas(32) FP_ELEM e_x[ROUND_UP(N,EPI16_PER_REG)];
+ alignas(32) FP_ELEM e_x[ROUND_UP(N,EPI16_PER_REG)] = {0};
for (int i = 0; i < N; i++) {
e_x[i] = e[i];
}
@@ -528,7 +528,7 @@
/* res: expand, align */
alignas(32) FP_ELEM res_x[ROUND_UP(N,EPI16_PER_REG)];
/* in: convert from uint8 to uint16, expand, align */
- alignas(32) FP_ELEM in_x[ROUND_UP(N,EPI16_PER_REG)];
+ alignas(32) FP_ELEM in_x[ROUND_UP(N,EPI16_PER_REG)] = {0};
for (int i = 0; i < N; i++) {
in_x[i] = in[i];
}
diff -ruaN unzip/Optimized_Implementation/lib/CROSS.c tmp/Optimized_Implementation/lib/CROSS.c
--- unzip/Optimized_Implementation/lib/CROSS.c 2025-08-22 02:46:26.450223711 +0200
+++ tmp/Optimized_Implementation/lib/CROSS.c 2025-08-22 00:31:16.036579456 +0200
@@ -38,6 +38,7 @@
#include "fp_arith.h"
#include "merkle_tree.h"
#include "pack_unpack.h"
+#include "randombytes.h"
#include "seedtree.h"
#if defined(RSDP)
diff -ruaN unzip/Reference_Implementation/include/api.h tmp/Reference_Implementation/include/api.h
--- unzip/Reference_Implementation/include/api.h 2025-08-22 02:46:26.450223711 +0200
+++ tmp/Reference_Implementation/include/api.h 2025-08-22 00:41:07.441952861 +0200
@@ -32,7 +32,7 @@
#pragma once
-#include "CROSS.h"
+#include "CROSS_struct.h"
#include "parameters.h"
#define CRYPTO_ALGNAME "CROSS"
diff -ruaN unzip/Reference_Implementation/include/CROSS.h tmp/Reference_Implementation/include/CROSS.h
--- unzip/Reference_Implementation/include/CROSS.h 2025-08-22 02:46:26.450223711 +0200
+++ tmp/Reference_Implementation/include/CROSS.h 2025-08-22 00:41:48.618320272 +0200
@@ -33,49 +33,10 @@
#include <stdint.h>
+#include "CROSS_struct.h"
#include "pack_unpack.h"
#include "parameters.h"
-/* Public key: the parity check matrix is shrunk to a seed, syndrome
- * represented in full */
-typedef struct {
- uint8_t seed_pk[KEYPAIR_SEED_LENGTH_BYTES];
- uint8_t s[DENSELY_PACKED_FP_SYN_SIZE];
-} pk_t;
-
-/* Private key: just a single seed*/
-typedef struct {
- uint8_t seed_sk[KEYPAIR_SEED_LENGTH_BYTES];
-} sk_t;
-
-typedef struct {
- uint8_t y[DENSELY_PACKED_FP_VEC_SIZE];
-#if defined(RSDP)
- uint8_t v_bar[DENSELY_PACKED_FZ_VEC_SIZE];
-#elif defined(RSDPG)
- uint8_t v_G_bar[DENSELY_PACKED_FZ_RSDP_G_VEC_SIZE];
-#endif
-} resp_0_t;
-
-/* Signature: */
-typedef struct {
- uint8_t salt[SALT_LENGTH_BYTES];
- uint8_t digest_cmt[HASH_DIGEST_LENGTH];
- uint8_t digest_chall_2[HASH_DIGEST_LENGTH];
-#if defined(NO_TREES)
- uint8_t path[W*SEED_LENGTH_BYTES];
- uint8_t proof[W*HASH_DIGEST_LENGTH];
-#else
- /*Seed tree paths storage*/
- uint8_t path[TREE_NODES_TO_STORE*SEED_LENGTH_BYTES];
- /*Merkle tree proof field.*/
- uint8_t proof[HASH_DIGEST_LENGTH*TREE_NODES_TO_STORE];
-#endif
- uint8_t resp_1[T-W][HASH_DIGEST_LENGTH];
- resp_0_t resp_0[T-W];
-} CROSS_sig_t;
-
-
/* keygen cannot fail */
void CROSS_keygen(sk_t *SK,
pk_t *PK);
diff -ruaN unzip/Reference_Implementation/include/CROSS_struct.h tmp/Reference_Implementation/include/CROSS_struct.h
--- unzip/Reference_Implementation/include/CROSS_struct.h 1970-01-01 01:00:00.000000000 +0100
+++ tmp/Reference_Implementation/include/CROSS_struct.h 2025-08-22 00:51:40.694344747 +0200
@@ -0,0 +1,47 @@
+#pragma once
+
+#include <stdint.h>
+
+#include "parameters.h"
+
+/* SUPERCOP edit: place struct definitions in a separate file so they can be
+ * used in api.h without breaking namespacing */
+
+/* Public key: the parity check matrix is shrunk to a seed, syndrome
+ * represented in full */
+typedef struct {
+ uint8_t seed_pk[KEYPAIR_SEED_LENGTH_BYTES];
+ uint8_t s[DENSELY_PACKED_FP_SYN_SIZE];
+} pk_t;
+
+/* Private key: just a single seed*/
+typedef struct {
+ uint8_t seed_sk[KEYPAIR_SEED_LENGTH_BYTES];
+} sk_t;
+
+typedef struct {
+ uint8_t y[DENSELY_PACKED_FP_VEC_SIZE];
+#if defined(RSDP)
+ uint8_t v_bar[DENSELY_PACKED_FZ_VEC_SIZE];
+#elif defined(RSDPG)
+ uint8_t v_G_bar[DENSELY_PACKED_FZ_RSDP_G_VEC_SIZE];
+#endif
+} resp_0_t;
+
+/* Signature: */
+typedef struct {
+ uint8_t salt[SALT_LENGTH_BYTES];
+ uint8_t digest_cmt[HASH_DIGEST_LENGTH];
+ uint8_t digest_chall_2[HASH_DIGEST_LENGTH];
+#if defined(NO_TREES)
+ uint8_t path[W*SEED_LENGTH_BYTES];
+ uint8_t proof[W*HASH_DIGEST_LENGTH];
+#else
+ /*Seed tree paths storage*/
+ uint8_t path[TREE_NODES_TO_STORE*SEED_LENGTH_BYTES];
+ /*Merkle tree proof field.*/
+ uint8_t proof[HASH_DIGEST_LENGTH*TREE_NODES_TO_STORE];
+#endif
+ uint8_t resp_1[T-W][HASH_DIGEST_LENGTH];
+ resp_0_t resp_0[T-W];
+} CROSS_sig_t;
\ No newline at end of file
diff -ruaN unzip/Reference_Implementation/include/csprng_hash.h tmp/Reference_Implementation/include/csprng_hash.h
--- unzip/Reference_Implementation/include/csprng_hash.h 2025-08-22 02:46:26.450223711 +0200
+++ tmp/Reference_Implementation/include/csprng_hash.h 2025-08-22 00:33:47.680655016 +0200
@@ -34,6 +34,7 @@
#ifndef CSPRNG_HASH_H
#define CSPRNG_HASH_H
+#include "crypto_declassify.h"
#include "parameters.h"
#include "sha3.h"
@@ -132,6 +133,10 @@
pos_remaining -= refresh_amount;
}
res[placed] = sub_buffer & mask;
+
+ /* SUPERCOP edit: tell TIMECOP to ignore non-constant-time behavior in rejection sampling. */
+ crypto_declassify(&res[placed], sizeof(FP_ELEM));
+
if (res[placed] < P) {
placed++;
}
@@ -177,6 +182,10 @@
}
/* draw from 0 ... P-2, then add 1*/
res[placed] = (sub_buffer & mask)+1;
+
+ /* SUPERCOP edit: tell TIMECOP to ignore non-constant-time behavior in rejection sampling. */
+ crypto_declassify(&res[placed], sizeof(FP_ELEM));
+
if (res[placed] < P) {
placed++;
}
@@ -219,6 +228,11 @@
pos_remaining -= refresh_amount;
}
*((FP_ELEM*)res+placed) = sub_buffer & mask;
+
+ /* SUPERCOP edit: tell TIMECOP to ignore non-constant-time behavior in rejection sampling. */
+ FP_ELEM *target = ((FP_ELEM*)res + placed);
+ crypto_declassify(target, sizeof(FP_ELEM));
+
if (*((FP_ELEM*)res+placed) < P) {
placed++;
}
@@ -262,6 +276,10 @@
pos_remaining -= refresh_amount;
}
res[placed] = sub_buffer & mask;
+
+ /* SUPERCOP edit: tell TIMECOP to ignore non-constant-time behavior in rejection sampling. */
+ crypto_declassify(&res[placed], sizeof(FZ_ELEM));
+
if (res[placed] < Z) {
placed++;
}
@@ -304,6 +322,10 @@
pos_remaining -= refresh_amount;
}
res[placed] = sub_buffer & mask;
+
+ /* SUPERCOP edit: tell TIMECOP to ignore non-constant-time behavior in rejection sampling. */
+ crypto_declassify(&res[placed], sizeof(FZ_ELEM));
+
if (res[placed] < Z) {
placed++;
}
@@ -347,6 +369,11 @@
pos_remaining -= refresh_amount;
}
*((FZ_ELEM*)res+placed) = sub_buffer & mask;
+
+ /* SUPERCOP edit: tell TIMECOP to ignore non-constant-time behavior in rejection sampling. */
+ FZ_ELEM *target = ((FZ_ELEM*)res + placed);
+ crypto_declassify(target, sizeof(FZ_ELEM));
+
if (*((FZ_ELEM*)res+placed) < Z) {
placed++;
}
diff -ruaN unzip/Reference_Implementation/lib/CROSS.c tmp/Reference_Implementation/lib/CROSS.c
--- unzip/Reference_Implementation/lib/CROSS.c 2025-08-22 02:46:26.454223739 +0200
+++ tmp/Reference_Implementation/lib/CROSS.c 2025-08-22 00:34:09.289199532 +0200
@@ -38,6 +38,7 @@
#include "fp_arith.h"
#include "merkle_tree.h"
#include "pack_unpack.h"
+#include "randombytes.h"
#include "seedtree.h"
#if defined(RSDP)
diff -ruaN unzip/Reference_Implementation/lib/csprng_hash.c tmp/Reference_Implementation/lib/csprng_hash.c
--- unzip/Reference_Implementation/lib/csprng_hash.c 2025-08-22 02:46:26.454223739 +0200
+++ tmp/Reference_Implementation/lib/csprng_hash.c 2025-08-22 00:35:10.610708869 +0200
@@ -79,6 +79,10 @@
int bits_for_pos = BITS_TO_REPRESENT(T-1-curr);
uint64_t pos_mask = ( (uint64_t) 1 << bits_for_pos) - 1;
uint16_t candidate_pos = (sub_buffer & pos_mask);
+
+ /* SUPERCOP edit: tell TIMECOP to ignore non-constant-time behavior in rejection sampling. */
+ crypto_declassify(&candidate_pos, sizeof(uint16_t));
+
if (candidate_pos < T-curr) {
int dest = curr+candidate_pos;
/* the position is admissible, swap */
diff -ruaN unzip/Reference_Implementation/lib/pack_unpack.c tmp/Reference_Implementation/lib/pack_unpack.c
--- unzip/Reference_Implementation/lib/pack_unpack.c 2025-08-22 02:46:26.454223739 +0200
+++ tmp/Reference_Implementation/lib/pack_unpack.c 2025-08-22 00:37:58.358639143 +0200
@@ -36,6 +36,9 @@
/*Implementation of packing and unpacking of 3/7/9 bit elements into byte vectors*/
+/* SUPERCOP edit: generic_pack_3_bit is unused in RSDPG */
+#if Z == 7
+
/*
* generic_pack_3_bit()
*
@@ -100,6 +103,8 @@
}
}
+#endif
+
/*
* generic_pack_7_bit()
*
@@ -182,6 +187,9 @@
}
}
+/* SUPERCOP edit: generic_pack_9_bit is unused in RSDP */
+#if P == 509
+
/*
* generic_pack_9_bit()
*
@@ -273,6 +281,8 @@
}
}
+#endif
+
/*
* generic_pack_fp()
*
@@ -324,6 +334,9 @@
#endif
}
+/* SUPERCOP edit: generic_unpack_3_bit is unused in RSDPG */
+#if Z == 7
+
/*
* generic_unpack_3_bit()
*
@@ -414,6 +427,8 @@
return is_packed_padd_ok;
}
+#endif
+
/*
* generic_unpack_7_bit()
*
@@ -504,6 +519,9 @@
return is_packed_padd_ok;
}
+/* SUPERCOP edit: generic_unpack_9_bit is unused in RSDP */
+#if P == 509
+
/*
* generic_unpack_9_bit()
*
@@ -594,6 +612,8 @@
return is_packed_padd_ok;
}
+#endif
+
/*
* generic_unpack_fp()
*
diff -ruaN unzip/Reference_Implementation/lib/sign.c tmp/Reference_Implementation/lib/sign.c
--- unzip/Reference_Implementation/lib/sign.c 2025-08-22 02:46:26.454223739 +0200
+++ tmp/Reference_Implementation/lib/sign.c 2025-08-22 00:48:45.627579006 +0200
@@ -33,6 +33,7 @@
#include <string.h> // memcpy
#include "api.h"
+#include "CROSS.h"
/*----------------------------------------------------------------------------*/
@@ -77,14 +78,18 @@
unsigned long long *mlen, // out parameter
const unsigned char *sm, // in parameter
unsigned long long smlen, // in parameter
- const unsigned char *pk) // in parameter
+ const unsigned char *pk_static) // in parameter
{
+ /* SUPERCOP edit: make a static copy of the public key */
+ const pk_t pk;
+ memcpy((unsigned char *) &pk, pk_static, sizeof(pk_t));
+
/* verify returns 1 if signature is ok, 0 otherwise */
*mlen = smlen-(unsigned long long) sizeof(CROSS_sig_t);
memcpy((unsigned char *) m, (const unsigned char *) sm, (size_t) *mlen);
- int ok = CROSS_verify((const pk_t *const) pk, // in parameter
+ int ok = CROSS_verify(&pk, // in parameter
(const char *const) m, // in parameter
(const uint64_t) *mlen, // in parameter
(const CROSS_sig_t * const) (sm+*mlen));// in parameter