aboutsummaryrefslogtreecommitdiffstats
path: root/test/clightgen/issue196.c
blob: 1821fd6d43d2b1e42913e02613f43d163a5d48dc (plain)
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
#include <stdint.h>
#include <stdlib.h>
#include <sys/types.h>


typedef int ASN1_BOOLEAN;
typedef int ASN1_NULL;
typedef struct ASN1_ITEM_st ASN1_ITEM;
typedef struct asn1_object_st ASN1_OBJECT;
typedef struct asn1_pctx_st ASN1_PCTX;
typedef struct asn1_string_st ASN1_BIT_STRING;
typedef struct asn1_string_st ASN1_BMPSTRING;
typedef struct asn1_string_st ASN1_ENUMERATED;
typedef struct asn1_string_st ASN1_GENERALIZEDTIME;
typedef struct asn1_string_st ASN1_GENERALSTRING;
typedef struct asn1_string_st ASN1_IA5STRING;
typedef struct asn1_string_st ASN1_INTEGER;
typedef struct asn1_string_st ASN1_OCTET_STRING;
typedef struct asn1_string_st ASN1_PRINTABLESTRING;
typedef struct asn1_string_st ASN1_STRING;
typedef struct asn1_string_st ASN1_T61STRING;
typedef struct asn1_string_st ASN1_TIME;
typedef struct asn1_string_st ASN1_UNIVERSALSTRING;
typedef struct asn1_string_st ASN1_UTCTIME;
typedef struct asn1_string_st ASN1_UTF8STRING;
typedef struct asn1_string_st ASN1_VISIBLESTRING;

