-
Notifications
You must be signed in to change notification settings - Fork 92
/
Copy pathx509.c
11945 lines (9779 loc) · 307 KB
/
x509.c
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
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2019 - This file is part of x509-parser project
*
* Author:
* Arnaud EBALARD <[email protected]>
*
* BSD License
* -----------
*
* Copyright (C) 2019
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __X509_CONFIG_H__
#define __X509_CONFIG_H__
#define MAX_UINT32 (0xffffffffUL)
#define ASN1_MAX_BUFFER_SIZE (MAX_UINT32)
typedef enum {
X509_PARSER_ERROR_VERSION_ABSENT = -1,
X509_PARSER_ERROR_VERSION_UNEXPECTED_LENGTH = -2,
X509_PARSER_ERROR_VERSION_NOT_3 = -3,
} x509_parser_errors;
#define TEMPORARY_LAXIST_HANDLE_ALL_REMAINING_RDN_OIDS
#define TEMPORARY_LAXIST_HANDLE_COMMON_UNSUPPORTED_EXT_OIDS
#define TEMPORARY_LAXIST_HANDLE_ALL_REMAINING_EXT_OIDS
#define TEMPORARY_LAXIST_RDN_UPPER_BOUND
#define TEMPORARY_LAXIST_CA_WO_SKI
#define TEMPORARY_LAXIST_EMAILADDRESS_WITH_UTF8_ENCODING
#define TEMPORARY_BAD_EXT_OIDS
#define TEMPORARY_BAD_OID_RDN
#define TEMPORARY_LAXIST_DIRECTORY_STRING
#define TEMPORARY_LAXIST_SERIAL_NEGATIVE
#define TEMPORARY_LAXIST_SERIAL_LENGTH
#define TEMPORARY_LAXIST_SERIAL_NULL
#define TEMPORARY_LAXIST_CA_BASIC_CONSTRAINTS_BOOLEAN_EXPLICIT_FALSE
#define TEMPORARY_LAXIST_EXTENSION_CRITICAL_FLAG_BOOLEAN_EXPLICIT_FALSE
#define TEMPORARY_LAXIST_SKI_CRITICAL_FLAG_SET
#define TEMPORARY_LAXIST_SERIAL_RDN_AS_IA5STRING
#define TEMPORARY_LAXIST_RSA_PUBKEY_AND_SIG_NO_PARAMS_INSTEAD_OF_NULL
#define TEMPORARY_LAXIST_ALLOW_MISSING_CRL_NEXT_UPDATE
#define TEMPORARY_LAXIST_ALLOW_CRL_ENTRY_EXT_WITH_EMPTY_SEQ
#define TEMPORARY_LAXIST_ALLOW_IDP_CRL_EXT_WITHOUT_CRITICAL_BIT_SET
#define TEMPORARY_LAXIST_ALLOW_REVOKED_CERTS_LIST_EMPTY
#define TEMPORARY_LAXIST_ALLOW_MISSING_AKI_OR_CRLNUM
#endif
#ifndef __X509_UTILS_H__
#define __X509_UTILS_H__
#include <stdint.h>
#include <unistd.h>
#include <string.h>
typedef uint8_t x509_u8;
typedef uint16_t x509_u16;
typedef uint32_t x509_u32;
typedef uint64_t x509_u64;
#if defined(__FRAMAC__)
#define ATTRIBUTE_UNUSED
#else
#define ATTRIBUTE_UNUSED __attribute__((unused))
#endif
#ifdef ERROR_TRACE_ENABLE
#define ERROR_TRACE_APPEND(x) do { \
extern int printf(const char *format, ...); \
printf("%06d ", (x)); \
} while (0);
#else
#define ERROR_TRACE_APPEND(x)
#endif
#define X509_FILE_LINE_NUM_ERR ((X509_FILE_NUM * 100000) + __LINE__)
#define P99_PROTECT(...) __VA_ARGS__
int bufs_differ(const x509_u8 *b1, const x509_u8 *b2, x509_u32 n);
#endif
#ifndef __X509_COMMON_H__
#define __X509_COMMON_H__
typedef enum {
CLASS_UNIVERSAL = 0x00,
CLASS_APPLICATION = 0x01,
CLASS_CONTEXT_SPECIFIC = 0x02,
CLASS_PRIVATE = 0x03
} tag_class;
typedef enum {
ASN1_TYPE_BOOLEAN = 0x01,
ASN1_TYPE_INTEGER = 0x02,
ASN1_TYPE_BIT_STRING = 0x03,
ASN1_TYPE_OCTET_STRING = 0x04,
ASN1_TYPE_NULL = 0x05,
ASN1_TYPE_OID = 0x06,
ASN1_TYPE_ENUMERATED = 0x0a,
ASN1_TYPE_SEQUENCE = 0x10,
ASN1_TYPE_SET = 0x11,
ASN1_TYPE_PrintableString = 0x13,
ASN1_TYPE_T61String = 0x14,
ASN1_TYPE_IA5String = 0x16,
ASN1_TYPE_UTCTime = 0x17,
ASN1_TYPE_GeneralizedTime = 0x18,
} asn1_type;
typedef enum {
HASH_ALG_UNKNOWN = 0,
HASH_ALG_MD2 = 1,
HASH_ALG_MD4 = 2,
HASH_ALG_MD5 = 3,
HASH_ALG_MDC2 = 4,
HASH_ALG_SHA1 = 5,
HASH_ALG_WHIRLPOOL = 6,
HASH_ALG_RIPEMD160 = 7,
HASH_ALG_RIPEMD128 = 8,
HASH_ALG_RIPEMD256 = 9,
HASH_ALG_SHA224 = 10,
HASH_ALG_SHA256 = 11,
HASH_ALG_SHA384 = 12,
HASH_ALG_SHA512 = 13,
HASH_ALG_SHA512_224 = 14,
HASH_ALG_SHA512_256 = 15,
HASH_ALG_SHA3_224 = 16,
HASH_ALG_SHA3_256 = 17,
HASH_ALG_SHA3_384 = 18,
HASH_ALG_SHA3_512 = 19,
HASH_ALG_SHAKE128 = 20,
HASH_ALG_SHAKE256 = 21,
HASH_ALG_SM3 = 22,
HASH_ALG_GOSTR3411_94 = 23,
HASH_ALG_STREEBOG256 = 24,
HASH_ALG_STREEBOG512 = 25,
HASH_ALG_HBELT = 26,
HASH_ALG_BASH256 = 27,
HASH_ALG_BASH384 = 28,
HASH_ALG_BASH512 = 29
} hash_alg_id;
typedef enum {
SIG_ALG_UNKNOWN = 0,
SIG_ALG_DSA = 1,
SIG_ALG_RSA_SSA_PSS = 2,
SIG_ALG_RSA_PKCS1_V1_5 = 3,
SIG_ALG_ED25519 = 4,
SIG_ALG_ED448 = 5,
SIG_ALG_SM2 = 6,
SIG_ALG_GOSTR3410_2012_256 = 7,
SIG_ALG_GOSTR3410_2012_512 = 8,
SIG_ALG_GOSTR3410_2001 = 9,
SIG_ALG_GOSTR3410_94 = 10,
SIG_ALG_BIGN = 11,
SIG_ALG_ECDSA = 12,
SIG_ALG_RSA_9796_2_PAD = 13,
SIG_ALG_MONKEYSPHERE = 14,
SIG_ALG_BELGIAN_RSA = 15,
} sig_alg_id;
typedef enum {
MGF_ALG_UNKNOWN = 0,
MGF_ALG_MGF1 = 1
} mgf_alg_id;
typedef enum {
SPKI_ALG_UNKNOWN = 0,
SPKI_ALG_ECPUBKEY = 1,
SPKI_ALG_ED25519 = 2,
SPKI_ALG_ED448 = 3,
SPKI_ALG_X25519 = 4,
SPKI_ALG_X448 = 5,
SPKI_ALG_RSA = 6,
SPKI_ALG_DSA = 7,
SPKI_ALG_GOSTR3410_2012_256 = 8,
SPKI_ALG_GOSTR3410_2012_512 = 9,
SPKI_ALG_GOSTR3410_2001 = 10,
SPKI_ALG_GOSTR3410_94 = 11,
SPKI_ALG_BIGN_PUBKEY = 12,
} spki_alg_id;
typedef enum {
CURVE_UNKNOWN = 0,
CURVE_BIGN256v1 = 1,
CURVE_BIGN384v1 = 2,
CURVE_BIGN512v1 = 3,
CURVE_C2PNB163V1 = 4,
CURVE_SECT571K1 = 5,
CURVE_SECT163K1 = 6,
CURVE_SECP192K1 = 7,
CURVE_SECP224K1 = 8,
CURVE_SECP256K1 = 9,
CURVE_SECP192R1 = 10,
CURVE_SECP224R1 = 11,
CURVE_SECP256R1 = 12,
CURVE_SECP384R1 = 13,
CURVE_SECP521R1 = 14,
CURVE_BRAINPOOLP192R1 = 15,
CURVE_BRAINPOOLP224R1 = 16,
CURVE_BRAINPOOLP256R1 = 17,
CURVE_BRAINPOOLP384R1 = 18,
CURVE_BRAINPOOLP512R1 = 19,
CURVE_BRAINPOOLP192T1 = 20,
CURVE_BRAINPOOLP224T1 = 21,
CURVE_BRAINPOOLP256T1 = 22,
CURVE_BRAINPOOLP320R1 = 23,
CURVE_BRAINPOOLP320T1 = 24,
CURVE_BRAINPOOLP384T1 = 25,
CURVE_BRAINPOOLP512T1 = 26,
CURVE_SM2P256TEST = 27,
CURVE_SM2P256V1 = 28,
CURVE_FRP256V1 = 29,
CURVE_WEI25519 = 30,
CURVE_WEI448 = 31,
CURVE_GOST256 = 32,
CURVE_GOST512 = 33,
CURVE_GOST_R3410_2012_256_PARAMSETA = 34,
CURVE_GOST_R3410_2001_TESTPARAMSET = 35,
CURVE_GOST_R3410_2001_CRYPTOPRO_A_PARAMSET = 36,
CURVE_GOST_R3410_2001_CRYPTOPRO_B_PARAMSET = 37,
CURVE_GOST_R3410_2001_CRYPTOPRO_C_PARAMSET = 38,
CURVE_GOST_R3410_2001_CRYPTOPRO_XCHA_PARAMSET = 39,
CURVE_GOST_R3410_2001_CRYPTOPRO_XCHB_PARAMSET = 40,
CURVE_GOST_R3410_2012_256_PARAMSETB = 41,
CURVE_GOST_R3410_2012_256_PARAMSETC = 42,
CURVE_GOST_R3410_2012_256_PARAMSETD = 43,
CURVE_GOST_R3410_2012_512_PARAMSETTEST = 44,
CURVE_GOST_R3410_2012_512_PARAMSETA = 45,
CURVE_GOST_R3410_2012_512_PARAMSETB = 46,
CURVE_GOST_R3410_2012_512_PARAMSETC = 47,
} curve_id;
typedef enum {
GOST94_PARAMS_UNKNOWN = 0,
GOST94_PARAMS_TEST = 1,
GOST94_PARAMS_CRYPTOPRO_A = 2,
GOST94_PARAMS_CRYPTOPRO_B = 3,
GOST94_PARAMS_CRYPTOPRO_C = 4,
GOST94_PARAMS_CRYPTOPRO_D = 5,
GOST94_PARAMS_CRYPTOPRO_XCHA = 6,
GOST94_PARAMS_CRYPTOPRO_XCHB = 7,
GOST94_PARAMS_CRYPTOPRO_XCHC = 8
} _gost94_pub_params_id;
typedef struct {
const x509_u8 *alg_name;
const x509_u8 *alg_printable_oid;
const x509_u8 *alg_der_oid;
const x509_u32 alg_der_oid_len;
hash_alg_id hash_id;
} _hash_alg;
typedef struct {
const x509_u8 *alg_name;
const x509_u8 *alg_printable_oid;
const x509_u8 *alg_der_oid;
const x509_u32 alg_der_oid_len;
const mgf_alg_id mgf_id;
} _mgf;
typedef struct {
const _hash_alg *hash;
const _mgf *mgf;
const _hash_alg *mgf_hash;
x509_u32 salt_len;
x509_u32 trailer_field;
} _rsassa_pss;
typedef struct {
const x509_u8 *crv_name;
const x509_u8 *crv_printable_oid;
const x509_u8 *crv_der_oid;
const x509_u32 crv_der_oid_len;
const x509_u32 crv_order_bit_len;
curve_id crv_id;
} _curve;
typedef struct {
curve_id curve;
x509_u32 curve_order_bit_len;
int compression;
x509_u32 ecc_raw_x_off;
x509_u32 ecc_raw_x_len;
x509_u32 ecc_raw_y_off;
x509_u32 ecc_raw_y_len;
} spki_ecpubkey_params;
typedef struct {
curve_id curve;
x509_u32 curve_order_bit_len;
x509_u32 ed25519_raw_pub_off;
x509_u32 ed25519_raw_pub_len;
} spki_ed25519_params;
typedef struct {
curve_id curve;
x509_u32 curve_order_bit_len;
x509_u32 ed448_raw_pub_off;
x509_u32 ed448_raw_pub_len;
} spki_ed448_params;
typedef struct {
curve_id curve;
x509_u32 curve_order_bit_len;
x509_u32 x25519_raw_pub_off;
x509_u32 x25519_raw_pub_len;
} spki_x25519_params;
typedef struct {
curve_id curve;
x509_u32 curve_order_bit_len;
x509_u32 x448_raw_pub_off;
x509_u32 x448_raw_pub_len;
} spki_x448_params;
typedef struct {
x509_u32 rsa_advertised_bit_len;
x509_u32 rsa_raw_modulus_off;
x509_u32 rsa_raw_modulus_len;
x509_u32 rsa_raw_pub_exp_off;
x509_u32 rsa_raw_pub_exp_len;
} spki_rsa_params;
typedef struct {
x509_u32 dsa_raw_pub_off;
x509_u32 dsa_raw_pub_len;
x509_u32 dsa_raw_p_off;
x509_u32 dsa_raw_p_len;
x509_u32 dsa_raw_q_off;
x509_u32 dsa_raw_q_len;
x509_u32 dsa_raw_g_off;
x509_u32 dsa_raw_g_len;
} spki_dsa_params;
typedef struct {
x509_u32 gost94_raw_pub_off;
x509_u32 gost94_raw_pub_len;
_gost94_pub_params_id gost94_params_id;
} spki_gost94_params;
typedef struct {
curve_id curve;
x509_u32 curve_order_bit_len;
x509_u32 gost2001_raw_x_pub_off;
x509_u32 gost2001_raw_x_pub_len;
x509_u32 gost2001_raw_y_pub_off;
x509_u32 gost2001_raw_y_pub_len;
} spki_gost2001_params;
typedef struct {
curve_id curve;
x509_u32 curve_order_bit_len;
x509_u32 gost2012_256_raw_x_pub_off;
x509_u32 gost2012_256_raw_x_pub_len;
x509_u32 gost2012_256_raw_y_pub_off;
x509_u32 gost2012_256_raw_y_pub_len;
} spki_gost2012_256_params;
typedef struct {
curve_id curve;
x509_u32 curve_order_bit_len;
x509_u32 gost2012_512_raw_x_pub_off;
x509_u32 gost2012_512_raw_x_pub_len;
x509_u32 gost2012_512_raw_y_pub_off;
x509_u32 gost2012_512_raw_y_pub_len;
} spki_gost2012_512_params;
typedef spki_rsa_params spki_ea_rsa_params;
typedef struct {
curve_id curve;
x509_u32 curve_order_bit_len;
x509_u32 bign_raw_x_pub_off;
x509_u32 bign_raw_x_pub_len;
x509_u32 bign_raw_y_pub_off;
x509_u32 bign_raw_y_pub_len;
} spki_bign_params;
typedef struct {
x509_u32 avest_raw_pub_off;
x509_u32 avest_raw_pub_len;
} spki_avest_params;
typedef spki_rsa_params spki_weird_rsa_params;
typedef union {
spki_ecpubkey_params ecpubkey;
spki_ed25519_params ed25519;
spki_ed448_params ed448;
spki_x25519_params x25519;
spki_x448_params x448;
spki_rsa_params rsa;
spki_ea_rsa_params ea_rsa;
spki_dsa_params dsa;
spki_gost94_params gost94;
spki_gost2001_params gost2001;
spki_gost2012_256_params gost2012_256;
spki_gost2012_512_params gost2012_512;
spki_bign_params bign;
spki_avest_params avest;
} spki_params;
typedef struct {
x509_u32 r_raw_off;
x509_u32 r_raw_len;
x509_u32 s_raw_off;
x509_u32 s_raw_len;
} sig_dsa_params;
typedef struct {
x509_u32 sig_raw_off;
x509_u32 sig_raw_len;
mgf_alg_id mgf_alg;
hash_alg_id mgf_hash_alg;
x509_u8 salt_len;
x509_u8 trailer_field;
} sig_rsa_ssa_pss_params;
typedef struct {
x509_u32 sig_raw_off;
x509_u32 sig_raw_len;
} sig_rsa_pkcs1_v1_5_params;
typedef sig_rsa_pkcs1_v1_5_params sig_rsa_9796_2_pad_params;
typedef sig_rsa_pkcs1_v1_5_params sig_belgian_rsa_params;
typedef struct {
x509_u32 r_raw_off;
x509_u32 r_raw_len;
x509_u32 s_raw_off;
x509_u32 s_raw_len;
} sig_ed25519_params;
typedef struct {
x509_u32 r_raw_off;
x509_u32 r_raw_len;
x509_u32 s_raw_off;
x509_u32 s_raw_len;
} sig_ed448_params;
typedef struct {
x509_u32 r_raw_off;
x509_u32 r_raw_len;
x509_u32 s_raw_off;
x509_u32 s_raw_len;
} sig_sm2_params;
typedef struct {
x509_u32 r_raw_off;
x509_u32 r_raw_len;
x509_u32 s_raw_off;
x509_u32 s_raw_len;
} sig_gost_r3410_2012_256_params;
typedef struct {
x509_u32 r_raw_off;
x509_u32 r_raw_len;
x509_u32 s_raw_off;
x509_u32 s_raw_len;
} sig_gost_r3410_2012_512_params;
typedef struct {
x509_u32 r_raw_off;
x509_u32 r_raw_len;
x509_u32 s_raw_off;
x509_u32 s_raw_len;
} sig_gost_r3410_2001_params;
typedef struct {
x509_u32 r_raw_off;
x509_u32 r_raw_len;
x509_u32 s_raw_off;
x509_u32 s_raw_len;
} sig_gost_r3410_94_params;
typedef struct {
x509_u32 sig_raw_off;
x509_u32 sig_raw_len;
} sig_bign_params;
typedef struct {
x509_u32 r_raw_off;
x509_u32 r_raw_len;
x509_u32 s_raw_off;
x509_u32 s_raw_len;
} sig_ecdsa_params;
typedef struct {
x509_u32 sig_raw_off;
x509_u32 sig_raw_len;
} sig_monkeysphere_params;
typedef union {
sig_dsa_params dsa;
sig_rsa_ssa_pss_params rsa_ssa_pss;
sig_rsa_pkcs1_v1_5_params rsa_pkcs1_v1_5;
sig_ed25519_params ed25519;
sig_ed448_params ed448;
sig_sm2_params sm2;
sig_gost_r3410_2012_256_params gost_r3410_2012_256;
sig_gost_r3410_2012_512_params gost_r3410_2012_512;
sig_gost_r3410_2001_params gost_r3410_2001;
sig_gost_r3410_94_params gost_r3410_94;
sig_bign_params bign;
sig_ecdsa_params ecdsa;
sig_rsa_9796_2_pad_params rsa_9796_2_pad;
sig_monkeysphere_params monkeysphere;
sig_belgian_rsa_params belgian_rsa;
} sig_params;
int parse_sig_ed448(sig_params *params, const x509_u8 *cert, x509_u32 off, x509_u32 len, x509_u32 *eaten);
int parse_sig_ed25519(sig_params *params, const x509_u8 *cert, x509_u32 off, x509_u32 len, x509_u32 *eaten);
int parse_sig_ecdsa(sig_params *params, const x509_u8 *cert, x509_u32 off, x509_u32 len, x509_u32 *eaten);
int parse_sig_sm2(sig_params *params, const x509_u8 *cert, x509_u32 off, x509_u32 len, x509_u32 *eaten);
int parse_sig_dsa(sig_params *params, const x509_u8 *cert, x509_u32 off, x509_u32 len, x509_u32 *eaten);
int parse_sig_rsa_pkcs1_v15(sig_params *params, const x509_u8 *cert, x509_u32 off, x509_u32 len, x509_u32 *eaten);
int parse_sig_rsa_ssa_pss(sig_params *params, const x509_u8 *cert, x509_u32 off, x509_u32 len, x509_u32 *eaten);
int parse_sig_rsa_9796_2_pad(sig_params *params, const x509_u8 *cert, x509_u32 off, x509_u32 len, x509_u32 *eaten);
int parse_sig_rsa_belgian(sig_params *params, const x509_u8 *cert, x509_u32 off, x509_u32 len, x509_u32 *eaten);
int parse_sig_gost94(sig_params *params, const x509_u8 *cert, x509_u32 off, x509_u32 len, x509_u32 *eaten);
int parse_sig_gost2001(sig_params *params, const x509_u8 *cert, x509_u32 off, x509_u32 len, x509_u32 *eaten);
int parse_sig_gost2012_512(sig_params *params, const x509_u8 *cert, x509_u32 off, x509_u32 len, x509_u32 *eaten);
int parse_sig_gost2012_256(sig_params *params, const x509_u8 *cert, x509_u32 off, x509_u32 len, x509_u32 *eaten);
int parse_sig_bign(sig_params *params, const x509_u8 *cert, x509_u32 off, x509_u32 len, x509_u32 *eaten);
int parse_sig_monkey(sig_params *params, const x509_u8 *cert, x509_u32 off, x509_u32 len, x509_u32 *eaten);
int parse_algoid_sig_params_ecdsa_with(sig_params *params, hash_alg_id *hash_alg, const x509_u8 *cert, x509_u32 off, x509_u32 len);
int parse_algoid_sig_params_ecdsa_with_specified(sig_params *params, hash_alg_id *hash_alg, const x509_u8 *cert, x509_u32 off, x509_u32 len);
int parse_algoid_sig_params_sm2(sig_params *params, hash_alg_id *hash_alg, const x509_u8 *cert, x509_u32 off, x509_u32 len);
int parse_algoid_sig_params_eddsa(sig_params *params, hash_alg_id *hash_alg, const x509_u8 *cert, x509_u32 off, x509_u32 len);
int parse_algoid_params_rsa(const x509_u8 *cert, x509_u32 off, x509_u32 len);
int parse_algoid_sig_params_rsa(sig_params *params, hash_alg_id *hash_alg, const x509_u8 *cert, x509_u32 off, x509_u32 len);
int parse_algoid_sig_params_rsassa_pss(sig_params *params, hash_alg_id *hash_alg, const x509_u8 *cert, x509_u32 off, x509_u32 len);
int parse_algoid_sig_params_none(sig_params *params, hash_alg_id *hash_alg, const x509_u8 *cert, x509_u32 off, x509_u32 ATTRIBUTE_UNUSED len);
int parse_algoid_sig_params_bign_with_hspec(sig_params *params, hash_alg_id *hash_alg, const x509_u8 *cert, x509_u32 off, x509_u32 len);
int parse_algoid_params_none(const x509_u8 *cert, x509_u32 off, x509_u32 len);
typedef struct {
const x509_u8 *alg_name;
const x509_u8 *alg_printable_oid;
const x509_u8 *alg_der_oid;
const x509_u32 alg_der_oid_len;
sig_alg_id sig_id;
hash_alg_id hash_id;
int (*parse_algoid_sig_params)(sig_params *params, hash_alg_id *hash_alg, const x509_u8 *cert, x509_u32 off, x509_u32 len);
int (*parse_sig)(sig_params *params, const x509_u8 *cert, x509_u32 off, x509_u32 len, x509_u32 *eaten);
} _sig_alg;
extern const _sig_alg *known_sig_algs[];
extern const x509_u16 num_known_sig_algs;
extern const _curve *known_curves[];
const _sig_alg * find_sig_alg_by_oid(const x509_u8 *buf, x509_u32 len);
const _hash_alg * find_hash_by_oid(const x509_u8 *buf, x509_u32 len);
const _curve * find_curve_by_oid(const x509_u8 *buf, x509_u32 len);
int get_length(const x509_u8 *buf, x509_u32 len,
x509_u32 *adv_len, x509_u32 *eaten);
int parse_id_len(const x509_u8 *buf, x509_u32 len,
tag_class exp_class, x509_u32 exp_type,
x509_u32 *parsed, x509_u32 *content_len);
int parse_explicit_id_len(const x509_u8 *buf, x509_u32 len,
x509_u32 exp_ext_type,
tag_class exp_int_class, x509_u32 exp_int_type,
x509_u32 *parsed, x509_u32 *data_len);
int parse_null(const x509_u8 *buf, x509_u32 len,
x509_u32 *parsed);
int parse_OID(const x509_u8 *buf, x509_u32 len,
x509_u32 *parsed);
int parse_integer(const x509_u8 *buf, x509_u32 len,
tag_class exp_class, x509_u32 exp_type,
x509_u32 *hdr_len, x509_u32 *data_len);
int parse_non_negative_integer(const x509_u8 *buf, x509_u32 len,
tag_class exp_class, x509_u32 exp_type,
x509_u32 *hdr_len, x509_u32 *data_len);
int parse_boolean(const x509_u8 *buf, x509_u32 len, x509_u32 *eaten);
int parse_generalizedTime(const x509_u8 *buf, x509_u32 len, x509_u32 *eaten,
x509_u16 *year, x509_u8 *month, x509_u8 *day,
x509_u8 *hour, x509_u8 *min, x509_u8 *sec);
#define NAME_TYPE_rfc822Name 0x81
#define NAME_TYPE_dNSName 0x82
#define NAME_TYPE_URI 0x86
#define NAME_TYPE_iPAddress 0x87
#define NAME_TYPE_registeredID 0x88
#define NAME_TYPE_otherName 0xa0
#define NAME_TYPE_x400Address 0xa3
#define NAME_TYPE_directoryName 0xa4
#define NAME_TYPE_ediPartyName 0xa5
int parse_GeneralName(const x509_u8 *buf, x509_u32 len, x509_u32 *eaten, int *empty);
int parse_SerialNumber(const x509_u8 *cert, x509_u32 off, x509_u32 len,
tag_class exp_class, x509_u32 exp_type,
x509_u32 *eaten);
int verify_correct_time_use(x509_u8 time_type, x509_u16 yyyy);
int parse_Time(const x509_u8 *buf, x509_u32 len, x509_u8 *t_type, x509_u32 *eaten,
x509_u16 *year, x509_u8 *month, x509_u8 *day,
x509_u8 *hour, x509_u8 *min, x509_u8 *sec);
int verify_correct_time_use(x509_u8 time_type, x509_u16 yyyy);
int parse_AKICertSerialNumber(const x509_u8 *cert, x509_u32 off, x509_u32 len,
tag_class exp_class, x509_u32 exp_type,
x509_u32 *eaten);
int parse_crldp_reasons(const x509_u8 *buf, x509_u32 len, x509_u32 exp_type, x509_u32 *eaten);
int parse_DistributionPoint(const x509_u8 *buf, x509_u32 len,
int *crldp_has_all_reasons, x509_u32 *eaten);
int parse_AIA(const x509_u8 *cert, x509_u32 off, x509_u32 len, int critical);
int parse_ia5_string(const x509_u8 *buf, x509_u32 len, x509_u32 lb, x509_u32 ub);
int parse_x509_Name(const x509_u8 *buf, x509_u32 len, x509_u32 *eaten, int *empty);
int parse_DisplayText(const x509_u8 *buf, x509_u32 len, x509_u32 *eaten);
int parse_nine_bit_named_bit_list(const x509_u8 *buf, x509_u32 len, x509_u16 *val);
int parse_GeneralName(const x509_u8 *buf, x509_u32 len, x509_u32 *eaten, int *empty);
int parse_GeneralNames(const x509_u8 *buf, x509_u32 len, tag_class exp_class,
x509_u32 exp_type, x509_u32 *eaten);
x509_u64 time_components_to_comparable_u64(x509_u16 na_year, x509_u8 na_month, x509_u8 na_day,
x509_u8 na_hour, x509_u8 na_min, x509_u8 na_sec);
#endif
#ifndef __X509_CERT_PARSER_H__
#define __X509_CERT_PARSER_H__
typedef struct {
x509_u32 tbs_start;
x509_u32 tbs_len;
x509_u8 version;
x509_u32 serial_start;
x509_u32 serial_len;
x509_u32 tbs_sig_alg_start;
x509_u32 tbs_sig_alg_len;
x509_u32 tbs_sig_alg_oid_start;
x509_u32 tbs_sig_alg_oid_len;
x509_u32 tbs_sig_alg_oid_params_start;
x509_u32 tbs_sig_alg_oid_params_len;
x509_u32 issuer_start;
x509_u32 issuer_len;
x509_u64 not_before;
x509_u64 not_after;
x509_u32 subject_start;
x509_u32 subject_len;
int empty_subject;
int subject_issuer_identical;
x509_u32 spki_start;
x509_u32 spki_len;
x509_u32 spki_alg_oid_start;
x509_u32 spki_alg_oid_len;
x509_u32 spki_alg_oid_params_start;
x509_u32 spki_alg_oid_params_len;
x509_u32 spki_pub_key_start;
x509_u32 spki_pub_key_len;
spki_alg_id spki_alg;
spki_params spki_alg_params;
int has_ski;
x509_u32 ski_start;
x509_u32 ski_len;
int has_aki;
int aki_has_keyIdentifier;
x509_u32 aki_keyIdentifier_start;
x509_u32 aki_keyIdentifier_len;
int aki_has_generalNames_and_serial;
x509_u32 aki_generalNames_start;
x509_u32 aki_generalNames_len;
x509_u32 aki_serial_start;
x509_u32 aki_serial_len;
int has_san;
int san_critical;
int bc_critical;
int ca_true;
int pathLenConstraint_set;
int has_keyUsage;
int keyCertSign_set;
int cRLSign_set;
int has_eku;
int has_crldp;
int one_crldp_has_all_reasons;
int has_name_constraints;
x509_u32 sig_alg_start;
x509_u32 sig_alg_len;
sig_alg_id sig_alg;
hash_alg_id hash_alg;
sig_params sig_alg_params;
x509_u32 sig_start;
x509_u32 sig_len;
} cert_parsing_ctx;
int parse_x509_cert(cert_parsing_ctx *ctx, const x509_u8 *buf, x509_u32 len);
#endif
#ifndef __X509_CRL_PARSER_H__
#define __X509_CRL_PARSER_H__
typedef struct {
x509_u32 tbs_start;
x509_u32 tbs_len;
x509_u8 version;
x509_u32 tbs_sig_alg_start;
x509_u32 tbs_sig_alg_len;
x509_u32 tbs_sig_alg_oid_start;
x509_u32 tbs_sig_alg_oid_len;
x509_u32 tbs_sig_alg_oid_params_start;
x509_u32 tbs_sig_alg_oid_params_len;
x509_u32 issuer_start;
x509_u32 issuer_len;
x509_u64 this_update;
x509_u64 next_update;
int has_aki;
int aki_has_keyIdentifier;
x509_u32 aki_keyIdentifier_start;
x509_u32 aki_keyIdentifier_len;
int aki_has_generalNames_and_serial;
x509_u32 aki_generalNames_start;
x509_u32 aki_generalNames_len;
x509_u32 aki_serial_start;
x509_u32 aki_serial_len;
int has_crldp;
int one_crldp_has_all_reasons;
int has_crlnumber;
x509_u32 crlnumber_start;
x509_u32 crlnumber_len;
int has_revoked_certs;
x509_u32 sig_alg_start;
x509_u32 sig_alg_len;
sig_alg_id sig_alg;
hash_alg_id hash_alg;
sig_params sig_alg_params;
x509_u32 sig_start;
x509_u32 sig_len;
} crl_parsing_ctx;
int parse_x509_crl(crl_parsing_ctx *ctx, const x509_u8 *buf, x509_u32 len);
#endif
#ifndef __X509_PARSER_H__
#define __X509_PARSER_H__
int parse_x509_cert_relaxed(cert_parsing_ctx *ctx, const x509_u8 *buf, x509_u32 len, x509_u32 *eaten);
int parse_x509_crl_relaxed(crl_parsing_ctx *ctx, const x509_u8 *buf, x509_u32 len, x509_u32 *eaten);
#endif
#define X509_FILE_NUM 2
static int parse_pubkey_ed448(cert_parsing_ctx *ctx, const x509_u8 *cert, x509_u32 off, x509_u32 len);
static int parse_pubkey_x448(cert_parsing_ctx *ctx, const x509_u8 *cert, x509_u32 off, x509_u32 len);
static int parse_pubkey_ed25519(cert_parsing_ctx *ctx, const x509_u8 *cert, x509_u32 off, x509_u32 len);
static int parse_pubkey_x25519(cert_parsing_ctx *ctx, const x509_u8 *cert, x509_u32 off, x509_u32 len);
static int parse_pubkey_ec(cert_parsing_ctx *ctx, const x509_u8 *cert, x509_u32 off, x509_u32 len);
static int parse_pubkey_rsa(cert_parsing_ctx *ctx, const x509_u8 *cert, x509_u32 off, x509_u32 len);
static int parse_pubkey_gostr3410_94(cert_parsing_ctx *ctx, const x509_u8 *cert, x509_u32 off, x509_u32 len);
static int parse_pubkey_gostr3410_2001(cert_parsing_ctx *ctx, const x509_u8 *cert, x509_u32 off, x509_u32 len);
static int parse_pubkey_gostr3410_2012_256(cert_parsing_ctx *ctx, const x509_u8 *cert, x509_u32 off, x509_u32 len);
static int parse_pubkey_gostr3410_2012_512(cert_parsing_ctx *ctx, const x509_u8 *cert, x509_u32 off, x509_u32 len);
static int parse_pubkey_dsa(cert_parsing_ctx *ctx, const x509_u8 *cert, x509_u32 off, x509_u32 len);
static int parse_pubkey_bign(cert_parsing_ctx *ctx, const x509_u8 *cert, x509_u32 off, x509_u32 len);
static int parse_algoid_pubkey_params_ecPublicKey(cert_parsing_ctx *ctx, const x509_u8 *cert, x509_u32 off, x509_u32 len);
static int parse_algoid_pubkey_params_ed25519(cert_parsing_ctx *ctx, const x509_u8 *cert, x509_u32 off, x509_u32 len);
static int parse_algoid_pubkey_params_ed448(cert_parsing_ctx *ctx, const x509_u8 *cert, x509_u32 off, x509_u32 len);
static int parse_algoid_pubkey_params_x25519(cert_parsing_ctx *ctx, const x509_u8 *cert, x509_u32 off, x509_u32 len);
static int parse_algoid_pubkey_params_x448(cert_parsing_ctx *ctx, const x509_u8 *cert, x509_u32 off, x509_u32 len);
static int parse_algoid_pubkey_params_rsa(cert_parsing_ctx *ctx, const x509_u8 *cert, x509_u32 off, x509_u32 len);
static int parse_algoid_pubkey_params_gost_r3410_2012_256(cert_parsing_ctx *ctx, const x509_u8 *cert, x509_u32 off, x509_u32 len);
static int parse_algoid_pubkey_params_gost_r3410_2012_512(cert_parsing_ctx *ctx, const x509_u8 *cert, x509_u32 off, x509_u32 len);
static int parse_algoid_pubkey_params_gost_r3410_2001(cert_parsing_ctx *ctx, const x509_u8 *cert, x509_u32 off, x509_u32 len);
static int parse_algoid_pubkey_params_gost_r3410_94(cert_parsing_ctx *ctx, const x509_u8 *cert, x509_u32 off, x509_u32 len);
static int parse_algoid_pubkey_params_dsa(cert_parsing_ctx *ctx, const x509_u8 *cert, x509_u32 off, x509_u32 len);
static int parse_algoid_pubkey_params_ea_rsa(cert_parsing_ctx *ctx, const x509_u8 *cert, x509_u32 off, x509_u32 ATTRIBUTE_UNUSED len);
static int parse_algoid_pubkey_params_none(cert_parsing_ctx *ctx, const x509_u8 *cert, x509_u32 off, x509_u32 ATTRIBUTE_UNUSED len);
static int parse_algoid_pubkey_params_bign(cert_parsing_ctx *ctx, const x509_u8 *cert, x509_u32 off, x509_u32 ATTRIBUTE_UNUSED len);
typedef struct {
const x509_u8 *alg_name;
const x509_u8 *alg_printable_oid;
const x509_u8 *alg_der_oid;
const x509_u32 alg_der_oid_len;
spki_alg_id pubkey_id;
int (*parse_algoid_pubkey_params)(cert_parsing_ctx ATTRIBUTE_UNUSED *ctx, const x509_u8 *cert, x509_u32 off, x509_u32 len);
int (*parse_pubkey)(cert_parsing_ctx ATTRIBUTE_UNUSED *ctx, const x509_u8 *cert, x509_u32 off, x509_u32 len);
} _pubkey_alg;
#define DECL_PUBKEY_ALG(TTalg, XXtype, YYparse_pubkey, ZZparse_algoid, UUname, VVoid, WWoidbuf) \
static const x509_u8 _##TTalg##_pubkey_name[] = UUname; \
static const x509_u8 _##TTalg##_pubkey_printable_oid[] = VVoid; \
static const x509_u8 _##TTalg##_pubkey_der_oid[] = WWoidbuf; \
\
static const _pubkey_alg _##TTalg##_pubkey_alg = { \
.alg_name = _##TTalg##_pubkey_name, \
.alg_printable_oid = _##TTalg##_pubkey_printable_oid, \
.alg_der_oid = _##TTalg##_pubkey_der_oid, \
.alg_der_oid_len = sizeof(_##TTalg##_pubkey_der_oid), \
.pubkey_id = (XXtype), \
.parse_pubkey = (YYparse_pubkey), \
.parse_algoid_pubkey_params = (ZZparse_algoid), \
}
DECL_PUBKEY_ALG(pkcs1_rsaEncryption , SPKI_ALG_RSA , parse_pubkey_rsa , parse_algoid_pubkey_params_rsa , "PKCS-1 rsaEncryption" , "1.2.840.113549.1.1.1" , P99_PROTECT({ 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01 }));
DECL_PUBKEY_ALG(weird_rsa_pub_1 , SPKI_ALG_RSA , parse_pubkey_rsa , parse_algoid_pubkey_params_rsa , "Undocumented RSA pub key oid" , "1.2.840.887.13.1.1.1" , P99_PROTECT({ 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0x77, 0x0d, 0x01, 0x01, 0x01 }));
DECL_PUBKEY_ALG(weird_rsa_pub_2 , SPKI_ALG_RSA , parse_pubkey_rsa , parse_algoid_pubkey_params_rsa , "another rsa pubkey oid" , "1.18.840.113549.1.1.1" , P99_PROTECT({ 0x06, 0x09, 0x3a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01 }));
DECL_PUBKEY_ALG(rsa_gip_cps , SPKI_ALG_RSA , parse_pubkey_rsa , parse_algoid_pubkey_params_rsa , "GIP-CPS" , "1.2.250.1.71.2.6.1" , P99_PROTECT({ 0x06, 0x08, 0x2a, 0x81, 0x7a, 0x01, 0x47, 0x02, 0x06, 0x01 }));
DECL_PUBKEY_ALG(rsassa_pss_shake256 , SPKI_ALG_RSA , parse_pubkey_rsa , parse_algoid_pubkey_params_none , "RSASSA-PSS-SHAKE256" , "1.3.6.1.5.5.7.6.31" , P99_PROTECT({ 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x06, 0x1f }));
DECL_PUBKEY_ALG(rsassa_pss_shake128 , SPKI_ALG_RSA , parse_pubkey_rsa , parse_algoid_pubkey_params_none , "RSASSA-PSS-SHAKE128" , "1.3.6.1.5.5.7.6.30" , P99_PROTECT({ 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x06, 0x1e }));
DECL_PUBKEY_ALG(ea_rsa , SPKI_ALG_RSA , parse_pubkey_rsa , parse_algoid_pubkey_params_ea_rsa , "id-ea-rsa" , "2.5.8.1.1" , P99_PROTECT({ 0x06, 0x04, 0x55, 0x08, 0x01, 0x01 }));
DECL_PUBKEY_ALG(ecpublickey , SPKI_ALG_ECPUBKEY , parse_pubkey_ec , parse_algoid_pubkey_params_ecPublicKey , "ecPublicKey" , "1.2.840.10045.2.1" , P99_PROTECT({ 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01 }));
DECL_PUBKEY_ALG(dsa_pubkey , SPKI_ALG_DSA , parse_pubkey_dsa , parse_algoid_pubkey_params_dsa , "DSA subject public key" , "1.2.840.10040.4.1" , P99_PROTECT({ 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x38, 0x04, 0x01 }));
DECL_PUBKEY_ALG(x448 , SPKI_ALG_X448 , parse_pubkey_x448 , parse_algoid_pubkey_params_x448 , "X448" , "1.3.101.111" , P99_PROTECT({ 0x06, 0x03, 0x2b, 0x65, 0x6f }));
DECL_PUBKEY_ALG(ed448 , SPKI_ALG_ED448 , parse_pubkey_ed448 , parse_algoid_pubkey_params_ed448 , "Ed448" , "1.3.101.113" , P99_PROTECT({ 0x06, 0x03, 0x2b, 0x65, 0x71 }));
DECL_PUBKEY_ALG(x25519 , SPKI_ALG_X25519 , parse_pubkey_x25519 , parse_algoid_pubkey_params_x25519 , "X25519" , "1.3.101.110" , P99_PROTECT({ 0x06, 0x03, 0x2b, 0x65, 0x6e }));
DECL_PUBKEY_ALG(ed25519 , SPKI_ALG_ED25519 , parse_pubkey_ed25519 , parse_algoid_pubkey_params_ed25519 , "Ed25519" , "1.3.101.112" , P99_PROTECT({ 0x06, 0x03, 0x2b, 0x65, 0x70 }));
DECL_PUBKEY_ALG(bign , SPKI_ALG_BIGN_PUBKEY , parse_pubkey_bign , parse_algoid_pubkey_params_bign , "bign-pubkey" , "1.2.112.0.2.0.34.101.45.2.1", P99_PROTECT({ 0x06, 0x0a, 0x2a, 0x70, 0x00, 0x02, 0x00, 0x22, 0x65, 0x2d, 0x02, 0x01 }));
DECL_PUBKEY_ALG(gost_R3410_94 , SPKI_ALG_GOSTR3410_94 , parse_pubkey_gostr3410_94 , parse_algoid_pubkey_params_gost_r3410_94 , "gostR3410-94 public key" , "1.2.643.2.2.20" , P99_PROTECT({ 0x06, 0x06, 0x2a, 0x85, 0x03, 0x02, 0x02, 0x14 }));
DECL_PUBKEY_ALG(gost_R3410_2001 , SPKI_ALG_GOSTR3410_2001 , parse_pubkey_gostr3410_2001 , parse_algoid_pubkey_params_gost_r3410_2001 , "gostR3410-2001 public key" , "1.2.643.2.2.19" , P99_PROTECT({ 0x06, 0x06, 0x2a, 0x85, 0x03, 0x02, 0x02, 0x13 }));
DECL_PUBKEY_ALG(gost_R3410_2012_512 , SPKI_ALG_GOSTR3410_2012_512, parse_pubkey_gostr3410_2012_512, parse_algoid_pubkey_params_gost_r3410_2012_512, "gost3410-2012-512 public key" , "1.2.643.7.1.1.1.2" , P99_PROTECT({ 0x06, 0x08, 0x2a, 0x85, 0x03, 0x07, 0x01, 0x01, 0x01, 0x02 }));
DECL_PUBKEY_ALG(gost_R3410_2012_256 , SPKI_ALG_GOSTR3410_2012_256, parse_pubkey_gostr3410_2012_256, parse_algoid_pubkey_params_gost_r3410_2012_256, "gost3410-2012-256 public key" , "1.2.643.7.1.1.1.1" , P99_PROTECT({ 0x06, 0x08, 0x2a, 0x85, 0x03, 0x07, 0x01, 0x01, 0x01, 0x01 }));
static const _pubkey_alg ATTRIBUTE_UNUSED *known_pubkey_algs[] = {
&_ecpublickey_pubkey_alg,
&_pkcs1_rsaEncryption_pubkey_alg,
&_rsa_gip_cps_pubkey_alg,
&_rsassa_pss_shake256_pubkey_alg,
&_rsassa_pss_shake128_pubkey_alg,
&_ed448_pubkey_alg,
&_ed25519_pubkey_alg,
&_x448_pubkey_alg,
&_x25519_pubkey_alg,
&_gost_R3410_94_pubkey_alg,
&_gost_R3410_2001_pubkey_alg,
&_gost_R3410_2012_512_pubkey_alg,
&_gost_R3410_2012_256_pubkey_alg,
&_bign_pubkey_alg,
&_weird_rsa_pub_1_pubkey_alg,
&_weird_rsa_pub_2_pubkey_alg,
&_dsa_pubkey_pubkey_alg,
&_ea_rsa_pubkey_alg,
};
const x509_u16 num_known_pubkey_algs = (sizeof(known_pubkey_algs) / sizeof(known_pubkey_algs[0]));
typedef struct {
const x509_u8 *params_name;
const x509_u8 *params_printable_oid;
const x509_u8 *params_der_oid;
const x509_u32 params_der_oid_len;
_gost94_pub_params_id params_id;
} _gost94_pub_params;
#define DECL_GOST94_PARAMS(EEparams, AAid, BBname, CCoid, DDoidbuf) \
static const x509_u8 _##EEparams##_gost_94_params_name[] = BBname; \
static const x509_u8 _##EEparams##_gost_94_params_printable_oid[] = CCoid; \
static const x509_u8 _##EEparams##_gost_94_params_der_oid[] = DDoidbuf; \
\
static const _gost94_pub_params _##EEparams##_ParamSet = { \
.params_name = _##EEparams##_gost_94_params_name, \
.params_printable_oid = _##EEparams##_gost_94_params_printable_oid, \
.params_der_oid = _##EEparams##_gost_94_params_der_oid, \
.params_der_oid_len = sizeof(_##EEparams##_gost_94_params_der_oid), \
.params_id = (AAid), \
}
DECL_GOST94_PARAMS(GostR3410_94_Test, GOST94_PARAMS_TEST , "GostR3410_94_TestParamSet", "1.2.643.2.2.32.0", P99_PROTECT({ 0x06, 0x07, 0x2A, 0x85, 0x03, 0x02, 0x02, 0x20, 0x00 }));
DECL_GOST94_PARAMS(GostR3410_94_CryptoPro_A, GOST94_PARAMS_CRYPTOPRO_A , "GostR3410_94_CryptoPro_A_ParamSet", "1.2.643.2.2.32.2", P99_PROTECT({ 0x06, 0x07, 0x2A, 0x85, 0x03, 0x02, 0x02, 0x20, 0x02 }));
DECL_GOST94_PARAMS(GostR3410_94_CryptoPro_B, GOST94_PARAMS_CRYPTOPRO_B , "GostR3410_94_CryptoPro_B_ParamSet", "1.2.643.2.2.32.3", P99_PROTECT({ 0x06, 0x07, 0x2A, 0x85, 0x03, 0x02, 0x02, 0x20, 0x03 }));
DECL_GOST94_PARAMS(GostR3410_94_CryptoPro_C, GOST94_PARAMS_CRYPTOPRO_C , "GostR3410_94_CryptoPro_C_ParamSet", "1.2.643.2.2.32.4", P99_PROTECT({ 0x06, 0x07, 0x2A, 0x85, 0x03, 0x02, 0x02, 0x20, 0x04 }));
DECL_GOST94_PARAMS(GostR3410_94_CryptoPro_D, GOST94_PARAMS_CRYPTOPRO_D , "GostR3410_94_CryptoPro_D_ParamSet", "1.2.643.2.2.32.5", P99_PROTECT({ 0x06, 0x07, 0x2A, 0x85, 0x03, 0x02, 0x02, 0x20, 0x05 }));
DECL_GOST94_PARAMS(GostR3410_94_CryptoPro_XchA, GOST94_PARAMS_CRYPTOPRO_XCHA, "GostR3410_94_CryptoPro_XchA_ParamSet", "1.2.643.2.2.33.1", P99_PROTECT({ 0x06, 0x07, 0x2A, 0x85, 0x03, 0x02, 0x02, 0x21, 0x01 }));
DECL_GOST94_PARAMS(GostR3410_94_CryptoPro_XchB, GOST94_PARAMS_CRYPTOPRO_XCHB, "GostR3410_94_CryptoPro_XchB_ParamSet", "1.2.643.2.2.33.2", P99_PROTECT({ 0x06, 0x07, 0x2A, 0x85, 0x03, 0x02, 0x02, 0x21, 0x02 }));
DECL_GOST94_PARAMS(GostR3410_94_CryptoPro_XchC, GOST94_PARAMS_CRYPTOPRO_XCHC, "GostR3410_94_CryptoPro_XchC_ParamSet", "1.2.643.2.2.33.3", P99_PROTECT({ 0x06, 0x07, 0x2A, 0x85, 0x03, 0x02, 0x02, 0x21, 0x03 }));
static const _gost94_pub_params ATTRIBUTE_UNUSED *known_gost_94_params[] = {
&_GostR3410_94_Test_ParamSet,
&_GostR3410_94_CryptoPro_A_ParamSet,
&_GostR3410_94_CryptoPro_B_ParamSet,
&_GostR3410_94_CryptoPro_C_ParamSet,
&_GostR3410_94_CryptoPro_D_ParamSet,
&_GostR3410_94_CryptoPro_XchA_ParamSet,
&_GostR3410_94_CryptoPro_XchB_ParamSet,
&_GostR3410_94_CryptoPro_XchC_ParamSet,
};
const x509_u16 num_known_gost94_params = (sizeof(known_gost_94_params) / sizeof(known_gost_94_params[0]));
const _gost94_pub_params * find_gost94_params_by_oid(const x509_u8 *buf, x509_u32 len)
{
const _gost94_pub_params *found = NULL;
const _gost94_pub_params *cur = NULL;
x509_u8 k;
if ((buf == NULL) || (len == 0)) {
goto out;
}
for (k = 0; k < num_known_gost94_params; k++) {
int ret;
cur = known_gost_94_params[k];
if (cur->params_der_oid_len != len) {
continue;
}
ret = !bufs_differ(cur->params_der_oid, buf, cur->params_der_oid_len);
if (ret) {
found = cur;
break;
}
}
out:
return found;
}
const _pubkey_alg * find_pubkey_alg_by_oid(const x509_u8 *buf, x509_u32 len)