forked from ddlencemc/RSA-via-OpenSSL-libeay32
-
Notifications
You must be signed in to change notification settings - Fork 0
/
libeay32.pas
1947 lines (1694 loc) · 75.6 KB
/
libeay32.pas
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
(******************************************************************************
Delphi import unit for OpenSSL libeay, version 0.7m, 2010-11-05
For OpenSSL libeay32.dll version 0.9.6b, DLL compiled by GnuWin32.
Tested with Borland Delphi 6, 7 Personal
Copyright (C) 2002-2010, Marco Ferrante.
2002-2006, CSITA - Università di Genova (IT).
http://www.csita.unige.it/.
2007-2009, DISI - Università di Genova (IT).
http://www.disi.unige.it/.
2010, CSITA - Università di Genova (IT).
http://www.csita.unige.it/.
Thanks to:
- Michal Hlavac (Slovakia)
- Risto Tamme (Estonia)
- Simon Sun (probably USA)
- Luis Carrasco, Bambu Code (Mexico)
for contributes and fix
A small part of this work is inspired on MySSL, interface to OpenSSL for
Delphi written by Jan Tomasek.
This product is related to cryptographic software written by Eric
Young ([email protected]). This product is related to software written
by Tim Hudson ([email protected])
== Changelog =======================================================
Version 0.7n, 2010-12-27
- typo corrected
Version 0.7m, 2010-11-05
- added support for PCKS#8 functions (contributed by Luis Carrasco - Bambu Code, Mexico),
- redefinition of PChar as PCharacter to handle PChar and PAnsiChar types
- basic AES support
Version 0.7h, 2009-02-25
- added X509_sign(),
Version 0.7g, 2007-02-20
- Bugfix: PKCS12_parse function uses a by-reference parameter
- Bugfix: BIO_get_mem_data(). Thanks to Andrei
- Removed redundant declarations
Version 0.7f, 2007-02-20
- Bugfix: PEM_read_* function uses a by-reference parameter
Version 0.7e, 2007-02-11
- Bugfix
- Replace BN_mod import with a wrapper to BN_div, see man BN_mul(3)
Version 0.7d, 2006-12-15
- Typos
- Removed EVP_MD_size and EVP_MD_CTX_size: these functions are not defined in
DLL and handle their parameter in a non-opaque way.
Version 0.7c, 2006-11-14
- Add BIGNUM functions
- Defined RSA record
- Add missing EVP_VerifyFinal
Version 0.7b, 2006-11-05
- Between 0.9.6h and 0.9.7, OpenSSL split OpenSSL_add_all_algorithms
in two new functions. Some versions of libeay32.dll use old name,
some use new one. See http://www.openssl.org/news/changelog.html
In this unit, OpenSSL_add_all_algorithms is now a wrapper that
dynamically loads appropriate function from DLL.
Version 0.7a, 2006-09-14
- Bug fixes
- Defined wrapper for OpenSSL memory management function
== License =========================================================
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.
3. All advertising materials mentioning features or use of this
software must display the following acknowledgment:
"This product includes software developed by CSITA - University
of Genoa (Italy) (http://www.unige.it/)"
4. Redistributions of any form whatsoever must retain the following
acknowledgment:
"This product includes software developed by the University
of Genoa (Italy) (http://www.unige.it/) and its contributors"
THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
EXPRESSED 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 OpenSSL PROJECT OR
ITS 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.
====================================================================
******************************************************************************)
unit libeay32;
interface
const
_SSLEAY_VERSION = 0;
_SSLEAY_CFLAGS = 2;
_SSLEAY_BUILT_ON = 3;
_SSLEAY_PLATFORM = 4;
// PADDING constants
RSA_PKCS1_PADDING = 1;
RSA_SSLV23_PADDING = 2;
RSA_NO_PADDING = 3;
RSA_PKCS1_OAEP_PADDING = 4;
// ASN1 type constants
NID_undef = 0;
NID_rsaEncryption = 6;
NID_pkcs7_signed = 22;
NID_pkcs7_signedAndEnveloped = 24;
NID_basic_constraints = 87;
NID_subject_alt_name = 85;
V_ASN1_INTEGER = $02;
V_ASN1_ENUMERATED = 10;
V_ASN1_NEG_INTEGER = $102;
V_ASN1_UTCTIME = 23;
V_ASN1_GENERALIZEDTIME = 24;
V_ASN1_CONTEXT_SPECIFIC = $80;
B_ASN1_NUMERICSTRING = $0001;
B_ASN1_PRINTABLESTRING = $0002;
B_ASN1_T61STRING = $0004;
B_ASN1_TELETEXSTRING = $0008;
B_ASN1_VIDEOTEXSTRING = $0008;
B_ASN1_IA5STRING = $0010;
B_ASN1_GRAPHICSTRING = $0020;
B_ASN1_ISO64STRING = $0040;
B_ASN1_VISIBLESTRING = $0040;
B_ASN1_GENERALSTRING = $0080;
B_ASN1_UNIVERSALSTRING = $0100;
B_ASN1_OCTET_STRING = $0200;
B_ASN1_BIT_STRING = $0400;
B_ASN1_BMPSTRING = $0800;
B_ASN1_UNKNOWN = $1000;
B_ASN1_UTF8STRING = $2000;
MBSTRING_FLAG = $1000;
MBSTRING_ASC = MBSTRING_FLAG or 1;
MBSTRING_BMP = MBSTRING_FLAG or 2;
MBSTRING_UNIV = MBSTRING_FLAG or 3;
MBSTRING_UTF8 = MBSTRING_FLAG or 4;
// These are the 'types' of BIOs
BIO_TYPE_NONE = $0000;
BIO_TYPE_MEM = $0001 or $0400;
BIO_TYPE_FILE = $0002 or $0400;
BIO_TYPE_FD = $0004 or $0400 or $0100;
BIO_TYPE_SOCKET = $0005 or $0400 or $0100;
BIO_TYPE_NULL = $0006 or $0400;
BIO_TYPE_SSL = $0007 or $0200;
BIO_TYPE_MD = $0008 or $0200; // passive filter
BIO_TYPE_BUFFER = $0009 or $0200; // filter
BIO_TYPE_CIPHER = $00010 or $0200; // filter
BIO_TYPE_BASE64 = $00011 or $0200; // filter
BIO_TYPE_CONNECT = $00012 or $0400 or $0100; // socket - connect
BIO_TYPE_ACCEPT = $00013 or $0400 or $0100; // socket for accept
BIO_TYPE_PROXY_CLIENT = $00014 or $0200; // client proxy BIO
BIO_TYPE_PROXY_SERVER = $00015 or $0200; // server proxy BIO
BIO_TYPE_NBIO_TEST = $00016 or $0200; // server proxy BIO
BIO_TYPE_NULL_FILTER = $00017 or $0200;
BIO_TYPE_BER = $00018 or $0200; // BER -> bin filter
BIO_TYPE_BIO = $00019 or $0400; // (half a; BIO pair
BIO_TYPE_LINEBUFFER = $00020 or $0200; // filter
BIO_TYPE_DESCRIPTOR = $0100; // socket, fd, connect or accept
BIO_TYPE_FILTER= $0200;
BIO_TYPE_SOURCE_SINK = $0400;
// BIO ops constants
// BIO_FILENAME_READ|BIO_CLOSE to open or close on free.
// BIO_set_fp(in,stdin,BIO_NOCLOSE);
BIO_NOCLOSE = $00;
BIO_CLOSE = $01;
BIO_FP_READ = $02;
BIO_FP_WRITE = $04;
BIO_FP_APPEND = $08;
BIO_FP_TEXT = $10;
BIO_C_SET_FILENAME = 108;
BIO_CTRL_RESET = 1; // opt - rewind/zero etc
BIO_CTRL_EOF = 2; // opt - are we at the eof
BIO_CTRL_INFO = 3; // opt - extra tit-bits
BIO_CTRL_SET = 4; // man - set the 'IO' type
BIO_CTRL_GET = 5; // man - get the 'IO' type
BIO_CTRL_PUSH = 6; // opt - internal, used to signify change
BIO_CTRL_POP = 7; // opt - internal, used to signify change
BIO_CTRL_GET_CLOSE = 8; // man - set the 'close' on free
BIO_CTRL_SET_CLOSE = 9; // man - set the 'close' on free
BIO_CTRL_PENDING = 10; // opt - is their more data buffered
BIO_CTRL_FLUSH = 11; // opt - 'flush' buffered output
BIO_CTRL_DUP = 12; // man - extra stuff for 'duped' BIO
BIO_CTRL_WPENDING = 13; // opt - number of bytes still to write
BIO_C_GET_MD_CTX = 120;
BN_CTX_NUM = 16;
BN_CTX_NUM_POS = 12;
// RSA key exponent
RSA_3: longint = $3;
RSA_F4: longint = $10001;
FORMAT_UNDEF = 0;
FORMAT_ASN1 = 1;
FORMAT_TEXT = 2;
FORMAT_PEM = 3;
FORMAT_NETSCAPE = 4;
FORMAT_PKCS12 = 5;
FORMAT_SMIME = 6;
FORMAT_X509 = 509; // Not defined in original libeay
PKCS7_TEXT = $001;
PKCS7_NOCERTS = $002;
PKCS7_NOSIGS = $004;
PKCS7_NOCHAIN = $008;
PKCS7_NOINTERN = $010;
PKCS7_NOVERIFY = $020;
PKCS7_DETACHED = $040;
PKCS7_BINARY = $080;
PKCS7_NOATTR = $100;
PKCS7_NOSMIMECAP = $200;
X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT = 18;
SHA_DIGEST_LENGTH = 20;
EVP_MAX_MD_SIZE = 16+20; // The SSLv3 md5+sha1 type
EVP_PKEY_RSA = NID_rsaEncryption;
EXFLAG_KUSAGE = $02;
EXFLAG_BCONS = $1;
EXFLAG_CA = $10;
EXFLAG_SS = $20;
EXFLAG_V1 = $40;
KU_KEY_CERT_SIGN = $0004;
V1_ROOT = EXFLAG_V1 or EXFLAG_SS;
GEN_OTHERNAME = 0 or V_ASN1_CONTEXT_SPECIFIC;
GEN_EMAIL = 1 or V_ASN1_CONTEXT_SPECIFIC;
GEN_DNS = 2 or V_ASN1_CONTEXT_SPECIFIC;
GEN_X400 = 3 or V_ASN1_CONTEXT_SPECIFIC;
GEN_DIRNAME = 4 or V_ASN1_CONTEXT_SPECIFIC;
GEN_EDIPARTY = 5 or V_ASN1_CONTEXT_SPECIFIC;
GEN_URI = 6 or V_ASN1_CONTEXT_SPECIFIC;
GEN_IPADD = 7 or V_ASN1_CONTEXT_SPECIFIC;
GEN_RID = 8 or V_ASN1_CONTEXT_SPECIFIC;
type
// Check the correct "Char" type to use according to the Delphi Version
{$IF CompilerVersion >= 20}
PCharacter = PAnsiChar;
{$ELSE}
PCharacter = PChar;
{$IFEND}
pSTACK = pointer;
// ASN1 types
pASN1_OBJECT = pointer;
pASN1_STRING = ^ASN1_STRING;
ASN1_STRING = record
length: integer;
asn1_type: integer;
data: pointer;
flags: longint;
end;
pASN1_IA5STRING = pASN1_STRING;
pASN1_INTEGER = pASN1_STRING;
pASN1_ENUMERATED = pASN1_STRING;
pASN1_TIME = pASN1_STRING;
pASN1_OCTET_STRING = pASN1_STRING;
pBN_ULONG = ^BN_ULONG;
BN_ULONG = array of byte; // system dependent, consider it as a opaque pointer
pBIGNUM = ^BIGNUM;
BIGNUM = record
d: pBN_ULONG; // Pointer to an array of 'BN_BITS2' bit chunks.
top: integer; // Index of last used d +1.
// The next are internal book keeping for bn_expand.
dmax: integer; // Size of the d array.
neg: integer; // one if the number is negative
flags: integer;
end;
pBN_CTX = ^BN_CTX;
BN_CTX = record
tos: integer;
bn: array [0..BN_CTX_NUM-1] of BIGNUM;
flags: integer;
depth: integer;
pos: array [0..BN_CTX_NUM_POS-1] of integer;
too_many: integer;
end;
pBN_BLINDING = ^BN_BLINDING;
BN_BLINDING = record
init: integer;
A: pBIGNUM;
Ai: pBIGNUM;
_mod: pBIGNUM; // just a reference (original name: mod)
end;
// Used for montgomery multiplication
pBN_MONT_CTX = ^BN_MONT_CTX;
BN_MONT_CTX = record
ri: integer; // number of bits in R
RR: BIGNUM; // used to convert to montgomery form
N: BIGNUM; // The modulus
Ni: BIGNUM; // R*(1/R mod N) - N*Ni = 1
// (Ni is only stored for bignum algorithm)
n0: BN_ULONG; // least significant word of Ni
flags: integer;
end;
// Used for reciprocal division/mod functions
// It cannot be shared between threads
pBN_RECP_CTX = ^BN_RECP_CTX;
BN_RECP_CTX = record
N: BIGNUM; // the divisor
Nr: BIGNUM; // the reciprocal
num_bits: integer;
shift: integer;
flags: integer;
end;
pX509_STORE_CTX = pointer;
// Password ask callback for I/O function prototipe
// It must fill buffer with password and return password length
TPWCallbackFunction = function(buffer: PCharacter; length: integer;
verify: integer; data: pointer): integer; cdecl;
// Progress callback function prototipe
TProgressCallbackFunction = procedure(status: integer; progress: integer;
data: pointer);
// Certificate verification callback
TCertificateVerifyFunction = function(ok: integer;
ctx: pX509_STORE_CTX): integer; cdecl;
pBIO = pointer;
pBIO_METHOD = pointer;
pBUF_MEM = pointer;
des_cblock = array [0..7] of byte;
MD2_CTX = record
num: integer;
data: array [0..15] of byte;
cksm: array [0..15] of cardinal;
state: array [0..15] of cardinal;
end;
MD4_CTX = record
A, B, C, D: cardinal;
Nl, Nh: cardinal;
data: array [0..15] of cardinal;
num: integer;
end;
MD5_CTX = record
A, B, C, D: cardinal;
Nl, Nh: cardinal;
data: array [0..15] of cardinal;
num: integer;
end;
RIPEMD160_CTX = record
A, B, C, D, E: cardinal;
Nl, Nh: cardinal;
data: array [0..15] of cardinal;
num: integer;
end;
SHA_CTX = record
h0, h1, h2, h3, h4: cardinal;
Nl, Nh: cardinal;
data: array [0..16] of cardinal;
num: integer;
end;
MDC2_CTX = record
num: integer;
data: array [0..7] of byte;
h, hh: des_cblock;
pad_type: integer; // either 1 or 2, default 1
end;
CRYPTO_EX_DATA = record
sk: pointer;
dummy: integer;
end;
pAES_KEY = pointer;
pRSA = pointer;
pRSA_METHOD = pointer;
RSA = record
// The first parameter is used to pickup errors where
// this is passed instead of aEVP_PKEY, it is set to 0
pad: integer;
version: integer;
meth: pRSA_METHOD;
n: pBIGNUM;
e: pBIGNUM;
d: pBIGNUM;
p: pBIGNUM;
q: pBIGNUM;
dmp1: pBIGNUM;
dmq1: pBIGNUM;
iqmp: pBIGNUM;
// be careful using this if the RSA structure is shared
ex_data: CRYPTO_EX_DATA;
references: integer;
flags: integer;
// Used to cache montgomery values
_method_mod_n: pBN_MONT_CTX;
_method_mod_p: pBN_MONT_CTX;
_method_mod_q: pBN_MONT_CTX;
// all BIGNUM values are actually in the following data, if it is not
// NULL
bignum_data: ^byte;
blinding: ^BN_BLINDING;
end;
pDSA = ^DSA;
DSA = record
// This first variable is used to pick up errors where
// a DSA is passed instead of of a EVP_PKEY
pad: integer;
version: integer;
write_params: integer;
p: pointer;
q: pointer; // = 20
g: pointer;
pub_key: pointer; // y public key
priv_key: pointer; // x private key
kinv: pointer; // Signing pre-calc
r: pointer; // Signing pre-calc
flags: integer;
// Normally used to cache montgomery values
method_mont_p: PCharacter;
references: integer;
ex_data: record
sk: pointer;
dummy: integer;
end;
meth: pointer;
end;
pDH = pointer;
pEC_KEY = pointer;
pEVP_CIPHER = pointer;
pEVP_MD = ^EVP_MD;
EVP_MD = record
_type: integer;
pkey_type: integer;
md_size: integer;
init: pointer;
update: pointer;
final: pointer;
sign: pointer;
verify: pointer;
required_pkey_type: array [0..4] of integer;
block_size: integer;
ctx_size: integer;
end;
// Superfluo? No, in EVP_MD ci sono le dimensioni del risultato
pEVP_MD_CTX = ^EVP_MD_CTX;
EVP_MD_CTX = record
digest: pEVP_MD;
case integer of
0: (base: array [0..3] of byte);
1: (md2: MD2_CTX);
8: (md4: MD4_CTX);
2: (md5: MD5_CTX);
16: (ripemd160: RIPEMD160_CTX);
4: (sha: SHA_CTX);
32: (mdc2: MDC2_CTX);
end;
pX509_NAME_ENTRY = ^X509_NAME_ENTRY;
X509_NAME_ENTRY = record
obj: pASN1_OBJECT;
value: pASN1_STRING;
_set: integer;
size: integer; // temp variable
end;
pX509_NAME = ^X509_NAME;
pDN = ^X509_NAME;
X509_NAME = record
entries: pointer;
modified: integer;
bytes: pointer;
hash: cardinal;
end;
pX509_VAL = ^X509_VAL;
X509_VAL = record
notBefore: pASN1_TIME;
notAfter: pASN1_TIME;
end;
pX509_CINF = ^X509_CINF;
X509_CINF = record
version: pointer;
serialNumber: pointer;
signature: pointer;
issuer: pointer;
validity: pX509_VAL;
subject: pointer;
key: pointer;
issuerUID: pointer;
subjectUID: pointer;
extensions: pointer;
end;
pX509 = ^X509;
X509 = record
cert_info: pX509_CINF;
sig_alg: pointer; // ^X509_ALGOR
signature: pointer; // ^ASN1_BIT_STRING
valid: integer;
references: integer;
name: PCharacter;
ex_data: CRYPTO_EX_DATA;
ex_pathlen: integer;
ex_flags: integer;
ex_kusage: integer;
ex_xkusage: integer;
ex_nscert: integer;
skid: pASN1_OCTET_STRING;
akid: pointer; // ?
sha1_hash: array [0..SHA_DIGEST_LENGTH-1] of char;
aux: pointer; // ^X509_CERT_AUX
end;
pSTACK_OFX509 = pointer;
pX509_STORE = ^X509_STORE;
pX509_LOOKUP = pointer;
pSTACK_OF509LOOKUP = pointer;
pX509_LOOKUP_METHOD = pointer;
X509_STORE = record
cache: integer;
objs: pSTACK_OFX509;
get_cert_methods: pSTACK_OF509LOOKUP;
verify: pointer; // function called to verify a certificate
verify_cb: TCertificateVerifyFunction;
ex_data: pointer;
references: integer;
depth: integer;
end;
pX509V3_CTX = pointer;
pX509_REQ = ^X509_REQ;
pX509_REQ_INFO = ^X509_REQ_INFO;
X509_REQ_INFO = record
asn1: pointer;
length: integer;
version: pointer;
subject: pX509_NAME;
pubkey: pointer;
attributes: pointer;
req_kludge: integer;
end;
X509_REQ = record
req_info: pX509_REQ_INFO;
sig_alg: pointer;
signature: pointer;
references: integer;
end;
pX509_EXTENSION = ^X509_EXTENSION;
X509_EXTENSION = record
obj: pASN1_OBJECT;
critical: Smallint;
netscape_hack: Smallint;
value: pASN1_OCTET_STRING;
method: pointer; // struct v3_ext_method *: V3 method to use
ext_val: pointer; // extension value
end;
pSTACK_OFX509_EXTENSION = pointer;
pX509_CRL = pointer;
pX509_SIG = ^X509_SIG;
X509_SIG = record
algor: Pointer; // X509_ALGOR *algor;
digest: pASN1_OCTET_STRING;
end;
pBASIC_CONSTRAINTS = ^BASIC_CONSTRAINTS;
BASIC_CONSTRAINTS = record
ca: integer;
pathlen: pASN1_INTEGER;
end;
pOTHERNAME = ^OTHERNAME;
OTHERNAME = record
type_id: pASN1_OBJECT; //There is a bug in x509v3/x509v3.h ?
value: pointer; //pASN1_TYPE;
end;
pGENERAL_NAME = ^GENERAL_NAME ;
pGENERAL_NAMEDATA = record
case integer of
GEN_EMAIL: (ia5: pASN1_IA5STRING); // also DNS and URI
GEN_IPADD: (ip: pASN1_OCTET_STRING);
GEN_DIRNAME: (dirn: pX509_NAME);
GEN_RID: (rid: pASN1_OBJECT);
GEN_OTHERNAME: (otherName: pOTHERNAME);
GEN_X400: (other: pointer); // also EDI
end;
GENERAL_NAME = record
nametype: integer;
d: pGENERAL_NAMEDATA;
end;
pEVP_PKEY = ^EVP_PKEY;
EVP_PKEY_PKEY = record
case integer of
0: (ptr: PCharacter);
1: (rsa: pRSA); // ^rsa_st
2: (dsa: pDSA); // ^dsa_st
3: (dh: pDH); // ^dh_st
end;
EVP_PKEY = record
ktype: integer;
save_type: integer;
references: integer;
pkey: EVP_PKEY_PKEY;
save_parameters: integer;
attributes: pSTACK_OFX509;
end;
pPKCS7_SIGNER_INFO = pointer;
pSTACK_OFPKCS7_SIGNER_INFO = pointer;
pPKCS7_signed = ^PKCS7_signed;
PKCS7_signed = record
version: pASN1_INTEGER;
md_algs: pointer; // ^STACK_OF(X509_ALGOR)
cert: pointer; // ^STACK_OF(X509)
crl: pointer; // ^STACK_OF(X509_CRL)
signer_info: pSTACK_OFPKCS7_SIGNER_INFO;
contents: pointer; // ^struct pkcs7_st
end;
pPKCS7_signedandenveloped = ^PKCS7_signedandenveloped;
PKCS7_signedandenveloped = record
version: pASN1_INTEGER;
md_algs: pointer; // ^STACK_OF(X509_ALGOR)
cert: pointer; // ^STACK_OF(X509)
crl: pointer; // ^STACK_OF(X509_CRL)
signer_info: pSTACK_OFPKCS7_SIGNER_INFO;
enc_data: pointer; // ^PKCS7_ENC_CONTENT
recipientinfo: pointer; // ^STACK_OF(PKCS7_RECIP_INFO)
end;
pPKCS7 = ^PKCS7;
PKCS7 = record
asn1: PCharacter;
length: integer;
state: integer;
detached: integer;
asn1_type: pointer; // ^ASN1_OBJECT
case integer of
0: (ptr: pASN1_OCTET_STRING);
1: (data: pointer); // ^PKCS7_SIGNED
2: (sign: pPKCS7_signed); // ^PKCS7_SIGNED
3: (enveloped: pointer); // ^PKCS7_ENVELOPE
4: (signed_and_enveloped: pPKCS7_signedandenveloped);
5: (digest: pointer); // ^PKCS7_DIGEST
6: (encrypted: pointer); // ^PKCS7_ENCRYPT
7: (other: pointer); // ^ASN1_TYPE
end;
pPKCS8_Priv_Key_Info = ^PKCS8_Priv_Key_Info;
PKCS8_Priv_Key_Info = record
broken: Integer; // Flag for various broken formats */
version: pASN1_INTEGER;
pkeyalg: Pointer; // X509_ALGOR *pkeyalg;
pkey: Pointer; // ASN1_TYPE *pkey; /* Should be OCTET STRING but some are broken */
attributes: Pointer; // STACK_OF(X509_ATTRIBUTE) *attributes;
end;
pPKCS12 = ^PKCS12;
PKCS12 = record
version: pointer;
mac: pointer;
authsafes: pPKCS7;
end;
function SSLeay: cardinal;
function SSLeay_version(t: integer): PCharacter; cdecl;
procedure OpenSSL_add_all_algorithms;
procedure OpenSSL_add_all_ciphers; cdecl;
procedure OpenSSL_add_all_digests; cdecl;
procedure EVP_cleanup(); cdecl;
function ERR_get_error: cardinal; cdecl;
function ERR_peek_error: cardinal; cdecl;
function ERR_peek_last_error: cardinal; cdecl;
function ERR_error_string(e: cardinal; buf: PCharacter): PCharacter; cdecl;
procedure ERR_clear_error;
procedure ERR_load_crypto_strings;
procedure ERR_free_strings;
// Low level debugable memory management function
function CRYPTO_malloc(length: longint; const f: PCharacter; line: integer): pointer; cdecl;
function CRYPTO_realloc(str: PCharacter; length: longint; const f: PCharacter; line: integer): pointer; cdecl;
function CRYPTO_remalloc(a: pointer; length: longint; const f: PCharacter; line: integer): pointer; cdecl;
procedure CRYPTO_free(str: pointer); cdecl;
// High level memory management function
function OPENSSL_malloc(length: longint): pointer;
function OPENSSL_realloc(address: PCharacter; length: longint): pointer;
function OPENSSL_remalloc(var address: pointer; length: longint): pointer;
procedure OPENSSL_free(address: pointer); cdecl;
// Big number function
function BN_new(): pBIGNUM; cdecl;
procedure BN_init(bn: pBIGNUM); cdecl;
procedure BN_clear(bn: pBIGNUM); cdecl;
procedure BN_free(bn: pBIGNUM); cdecl;
procedure BN_clear_free(bn: pBIGNUM); cdecl;
procedure BN_set_params(mul, high, low, mont: integer); cdecl;
function BN_get_params(which: integer): integer; cdecl;
function BN_options: PCharacter; cdecl;
function BN_CTX_new: pBN_CTX; cdecl;
procedure BN_CTX_init(ctx: pBN_CTX); cdecl;
procedure BN_CTX_start(ctx: pBN_CTX); cdecl;
function BN_CTX_get(ctx: pBN_CTX): pBIGNUM; cdecl;
procedure BN_CTX_end(ctx: pBN_CTX); cdecl;
procedure BN_CTX_free(ctx: pBN_CTX); cdecl;
function BN_MONT_CTX_new: pBN_MONT_CTX; cdecl;
procedure BN_MONT_CTX_init(m_ctx: pBN_MONT_CTX); cdecl;
function BN_MONT_CTX_set(m_ctx: pBN_MONT_CTX;
const modulus: pBIGNUM; ctx: pBN_CTX): integer; cdecl;
function BN_MONT_CTX_copy(_to: pBN_MONT_CTX; from: pBN_MONT_CTX): pBN_MONT_CTX; cdecl;
procedure BN_MONT_CTX_free(m_ctx: pBN_MONT_CTX); cdecl;
function BN_mod_mul_montgomery(r, a, b: pBIGNUM; m_ctx: pBN_MONT_CTX; ctx: pBN_CTX): integer; cdecl;
function BN_from_montgomery(r, a: pBIGNUM; m_ctx: pBN_MONT_CTX; ctx: pBN_CTX): integer; cdecl;
function BN_to_montgomery(r, a: pBIGNUM; m_ctx: pBN_MONT_CTX; ctx: pBN_CTX): integer;
procedure BN_RECP_CTX_init(recp: pBN_RECP_CTX); cdecl;
function BN_RECP_CTX_set(recp: pBN_RECP_CTX; const rdiv: pBIGNUM; ctx: pBN_CTX): integer; cdecl;
function BN_RECP_CTX_new: pBN_RECP_CTX; cdecl;
procedure BN_RECP_CTX_free(recp: pBN_RECP_CTX); cdecl;
function BN_div_recp(dv, rem, a: pBIGNUM; recp: pBN_RECP_CTX; ctx: pBN_CTX): integer; cdecl;
function BN_mod_mul_reciprocal(r, a, b: pBIGNUM; recp: pBN_RECP_CTX; ctx: pBN_CTX): integer; cdecl;
function BN_BLINDING_new(a: pBIGNUM; Ai: pBIGNUM; _mod: pBIGNUM): pBN_BLINDING; cdecl;
function BN_BLINDING_update(b: pBN_BLINDING; ctx: pBN_CTX): pBN_BLINDING; cdecl;
procedure BN_BLINDING_free(b: pBN_BLINDING); cdecl;
function BN_BLINDING_convert(n: pBIGNUM; r: pBN_BLINDING; ctx: pBN_CTX): integer; cdecl;
function BN_BLINDING_invert(n: pBIGNUM; b: pBN_BLINDING; ctx: pBN_CTX): integer; cdecl;
function BN_copy(_to: pBIGNUM; const from: pBIGNUM): pBIGNUM; cdecl;
function BN_dup(const from: pBIGNUM): pBIGNUM; cdecl;
// Helper: convert standard Delphi integer in big-endian integer
function int2bin(n: integer): integer;
function BN_bn2bin(const n: pBIGNUM; _to: pointer): integer; cdecl;
function BN_bin2bn(const _from: pointer; len: integer; ret: pBIGNUM): pBIGNUM; cdecl;
function BN_bn2hex(const n: pBIGNUM): PCharacter; cdecl;
function BN_bn2dec(const n: pBIGNUM): PCharacter; cdecl;
function BN_hex2bn(var n: pBIGNUM; const str: PCharacter): integer; cdecl;
function BN_dec2bn(var n: pBIGNUM; const str: PCharacter): integer; cdecl;
function BN_bn2mpi(const a: pBIGNUM; _to: pointer): integer; cdecl;
function BN_mpi2bn(s: pointer; len: integer; ret: pBIGNUM): pBIGNUM; cdecl;
function BN_print(fp: pBIO; const a: pointer): integer; cdecl;
//function BN_print_fp(FILE *fp, const BIGNUM *a): integer; cdecl;
function BN_zero(n: pBIGNUM): integer;
function BN_one(n: pBIGNUM): integer;
function BN_value_one(): pBIGNUM; cdecl;
function BN_set_word(n: pBIGNUM; w: cardinal): integer; cdecl;
function BN_get_word(n: pBIGNUM): cardinal; cdecl;
function BN_cmp(a: pBIGNUM; b: pBIGNUM): integer; cdecl;
function BN_ucmp(a: pBIGNUM; b: pBIGNUM): integer; cdecl;
//function BN_is_zero(a: pBIGNUM): boolean;
//function BN_is_one(a: pBIGNUM): boolean;
//function BN_is_word(a: pBIGNUM; w: BN_ULONG): boolean;
//function BN_is_odd(a: pBIGNUM): boolean;
function BN_num_bytes(const a: pBIGNUM): integer;
function BN_num_bits(const a: pBIGNUM): integer; cdecl;
function BN_num_bits_word(w: BN_ULONG): integer; cdecl;
function BN_add(r: pBIGNUM; const a, b: pBIGNUM): integer; cdecl;
function BN_sub(r: pBIGNUM; const a, b: pBIGNUM): integer; cdecl;
function BN_uadd(r: pBIGNUM; const a, b: pBIGNUM): integer; cdecl;
function BN_usub(r: pBIGNUM; const a, b: pBIGNUM): integer; cdecl;
function BN_mul(r: pBIGNUM; a: pBIGNUM; b: pBIGNUM; ctx: pBN_CTX): integer; cdecl;
function BN_sqr(r: pBIGNUM; a: pBIGNUM; ctx: pBN_CTX): integer; cdecl;
function BN_div(dv: pBIGNUM; rem: pBIGNUM; const a, d: pBIGNUM; ctx: pBN_CTX): integer; cdecl;
// BN_mod redefined as BN_div in some DLL version
function BN_mod(rem: pBIGNUM; const a, m: pBIGNUM; ctx: pBN_CTX): integer;
function BN_exp(r: pBIGNUM; a: pBIGNUM; p: pBIGNUM; ctx: pBN_CTX): integer; cdecl;
function BN_mod_exp(r, a: pBIGNUM; const p, m: pBIGNUM; ctx: pBN_CTX): integer; cdecl;
function BN_gcd(r: pBIGNUM; a: pBIGNUM; b: pBIGNUM; ctx: pBN_CTX): integer; cdecl;
// BN_nnmod requires OpenSSL >= 0.9.7
function BN_nnmod(rem: pBIGNUM; const a: pBIGNUM; const m: pBIGNUM; ctx: pBN_CTX): integer; cdecl;
// BN_mod_add requires OpenSSL >= 0.9.7
function BN_mod_add(r: pBIGNUM; a: pBIGNUM; b: pBIGNUM; const m: pBIGNUM;
ctx: pBN_CTX): integer; cdecl;
// BN_mod_sub requires OpenSSL >= 0.9.7
function BN_mod_sub(r: pBIGNUM; a: pBIGNUM; b: pBIGNUM; const m: pBIGNUM;
ctx: pBN_CTX): integer; cdecl;
// BN_mod_mul requires OpenSSL >= 0.9.7
function BN_mod_mul(ret, a, b: pBIGNUM; const m: pBIGNUM; ctx: pBN_CTX): integer; cdecl;
// BN_mod_sqr requires OpenSSL >= 0.9.7
function BN_mod_sqr(r: pBIGNUM; a: pBIGNUM; const m: pBIGNUM; ctx: pBN_CTX): integer; cdecl;
function BN_reciprocal(r, m: pBIGNUM; ctx: pBN_CTX): integer; cdecl;
function BN_mod_exp2_mont(r, a1, p1, a2, p2, m: pBIGNUM;
ctx: pBN_CTX; m_ctx: pBN_MONT_CTX): integer; cdecl;
function BN_mod_exp_mont(r, a: pBIGNUM; const p, m: pBIGNUM;
ctx: pBN_CTX; m_ctx: pBN_MONT_CTX): integer; cdecl;
function BN_mod_exp_mont_word(r: pBIGNUM; a: BN_ULONG; const p, m: pBIGNUM;
ctx: pBN_CTX; m_ctx: pBN_MONT_CTX): integer; cdecl;
function BN_mod_exp_simple(r, a, p, m: pBIGNUM; ctx: pBN_CTX): integer; cdecl;
function BN_mod_exp_recp(r: pBIGNUM; const a, p, m: pBIGNUM; ctx: pBN_CTX): integer; cdecl;
function BN_mod_inverse(ret, a: pBIGNUM; const n: pBIGNUM; ctx: pBN_CTX): pBIGNUM; cdecl;
function BN_add_word(a: pBIGNUM; w: BN_ULONG): integer; cdecl; // Adds w to a ("a+=w").
function BN_sub_word(a: pBIGNUM; w: BN_ULONG): integer; cdecl; // Subtracts w from a ("a-=w").
function BN_mul_word(a: pBIGNUM; w: BN_ULONG): integer; cdecl; // Multiplies a and w ("a*=b").
function BN_div_word(a: pBIGNUM; w: BN_ULONG): BN_ULONG; cdecl; // Divides a by w ("a/=w") and returns the remainder.
function BN_mod_word(const a: pBIGNUM; w: BN_ULONG): BN_ULONG; cdecl; // Returns the remainder of a divided by w ("a%m").
function bn_mul_words(rp, ap: pBN_ULONG; num: integer; w: BN_ULONG): BN_ULONG; cdecl;
function bn_mul_add_words(rp, ap: pBN_ULONG; num: integer; w: BN_ULONG): BN_ULONG; cdecl;
procedure bn_sqr_words(rp, ap: pBN_ULONG; num: integer); cdecl;
function bn_div_words(h, l, d: BN_ULONG): BN_ULONG; cdecl;
function bn_add_words(rp, ap, bp: pBN_ULONG; num: integer): BN_ULONG; cdecl;
function bn_sub_words(rp, ap, bp: pBN_ULONG; num: integer): BN_ULONG; cdecl;
function bn_expand2(a: pBIGNUM; n: integer): pBIGNUM; cdecl;
function BN_set_bit(a: pBIGNUM; n: integer): integer; cdecl;
function BN_clear_bit(a: pBIGNUM; n: integer): integer; cdecl;
function BN_is_bit_set(const a: pBIGNUM; n: integer): integer; cdecl;
function BN_mask_bits(a: pBIGNUM; n: integer): integer; cdecl;
function BN_lshift(r: pBIGNUM; const a: pBIGNUM; n: integer): integer; cdecl;
function BN_lshift1(r: pBIGNUM; a: pBIGNUM): integer; cdecl;
function BN_rshift(r: pBIGNUM; const a: pBIGNUM; n: integer): integer; cdecl;
function BN_rshift1(r: pBIGNUM; a: pBIGNUM): integer; cdecl;
function BN_generate_prime(ret: pBIGNUM; num, safe: integer; add, rem: pBIGNUM;
progress: TProgressCallbackFunction; cb_arg: pointer): pBIGNUM; cdecl;
function BN_is_prime(const a: pBIGNUM; checks: integer;
progress: TProgressCallbackFunction; ctx: pBN_CTX; cb_arg: pointer): integer; cdecl;
function BN_is_prime_fasttest(const a: pBIGNUM; checks: integer;
progress: TProgressCallbackFunction; ctx: pBN_CTX; cb_arg: pointer;
do_trial_division: integer): integer; cdecl;
function BN_rand(rnd: pBIGNUM; bits, top, bottom: integer): integer; cdecl;
function BN_pseudo_rand(rnd: pBIGNUM; bits, top, bottom: integer): integer; cdecl;
function BN_rand_range(rnd, range: pBIGNUM): integer; cdecl;
// BN_pseudo_rand_range requires OpenSSL >= 0.9.6c
function BN_pseudo_rand_range(rnd, range: pBIGNUM): integer; cdecl;
function BN_bntest_rand(rnd: pBIGNUM; bits, top, bottom: integer): integer; cdecl;
function BN_to_ASN1_INTEGER(bn: pBIGNUM; ai: pASN1_INTEGER): pASN1_INTEGER; cdecl;
function BN_to_ASN1_ENUMERATED(bn: pBIGNUM; ai: pASN1_ENUMERATED): pASN1_ENUMERATED; cdecl;
// ASN.1 functions
function ASN1_IA5STRING_new: pASN1_IA5STRING; cdecl;
procedure ASN1_INTEGER_free(x: pASN1_IA5STRING); cdecl;
function ASN1_INTEGER_get(a: pointer): longint; cdecl;
procedure ASN1_STRING_set_default_mask(mask: cardinal); cdecl;
function ASN1_STRING_get_default_mask: cardinal; cdecl;
function ASN1_TIME_print(fp: pBIO; a: pASN1_TIME): integer; cdecl;
// OBJ functions
function OBJ_obj2nid(asn1_object: pointer): integer; cdecl;
function OBJ_txt2nid(s: PCharacter): integer; cdecl;
function OBJ_txt2obj(s: PCharacter; no_name: integer): integer; cdecl;
// safestack functions
function sk_new_null: pointer; cdecl;
procedure sk_free(st: pointer); cdecl;
function sk_push(st: pointer; val: pointer): integer; cdecl;
function sk_num(st: pointer): integer; cdecl;
function sk_value(st: pointer; i: integer): pointer; cdecl;
// BIO functions
function BIO_new(_type: pBIO_METHOD): pBIO; cdecl;
function BIO_new_file(const filename: PCharacter; const mode: PCharacter): pBIO; cdecl;
function BIO_set(a: pBIO; _type: pBIO_METHOD): integer; cdecl;
function BIO_free(a: pBIO): integer; cdecl;
procedure BIO_vfree(a: pBIO); cdecl;
procedure BIO_free_all(a: pBIO); cdecl;
function BIO_push(b: pBIO; append: pBIO): pBIO; cdecl;
function BIO_pop(b: pBIO): pBIO; cdecl;
function BIO_ctrl(bp: pBIO; cmd: Integer; larg: Longint;
parg: Pointer): Longint; cdecl;
function BIO_read(b: pBIO; buf: pointer; len: integer): integer; cdecl;
function BIO_gets(b: pBIO; buf: PCharacter; size: integer): integer; cdecl;
function BIO_write(b: pBIO; const buf: pointer; len: integer): integer; cdecl;
function BIO_puts(b: pBIO; const buf: PCharacter): integer; cdecl;
function BIO_flush(b: pBIO): integer;
function BIO_reset(bp: pBIO): integer;
function BIO_eof(bp: pBIO): integer;
function BIO_set_close(bp: pBIO; c: integer): integer;
function BIO_get_close(bp: pBIO): integer;
function BIO_pending(bp: pBIO): integer;
function BIO_wpending(bp: pBIO): integer;
function BIO_read_filename(bp: pBIO; filename: PCharacter): integer;
function BIO_write_filename(bp: pBIO; filename: PCharacter): integer;
function BIO_append_filename(bp: pBIO; filename: PCharacter): integer;
function BIO_rw_filename(bp: pBIO; filename: PCharacter): integer;
function BIO_s_mem: pBIO_METHOD; cdecl;
function BIO_f_base64: pBIO_METHOD; cdecl;
procedure BIO_set_mem_eof_return(b: pBIO; v: integer); cdecl;
function BIO_get_mem_data(b: pBIO; var pp: PCharacter): integer; cdecl; // long ??
procedure BIO_set_mem_buf(b: pBIO; bm: pBUF_MEM; c: integer); cdecl;
procedure BIO_get_mem_ptr(b: pBIO; var pp: pBUF_MEM); cdecl;
function BIO_new_mem_buf(buf: pointer; len: integer): pBIO; cdecl;
function BIO_s_file: pBIO_METHOD; cdecl;
function BIO_get_md_ctx(bp: pBIO; mdcp: Pointer): Longint;
// Internal to DER and DER to internal conversion functions
function i2d_ASN1_TIME(a: pASN1_TIME; pp: PCharacter): integer; cdecl;
function d2i_ASN1_TIME(var a: pASN1_TIME; pp: PCharacter; length: longint): pASN1_TIME; cdecl;
function d2i_X509_REQ_bio(bp: pBIO; req: pX509_REQ): pX509_REQ; cdecl;
function i2d_X509_REQ_bio(bp: pBIO; req: pX509_REQ): integer; cdecl;
function d2i_X509_bio(bp: pBIO; x509: pX509): pX509; cdecl;
function i2d_X509_bio(bp: pBIO; x509: pX509): integer; cdecl;
function d2i_PrivateKey_bio(bp: pBIO; var a: pEVP_PKEY): pEVP_PKEY; cdecl;
function i2d_PrivateKey_bio(bp: pBIO; pkey: pEVP_PKEY): integer; cdecl;
function d2i_PUBKEY_bio(bp: pBIO; var a: pEVP_PKEY): pEVP_PKEY; cdecl;
function i2d_PUBKEY_bio(bp: pBIO; pkey: pEVP_PKEY): integer; cdecl;
function d2i_PKCS12_bio(bp: pBIO; pkcs12: pPKCS12): pPKCS12; cdecl;
function i2d_PKCS12_bio(bp: pBIO; pkcs12: pPKCS12): integer; cdecl;
function d2i_PKCS7(var a: pPKCS7; pp: pointer; length: longint): pPKCS7; cdecl;
function d2i_PKCS7_bio(bp: pBIO; p7: pPKCS7): pPKCS7; cdecl;
function i2d_PKCS7_bio(bp: pBIO; p7: pPKCS7): integer; cdecl;
function d2i_PKCS8_bio(bp: pBIO; p8: pX509_SIG): pX509_SIG; cdecl;
function d2i_PKCS8_PRIV_KEY_INFO(var a: pPKCS8_Priv_Key_Info;
pp: PCharacter; Length: LongInt): pPKCS8_Priv_Key_Info; cdecl;
function d2i_DSAPrivateKey_bio(bp: pBIO; dsa: pDSA): pDSA; cdecl;
function i2d_DSAPrivateKey_bio(bp: pBIO; dsa: pDSA): integer; cdecl;
function d2i_RSAPrivateKey_bio(bp: pBIO; rsa: pRSA): pRSA; cdecl;
function i2d_RSAPrivateKey_bio(bp: pBIO; rsa: pRSA): integer; cdecl;
// Internal to ASN.1 and ASN.1 to internal conversion functions
function i2a_ASN1_INTEGER(bp: pBIO; a: pASN1_INTEGER): integer; cdecl;
function a2i_ASN1_INTEGER(bp: pBIO; bs: pASN1_INTEGER; buf: PCharacter;
size: integer): integer; cdecl;
// Hash functions
function EVP_md_null: pEVP_MD; cdecl;
function EVP_md2: pEVP_MD; cdecl;
function EVP_md5: pEVP_MD; cdecl;
function EVP_sha: pEVP_MD; cdecl;
function EVP_sha1: pEVP_MD; cdecl;
function EVP_sha256: pEVP_MD; cdecl;
function EVP_sha512: pEVP_MD; cdecl;
function EVP_dss: pEVP_MD; cdecl;
function EVP_dss1: pEVP_MD; cdecl;
function EVP_mdc2: pEVP_MD; cdecl;
function EVP_ripemd160: pEVP_MD; cdecl;
function EVP_get_digestbyname(const name: PCharacter): pEVP_MD; cdecl;
procedure EVP_DigestInit(ctx: pEVP_MD_CTX; const _type: pEVP_MD); cdecl;
procedure EVP_DigestUpdate(ctx: pEVP_MD_CTX; const d: Pointer; cnt: cardinal); cdecl;
procedure EVP_DigestFinal(ctx: pEVP_MD_CTX; md: PCharacter; var s: cardinal); cdecl;
procedure EVP_SignInit(ctx: pEVP_MD_CTX; const _type: pEVP_MD);
procedure EVP_SignUpdate(ctx: pEVP_MD_CTX; const d: Pointer; cnt: cardinal);
function EVP_SignFinal(ctx: pEVP_MD_CTX; sig: pointer; var s: cardinal;
key: pEVP_PKEY): integer; cdecl;