delphi 华为云AKSK签名
难点主要是用的D7开发的,签名算法要求是rsa256 。网上找资料后是调用libeay32.dll 函数来实现签名。
从网上找到libeay32.pas
1 (****************************************************************************** 2 Delphi import unit for OpenSSL libeay, version 0.7m, 2010-11-05 3 4 For OpenSSL libeay32.dll version 0.9.6b, DLL compiled by GnuWin32. 5 Tested with Borland Delphi 6, 7 Personal 6 7 Copyright (C) 2002-2010, Marco Ferrante. 8 2002-2006, CSITA - Universit?di Genova (IT). 9 http://www.csita.unige.it/. 10 2007-2009, DISI - Universit?di Genova (IT). 11 http://www.disi.unige.it/. 12 2010, CSITA - Universit?di Genova (IT). 13 http://www.csita.unige.it/. 14 Thanks to: 15 - Michal Hlavac (Slovakia) 16 - Risto Tamme (Estonia) 17 - Simon Sun (probably USA) 18 19 - Luis Carrasco, Bambu Code (Mexico) 20 for contributes and fix 21 22 A small part of this work is inspired on MySSL, interface to OpenSSL for 23 Delphi written by Jan Tomasek. 24 25 This product is related to cryptographic software written by Eric 26 Young (eay@cryptsoft.com). This product is related to software written 27 by Tim Hudson (tjh@cryptsoft.com) 28 29 == Changelog ======================================================= 30 31 Version 0.7n, 2010-12-27 32 - typo corrected 33 34 Version 0.7m, 2010-11-05 35 - added support for PCKS#8 functions (contributed by Luis Carrasco - Bambu Code, Mexico), 36 - redefinition of PChar as PCharacter to handle PChar and PAnsiChar types 37 - basic AES support 38 39 Version 0.7h, 2009-02-25 40 - added X509_sign(), 41 42 Version 0.7g, 2007-02-20 43 - Bugfix: PKCS12_parse function uses a by-reference parameter 44 - Bugfix: BIO_get_mem_data(). Thanks to Andrei 45 - Removed redundant declarations 46 47 Version 0.7f, 2007-02-20 48 - Bugfix: PEM_read_* function uses a by-reference parameter 49 50 Version 0.7e, 2007-02-11 51 - Bugfix 52 - Replace BN_mod import with a wrapper to BN_div, see man BN_mul(3) 53 54 Version 0.7d, 2006-12-15 55 - Typos 56 - Removed EVP_MD_size and EVP_MD_CTX_size: these functions are not defined in 57 DLL and handle their parameter in a non-opaque way. 58 59 Version 0.7c, 2006-11-14 60 - Add BIGNUM functions 61 - Defined RSA record 62 - Add missing EVP_VerifyFinal 63 64 Version 0.7b, 2006-11-05 65 - Between 0.9.6h and 0.9.7, OpenSSL split OpenSSL_add_all_algorithms 66 in two new functions. Some versions of libeay32.dll use old name, 67 some use new one. See http://www.openssl.org/news/changelog.html 68 In this unit, OpenSSL_add_all_algorithms is now a wrapper that 69 dynamically loads appropriate function from DLL. 70 71 Version 0.7a, 2006-09-14 72 - Bug fixes 73 - Defined wrapper for OpenSSL memory management function 74 75 == License ========================================================= 76 Redistribution and use in source and binary forms, with or without 77 modification, are permitted provided that the following conditions 78 are met: 79 80 1. Redistributions of source code must retain the above copyright 81 notice, this list of conditions and the following disclaimer. 82 83 2. Redistributions in binary form must reproduce the above copyright 84 notice, this list of conditions and the following disclaimer in 85 the documentation and/or other materials provided with the 86 distribution. 87 88 3. All advertising materials mentioning features or use of this 89 software must display the following acknowledgment: 90 "This product includes software developed by CSITA - University 91 of Genoa (Italy) (http://www.unige.it/)" 92 93 4. Redistributions of any form whatsoever must retain the following 94 acknowledgment: 95 "This product includes software developed by the University 96 of Genoa (Italy) (http://www.unige.it/) and its contributors" 97 98 THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 99 EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 100 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 101 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 102 ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 103 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 104 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 105 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 106 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 107 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 108 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 109 OF THE POSSIBILITY OF SUCH DAMAGE. 110 ==================================================================== 111 112 ******************************************************************************) 113 unit libeay32; 114 115 interface 116 117 const 118 _SSLEAY_VERSION = 0; 119 _SSLEAY_CFLAGS = 2; 120 _SSLEAY_BUILT_ON = 3; 121 _SSLEAY_PLATFORM = 4; 122 123 // PADDING constants 124 RSA_PKCS1_PADDING = 1; 125 RSA_SSLV23_PADDING = 2; 126 RSA_NO_PADDING = 3; 127 RSA_PKCS1_OAEP_PADDING = 4; 128 129 // ASN1 type constants 130 NID_undef = 0; 131 NID_rsaEncryption = 6; 132 NID_pkcs7_signed = 22; 133 NID_pkcs7_signedAndEnveloped = 24; 134 NID_basic_constraints = 87; 135 NID_subject_alt_name = 85; 136 137 V_ASN1_INTEGER = $02; 138 V_ASN1_ENUMERATED = 10; 139 V_ASN1_NEG_INTEGER = $102; 140 V_ASN1_UTCTIME = 23; 141 V_ASN1_GENERALIZEDTIME = 24; 142 V_ASN1_CONTEXT_SPECIFIC = $80; 143 144 B_ASN1_NUMERICSTRING = $0001; 145 B_ASN1_PRINTABLESTRING = $0002; 146 B_ASN1_T61STRING = $0004; 147 B_ASN1_TELETEXSTRING = $0008; 148 B_ASN1_VIDEOTEXSTRING = $0008; 149 B_ASN1_IA5STRING = $0010; 150 B_ASN1_GRAPHICSTRING = $0020; 151 B_ASN1_ISO64STRING = $0040; 152 B_ASN1_VISIBLESTRING = $0040; 153 B_ASN1_GENERALSTRING = $0080; 154 B_ASN1_UNIVERSALSTRING = $0100; 155 B_ASN1_OCTET_STRING = $0200; 156 B_ASN1_BIT_STRING = $0400; 157 B_ASN1_BMPSTRING = $0800; 158 B_ASN1_UNKNOWN = $1000; 159 B_ASN1_UTF8STRING = $2000; 160 161 MBSTRING_FLAG = $1000; 162 MBSTRING_ASC = MBSTRING_FLAG or 1; 163 MBSTRING_BMP = MBSTRING_FLAG or 2; 164 MBSTRING_UNIV = MBSTRING_FLAG or 3; 165 MBSTRING_UTF8 = MBSTRING_FLAG or 4; 166 167 // These are the 'types' of BIOs 168 BIO_TYPE_NONE = $0000; 169 BIO_TYPE_MEM = $0001 or $0400; 170 BIO_TYPE_FILE = $0002 or $0400; 171 172 BIO_TYPE_FD = $0004 or $0400 or $0100; 173 BIO_TYPE_SOCKET = $0005 or $0400 or $0100; 174 BIO_TYPE_NULL = $0006 or $0400; 175 BIO_TYPE_SSL = $0007 or $0200; 176 BIO_TYPE_MD = $0008 or $0200; // passive filter 177 BIO_TYPE_BUFFER = $0009 or $0200; // filter 178 BIO_TYPE_CIPHER = $00010 or $0200; // filter 179 BIO_TYPE_BASE64 = $00011 or $0200; // filter 180 BIO_TYPE_CONNECT = $00012 or $0400 or $0100; // socket - connect 181 BIO_TYPE_ACCEPT = $00013 or $0400 or $0100; // socket for accept 182 BIO_TYPE_PROXY_CLIENT = $00014 or $0200; // client proxy BIO 183 BIO_TYPE_PROXY_SERVER = $00015 or $0200; // server proxy BIO 184 BIO_TYPE_NBIO_TEST = $00016 or $0200; // server proxy BIO 185 BIO_TYPE_NULL_FILTER = $00017 or $0200; 186 BIO_TYPE_BER = $00018 or $0200; // BER -> bin filter 187 BIO_TYPE_BIO = $00019 or $0400; // (half a; BIO pair 188 BIO_TYPE_LINEBUFFER = $00020 or $0200; // filter 189 190 BIO_TYPE_DESCRIPTOR = $0100; // socket, fd, connect or accept 191 BIO_TYPE_FILTER= $0200; 192 BIO_TYPE_SOURCE_SINK = $0400; 193 194 // BIO ops constants 195 // BIO_FILENAME_READ|BIO_CLOSE to open or close on free. 196 // BIO_set_fp(in,stdin,BIO_NOCLOSE); 197 BIO_NOCLOSE = $00; 198 BIO_CLOSE = $01; 199 BIO_FP_READ = $02; 200 BIO_FP_WRITE = $04; 201 BIO_FP_APPEND = $08; 202 BIO_FP_TEXT = $10; 203 204 BIO_C_SET_FILENAME = 108; 205 BIO_CTRL_RESET = 1; // opt - rewind/zero etc 206 BIO_CTRL_EOF = 2; // opt - are we at the eof 207 BIO_CTRL_INFO = 3; // opt - extra tit-bits 208 BIO_CTRL_SET = 4; // man - set the 'IO' type 209 BIO_CTRL_GET = 5; // man - get the 'IO' type 210 BIO_CTRL_PUSH = 6; // opt - internal, used to signify change 211 BIO_CTRL_POP = 7; // opt - internal, used to signify change 212 BIO_CTRL_GET_CLOSE = 8; // man - set the 'close' on free 213 BIO_CTRL_SET_CLOSE = 9; // man - set the 'close' on free 214 BIO_CTRL_PENDING = 10; // opt - is their more data buffered 215 BIO_CTRL_FLUSH = 11; // opt - 'flush' buffered output 216 BIO_CTRL_DUP = 12; // man - extra stuff for 'duped' BIO 217 BIO_CTRL_WPENDING = 13; // opt - number of bytes still to write 218 219 BIO_C_GET_MD_CTX = 120; 220 221 BN_CTX_NUM = 16; 222 BN_CTX_NUM_POS = 12; 223 224 // RSA key exponent 225 RSA_3: longint = $3; 226 RSA_F4: longint = $10001; 227 228 FORMAT_UNDEF = 0; 229 FORMAT_ASN1 = 1; 230 FORMAT_TEXT = 2; 231 FORMAT_PEM = 3; 232 FORMAT_NETSCAPE = 4; 233 FORMAT_PKCS12 = 5; 234 FORMAT_SMIME = 6; 235 FORMAT_X509 = 509; // Not defined in original libeay 236 237 PKCS7_TEXT = $001; 238 PKCS7_NOCERTS = $002; 239 PKCS7_NOSIGS = $004; 240 PKCS7_NOCHAIN = $008; 241 PKCS7_NOINTERN = $010; 242 PKCS7_NOVERIFY = $020; 243 PKCS7_DETACHED = $040; 244 PKCS7_BINARY = $080; 245 PKCS7_NOATTR = $100; 246 PKCS7_NOSMIMECAP = $200; 247 248 X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT = 18; 249 250 SHA_DIGEST_LENGTH = 20; 251 252 //EVP_MAX_MD_SIZE = 16+20; // The SSLv3 md5+sha1 type 253 EVP_MAX_MD_SIZE = 64;//longest known is SHA512 254 EVP_PKEY_RSA = NID_rsaEncryption; 255 256 EXFLAG_KUSAGE = $02; 257 EXFLAG_BCONS = $1; 258 EXFLAG_CA = $10; 259 EXFLAG_SS = $20; 260 EXFLAG_V1 = $40; 261 KU_KEY_CERT_SIGN = $0004; 262 V1_ROOT = EXFLAG_V1 or EXFLAG_SS; 263 264 GEN_OTHERNAME = 0 or V_ASN1_CONTEXT_SPECIFIC; 265 GEN_EMAIL = 1 or V_ASN1_CONTEXT_SPECIFIC; 266 GEN_DNS = 2 or V_ASN1_CONTEXT_SPECIFIC; 267 GEN_X400 = 3 or V_ASN1_CONTEXT_SPECIFIC; 268 GEN_DIRNAME = 4 or V_ASN1_CONTEXT_SPECIFIC; 269 GEN_EDIPARTY = 5 or V_ASN1_CONTEXT_SPECIFIC; 270 GEN_URI = 6 or V_ASN1_CONTEXT_SPECIFIC; 271 GEN_IPADD = 7 or V_ASN1_CONTEXT_SPECIFIC; 272 GEN_RID = 8 or V_ASN1_CONTEXT_SPECIFIC; 273 274 275 AES_MAXNR = 14; 276 277 HMAC_MAX_MD_CBLOCK = 128; //* largest known is SHA512 */ 278 279 type 280 // Check the correct "Char" type to use according to the Delphi Version 281 {$IF CompilerVersion >= 20} //Delphi 2009 - 20 282 PCharacter = PAnsiChar; 283 {$ELSE} 284 PCharacter = PChar; 285 {$IFEND} 286 287 pSTACK = pointer; 288 289 // ASN1 types 290 pASN1_OBJECT = pointer; 291 pASN1_STRING = ^ASN1_STRING; 292 ASN1_STRING = record 293 length: integer; 294 asn1_type: integer; 295 data: pointer; 296 flags: longint; 297 end; 298 pASN1_IA5STRING = pASN1_STRING; 299 pASN1_INTEGER = pASN1_STRING; 300 pASN1_ENUMERATED = pASN1_STRING; 301 pASN1_TIME = pASN1_STRING; 302 pASN1_OCTET_STRING = pASN1_STRING; 303 304 pBN_ULONG = ^BN_ULONG; 305 BN_ULONG = array of byte; // system dependent, consider it as a opaque pointer 306 pBIGNUM = ^BIGNUM; 307 BIGNUM = record 308 d: pBN_ULONG; // Pointer to an array of 'BN_BITS2' bit chunks. 309 top: integer; // Index of last used d +1. 310 // The next are internal book keeping for bn_expand. 311 dmax: integer; // Size of the d array. 312 neg: integer; // one if the number is negative 313 flags: integer; 314 end; 315 316 pBN_CTX = ^BN_CTX; 317 BN_CTX = record 318 tos: integer; 319 bn: array [0..BN_CTX_NUM-1] of BIGNUM; 320 flags: integer; 321 depth: integer; 322 pos: array [0..BN_CTX_NUM_POS-1] of integer; 323 too_many: integer; 324 end; 325 326 pBN_BLINDING = ^BN_BLINDING; 327 BN_BLINDING = record 328 init: integer; 329 A: pBIGNUM; 330 Ai: pBIGNUM; 331 _mod: pBIGNUM; // just a reference (original name: mod) 332 end; 333 334 // Used for montgomery multiplication 335 pBN_MONT_CTX = ^BN_MONT_CTX; 336 BN_MONT_CTX = record 337 ri: integer; // number of bits in R 338 RR: BIGNUM; // used to convert to montgomery form 339 N: BIGNUM; // The modulus 340 Ni: BIGNUM; // R*(1/R mod N) - N*Ni = 1 341 // (Ni is only stored for bignum algorithm) 342 n0: BN_ULONG; // least significant word of Ni 343 flags: integer; 344 end; 345 346 // Used for reciprocal division/mod functions 347 // It cannot be shared between threads 348 pBN_RECP_CTX = ^BN_RECP_CTX; 349 BN_RECP_CTX = record 350 N: BIGNUM; // the divisor 351 Nr: BIGNUM; // the reciprocal 352 num_bits: integer; 353 shift: integer; 354 flags: integer; 355 end; 356 357 pX509_STORE_CTX = pointer; 358 359 // Password ask callback for I/O function prototipe 360 // It must fill buffer with password and return password length 361 TPWCallbackFunction = function(buffer: PCharacter; length: integer; 362 verify: integer; data: pointer): integer; cdecl; 363 // Progress callback function prototipe 364 TProgressCallbackFunction = procedure(status: integer; progress: integer; 365 data: pointer); 366 // Certificate verification callback 367 TCertificateVerifyFunction = function(ok: integer; 368 ctx: pX509_STORE_CTX): integer; cdecl; 369 370 pBIO = pointer; 371 pBIO_METHOD = pointer; 372 //pBUF_MEM = pointer; 373 374 //2016/02/19 15:26 375 buf_mem_st = record 376 length : Integer;//TIdC_INT; // current number of bytes 377 data : PAnsiChar; 378 max: Integer;//TIdC_INT; // size of buffer 379 end; 380 BUF_MEM = buf_mem_st; 381 PBUF_MEM = ^BUF_MEM; 382 PPBUF_MEM = ^PBUF_MEM; 383 //============================ 2016/02/19 15:26 384 385 386 387 des_cblock = array [0..7] of byte; 388 MD2_CTX = record 389 num: integer; 390 data: array [0..15] of byte; 391 cksm: array [0..15] of cardinal; 392 state: array [0..15] of cardinal; 393 end; 394 MD4_CTX = record 395 A, B, C, D: cardinal; 396 Nl, Nh: cardinal; 397 data: array [0..15] of cardinal; 398 num: integer; 399 end; 400 MD5_CTX = record 401 A, B, C, D: cardinal; 402 Nl, Nh: cardinal; 403 data: array [0..15] of cardinal; 404 num: integer; 405 end; 406 RIPEMD160_CTX = record 407 A, B, C, D, E: cardinal; 408 Nl, Nh: cardinal; 409 data: array [0..15] of cardinal; 410 num: integer; 411 end; 412 SHA_CTX = record 413 h0, h1, h2, h3, h4: cardinal; 414 Nl, Nh: cardinal; 415 data: array [0..16] of cardinal; 416 num: integer; 417 end; 418 MDC2_CTX = record 419 num: integer; 420 data: array [0..7] of byte; 421 h, hh: des_cblock; 422 pad_type: integer; // either 1 or 2, default 1 423 end; 424 425 CRYPTO_EX_DATA = record 426 sk: pointer; 427 dummy: integer; 428 end; 429 430 431 432 AES_KEY = record 433 rd_key: array[0..(4 *(AES_MAXNR + 1)-1)] of Cardinal;//TIdC_UINT; 434 rounds : Cardinal;//TIdC_INT; 435 end; 436 pAES_KEY = ^AES_KEY;//pointer; 437 438 pRSA = pointer; 439 pRSA_METHOD = pointer; 440 RSA = record 441 // The first parameter is used to pickup errors where 442 // this is passed instead of aEVP_PKEY, it is set to 0 443 pad: integer; 444 version: integer; 445 meth: pRSA_METHOD; 446 n: pBIGNUM; 447 e: pBIGNUM; 448 d: pBIGNUM; 449 p: pBIGNUM; 450 q: pBIGNUM; 451 dmp1: pBIGNUM; 452 dmq1: pBIGNUM; 453 iqmp: pBIGNUM; 454 // be careful using this if the RSA structure is shared 455 ex_data: CRYPTO_EX_DATA; 456 references: integer; 457 flags: integer; 458 // Used to cache montgomery values 459 _method_mod_n: pBN_MONT_CTX; 460 _method_mod_p: pBN_MONT_CTX; 461 _method_mod_q: pBN_MONT_CTX; 462 // all BIGNUM values are actually in the following data, if it is not 463 // NULL 464 bignum_data: ^byte; 465 blinding: ^BN_BLINDING; 466 end; 467 468 pDSA = ^DSA; 469 DSA = record 470 // This first variable is used to pick up errors where 471 // a DSA is passed instead of of a EVP_PKEY 472 pad: integer; 473 version: integer; 474 write_params: integer; 475 p: pointer; 476 q: pointer; // = 20 477 g: pointer; 478 pub_key: pointer; // y public key 479 priv_key: pointer; // x private key 480 kinv: pointer; // Signing pre-calc 481 r: pointer; // Signing pre-calc 482 flags: integer; 483 // Normally used to cache montgomery values 484 method_mont_p: PCharacter; 485 references: integer; 486 ex_data: record 487 sk: pointer; 488 dummy: integer; 489 end; 490 meth: pointer; 491 end; 492 493 pDH = pointer; 494 495 pEC_KEY = pointer; 496 497 pEVP_CIPHER = pointer; 498 499 pEVP_MD = ^EVP_MD; 500 EVP_MD = record 501 _type: integer; 502 pkey_type: integer; 503 md_size: integer; 504 init: pointer; 505 update: pointer; 506 final: pointer; 507 sign: pointer; 508 verify: pointer; 509 required_pkey_type: array [0..4] of integer; 510 block_size: integer; 511 ctx_size: integer; 512 end; 513 514 // Superfluo? No, in EVP_MD ci sono le dimensioni del risultato 515 pEVP_MD_CTX = ^EVP_MD_CTX; 516 EVP_MD_CTX = record 517 digest: pEVP_MD; 518 case integer of 519 0: (base: array [0..3] of byte); 520 1: (md2: MD2_CTX); 521 8: (md4: MD4_CTX); 522 2: (md5: MD5_CTX); 523 16: (ripemd160: RIPEMD160_CTX); 524 4: (sha: SHA_CTX); 525 32: (mdc2: MDC2_CTX); 526 end; 527 528 pHMAC_CTX=^HMAC_CTX; 529 HMAC_CTX = record 530 md : PEVP_MD; 531 md_ctx : EVP_MD_CTX; 532 i_ctx : EVP_MD_CTX; 533 o_ctx : EVP_MD_CTX; 534 key_length : Cardinal; 535 key : array[0..(HMAC_MAX_MD_CBLOCK - 1)] of byte; 536 end; 537 538 539 540 pX509_NAME_ENTRY = ^X509_NAME_ENTRY; 541 X509_NAME_ENTRY = record 542 obj: pASN1_OBJECT; 543 value: pASN1_STRING; 544 _set: integer; 545 size: integer; // temp variable 546 end; 547 548 pX509_NAME = ^X509_NAME; 549 pDN = ^X509_NAME; 550 X509_NAME = record 551 entries: pointer; 552 modified: integer; 553 bytes: pointer; 554 hash: cardinal; 555 end; 556 557 pX509_VAL = ^X509_VAL; 558 X509_VAL = record 559 notBefore: pASN1_TIME; 560 notAfter: pASN1_TIME; 561 end; 562 563 pX509_CINF = ^X509_CINF; 564 X509_CINF = record 565 version: pointer; 566 serialNumber: pointer; 567 signature: pointer; 568 issuer: pointer; 569 validity: pX509_VAL; 570 subject: pointer; 571 key: pointer; 572 issuerUID: pointer; 573 subjectUID: pointer; 574 extensions: pointer; 575 end; 576 577 pX509 = ^X509; 578 X509 = record 579 cert_info: pX509_CINF; 580 sig_alg: pointer; // ^X509_ALGOR 581 signature: pointer; // ^ASN1_BIT_STRING 582 valid: integer; 583 references: integer; 584 name: PCharacter; 585 ex_data: CRYPTO_EX_DATA; 586 ex_pathlen: integer; 587 ex_flags: integer; 588 ex_kusage: integer; 589 ex_xkusage: integer; 590 ex_nscert: integer; 591 skid: pASN1_OCTET_STRING; 592 akid: pointer; // ? 593 sha1_hash: array [0..SHA_DIGEST_LENGTH-1] of char; 594 aux: pointer; // ^X509_CERT_AUX 595 end; 596 pSTACK_OFX509 = pointer; 597 pX509_STORE = ^X509_STORE; 598 pX509_LOOKUP = pointer; 599 pSTACK_OF509LOOKUP = pointer; 600 pX509_LOOKUP_METHOD = pointer; 601 X509_STORE = record 602 cache: integer; 603 objs: pSTACK_OFX509; 604 get_cert_methods: pSTACK_OF509LOOKUP; 605 verify: pointer; // function called to verify a certificate 606 verify_cb: TCertificateVerifyFunction; 607 ex_data: pointer; 608 references: integer; 609 depth: integer; 610 end; 611 612 pX509V3_CTX = pointer; 613 614 pX509_REQ = ^X509_REQ; 615 pX509_REQ_INFO = ^X509_REQ_INFO; 616 X509_REQ_INFO = record 617 asn1: pointer; 618 length: integer; 619 version: pointer; 620 subject: pX509_NAME; 621 pubkey: pointer; 622 attributes: pointer; 623 req_kludge: integer; 624 end; 625 X509_REQ = record 626 req_info: pX509_REQ_INFO; 627 sig_alg: pointer; 628 signature: pointer; 629 references: integer; 630 end; 631 632 pX509_EXTENSION = ^X509_EXTENSION; 633 X509_EXTENSION = record 634 obj: pASN1_OBJECT; 635 critical: Smallint; 636 netscape_hack: Smallint; 637 value: pASN1_OCTET_STRING; 638 method: pointer; // struct v3_ext_method *: V3 method to use 639 ext_val: pointer; // extension value 640 end; 641 pSTACK_OFX509_EXTENSION = pointer; 642 643 pX509_CRL = pointer; 644 645 pX509_SIG = ^X509_SIG; 646 X509_SIG = record 647 algor: Pointer; // X509_ALGOR *algor; 648 digest: pASN1_OCTET_STRING; 649 end; 650 651 pBASIC_CONSTRAINTS = ^BASIC_CONSTRAINTS; 652 BASIC_CONSTRAINTS = record 653 ca: integer; 654 pathlen: pASN1_INTEGER; 655 end; 656 pOTHERNAME = ^OTHERNAME; 657 OTHERNAME = record 658 type_id: pASN1_OBJECT; //There is a bug in x509v3/x509v3.h ? 659 value: pointer; //pASN1_TYPE; 660 end; 661 pGENERAL_NAME = ^GENERAL_NAME ; 662 pGENERAL_NAMEDATA = record 663 case integer of 664 GEN_EMAIL: (ia5: pASN1_IA5STRING); // also DNS and URI 665 GEN_IPADD: (ip: pASN1_OCTET_STRING); 666 GEN_DIRNAME: (dirn: pX509_NAME); 667 GEN_RID: (rid: pASN1_OBJECT); 668 GEN_OTHERNAME: (otherName: pOTHERNAME); 669 GEN_X400: (other: pointer); // also EDI 670 end; 671 GENERAL_NAME = record 672 nametype: integer; 673 d: pGENERAL_NAMEDATA; 674 end; 675 676 pEVP_PKEY = ^EVP_PKEY; 677 EVP_PKEY_PKEY = record 678 case integer of 679 0: (ptr: PCharacter); 680 1: (rsa: pRSA); // ^rsa_st 681 2: (dsa: pDSA); // ^dsa_st 682 3: (dh: pDH); // ^dh_st 683 end; 684 EVP_PKEY = record 685 ktype: integer; 686 save_type: integer; 687 references: integer; 688 pkey: EVP_PKEY_PKEY; 689 save_parameters: integer; 690 attributes: pSTACK_OFX509; 691 end; 692 693 pPKCS7_SIGNER_INFO = pointer; 694 pSTACK_OFPKCS7_SIGNER_INFO = pointer; 695 pPKCS7_signed = ^PKCS7_signed; 696 PKCS7_signed = record 697 version: pASN1_INTEGER; 698 md_algs: pointer; // ^STACK_OF(X509_ALGOR) 699 cert: pointer; // ^STACK_OF(X509) 700 crl: pointer; // ^STACK_OF(X509_CRL) 701 signer_info: pSTACK_OFPKCS7_SIGNER_INFO; 702 contents: pointer; // ^struct pkcs7_st 703 end; 704 705 pPKCS7_signedandenveloped = ^PKCS7_signedandenveloped; 706 PKCS7_signedandenveloped = record 707 version: pASN1_INTEGER; 708 md_algs: pointer; // ^STACK_OF(X509_ALGOR) 709 cert: pointer; // ^STACK_OF(X509) 710 crl: pointer; // ^STACK_OF(X509_CRL) 711 signer_info: pSTACK_OFPKCS7_SIGNER_INFO; 712 enc_data: pointer; // ^PKCS7_ENC_CONTENT 713 recipientinfo: pointer; // ^STACK_OF(PKCS7_RECIP_INFO) 714 end; 715 716 pPKCS7 = ^PKCS7; 717 PKCS7 = record 718 asn1: PCharacter; 719 length: integer; 720 state: integer; 721 detached: integer; 722 asn1_type: pointer; // ^ASN1_OBJECT 723 case integer of 724 0: (ptr: pASN1_OCTET_STRING); 725 1: (data: pointer); // ^PKCS7_SIGNED 726 2: (sign: pPKCS7_signed); // ^PKCS7_SIGNED 727 3: (enveloped: pointer); // ^PKCS7_ENVELOPE 728 4: (signed_and_enveloped: pPKCS7_signedandenveloped); 729 5: (digest: pointer); // ^PKCS7_DIGEST 730 6: (encrypted: pointer); // ^PKCS7_ENCRYPT 731 7: (other: pointer); // ^ASN1_TYPE 732 end; 733 734 pPKCS8_Priv_Key_Info = ^PKCS8_Priv_Key_Info; 735 PKCS8_Priv_Key_Info = record 736 broken: Integer; // Flag for various broken formats */ 737 version: pASN1_INTEGER; 738 pkeyalg: Pointer; // X509_ALGOR *pkeyalg; 739 pkey: Pointer; // ASN1_TYPE *pkey; /* Should be OCTET STRING but some are broken */ 740 attributes: Pointer; // STACK_OF(X509_ATTRIBUTE) *attributes; 741 end; 742 743 pPKCS12 = ^PKCS12; 744 PKCS12 = record 745 version: pointer; 746 mac: pointer; 747 authsafes: pPKCS7; 748 end; 749 750 //by lwm8246 2016/02/28 20:03 751 pSHA256_CTX=^SHA256_CTX; 752 SHA256_CTX = record 753 h : array [0..(8 - 1)] of Cardinal; 754 Nl,Nh : Cardinal; 755 data : array [0..(16 -1)] of Cardinal; 756 num,md_len : Cardinal; 757 end; 758 759 PENGINE = Pointer;//^ENGINE; 760 761 762 function SSLeay: cardinal; 763 function SSLeay_version(t: integer): PCharacter; cdecl; 764 procedure OpenSSL_add_all_algorithms; 765 procedure OpenSSL_add_all_ciphers; cdecl; 766 procedure OpenSSL_add_all_digests; cdecl; 767 procedure EVP_cleanup(); cdecl; 768 769 function ERR_get_error: cardinal; cdecl; 770 function ERR_peek_error: cardinal; cdecl; 771 function ERR_peek_last_error: cardinal; cdecl; 772 function ERR_error_string(e: cardinal; buf: PCharacter): PCharacter; cdecl; 773 procedure ERR_clear_error; 774 procedure ERR_load_crypto_strings; 775 procedure ERR_free_strings; 776 777 // Low level debugable memory management function 778 function CRYPTO_malloc(length: longint; const f: PCharacter; line: integer): pointer; cdecl; 779 function CRYPTO_realloc(str: PCharacter; length: longint; const f: PCharacter; line: integer): pointer; cdecl; 780 function CRYPTO_remalloc(a: pointer; length: longint; const f: PCharacter; line: integer): pointer; cdecl; 781 procedure CRYPTO_free(str: pointer); cdecl; 782 // High level memory management function 783 function OPENSSL_malloc(length: longint): pointer; 784 function OPENSSL_realloc(address: PCharacter; length: longint): pointer; 785 function OPENSSL_remalloc(var address: pointer; length: longint): pointer; 786 procedure OPENSSL_free(address: pointer); cdecl; 787 788 // Big number function 789 function BN_new(): pBIGNUM; cdecl; 790 procedure BN_init(bn: pBIGNUM); cdecl; 791 procedure BN_clear(bn: pBIGNUM); cdecl; 792 procedure BN_free(bn: pBIGNUM); cdecl; 793 procedure BN_clear_free(bn: pBIGNUM); cdecl; 794 procedure BN_set_params(mul, high, low, mont: integer); cdecl; 795 function BN_get_params(which: integer): integer; cdecl; 796 797 function BN_options: PCharacter; cdecl; 798 799 function BN_CTX_new: pBN_CTX; cdecl; 800 procedure BN_CTX_init(ctx: pBN_CTX); cdecl; 801 procedure BN_CTX_start(ctx: pBN_CTX); cdecl; 802 function BN_CTX_get(ctx: pBN_CTX): pBIGNUM; cdecl; 803 procedure BN_CTX_end(ctx: pBN_CTX); cdecl; 804 procedure BN_CTX_free(ctx: pBN_CTX); cdecl; 805 806 function BN_MONT_CTX_new: pBN_MONT_CTX; cdecl; 807 procedure BN_MONT_CTX_init(m_ctx: pBN_MONT_CTX); cdecl; 808 function BN_MONT_CTX_set(m_ctx: pBN_MONT_CTX; 809 const modulus: pBIGNUM; ctx: pBN_CTX): integer; cdecl; 810 function BN_MONT_CTX_copy(_to: pBN_MONT_CTX; from: pBN_MONT_CTX): pBN_MONT_CTX; cdecl; 811 procedure BN_MONT_CTX_free(m_ctx: pBN_MONT_CTX); cdecl; 812 function BN_mod_mul_montgomery(r, a, b: pBIGNUM; m_ctx: pBN_MONT_CTX; ctx: pBN_CTX): integer; cdecl; 813 function BN_from_montgomery(r, a: pBIGNUM; m_ctx: pBN_MONT_CTX; ctx: pBN_CTX): integer; cdecl; 814 function BN_to_montgomery(r, a: pBIGNUM; m_ctx: pBN_MONT_CTX; ctx: pBN_CTX): integer; 815 816 procedure BN_RECP_CTX_init(recp: pBN_RECP_CTX); cdecl; 817 function BN_RECP_CTX_set(recp: pBN_RECP_CTX; const rdiv: pBIGNUM; ctx: pBN_CTX): integer; cdecl; 818 function BN_RECP_CTX_new: pBN_RECP_CTX; cdecl; 819 procedure BN_RECP_CTX_free(recp: pBN_RECP_CTX); cdecl; 820 function BN_div_recp(dv, rem, a: pBIGNUM; recp: pBN_RECP_CTX; ctx: pBN_CTX): integer; cdecl; 821 function BN_mod_mul_reciprocal(r, a, b: pBIGNUM; recp: pBN_RECP_CTX; ctx: pBN_CTX): integer; cdecl; 822 823 function BN_BLINDING_new(a: pBIGNUM; Ai: pBIGNUM; _mod: pBIGNUM): pBN_BLINDING; cdecl; 824 function BN_BLINDING_update(b: pBN_BLINDING; ctx: pBN_CTX): pBN_BLINDING; cdecl; 825 procedure BN_BLINDING_free(b: pBN_BLINDING); cdecl; 826 function BN_BLINDING_convert(n: pBIGNUM; r: pBN_BLINDING; ctx: pBN_CTX): integer; cdecl; 827 function BN_BLINDING_invert(n: pBIGNUM; b: pBN_BLINDING; ctx: pBN_CTX): integer; cdecl; 828 829 function BN_copy(_to: pBIGNUM; const from: pBIGNUM): pBIGNUM; cdecl; 830 function BN_dup(const from: pBIGNUM): pBIGNUM; cdecl; 831 832 // Helper: convert standard Delphi integer in big-endian integer 833 function int2bin(n: integer): integer; 834 835 function BN_bn2bin(const n: pBIGNUM; _to: pointer): integer; cdecl; 836 function BN_bin2bn(const _from: pointer; len: integer; ret: pBIGNUM): pBIGNUM; cdecl; 837 838 function BN_bn2hex(const n: pBIGNUM): PCharacter; cdecl; 839 function BN_bn2dec(const n: pBIGNUM): PCharacter; cdecl; 840 function BN_hex2bn(var n: pBIGNUM; const str: PCharacter): integer; cdecl; 841 function BN_dec2bn(var n: pBIGNUM; const str: PCharacter): integer; cdecl; 842 function BN_bn2mpi(const a: pBIGNUM; _to: pointer): integer; cdecl; 843 function BN_mpi2bn(s: pointer; len: integer; ret: pBIGNUM): pBIGNUM; cdecl; 844 function BN_print(fp: pBIO; const a: pointer): integer; cdecl; 845 //function BN_print_fp(FILE *fp, const BIGNUM *a): integer; cdecl; 846 847 function BN_zero(n: pBIGNUM): integer; 848 function BN_one(n: pBIGNUM): integer; 849 function BN_value_one(): pBIGNUM; cdecl; 850 function BN_set_word(n: pBIGNUM; w: cardinal): integer; cdecl; 851 function BN_get_word(n: pBIGNUM): cardinal; cdecl; 852 853 function BN_cmp(a: pBIGNUM; b: pBIGNUM): integer; cdecl; 854 function BN_ucmp(a: pBIGNUM; b: pBIGNUM): integer; cdecl; 855 //function BN_is_zero(a: pBIGNUM): boolean; 856 //function BN_is_one(a: pBIGNUM): boolean; 857 //function BN_is_word(a: pBIGNUM; w: BN_ULONG): boolean; 858 //function BN_is_odd(a: pBIGNUM): boolean; 859 860 function BN_num_bytes(const a: pBIGNUM): integer; 861 function BN_num_bits(const a: pBIGNUM): integer; cdecl; 862 function BN_num_bits_word(w: BN_ULONG): integer; cdecl; 863 864 function BN_add(r: pBIGNUM; const a, b: pBIGNUM): integer; cdecl; 865 function BN_sub(r: pBIGNUM; const a, b: pBIGNUM): integer; cdecl; 866 function BN_uadd(r: pBIGNUM; const a, b: pBIGNUM): integer; cdecl; 867 function BN_usub(r: pBIGNUM; const a, b: pBIGNUM): integer; cdecl; 868 function BN_mul(r: pBIGNUM; a: pBIGNUM; b: pBIGNUM; ctx: pBN_CTX): integer; cdecl; 869 function BN_sqr(r: pBIGNUM; a: pBIGNUM; ctx: pBN_CTX): integer; cdecl; 870 function BN_div(dv: pBIGNUM; rem: pBIGNUM; const a, d: pBIGNUM; ctx: pBN_CTX): integer; cdecl; 871 // BN_mod redefined as BN_div in some DLL version 872 function BN_mod(rem: pBIGNUM; const a, m: pBIGNUM; ctx: pBN_CTX): integer; 873 function BN_exp(r: pBIGNUM; a: pBIGNUM; p: pBIGNUM; ctx: pBN_CTX): integer; cdecl; 874 function BN_mod_exp(r, a: pBIGNUM; const p, m: pBIGNUM; ctx: pBN_CTX): integer; cdecl; 875 function BN_gcd(r: pBIGNUM; a: pBIGNUM; b: pBIGNUM; ctx: pBN_CTX): integer; cdecl; 876 // BN_nnmod requires OpenSSL >= 0.9.7 877 function BN_nnmod(rem: pBIGNUM; const a: pBIGNUM; const m: pBIGNUM; ctx: pBN_CTX): integer; cdecl; 878 // BN_mod_add requires OpenSSL >= 0.9.7 879 function BN_mod_add(r: pBIGNUM; a: pBIGNUM; b: pBIGNUM; const m: pBIGNUM; 880 ctx: pBN_CTX): integer; cdecl; 881 // BN_mod_sub requires OpenSSL >= 0.9.7 882 function BN_mod_sub(r: pBIGNUM; a: pBIGNUM; b: pBIGNUM; const m: pBIGNUM; 883 ctx: pBN_CTX): integer; cdecl; 884 // BN_mod_mul requires OpenSSL >= 0.9.7 885 function BN_mod_mul(ret, a, b: pBIGNUM; const m: pBIGNUM; ctx: pBN_CTX): integer; cdecl; 886 // BN_mod_sqr requires OpenSSL >= 0.9.7 887 function BN_mod_sqr(r: pBIGNUM; a: pBIGNUM; const m: pBIGNUM; ctx: pBN_CTX): integer; cdecl; 888 function BN_reciprocal(r, m: pBIGNUM; ctx: pBN_CTX): integer; cdecl; 889 890 function BN_mod_exp2_mont(r, a1, p1, a2, p2, m: pBIGNUM; 891 ctx: pBN_CTX; m_ctx: pBN_MONT_CTX): integer; cdecl; 892 function BN_mod_exp_mont(r, a: pBIGNUM; const p, m: pBIGNUM; 893 ctx: pBN_CTX; m_ctx: pBN_MONT_CTX): integer; cdecl; 894 function BN_mod_exp_mont_word(r: pBIGNUM; a: BN_ULONG; const p, m: pBIGNUM; 895 ctx: pBN_CTX; m_ctx: pBN_MONT_CTX): integer; cdecl; 896 function BN_mod_exp_simple(r, a, p, m: pBIGNUM; ctx: pBN_CTX): integer; cdecl; 897 function BN_mod_exp_recp(r: pBIGNUM; const a, p, m: pBIGNUM; ctx: pBN_CTX): integer; cdecl; 898 function BN_mod_inverse(ret, a: pBIGNUM; const n: pBIGNUM; ctx: pBN_CTX): pBIGNUM; cdecl; 899 900 function BN_add_word(a: pBIGNUM; w: BN_ULONG): integer; cdecl; // Adds w to a ("a+=w"). 901 function BN_sub_word(a: pBIGNUM; w: BN_ULONG): integer; cdecl; // Subtracts w from a ("a-=w"). 902 function BN_mul_word(a: pBIGNUM; w: BN_ULONG): integer; cdecl; // Multiplies a and w ("a*=b"). 903 function BN_div_word(a: pBIGNUM; w: BN_ULONG): BN_ULONG; cdecl; // Divides a by w ("a/=w") and returns the remainder. 904 function BN_mod_word(const a: pBIGNUM; w: BN_ULONG): BN_ULONG; cdecl; // Returns the remainder of a divided by w ("a%m"). 905 function bn_mul_words(rp, ap: pBN_ULONG; num: integer; w: BN_ULONG): BN_ULONG; cdecl; 906 function bn_mul_add_words(rp, ap: pBN_ULONG; num: integer; w: BN_ULONG): BN_ULONG; cdecl; 907 procedure bn_sqr_words(rp, ap: pBN_ULONG; num: integer); cdecl; 908 function bn_div_words(h, l, d: BN_ULONG): BN_ULONG; cdecl; 909 function bn_add_words(rp, ap, bp: pBN_ULONG; num: integer): BN_ULONG; cdecl; 910 function bn_sub_words(rp, ap, bp: pBN_ULONG; num: integer): BN_ULONG; cdecl; 911 function bn_expand2(a: pBIGNUM; n: integer): pBIGNUM; cdecl; 912 913 function BN_set_bit(a: pBIGNUM; n: integer): integer; cdecl; 914 function BN_clear_bit(a: pBIGNUM; n: integer): integer; cdecl; 915 function BN_is_bit_set(const a: pBIGNUM; n: integer): integer; cdecl; 916 function BN_mask_bits(a: pBIGNUM; n: integer): integer; cdecl; 917 function BN_lshift(r: pBIGNUM; const a: pBIGNUM; n: integer): integer; cdecl; 918 function BN_lshift1(r: pBIGNUM; a: pBIGNUM): integer; cdecl; 919 function BN_rshift(r: pBIGNUM; const a: pBIGNUM; n: integer): integer; cdecl; 920 function BN_rshift1(r: pBIGNUM; a: pBIGNUM): integer; cdecl; 921 922 function BN_generate_prime(ret: pBIGNUM; num, safe: integer; add, rem: pBIGNUM; 923 progress: TProgressCallbackFunction; cb_arg: pointer): pBIGNUM; cdecl; 924 function BN_is_prime(const a: pBIGNUM; checks: integer; 925 progress: TProgressCallbackFunction; ctx: pBN_CTX; cb_arg: pointer): integer; cdecl; 926 function BN_is_prime_fasttest(const a: pBIGNUM; checks: integer; 927 progress: TProgressCallbackFunction; ctx: pBN_CTX; cb_arg: pointer; 928 do_trial_division: integer): integer; cdecl; 929 930 function BN_rand(rnd: pBIGNUM; bits, top, bottom: integer): integer; cdecl; 931 function BN_pseudo_rand(rnd: pBIGNUM; bits, top, bottom: integer): integer; cdecl; 932 function BN_rand_range(rnd, range: pBIGNUM): integer; cdecl; 933 // BN_pseudo_rand_range requires OpenSSL >= 0.9.6c 934 function BN_pseudo_rand_range(rnd, range: pBIGNUM): integer; cdecl; 935 function BN_bntest_rand(rnd: pBIGNUM; bits, top, bottom: integer): integer; cdecl; 936 937 function BN_to_ASN1_INTEGER(bn: pBIGNUM; ai: pASN1_INTEGER): pASN1_INTEGER; cdecl; 938 function BN_to_ASN1_ENUMERATED(bn: pBIGNUM; ai: pASN1_ENUMERATED): pASN1_ENUMERATED; cdecl; 939 940 // ASN.1 functions 941 function ASN1_IA5STRING_new: pASN1_IA5STRING; cdecl; 942 procedure ASN1_INTEGER_free(x: pASN1_IA5STRING); cdecl; 943 function ASN1_INTEGER_get(a: pointer): longint; cdecl; 944 procedure ASN1_STRING_set_default_mask(mask: cardinal); cdecl; 945 function ASN1_STRING_get_default_mask: cardinal; cdecl; 946 function ASN1_TIME_print(fp: pBIO; a: pASN1_TIME): integer; cdecl; 947 948 // OBJ functions 949 function OBJ_obj2nid(asn1_object: pointer): integer; cdecl; 950 function OBJ_txt2nid(s: PCharacter): integer; cdecl; 951 function OBJ_txt2obj(s: PCharacter; no_name: integer): integer; cdecl; 952 953 // safestack functions 954 function sk_new_null: pointer; cdecl; 955 procedure sk_free(st: pointer); cdecl; 956 function sk_push(st: pointer; val: pointer): integer; cdecl; 957 function sk_num(st: pointer): integer; cdecl; 958 function sk_value(st: pointer; i: integer): pointer; cdecl; 959 960 // BIO functions 961 function BIO_new(_type: pBIO_METHOD): pBIO; cdecl; 962 function BIO_new_file(const filename: PCharacter; const mode: PCharacter): pBIO; cdecl; 963 function BIO_set(a: pBIO; _type: pBIO_METHOD): integer; cdecl; 964 function BIO_free(a: pBIO): integer; cdecl; 965 procedure BIO_vfree(a: pBIO); cdecl; 966 procedure BIO_free_all(a: pBIO); cdecl; 967 function BIO_push(b: pBIO; append: pBIO): pBIO; cdecl; 968 function BIO_pop(b: pBIO): pBIO; cdecl; 969 function BIO_ctrl(bp: pBIO; cmd: Integer; larg: Longint; 970 parg: Pointer): Longint; cdecl; 971 972 function BIO_read(b: pBIO; buf: pointer; len: integer): integer; cdecl; 973 function BIO_gets(b: pBIO; buf: PCharacter; size: integer): integer; cdecl; 974 function BIO_write(b: pBIO; const buf: pointer; len: integer): integer; cdecl; 975 function BIO_puts(b: pBIO; const buf: PCharacter): integer; cdecl; 976 function BIO_flush(b: pBIO): integer; 977 978 function BIO_reset(bp: pBIO): integer; 979 function BIO_eof(bp: pBIO): integer; 980 function BIO_set_close(bp: pBIO; c: integer): integer; 981 function BIO_get_close(bp: pBIO): integer; 982 function BIO_pending(bp: pBIO): integer; 983 function BIO_wpending(bp: pBIO): integer; 984 function BIO_read_filename(bp: pBIO; filename: PCharacter): integer; 985 function BIO_write_filename(bp: pBIO; filename: PCharacter): integer; 986 function BIO_append_filename(bp: pBIO; filename: PCharacter): integer; 987 function BIO_rw_filename(bp: pBIO; filename: PCharacter): integer; 988 989 function BIO_s_mem: pBIO_METHOD; cdecl; 990 function BIO_f_base64: pBIO_METHOD; cdecl; 991 procedure BIO_set_mem_eof_return(b: pBIO; v: integer); cdecl; 992 function BIO_get_mem_data(b: pBIO; var pp: PCharacter): integer; cdecl; // long ?? 993 procedure BIO_set_mem_buf(b: pBIO; bm: pBUF_MEM; c: integer); cdecl; 994 function BIO_get_mem_ptr(b: pBIO; pp: PPBUF_MEM):Integer; cdecl; 995 function BIO_new_mem_buf(buf: pointer; len: integer): pBIO; cdecl; 996 function BIO_s_file: pBIO_METHOD; cdecl; 997 998 function BIO_get_md_ctx(bp: pBIO; mdcp: Pointer): Longint; 999 1000 // Internal to DER and DER to internal conversion functions 1001 function i2d_ASN1_TIME(a: pASN1_TIME; pp: PCharacter): integer; cdecl; 1002 function d2i_ASN1_TIME(var a: pASN1_TIME; pp: PCharacter; length: longint): pASN1_TIME; cdecl; 1003 function d2i_X509_REQ_bio(bp: pBIO; req: pX509_REQ): pX509_REQ; cdecl; 1004 function i2d_X509_REQ_bio(bp: pBIO; req: pX509_REQ): integer; cdecl; 1005 function d2i_X509_bio(bp: pBIO; x509: pX509): pX509; cdecl; 1006 function i2d_X509_bio(bp: pBIO; x509: pX509): integer; cdecl; 1007 function d2i_PrivateKey_bio(bp: pBIO; var a: pEVP_PKEY): pEVP_PKEY; cdecl; 1008 function i2d_PrivateKey_bio(bp: pBIO; pkey: pEVP_PKEY): integer; cdecl; 1009 function d2i_PUBKEY_bio(bp: pBIO; var a: pEVP_PKEY): pEVP_PKEY; cdecl; 1010 function i2d_PUBKEY_bio(bp: pBIO; pkey: pEVP_PKEY): integer; cdecl; 1011 function d2i_PKCS12_bio(bp: pBIO; pkcs12: pPKCS12): pPKCS12; cdecl; 1012 function i2d_PKCS12_bio(bp: pBIO; pkcs12: pPKCS12): integer; cdecl; 1013 function d2i_PKCS7(var a: pPKCS7; pp: pointer; length: longint): pPKCS7; cdecl; 1014 function d2i_PKCS7_bio(bp: pBIO; p7: pPKCS7): pPKCS7; cdecl; 1015 function i2d_PKCS7_bio(bp: pBIO; p7: pPKCS7): integer; cdecl; 1016 function d2i_PKCS8_bio(bp: pBIO; p8: pX509_SIG): pX509_SIG; cdecl; 1017 function d2i_PKCS8_PRIV_KEY_INFO(var a: pPKCS8_Priv_Key_Info; 1018 pp: PCharacter; Length: LongInt): pPKCS8_Priv_Key_Info; cdecl; 1019 function d2i_DSAPrivateKey_bio(bp: pBIO; dsa: pDSA): pDSA; cdecl; 1020 function i2d_DSAPrivateKey_bio(bp: pBIO; dsa: pDSA): integer; cdecl; 1021 function d2i_RSAPrivateKey_bio(bp: pBIO; rsa: pRSA): pRSA; cdecl; 1022 function i2d_RSAPrivateKey_bio(bp: pBIO; rsa: pRSA): integer; cdecl; 1023 1024 // Internal to ASN.1 and ASN.1 to internal conversion functions 1025 function i2a_ASN1_INTEGER(bp: pBIO; a: pASN1_INTEGER): integer; cdecl; 1026 function a2i_ASN1_INTEGER(bp: pBIO; bs: pASN1_INTEGER; buf: PCharacter; 1027 size: integer): integer; cdecl; 1028 1029 // Hash functions 1030 function EVP_md_null: pEVP_MD; cdecl; 1031 function EVP_md2: pEVP_MD; cdecl; 1032 function EVP_md5: pEVP_MD; cdecl; 1033 function EVP_sha: pEVP_MD; cdecl; 1034 function EVP_sha1: pEVP_MD; cdecl; 1035 function EVP_dss: pEVP_MD; cdecl; 1036 function EVP_dss1: pEVP_MD; cdecl; 1037 function EVP_mdc2: pEVP_MD; cdecl; 1038 function EVP_ripemd160: pEVP_MD; cdecl; 1039 function EVP_get_digestbyname(const name: PCharacter): pEVP_MD; cdecl; 1040 1041 procedure EVP_DigestInit(ctx: pEVP_MD_CTX; const _type: pEVP_MD); cdecl; 1042 procedure EVP_DigestUpdate(ctx: pEVP_MD_CTX; const d: Pointer; cnt: cardinal); cdecl; 1043 procedure EVP_DigestFinal(ctx: pEVP_MD_CTX; md: PCharacter; var s: cardinal); cdecl; 1044 procedure EVP_SignInit(ctx: pEVP_MD_CTX; const _type: pEVP_MD); 1045 procedure EVP_SignUpdate(ctx: pEVP_MD_CTX; const d: Pointer; cnt: cardinal); 1046 function EVP_SignFinal(ctx: pEVP_MD_CTX; sig: pointer; var s: cardinal; 1047 key: pEVP_PKEY): integer; cdecl; 1048 procedure EVP_VerifyInit(ctx: pEVP_MD_CTX; const _type: pEVP_MD); 1049 procedure EVP_VerifyUpdate(ctx: pEVP_MD_CTX; const d: Pointer; cnt: cardinal); 1050 function EVP_VerifyFinal(ctx: pEVP_MD_CTX; sigbuf: pointer; 1051 siglen: cardinal; pkey: pEVP_PKEY): integer; cdecl; 1052 function EVP_PKEY_assign(pkey: pEVP_PKEY; key_type: integer; 1053 key: PCharacter): integer; cdecl; 1054 //function EVP_MD_size(e: pEVP_MD): integer; 1055 //function EVP_MD_CTX_size(e: pEVP_MD_CTX): integer; 1056 function EVP_MD_CTX_copy(_out: pEVP_MD_CTX; _in: pEVP_MD_CTX): integer; cdecl; 1057 1058 // Crypt functions 1059 function EVP_enc_null: pEVP_CIPHER; cdecl; 1060 function EVP_des_ecb: pEVP_CIPHER; cdecl; 1061 function EVP_des_ede: pEVP_CIPHER; cdecl; 1062 function EVP_des_ede3: pEVP_CIPHER; cdecl; 1063 function EVP_des_cfb: pEVP_CIPHER; cdecl; 1064 function EVP_des_ede_cfb: pEVP_CIPHER; cdecl; 1065 function EVP_des_ede3_cfb: pEVP_CIPHER; cdecl; 1066 function EVP_des_ofb: pEVP_CIPHER; cdecl; 1067 function EVP_des_ede_ofb: pEVP_CIPHER; cdecl; 1068 function EVP_des_ede3_ofb: pEVP_CIPHER; cdecl; 1069 function EVP_des_cbc: pEVP_CIPHER; cdecl; 1070 function EVP_des_ede_cbc: pEVP_CIPHER; cdecl; 1071 function EVP_des_ede3_cbc: pEVP_CIPHER; cdecl; 1072 function EVP_desx_cbc: pEVP_CIPHER; cdecl; 1073 function EVP_idea_cbc: pEVP_CIPHER; cdecl; 1074 function EVP_idea_cfb: pEVP_CIPHER; cdecl; 1075 function EVP_idea_ecb: pEVP_CIPHER; cdecl; 1076 function EVP_idea_ofb: pEVP_CIPHER; cdecl; 1077 function EVP_get_cipherbyname(name: PCharacter): pEVP_CIPHER; cdecl; 1078 1079 // EVP Key functions 1080 function EVP_PKEY_new: pEVP_PKEY; cdecl; 1081 procedure EVP_PKEY_free(key: pEVP_PKEY); cdecl; 1082 function EVP_PKEY_type(keytype: integer): integer; cdecl; 1083 function EVP_PKEY_assign_RSA(key: pEVP_PKEY; rsa: pRSA): integer; cdecl; 1084 function EVP_PKEY_assign_DSA(key: pEVP_PKEY; dsa: pDSA): integer; cdecl; 1085 function EVP_PKEY_assign_DH(key: pEVP_PKEY; dh: pDH): integer; cdecl; 1086 function EVP_PKEY_assign_EC_KEY(key: pEVP_PKEY; ec: pEC_KEY): integer; cdecl; 1087 function EVP_PKEY_set1_RSA(key: pEVP_PKEY; rsa: pRSA): integer; cdecl; 1088 function EVP_PKEY_set1_DSA(key: pEVP_PKEY; dsa: pDSA): integer; cdecl; 1089 function EVP_PKEY_set1_DH(key: pEVP_PKEY; dh: pDH): integer; cdecl; 1090 function EVP_PKEY_set1_EC_KEY(key: pEVP_PKEY; ec: pEC_KEY): integer; cdecl; 1091 function EVP_PKEY_size(key: pEVP_PKEY): integer; cdecl; 1092 function EVP_PKEY_get1_RSA(key: pEVP_PKEY): pRSA; cdecl; 1093 function EVP_PKEY_get1_DSA(key: pEVP_PKEY): pDSA; cdecl; 1094 function EVP_PKEY_get1_DH(key: pEVP_PKEY): pDH; cdecl; 1095 function EVP_PKEY_get1_EC_KEY(key: pEVP_PKEY): pEC_KEY; cdecl; 1096 1097 // Password prompt for callback function 1098 procedure EVP_set_pw_prompt(prompt: PCharacter); 1099 function EVP_get_pw_prompt: PCharacter; 1100 // Default callback password function: replace if you want 1101 function EVP_read_pw_string(buf: PCharacter; len: integer; 1102 const prompt: PCharacter; verify: integer): integer; 1103 1104 // pseudo-random number generator (PRNG) functions 1105 procedure RAND_seed(const buf: pointer; num: integer); cdecl; 1106 procedure RAND_add(const buf: pointer; num: integer; entropy: double); cdecl; 1107 function RAND_status: integer; cdecl; 1108 //function RAND_event(UINT iMsg, WPARAM wParam, LPARAM lParam): integer; cdecl; 1109 procedure RAND_screen; cdecl; 1110 function RAND_file_name(buf: PCharacter; size_t: cardinal): PCharacter; cdecl; 1111 function RAND_load_file(const filename: PCharacter; max_bytes: longint): integer; cdecl; 1112 function RAND_write_file(const filename: PCharacter): integer; cdecl; 1113 1114 // RSA function 1115 function RSA_new: pRSA; cdecl; 1116 procedure RSA_free(r: pRSA); cdecl; 1117 function RSA_new_method(method: pRSA_METHOD): pRSA; cdecl; 1118 function RSA_size(pkey: pRSA): integer; cdecl; 1119 function RSA_generate_key(bits: integer; exp: Cardinal; 1120 progress: TProgressCallbackFunction; cb_arg: pointer):pRSA; cdecl; 1121 function RSA_check_key(arg0: pRSA): integer; cdecl; 1122 function RSA_public_encrypt(flen: integer; from: PCharacter; _to: PCharacter; rsa: pRSA; padding: integer): integer; cdecl; 1123 function RSA_private_encrypt(flen: integer; from: PCharacter; _to: PCharacter; rsa: pRSA; padding: integer): integer; cdecl; 1124 function RSA_public_decrypt(flen: integer; from: PCharacter; _to: PCharacter; rsa: pRSA; padding: integer): integer; cdecl; 1125 function RSA_private_decrypt(flen: integer; from: PCharacter; _to: PCharacter; rsa: pRSA; padding: integer): integer; cdecl; 1126 function RSA_flags(r: pRSA): integer; cdecl; 1127 procedure RSA_set_default_method(meth: pRSA_METHOD); cdecl; 1128 function RSA_get_default_method: pRSA_METHOD; cdecl; 1129 function RSA_get_method(rsa: pRSA): pRSA_METHOD; cdecl; 1130 function RSA_set_method(rsa: pRSA; meth: pRSA_METHOD): pRSA_METHOD; cdecl; 1131 function RSA_memory_lock(r: pRSA):integer; cdecl; 1132 function RSA_PKCS1_SSLeay: pRSA_METHOD; cdecl; 1133 procedure ERR_load_RSA_strings; cdecl; 1134 1135 //function RSA_sign(len:integer;_m:PCharacter;_m_length:integer; from: PCharacter; _to: pointer; rsa: pRSA): integer; cdecl; 1136 //int RSA_sign(int type, 1137 // const unsigned char *m, 1138 // unsigned int m_len, 1139 // unsigned char *sigret, 1140 // unsigned int *siglen, 1141 // RSA *rsa); 1142 function RSA_sign(_type:Integer; 1143 m:PCharacter; 1144 m_len:Integer; 1145 sigret:PCharacter; 1146 siglen:PInteger; 1147 ras:pRSA):Integer;cdecl; //2016/02/18 16:52 1148 1149 // int RSA_verify(int type, 1150 // const unsigned char *m, 1151 // unsigned int m_len, 1152 // unsigned char *sigbuf, 1153 // unsigned int siglen, 1154 // RSA *rsa); 1155 function RSA_verify(_type:Integer; 1156 m:PCharacter; 1157 m_len:Integer; // unsigned int m_len, 1158 sigbuf:PAnsichar; //unsigned char *sigbuf, 1159 siglen:Integer; // unsigned int siglen, 1160 ras:pRSA):Integer;cdecl;//2016/02/19 13:43 1161 1162 1163 1164 function DSA_new: pDSA; cdecl; 1165 procedure DSA_free(r: pDSA); cdecl; 1166 function DSA_generate_parameters(bits: integer; seed: pointer; seed_len: integer; 1167 var counter_ret: integer; var h_ret: cardinal; 1168 progress: TProgressCallbackFunction; cb_arg: Pointer): pDSA; cdecl; 1169 function DSA_generate_key(a: pDSA): integer; cdecl; 1170 1171 // X.509 names (DN) 1172 function X509_NAME_oneline(a: pX509_NAME; buf: PCharacter; size: integer): PCharacter; cdecl; 1173 function X509_NAME_new: pX509_NAME; cdecl; 1174 procedure X509_NAME_free(x:pX509_NAME) cdecl; 1175 function X509_NAME_add_entry_by_txt(name: pX509_NAME; field: PCharacter; 1176 asn1_type: integer; bytes: pointer; len, loc, pos: integer): integer; cdecl; 1177 function X509_NAME_get_entry(name: pX509_NAME; loc: integer): pX509_NAME_ENTRY; cdecl; 1178 function X509_NAME_get_text_by_NID(name: pX509_NAME; nid: integer; buf: PCharacter; 1179 len: integer): integer; cdecl; 1180 1181 // X.509 function 1182 function X509_new: pX509; cdecl; 1183 procedure X509_free(a: pX509); cdecl; 1184 function X509_print(bp: pBIO; x: pX509): integer; cdecl; 1185 function X509_set_version(x: pX509; version: longint): integer; cdecl; 1186 function X509_get_version(x: pX509): integer; 1187 function X509_get_serialNumber(x: pX509): pASN1_INTEGER; cdecl; 1188 function X509_load_cert_file(ctx: pX509_LOOKUP; const filename: PCharacter; 1189 _type: integer): integer; cdecl; 1190 function X509_get_issuer_name(a: pX509): pX509_NAME; cdecl; 1191 function X509_get_subject_name(a: pX509): pX509_NAME; cdecl; 1192 function X509_get_notBefore(a: pX509): pASN1_TIME; 1193 function X509_get_notAfter(a: pX509): pASN1_TIME; 1194 function X509_get1_email(x: pX509): pSTACK; cdecl; 1195 function X509_get_pubkey(a: pX509): pEVP_PKEY; cdecl; 1196 function X509_check_private_key(x509: pX509; pkey: pEVP_PKEY): integer; cdecl; 1197 function X509_check_purpose(x: pX509; id: integer; ca: integer): integer; cdecl; 1198 function X509_issuer_and_serial_cmp(a: pX509; b: pX509): integer; cdecl; 1199 function X509_issuer_and_serial_hash(a: pX509): cardinal; cdecl; 1200 function X509_gmtime_adj(s: pASN1_TIME; adj: longint): pASN1_TIME; cdecl; 1201 function X509_verify_cert(ctx: pX509_STORE_CTX): integer; cdecl; 1202 function X509_verify_cert_error_string(n: longint): PCharacter; cdecl; 1203 procedure X509_email_free(sk: pSTACK); cdecl; 1204 function X509_get_ext(x: pX509; loc: integer): pX509_EXTENSION; cdecl; 1205 function X509_get_ext_by_NID(x: pX509; nid, lastpos: integer): integer; cdecl; 1206 function X509_get_ext_d2i(x: pX509; nid: integer; var crit, 1207 idx: integer): pointer; cdecl; 1208 function X509V3_EXT_d2i(ext: pX509_EXTENSION): pointer; cdecl; 1209 function X509V3_EXT_i2d(ext_nid: integer; crit: integer; ext_struc: pointer): 1210 pX509_EXTENSION; cdecl; 1211 function X509V3_EXT_conf_nid(conf: pointer; ctx: pointer; 1212 ext_nid: integer; value: PCharacter): pX509_EXTENSION; cdecl; 1213 1214 function X509_sign(x: pX509; pkey: pEVP_PKEY; const md: pEVP_MD): integer; cdecl; 1215 function X509_set_issuer_name(x: pX509; name: pX509_NAME): integer; cdecl; 1216 function X509_set_subject_name(x: pX509; name: pX509_NAME): integer; cdecl; 1217 procedure X509V3_set_ctx(ctx: pX509V3_CTX; issuer: pX509; subject: pX509; 1218 req: pX509_REQ; crl: pX509_CRL; flags: integer); 1219 procedure X509_SIG_free(a: pX509_SIG); cdecl; 1220 1221 function X509_PUBKEY_get(key: pointer): pEVP_PKEY; cdecl; 1222 1223 function X509_REQ_new: pX509_REQ; cdecl; 1224 procedure X509_REQ_free(req: pX509_REQ); cdecl; 1225 function X509_REQ_set_version(req: pX509_REQ; version: longint): integer; cdecl; 1226 function X509_REQ_get_version(req: pX509_REQ): integer; 1227 function X509_REQ_set_subject_name(req: pX509_REQ; name: pX509_NAME): integer; cdecl; 1228 function X509_REQ_get_subject_name(req: pX509_REQ): pX509_NAME; 1229 function X509_REQ_add1_attr_by_txt(req: pX509_REQ; attrname: PCharacter; 1230 asn1_type: integer; bytes: pointer; len: integer): integer; cdecl; 1231 function X509_REQ_add_extensions(req: pX509_REQ; 1232 exts: pSTACK_OFX509_EXTENSION): integer; cdecl; 1233 function X509_REQ_set_pubkey(req: pX509_REQ; pkey: pEVP_PKEY): integer; cdecl; 1234 function X509_REQ_get_pubkey(req: pX509_REQ): pEVP_PKEY; cdecl; 1235 function X509_REQ_sign(req: pX509_REQ; pkey: pEVP_PKEY; const md: pEVP_MD): integer; cdecl; 1236 1237 // X.509 collections 1238 function X509_STORE_new: pX509_STORE; cdecl; 1239 procedure X509_STORE_free(v: pX509_STORE); cdecl; 1240 function X509_STORE_add_cert(ctx: pX509_STORE; x: pX509): integer; cdecl; 1241 function X509_STORE_add_lookup(v: pX509_STORE; m: pX509_LOOKUP_METHOD): 1242 pX509_LOOKUP; cdecl; 1243 function X509_STORE_CTX_new: pX509_STORE_CTX; cdecl; 1244 procedure X509_STORE_CTX_free(ctx: pX509_STORE); cdecl; 1245 procedure X509_STORE_CTX_init(ctx: pX509_STORE_CTX; store: pX509_STORE; 1246 x509: pX509; chain: pSTACK_OFX509); cdecl; 1247 function X509_STORE_CTX_get_current_cert(ctx: pX509_STORE_CTX): pX509; cdecl; 1248 function X509_STORE_CTX_get_error(ctx: pX509_STORE_CTX): integer; cdecl; 1249 function X509_STORE_CTX_get_error_depth(ctx: pX509_STORE_CTX): integer; cdecl; 1250 1251 function X509_LOOKUP_new(method: pX509_LOOKUP_METHOD): pX509_LOOKUP; cdecl; 1252 function X509_LOOKUP_init(ctx: pX509_LOOKUP): integer; cdecl; 1253 procedure X509_LOOKUP_free(ctx: pX509_LOOKUP); cdecl; 1254 function X509_LOOKUP_ctrl(ctx: pX509_LOOKUP; cmd: integer; const argc: PCharacter; 1255 argl: longint; ret: pointer): integer; cdecl; 1256 function X509_LOOKUP_file: pX509_LOOKUP_METHOD; cdecl; 1257 1258 // PEM functions 1259 function PEM_read_bio_RSAPrivateKey(bp: pBIO; var x: pRSA; 1260 cb: TPWCallbackFunction; u: pointer): pRSA; cdecl; 1261 function PEM_write_bio_RSAPrivateKey(bp: pBIO; x: pRSA; const enc: pEVP_CIPHER; 1262 kstr: PCharacter; klen: integer; cb: TPWCallbackFunction; 1263 u: pointer): integer; cdecl; 1264 function PEM_read_bio_RSAPublicKey(bp: pBIO; var x: pRSA; 1265 cb: TPWCallbackFunction; u: pointer): pRSA; cdecl; 1266 function PEM_write_bio_RSAPublicKey(bp: pBIO; x: pRSA): integer; cdecl; 1267 1268 function PEM_read_bio_DSAPrivateKey(bp: pBIO; var dsa: pDSA; 1269 cb: TPWCallbackFunction; data: pointer): pDSA; cdecl; 1270 function PEM_write_bio_DSAPrivateKey(bp: pBIO; dsa: pDSA; const enc: pEVP_CIPHER; 1271 kstr: PCharacter; klen: integer; cb: TPWCallbackFunction; 1272 data: pointer): integer; cdecl; 1273 1274 function PEM_read_bio_PUBKEY(bp: pBIO; var x: pEVP_PKEY; 1275 cb: TPWCallbackFunction; u: pointer): pEVP_PKEY; cdecl; 1276 function PEM_write_bio_PUBKEY(bp: pBIO; x: pEVP_PKEY): integer; cdecl; 1277 1278 function PEM_read_bio_X509(bp: pBIO; var x: pX509; cb: TPWCallbackFunction; 1279 u: pointer): pX509; cdecl; 1280 function PEM_write_bio_X509(bp: pBIO; x: pX509): integer; cdecl; 1281 function PEM_read_bio_X509_AUX(bp: pBIO; var x: pX509; cb: TPWCallbackFunction; 1282 u: pointer): pX509; cdecl; 1283 function PEM_write_bio_X509_AUX(bp: pBIO; x: pX509): integer; cdecl; 1284 function PEM_read_bio_X509_REQ(bp: pBIO; var x: pX509_REQ; cb: TPWCallbackFunction; 1285 u: pointer): pX509_REQ; cdecl; 1286 function PEM_write_bio_X509_REQ(bp: pBIO; x: pX509_REQ): integer; cdecl; 1287 function PEM_read_bio_X509_CRL(bp: pBIO; var x: pX509_CRL; cb: TPWCallbackFunction; 1288 u: pointer): pX509_CRL; cdecl; 1289 function PEM_write_bio_X509_CRL(bp: pBIO; x: pX509_CRL): integer; cdecl; 1290 1291 function PEM_read_bio_PrivateKey(bp: pBIO; var x: pEVP_PKEY; 1292 cb: TPWCallbackFunction; u: pointer): pEVP_PKEY; cdecl; 1293 function PEM_write_bio_PrivateKey(bp: pBIO; x: pEVP_PKEY; 1294 const enc: pEVP_CIPHER; kstr: PCharacter; klen: Integer; cb: TPWCallbackFunction; 1295 u: pointer): integer; cdecl; 1296 function PEM_write_bio_PKCS7(bp: pBIO; x: pPKCS7): integer; cdecl; 1297 1298 // PKCS#5 functions 1299 function PKCS5_PBKDF2_HMAC_SHA1(pass: PCharacter; passlen: integer; 1300 salt: pointer; saltlen: integer; iter: integer; 1301 keylen: integer; u: pointer): integer; cdecl; 1302 1303 // PKCS#7 functions 1304 function PKCS7_sign(signcert: pX509; pkey: pEVP_PKEY; certs: pointer; 1305 data: pBIO; flags: integer): pPKCS7; cdecl; 1306 function PKCS7_get_signer_info(p7: pPKCS7): pSTACK_OFPKCS7_SIGNER_INFO; cdecl; 1307 function PKCS7_verify(p7: pPKCS7; certs: pointer; store: pSTACK_OFX509; 1308 indata: pBIO; _out: pBIO; flags: integer): integer; cdecl; 1309 function PKCS7_get0_signers(p7: pPKCS7; certs: pSTACK_OFX509; 1310 flags: integer): pSTACK_OFX509; cdecl; 1311 function PKCS7_signatureVerify(bio: pBIO; p7: pPKCS7; si: pPKCS7_SIGNER_INFO; 1312 x509: pX509): integer; cdecl; 1313 function PKCS7_encrypt(certs: pSTACK_OFX509; _in: pBIO; 1314 cipher: pEVP_CIPHER; flags: integer): pPKCS7; cdecl; 1315 function PKCS7_decrypt(p7: pPKCS7; pkey: pEVP_PKEY; cert: pX509; 1316 data: pBIO; flags: integer): integer; cdecl; 1317 procedure PKCS7_free(p7: pPKCS7); cdecl; 1318 function PKCS7_ctrl(p7: pPKCS7; cmd: integer; larg: longint; 1319 parg: PCharacter): longint; cdecl; 1320 function PKCS7_get_detached(p7: pPKCS7): pointer; 1321 function PKCS7_dataInit(p7: pPKCS7; bio: pBIO): pBIO; cdecl; 1322 // PKCS#7 DER/PEM to internal conversion function 1323 { 1324 d2i_PKCS7_DIGEST @737 1325 d2i_PKCS7_ENCRYPT @738 1326 d2i_PKCS7_ENC_CONTENT @739 1327 d2i_PKCS7_ENVELOPE @740 1328 d2i_PKCS7_ISSUER_AND_SERIAL @741 1329 d2i_PKCS7_RECIP_INFO @742 1330 d2i_PKCS7_SIGNED @743 1331 d2i_PKCS7_SIGNER_INFO @744 1332 d2i_PKCS7_SIGN_ENVELOPE @745 } 1333 1334 function EVP_PKCS82PKEY(p8 : pPKCS8_Priv_Key_Info) : pEVP_PKEY; cdecl; 1335 function PKCS8_decrypt(p8: pX509_SIG; Pass: PCharacter; PassLen: integer): pPKCS8_Priv_Key_Info; cdecl; 1336 procedure PKCS8_PRIV_KEY_INFO_free(var a: pPKCS8_Priv_Key_Info); cdecl; 1337 1338 function PKCS12_new: pPKCS12; cdecl; 1339 procedure PKCS12_free(a: pPKCS12); cdecl; 1340 function PKCS12_parse(p12: pPKCS12; pass: PCharacter; var pkey: pEVP_PKEY; 1341 var cert: pX509; var ca: pSTACK_OFX509): integer; cdecl; 1342 1343 function AES_set_decrypt_key(userKey: PCharacter; bits: integer; key: pAES_KEY): integer; cdecl; 1344 1345 (* 1346 void AES_cbc_encrypt(const unsigned char *in, unsigned char *out, 1347 size_t len, const AES_KEY *key, 1348 unsigned char *ivec, const int enc) 1349 *) 1350 procedure AES_cbc_encrypt(buffer: PCharacter; u: PCharacter; length: longint; 1351 key: pAES_KEY; ivec: pointer; enc: integer); cdecl; 1352 1353 function PEM_read_bio_PKCS7(bp: pBIO; data: pointer; 1354 cb: TPWCallbackFunction; u: pointer): pPKCS7; cdecl; 1355 1356 // SMIME function 1357 function SMIME_write_PKCS7(bp: pBIO; p7: pPKCS7; data: pBIO; 1358 flags: integer): integer; cdecl; 1359 function SMIME_read_PKCS7(bp: pBIO; var bcont: pBIO): pPKCS7; cdecl; 1360 1361 1362 //2016/02/19 19:39 1363 procedure EVP_MD_CTX_init(ctx : PEVP_MD_CTX) cdecl; 1364 function EVP_MD_CTX_cleanup(ctx : PEVP_MD_CTX):Integer;cdecl; 1365 procedure BIO_set_flags(a:PBIO;Flags:Integer);cdecl; 1366 function AES_set_encrypt_key(const userKey:Pointer; const bits:integer;key:PAES_KEY):Integer;cdecl; 1367 1368 //设置解密密钥,同样适用字符缓冲区 1369 //int AES_set_decrypt_key( 1370 // const unsigned char *userKey, 1371 // const int bits, 1372 // AES_KEY *key); 1373 1374 // RSA *PEM_read_bio_RSA_PUBKEY(BIO *bp, RSA **x,pem_password_cb *cb, void *u); 1375 function PEM_read_bio_RSA_PUBKEY(bp: pBIO;var x: pRSA;cb:Pointer;u:pointer):pRSA;cdecl; 1376 1377 1378 //int MD5_Init(MD5_CTX *c); 1379 function MD5_Init(var c:MD5_CTX):Integer;cdecl; //2016/02/28 11:12 1380 1381 //int MD5_Update(MD5_CTX *c, const void *data, size_t len); 1382 function MD5_Update(var c: MD5_CTX;const data:Pointer;len:Integer):Integer;cdecl; //2016/02/28 11:12 1383 1384 1385 //int MD5_Final(unsigned char *md, MD5_CTX *c); 1386 function MD5_Final(md:Pointer;var c: MD5_CTX):Integer;cdecl; //2016/02/28 11:12 1387 1388 1389 //int RAND_bytes(unsigned char *buf,int num); 1390 function RAND_bytes(OutBuf:Pointer;num:Integer):Integer;cdecl;//2016/02/28 14:30 1391 1392 1393 //unsigned char *SHA256(const unsigned char *d, size_t n, unsigned char *md); 1394 function SHA256(const d:PAnsichar;n:Integer;md:PAnsichar):PAnsichar;cdecl;//2016/02/28 15:20 1395 1396 //int SHA256_Init(SHA256_CTX *c); 1397 function SHA256_Init(c:pSHA256_CTX):Integer;cdecl;//2016/02/28 20:05 1398 1399 //int SHA256_Update(SHA256_CTX *c, const void *data, size_t len); 1400 function SHA256_Update(c:pSHA256_CTX;const data:Pointer;len:Cardinal):Integer;cdecl; //2016/02/28 20:07 1401 1402 //int SHA256_Final(unsigned char *md, SHA256_CTX *c); 1403 function SHA256_Final(md:Pointer;c:pSHA256_CTX):Integer;cdecl; //2016/02/28 20:08 1404 1405 1406 (* 1407 unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len, 1408 const unsigned char *d, size_t n, unsigned char *md, 1409 unsigned int *md_len); 1410 *) 1411 //function HMAC(const evp_md:pEVP_MD; 1412 // const key:Pointer; 1413 // key_len:Integer; 1414 // const d:PAnsichar; 1415 // n:Cardinal; 1416 // md:PAnsichar; 1417 // md_len:Cardinal):PAnsichar;cdecl;//2016/02/29 18:11 1418 1419 function HMAC(evp: pEVP_MD; key: PByte; key_len: integer; 1420 data: PByte; data_len: integer; 1421 md: PByte; var md_len: integer): PByte; cdecl; 1422 1423 //const EVP_MD *EVP_sha512(void); 1424 function EVP_sha512():pEVP_MD;cdecl;//2016/02/29 18:16 1425 1426 //const EVP_MD *EVP_sha224(void); 1427 function EVP_sha224():pEVP_MD;cdecl;//2016/02/29 18:19 1428 1429 //const EVP_MD *EVP_sha256(void); 1430 function EVP_sha256():pEVP_MD;cdecl; //2016/02/29 18:19 1431 1432 //const EVP_MD *EVP_sha384(void); 1433 function EVP_sha384():pEVP_MD;cdecl;//2016/03/01 00:30 1434 1435 1436 //int HMAC_Init(HMAC_CTX *ctx, const void *key, int len, const EVP_MD *md); 1437 function HMAC_Init(ctx:pHMAC_CTX; const key:PAnsichar;len:Integer;const md:pEVP_MD):Integer;cdecl;//2016/02/29 23:53 1438 1439 //int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len,const EVP_MD *md, ENGINE *impl); 1440 function HMAC_Init_ex(ctx:pHMAC_CTX;const key:PAnsichar;Len:Integer;const md:pEVP_MD; impl:pENGINE):Integer;cdecl;//2016/03/01 00:00 1441 1442 //int HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, size_t len); 1443 function HMAC_Update(ctx:pHMAC_CTX;const data:PAnsichar;len:Cardinal):Integer;cdecl;//2016/03/01 00:05 1444 1445 //int HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len); 1446 function HMAC_Final(ctx:pHMAC_CTX; md:PAnsichar;len:PInteger):Integer;cdecl;//2016/03/01 00:05 1447 1448 //void HMAC_CTX_init(HMAC_CTX *ctx); 1449 procedure HMAC_CTX_init(ctx:pHMAC_CTX);cdecl;//2016/03/01 00:06 1450 1451 //void HMAC_CTX_cleanup(HMAC_CTX *ctx); 1452 procedure HMAC_CTX_cleanup(ctx:PHMAC_CTX);cdecl;//2016/03/01 00:06 1453 1454 1455 implementation 1456 1457 uses 1458 Windows, SysUtils; 1459 1460 const 1461 LIBEAY_DLL_NAME = 'libeay32.dll'; 1462 //LIBEAY_DLL_NAME = 'libeay32_SF.dll'; 1463 1464 1465 type 1466 TOpenSSL_InitFunction = procedure; cdecl; 1467 1468 function SSLeay: cardinal; external LIBEAY_DLL_NAME; 1469 function SSLeay_version; external LIBEAY_DLL_NAME; 1470 // OpenSSL_add_all_algorithms prototype changed between OpenSSL version 0.9.6 and 0.9.7 1471 // See: http://www.openssl.org/news/changelog.html 1472 procedure OpenSSL_add_all_algorithms_old; external LIBEAY_DLL_NAME name 'OpenSSL_add_all_algorithms'; 1473 procedure OpenSSL_add_all_algorithms_noconf; external LIBEAY_DLL_NAME; 1474 1475 procedure OpenSSL_add_all_algorithms; 1476 var 1477 hLibeayDLL: THandle; 1478 Add_all_algorithms_procedure: TOpenSSL_InitFunction; 1479 begin 1480 hLibeayDLL := GetModuleHandle(LIBEAY_DLL_NAME); 1481 if hLibeayDLL = 0 then 1482 raise Exception.Create('libeay32.dll not loaded'); 1483 // Try to load new version 1484 @Add_all_algorithms_procedure := GetProcAddress(hLibeayDLL, 'OPENSSL_add_all_algorithms_noconf'); 1485 // Fallback to old version 1486 if @Add_all_algorithms_procedure = nil then 1487 @Add_all_algorithms_procedure := GetProcAddress(hLibeayDLL, 'OpenSSL_add_all_algorithms'); 1488 if @Add_all_algorithms_procedure <> nil then 1489 begin 1490 Add_all_algorithms_procedure; 1491 end 1492 else 1493 raise Exception.Create('OpenSSL_add_all_algorithms procedure not defined in libeay32.dll'); 1494 end; 1495 1496 procedure OpenSSL_add_all_ciphers; external LIBEAY_DLL_NAME; 1497 procedure OpenSSL_add_all_digests; external LIBEAY_DLL_NAME; 1498 procedure EVP_cleanup; external LIBEAY_DLL_NAME; 1499 1500 function ERR_get_error: cardinal; external LIBEAY_DLL_NAME; 1501 function ERR_peek_error: cardinal; external LIBEAY_DLL_NAME; 1502 function ERR_peek_last_error: cardinal; external LIBEAY_DLL_NAME; 1503 function ERR_error_string; external LIBEAY_DLL_NAME; 1504 procedure ERR_clear_error; external LIBEAY_DLL_NAME; 1505 procedure ERR_load_crypto_strings; external LIBEAY_DLL_NAME; 1506 procedure ERR_free_strings; external LIBEAY_DLL_NAME; 1507 1508 function CRYPTO_malloc; external LIBEAY_DLL_NAME; 1509 function CRYPTO_realloc; external LIBEAY_DLL_NAME; 1510 function CRYPTO_remalloc; external LIBEAY_DLL_NAME; 1511 procedure CRYPTO_free; external LIBEAY_DLL_NAME; 1512 1513 // Not in DLL 1514 function OPENSSL_malloc(length: longint): pointer; 1515 begin 1516 OPENSSL_malloc := CRYPTO_malloc(length, nil, 0); 1517 end; 1518 function OPENSSL_realloc(address: PCharacter; length: longint): pointer; 1519 begin 1520 OPENSSL_realloc := CRYPTO_realloc(address, length, nil, 0); 1521 end; 1522 function OPENSSL_remalloc(var address: pointer; length: longint): pointer; 1523 begin 1524 OPENSSL_remalloc := CRYPTO_remalloc(address, length, nil, 0); 1525 end; 1526 procedure OPENSSL_free(address: pointer); 1527 begin 1528 CRYPTO_free(address); 1529 end; 1530 1531 function BN_new; external LIBEAY_DLL_NAME; 1532 procedure BN_init; external LIBEAY_DLL_NAME; 1533 procedure BN_clear; external LIBEAY_DLL_NAME; 1534 procedure BN_free; external LIBEAY_DLL_NAME; 1535 procedure BN_clear_free; external LIBEAY_DLL_NAME; 1536 1537 procedure BN_set_params; external LIBEAY_DLL_NAME; 1538 function BN_get_params; external LIBEAY_DLL_NAME; 1539 1540 function BN_options; external LIBEAY_DLL_NAME; 1541 1542 function BN_CTX_new; external LIBEAY_DLL_NAME; 1543 procedure BN_CTX_init; external LIBEAY_DLL_NAME; 1544 procedure BN_CTX_start; external LIBEAY_DLL_NAME; 1545 function BN_CTX_get; external LIBEAY_DLL_NAME; 1546 procedure BN_CTX_end; external LIBEAY_DLL_NAME; 1547 procedure BN_CTX_free; external LIBEAY_DLL_NAME; 1548 1549 function BN_MONT_CTX_new; external LIBEAY_DLL_NAME; 1550 procedure BN_MONT_CTX_init; external LIBEAY_DLL_NAME; 1551 function BN_MONT_CTX_set; external LIBEAY_DLL_NAME; 1552 function BN_MONT_CTX_copy; external LIBEAY_DLL_NAME; 1553 procedure BN_MONT_CTX_free; external LIBEAY_DLL_NAME; 1554 function BN_mod_mul_montgomery; external LIBEAY_DLL_NAME; 1555 function BN_from_montgomery; external LIBEAY_DLL_NAME; 1556 function BN_to_montgomery(r, a: pBIGNUM; m_ctx: pBN_MONT_CTX; ctx: pBN_CTX): integer; 1557 begin 1558 result := BN_mod_mul_montgomery(r, a, @(m_ctx^.RR), m_ctx, ctx); 1559 end; 1560 1561 procedure BN_RECP_CTX_init; external LIBEAY_DLL_NAME; 1562 function BN_RECP_CTX_set; external LIBEAY_DLL_NAME; 1563 function BN_RECP_CTX_new; external LIBEAY_DLL_NAME; 1564 procedure BN_RECP_CTX_free; external LIBEAY_DLL_NAME; 1565 function BN_div_recp; external LIBEAY_DLL_NAME; 1566 function BN_mod_mul_reciprocal; external LIBEAY_DLL_NAME; 1567 1568 function BN_BLINDING_new; external LIBEAY_DLL_NAME; 1569 function BN_BLINDING_update; external LIBEAY_DLL_NAME; 1570 procedure BN_BLINDING_free; external LIBEAY_DLL_NAME; 1571 function BN_BLINDING_convert; external LIBEAY_DLL_NAME; 1572 function BN_BLINDING_invert; external LIBEAY_DLL_NAME; 1573 1574 function BN_copy; external LIBEAY_DLL_NAME; 1575 function BN_dup; external LIBEAY_DLL_NAME; 1576 1577 function int2bin(n: integer): integer; 1578 begin 1579 result := ((cardinal(n) shr 24) and $000000FF) or 1580 ((cardinal(n) shr 8) and $0000FF00) or 1581 ((cardinal(n) shl 8) and $00FF0000) or 1582 ((cardinal(n) shl 24) and $FF000000); 1583 end; 1584 1585 function BN_bn2bin; external LIBEAY_DLL_NAME; 1586 function BN_bin2bn; external LIBEAY_DLL_NAME; 1587 1588 function BN_bn2hex; external LIBEAY_DLL_NAME; 1589 function BN_bn2dec; external LIBEAY_DLL_NAME; 1590 function BN_hex2bn; external LIBEAY_DLL_NAME; 1591 function BN_dec2bn; external LIBEAY_DLL_NAME; 1592 function BN_bn2mpi; external LIBEAY_DLL_NAME; 1593 function BN_mpi2bn; external LIBEAY_DLL_NAME; 1594 function BN_print; external LIBEAY_DLL_NAME; 1595 1596 function BN_zero(n: pBIGNUM): integer; 1597 begin 1598 result := BN_set_word(n, 0) 1599 end; 1600 1601 function BN_one(n: pBIGNUM): integer; 1602 begin 1603 result := BN_set_word(n, 1) 1604 end; 1605 1606 function BN_value_one; external LIBEAY_DLL_NAME; 1607 function BN_set_word; external LIBEAY_DLL_NAME; 1608 function BN_get_word; external LIBEAY_DLL_NAME; 1609 1610 function BN_cmp; external LIBEAY_DLL_NAME; 1611 function BN_ucmp; external LIBEAY_DLL_NAME; 1612 1613 //function BN_is_zero(a: pBIGNUM): boolean; 1614 //begin 1615 //result := (a^.top = 0) or BN_is_word(a, 0); 1616 //end; 1617 1618 //function BN_is_one(a: pBIGNUM): boolean; 1619 //begin 1620 // define BN_is_one(a) (BN_is_word((a),1)) 1621 //result := BN_is_word(a, 1); 1622 //end; 1623 1624 //function BN_is_word(a: pBIGNUM; w: BN_ULONG): boolean; 1625 //begin 1626 //define BN_is_word(a,w) (((a)->top == 1) && ((a)->d[0] == (BN_ULONG)(w))) 1627 //result := (a^.top = 1) and (a^.d[0] = w); 1628 //end; 1629 1630 //function BN_is_odd(a: pBIGNUM): boolean; 1631 //begin 1632 //result := (a^.top > 0) and ((a^.d[0] and $01) = $01); 1633 //end; 1634 1635 function BN_num_bytes(const a: pBIGNUM): integer; 1636 begin 1637 result := (BN_num_bits(a) + 7) div 8; 1638 end; 1639 1640 function BN_num_bits; external LIBEAY_DLL_NAME; 1641 function BN_num_bits_word; external LIBEAY_DLL_NAME; 1642 1643 function BN_add; external LIBEAY_DLL_NAME; 1644 function BN_sub; external LIBEAY_DLL_NAME; 1645 function BN_uadd; external LIBEAY_DLL_NAME; 1646 function BN_usub; external LIBEAY_DLL_NAME; 1647 function BN_mul; external LIBEAY_DLL_NAME; 1648 function BN_sqr; external LIBEAY_DLL_NAME; 1649 function BN_div; external LIBEAY_DLL_NAME; 1650 1651 function BN_mod(rem: pBIGNUM; const a, m: pBIGNUM; ctx: pBN_CTX): integer; 1652 begin 1653 result := BN_div(nil, rem, a, m, ctx); 1654 end; 1655 1656 function BN_exp; external LIBEAY_DLL_NAME; 1657 function BN_mod_exp; external LIBEAY_DLL_NAME; 1658 function BN_gcd; external LIBEAY_DLL_NAME; 1659 function BN_nnmod; external LIBEAY_DLL_NAME; 1660 function BN_mod_add; external LIBEAY_DLL_NAME; 1661 function BN_mod_sub; external LIBEAY_DLL_NAME; 1662 function BN_mod_mul; external LIBEAY_DLL_NAME; 1663 function BN_mod_sqr; external LIBEAY_DLL_NAME; 1664 function BN_reciprocal; external LIBEAY_DLL_NAME; 1665 1666 function BN_mod_exp2_mont; external LIBEAY_DLL_NAME; 1667 function BN_mod_exp_mont; external LIBEAY_DLL_NAME; 1668 function BN_mod_exp_mont_word; external LIBEAY_DLL_NAME; 1669 function BN_mod_exp_simple; external LIBEAY_DLL_NAME; 1670 function BN_mod_exp_recp; external LIBEAY_DLL_NAME; 1671 function BN_mod_inverse; external LIBEAY_DLL_NAME; 1672 1673 function BN_add_word; external LIBEAY_DLL_NAME; 1674 function BN_sub_word; external LIBEAY_DLL_NAME; 1675 function BN_mul_word; external LIBEAY_DLL_NAME; 1676 function BN_div_word; external LIBEAY_DLL_NAME; 1677 function BN_mod_word; external LIBEAY_DLL_NAME; 1678 function bn_mul_words; external LIBEAY_DLL_NAME; 1679 function bn_mul_add_words; external LIBEAY_DLL_NAME; 1680 procedure bn_sqr_words; external LIBEAY_DLL_NAME; 1681 function bn_div_words; external LIBEAY_DLL_NAME; 1682 function bn_add_words; external LIBEAY_DLL_NAME; 1683 function bn_sub_words; external LIBEAY_DLL_NAME; 1684 function bn_expand2; external LIBEAY_DLL_NAME; 1685 1686 function BN_set_bit; external LIBEAY_DLL_NAME; 1687 function BN_clear_bit; external LIBEAY_DLL_NAME; 1688 function BN_is_bit_set; external LIBEAY_DLL_NAME; 1689 function BN_mask_bits; external LIBEAY_DLL_NAME; 1690 function BN_lshift; external LIBEAY_DLL_NAME; 1691 function BN_lshift1; external LIBEAY_DLL_NAME; 1692 function BN_rshift; external LIBEAY_DLL_NAME; 1693 function BN_rshift1; external LIBEAY_DLL_NAME; 1694 1695 function BN_generate_prime; external LIBEAY_DLL_NAME; 1696 function BN_is_prime; external LIBEAY_DLL_NAME; 1697 function BN_is_prime_fasttest; external LIBEAY_DLL_NAME; 1698 1699 function BN_rand; external LIBEAY_DLL_NAME; 1700 function BN_pseudo_rand; external LIBEAY_DLL_NAME; 1701 function BN_rand_range; external LIBEAY_DLL_NAME; 1702 function BN_pseudo_rand_range; external LIBEAY_DLL_NAME; 1703 function BN_bntest_rand; external LIBEAY_DLL_NAME; 1704 1705 function BN_to_ASN1_INTEGER; external LIBEAY_DLL_NAME; 1706 function BN_to_ASN1_ENUMERATED; external LIBEAY_DLL_NAME; 1707 1708 function ASN1_IA5STRING_new; external LIBEAY_DLL_NAME; 1709 procedure ASN1_INTEGER_free; external LIBEAY_DLL_NAME; 1710 function ASN1_INTEGER_get; external LIBEAY_DLL_NAME; 1711 procedure ASN1_STRING_set_default_mask; external LIBEAY_DLL_NAME; 1712 function ASN1_STRING_get_default_mask; external LIBEAY_DLL_NAME; 1713 function ASN1_TIME_print; external LIBEAY_DLL_NAME; 1714 1715 function OBJ_obj2nid; external LIBEAY_DLL_NAME; 1716 function OBJ_txt2nid; external LIBEAY_DLL_NAME; 1717 function OBJ_txt2obj; external LIBEAY_DLL_NAME; 1718 1719 function sk_new_null; external LIBEAY_DLL_NAME; 1720 procedure sk_free; external LIBEAY_DLL_NAME; 1721 function sk_push; external LIBEAY_DLL_NAME; 1722 function sk_num; external LIBEAY_DLL_NAME; 1723 function sk_value; external LIBEAY_DLL_NAME; 1724 1725 function BIO_new; external LIBEAY_DLL_NAME; 1726 function BIO_new_file; external LIBEAY_DLL_NAME; 1727 function BIO_set; external LIBEAY_DLL_NAME; 1728 function BIO_free; external LIBEAY_DLL_NAME; 1729 procedure BIO_vfree; external LIBEAY_DLL_NAME; 1730 procedure BIO_free_all; external LIBEAY_DLL_NAME; 1731 function BIO_push; external LIBEAY_DLL_NAME; 1732 function BIO_pop; external LIBEAY_DLL_NAME; 1733 function BIO_ctrl; external LIBEAY_DLL_NAME; 1734 1735 function BIO_read; external LIBEAY_DLL_NAME; 1736 function BIO_gets; external LIBEAY_DLL_NAME; 1737 function BIO_write; external LIBEAY_DLL_NAME; 1738 function BIO_puts; external LIBEAY_DLL_NAME; 1739 1740 function BIO_flush(b: pBIO): integer; 1741 begin 1742 result := BIO_ctrl(b, BIO_CTRL_FLUSH, 0, nil); 1743 end; 1744 1745 function BIO_s_mem; external LIBEAY_DLL_NAME; 1746 function BIO_f_base64; external LIBEAY_DLL_NAME; 1747 procedure BIO_set_mem_eof_return; external LIBEAY_DLL_NAME; 1748 1749 function BIO_get_mem_data(b: pBIO; var pp: PCharacter): integer; cdecl; 1750 begin 1751 result := BIO_ctrl(b, BIO_CTRL_INFO, 0, @pp); 1752 end; 1753 1754 procedure BIO_set_mem_buf; external LIBEAY_DLL_NAME; 1755 1756 //procedure BIO_get_mem_ptr; external LIBEAY_DLL_NAME; 1757 function BIO_get_mem_ptr(b: pBIO; pp: PPBUF_MEM):Integer; 1758 const 1759 BIO_C_GET_BUF_MEM_PTR = 115; 1760 begin 1761 Result := BIO_ctrl(b,BIO_C_GET_BUF_MEM_PTR, 0, pp); 1762 end; 1763 1764 function BIO_new_mem_buf; external LIBEAY_DLL_NAME; 1765 function BIO_s_file; external LIBEAY_DLL_NAME; 1766 1767 // Not in DLL 1768 function BIO_get_md_ctx(bp: pBIO; mdcp: Pointer): Longint; 1769 begin 1770 result := BIO_ctrl(bp, BIO_C_GET_MD_CTX, 0, mdcp); 1771 end; 1772 1773 function BIO_reset(bp: pBIO): integer; 1774 begin 1775 result := BIO_ctrl(bp, BIO_CTRL_RESET, 0, nil); 1776 end; 1777 1778 function BIO_eof(bp: pBIO): integer; 1779 begin 1780 result := BIO_ctrl(bp, BIO_CTRL_EOF, 0, nil); 1781 end; 1782 1783 function BIO_set_close(bp: pBIO; c: integer): integer; 1784 begin 1785 result := BIO_ctrl(bp, BIO_CTRL_SET_CLOSE, c, nil); 1786 end; 1787 1788 function BIO_get_close(bp: pBIO): integer; 1789 begin 1790 result := BIO_ctrl(bp, BIO_CTRL_GET_CLOSE, 0, nil); 1791 end; 1792 1793 function BIO_pending(bp: pBIO): integer; 1794 begin 1795 result := BIO_ctrl(bp, BIO_CTRL_PENDING, 0, nil); 1796 end; 1797 1798 function BIO_wpending(bp: pBIO): integer; 1799 begin 1800 result := BIO_ctrl(bp, BIO_CTRL_WPENDING, 0, nil); 1801 end; 1802 1803 function BIO_read_filename(bp: pBIO; filename: PCharacter): integer; 1804 begin 1805 result := BIO_ctrl(bp, BIO_C_SET_FILENAME, BIO_CLOSE or BIO_FP_READ, filename); 1806 end; 1807 1808 function BIO_write_filename(bp: pBIO; filename: PCharacter): integer; 1809 begin 1810 result := BIO_ctrl(bp, BIO_C_SET_FILENAME, BIO_CLOSE or BIO_FP_WRITE, filename); 1811 end; 1812 1813 function BIO_append_filename(bp: pBIO; filename: PCharacter): integer; 1814 begin 1815 result := BIO_ctrl(bp, BIO_C_SET_FILENAME, BIO_CLOSE or BIO_FP_APPEND, filename); 1816 end; 1817 1818 function BIO_rw_filename(bp: pBIO; filename: PCharacter): integer; 1819 begin 1820 result := BIO_ctrl(bp, BIO_C_SET_FILENAME, BIO_CLOSE or BIO_FP_READ or BIO_FP_WRITE, filename); 1821 end; 1822 1823 function i2d_ASN1_TIME; external LIBEAY_DLL_NAME; 1824 function d2i_ASN1_TIME; external LIBEAY_DLL_NAME; 1825 function d2i_X509_REQ_bio; external LIBEAY_DLL_NAME; 1826 function i2d_X509_REQ_bio; external LIBEAY_DLL_NAME; 1827 function d2i_X509_bio; external LIBEAY_DLL_NAME; 1828 function i2d_X509_bio; external LIBEAY_DLL_NAME; 1829 function d2i_PrivateKey_bio; external LIBEAY_DLL_NAME; 1830 function i2d_PrivateKey_bio; external LIBEAY_DLL_NAME; 1831 function d2i_PUBKEY_bio; external LIBEAY_DLL_NAME; 1832 function i2d_PUBKEY_bio; external LIBEAY_DLL_NAME; 1833 function d2i_PKCS12_bio; external LIBEAY_DLL_NAME; 1834 function i2d_PKCS12_bio; external LIBEAY_DLL_NAME; 1835 function d2i_PKCS7; external LIBEAY_DLL_NAME; 1836 function d2i_PKCS7_bio; external LIBEAY_DLL_NAME; 1837 function i2d_PKCS7_bio; external LIBEAY_DLL_NAME; 1838 function d2i_PKCS8_bio; external LIBEAY_DLL_NAME; 1839 function d2i_PKCS8_PRIV_KEY_INFO; external LIBEAY_DLL_NAME; 1840 function d2i_DSAPrivateKey_bio; external LIBEAY_DLL_NAME; 1841 function i2d_DSAPrivateKey_bio; external LIBEAY_DLL_NAME; 1842 function d2i_RSAPrivateKey_bio; external LIBEAY_DLL_NAME 1843 function i2d_RSAPrivateKey_bio; external LIBEAY_DLL_NAME 1844 1845 function i2a_ASN1_INTEGER; external LIBEAY_DLL_NAME; 1846 function a2i_ASN1_INTEGER; external LIBEAY_DLL_NAME; 1847 1848 function EVP_md_null; external LIBEAY_DLL_NAME; 1849 function EVP_md2; external LIBEAY_DLL_NAME; 1850 function EVP_md5; external LIBEAY_DLL_NAME; 1851 function EVP_sha; external LIBEAY_DLL_NAME; 1852 function EVP_sha1; external LIBEAY_DLL_NAME; 1853 function EVP_dss; external LIBEAY_DLL_NAME; 1854 function EVP_dss1; external LIBEAY_DLL_NAME; 1855 function EVP_mdc2; external LIBEAY_DLL_NAME; 1856 function EVP_ripemd160; external LIBEAY_DLL_NAME; 1857 function EVP_get_digestbyname; external LIBEAY_DLL_NAME; 1858 1859 function EVP_PKEY_new; external LIBEAY_DLL_NAME; 1860 procedure EVP_PKEY_free; external LIBEAY_DLL_NAME; 1861 function EVP_PKEY_type; external LIBEAY_DLL_NAME; 1862 function EVP_PKEY_assign_RSA; external LIBEAY_DLL_NAME; 1863 function EVP_PKEY_assign_DSA; external LIBEAY_DLL_NAME; 1864 function EVP_PKEY_assign_DH; external LIBEAY_DLL_NAME; 1865 function EVP_PKEY_assign_EC_KEY; external LIBEAY_DLL_NAME; 1866 function EVP_PKEY_set1_RSA; external LIBEAY_DLL_NAME; 1867 function EVP_PKEY_set1_DSA; external LIBEAY_DLL_NAME; 1868 function EVP_PKEY_set1_DH; external LIBEAY_DLL_NAME; 1869 function EVP_PKEY_set1_EC_KEY; external LIBEAY_DLL_NAME; 1870 function EVP_PKEY_size; external LIBEAY_DLL_NAME; 1871 function EVP_PKEY_get1_RSA; external LIBEAY_DLL_NAME; 1872 function EVP_PKEY_get1_DSA; external LIBEAY_DLL_NAME; 1873 function EVP_PKEY_get1_DH; external LIBEAY_DLL_NAME; 1874 function EVP_PKEY_get1_EC_KEY; external LIBEAY_DLL_NAME; 1875 1876 procedure EVP_DigestInit; external LIBEAY_DLL_NAME; 1877 procedure EVP_DigestUpdate; external LIBEAY_DLL_NAME; 1878 procedure EVP_DigestFinal; external LIBEAY_DLL_NAME; 1879 1880 procedure EVP_SignInit(ctx: pEVP_MD_CTX; const _type: pEVP_MD); 1881 begin 1882 EVP_DigestInit(ctx, _type); 1883 end; 1884 1885 procedure EVP_SignUpdate(ctx: pEVP_MD_CTX; const d: Pointer; cnt: cardinal); 1886 begin 1887 EVP_DigestUpdate(ctx, d, cnt); 1888 end; 1889 1890 function EVP_SignFinal; external LIBEAY_DLL_NAME; 1891 1892 procedure EVP_VerifyInit(ctx: pEVP_MD_CTX; const _type: pEVP_MD); 1893 begin 1894 EVP_DigestInit(ctx, _type); 1895 end; 1896 1897 procedure EVP_VerifyUpdate(ctx: pEVP_MD_CTX; const d: Pointer; cnt: cardinal); 1898 begin 1899 EVP_DigestUpdate(ctx, d, cnt); 1900 end; 1901 1902 function EVP_VerifyFinal; external LIBEAY_DLL_NAME; 1903 function EVP_PKEY_assign; external LIBEAY_DLL_NAME; 1904 1905 // Not in DLL 1906 function EVP_MD_size(e: pEVP_MD): integer; 1907 begin 1908 result := e^.md_size; 1909 end; 1910 1911 // Not in DLL 1912 function EVP_MD_CTX_size(e: pEVP_MD_CTX): integer; 1913 begin 1914 result := EVP_MD_size(e^.digest); 1915 end; 1916 1917 function EVP_MD_CTX_copy; external LIBEAY_DLL_NAME; 1918 1919 function EVP_enc_null; external LIBEAY_DLL_NAME; 1920 function EVP_des_ecb; external LIBEAY_DLL_NAME; 1921 function EVP_des_ede; external LIBEAY_DLL_NAME; 1922 function EVP_des_ede3; external LIBEAY_DLL_NAME; 1923 function EVP_des_cfb; external LIBEAY_DLL_NAME; 1924 function EVP_des_ede_cfb; external LIBEAY_DLL_NAME; 1925 function EVP_des_ede3_cfb; external LIBEAY_DLL_NAME; 1926 function EVP_des_ofb; external LIBEAY_DLL_NAME; 1927 function EVP_des_ede_ofb; external LIBEAY_DLL_NAME; 1928 function EVP_des_ede3_ofb; external LIBEAY_DLL_NAME; 1929 function EVP_des_cbc; external LIBEAY_DLL_NAME; 1930 function EVP_des_ede_cbc; external LIBEAY_DLL_NAME; 1931 function EVP_des_ede3_cbc; external LIBEAY_DLL_NAME; 1932 function EVP_desx_cbc; external LIBEAY_DLL_NAME; 1933 function EVP_idea_cbc; external LIBEAY_DLL_NAME; 1934 function EVP_idea_cfb; external LIBEAY_DLL_NAME; 1935 function EVP_idea_ecb; external LIBEAY_DLL_NAME; 1936 function EVP_idea_ofb; external LIBEAY_DLL_NAME; 1937 function EVP_get_cipherbyname; external LIBEAY_DLL_NAME; 1938 1939 procedure EVP_set_pw_prompt; external LIBEAY_DLL_NAME; 1940 function EVP_get_pw_prompt; external LIBEAY_DLL_NAME; 1941 function EVP_read_pw_string; external LIBEAY_DLL_NAME; 1942 1943 procedure RAND_seed; external LIBEAY_DLL_NAME; 1944 procedure RAND_add; external LIBEAY_DLL_NAME; 1945 function RAND_status; external LIBEAY_DLL_NAME; 1946 //function RAND_event(UINT iMsg, WPARAM wParam, LPARAM lParam): integer; cdecl; external LIBEAY_DLL_NAME; 1947 procedure RAND_screen; external LIBEAY_DLL_NAME; 1948 function RAND_file_name; external LIBEAY_DLL_NAME; 1949 function RAND_load_file; external LIBEAY_DLL_NAME; 1950 function RAND_write_file; external LIBEAY_DLL_NAME; 1951 1952 function RSA_new; external LIBEAY_DLL_NAME; 1953 procedure RSA_free; external LIBEAY_DLL_NAME; 1954 function RSA_new_method; external LIBEAY_DLL_NAME; 1955 function RSA_size; external LIBEAY_DLL_NAME; 1956 function RSA_generate_key; external LIBEAY_DLL_NAME; 1957 function RSA_check_key; external LIBEAY_DLL_NAME; 1958 function RSA_public_encrypt; external LIBEAY_DLL_NAME; 1959 function RSA_private_encrypt; external LIBEAY_DLL_NAME; 1960 function RSA_public_decrypt; external LIBEAY_DLL_NAME; 1961 function RSA_private_decrypt; external LIBEAY_DLL_NAME; 1962 function RSA_flags; external LIBEAY_DLL_NAME; 1963 procedure RSA_set_default_method; external LIBEAY_DLL_NAME; 1964 function RSA_get_default_method; external LIBEAY_DLL_NAME; 1965 function RSA_get_method; external LIBEAY_DLL_NAME; 1966 function RSA_set_method; external LIBEAY_DLL_NAME; 1967 function RSA_memory_lock; external LIBEAY_DLL_NAME; 1968 function RSA_PKCS1_SSLeay; external LIBEAY_DLL_NAME; 1969 procedure ERR_load_RSA_strings; external LIBEAY_DLL_NAME; 1970 1971 function RSA_sign;external LIBEAY_DLL_NAME; //2016/02/19 13:45 1972 function RSA_verify;external LIBEAY_DLL_NAME; //2016/02/19 13:45 1973 1974 1975 function DSA_new; external LIBEAY_DLL_NAME; 1976 procedure DSA_free; external LIBEAY_DLL_NAME; 1977 function DSA_generate_parameters; external LIBEAY_DLL_NAME; 1978 function DSA_generate_key; external LIBEAY_DLL_NAME; 1979 1980 function X509_NAME_oneline; external LIBEAY_DLL_NAME; 1981 function X509_NAME_new; external LIBEAY_DLL_NAME; 1982 procedure X509_NAME_free; external LIBEAY_DLL_NAME; 1983 function X509_NAME_add_entry_by_txt; external LIBEAY_DLL_NAME; 1984 function X509_NAME_get_entry; external LIBEAY_DLL_NAME; 1985 function X509_NAME_get_text_by_NID; external LIBEAY_DLL_NAME; 1986 1987 function X509_new; external LIBEAY_DLL_NAME; 1988 procedure X509_free; external LIBEAY_DLL_NAME; 1989 function X509_print; external LIBEAY_DLL_NAME; 1990 function X509_set_version; external LIBEAY_DLL_NAME; 1991 1992 function X509_get_version(x: pX509): integer; 1993 begin 1994 result := ASN1_INTEGER_get(x.cert_info.version); 1995 end; 1996 1997 function X509_get_serialNumber; external LIBEAY_DLL_NAME; 1998 function X509_load_cert_file; external LIBEAY_DLL_NAME; 1999 function X509_get_issuer_name; external LIBEAY_DLL_NAME; 2000 function X509_get_subject_name; external LIBEAY_DLL_NAME; 2001 2002 function X509_get_notBefore(a: pX509): pASN1_TIME; 2003 begin 2004 result := a.cert_info.validity.notBefore; 2005 end; 2006 function X509_get_notAfter(a: pX509): pASN1_TIME; 2007 begin 2008 result := a.cert_info.validity.notAfter; 2009 end; 2010 2011 function X509_get1_email; external LIBEAY_DLL_NAME; 2012 function X509_get_pubkey; external LIBEAY_DLL_NAME; 2013 function X509_check_private_key; external LIBEAY_DLL_NAME; 2014 function X509_check_purpose; external LIBEAY_DLL_NAME; 2015 function X509_issuer_and_serial_cmp; external LIBEAY_DLL_NAME; 2016 function X509_issuer_and_serial_hash; external LIBEAY_DLL_NAME; 2017 function X509_gmtime_adj; external LIBEAY_DLL_NAME; 2018 function X509_verify_cert; external LIBEAY_DLL_NAME; 2019 function X509_verify_cert_error_string; external LIBEAY_DLL_NAME; 2020 procedure X509_email_free; external LIBEAY_DLL_NAME; 2021 function X509_get_ext; external LIBEAY_DLL_NAME; 2022 function X509_get_ext_by_NID; external LIBEAY_DLL_NAME; 2023 function X509_get_ext_d2i; external LIBEAY_DLL_NAME; 2024 function X509V3_EXT_d2i; external LIBEAY_DLL_NAME; 2025 function X509V3_EXT_i2d; external LIBEAY_DLL_NAME; 2026 function X509V3_EXT_conf_nid; external LIBEAY_DLL_NAME; 2027 2028 function X509_sign; external LIBEAY_DLL_NAME; 2029 function X509_set_issuer_name; external LIBEAY_DLL_NAME; 2030 function X509_set_subject_name; external LIBEAY_DLL_NAME; 2031 procedure X509V3_set_ctx; external LIBEAY_DLL_NAME; 2032 procedure X509_SIG_free; external LIBEAY_DLL_NAME; 2033 2034 function X509_PUBKEY_get; external LIBEAY_DLL_NAME; 2035 2036 function X509_REQ_new; external LIBEAY_DLL_NAME; 2037 procedure X509_REQ_free; external LIBEAY_DLL_NAME; 2038 function X509_REQ_set_version; external LIBEAY_DLL_NAME; 2039 2040 function X509_REQ_get_version(req: pX509_REQ): integer; 2041 begin 2042 result := ASN1_INTEGER_get(req.req_info.version); 2043 end; 2044 2045 function X509_REQ_set_subject_name; external LIBEAY_DLL_NAME; 2046 2047 function X509_REQ_get_subject_name(req: pX509_REQ): pX509_NAME; 2048 begin 2049 result := req.req_info.subject; 2050 end; 2051 2052 function X509_REQ_add1_attr_by_txt; external LIBEAY_DLL_NAME; 2053 function X509_REQ_add_extensions; external LIBEAY_DLL_NAME; 2054 function X509_REQ_set_pubkey; external LIBEAY_DLL_NAME; 2055 function X509_REQ_get_pubkey; external LIBEAY_DLL_NAME; 2056 function X509_REQ_sign; external LIBEAY_DLL_NAME; 2057 2058 function X509_STORE_new; external LIBEAY_DLL_NAME; 2059 procedure X509_STORE_free; external LIBEAY_DLL_NAME; 2060 function X509_STORE_add_cert; external LIBEAY_DLL_NAME; 2061 function X509_STORE_add_lookup; external LIBEAY_DLL_NAME; 2062 function X509_STORE_CTX_new; external LIBEAY_DLL_NAME; 2063 procedure X509_STORE_CTX_free; external LIBEAY_DLL_NAME; 2064 procedure X509_STORE_CTX_init; external LIBEAY_DLL_NAME; 2065 2066 function X509_STORE_CTX_get_current_cert; external LIBEAY_DLL_NAME; 2067 function X509_STORE_CTX_get_error; external LIBEAY_DLL_NAME; 2068 function X509_STORE_CTX_get_error_depth; external LIBEAY_DLL_NAME; 2069 2070 function X509_LOOKUP_new; external LIBEAY_DLL_NAME; 2071 function X509_LOOKUP_init; external LIBEAY_DLL_NAME; 2072 procedure X509_LOOKUP_free; external LIBEAY_DLL_NAME; 2073 2074 function X509_LOOKUP_ctrl; external LIBEAY_DLL_NAME; 2075 function X509_LOOKUP_file; external LIBEAY_DLL_NAME; 2076 2077 function PEM_read_bio_RSAPrivateKey; external LIBEAY_DLL_NAME; 2078 function PEM_write_bio_RSAPrivateKey; external LIBEAY_DLL_NAME; 2079 function PEM_read_bio_RSAPublicKey; external LIBEAY_DLL_NAME; 2080 function PEM_write_bio_RSAPublicKey; external LIBEAY_DLL_NAME; 2081 2082 function PEM_read_bio_DSAPrivateKey; external LIBEAY_DLL_NAME; 2083 function PEM_write_bio_DSAPrivateKey; external LIBEAY_DLL_NAME; 2084 2085 function PEM_read_bio_PUBKEY; external LIBEAY_DLL_NAME; 2086 function PEM_write_bio_PUBKEY; external LIBEAY_DLL_NAME; 2087 2088 function PEM_read_bio_X509; external LIBEAY_DLL_NAME; 2089 function PEM_write_bio_X509; external LIBEAY_DLL_NAME; 2090 function PEM_read_bio_X509_AUX; external LIBEAY_DLL_NAME; 2091 function PEM_write_bio_X509_AUX; external LIBEAY_DLL_NAME; 2092 function PEM_read_bio_X509_REQ; external LIBEAY_DLL_NAME; 2093 function PEM_write_bio_X509_REQ; external LIBEAY_DLL_NAME; 2094 function PEM_read_bio_X509_CRL; external LIBEAY_DLL_NAME; 2095 function PEM_write_bio_X509_CRL; external LIBEAY_DLL_NAME; 2096 function PEM_read_bio_PrivateKey; external LIBEAY_DLL_NAME; 2097 function PEM_write_bio_PrivateKey; external LIBEAY_DLL_NAME; 2098 function PEM_read_bio_PKCS7; external LIBEAY_DLL_NAME; 2099 function PEM_write_bio_PKCS7; external LIBEAY_DLL_NAME; 2100 2101 function PKCS5_PBKDF2_HMAC_SHA1; external LIBEAY_DLL_NAME; 2102 2103 function PKCS7_sign; external LIBEAY_DLL_NAME; 2104 function PKCS7_get_signer_info; external LIBEAY_DLL_NAME; // STACK_OF(PKCS7_SIGNER_INFO) 2105 function PKCS7_verify; external LIBEAY_DLL_NAME; 2106 function PKCS7_get0_signers; external LIBEAY_DLL_NAME; 2107 function PKCS7_signatureVerify; external LIBEAY_DLL_NAME; 2108 function PKCS7_encrypt; external LIBEAY_DLL_NAME; 2109 function PKCS7_decrypt; external LIBEAY_DLL_NAME; 2110 procedure PKCS7_free; external LIBEAY_DLL_NAME; 2111 function PKCS7_ctrl; external LIBEAY_DLL_NAME; 2112 2113 function PKCS7_get_detached(p7: pPKCS7): pointer; 2114 begin 2115 result := pointer(PKCS7_ctrl(p7, 2, 0, nil)); 2116 end; 2117 2118 function PKCS7_dataInit; external LIBEAY_DLL_NAME; 2119 2120 function EVP_PKCS82PKEY; external LIBEAY_DLL_NAME; 2121 procedure PKCS8_PRIV_KEY_INFO_free; external LIBEAY_DLL_NAME; 2122 function PKCS8_decrypt; external LIBEAY_DLL_NAME; 2123 2124 function PKCS12_new; external LIBEAY_DLL_NAME; 2125 procedure PKCS12_free; external LIBEAY_DLL_NAME; 2126 function PKCS12_parse; external LIBEAY_DLL_NAME; 2127 2128 function AES_set_decrypt_key; external LIBEAY_DLL_NAME; 2129 procedure AES_cbc_encrypt; external LIBEAY_DLL_NAME; 2130 2131 function SMIME_write_PKCS7; external LIBEAY_DLL_NAME; 2132 function SMIME_read_PKCS7; external LIBEAY_DLL_NAME; 2133 2134 2135 //======================by lwm8246========================================= 2136 2137 procedure EVP_MD_CTX_init(ctx : PEVP_MD_CTX) cdecl;external LIBEAY_DLL_NAME; 2138 function EVP_MD_CTX_cleanup(ctx : PEVP_MD_CTX):Integer; cdecl;external LIBEAY_DLL_NAME; 2139 procedure BIO_set_flags(a:PBIO;Flags:Integer);cdecl;external LIBEAY_DLL_NAME; 2140 2141 //int AES_set_encrypt_key(const unsigned char *userKey, const int bits,AES_KEY *key); 2142 function AES_set_encrypt_key(const userKey:Pointer; const bits:integer;key:PAES_KEY):Integer;cdecl;external LIBEAY_DLL_NAME; 2143 2144 2145 //int MD5_Init(MD5_CTX *c); 2146 function MD5_Init(var c:MD5_CTX):Integer;cdecl;external LIBEAY_DLL_NAME; 2147 2148 //int MD5_Update(MD5_CTX *c, const void *data, size_t len); 2149 function MD5_Update(var c: MD5_CTX;const data:Pointer;len:Integer):Integer;cdecl;external LIBEAY_DLL_NAME; 2150 2151 2152 //int MD5_Final(unsigned char *md, MD5_CTX *c); 2153 function MD5_Final(md:Pointer;var c: MD5_CTX):Integer;cdecl;external LIBEAY_DLL_NAME; 2154 2155 2156 function RAND_bytes(OutBuf:Pointer;num:Integer):Integer;cdecl;external LIBEAY_DLL_NAME;//2016/02/28 14:30 2157 2158 function SHA256(const d:PAnsichar;n:Integer;md:PAnsichar):PAnsichar;cdecl;external LIBEAY_DLL_NAME; 2159 2160 2161 //int SHA256_Init(SHA256_CTX *c); 2162 function SHA256_Init(c:pSHA256_CTX):Integer;cdecl;external LIBEAY_DLL_NAME; 2163 2164 //int SHA256_Update(SHA256_CTX *c, const void *data, size_t len); 2165 function SHA256_Update(c:pSHA256_CTX;const data:Pointer;len:Cardinal):Integer;cdecl; external LIBEAY_DLL_NAME; 2166 2167 //int SHA256_Final(unsigned char *md, SHA256_CTX *c); 2168 function SHA256_Final(md:Pointer;c:pSHA256_CTX):Integer;cdecl; external LIBEAY_DLL_NAME; 2169 2170 2171 //=============================================================================== 2172 2173 function PEM_read_bio_RSA_PUBKEY(bp: pBIO;var x: pRSA;cb:Pointer;u:pointer):pRSA;cdecl;external LIBEAY_DLL_NAME; 2174 2175 2176 //function HMAC(const evp_md:pEVP_MD; 2177 // const key:Pointer; 2178 // key_len:Integer; 2179 // const d:PAnsichar; 2180 // n:Cardinal; 2181 // md:PAnsichar; 2182 // md_len:Cardinal):PAnsichar;cdecl;external LIBEAY_DLL_NAME;//2016/02/29 18:11 2183 2184 2185 function HMAC(evp: pEVP_MD; key: PByte; key_len: integer; 2186 data: PByte; data_len: integer; 2187 md: PByte; var md_len: integer): PByte; cdecl; external LIBEAY_DLL_NAME; 2188 2189 function EVP_sha512():pEVP_MD;cdecl;external LIBEAY_DLL_NAME;//2016/02/29 18:16 2190 2191 function EVP_sha224():pEVP_MD;cdecl;external LIBEAY_DLL_NAME;//2016/02/29 18:19 2192 2193 function EVP_sha256():pEVP_MD;cdecl;external LIBEAY_DLL_NAME; //2016/02/29 18:19 2194 2195 function EVP_sha384():pEVP_MD;cdecl;external LIBEAY_DLL_NAME;//2016/03/01 00:30 2196 2197 function HMAC_Init(ctx:pHMAC_CTX; 2198 const key:PAnsichar; 2199 len:Integer; 2200 const md:pEVP_MD):Integer;cdecl;external LIBEAY_DLL_NAME;//2016/02/29 23:53 2201 2202 //int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len,const EVP_MD *md, ENGINE *impl); 2203 function HMAC_Init_ex(ctx:pHMAC_CTX; 2204 const key:PAnsichar; 2205 Len:Integer; 2206 const md:pEVP_MD; 2207 impl:pENGINE):integer;cdecl;external LIBEAY_DLL_NAME;//2016/03/01 00:00 2208 2209 //int HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, size_t len); 2210 function HMAC_Update(ctx:pHMAC_CTX;const data:PAnsichar;len:Cardinal):Integer;cdecl;external LIBEAY_DLL_NAME;//2016/03/01 00:05 2211 2212 function HMAC_Final(ctx:pHMAC_CTX; md:PAnsichar;len:PInteger):Integer;cdecl;external LIBEAY_DLL_NAME;//2016/03/01 00:05 2213 2214 procedure HMAC_CTX_cleanup(ctx:PHMAC_CTX);cdecl;external LIBEAY_DLL_NAME;//2016/03/01 00:06 2215 2216 procedure HMAC_CTX_init(ctx:pHMAC_CTX);cdecl;external LIBEAY_DLL_NAME;//2016/03/01 00:06 2217 2218 end.
这里用的是RTC的request来实现的。
1 implementation 2 3 4 /// <summary> 5 /// 获取UTC时间 格式:YYYYMMDDTHHMMSSZ。 6 /// </summary> 7 function Gettime:string; 8 var 9 TimeNow: TDateTime; 10 pTime: _TIME_ZONE_INFORMATION; 11 Bias : Longint; 12 begin 13 GetTimeZoneInformation(pTime);//获取时区 14 Bias := pTime.Bias; 15 TimeNow := IncMinute(Now, Bias); 16 Result := FormatDateTime('yyyyMMdd',TimeNow)+'T'+FormatDateTime('HHmmss',TimeNow)+'Z'; 17 end; 18 19 /// <summary> 20 /// 字符串转16进制 21 /// </summary> 22 function StrToHex(s:string):string; //字串转16进制 23 var 24 TmpStr:string; 25 i:integer; 26 begin 27 TmpStr:=''; 28 for i:=1 to Length(s)do 29 begin 30 TmpStr:=TmpStr+IntToHex(ord(s[i]),2); 31 end; 32 Result:=TmpStr; 33 end; 34 35 /// <summary> 36 /// 摘抄diocpo的StringToUtf8Bytes 这里只管D7 37 /// </summary> 38 function StringToUtf8Bytes(const pvData: string; pvProcessEndByte: Boolean=false): TBytes; 39 var 40 lvRawStr:AnsiString; 41 begin 42 lvRawStr := UTF8Encode(pvData); 43 if pvProcessEndByte then 44 begin 45 SetLength(Result, Length(lvRawStr) + 1); 46 Move(PAnsiChar(lvRawStr)^, Result[0], Length(lvRawStr)); 47 Result[Length(Result) -1 ] := 0; 48 end else 49 begin 50 SetLength(Result, Length(lvRawStr)); 51 Move(PAnsiChar(lvRawStr)^, Result[0], Length(lvRawStr)); 52 end; 53 end; 54 55 /// <summary> 56 /// 摘抄diocpo的URLEncode 改了排除的符号 57 /// </summary> 58 function URLEncode_RFC3986(AStr: String):string; 59 //华为接口 60 // 根据以下规则对每个参数名和值进行URI编码: 61 //请勿对RFC 3986定义的任何非预留字符进行URI编码,这些字符包括:A-Z、a-z、0-9、-、_、.和~。 62 //使用%XY对所有非预留字符进行百分比编码,其中X和Y为十六进制字符(0-9和A-F)。 63 //例如,空格字符必须编码为%20,扩展UTF-8字符必须采用“%XY%ZA%BC”格式。 64 function BufferURLEncode(pvBuff: PByte; pvLen: Integer): string; 65 const 66 NoConversion = [Ord('A') .. Ord('Z'), Ord('a') .. Ord('z'), Ord('0') .. Ord('9'), 67 Ord('-'), Ord('_'),Ord('.'),Ord('~')]; 68 // Ord('@'), Ord('.'), Ord('_'), Ord('-'), Ord('0') .. Ord('9'), Ord('$'), 69 // Ord('!'), Ord(''''), Ord('('), Ord(')')]; 70 71 procedure AppendByte(B: Byte; var Buffer: PChar); 72 const 73 Hex = '0123456789ABCDEF'; 74 {$IF CompilerVersion>= 28} // XE7 75 LOW_INDEX = Low(string); 76 {$ELSE} 77 LOW_INDEX = 1; 78 {$IFEND} 79 begin 80 Buffer[0] := '%'; 81 Buffer[1] := Hex[B shr 4 + LOW_INDEX]; 82 Buffer[2] := Hex[B and $F + LOW_INDEX]; 83 inc(Buffer, 3); 84 end; 85 var 86 Rp: PChar; 87 lvBuff: PByte; 88 j: Integer; 89 begin 90 // Characters that require more than 1 byte are translated as "percent-encoded byte" 91 // which will be encoded with 3 chars per byte -> %XX 92 // Example: U+00D1 ($F1 in CodePage 1252) 93 // UTF-8 representation: $C3 $91 (2 bytes) 94 // URL encode representation: %C3%91 95 // 96 // 3 characters to represent each byte 97 SetLength(Result, pvLen * 3); 98 lvBuff := PByte(pvBuff); 99 Rp := PChar(Result); 100 j := 0; 101 while j < pvLen do 102 begin 103 if lvBuff^ in NoConversion then 104 begin 105 Rp^ := Char(lvBuff^); 106 inc(Rp) 107 end 108 // else if pvBuff^ = Ord(' ') then 109 // begin 110 // Rp^ := '+'; 111 // Inc(Rp) 112 // end 113 else 114 begin 115 AppendByte(lvBuff^, Rp) 116 end; 117 inc(lvBuff); 118 inc(j); 119 end; 120 SetLength(Result, Rp - PChar(Result)); 121 end; 122 123 var 124 lvBytes: TBytes; 125 begin 126 lvBytes := TBytes(StringToUtf8Bytes(AStr)); 127 128 Result := BufferURLEncode(@lvBytes[0], length(lvBytes)); 129 end; 130 131 132 /// <summary> 133 134 /// AnsiToUnicode 135 136 /// </summary> 137 138 function AnsiToUnicode(Str: ansistring): string; 139 140 var 141 s: ansistring; 142 i:integer; 143 j,k:string[2]; 144 a:array [1..1000] of ansichar; 145 begin 146 s:=''; 147 StringToWideChar(Str,@(a[1]),500); 148 i:=1; 149 while ((a[i]<>#0) or (a[i+1]<>#0)) do 150 begin 151 j:=IntToHex(Integer(a[i]),2); 152 k:=IntToHex(Integer(a[i+1]),2); 153 s:=s+'u'+k+j; 154 i:=i+2; 155 end; 156 Result:=s; 157 end; 158 159 /// <summary> 160 /// UnicodeToChinese 161 162 /// </summary> 163 function UnicodeToChinese(inputstr: string): string; 164 var 165 i: Integer; 166 index: Integer; 167 temp, top, last: string; 168 begin 169 index := 1; 170 while index >= 0 do 171 begin 172 index := Pos('u', inputstr) - 1; 173 if index < 0 then 174 begin 175 last := inputstr; 176 Result := Result + last; 177 Exit; 178 end; 179 top := Copy(inputstr, 1, index); // 取出 编码字符前的 非 unic 编码的字符,如数字 180 temp := Copy(inputstr, index + 1, 6); // 取出编码,包括 u,如u4e3f 181 Delete(temp, 1, 2); 182 Delete(inputstr, 1, index + 6); 183 Result := Result + top + WideChar(StrToInt('$' + temp)); 184 end; 185 end; 186 187 188 /// <summary> 189 /// 生成备份名称 190 /// </summary> 191 function CreateBackupName:string; 192 193 function NumToStr (num, len, base: Integer; neg: Boolean; fill: char): string; 194 195 const 196 MinBase = 2; 197 MaxBase = 36; 198 // num = 要转换的数 199 // len = 生成字符串的最小长度 200 // base = 进制数 2 = 二进制 201 // neg = 是否允许负数 202 // fill = 填充字符用于补满字符串长度// 203 // 用法: 204 // NumToStr (45, 8, 2, false, '0') > '00101101' 205 // NumToStr (45, 4, 8, false, '0') > '0055' 206 // NumToStr (45, 4, 10, false, ' ') > ' 45' 207 // NumToStr (45, 4, 16, false, '0') > '002D' 208 // NumToStr (45, 0, 36, false, ' ') > '19' 209 var 210 s: string; 211 digit: Integer; 212 begin 213 num:= ABS (num); 214 if ((base >= MinBase) and (base <= MaxBase)) then 215 begin 216 s:= ''; 217 repeat 218 digit:= num mod base; 219 if digit < 10 then 220 Insert (CHR (digit + 48), s, 1) 221 else 222 Insert (CHR (digit + 55), s, 1); 223 num:= num div base; 224 until num = 0; 225 if neg then 226 Insert ('-', s, 1); 227 while Length(s) < len do 228 Insert (fill, s, 1); 229 end; 230 Result:= s; 231 end; 232 233 234 begin 235 Randomize; 236 Result := 'backup-'+LowerCase(NumToStr(Floor(2147483648 * random), 0, 4, False, ' ')); 237 end; 238 239 240 //***************** libeay32dll相关****************** 241 procedure LoadSSL; 242 begin 243 OpenSSL_add_all_algorithms; 244 OpenSSL_add_all_ciphers; 245 OpenSSL_add_all_digests; 246 ERR_load_crypto_strings; 247 ERR_load_RSA_strings; 248 end; 249 250 procedure FreeSSL; 251 begin 252 EVP_cleanup; 253 ERR_free_strings; 254 end; 255 256 function UTF8Bytes(const s: UTF8String): TBytes; 257 var 258 B: TBytes; 259 begin 260 SetLength(B,Length(S)); 261 CopyMemory(@B[0],@S[1],Length(S)); 262 Result:=B; 263 end; 264 265 /// <summary> 266 /// 摘抄网上调 libeay32.dll 字符串哈希值 267 268 /// </summary> 269 function GetSHA256(AData: string): string; 270 var 271 Len: cardinal; 272 mdctx: EVP_MD_CTX; 273 inbuf, outbuf: array [0..1023] of char; 274 key: pEVP_PKEY; 275 r: PAnsiChar; 276 begin 277 StrPCopy(inbuf, AData); 278 LoadSSL; 279 280 EVP_DigestInit(@mdctx, EVP_sha256()); 281 EVP_DigestUpdate(@mdctx, @inbuf, StrLen(inbuf)); 282 EVP_DigestFinal(@mdctx, @outbuf, Len); 283 284 FreeSSL; 285 BinToHex(outbuf, inbuf,Len); 286 inbuf[2*Len]:=#0; 287 result := LowerCase(StrPas(inbuf)); 288 end; 289 290 /// <summary> 291 /// 摘抄网上调 libeay32.dll 签名字符串 sha256 292 293 /// </summary> 294 295 function GetHMAC(const AData,AKey: string): string; 296 var 297 key, data, rsa256: TBytes; 298 md_len: integer; 299 res: PByte; 300 i: integer; 301 begin 302 Result := ''; 303 LoadSSL; 304 key := UTF8Bytes(AKey); 305 data := UTF8Bytes(AData); 306 md_len := EVP_MAX_MD_SIZE; 307 SetLength(rsa256, md_len); 308 309 res := HMAC(EVP_sha256, @key[0], Length(key), @data[0], Length(data), @rsa256[0], md_len); 310 if (res <> nil) then 311 begin 312 SetLength(rsa256, md_len); 313 for i := low(rsa256) to high(rsa256) do 314 Result:= Result+IntToHex(rsa256[i],2); 315 Result := LowerCase(Result); 316 end; 317 FreeSSL; 318 end; 319 //***************** libeay32dll相关****************** 320 321 /// <summary> 322 /// 华为云接口的aksk签名 323 /// </summary> 324 procedure HuaweiSetAuthorization(RtcDataRequest:TRtcDataRequest; Accesskey, SecretAccessKey:string); 325 const 326 Algorithm :string ='SDK-HMAC-SHA256'; 327 HeaderXDate :string ='X-Sdk-Date'; 328 HeaderAuthorization :string = 'Authorization'; 329 330 var 331 CanonicalRequest,HashedCanonicalRequest:string; 332 XSdkDate, StringToSign, Signature,Authorization :string; 333 HTTPRequestMethod,CanonicalURI,CanonicalQueryString, 334 CanonicalHeaders,SignedHeaders,hasRequestPayload:string; 335 SortList:TStringList; 336 i: integer; 337 begin 338 //headers 添加时间 339 XSdkDate := Gettime; 340 RtcDataRequest.Request.asString[HeaderXDate] := XSdkDate; 341 //规范请求的方法 342 HTTPRequestMethod := RtcDataRequest.Request.Method; 343 344 //规范URI参数 345 CanonicalURI := '/'; 346 for i := 0 to RtcDataRequest.Request.FilePath.Count -1 do 347 //路径中每个部分必须为URI编码 RFC3986 标准 348 CanonicalURI := CanonicalURI+URLEncode_RFC3986(RtcDataRequest.Request.FilePath.Value[i])+'/'; 349 350 //规范查询字符串 351 SortList := TStringList.Create; 352 SortList.Clear; 353 for i := 0 to RtcDataRequest.Request.Query.ItemCount -1 do 354 with RtcDataRequest.Request.Query do 355 SortList.Add(URLEncode_RFC3986(ItemName[i])+'='+URLEncode_RFC3986(ItemValue[i])); 356 //按字符串去排序 357 SortList.Sort; 358 359 CanonicalQueryString := ''; 360 for i := 0 to SortList.Count-1 do 361 CanonicalQueryString := CanonicalQueryString+SortList[i]+RtcDataRequest.Request.Query.Delimiter; 362 if CanonicalQueryString <> '' then 363 CanonicalQueryString := Copy(CanonicalQueryString, 1,Length(CanonicalQueryString)-Length(RtcDataRequest.Request.Query.Delimiter)); 364 365 //规范消息头 366 SortList.Clear; 367 for i := 0 to RtcDataRequest.Request.ItemCount -1 do 368 SortList.Add(LowerCase(RtcDataRequest.Request.ItemName[i])+':'+Trim(RtcDataRequest.Request.ItemValue[i])); 369 SortList.Sort; 370 371 CanonicalHeaders := ''; 372 for i := 0 to SortList.Count -1 do 373 CanonicalHeaders := CanonicalHeaders+SortList[i]+#10; 374 375 //签名的消息头声明 376 SortList.Clear; 377 for i := 0 to RtcDataRequest.Request.ItemCount -1 do 378 SortList.Add(LowerCase(RtcDataRequest.Request.ItemName[i])); 379 SortList.Sort; 380 381 SignedHeaders := ''; 382 for i := 0 to SortList.Count -1 do 383 SignedHeaders := SignedHeaders+SortList[i]+';'; 384 385 SortList.Free; 386 387 if SignedHeaders <> '' then 388 SignedHeaders := Copy(SignedHeaders, 1, Length(SignedHeaders)-1); 389 390 //使用SHA 256哈希函数以基于HTTP或HTTPS请求正文中的body体(RequestPayload),创建哈希值。 391 hasRequestPayload := GetSHA256(RtcDataRequest.Request.Params.Text); 392 393 //规范请求构造 394 // HTTPRequestMethod + ' ' + 395 // CanonicalURI + ' ' + 396 // CanonicalQueryString + ' ' + 397 // CanonicalHeaders + ' ' + 398 // SignedHeaders + ' ' + 399 // HexEncode(Hash(RequestPayload)) 400 401 CanonicalRequest := Format('%s'+#10+ 402 '%s'+#10+ 403 '%s'+#10+ 404 '%s'+#10+ 405 '%s'+#10+ 406 '%s' 407 ,[HTTPRequestMethod, 408 CanonicalURI, 409 CanonicalQueryString, 410 CanonicalHeaders, 411 SignedHeaders, 412 hasRequestPayload 413 ] ); 414 // Form1.Memo1.lines.add('规范请求'); 415 // Form1.Memo1.lines.add(CanonicalRequest); 416 // ShowMessage(CanonicalRequest); 417 418 // showmessage(CanonicalRequest); 419 //对构造好的规范请求进行SHA256 创建哈希值 420 HashedCanonicalRequest := GetSHA256(CanonicalRequest); 421 422 //创建待签字符串 423 StringToSign := Algorithm+#10+XSdkDate+#10+HashedCanonicalRequest; 424 // Form1.Memo1.lines.add('待签字符串'); 425 // Form1.Memo1.lines.add(StringToSign); 426 // ShowMessage(StringToSign); 427 428 //进行签名 429 Signature := GetHMAC(StringToSign, SecretAccessKey); 430 431 //最终的签名 432 Authorization := Algorithm+' Access='+Accesskey+', SignedHeaders='+SignedHeaders+', Signature='+Signature; 433 434 // Form1.Memo1.lines.add('最终的签名'); 435 // Form1.Memo1.lines.add(Authorization); 436 437 RtcDataRequest.Request.asString[HeaderAuthorization] :=Authorization; 438 // Form1.Memo1.lines.add('最终HeaderText签名'); 439 // Form1.Memo1.lines.add(RtcDataRequest.Request.HeaderText); 440 // ShowMessage(RtcDataRequest.Request.HeaderText); 441 442 end;
用法:
1 function TForm1.BackupDB(instance_id,dbs,dbjons:string; AbackupName:string=''): string; 2 var 3 backupname:string; 4 begin 5 with RtcHttpClient do 6 begin 7 Disconnect; 8 ServerAddr := 'rds.'+Endpoint+'.myhuaweicloud.com'; 9 ServerPort := '443'; 10 Connect(); 11 SkipRequests; 12 end; 13 backupname := AbackupName; 14 if backupname ='' then 15 backupname := CreateBackupName; 16 with RtcDataRequest_backup.Request do 17 begin 18 Clear; 19 Close := True; 20 Agent := AnsiString('Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36'); 21 ContentType := AnsiString('application/json; charset=UTF-8'); 22 Method:=AnsiString('POST'); 23 FileName:=AnsiString('/v3/'+ProjectID+'/backups'); 24 Host:=AnsiString('rds.'+Endpoint+'.myhuaweicloud.com'); 25 asString['backupname'] := backupname; 26 Params.Text := Utf8Encode('{"instance_id": "'+instance_id+'","name":"'+backupname+ 27 '","description": "'+dbs+'","databases": ['+dbjons+']}'); 28 // if Token <> '' then 29 // RtcDataRequest1.Request.asString[HeaderToken] := Token 30 // else //用aksk验证 31 HuaweiSetAuthorization(RtcDataRequest_backup, AccessKey, SecretAccessKey); 32 end; 33 RtcDataRequest_backup.Post; 34 35 Result := backupname; 36 RtcDataRequest_backup.WaitForCompletion(True, 3000, True);