typedef struct AUTHORITY_KEYID_st AUTHORITY_KEYID;
typedef struct DIST_POINT_st DIST_POINT;
typedef struct ISSUING_DIST_POINT_st ISSUING_DIST_POINT;
typedef struct NAME_CONSTRAINTS_st NAME_CONSTRAINTS;
typedef struct X509_POLICY_CACHE_st X509_POLICY_CACHE;
typedef struct X509_POLICY_LEVEL_st X509_POLICY_LEVEL;
typedef struct X509_POLICY_NODE_st X509_POLICY_NODE;
typedef struct X509_POLICY_TREE_st X509_POLICY_TREE;
typedef struct X509_algor_st X509_ALGOR;
typedef struct X509_crl_st X509_CRL;
typedef struct X509_pubkey_st X509_PUBKEY;
typedef struct bignum_ctx BN_CTX;
typedef struct bignum_st BIGNUM;
typedef struct bio_method_st BIO_METHOD;
typedef struct bio_st BIO;
typedef struct bn_gencb_st BN_GENCB;
typedef struct bn_mont_ctx_st BN_MONT_CTX;
typedef struct buf_mem_st BUF_MEM;
typedef struct cbb_st CBB;
typedef struct cbs_st CBS;
typedef struct conf_st CONF;
typedef struct dh_method DH_METHOD;
typedef struct dh_st DH;
typedef struct dsa_method DSA_METHOD;
typedef struct dsa_st DSA;
typedef struct ec_key_st EC_KEY;
typedef struct ecdsa_method_st ECDSA_METHOD;
typedef struct ecdsa_sig_st ECDSA_SIG;
typedef struct engine_st ENGINE;
typedef struct env_md_ctx_st EVP_MD_CTX;
typedef struct env_md_st EVP_MD;
typedef struct evp_aead_st EVP_AEAD;
typedef struct evp_cipher_ctx_st EVP_CIPHER_CTX;
typedef struct evp_cipher_st EVP_CIPHER;
typedef struct evp_pkey_asn1_method_st EVP_PKEY_ASN1_METHOD;
typedef struct evp_pkey_ctx_st EVP_PKEY_CTX;
typedef struct evp_pkey_method_st EVP_PKEY_METHOD;
typedef struct evp_pkey_st EVP_PKEY;
typedef struct hmac_ctx_st HMAC_CTX;
typedef struct md4_state_st MD4_CTX;
typedef struct md5_state_st MD5_CTX;
typedef struct pkcs8_priv_key_info_st PKCS8_PRIV_KEY_INFO;
typedef struct pkcs12_st PKCS12;
typedef struct rand_meth_st RAND_METHOD;
typedef struct rc4_key_st RC4_KEY;
typedef struct rsa_meth_st RSA_METHOD;
typedef struct rsa_st RSA;
typedef struct sha256_state_st SHA256_CTX;
typedef struct sha512_state_st SHA512_CTX;
typedef struct sha_state_st SHA_CTX;
typedef struct ssl_ctx_st SSL_CTX;
typedef struct ssl_st SSL;
typedef struct st_ERR_FNS ERR_FNS;
typedef struct v3_ext_ctx X509V3_CTX;
typedef struct x509_crl_method_st X509_CRL_METHOD;
typedef struct x509_revoked_st X509_REVOKED;
typedef struct x509_st X509;
typedef struct x509_store_ctx_st X509_STORE_CTX;
typedef struct x509_store_st X509_STORE;
typedef void *OPENSSL_BLOCK;
 const EVP_MD *EVP_md4(void);
 const EVP_MD *EVP_md5(void);
 const EVP_MD *EVP_sha1(void);
 const EVP_MD *EVP_sha224(void);
 const EVP_MD *EVP_sha256(void);
 const EVP_MD *EVP_sha384(void);
 const EVP_MD *EVP_sha512(void);



 const EVP_MD *EVP_md5_sha1(void);



 const EVP_MD *EVP_get_digestbynid(int nid);



 const EVP_MD *EVP_get_digestbyobj(const ASN1_OBJECT *obj);
 void EVP_MD_CTX_init(EVP_MD_CTX *ctx);



 EVP_MD_CTX *EVP_MD_CTX_create(void);



 int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx);


 void EVP_MD_CTX_destroy(EVP_MD_CTX *ctx);



 int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in);







 int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type,
                                     ENGINE *engine);



 int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type);



 int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *data,
                                    size_t len);
 int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, uint8_t *md_out,
                                      unsigned int *out_size);



 int EVP_DigestFinal(EVP_MD_CTX *ctx, uint8_t *md_out,
                                   unsigned int *out_size);






 int EVP_Digest(const void *data, size_t len, uint8_t *md_out,
                              unsigned int *md_out_size, const EVP_MD *type,
                              ENGINE *impl);
 int EVP_MD_type(const EVP_MD *md);


 const char *EVP_MD_name(const EVP_MD *md);



 uint32_t EVP_MD_flags(const EVP_MD *md);


 size_t EVP_MD_size(const EVP_MD *md);


 size_t EVP_MD_block_size(const EVP_MD *md);
 int EVP_MD_CTX_copy(EVP_MD_CTX *out, const EVP_MD_CTX *in);



 int EVP_add_digest(const EVP_MD *digest);






 const EVP_MD *EVP_MD_CTX_md(const EVP_MD_CTX *ctx);



 unsigned EVP_MD_CTX_size(const EVP_MD_CTX *ctx);



 unsigned EVP_MD_CTX_block_size(const EVP_MD_CTX *ctx);




 int EVP_MD_CTX_type(const EVP_MD_CTX *ctx);


 void EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, uint32_t flags);



 void EVP_MD_CTX_clear_flags(EVP_MD_CTX *ctx, uint32_t flags);



 uint32_t EVP_MD_CTX_test_flags(const EVP_MD_CTX *ctx,
                                              uint32_t flags);


struct evp_md_pctx_ops;

struct env_md_ctx_st {

  const EVP_MD *digest;

  uint32_t flags;


  void *md_data;



  int (*update)(EVP_MD_CTX *ctx, const void *data, size_t count);



  EVP_PKEY_CTX *pctx;



  const struct evp_md_pctx_ops *pctx_ops;
} ;

 int MD4_Init(MD4_CTX *md4);


 int MD4_Update(MD4_CTX *md4, const void *data, size_t len);




 int MD4_Final(uint8_t *md, MD4_CTX *md4);



 void MD4_Transform(MD4_CTX *md4, const uint8_t *block);

