This repository has been archived by the owner on Jan 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 86
/
sig_algs_internal.h
650 lines (616 loc) · 21.2 KB
/
sig_algs_internal.h
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
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
/*
* Copyright (C) 2017 - This file is part of libecc project
*
* Authors:
* Ryad BENADJILA <[email protected]>
* Arnaud EBALARD <[email protected]>
* Jean-Pierre FLORI <[email protected]>
*
* Contributors:
* Nicolas VIVET <[email protected]>
* Karim KHALFALLAH <[email protected]>
*
* This software is licensed under a dual BSD and GPL v2 license.
* See LICENSE file at the root folder of the project.
*/
#ifndef __SIG_ALGS_INTERNAL_H__
#define __SIG_ALGS_INTERNAL_H__
#include "../hash/hash_algs.h"
#include "../curves/curves.h"
#include "ec_key.h"
#include "ecdsa.h"
#include "eckcdsa.h"
#include "ecsdsa.h"
#include "ecosdsa.h"
#include "ecfsdsa.h"
#include "ecgdsa.h"
#include "ecrdsa.h"
#include "sm2.h"
#include "eddsa.h"
#include "decdsa.h"
#include "bign.h"
#include "dbign.h"
#include "bip0340.h"
/* Includes for fuzzing */
#ifdef USE_CRYPTOFUZZ
#include "fuzzing_ecdsa.h"
#include "fuzzing_ecgdsa.h"
#include "fuzzing_ecrdsa.h"
#endif
#if (EC_MAX_SIGLEN == 0)
#error "It seems you disabled all signature schemes in lib_ecc_config.h"
#endif
/*
* All the signature algorithms we support are abstracted using the following
* structure (and following map) which provides for each hash alg its
* digest size, its block size and the associated scattered function.
*/
typedef struct {
ec_alg_type type;
const char *name;
ATTRIBUTE_WARN_UNUSED_RET int (*siglen) (u16 p_bit_len, u16 q_bit_len, u8 hsize, u8 blocksize, u8 *siglen);
ATTRIBUTE_WARN_UNUSED_RET int (*gen_priv_key) (ec_priv_key *priv_key);
ATTRIBUTE_WARN_UNUSED_RET int (*init_pub_key) (ec_pub_key *pub_key, const ec_priv_key *priv_key);
ATTRIBUTE_WARN_UNUSED_RET int (*sign_init) (struct ec_sign_context * ctx);
ATTRIBUTE_WARN_UNUSED_RET int (*sign_update) (struct ec_sign_context * ctx,
const u8 *chunk, u32 chunklen);
ATTRIBUTE_WARN_UNUSED_RET int (*sign_finalize) (struct ec_sign_context * ctx,
u8 *sig, u8 siglen);
ATTRIBUTE_WARN_UNUSED_RET int (*sign) (u8 *sig, u8 siglen, const ec_key_pair *key_pair,
const u8 *m, u32 mlen, int (*rand) (nn_t out, nn_src_t q),
ec_alg_type sig_type, hash_alg_type hash_type,
const u8 *adata, u16 adata_len);
ATTRIBUTE_WARN_UNUSED_RET int (*verify_init) (struct ec_verify_context * ctx,
const u8 *sig, u8 siglen);
ATTRIBUTE_WARN_UNUSED_RET int (*verify_update) (struct ec_verify_context * ctx,
const u8 *chunk, u32 chunklen);
ATTRIBUTE_WARN_UNUSED_RET int (*verify_finalize) (struct ec_verify_context * ctx);
ATTRIBUTE_WARN_UNUSED_RET int (*verify) (const u8 *sig, u8 siglen, const ec_pub_key *pub_key,
const u8 *m, u32 mlen, ec_alg_type sig_type,
hash_alg_type hash_type, const u8 *adata, u16 adata_len);
ATTRIBUTE_WARN_UNUSED_RET int (*verify_batch) (const u8 **s, const u8 *s_len, const ec_pub_key **pub_keys,
const u8 **m, const u32 *m_len, u32 num, ec_alg_type sig_type,
hash_alg_type hash_type, const u8 **adata, const u16 *adata_len,
verify_batch_scratch_pad *scratch_pad_area, u32 *scratch_pad_area_len);
} ec_sig_mapping;
/* Sanity check to ensure our sig mapping does not contain
* NULL pointers
*/
ATTRIBUTE_WARN_UNUSED_RET static inline int sig_mapping_sanity_check(const ec_sig_mapping *sm)
{
int ret;
MUST_HAVE(((sm != NULL) && (sm->name != NULL) && (sm->siglen != NULL) &&
(sm->gen_priv_key != NULL) && (sm->init_pub_key != NULL) &&
(sm->sign_init != NULL) && (sm->sign_update != NULL) &&
(sm->sign_finalize != NULL) && (sm->sign != NULL) &&
(sm->verify_init != NULL) && (sm->verify_update != NULL) &&
(sm->verify_finalize != NULL) && (sm->verify != NULL) &&
(sm->verify_batch != NULL)),
ret, err);
ret = 0;
err:
return ret;
}
/*
* Each specific signature scheme need to maintain some specific
* data between calls to init()/update()/finalize() functions.
*
* Each scheme provides a specific structure for that purpose
* (in its .h file) which we include in the union below. A field
* of that type (.sign_data) is then included in the generic
* struct ec_sign_context below.
*
* The purpose of that work is to allow static declaration and
* allocation of common struct ec_sign_context with enough room
* available for all supported signature types.
*/
typedef union {
#if defined(WITH_SIG_ECDSA) || defined(WITH_SIG_DECDSA) /* ECDSA and DECDSA */
ecdsa_sign_data ecdsa;
#endif
#ifdef WITH_SIG_ECKCDSA /* ECKCDSA */
eckcdsa_sign_data eckcdsa;
#endif
#if (defined(WITH_SIG_ECSDSA) || defined(WITH_SIG_ECOSDSA)) /* EC[O]SDSA */
ecsdsa_sign_data ecsdsa;
#endif
#ifdef WITH_SIG_ECFSDSA /* ECFSDSA */
ecfsdsa_sign_data ecfsdsa;
#endif
#ifdef WITH_SIG_ECGDSA /* ECGDSA */
ecgdsa_sign_data ecgdsa;
#endif
#ifdef WITH_SIG_ECRDSA /* ECRDSA */
ecrdsa_sign_data ecrdsa;
#endif
#ifdef WITH_SIG_SM2 /* SM2 */
sm2_sign_data sm2;
#endif
#if defined(WITH_SIG_EDDSA25519) || defined(WITH_SIG_EDDSA448) /* EDDSA25519, EDDSA448 */
eddsa_sign_data eddsa;
#endif
#if defined(WITH_SIG_BIGN) || defined(WITH_SIG_DBIGN) /* BIGN and DBIGN */
bign_sign_data bign;
#endif
} sig_sign_data;
/*
* The 'struct ec_sign_context' below provides a persistent state
* between successive calls to ec_sign_{init,update,finalize}().
*/
struct ec_sign_context {
word_t ctx_magic;
const ec_key_pair *key_pair;
ATTRIBUTE_WARN_UNUSED_RET int (*rand) (nn_t out, nn_src_t q);
const hash_mapping *h;
const ec_sig_mapping *sig;
sig_sign_data sign_data;
/* Optional ancillary data. This data is
* optionnally used by the signature algorithm.
*/
const u8 *adata;
u16 adata_len;
};
#define SIG_SIGN_MAGIC ((word_t)(0x4ed73cfe4594dfd3ULL))
ATTRIBUTE_WARN_UNUSED_RET static inline int sig_sign_check_initialized(struct ec_sign_context *ctx)
{
return (((ctx == NULL) || (ctx->ctx_magic != SIG_SIGN_MAGIC)) ? -1 : 0);
}
typedef union {
#if defined(WITH_SIG_ECDSA) || defined(WITH_SIG_DECDSA) /* ECDSA and DECDSA */
ecdsa_verify_data ecdsa;
#endif
#ifdef WITH_SIG_ECKCDSA /* ECKCDSA */
eckcdsa_verify_data eckcdsa;
#endif
#if (defined(WITH_SIG_ECSDSA) || defined(WITH_SIG_ECOSDSA)) /* EC[O]SDSA */
ecsdsa_verify_data ecsdsa;
#endif
#ifdef WITH_SIG_ECFSDSA /* ECFSDSA */
ecfsdsa_verify_data ecfsdsa;
#endif
#ifdef WITH_SIG_ECGDSA /* ECGDSA */
ecgdsa_verify_data ecgdsa;
#endif
#ifdef WITH_SIG_ECRDSA /* ECRDSA */
ecrdsa_verify_data ecrdsa;
#endif
#ifdef WITH_SIG_SM2 /* SM2 */
sm2_verify_data sm2;
#endif
#if defined(WITH_SIG_EDDSA25519) || defined(WITH_SIG_EDDSA448) /* EDDSA25519, EDDSA448 */
eddsa_verify_data eddsa;
#endif
#if defined(WITH_SIG_BIGN) || defined(WITH_SIG_DBIGN) /* BIGN and DBIGN */
bign_verify_data bign;
#endif
#if defined(WITH_SIG_BIP0340)
bip0340_verify_data bip0340;
#endif
} sig_verify_data;
/*
* The 'struct ec_verify_context' below provides a persistent state
* between successive calls to ec_verify_{init,update,finalize}().
*/
struct ec_verify_context {
word_t ctx_magic;
const ec_pub_key *pub_key;
const hash_mapping *h;
const ec_sig_mapping *sig;
sig_verify_data verify_data;
/* Optional ancillary data. This data is
* optionnally used by the signature algorithm.
*/
const u8 *adata;
u16 adata_len;
};
#define SIG_VERIFY_MAGIC ((word_t)(0x7e0d42d13e3159baULL))
ATTRIBUTE_WARN_UNUSED_RET static inline int sig_verify_check_initialized(struct ec_verify_context *ctx)
{
return (((ctx == NULL) || (ctx->ctx_magic != SIG_VERIFY_MAGIC)) ? -1 : 0);
}
/* Generic signature and verification APIs that will in fact call init / update / finalize in
* backend. Used for signature and verification functions that support these streaming APIs.
*
*/
ATTRIBUTE_WARN_UNUSED_RET int generic_ec_sign(u8 *sig, u8 siglen, const ec_key_pair *key_pair,
const u8 *m, u32 mlen, int (*rand) (nn_t out, nn_src_t q),
ec_alg_type sig_type, hash_alg_type hash_type, const u8 *adata, u16 adata_len);
ATTRIBUTE_WARN_UNUSED_RET int generic_ec_verify(const u8 *sig, u8 siglen, const ec_pub_key *pub_key,
const u8 *m, u32 mlen, ec_alg_type sig_type,
hash_alg_type hash_type, const u8 *adata, u16 adata_len);
/* Generic init / update / finalize functions returning an error and telling that they are
* unsupported.
*/
ATTRIBUTE_WARN_UNUSED_RET int unsupported_sign_init(struct ec_sign_context * ctx);
ATTRIBUTE_WARN_UNUSED_RET int unsupported_sign_update(struct ec_sign_context * ctx,
const u8 *chunk, u32 chunklen);
ATTRIBUTE_WARN_UNUSED_RET int unsupported_sign_finalize(struct ec_sign_context * ctx,
u8 *sig, u8 siglen);
ATTRIBUTE_WARN_UNUSED_RET int is_sign_streaming_mode_supported(ec_alg_type sig_type, int *check);
ATTRIBUTE_WARN_UNUSED_RET int unsupported_verify_init(struct ec_verify_context * ctx,
const u8 *sig, u8 siglen);
ATTRIBUTE_WARN_UNUSED_RET int unsupported_verify_update(struct ec_verify_context * ctx,
const u8 *chunk, u32 chunklen);
ATTRIBUTE_WARN_UNUSED_RET int unsupported_verify_finalize(struct ec_verify_context * ctx);
ATTRIBUTE_WARN_UNUSED_RET int is_verify_streaming_mode_supported(ec_alg_type sig_type, int *check);
ATTRIBUTE_WARN_UNUSED_RET int is_sign_deterministic(ec_alg_type sig_type, int *check);
ATTRIBUTE_WARN_UNUSED_RET int is_verify_batch_mode_supported(ec_alg_type sig_type, int *check);
ATTRIBUTE_WARN_UNUSED_RET int unsupported_verify_batch(const u8 **s, const u8 *s_len, const ec_pub_key **pub_keys,
const u8 **m, const u32 *m_len, u32 num, ec_alg_type sig_type,
hash_alg_type hash_type, const u8 **adata, const u16 *adata_len,
verify_batch_scratch_pad *scratch_pad_area, u32 *scratch_pad_area_len);
/*
* Each signature algorithm supported by the library and implemented
* in ec{,ck,s,fs,g,r}dsa.{c,h} is referenced below.
*/
#define MAX_SIG_ALG_NAME_LEN 0
static const ec_sig_mapping ec_sig_maps[] = {
#ifdef WITH_SIG_ECDSA
{.type = ECDSA,
.name = "ECDSA",
.siglen = ecdsa_siglen,
.gen_priv_key = generic_gen_priv_key,
.init_pub_key = ecdsa_init_pub_key,
.sign_init = _ecdsa_sign_init,
.sign_update = _ecdsa_sign_update,
.sign_finalize = _ecdsa_sign_finalize,
.sign = generic_ec_sign,
.verify_init = _ecdsa_verify_init,
.verify_update = _ecdsa_verify_update,
.verify_finalize = _ecdsa_verify_finalize,
.verify = generic_ec_verify,
.verify_batch = unsupported_verify_batch,
},
#if (MAX_SIG_ALG_NAME_LEN < 6)
#undef MAX_SIG_ALG_NAME_LEN
#define MAX_SIG_ALG_NAME_LEN 6
#endif /* MAX_SIG_ALG_NAME_LEN */
#endif /* WITH_SIG_ECDSA */
#ifdef WITH_SIG_ECKCDSA
{.type = ECKCDSA,
.name = "ECKCDSA",
.siglen = eckcdsa_siglen,
.gen_priv_key = generic_gen_priv_key,
.init_pub_key = eckcdsa_init_pub_key,
.sign_init = _eckcdsa_sign_init,
.sign_update = _eckcdsa_sign_update,
.sign_finalize = _eckcdsa_sign_finalize,
.sign = generic_ec_sign,
.verify_init = _eckcdsa_verify_init,
.verify_update = _eckcdsa_verify_update,
.verify_finalize = _eckcdsa_verify_finalize,
.verify = generic_ec_verify,
.verify_batch = unsupported_verify_batch,
},
#if (MAX_SIG_ALG_NAME_LEN < 8)
#undef MAX_SIG_ALG_NAME_LEN
#define MAX_SIG_ALG_NAME_LEN 8
#endif /* MAX_SIG_ALG_NAME_LEN */
#endif /* WITH_SIG_ECKCDSA */
#ifdef WITH_SIG_ECSDSA
{.type = ECSDSA,
.name = "ECSDSA",
.siglen = ecsdsa_siglen,
.gen_priv_key = generic_gen_priv_key,
.init_pub_key = ecsdsa_init_pub_key,
.sign_init = _ecsdsa_sign_init,
.sign_update = _ecsdsa_sign_update,
.sign_finalize = _ecsdsa_sign_finalize,
.sign = generic_ec_sign,
.verify_init = _ecsdsa_verify_init,
.verify_update = _ecsdsa_verify_update,
.verify_finalize = _ecsdsa_verify_finalize,
.verify = generic_ec_verify,
.verify_batch = unsupported_verify_batch,
},
#if (MAX_SIG_ALG_NAME_LEN < 7)
#undef MAX_SIG_ALG_NAME_LEN
#define MAX_SIG_ALG_NAME_LEN 7
#endif /* MAX_SIG_ALG_NAME_LEN */
#endif /* WITH_SIG_ECSDSA */
#ifdef WITH_SIG_ECOSDSA
{.type = ECOSDSA,
.name = "ECOSDSA",
.siglen = ecosdsa_siglen,
.gen_priv_key = generic_gen_priv_key,
.init_pub_key = ecosdsa_init_pub_key,
.sign_init = _ecosdsa_sign_init,
.sign_update = _ecosdsa_sign_update,
.sign_finalize = _ecosdsa_sign_finalize,
.sign = generic_ec_sign,
.verify_init = _ecosdsa_verify_init,
.verify_update = _ecosdsa_verify_update,
.verify_finalize = _ecosdsa_verify_finalize,
.verify = generic_ec_verify,
.verify_batch = unsupported_verify_batch,
},
#if (MAX_SIG_ALG_NAME_LEN < 8)
#undef MAX_SIG_ALG_NAME_LEN
#define MAX_SIG_ALG_NAME_LEN 8
#endif /* MAX_SIG_ALG_NAME_LEN */
#endif /* WITH_SIG_ECOSDSA */
#ifdef WITH_SIG_ECFSDSA
{.type = ECFSDSA,
.name = "ECFSDSA",
.siglen = ecfsdsa_siglen,
.gen_priv_key = generic_gen_priv_key,
.init_pub_key = ecfsdsa_init_pub_key,
.sign_init = _ecfsdsa_sign_init,
.sign_update = _ecfsdsa_sign_update,
.sign_finalize = _ecfsdsa_sign_finalize,
.sign = generic_ec_sign,
.verify_init = _ecfsdsa_verify_init,
.verify_update = _ecfsdsa_verify_update,
.verify_finalize = _ecfsdsa_verify_finalize,
.verify = generic_ec_verify,
.verify_batch = ecfsdsa_verify_batch,
},
#if (MAX_SIG_ALG_NAME_LEN < 8)
#undef MAX_SIG_ALG_NAME_LEN
#define MAX_SIG_ALG_NAME_LEN 8
#endif /* MAX_SIG_ALG_NAME_LEN */
#endif /* WITH_SIG_ECFSDSA */
#ifdef WITH_SIG_ECGDSA
{.type = ECGDSA,
.name = "ECGDSA",
.siglen = ecgdsa_siglen,
.gen_priv_key = generic_gen_priv_key,
.init_pub_key = ecgdsa_init_pub_key,
.sign_init = _ecgdsa_sign_init,
.sign_update = _ecgdsa_sign_update,
.sign_finalize = _ecgdsa_sign_finalize,
.sign = generic_ec_sign,
.verify_init = _ecgdsa_verify_init,
.verify_update = _ecgdsa_verify_update,
.verify_finalize = _ecgdsa_verify_finalize,
.verify = generic_ec_verify,
.verify_batch = unsupported_verify_batch,
},
#if (MAX_SIG_ALG_NAME_LEN < 7)
#undef MAX_SIG_ALG_NAME_LEN
#define MAX_SIG_ALG_NAME_LEN 7
#endif /* MAX_SIG_ALG_NAME_LEN */
#endif /* WITH_SIG_ECGDSA */
#ifdef WITH_SIG_ECRDSA
{.type = ECRDSA,
.name = "ECRDSA",
.siglen = ecrdsa_siglen,
.gen_priv_key = generic_gen_priv_key,
.init_pub_key = ecrdsa_init_pub_key,
.sign_init = _ecrdsa_sign_init,
.sign_update = _ecrdsa_sign_update,
.sign_finalize = _ecrdsa_sign_finalize,
.sign = generic_ec_sign,
.verify_init = _ecrdsa_verify_init,
.verify_update = _ecrdsa_verify_update,
.verify_finalize = _ecrdsa_verify_finalize,
.verify = generic_ec_verify,
.verify_batch = unsupported_verify_batch,
},
#if (MAX_SIG_ALG_NAME_LEN < 7)
#undef MAX_SIG_ALG_NAME_LEN
#define MAX_SIG_ALG_NAME_LEN 7
#endif /* MAX_SIG_ALG_NAME_LEN */
#endif /* WITH_SIG_ECRDSA */
#ifdef WITH_SIG_SM2
{.type = SM2,
.name = "SM2",
.siglen = sm2_siglen,
.gen_priv_key = sm2_gen_priv_key,
.init_pub_key = sm2_init_pub_key,
.sign_init = _sm2_sign_init,
.sign_update = _sm2_sign_update,
.sign_finalize = _sm2_sign_finalize,
.sign = generic_ec_sign,
.verify_init = _sm2_verify_init,
.verify_update = _sm2_verify_update,
.verify_finalize = _sm2_verify_finalize,
.verify = generic_ec_verify,
.verify_batch = unsupported_verify_batch,
},
#if (MAX_SIG_ALG_NAME_LEN < 4)
#undef MAX_SIG_ALG_NAME_LEN
#define MAX_SIG_ALG_NAME_LEN 4
#endif /* MAX_SIG_ALG_NAME_LEN */
#endif /* WITH_SIG_SM2 */
#ifdef WITH_SIG_EDDSA25519
{.type = EDDSA25519,
.name = "EDDSA25519",
.siglen = eddsa_siglen,
.gen_priv_key = eddsa_gen_priv_key,
.init_pub_key = eddsa_init_pub_key,
/* NOTE: for "pure" EdDSA, streaming mode is not supported */
.sign_init = unsupported_sign_init,
.sign_update = unsupported_sign_update,
.sign_finalize = unsupported_sign_finalize,
.sign = _eddsa_sign,
.verify_init = _eddsa_verify_init,
.verify_update = _eddsa_verify_update,
.verify_finalize = _eddsa_verify_finalize,
.verify = generic_ec_verify,
.verify_batch = eddsa_verify_batch,
},
{.type = EDDSA25519CTX,
.name = "EDDSA25519CTX",
.siglen = eddsa_siglen,
.gen_priv_key = eddsa_gen_priv_key,
.init_pub_key = eddsa_init_pub_key,
/* NOTE: for "ctx" EdDSA, streaming mode is not supported */
.sign_init = unsupported_sign_init,
.sign_update = unsupported_sign_update,
.sign_finalize = unsupported_sign_finalize,
.sign = _eddsa_sign,
.verify_init = _eddsa_verify_init,
.verify_update = _eddsa_verify_update,
.verify_finalize = _eddsa_verify_finalize,
.verify = generic_ec_verify,
.verify_batch = eddsa_verify_batch,
},
{.type = EDDSA25519PH,
.name = "EDDSA25519PH",
.siglen = eddsa_siglen,
.gen_priv_key = eddsa_gen_priv_key,
.init_pub_key = eddsa_init_pub_key,
.sign_init = _eddsa_sign_init_pre_hash,
.sign_update = _eddsa_sign_update_pre_hash,
.sign_finalize = _eddsa_sign_finalize_pre_hash,
.sign = _eddsa_sign,
.verify_init = _eddsa_verify_init,
.verify_update = _eddsa_verify_update,
.verify_finalize = _eddsa_verify_finalize,
.verify = generic_ec_verify,
.verify_batch = eddsa_verify_batch,
},
#if (MAX_SIG_ALG_NAME_LEN < 14)
#undef MAX_SIG_ALG_NAME_LEN
#define MAX_SIG_ALG_NAME_LEN 14
#endif /* MAX_SIG_ALG_NAME_LEN */
#endif /* WITH_SIG_EDDSA25519 */
#ifdef WITH_SIG_EDDSA448
{.type = EDDSA448,
.name = "EDDSA448",
.siglen = eddsa_siglen,
.gen_priv_key = eddsa_gen_priv_key,
.init_pub_key = eddsa_init_pub_key,
/* NOTE: for "pure" EdDSA, streaming mode is not supported */
.sign_init = unsupported_sign_init,
.sign_update = unsupported_sign_update,
.sign_finalize = unsupported_sign_finalize,
.sign = _eddsa_sign,
.verify_init = _eddsa_verify_init,
.verify_update = _eddsa_verify_update,
.verify_finalize = _eddsa_verify_finalize,
.verify = generic_ec_verify,
.verify_batch = eddsa_verify_batch,
},
{.type = EDDSA448PH,
.name = "EDDSA448PH",
.siglen = eddsa_siglen,
.gen_priv_key = eddsa_gen_priv_key,
.init_pub_key = eddsa_init_pub_key,
.sign_init = _eddsa_sign_init_pre_hash,
.sign_update = _eddsa_sign_update_pre_hash,
.sign_finalize = _eddsa_sign_finalize_pre_hash,
.sign = _eddsa_sign,
.verify_init = _eddsa_verify_init,
.verify_update = _eddsa_verify_update,
.verify_finalize = _eddsa_verify_finalize,
.verify = generic_ec_verify,
.verify_batch = eddsa_verify_batch,
},
#if (MAX_SIG_ALG_NAME_LEN < 11)
#undef MAX_SIG_ALG_NAME_LEN
#define MAX_SIG_ALG_NAME_LEN 11
#endif /* MAX_SIG_ALG_NAME_LEN */
#endif /* WITH_SIG_EDDSA448 */
#ifdef WITH_SIG_DECDSA
{.type = DECDSA,
.name = "DECDSA",
.siglen = decdsa_siglen,
.gen_priv_key = generic_gen_priv_key,
.init_pub_key = decdsa_init_pub_key,
.sign_init = _decdsa_sign_init,
.sign_update = _decdsa_sign_update,
.sign_finalize = _decdsa_sign_finalize,
.sign = generic_ec_sign,
.verify_init = _decdsa_verify_init,
.verify_update = _decdsa_verify_update,
.verify_finalize = _decdsa_verify_finalize,
.verify = generic_ec_verify,
.verify_batch = unsupported_verify_batch,
},
#if (MAX_SIG_ALG_NAME_LEN < 7)
#undef MAX_SIG_ALG_NAME_LEN
#define MAX_SIG_ALG_NAME_LEN 7
#endif /* MAX_SIG_ALG_NAME_LEN */
#endif /* WITH_SIG_DECDSA */
#ifdef WITH_SIG_BIGN
{.type = BIGN,
.name = "BIGN",
.siglen = bign_siglen,
.gen_priv_key = generic_gen_priv_key,
.init_pub_key = bign_init_pub_key,
.sign_init = _bign_sign_init,
.sign_update = _bign_sign_update,
.sign_finalize = _bign_sign_finalize,
.sign = generic_ec_sign,
.verify_init = _bign_verify_init,
.verify_update = _bign_verify_update,
.verify_finalize = _bign_verify_finalize,
.verify = generic_ec_verify,
.verify_batch = unsupported_verify_batch,
},
#if (MAX_SIG_ALG_NAME_LEN < 5)
#undef MAX_SIG_ALG_NAME_LEN
#define MAX_SIG_ALG_NAME_LEN 5
#endif /* MAX_SIG_ALG_NAME_LEN */
#endif /* WITH_SIG_BIGN */
#ifdef WITH_SIG_DBIGN
{.type = DBIGN,
.name = "DBIGN",
.siglen = dbign_siglen,
.gen_priv_key = generic_gen_priv_key,
.init_pub_key = dbign_init_pub_key,
.sign_init = _dbign_sign_init,
.sign_update = _dbign_sign_update,
.sign_finalize = _dbign_sign_finalize,
.sign = generic_ec_sign,
.verify_init = _dbign_verify_init,
.verify_update = _dbign_verify_update,
.verify_finalize = _dbign_verify_finalize,
.verify = generic_ec_verify,
.verify_batch = unsupported_verify_batch,
},
#if (MAX_SIG_ALG_NAME_LEN < 6)
#undef MAX_SIG_ALG_NAME_LEN
#define MAX_SIG_ALG_NAME_LEN 6
#endif /* MAX_SIG_ALG_NAME_LEN */
#endif /* WITH_SIG_DBIGN */
#ifdef WITH_SIG_BIP0340
{.type = BIP0340,
.name = "BIP0340",
.siglen = bip0340_siglen,
.gen_priv_key = generic_gen_priv_key,
.init_pub_key = bip0340_init_pub_key,
.sign_init = unsupported_sign_init,
.sign_update = unsupported_sign_update,
.sign_finalize = unsupported_sign_finalize,
.sign = _bip0340_sign,
.verify_init = _bip0340_verify_init,
.verify_update = _bip0340_verify_update,
.verify_finalize = _bip0340_verify_finalize,
.verify = generic_ec_verify,
.verify_batch = bip0340_verify_batch,
},
#if (MAX_SIG_ALG_NAME_LEN < 8)
#undef MAX_SIG_ALG_NAME_LEN
#define MAX_SIG_ALG_NAME_LEN 8
#endif /* MAX_SIG_ALG_NAME_LEN */
#endif /* WITH_SIG_BIP0340 */
{.type = UNKNOWN_ALG, /* Needs to be kept last */
.name = "UNKNOWN",
.siglen = 0,
.gen_priv_key = NULL,
.init_pub_key = NULL,
.sign_init = NULL,
.sign_update = NULL,
.sign_finalize = NULL,
.sign = NULL,
.verify_init = NULL,
.verify_update = NULL,
.verify_finalize = NULL,
.verify = NULL,
.verify_batch = NULL,
},
};
/*
* For a given raw signature, the structured version is produced by prepending
* three bytes providing specific sig alg, hash alg and curve.
*/
#define EC_STRUCTURED_SIG_EXPORT_SIZE(siglen) (u8)((siglen) + (u8)(3 * sizeof(u8)))
#define EC_STRUCTURED_SIG_MAX_EXPORT_SIZE (EC_MAX_SIGLEN + 3)
/* Sanity check */
#if EC_STRUCTURED_SIG_MAX_EXPORT_SIZE > 255
#error "All structured signatures sizes are expected to fit on an u8."
#endif
#endif /* __SIG_ALGS_INTERNAL_H__ */