struct md4_state_st {
  uint32_t A, B, C, D;
  uint32_t Nl, Nh;
  uint32_t data[16];
  unsigned int num;
};
 int MD5_Init(MD5_CTX *md5);


 int MD5_Update(MD5_CTX *md5, const void *data, size_t len);




 int MD5_Final(uint8_t *md, MD5_CTX *md5);



 uint8_t *MD5(const uint8_t *data, size_t len, uint8_t *out);



 void MD5_Transform(MD5_CTX *md5, const uint8_t *block);

struct md5_state_st {
  uint32_t A, B, C, D;
  uint32_t Nl, Nh;
  uint32_t data[16];
  unsigned int num;
};
struct cbs_st {
  const uint8_t *data;
  size_t len;
};



 void CBS_init(CBS *cbs, const uint8_t *data, size_t len);



 int CBS_skip(CBS *cbs, size_t len);


 const uint8_t *CBS_data(const CBS *cbs);


 size_t CBS_len(const CBS *cbs);






 int CBS_stow(const CBS *cbs, uint8_t **out_ptr, size_t *out_len);
 int CBS_strdup(const CBS *cbs, char **out_ptr);



 int CBS_contains_zero_byte(const CBS *cbs);




 int CBS_mem_equal(const CBS *cbs, const uint8_t *data,
                                 size_t len);



 int CBS_get_u8(CBS *cbs, uint8_t *out);



 int CBS_get_u16(CBS *cbs, uint16_t *out);



 int CBS_get_u24(CBS *cbs, uint32_t *out);



 int CBS_get_u32(CBS *cbs, uint32_t *out);



 int CBS_get_bytes(CBS *cbs, CBS *out, size_t len);




 int CBS_get_u8_length_prefixed(CBS *cbs, CBS *out);




 int CBS_get_u16_length_prefixed(CBS *cbs, CBS *out);




 int CBS_get_u24_length_prefixed(CBS *cbs, CBS *out);
 int CBS_get_asn1(CBS *cbs, CBS *out, unsigned tag_value);



 int CBS_get_asn1_element(CBS *cbs, CBS *out, unsigned tag_value);






 int CBS_peek_asn1_tag(const CBS *cbs, unsigned tag_value);
 int CBS_get_any_asn1_element(CBS *cbs, CBS *out,
                                            unsigned *out_tag,
                                            size_t *out_header_len);





 int CBS_get_asn1_uint64(CBS *cbs, uint64_t *out);






 int CBS_get_optional_asn1(CBS *cbs, CBS *out, int *out_present,
                                         unsigned tag);







 int CBS_get_optional_asn1_octet_string(CBS *cbs, CBS *out,
                                                      int *out_present,
                                                      unsigned tag);






 int CBS_get_optional_asn1_uint64(CBS *cbs, uint64_t *out,
                                                unsigned tag,
                                                uint64_t default_value);






 int CBS_get_optional_asn1_bool(CBS *cbs, int *out, unsigned tag,
                                              int default_value);
struct cbb_buffer_st {
  uint8_t *buf;
  size_t len;
  size_t cap;
  char can_resize;

};

struct cbb_st {
  struct cbb_buffer_st *base;


  size_t offset;

  struct cbb_st *child;


  uint8_t pending_len_len;
  char pending_is_asn1;


  char is_top_level;
};




 int CBB_init(CBB *cbb, size_t initial_capacity);




 int CBB_init_fixed(CBB *cbb, uint8_t *buf, size_t len);




 void CBB_cleanup(CBB *cbb);
 int CBB_finish(CBB *cbb, uint8_t **out_data, size_t *out_len);




 int CBB_flush(CBB *cbb);




 int CBB_add_u8_length_prefixed(CBB *cbb, CBB *out_contents);




 int CBB_add_u16_length_prefixed(CBB *cbb, CBB *out_contents);




 int CBB_add_u24_length_prefixed(CBB *cbb, CBB *out_contents);






 int CBB_add_asn1(CBB *cbb, CBB *out_contents, uint8_t tag);



 int CBB_add_bytes(CBB *cbb, const uint8_t *data, size_t len);





 int CBB_add_space(CBB *cbb, uint8_t **out_data, size_t len);



 int CBB_add_u8(CBB *cbb, uint8_t value);



 int CBB_add_u16(CBB *cbb, uint16_t value);



 int CBB_add_u24(CBB *cbb, uint32_t value);




 int CBB_add_asn1_uint64(CBB *cbb, uint64_t value);
 ASN1_OBJECT *OBJ_dup(const ASN1_OBJECT *obj);



 int OBJ_cmp(const ASN1_OBJECT *a, const ASN1_OBJECT *b);






 int OBJ_obj2nid(const ASN1_OBJECT *obj);



 int OBJ_cbs2nid(const CBS *cbs);



 int OBJ_sn2nid(const char *short_name);



 int OBJ_ln2nid(const char *long_name);




 int OBJ_txt2nid(const char *s);






 const ASN1_OBJECT *OBJ_nid2obj(int nid);


 const char *OBJ_nid2sn(int nid);


 const char *OBJ_nid2ln(int nid);



 int OBJ_nid2cbb(CBB *out, int nid);
 ASN1_OBJECT *OBJ_txt2obj(const char *s, int dont_search_names);
 int OBJ_obj2txt(char *out, int out_len, const ASN1_OBJECT *obj,
                               int dont_return_name);






 int OBJ_create(const char *oid, const char *short_name,
                              const char *long_name);
 int OBJ_find_sigid_algs(int sign_nid, int *out_digest_nid,
                                       int *out_pkey_nid);






 int OBJ_find_sigid_by_algs(int *out_sign_nid, int digest_nid,
                                          int pkey_nid);
 int SHA1_Init(SHA_CTX *sha);


 int SHA1_Update(SHA_CTX *sha, const void *data, size_t len);




 int SHA1_Final(uint8_t *md, SHA_CTX *sha);




 uint8_t *SHA1(const uint8_t *data, size_t len, uint8_t *out);



 void SHA1_Transform(SHA_CTX *sha, const uint8_t *block);

struct sha_state_st {
  uint32_t h0, h1, h2, h3, h4;
  uint32_t Nl, Nh;
  uint32_t data[16];
  unsigned int num;
};
 int SHA224_Init(SHA256_CTX *sha);


 int SHA224_Update(SHA256_CTX *sha, const void *data, size_t len);



 int SHA224_Final(uint8_t *md, SHA256_CTX *sha);




 uint8_t *SHA224(const uint8_t *data, size_t len, uint8_t *out);
 int SHA256_Init(SHA256_CTX *sha);


 int SHA256_Update(SHA256_CTX *sha, const void *data, size_t len);



 int SHA256_Final(uint8_t *md, SHA256_CTX *sha);




 uint8_t *SHA256(const uint8_t *data, size_t len, uint8_t *out);



 void SHA256_Transform(SHA256_CTX *sha, const uint8_t *data);

struct sha256_state_st {
  uint32_t h[8];
  uint32_t Nl, Nh;
  uint32_t data[16];
  unsigned int num, md_len;
};
 int SHA384_Init(SHA512_CTX *sha);


 int SHA384_Update(SHA512_CTX *sha, const void *data, size_t len);



 int SHA384_Final(uint8_t *md, SHA512_CTX *sha);




 uint8_t *SHA384(const uint8_t *data, size_t len, uint8_t *out);



 void SHA384_Transform(SHA512_CTX *sha, const uint8_t *data);
 int SHA512_Init(SHA512_CTX *sha);


 int SHA512_Update(SHA512_CTX *sha, const void *data, size_t len);



 int SHA512_Final(uint8_t *md, SHA512_CTX *sha);




 uint8_t *SHA512(const uint8_t *data, size_t len, uint8_t *out);



 void SHA512_Transform(SHA512_CTX *sha, const uint8_t *data);

struct sha512_state_st {
  uint64_t h[8];
  uint64_t Nl, Nh;
  union {
    uint64_t d[16];
    uint8_t p[128];
  } u;
  unsigned int num, md_len;
};

struct env_md_st {


  int type;


  unsigned md_size;


  uint32_t flags;



  int (*init)(EVP_MD_CTX *ctx);


  int (*update)(EVP_MD_CTX *ctx, const void *data, size_t count);


  int (*final)(EVP_MD_CTX *ctx, uint8_t *out);


  unsigned block_size;


  unsigned ctx_size;
};




struct evp_md_pctx_ops {


  void (*free) (EVP_PKEY_CTX *pctx);



  EVP_PKEY_CTX* (*dup) (EVP_PKEY_CTX *pctx);



  int (*begin_digest) (EVP_MD_CTX *ctx);
};


static int md4_init(EVP_MD_CTX *ctx) { return MD4_Init(ctx->md_data); }

static int md4_update(EVP_MD_CTX *ctx, const void *data, size_t count) {
  return MD4_Update(ctx->md_data, data, count);
}

static int md4_final(EVP_MD_CTX *ctx, unsigned char *out) {
  return MD4_Final(out, ctx->md_data);
}

static const EVP_MD md4_md = {
    257, 16, 0 , md4_init,
    md4_update, md4_final, 64 , sizeof(MD4_CTX),
};

const EVP_MD *EVP_md4(void) { return &md4_md; }


static int md5_init(EVP_MD_CTX *ctx) { return MD5_Init(ctx->md_data); }

static int md5_update(EVP_MD_CTX *ctx, const void *data, size_t count) {
  return MD5_Update(ctx->md_data, data, count);
}

static int md5_final(EVP_MD_CTX *ctx, unsigned char *out) {
  return MD5_Final(out, ctx->md_data);
}

static const EVP_MD md5_md = {
    4, 16, 0 , md5_init,
    md5_update, md5_final, 64 , sizeof(MD5_CTX),
};

const EVP_MD *EVP_md5(void) { return &md5_md; }


static int sha1_init(EVP_MD_CTX *ctx) { return SHA1_Init(ctx->md_data); }

static int sha1_update(EVP_MD_CTX *ctx, const void *data, size_t count) {
  return SHA1_Update(ctx->md_data, data, count);
}

static int sha1_final(EVP_MD_CTX *ctx, unsigned char *md) {
  return SHA1_Final(md, ctx->md_data);
}

static const EVP_MD sha1_md = {
    64, 20, 0 , sha1_init,
    sha1_update, sha1_final, 64 , sizeof(SHA_CTX),
};

const EVP_MD *EVP_sha1(void) { return &sha1_md; }


static int sha224_init(EVP_MD_CTX *ctx) { return SHA224_Init(ctx->md_data); }

static int sha224_update(EVP_MD_CTX *ctx, const void *data, size_t count) {
  return SHA224_Update(ctx->md_data, data, count);
}

static int sha224_final(EVP_MD_CTX *ctx, unsigned char *md) {
  return SHA224_Final(md, ctx->md_data);
}

static const EVP_MD sha224_md = {
    675, 28, 0 ,
    sha224_init, sha224_update, sha224_final,
    64 , sizeof(SHA256_CTX),
};

const EVP_MD *EVP_sha224(void) { return &sha224_md; }


static int sha256_init(EVP_MD_CTX *ctx) { return SHA256_Init(ctx->md_data); }

static int sha256_update(EVP_MD_CTX *ctx, const void *data, size_t count) {
  return SHA256_Update(ctx->md_data, data, count);
}

static int sha256_final(EVP_MD_CTX *ctx, unsigned char *md) {
  return SHA256_Final(md, ctx->md_data);
}

static const EVP_MD sha256_md = {
    672, 32, 0 ,
    sha256_init, sha256_update, sha256_final,
    64 , sizeof(SHA256_CTX),
};

const EVP_MD *EVP_sha256(void) { return &sha256_md; }


static int sha384_init(EVP_MD_CTX *ctx) { return SHA384_Init(ctx->md_data); }

static int sha384_update(EVP_MD_CTX *ctx, const void *data, size_t count) {
  return SHA384_Update(ctx->md_data, data, count);
}

static int sha384_final(EVP_MD_CTX *ctx, unsigned char *md) {
  return SHA384_Final(md, ctx->md_data);
}

static const EVP_MD sha384_md = {
    673, 48, 0 ,
    sha384_init, sha384_update, sha384_final,
    128 , sizeof(SHA512_CTX),
};

const EVP_MD *EVP_sha384(void) { return &sha384_md; }


static int sha512_init(EVP_MD_CTX *ctx) { return SHA512_Init(ctx->md_data); }

static int sha512_update(EVP_MD_CTX *ctx, const void *data, size_t count) {
  return SHA512_Update(ctx->md_data, data, count);
}

static int sha512_final(EVP_MD_CTX *ctx, unsigned char *md) {
  return SHA512_Final(md, ctx->md_data);
}

static const EVP_MD sha512_md = {
    674, 64, 0 ,
    sha512_init, sha512_update, sha512_final,
    128 , sizeof(SHA512_CTX),
};

const EVP_MD *EVP_sha512(void) { return &sha512_md; }


typedef struct {
  MD5_CTX md5;
  SHA_CTX sha1;
} MD5_SHA1_CTX;

static int md5_sha1_init(EVP_MD_CTX *md_ctx) {
  MD5_SHA1_CTX *ctx = md_ctx->md_data;
  return MD5_Init(&ctx->md5) && SHA1_Init(&ctx->sha1);
}

static int md5_sha1_update(EVP_MD_CTX *md_ctx, const void *data, size_t count) {
  MD5_SHA1_CTX *ctx = md_ctx->md_data;
  return MD5_Update(&ctx->md5, data, count) && SHA1_Update(&ctx->sha1, data, count);
}

static int md5_sha1_final(EVP_MD_CTX *md_ctx, unsigned char *out) {
  MD5_SHA1_CTX *ctx = md_ctx->md_data;
  if (!MD5_Final(out, &ctx->md5) ||
      !SHA1_Final(out + 16, &ctx->sha1)) {
    return 0;
  }
  return 1;
}

static const EVP_MD md5_sha1_md = {
    114,
    16 + 20,
    0 ,
    md5_sha1_init,
    md5_sha1_update,
    md5_sha1_final,
    64 ,
    sizeof(MD5_SHA1_CTX),
};

const EVP_MD *EVP_md5_sha1(void) { return &md5_sha1_md; }


struct nid_to_digest {
  int nid;
  const EVP_MD* (*md_func)(void);
};

static const struct nid_to_digest nid_to_digest_mapping[] = {
  { 4, EVP_md5 },
  { 64, EVP_sha1 },
  { 675, EVP_sha224 },
  { 672, EVP_sha256 },
  { 673, EVP_sha384 },
  { 674, EVP_sha512 },
  { 114, EVP_md5_sha1 },
  { 66, EVP_sha1 },
  { 113, EVP_sha1 },
  { 416, EVP_sha1 },
  { 8, EVP_md5 },
  { 65, EVP_sha1 },
  { 671, EVP_sha224 },
  { 668, EVP_sha256 },
  { 669, EVP_sha384 },
  { 670, EVP_sha512 },
};

const EVP_MD* EVP_get_digestbynid(int nid) {
  unsigned i;

  for (i = 0; i < sizeof(nid_to_digest_mapping) / sizeof(struct nid_to_digest);
       i++) {
    if (nid_to_digest_mapping[i].nid == nid) {
      return nid_to_digest_mapping[i].md_func();
    }
  }

  return 
        ((void *)0)
            ;
}

const EVP_MD* EVP_get_digestbyobj(const ASN1_OBJECT *obj) {
  return EVP_get_digestbynid(OBJ_obj2nid(obj));
}