openssl.pas 146 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487
  1. unit openssl;
  2. {==============================================================================|
  3. | Project : Ararat Synapse | 003.004.001 |
  4. |==============================================================================|
  5. | Content: SSL support by OpenSSL |
  6. |==============================================================================|
  7. | Copyright (c)1999-2005, Lukas Gebauer |
  8. | All rights reserved. |
  9. | |
  10. | Redistribution and use in source and binary forms, with or without |
  11. | modification, are permitted provided that the following conditions are met: |
  12. | |
  13. | Redistributions of source code must retain the above copyright notice, this |
  14. | list of conditions and the following disclaimer. |
  15. | |
  16. | Redistributions in binary form must reproduce the above copyright notice, |
  17. | this list of conditions and the following disclaimer in the documentation |
  18. | and/or other materials provided with the distribution. |
  19. | |
  20. | Neither the name of Lukas Gebauer nor the names of its contributors may |
  21. | be used to endorse or promote products derived from this software without |
  22. | specific prior written permission. |
  23. | |
  24. | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
  25. | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
  26. | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
  27. | ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR |
  28. | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
  29. | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
  30. | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
  31. | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
  32. | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
  33. | OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
  34. | DAMAGE. |
  35. |==============================================================================|
  36. | The Initial Developer of the Original Code is Lukas Gebauer (Czech Republic).|
  37. | Portions created by Lukas Gebauer are Copyright (c)2002-2005. |
  38. | All Rights Reserved. |
  39. |==============================================================================|
  40. | Contributor(s): |
  41. |==============================================================================|
  42. | FreePascal basic cleanup (original worked too): Ales Katona |
  43. | WARNING: due to reliance on some units, I have removed the ThreadLocks init |
  44. | if need be, it should be re-added, or handled by the |
  45. | OS threading init somehow |
  46. | |
  47. | 2010 - Felipe Monteiro de Carvalho - Added RAND functios |
  48. |==============================================================================|
  49. | 2010-08-24 add fuctions to hash strings based on rsa key PEM format |
  50. | change some type declarationc on x509 type |
  51. | work is not complete. |
  52. | Work made by Alberto Brito based on unit from |
  53. | Marco Ferrante |
  54. | |
  55. | |
  56. | |
  57. |==============================================================================|
  58. | History: see HISTORY.HTM from distribution package |
  59. | (Found at URL: http://www.ararat.cz/synapse/) |
  60. |==============================================================================}
  61. {
  62. Special thanks to Gregor Ibic <[email protected]>
  63. (Intelicom d.o.o., http://www.intelicom.si)
  64. for good inspiration about begin with SSL programming.
  65. }
  66. {$MODE DELPHI}{$H+}
  67. {$Packrecords C}
  68. {:@abstract(OpenSSL support)
  69. This unit is Pascal interface to OpenSSL library (used by @link(ssl_openssl) unit).
  70. OpenSSL is loaded dynamicly on-demand. If this library is not found in system,
  71. requested OpenSSL function just return errorcode.
  72. }
  73. interface
  74. uses
  75. {$IFDEF OS2}
  76. Sockets,
  77. {$ENDIF OS2}
  78. DynLibs, cTypes, SysUtils;
  79. var
  80. {$IFDEF WINDOWS}
  81. DLLSSLName: string = 'ssleay32.dll';
  82. DLLSSLName2: string = 'libssl32.dll';
  83. DLLUtilName: string = 'libeay32.dll';
  84. {$ELSE}
  85. {$IFDEF OS2}
  86. {$IFDEF OS2GCC}
  87. DLLSSLName: string = 'kssl10.dll';
  88. DLLUtilName: string = 'kcrypt10.dll';
  89. DLLSSLName2: string = 'kssl.dll';
  90. DLLUtilName2: string = 'kcrypto.dll';
  91. {$ELSE OS2GCC}
  92. DLLSSLName: string = 'emssl10.dll';
  93. DLLUtilName: string = 'emcrpt10.dll';
  94. DLLSSLName2: string = 'ssl.dll';
  95. DLLUtilName2: string = 'crypto.dll';
  96. {$ENDIF OS2GCC}
  97. {$ELSE OS2}
  98. DLLSSLName: string = 'libssl';
  99. DLLUtilName: string = 'libcrypto';
  100. { ADD NEW ONES WHEN THEY APPEAR!
  101. Always make .so/dylib first, then versions, in descending order!
  102. Add "." .before the version, first is always just "" }
  103. DLLVersions: array[1..16] of string = ('', '.1.0.6', '.1.0.5', '.1.0.4', '.1.0.3',
  104. '.1.0.2', '.1.0.1','.1.0.0','.0.9.8',
  105. '.0.9.7', '.0.9.6', '.0.9.5', '.0.9.4',
  106. '.0.9.3', '.0.9.2', '.0.9.1');
  107. {$ENDIF OS2}
  108. {$ENDIF WINDOWS}
  109. const
  110. // EVP.h Constants
  111. EVP_MAX_MD_SIZE = 64; //* longest known is SHA512 */
  112. EVP_MAX_KEY_LENGTH = 32;
  113. EVP_MAX_IV_LENGTH = 16;
  114. EVP_MAX_BLOCK_LENGTH = 32;
  115. SHA_DIGEST_LENGTH = 20;
  116. type
  117. SslPtr = Pointer;
  118. PSslPtr = ^SslPtr;
  119. PSSL_CTX = SslPtr;
  120. PSSL = SslPtr;
  121. PSSL_METHOD = SslPtr;
  122. { PX509 = SslPtr;}
  123. { PX509_NAME = SslPtr;}
  124. PEVP_MD = SslPtr;
  125. PBIO_METHOD = SslPtr;
  126. PBIO = SslPtr;
  127. { EVP_PKEY = SslPtr;}
  128. PRSA = SslPtr;
  129. PASN1_UTCTIME = SslPtr;
  130. PASN1_INTEGER = SSlPtr;
  131. PDH = pointer;
  132. PSTACK_OFX509 = pointer;
  133. X509_NAME = record
  134. entries: pointer;
  135. modified: integer;
  136. bytes: pointer;
  137. hash: cardinal;
  138. end;
  139. PX509_NAME = ^X509_NAME;
  140. PDN = ^X509_NAME;
  141. ASN1_STRING = record
  142. length: integer;
  143. asn1_type: integer;
  144. data: pointer;
  145. flags: longint;
  146. end;
  147. PASN1_STRING = ^ASN1_STRING;
  148. PASN1_TIME = PASN1_STRING;
  149. X509_VAL = record
  150. notBefore: PASN1_TIME;
  151. notAfter: PASN1_TIME;
  152. end;
  153. PX509_VAL = ^X509_VAL;
  154. X509_CINF = record
  155. version: pointer;
  156. serialNumber: pointer;
  157. signature: pointer;
  158. issuer: pointer;
  159. validity: PX509_VAL;
  160. subject: pointer;
  161. key: pointer;
  162. issuerUID: pointer;
  163. subjectUID: pointer;
  164. extensions: pointer;
  165. end;
  166. PX509_CINF = ^X509_CINF;
  167. CRYPTO_EX_DATA = record
  168. sk: pointer;
  169. dummy: integer;
  170. end;
  171. X509 = record
  172. cert_info: PX509_CINF;
  173. sig_alg: pointer; // ^X509_ALGOR
  174. signature: pointer; // ^ASN1_BIT_STRING
  175. valid: integer;
  176. references: integer;
  177. name: PChar;
  178. ex_data: CRYPTO_EX_DATA;
  179. ex_pathlen: integer;
  180. ex_flags: integer;
  181. ex_kusage: integer;
  182. ex_xkusage: integer;
  183. ex_nscert: integer;
  184. skid: pointer; // ^ASN1_OCTET_STRING
  185. akid: pointer; // ?
  186. sha1_hash: array [0..SHA_DIGEST_LENGTH-1] of char;
  187. aux: pointer; // ^X509_CERT_AUX
  188. end;
  189. pX509 = ^X509;
  190. PPX509 = ^PX509;
  191. DSA = record
  192. pad: integer;
  193. version: integer;
  194. write_params: integer;
  195. p: pointer;
  196. q: pointer;
  197. g: pointer;
  198. pub_key: pointer;
  199. priv_key: pointer;
  200. kinv: pointer;
  201. r: pointer;
  202. flags: integer;
  203. method_mont_p: PChar;
  204. references: integer;
  205. ex_data: record
  206. sk: pointer;
  207. dummy: integer;
  208. end;
  209. meth: pointer;
  210. end;
  211. pDSA = ^DSA;
  212. EVP_PKEY_PKEY = record
  213. case integer of
  214. 0: (ptr: PChar);
  215. 1: (rsa: pRSA);
  216. 2: (dsa: pDSA);
  217. 3: (dh: pDH);
  218. end;
  219. EVP_PKEY = record
  220. ktype: integer;
  221. save_type: integer;
  222. references: integer;
  223. pkey: EVP_PKEY_PKEY;
  224. save_parameters: integer;
  225. attributes: PSTACK_OFX509;
  226. end;
  227. PEVP_PKEY = ^EVP_PKEY;
  228. PPEVP_PKEY = ^PEVP_PKEY;
  229. PPRSA = ^PRSA;
  230. PASN1_cInt = SslPtr;
  231. PPasswdCb = SslPtr;
  232. PFunction = procedure;
  233. DES_cblock = array[0..7] of Byte;
  234. PDES_cblock = ^DES_cblock;
  235. des_ks_struct = packed record
  236. ks: DES_cblock;
  237. weak_key: cInt;
  238. end;
  239. des_key_schedule = array[1..16] of des_ks_struct;
  240. MD2_CTX = record
  241. num: integer;
  242. data: array [0..15] of byte;
  243. cksm: array [0..15] of cardinal;
  244. state: array [0..15] of cardinal;
  245. end;
  246. MD4_CTX = record
  247. A, B, C, D: cardinal;
  248. Nl, Nh: cardinal;
  249. data: array [0..15] of cardinal;
  250. num: integer;
  251. end;
  252. MD5_CTX = record
  253. A, B, C, D: cardinal;
  254. Nl, Nh: cardinal;
  255. data: array [0..15] of cardinal;
  256. num: integer;
  257. end;
  258. RIPEMD160_CTX = record
  259. A, B, C, D, E: cardinal;
  260. Nl, Nh: cardinal;
  261. data: array [0..15] of cardinal;
  262. num: integer;
  263. end;
  264. SHA_CTX = record
  265. h0, h1, h2, h3, h4: cardinal;
  266. Nl, Nh: cardinal;
  267. data: array [0..16] of cardinal;
  268. num: integer;
  269. end;
  270. MDC2_CTX = record
  271. num: integer;
  272. data: array [0..7] of byte;
  273. h, hh: des_cblock;
  274. pad_type: integer;
  275. end;
  276. // Rand
  277. RAND_METHOD = record
  278. end;
  279. PRAND_METHOD = ^RAND_METHOD;
  280. // RSA
  281. PENGINE = Pointer;
  282. PBIGNUM = Pointer;
  283. PBN_GENCB = Pointer;
  284. PBN_MONT_CTX = Pointer;
  285. PBN_CTX = Pointer;
  286. PPByte = ^PByte;
  287. Trsa_pub_enc = function(flen: cint;
  288. const from_, to_: PByte; arsa: PRSA; padding: cint): cint;
  289. Trsa_pub_dec = function(flen: cint;
  290. const from_, to_: PByte; arsa: PRSA; padding: cint): cint;
  291. Trsa_priv_enc = function(flen: cint;
  292. const from_, to_: PByte; arsa: PRSA; padding: cint): cint;
  293. Trsa_priv_dec = function(flen: cint;
  294. const from_, to_: PByte; arsa: PRSA; padding: cint): cint;
  295. Trsa_mod_exp = function(r0: PBIGNUM; const l: PBIGNUM; arsa: PRSA; ctx: PBN_CTX): cint;
  296. Tbn_mod_exp = function(r: PBIGNUM; const a, p, m: PBIGNUM; arsa: PRSA;
  297. ctx: PBN_CTX; m_ctx: PBN_MONT_CTX): cint;
  298. Tinit = function(arsa: PRSA): cint;
  299. Tfinish = function(arsa: PRSA): cint;
  300. Trsa_sign = function(type_: cint; const m: PByte; m_length: cuint;
  301. sigret: PByte; siglen: pcuint; arsa: PRSA): cint;
  302. Trsa_verify = function(dtype: cint;
  303. const m: PByte; m_length: cuint;
  304. const sigbuf: PByte; siglen: cuint; arsa: PRSA): cint;
  305. Trsa_keygen = function(arsa: PRSA; bits: cint; e: PBIGNUM; cb: PBN_GENCB): cint;
  306. RSA_METHOD = record
  307. name: PChar;
  308. rsa_pub_enc: Trsa_pub_enc;
  309. rsa_pub_dec: Trsa_pub_dec;
  310. rsa_priv_enc: Trsa_priv_enc;
  311. rsa_priv_dec: Trsa_priv_dec;
  312. rsa_mod_exp: Trsa_mod_exp; { Can be null }
  313. bn_mod_exp: Tbn_mod_exp; { Can be null }
  314. init: Tinit; { called at new }
  315. finish: Tfinish; { called at free }
  316. flags: cint; { RSA_METHOD_FLAG_* things }
  317. app_data: PChar; { may be needed! }
  318. { New sign and verify functions: some libraries don't allow arbitrary data
  319. * to be signed/verified: this allows them to be used. Note: for this to work
  320. * the RSA_public_decrypt() and RSA_private_encrypt() should *NOT* be used
  321. * RSA_sign(), RSA_verify() should be used instead. Note: for backwards
  322. * compatibility this functionality is only enabled if the RSA_FLAG_SIGN_VER
  323. * option is set in 'flags'.
  324. }
  325. rsa_sign: Trsa_sign;
  326. rsa_verify: Trsa_verify;
  327. { If this callback is NULL, the builtin software RSA key-gen will be used. This
  328. * is for behavioural compatibility whilst the code gets rewired, but one day
  329. * it would be nice to assume there are no such things as "builtin software"
  330. * implementations. }
  331. rsa_keygen: Trsa_keygen;
  332. end;
  333. PRSA_METHOD = ^RSA_METHOD;
  334. // EVP
  335. EVP_MD_CTX = record
  336. digest: pEVP_MD;
  337. case integer of
  338. 0: (base: array [0..3] of byte);
  339. 1: (md2: MD2_CTX);
  340. 8: (md4: MD4_CTX);
  341. 2: (md5: MD5_CTX);
  342. 16: (ripemd160: RIPEMD160_CTX);
  343. 4: (sha: SHA_CTX);
  344. 32: (mdc2: MDC2_CTX);
  345. end;
  346. PEVP_MD_CTX = ^EVP_MD_CTX;
  347. PEVP_CIPHER_CTX = ^EVP_CIPHER_CTX;
  348. PASN1_TYPE = Pointer;
  349. EVP_CIPHER_INIT_FUNC = function(ctx: PEVP_CIPHER_CTX; const key, iv: PByte; enc: cint): cint; cdecl;
  350. EVP_CIPHER_DO_CIPHER_FUNC = function(ctx: PEVP_CIPHER_CTX; out_data: PByte; const in_data: PByte; inl: csize_t): cint; cdecl;
  351. EVP_CIPHER_CLEANUP_FUNC = function(ctx: PEVP_CIPHER_CTX): cint; cdecl;
  352. EVP_CIPHER_SET_ASN1_PARAMETERS_FUNC = function(ctx: PEVP_CIPHER_CTX; asn1_type: PASN1_TYPE): cint; cdecl;
  353. EVP_CIPHER_GET_ASN1_PARAMETERS_FUNC = function(ctx: PEVP_CIPHER_CTX; asn1_type: PASN1_TYPE): cint; cdecl;
  354. EVP_CIPHER_CTRL_FUNC = function(ctx: PEVP_CIPHER_CTX; type_, arg: cint; ptr: Pointer): cint; cdecl;
  355. EVP_CIPHER = record // Updated with EVP.h from OpenSSL 1.0.0
  356. nid: cint;
  357. block_size: cint;
  358. key_len: cint; //* Default value for variable length ciphers */
  359. iv_len: cint;
  360. flags: culong; //* Various flags */
  361. init: EVP_CIPHER_INIT_FUNC; //* init key */
  362. do_cipher: EVP_CIPHER_DO_CIPHER_FUNC;//* encrypt/decrypt data */
  363. cleanup: EVP_CIPHER_CLEANUP_FUNC; //* cleanup ctx */
  364. ctx_size: cint; //* how big ctx->cipher_data needs to be */
  365. set_asn1_parameters: EVP_CIPHER_SET_ASN1_PARAMETERS_FUNC; //* Populate a ASN1_TYPE with parameters */
  366. get_asn1_parameters: EVP_CIPHER_GET_ASN1_PARAMETERS_FUNC; //* Get parameters from a ASN1_TYPE */
  367. ctrl: EVP_CIPHER_CTRL_FUNC; //* Miscellaneous operations */
  368. app_data: Pointer; //* Application data */
  369. end;
  370. PEVP_CIPHER = ^EVP_CIPHER;
  371. EVP_CIPHER_CTX = record // Updated with EVP.h from OpenSSL 1.0.0
  372. cipher: PEVP_CIPHER;
  373. engine: PENGINE; //* functional reference if 'cipher' is ENGINE-provided */
  374. encrypt: cint; //* encrypt or decrypt */
  375. buf_len: cint; //* number we have left */
  376. oiv: array[0..EVP_MAX_IV_LENGTH-1] of Byte; //* original iv */
  377. iv: array[0..EVP_MAX_IV_LENGTH-1] of Byte; //* working iv */
  378. buf: array[0..EVP_MAX_IV_LENGTH-1] of Byte; //* saved partial block */
  379. num: cint; //* used by cfb/ofb mode */
  380. app_data: Pointer; //* application stuff */
  381. key_len: cint; //* May change for variable length cipher */
  382. flags: culong; //* Various flags */
  383. cipher_data: Pointer; //* per EVP data */
  384. final_used: cint;
  385. block_mask: cint;
  386. final: array[0..EVP_MAX_BLOCK_LENGTH-1] of Byte; //* possible final block */
  387. final2: array[0..$1FFF] of Byte; // Extra storage space, otherwise an access violation
  388. // in the OpenSSL library will occur
  389. end;
  390. // PEM
  391. Ppem_password_cb = Pointer;
  392. // PKCS7
  393. PPKCS7 = ^PKCS7;
  394. PPKCS7_DIGEST = ^PKCS7_DIGEST;
  395. PPKCS7_ENC_CONTENT = ^PKCS7_ENC_CONTENT;
  396. PPKCS7_ENCRYPT = ^TPKCS7_ENCRYPT;
  397. PPKCS7_ENVELOPE = ^PKCS7_ENVELOPE;
  398. PPKCS7_ISSUER_AND_SERIAL = ^PKCS7_ISSUER_AND_SERIAL;
  399. PPKCS7_RECIP_INFO = ^PKCS7_RECIP_INFO;
  400. PPKCS7_SIGN_ENVELOPE = ^PKCS7_SIGN_ENVELOPE;
  401. PPKCS7_SIGNED = ^PKCS7_SIGNED;
  402. PPKCS7_SIGNER_INFO = ^PKCS7_SIGNER_INFO;
  403. Pstack_st_X509 = Pointer;
  404. Pstack_st_X509_ALGOR = Pointer;
  405. Pstack_st_X509_ATTRIBUTE = Pointer;
  406. ppkcs7_st = ^pkcs7_st;
  407. pkcs7_issuer_and_serial_st = record
  408. issuer : ^X509_NAME;
  409. serial : PASN1_INTEGER;
  410. end;
  411. PKCS7_ISSUER_AND_SERIAL = pkcs7_issuer_and_serial_st;
  412. pkcs7_signer_info_st = record
  413. version : PASN1_INTEGER;
  414. issuer_and_serial : PPKCS7_ISSUER_AND_SERIAL;
  415. digest_alg : pointer;
  416. auth_attr : pointer;
  417. digest_enc_alg : pointer;
  418. enc_digest : pointer;
  419. unauth_attr : pointer;
  420. pkey : ^EVP_PKEY;
  421. end;
  422. PKCS7_SIGNER_INFO = pkcs7_signer_info_st;
  423. stack_st_PKCS7_SIGNER_INFO = record
  424. stack : Pointer;
  425. end;
  426. pkcs7_recip_info_st = record
  427. version : PASN1_INTEGER;
  428. issuer_and_serial : PPKCS7_ISSUER_AND_SERIAL;
  429. key_enc_algor : Pointer;
  430. enc_key : Pointer;
  431. cert : PX509;
  432. end;
  433. PKCS7_RECIP_INFO = pkcs7_recip_info_st;
  434. stack_st_PKCS7_RECIP_INFO = record
  435. stack : Pointer;
  436. end;
  437. pkcs7_signed_st = record
  438. version : PASN1_INTEGER;
  439. md_algs : Pointer;
  440. cert : pointer;
  441. crl : pointer;
  442. signer_info : pointer;
  443. contents : Pointer;
  444. end;
  445. PKCS7_SIGNED = pkcs7_signed_st;
  446. (* Const before type ignored *)
  447. pkcs7_enc_content_st = record
  448. content_type : Pointer;
  449. algorithm : Pointer;
  450. enc_data : Pointer;
  451. cipher : PEVP_CIPHER;
  452. end;
  453. PKCS7_ENC_CONTENT = pkcs7_enc_content_st;
  454. pkcs7_enveloped_st = record
  455. version : PASN1_INTEGER;
  456. recipientinfo : ^stack_st_PKCS7_RECIP_INFO;
  457. enc_data : ^PKCS7_ENC_CONTENT;
  458. end;
  459. PKCS7_ENVELOPE = pkcs7_enveloped_st;
  460. pkcs7_signedandenveloped_st = record
  461. version : PASN1_INTEGER;
  462. md_algs : Pstack_st_X509_ALGOR;
  463. cert : Pstack_st_X509;
  464. crl : Pointer;
  465. signer_info : pointer;
  466. enc_data : PPKCS7_ENC_CONTENT;
  467. recipientinfo : ^stack_st_PKCS7_RECIP_INFO;
  468. end;
  469. PKCS7_SIGN_ENVELOPE = pkcs7_signedandenveloped_st;
  470. pkcs7_digest_st = record
  471. version : PASN1_INTEGER;
  472. md : POinter;
  473. contents : ppkcs7_st;
  474. digest : Pointer;
  475. end;
  476. PKCS7_DIGEST = pkcs7_digest_st;
  477. pkcs7_encrypted_st = record
  478. version : PASN1_INTEGER;
  479. enc_data : ^PKCS7_ENC_CONTENT;
  480. end;
  481. TPKCS7_ENCRYPT = pkcs7_encrypted_st;
  482. pkcs7_st = record
  483. asn1 : ^byte;
  484. length : longint;
  485. state : longint;
  486. detached : longint;
  487. _type : Pointer;
  488. d : record
  489. case longint of
  490. 0 : ( ptr : pchar );
  491. 1 : ( data : Pointer);
  492. 2 : ( sign : PPKCS7_SIGNED );
  493. 3 : ( enveloped : ^PKCS7_ENVELOPE );
  494. 4 : ( signed_and_enveloped : ^PKCS7_SIGN_ENVELOPE );
  495. 5 : ( digest : ^PKCS7_DIGEST );
  496. 6 : ( encrypted : ^TPKCS7_ENCRYPT );
  497. 7 : ( other : PASN1_TYPE );
  498. end;
  499. end;
  500. pkcs7 = pkcs7_st;
  501. stack_st_PKCS7 = record
  502. stack : Pointer;
  503. end;
  504. PPPKCS7_ISSUER_AND_SERIAL = ^PPKCS7_ISSUER_AND_SERIAL;
  505. const
  506. SSL_ERROR_NONE = 0;
  507. SSL_ERROR_SSL = 1;
  508. SSL_ERROR_WANT_READ = 2;
  509. SSL_ERROR_WANT_WRITE = 3;
  510. SSL_ERROR_WANT_X509_LOOKUP = 4;
  511. SSL_ERROR_SYSCALL = 5; //look at error stack/return value/errno
  512. SSL_ERROR_ZERO_RETURN = 6;
  513. SSL_ERROR_WANT_CONNECT = 7;
  514. SSL_ERROR_WANT_ACCEPT = 8;
  515. SSL_CTRL_NEED_TMP_RSA = 1;
  516. SSL_CTRL_SET_TMP_RSA = 2;
  517. SSL_CTRL_SET_TMP_DH = 3;
  518. SSL_CTRL_SET_TMP_ECDH = 4;
  519. SSL_CTRL_SET_TMP_RSA_CB = 5;
  520. SSL_CTRL_SET_TMP_DH_CB = 6;
  521. SSL_CTRL_SET_TMP_ECDH_CB = 7;
  522. SSL_CTRL_GET_SESSION_REUSED = 8;
  523. SSL_CTRL_GET_CLIENT_CERT_REQUEST = 9;
  524. SSL_CTRL_GET_NUM_RENEGOTIATIONS = 10;
  525. SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS = 11;
  526. SSL_CTRL_GET_TOTAL_RENEGOTIATIONS = 12;
  527. SSL_CTRL_GET_FLAGS = 13;
  528. SSL_CTRL_EXTRA_CHAIN_CERT = 14;
  529. SSL_CTRL_SET_MSG_CALLBACK = 15;
  530. SSL_CTRL_SET_MSG_CALLBACK_ARG = 16;
  531. SSL_CTRL_SET_MTU = 17;
  532. SSL_CTRL_SESS_NUMBER = 20;
  533. SSL_CTRL_SESS_CONNECT = 21;
  534. SSL_CTRL_SESS_CONNECT_GOOD = 22;
  535. SSL_CTRL_SESS_CONNECT_RENEGOTIATE = 23;
  536. SSL_CTRL_SESS_ACCEPT = 24;
  537. SSL_CTRL_SESS_ACCEPT_GOOD = 25;
  538. SSL_CTRL_SESS_ACCEPT_RENEGOTIATE = 26;
  539. SSL_CTRL_SESS_HIT = 27;
  540. SSL_CTRL_SESS_CB_HIT = 28;
  541. SSL_CTRL_SESS_MISSES = 29;
  542. SSL_CTRL_SESS_TIMEOUTS = 30;
  543. SSL_CTRL_SESS_CACHE_FULL = 31;
  544. SSL_CTRL_OPTIONS = 32;
  545. SSL_CTRL_MODE = 33;
  546. SSL_CTRL_GET_READ_AHEAD = 40;
  547. SSL_CTRL_SET_READ_AHEAD = 41;
  548. SSL_CTRL_SET_SESS_CACHE_SIZE = 42;
  549. SSL_CTRL_GET_SESS_CACHE_SIZE = 43;
  550. SSL_CTRL_SET_SESS_CACHE_MODE = 44;
  551. SSL_CTRL_GET_SESS_CACHE_MODE = 45;
  552. SSL_CTRL_GET_MAX_CERT_LIST = 50;
  553. SSL_CTRL_SET_MAX_CERT_LIST = 51;
  554. SSL_CTRL_SET_MAX_SEND_FRAGMENT = 52;
  555. SSL_CTRL_SET_TLSEXT_SERVERNAME_CB = 53;
  556. SSL_CTRL_SET_TLSEXT_SERVERNAME_ARG = 54;
  557. SSL_CTRL_SET_TLSEXT_HOSTNAME = 55;
  558. SSL_CTRL_SET_TLSEXT_DEBUG_CB = 56;
  559. SSL_CTRL_SET_TLSEXT_DEBUG_ARG = 57;
  560. SSL_CTRL_GET_TLSEXT_TICKET_KEYS = 58;
  561. SSL_CTRL_SET_TLSEXT_TICKET_KEYS = 59;
  562. SSL_CTRL_SET_TLSEXT_OPAQUE_PRF_INPUT = 60;
  563. SSL_CTRL_SET_TLSEXT_OPAQUE_PRF_INPUT_CB = 61;
  564. SSL_CTRL_SET_TLSEXT_OPAQUE_PRF_INPUT_CB_ARG = 62;
  565. SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB = 63;
  566. SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB_ARG = 64;
  567. SSL_CTRL_SET_TLSEXT_STATUS_REQ_TYPE = 65;
  568. SSL_CTRL_GET_TLSEXT_STATUS_REQ_EXTS = 66;
  569. SSL_CTRL_SET_TLSEXT_STATUS_REQ_EXTS = 67;
  570. SSL_CTRL_GET_TLSEXT_STATUS_REQ_IDS = 68;
  571. SSL_CTRL_SET_TLSEXT_STATUS_REQ_IDS = 69;
  572. SSL_CTRL_GET_TLSEXT_STATUS_REQ_OCSP_RESP = 70;
  573. SSL_CTRL_SET_TLSEXT_STATUS_REQ_OCSP_RESP = 71;
  574. SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB = 72;
  575. SSL_CTRL_SET_TLS_EXT_SRP_USERNAME_CB = 75;
  576. SSL_CTRL_SET_SRP_VERIFY_PARAM_CB = 76;
  577. SSL_CTRL_SET_SRP_GIVE_CLIENT_PWD_CB = 77;
  578. SSL_CTRL_SET_SRP_ARG = 78;
  579. SSL_CTRL_SET_TLS_EXT_SRP_USERNAME = 79;
  580. SSL_CTRL_SET_TLS_EXT_SRP_STRENGTH = 80;
  581. SSL_CTRL_SET_TLS_EXT_SRP_PASSWORD = 81;
  582. SSL_CTRL_GET_EXTRA_CHAIN_CERTS = 82;
  583. SSL_CTRL_CLEAR_EXTRA_CHAIN_CERTS = 83;
  584. SSL_CTRL_TLS_EXT_SEND_HEARTBEAT = 85;
  585. SSL_CTRL_GET_TLS_EXT_HEARTBEAT_PENDING = 86;
  586. SSL_CTRL_SET_TLS_EXT_HEARTBEAT_NO_REQUESTS = 87;
  587. // Some missing values ?
  588. DTLS_CTRL_GET_TIMEOUT = 73;
  589. DTLS_CTRL_HANDLE_TIMEOUT = 74;
  590. DTLS_CTRL_LISTEN = 75;
  591. SSL_CTRL_GET_RI_SUPPORT = 76;
  592. SSL_CTRL_CLEAR_OPTIONS = 77;
  593. SSL_CTRL_CLEAR_MODE = 78;
  594. TLSEXT_NAMETYPE_host_name = 0;
  595. SSL_MODE_ENABLE_PARTIAL_WRITE = 1;
  596. SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER = 2;
  597. SSL_MODE_AUTO_RETRY = 4;
  598. SSL_MODE_NO_AUTO_CHAIN = 8;
  599. SSL_OP_NO_SSLv2 = $01000000;
  600. SSL_OP_NO_SSLv3 = $02000000;
  601. SSL_OP_NO_TLSv1 = $04000000;
  602. SSL_OP_ALL = $000FFFFF;
  603. SSL_VERIFY_NONE = $00;
  604. SSL_VERIFY_PEER = $01;
  605. OPENSSL_DES_DECRYPT = 0;
  606. OPENSSL_DES_ENCRYPT = 1;
  607. X509_V_OK = 0;
  608. X509_V_ILLEGAL = 1;
  609. X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT = 2;
  610. X509_V_ERR_UNABLE_TO_GET_CRL = 3;
  611. X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE = 4;
  612. X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE = 5;
  613. X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY = 6;
  614. X509_V_ERR_CERT_SIGNATURE_FAILURE = 7;
  615. X509_V_ERR_CRL_SIGNATURE_FAILURE = 8;
  616. X509_V_ERR_CERT_NOT_YET_VALID = 9;
  617. X509_V_ERR_CERT_HAS_EXPIRED = 10;
  618. X509_V_ERR_CRL_NOT_YET_VALID = 11;
  619. X509_V_ERR_CRL_HAS_EXPIRED = 12;
  620. X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD = 13;
  621. X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD = 14;
  622. X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD = 15;
  623. X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD = 16;
  624. X509_V_ERR_OUT_OF_MEM = 17;
  625. X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT = 18;
  626. X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN = 19;
  627. X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY = 20;
  628. X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE = 21;
  629. X509_V_ERR_CERT_CHAIN_TOO_LONG = 22;
  630. X509_V_ERR_CERT_REVOKED = 23;
  631. X509_V_ERR_INVALID_CA = 24;
  632. X509_V_ERR_PATH_LENGTH_EXCEEDED = 25;
  633. X509_V_ERR_INVALID_PURPOSE = 26;
  634. X509_V_ERR_CERT_UNTRUSTED = 27;
  635. X509_V_ERR_CERT_REJECTED = 28;
  636. //These are 'informational' when looking for issuer cert
  637. X509_V_ERR_SUBJECT_ISSUER_MISMATCH = 29;
  638. X509_V_ERR_AKID_SKID_MISMATCH = 30;
  639. X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH = 31;
  640. X509_V_ERR_KEYUSAGE_NO_CERTSIGN = 32;
  641. X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER = 33;
  642. X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION = 34;
  643. //The application is not happy
  644. X509_V_ERR_APPLICATION_VERIFICATION = 50;
  645. SSL_FILETYPE_ASN1 = 2;
  646. SSL_FILETYPE_PEM = 1;
  647. EVP_PKEY_RSA = 6;
  648. // RSA
  649. RSA_PKCS1_PADDING = 1;
  650. RSA_SSLV23_PADDING = 2;
  651. RSA_NO_PADDING = 3;
  652. RSA_PKCS1_OAEP_PADDING = 4;
  653. // BIO
  654. BIO_NOCLOSE = $00;
  655. BIO_CLOSE = $01;
  656. //* modifiers */
  657. BIO_FP_READ = $02;
  658. BIO_FP_WRITE = $04;
  659. BIO_FP_APPEND = $08;
  660. BIO_FP_TEXT = $10;
  661. BIO_C_SET_CONNECT = 100;
  662. BIO_C_DO_STATE_MACHINE = 101;
  663. BIO_C_SET_NBIO = 102;
  664. BIO_C_SET_PROXY_PARAM = 103;
  665. BIO_C_SET_FD = 104;
  666. BIO_C_GET_FD = 105;
  667. BIO_C_SET_FILE_PTR = 106;
  668. BIO_C_GET_FILE_PTR = 107;
  669. BIO_C_SET_FILENAME = 108;
  670. BIO_C_SET_SSL = 109;
  671. BIO_C_GET_SSL = 110;
  672. BIO_C_SET_MD = 111;
  673. BIO_C_GET_MD = 112;
  674. BIO_C_GET_CIPHER_STATUS = 113;
  675. BIO_C_SET_BUF_MEM = 114;
  676. BIO_C_GET_BUF_MEM_PTR = 115;
  677. BIO_C_GET_BUFF_NUM_LINES = 116;
  678. BIO_C_SET_BUFF_SIZE = 117;
  679. BIO_C_SET_ACCEPT = 118;
  680. BIO_C_SSL_MODE = 119;
  681. BIO_C_GET_MD_CTX = 120;
  682. BIO_C_GET_PROXY_PARAM = 121;
  683. BIO_C_SET_BUFF_READ_DATA = 122; // data to read first */
  684. BIO_C_GET_CONNECT = 123;
  685. BIO_C_GET_ACCEPT = 124;
  686. BIO_C_SET_SSL_RENEGOTIATE_BYTES = 125;
  687. BIO_C_GET_SSL_NUM_RENEGOTIATES = 126;
  688. BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT = 127;
  689. BIO_C_FILE_SEEK = 128;
  690. BIO_C_GET_CIPHER_CTX = 129;
  691. BIO_C_SET_BUF_MEM_EOF_RETURN = 130;//*return end of input value*/
  692. BIO_C_SET_BIND_MODE = 131;
  693. BIO_C_GET_BIND_MODE = 132;
  694. BIO_C_FILE_TELL = 133;
  695. BIO_C_GET_SOCKS = 134;
  696. BIO_C_SET_SOCKS = 135;
  697. BIO_C_SET_WRITE_BUF_SIZE = 136;//* for BIO_s_bio */
  698. BIO_C_GET_WRITE_BUF_SIZE = 137;
  699. BIO_C_MAKE_BIO_PAIR = 138;
  700. BIO_C_DESTROY_BIO_PAIR = 139;
  701. BIO_C_GET_WRITE_GUARANTEE = 140;
  702. BIO_C_GET_READ_REQUEST = 141;
  703. BIO_C_SHUTDOWN_WR = 142;
  704. BIO_C_NREAD0 = 143;
  705. BIO_C_NREAD = 144;
  706. BIO_C_NWRITE0 = 145;
  707. BIO_C_NWRITE = 146;
  708. BIO_C_RESET_READ_REQUEST = 147;
  709. BIO_C_SET_MD_CTX = 148;
  710. BIO_C_SET_PREFIX = 149;
  711. BIO_C_GET_PREFIX = 150;
  712. BIO_C_SET_SUFFIX = 151;
  713. BIO_C_GET_SUFFIX = 152;
  714. BIO_C_SET_EX_ARG = 153;
  715. BIO_C_GET_EX_ARG = 154;
  716. BIO_CTRL_RESET = 1 ; { opt - rewind/zero etc }
  717. BIO_CTRL_EOF = 2 ; { opt - are we at the eof }
  718. BIO_CTRL_INFO = 3 ; { opt - extra tit-bits }
  719. BIO_CTRL_SET = 4 ; { man - set the 'IO' type }
  720. BIO_CTRL_GET = 5 ; { man - get the 'IO' type }
  721. BIO_CTRL_PUSH = 6 ; { opt - internal, used to signify change }
  722. BIO_CTRL_POP = 7 ; { opt - internal, used to signify change }
  723. BIO_CTRL_GET_CLOSE = 8 ; { man - set the 'close' on free }
  724. BIO_CTRL_SET_CLOSE = 9 ; { man - set the 'close' on free }
  725. BIO_CTRL_PENDING = 10 ; { opt - is their more data buffered }
  726. BIO_CTRL_FLUSH = 11 ; { opt - 'flush' buffered output }
  727. BIO_CTRL_DUP = 12 ; { man - extra stuff for 'duped' BIO }
  728. BIO_CTRL_WPENDING = 13 ; { opt - number of bytes still to write }
  729. BIO_CTRL_SET_CALLBACK = 14 ; { opt - set callback function }
  730. BIO_CTRL_GET_CALLBACK = 15 ; { opt - set callback function }
  731. BIO_CTRL_SET_FILENAME = 30 ; { BIO_s_file special }
  732. BIO_CTRL_DGRAM_CONNECT = 31 ; { BIO dgram special }
  733. BIO_CTRL_DGRAM_SET_CONNECTED = 32 ; { allow for an externally }
  734. BIO_CTRL_DGRAM_SET_RECV_TIMEOUT = 33 ; { setsockopt, essentially }
  735. BIO_CTRL_DGRAM_GET_RECV_TIMEOUT = 34 ; { getsockopt, essentially }
  736. BIO_CTRL_DGRAM_SET_SEND_TIMEOUT = 35 ; { setsockopt, essentially }
  737. BIO_CTRL_DGRAM_GET_SEND_TIMEOUT = 36 ; { getsockopt, essentially }
  738. BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP = 37 ; { flag whether the last }
  739. BIO_CTRL_DGRAM_GET_SEND_TIMER_EXP = 38 ; { I/O operation tiemd out }
  740. BIO_CTRL_DGRAM_MTU_DISCOVER = 39 ; { set DF bit on egress packets }
  741. BIO_CTRL_DGRAM_QUERY_MTU = 40 ; { as kernel for current MTU }
  742. BIO_CTRL_DGRAM_GET_FALLBACK_MTU = 47 ;
  743. BIO_CTRL_DGRAM_GET_MTU = 41 ; { get cached value for MTU }
  744. BIO_CTRL_DGRAM_SET_MTU = 42 ; { set cached value for }
  745. BIO_CTRL_DGRAM_MTU_EXCEEDED = 43 ; { check whether the MTU }
  746. BIO_CTRL_DGRAM_GET_PEER = 46 ;
  747. BIO_CTRL_DGRAM_SET_PEER = 44 ; { Destination for the data }
  748. BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT = 45 ; { Next DTLS handshake timeout to }
  749. BIO_CTRL_DGRAM_SCTP_SET_IN_HANDSHAKE = 50;
  750. BIO_CTRL_DGRAM_SCTP_ADD_AUTH_KEY = 51;
  751. BIO_CTRL_DGRAM_SCTP_NEXT_AUTH_KEY = 52;
  752. BIO_CTRL_DGRAM_SCTP_AUTH_CCS_RCVD = 53;
  753. BIO_CTRL_DGRAM_SCTP_GET_SNDINFO = 60;
  754. BIO_CTRL_DGRAM_SCTP_SET_SNDINFO = 61;
  755. BIO_CTRL_DGRAM_SCTP_GET_RCVINFO = 62;
  756. BIO_CTRL_DGRAM_SCTP_SET_RCVINFO = 63;
  757. BIO_CTRL_DGRAM_SCTP_GET_PRINFO = 64;
  758. BIO_CTRL_DGRAM_SCTP_SET_PRINFO = 65;
  759. BIO_CTRL_DGRAM_SCTP_SAVE_SHUTDOWN = 70;
  760. //DES modes
  761. DES_ENCRYPT = 1;
  762. DES_DECRYPT = 0;
  763. var
  764. SSLLibHandle: TLibHandle = 0;
  765. SSLUtilHandle: TLibHandle = 0;
  766. SSLLibFile: string = '';
  767. SSLUtilFile: string = '';
  768. // libssl.dll
  769. function SslGetError(s: PSSL; ret_code: cInt):cInt;
  770. function SslLibraryInit:cInt;
  771. procedure SslLoadErrorStrings;
  772. // function SslCtxSetCipherList(arg0: PSSL_CTX; str: PChar):cInt;
  773. function SslCtxSetCipherList(arg0: PSSL_CTX; var str: String):cInt;
  774. function SslCtxNew(meth: PSSL_METHOD):PSSL_CTX;
  775. procedure SslCtxFree(arg0: PSSL_CTX);
  776. function SslSetFd(s: PSSL; fd: cInt):cInt;
  777. function SslCtrl(ssl: PSSL; cmd: cInt; larg: clong; parg: Pointer): cLong;
  778. function SslCTXCtrl(ctx: PSSL_CTX; cmd: cInt; larg: clong; parg: Pointer): cLong;
  779. function SSLCTXSetMode(ctx: PSSL_CTX; mode: cLong): cLong;
  780. function SSLSetMode(s: PSSL; mode: cLong): cLong;
  781. function SSLCTXGetMode(ctx: PSSL_CTX): cLong;
  782. function SSLGetMode(s: PSSL): cLong;
  783. function SslMethodV2:PSSL_METHOD;
  784. function SslMethodV3:PSSL_METHOD;
  785. function SslMethodTLSV1:PSSL_METHOD;
  786. function SslMethodV23:PSSL_METHOD;
  787. function SslCtxUsePrivateKey(ctx: PSSL_CTX; pkey: SslPtr):cInt;
  788. function SslCtxUsePrivateKeyASN1(pk: cInt; ctx: PSSL_CTX; d: String; len: cLong):cInt;
  789. // function SslCtxUsePrivateKeyFile(ctx: PSSL_CTX; const _file: PChar; _type: cInt):cInt;
  790. function SslCtxUsePrivateKeyFile(ctx: PSSL_CTX; const _file: String; _type: cInt):cInt;
  791. function SslCtxUseCertificate(ctx: PSSL_CTX; x: SslPtr):cInt;
  792. function SslCtxUseCertificateASN1(ctx: PSSL_CTX; len: cLong; d: String):cInt;
  793. function SslCtxUseCertificateFile(ctx: PSSL_CTX; const _file: String; _type: cInt):cInt;
  794. // function SslCtxUseCertificateChainFile(ctx: PSSL_CTX; const _file: PChar):cInt;
  795. function SslCtxUseCertificateChainFile(ctx: PSSL_CTX; const _file: String):cInt;
  796. function SslCtxCheckPrivateKeyFile(ctx: PSSL_CTX):cInt;
  797. procedure SslCtxSetDefaultPasswdCb(ctx: PSSL_CTX; cb: PPasswdCb);
  798. procedure SslCtxSetDefaultPasswdCbUserdata(ctx: PSSL_CTX; u: SslPtr);
  799. // function SslCtxLoadVerifyLocations(ctx: PSSL_CTX; const CAfile: PChar; const CApath: PChar):cInt;
  800. function SslCtxLoadVerifyLocations(ctx: PSSL_CTX; const CAfile: String; const CApath: String):cInt;
  801. function SslNew(ctx: PSSL_CTX):PSSL;
  802. procedure SslFree(ssl: PSSL);
  803. function SslAccept(ssl: PSSL):cInt;
  804. function SslConnect(ssl: PSSL):cInt;
  805. function SslShutdown(ssl: PSSL):cInt;
  806. function SslRead(ssl: PSSL; buf: SslPtr; num: cInt):cInt;
  807. function SslPeek(ssl: PSSL; buf: SslPtr; num: cInt):cInt;
  808. function SslWrite(ssl: PSSL; buf: SslPtr; num: cInt):cInt;
  809. function SslPending(ssl: PSSL):cInt;
  810. function SslGetVersion(ssl: PSSL):String;
  811. function SslGetPeerCertificate(ssl: PSSL):PX509;
  812. procedure SslCtxSetVerify(ctx: PSSL_CTX; mode: cInt; arg2: PFunction);
  813. function SSLGetCurrentCipher(s: PSSL):SslPtr;
  814. function SSLCipherGetName(c: SslPtr): String;
  815. function SSLCipherGetBits(c: SslPtr; var alg_bits: cInt):cInt;
  816. function SSLGetVerifyResult(ssl: PSSL):cLong;
  817. // libeay.dll
  818. procedure ERR_load_crypto_strings;
  819. function X509New: PX509;
  820. procedure X509Free(x: PX509);
  821. function X509NameOneline(a: PX509_NAME; var buf: String; size: cInt):String;
  822. function X509GetSubjectName(a: PX509):PX509_NAME;
  823. function X509GetIssuerName(a: PX509):PX509_NAME;
  824. function X509NameHash(x: PX509_NAME):cuLong;
  825. // function SslX509Digest(data: PX509; _type: PEVP_MD; md: PChar; len: PcInt):cInt;
  826. function X509Digest(data: PX509; _type: PEVP_MD; md: String; var len: cInt):cInt;
  827. function X509print(b: PBIO; a: PX509): cInt;
  828. function X509SetVersion(x: PX509; version: cInt): cInt;
  829. function X509SetPubkey(x: PX509; pkey: PEVP_PKEY): cInt;
  830. function X509GetPubkey(x: PX509): PEVP_PKEY;
  831. function X509SetIssuerName(x: PX509; name: PX509_NAME): cInt;
  832. function X509NameAddEntryByTxt(name: PX509_NAME; field: string; _type: cInt;
  833. bytes: string; len, loc, _set: cInt): cInt;
  834. function X509Sign(x: PX509; pkey: PEVP_PKEY; const md: PEVP_MD): cInt;
  835. function X509GmtimeAdj(s: PASN1_UTCTIME; adj: cInt): PASN1_UTCTIME;
  836. function X509SetNotBefore(x: PX509; tm: PASN1_UTCTIME): cInt;
  837. function X509SetNotAfter(x: PX509; tm: PASN1_UTCTIME): cInt;
  838. function X509GetSerialNumber(x: PX509): PASN1_cInt;
  839. function EvpPkeyNew: PEVP_PKEY;
  840. procedure EvpPkeyFree(pk: PEVP_PKEY);
  841. function EvpPkeyAssign(pkey: PEVP_PKEY; _type: cInt; key: Prsa): cInt;
  842. function EvpGetDigestByName(Name: String): PEVP_MD;
  843. procedure EVPcleanup;
  844. function SSLeayversion(t: cInt): string;
  845. procedure ErrErrorString(e: cInt; var buf: string; len: cInt);
  846. function ErrGetError: cInt;
  847. procedure ErrClearError;
  848. procedure ErrFreeStrings;
  849. procedure ErrRemoveState(pid: cInt);
  850. procedure RandScreen;
  851. function d2iPKCS12bio(b:PBIO; Pkcs12: SslPtr): SslPtr;
  852. function PKCS12parse(p12: SslPtr; pass: string; var pkey, cert, ca: SslPtr): cInt;
  853. procedure PKCS12free(p12: SslPtr);
  854. function Asn1UtctimeNew: PASN1_UTCTIME;
  855. procedure Asn1UtctimeFree(a: PASN1_UTCTIME);
  856. function Asn1IntegerSet(a: PASN1_INTEGER; v: integer): integer;
  857. function Asn1IntegerGet(a: PASN1_INTEGER): integer;
  858. function i2dX509bio(b: PBIO; x: PX509): cInt;
  859. function i2dPrivateKeyBio(b: PBIO; pkey: PEVP_PKEY): cInt;
  860. // 3DES functions
  861. procedure DESsetoddparity(Key: des_cblock);
  862. function DESsetkey(key: des_cblock; schedule: des_key_schedule): cInt;
  863. function DESsetkeychecked(key: des_cblock; schedule: des_key_schedule): cInt;
  864. procedure DESecbencrypt(Input: des_cblock; output: des_cblock; ks: des_key_schedule; enc: cInt);
  865. // RAND functions
  866. function RAND_set_rand_method(const meth: PRAND_METHOD): cint;
  867. function RAND_get_rand_method: PRAND_METHOD;
  868. function RAND_SSLeay: PRAND_METHOD;
  869. procedure RAND_cleanup;
  870. function RAND_bytes(buf: PByte; num: cint): cint;
  871. function RAND_pseudo_bytes(buf: PByte; num: cint): cint;
  872. procedure RAND_seed(const buf: Pointer; num: cint);
  873. procedure RAND_add(const buf: Pointer; num: cint; entropy: cdouble);
  874. function RAND_load_file(const file_name: PChar; max_bytes: clong): cint;
  875. function RAND_write_file(const file_name: PChar): cint;
  876. function RAND_file_name(file_name: PChar; num: csize_t): PChar;
  877. function RAND_status: cint;
  878. function RAND_query_egd_bytes(const path: PChar; buf: PByte; bytes: cint): cint;
  879. function RAND_egd(const path: PChar): cint;
  880. function RAND_egd_bytes(const path: PChar; bytes: cint): cint;
  881. procedure ERR_load_RAND_strings;
  882. function RAND_poll: cint;
  883. // RSA Functions
  884. function RSA_new(): PRSA;
  885. function RSA_new_method(method: PENGINE): PRSA;
  886. function RSA_size(arsa: PRSA): cint;
  887. // Deprecated Function: Don't use!
  888. // For compatibility with previous versions of this file
  889. function RsaGenerateKey(bits, e: cInt; callback: PFunction; cb_arg: SslPtr): PRSA;
  890. // New version of the previous deprecated routine
  891. function RSA_generate_key_ex(arsa: PRSA; bits: cInt; e: PBIGNUM; cb: PBN_GENCB): PRSA;
  892. //
  893. function RSA_check_key(arsa: PRSA): cint;
  894. // Next 4 return -1 on error
  895. function RSA_public_encrypt(flen: cint; from_buf, to_buf: PByte; arsa: PRSA; padding: cint): cint;
  896. function RSA_private_encrypt(flen: cint; from_buf, to_buf: PByte; arsa: PRSA; padding: cint): cint;
  897. function RSA_public_decrypt(flen: cint; from_buf, to_buf: PByte; arsa: PRSA; padding: cint): cint;
  898. function RSA_private_decrypt(flen: cint; from_buf, to_buf: PByte; arsa: PRSA; padding: cint): cint;
  899. procedure RSA_free(arsa: PRSA);
  900. //
  901. // RSA_up_flags
  902. function RSA_flags(arsa: PRSA): Integer;
  903. //
  904. procedure RSA_set_default_method(method: PRSA_METHOD);
  905. function RSA_get_default_method: PRSA_METHOD;
  906. function RSA_get_method(arsa: PRSA): PRSA_METHOD;
  907. function RSA_set_method(arsa: PRSA; method: PRSA_METHOD): PRSA_METHOD;
  908. //
  909. // RSA_memory_lock
  910. // X509 Functions
  911. function d2i_RSAPublicKey(arsa: PPRSA; pp: PPByte; len: cint): PRSA;
  912. function i2d_RSAPublicKey(arsa: PRSA; pp: PPByte): cint;
  913. function d2i_RSAPrivateKey(arsa: PPRSA; pp: PPByte; len: cint): PRSA;
  914. function i2d_RSAPrivateKey(arsa: PRSA; pp: PPByte): cint;
  915. // ERR Functions
  916. function Err_Error_String(e: cInt; buf: PChar): PChar;
  917. // Crypto Functions
  918. function SSLeay_version(t: cint): PChar;
  919. // EVP Functions - evp.h
  920. function EVP_des_ede3_cbc : PEVP_CIPHER;
  921. Function EVP_enc_null : PEVP_CIPHER;
  922. Function EVP_rc2_cbc : PEVP_CIPHER;
  923. Function EVP_rc2_40_cbc : PEVP_CIPHER;
  924. Function EVP_rc2_64_cbc : PEVP_CIPHER;
  925. Function EVP_rc4 : PEVP_CIPHER;
  926. Function EVP_rc4_40 : PEVP_CIPHER;
  927. Function EVP_des_cbc : PEVP_CIPHER;
  928. Function EVP_aes_128_cbc : PEVP_CIPHER;
  929. Function EVP_aes_192_cbc : PEVP_CIPHER;
  930. Function EVP_aes_256_cbc : PEVP_CIPHER;
  931. Function EVP_aes_128_cfb8 : PEVP_CIPHER;
  932. Function EVP_aes_192_cfb8 : PEVP_CIPHER;
  933. Function EVP_aes_256_cfb8 : PEVP_CIPHER;
  934. Function EVP_camellia_128_cbc : PEVP_CIPHER;
  935. Function EVP_camellia_192_cbc : PEVP_CIPHER;
  936. Function EVP_camellia_256_cbc : PEVP_CIPHER;
  937. procedure OpenSSL_add_all_algorithms;
  938. procedure OpenSSL_add_all_ciphers;
  939. procedure OpenSSL_add_all_digests;
  940. //
  941. function EVP_DigestInit(ctx: PEVP_MD_CTX; type_: PEVP_MD): cint;
  942. function EVP_DigestUpdate(ctx: PEVP_MD_CTX; const data: Pointer; cnt: csize_t): cint;
  943. function EVP_DigestFinal(ctx: PEVP_MD_CTX; md: PByte; s: pcuint): cint;
  944. function EVP_SignFinal(ctx: pEVP_MD_CTX; sig: pointer; var s: cardinal;
  945. key: pEVP_PKEY): integer;
  946. function EVP_PKEY_size(key: pEVP_PKEY): integer;
  947. procedure EVP_PKEY_free(key: pEVP_PKEY);
  948. function EVP_VerifyFinal(ctx: pEVP_MD_CTX; sigbuf: pointer;
  949. siglen: cardinal; pkey: pEVP_PKEY): integer;
  950. //
  951. function EVP_get_cipherbyname(const name: PChar): PEVP_CIPHER;
  952. function EVP_get_digestbyname(const name: PChar): PEVP_MD;
  953. //
  954. procedure EVP_CIPHER_CTX_init(a: PEVP_CIPHER_CTX);
  955. function EVP_CIPHER_CTX_cleanup(a: PEVP_CIPHER_CTX): cint;
  956. function EVP_CIPHER_CTX_set_key_length(x: PEVP_CIPHER_CTX; keylen: cint): cint;
  957. function EVP_CIPHER_CTX_ctrl(ctx: PEVP_CIPHER_CTX; type_, arg: cint; ptr: Pointer): cint;
  958. //
  959. function EVP_EncryptInit(ctx: PEVP_CIPHER_CTX; const chipher_: PEVP_CIPHER;
  960. const key, iv: PByte): cint;
  961. function EVP_EncryptUpdate(ctx: PEVP_CIPHER_CTX; out_: pcuchar;
  962. outlen: pcint; const in_: pcuchar; inlen: cint): cint;
  963. function EVP_EncryptFinal(ctx: PEVP_CIPHER_CTX; out_data: PByte; outlen: pcint): cint;
  964. //
  965. function EVP_DecryptInit(ctx: PEVP_CIPHER_CTX; chiphir_type: PEVP_CIPHER;
  966. const key, iv: PByte): cint;
  967. function EVP_DecryptUpdate(ctx: PEVP_CIPHER_CTX; out_data: PByte;
  968. outl: pcint; const in_: PByte; inl: cint): cint;
  969. function EVP_DecryptFinal(ctx: PEVP_CIPHER_CTX; outm: PByte; outlen: pcint): cint;
  970. //
  971. // PEM Functions - pem.h
  972. //
  973. function PEM_read_bio_PrivateKey(bp: PBIO; X: PPEVP_PKEY;
  974. cb: Ppem_password_cb; u: Pointer): PEVP_PKEY;
  975. function PEM_read_bio_PUBKEY(bp: pBIO; var x: pEVP_PKEY;
  976. cb: Ppem_password_cb; u: pointer): pEVP_PKEY;
  977. function PEM_write_bio_PrivateKey(bp: pBIO; x: pEVP_PKEY;
  978. const enc: pEVP_CIPHER; kstr: PChar; klen: Integer; cb: Ppem_password_cb;
  979. u: pointer): integer;
  980. function PEM_write_bio_PUBKEY(bp: pBIO; x: pEVP_PKEY): integer;
  981. function PEM_read_bio_X509(bp: PBIO; x: PPX509; cb: ppem_password_cb; u: pointer): PX509;
  982. // BIO Functions - bio.h
  983. function BioNew(b: PBIO_METHOD): PBIO;
  984. procedure BioFreeAll(b: PBIO);
  985. function BioSMem: PBIO_METHOD;
  986. function BioCtrlPending(b: PBIO): cInt;
  987. function BioRead(b: PBIO; var Buf: String; Len: cInt): cInt;
  988. function BioWrite(b: PBIO; Buf: String; Len: cInt): cInt;
  989. function BIO_ctrl(bp: PBIO; cmd: cint; larg: clong; parg: Pointer): clong;
  990. function BIO_read_filename(b: PBIO; const name: PChar): cint;
  991. function BIO_s_file: pBIO_METHOD;
  992. function BIO_new_file(const filename: PChar; const mode: PChar): pBIO;
  993. function BIO_new_mem_buf(buf: pointer; len: integer): pBIO;
  994. procedure CRYPTOcleanupAllExData;
  995. procedure OPENSSLaddallalgorithms;
  996. // PKCS7 functions
  997. function PKCS7_ISSUER_AND_SERIAL_new : PPKCS7_ISSUER_AND_SERIAL;
  998. procedure PKCS7_ISSUER_AND_SERIAL_free (a:PPKCS7_ISSUER_AND_SERIAL);
  999. function PKCS7_ISSUER_AND_SERIAL_digest(data:PPKCS7_ISSUER_AND_SERIAL; _type:PEVP_MD; md:Pbyte; len:Pdword):longint;
  1000. function PKCS7_dup(p7:PPKCS7):PPKCS7;
  1001. function PEM_write_bio_PKCS7_stream(_out:PBIO; p7:PPKCS7; _in:PBIO; flags:longint):longint;
  1002. function PKCS7_SIGNER_INFO_new:PPKCS7_SIGNER_INFO;
  1003. procedure PKCS7_SIGNER_INFO_free(a:PPKCS7_SIGNER_INFO);
  1004. function PKCS7_RECIP_INFO_new:PPKCS7_RECIP_INFO;
  1005. procedure PKCS7_RECIP_INFO_free(a:PPKCS7_RECIP_INFO);
  1006. function PKCS7_SIGNED_new:PPKCS7_SIGNED;
  1007. procedure PKCS7_SIGNED_free(a:PPKCS7_SIGNED);
  1008. function PKCS7_ENC_CONTENT_new:PPKCS7_ENC_CONTENT;
  1009. procedure PKCS7_ENC_CONTENT_free(a:PPKCS7_ENC_CONTENT);
  1010. function PKCS7_ENVELOPE_new:PPKCS7_ENVELOPE;
  1011. procedure PKCS7_ENVELOPE_free(a:PPKCS7_ENVELOPE);
  1012. function PKCS7_SIGN_ENVELOPE_new:PPKCS7_SIGN_ENVELOPE;
  1013. procedure PKCS7_SIGN_ENVELOPE_free(a:PPKCS7_SIGN_ENVELOPE);
  1014. function PKCS7_DIGEST_new:PPKCS7_DIGEST;
  1015. procedure PKCS7_DIGEST_free(a:PPKCS7_DIGEST);
  1016. function PKCS7_ENCRYPT_new:PPKCS7_ENCRYPT;
  1017. procedure PKCS7_ENCRYPT_free(a:PPKCS7_ENCRYPT);
  1018. function PKCS7_new:PPKCS7;
  1019. procedure PKCS7_free(a:PPKCS7);
  1020. function PKCS7_print_ctx(_out:PBIO; x:PPKCS7; indent:longint; pctx:Pointer):longint;
  1021. function PKCS7_ctrl(p7:PPKCS7; cmd:longint; larg:longint; parg:Pchar):longint;
  1022. function PKCS7_set_type(p7:PPKCS7; _type:longint):longint;
  1023. function PKCS7_set0_type_other(p7:PPKCS7; _type:longint; other:PASN1_TYPE):longint;
  1024. function PKCS7_set_content(p7:PPKCS7; p7_data:PPKCS7):longint;
  1025. function PKCS7_SIGNER_INFO_set(p7i:PPKCS7_SIGNER_INFO; x509:PX509; pkey:PEVP_PKEY; dgst:PEVP_MD):longint;
  1026. function PKCS7_SIGNER_INFO_sign(si:PPKCS7_SIGNER_INFO):longint;
  1027. function PKCS7_add_signer(p7:PPKCS7; p7i:PPKCS7_SIGNER_INFO):longint;
  1028. function PKCS7_add_certificate(p7:PPKCS7; x509:PX509):longint;
  1029. function PKCS7_add_crl(p7:PPKCS7; x509: Pointer):longint;
  1030. function PKCS7_content_new(p7:PPKCS7; nid:longint):longint;
  1031. function PKCS7_add_signature(p7:PPKCS7; x509:PX509; pkey:PEVP_PKEY; dgst:PEVP_MD):PPKCS7_SIGNER_INFO;
  1032. function PKCS7_cert_from_signer_info(p7:PPKCS7; si:PPKCS7_SIGNER_INFO):PX509;
  1033. function PKCS7_set_digest(p7:PPKCS7; md:PEVP_MD):longint;
  1034. function PKCS7_add_recipient(p7:PPKCS7; x509:PX509):PPKCS7_RECIP_INFO;
  1035. function PKCS7_add_recipient_info(p7:PPKCS7; ri:PPKCS7_RECIP_INFO):longint;
  1036. function PKCS7_RECIP_INFO_set(p7i:PPKCS7_RECIP_INFO; x509:PX509):longint;
  1037. function PKCS7_set_cipher(p7:PPKCS7; cipher:PEVP_CIPHER):longint;
  1038. function PKCS7_get_issuer_and_serial(p7:PPKCS7; idx:longint):PPKCS7_ISSUER_AND_SERIAL;
  1039. function PKCS7_digest_from_attributes(sk:Pstack_st_X509_ATTRIBUTE):Pointer;
  1040. function PKCS7_add_signed_attribute(p7si:PPKCS7_SIGNER_INFO; nid:longint; _type:longint; data:pointer):longint;
  1041. function PKCS7_add_attribute(p7si:PPKCS7_SIGNER_INFO; nid:longint; atrtype:longint; value:pointer):longint;
  1042. function PKCS7_get_attribute(si:PPKCS7_SIGNER_INFO; nid:longint):PASN1_TYPE;
  1043. function PKCS7_get_signed_attribute(si:PPKCS7_SIGNER_INFO; nid:longint):PASN1_TYPE;
  1044. function PKCS7_set_signed_attributes(p7si:PPKCS7_SIGNER_INFO; sk:Pstack_st_X509_ATTRIBUTE):longint;
  1045. function PKCS7_set_attributes(p7si:PPKCS7_SIGNER_INFO; sk:Pstack_st_X509_ATTRIBUTE):longint;
  1046. function PKCS7_sign(signcert:PX509; pkey:PEVP_PKEY; certs:Pstack_st_X509; data:PBIO; flags:longint):PPKCS7;
  1047. function PKCS7_sign_add_signer(p7:PPKCS7; signcert:PX509; pkey:PEVP_PKEY; md:PEVP_MD; flags:longint):PPKCS7_SIGNER_INFO;
  1048. function PKCS7_final(p7:PPKCS7; data:PBIO; flags:longint):longint;
  1049. function PKCS7_verify(p7:PPKCS7; certs:Pstack_st_X509; store: Pointer; indata:PBIO; _out:PBIO; flags:longint):longint;
  1050. function PKCS7_encrypt(certs:Pstack_st_X509; _in:PBIO; cipher:PEVP_CIPHER; flags:longint):PPKCS7;
  1051. function PKCS7_decrypt(p7:PPKCS7; pkey:PEVP_PKEY; cert:PX509; data:PBIO; flags:longint):longint;
  1052. function PKCS7_add_attrib_smimecap(si:PPKCS7_SIGNER_INFO; cap:Pstack_st_X509_ALGOR):longint;
  1053. function PKCS7_simple_smimecap(sk:Pstack_st_X509_ALGOR; nid:longint; arg:longint):longint;
  1054. function PKCS7_add_attrib_content_type(si:PPKCS7_SIGNER_INFO; coid:Pointer):longint;
  1055. function PKCS7_add0_attrib_signing_time(si:PPKCS7_SIGNER_INFO; t:PASN1_TIME):longint;
  1056. function PKCS7_add1_attrib_digest(si:PPKCS7_SIGNER_INFO; md:Pbyte; mdlen:longint):longint;
  1057. function BIO_new_PKCS7(_out:PBIO; p7:PPKCS7):PBIO;
  1058. procedure ERR_load_PKCS7_strings;
  1059. function IsSSLloaded: Boolean;
  1060. function InitSSLInterface: Boolean; overload;
  1061. function DestroySSLInterface: Boolean;
  1062. // compatibility with old versions.
  1063. function Islibealoaded: Boolean; deprecated;
  1064. function InitSSLInterface(AVerboseLoading: Boolean): Boolean ; overload; deprecated;
  1065. function InitSSLEAInterface(AVerboseLoading: Boolean): Boolean; deprecated;
  1066. function InitLibeaInterface(AVerboseLoading: Boolean = false): Boolean; deprecated;
  1067. function DestroySSLEAInterface: Boolean; deprecated;
  1068. function DestroyLibeaInterface: Boolean; deprecated;
  1069. var
  1070. OpenSSL_unavailable_functions: string;
  1071. implementation
  1072. {
  1073. Compatibility functions
  1074. }
  1075. Var
  1076. SSLloaded: boolean = false;
  1077. LoadVerbose : Boolean;
  1078. SSLCS : TRTLCriticalSection;
  1079. Locks: Array of TRTLCriticalSection;
  1080. function Islibealoaded: Boolean; deprecated;
  1081. begin
  1082. Result:=isSSLLoaded;
  1083. end;
  1084. function InitSSLInterface(AVerboseLoading: Boolean): Boolean ; deprecated;
  1085. Var
  1086. B : Boolean;
  1087. begin
  1088. B:=LoadVerbose;
  1089. LoadVerbose:=AVerboseLoading;
  1090. try
  1091. Result:=InitSSLInterface;
  1092. finally
  1093. LoadVerbose:=B;
  1094. end;
  1095. end;
  1096. function InitSSLEAInterface(AVerboseLoading: Boolean): Boolean; deprecated;
  1097. Var
  1098. B : Boolean;
  1099. begin
  1100. B:=LoadVerbose;
  1101. LoadVerbose:=AVerboseLoading;
  1102. try
  1103. Result:=InitSSLInterface;
  1104. finally
  1105. LoadVerbose:=B;
  1106. end;
  1107. end;
  1108. function InitLibeaInterface(AVerboseLoading: Boolean = false): Boolean; deprecated;
  1109. Var
  1110. B : Boolean;
  1111. begin
  1112. B:=LoadVerbose;
  1113. LoadVerbose:=AVerboseLoading;
  1114. try
  1115. Result:=InitSSLInterface;
  1116. finally
  1117. LoadVerbose:=B;
  1118. end;
  1119. end;
  1120. function DestroySSLEAInterface: Boolean; deprecated;
  1121. begin
  1122. Result:=DestroySSLInterface;
  1123. end;
  1124. function DestroyLibeaInterface: Boolean; deprecated;
  1125. begin
  1126. Result:=DestroySSLInterface;
  1127. end;
  1128. type
  1129. // libssl.dll
  1130. TSslGetError = function(s: PSSL; ret_code: cInt):cInt; cdecl;
  1131. TSslLibraryInit = function:cInt; cdecl;
  1132. TSslLoadErrorStrings = procedure; cdecl;
  1133. TSslCtxSetCipherList = function(arg0: PSSL_CTX; str: PChar):cInt; cdecl;
  1134. TSslCtxNew = function(meth: PSSL_METHOD):PSSL_CTX; cdecl;
  1135. TSslCtxFree = procedure(arg0: PSSL_CTX); cdecl;
  1136. TSslSetFd = function(s: PSSL; fd: cInt):cInt; cdecl;
  1137. TSslCtrl = function(ssl: PSSL; cmd: cInt; larg: clong; parg: Pointer): cLong; cdecl;
  1138. TSslCTXCtrl = function(ctx: PSSL_CTX; cmd: cInt; larg: clong; parg: Pointer): cLong; cdecl;
  1139. TSslMethodV2 = function:PSSL_METHOD; cdecl;
  1140. TSslMethodV3 = function:PSSL_METHOD; cdecl;
  1141. TSslMethodTLSV1 = function:PSSL_METHOD; cdecl;
  1142. TSslMethodV23 = function:PSSL_METHOD; cdecl;
  1143. TSslCtxUsePrivateKey = function(ctx: PSSL_CTX; pkey: sslptr):cInt; cdecl;
  1144. TSslCtxUsePrivateKeyASN1 = function(pk: cInt; ctx: PSSL_CTX; d: sslptr; len: cInt):cInt; cdecl;
  1145. TSslCtxUsePrivateKeyFile = function(ctx: PSSL_CTX; const _file: PChar; _type: cInt):cInt; cdecl;
  1146. TSslCtxUseCertificate = function(ctx: PSSL_CTX; x: SslPtr):cInt; cdecl;
  1147. TSslCtxUseCertificateASN1 = function(ctx: PSSL_CTX; len: cInt; d: SslPtr):cInt; cdecl;
  1148. TSslCtxUseCertificateFile = function(ctx: PSSL_CTX; const _file: PChar; _type: cInt):cInt; cdecl;
  1149. TSslCtxUseCertificateChainFile = function(ctx: PSSL_CTX; const _file: PChar):cInt; cdecl;
  1150. TSslCtxCheckPrivateKeyFile = function(ctx: PSSL_CTX):cInt; cdecl;
  1151. TSslCtxSetDefaultPasswdCb = procedure(ctx: PSSL_CTX; cb: SslPtr); cdecl;
  1152. TSslCtxSetDefaultPasswdCbUserdata = procedure(ctx: PSSL_CTX; u: SslPtr); cdecl;
  1153. TSslCtxLoadVerifyLocations = function(ctx: PSSL_CTX; const CAfile: PChar; const CApath: PChar):cInt; cdecl;
  1154. TSslNew = function(ctx: PSSL_CTX):PSSL; cdecl;
  1155. TSslFree = procedure(ssl: PSSL); cdecl;
  1156. TSslAccept = function(ssl: PSSL):cInt; cdecl;
  1157. TSslConnect = function(ssl: PSSL):cInt; cdecl;
  1158. TSslShutdown = function(ssl: PSSL):cInt; cdecl;
  1159. TSslRead = function(ssl: PSSL; buf: PChar; num: cInt):cInt; cdecl;
  1160. TSslPeek = function(ssl: PSSL; buf: PChar; num: cInt):cInt; cdecl;
  1161. TSslWrite = function(ssl: PSSL; const buf: PChar; num: cInt):cInt; cdecl;
  1162. TSslPending = function(ssl: PSSL):cInt; cdecl;
  1163. TSslGetVersion = function(ssl: PSSL):PChar; cdecl;
  1164. TSslGetPeerCertificate = function(ssl: PSSL):PX509; cdecl;
  1165. TSslCtxSetVerify = procedure(ctx: PSSL_CTX; mode: cInt; arg2: SslPtr); cdecl;
  1166. TSSLGetCurrentCipher = function(s: PSSL):SslPtr; cdecl;
  1167. TSSLCipherGetName = function(c: Sslptr):PChar; cdecl;
  1168. TSSLCipherGetBits = function(c: SslPtr; alg_bits: PcInt):cInt; cdecl;
  1169. TSSLGetVerifyResult = function(ssl: PSSL):cInt; cdecl;
  1170. // libeay.dll
  1171. TERR_load_crypto_strings = procedure; cdecl;
  1172. TX509New = function: PX509; cdecl;
  1173. TX509Free = procedure(x: PX509); cdecl;
  1174. TX509NameOneline = function(a: PX509_NAME; buf: PChar; size: cInt):PChar; cdecl;
  1175. TX509GetSubjectName = function(a: PX509):PX509_NAME; cdecl;
  1176. TX509GetIssuerName = function(a: PX509):PX509_NAME; cdecl;
  1177. TX509NameHash = function(x: PX509_NAME):cuLong; cdecl;
  1178. TX509Digest = function(data: PX509; _type: PEVP_MD; md: PChar; len: PcInt):cInt; cdecl;
  1179. TX509print = function(b: PBIO; a: PX509): cInt; cdecl;
  1180. TX509SetVersion = function(x: PX509; version: cInt): cInt; cdecl;
  1181. TX509SetPubkey = function(x: PX509; pkey: PEVP_PKEY): cInt; cdecl;
  1182. TX509GetPubkey = function(x: PX509): PEVP_PKEY; cdecl;
  1183. TX509SetIssuerName = function(x: PX509; name: PX509_NAME): cInt; cdecl;
  1184. TX509NameAddEntryByTxt = function(name: PX509_NAME; field: PChar; _type: cInt;
  1185. bytes: PChar; len, loc, _set: cInt): cInt; cdecl;
  1186. TX509Sign = function(x: PX509; pkey: PEVP_PKEY; const md: PEVP_MD): cInt; cdecl;
  1187. TX509GmtimeAdj = function(s: PASN1_UTCTIME; adj: cInt): PASN1_UTCTIME; cdecl;
  1188. TX509SetNotBefore = function(x: PX509; tm: PASN1_UTCTIME): cInt; cdecl;
  1189. TX509SetNotAfter = function(x: PX509; tm: PASN1_UTCTIME): cInt; cdecl;
  1190. TX509GetSerialNumber = function(x: PX509): PASN1_cInt; cdecl;
  1191. TEvpPkeyNew = function: PEVP_PKEY; cdecl;
  1192. TEvpPkeyFree = procedure(pk: PEVP_PKEY); cdecl;
  1193. TEvpPkeyAssign = function(pkey: PEVP_PKEY; _type: cInt; key: Prsa): cInt; cdecl;
  1194. TEvpGetDigestByName = function(Name: PChar): PEVP_MD; cdecl;
  1195. TEVPcleanup = procedure; cdecl;
  1196. TSSLeayversion = function(t: cInt): PChar; cdecl;
  1197. TErrErrorString = procedure(e: cInt; buf: PChar; len: cInt); cdecl;
  1198. TErrGetError = function: cInt; cdecl;
  1199. TErrClearError = procedure; cdecl;
  1200. TErrFreeStrings = procedure; cdecl;
  1201. TErrRemoveState = procedure(pid: cInt); cdecl;
  1202. TRandScreen = procedure; cdecl;
  1203. TBioNew = function(b: PBIO_METHOD): PBIO; cdecl;
  1204. TBioFreeAll = procedure(b: PBIO); cdecl;
  1205. TBioSMem = function: PBIO_METHOD; cdecl;
  1206. TBioCtrlPending = function(b: PBIO): cInt; cdecl;
  1207. TBioRead = function(b: PBIO; Buf: PChar; Len: cInt): cInt; cdecl;
  1208. TBioWrite = function(b: PBIO; Buf: PChar; Len: cInt): cInt; cdecl;
  1209. Td2iPKCS12bio = function(b:PBIO; Pkcs12: SslPtr): SslPtr; cdecl;
  1210. TPKCS12parse = function(p12: SslPtr; pass: PChar; var pkey, cert, ca: SslPtr): cInt; cdecl;
  1211. TPKCS12free = procedure(p12: SslPtr); cdecl;
  1212. TAsn1UtctimeNew = function: PASN1_UTCTIME; cdecl;
  1213. TAsn1UtctimeFree = procedure(a: PASN1_UTCTIME); cdecl;
  1214. TAsn1IntegerSet = function(a: PASN1_INTEGER; v: integer): integer; cdecl;
  1215. TAsn1IntegerGet = function(a: PASN1_INTEGER): integer; cdecl;
  1216. Ti2dX509bio = function(b: PBIO; x: PX509): cInt; cdecl;
  1217. Ti2dPrivateKeyBio= function(b: PBIO; pkey: PEVP_PKEY): cInt; cdecl;
  1218. // 3DES functions
  1219. TDESsetoddparity = procedure(Key: des_cblock); cdecl;
  1220. TDESsetkeychecked = function(key: des_cblock; schedule: des_key_schedule): cInt; cdecl;
  1221. TDESsetkey = TDESsetkeychecked;
  1222. TDESecbencrypt = procedure(Input: des_cblock; output: des_cblock; ks: des_key_schedule; enc: cInt); cdecl;
  1223. //thread lock functions
  1224. TCRYPTOnumlocks = function: cInt; cdecl;
  1225. TCRYPTOSetLockingCallback = procedure(cb: Sslptr); cdecl;
  1226. // RAND functions
  1227. TRAND_set_rand_method = function(const meth: PRAND_METHOD): cint; cdecl;
  1228. TRAND_get_rand_method = function(): PRAND_METHOD; cdecl;
  1229. TRAND_SSLeay = function(): PRAND_METHOD; cdecl;
  1230. TRAND_cleanup = procedure(); cdecl;
  1231. TRAND_bytes = function(buf: PByte; num: cint): cint; cdecl;
  1232. TRAND_pseudo_bytes = function(buf: PByte; num: cint): cint; cdecl;
  1233. TRAND_seed = procedure(const buf: Pointer; num: cint); cdecl;
  1234. TRAND_add = procedure(const buf: Pointer; num: cint; entropy: cdouble); cdecl;
  1235. TRAND_load_file = function(const file_name: PChar; max_bytes: clong): cint; cdecl;
  1236. TRAND_write_file = function(const file_name: PChar): cint; cdecl;
  1237. TRAND_file_name = function(file_name: PChar; num: csize_t): PChar; cdecl;
  1238. TRAND_status = function(): cint; cdecl;
  1239. TRAND_query_egd_bytes = function(const path: PChar; buf: PByte; bytes: cint): cint; cdecl;
  1240. TRAND_egd = function(const path: PChar): cint; cdecl;
  1241. TRAND_egd_bytes = function(const path: PChar; bytes: cint): cint; cdecl;
  1242. TERR_load_RAND_strings = procedure(); cdecl;
  1243. TRAND_poll = function(): cint; cdecl;
  1244. // RSA Functions
  1245. TRSA_new = function (): PRSA; cdecl;
  1246. TRSA_new_method = function (method: PENGINE): PRSA; cdecl;
  1247. TRSA_size = function (arsa: PRSA): cint; cdecl;
  1248. TRsaGenerateKey = function(bits, e: cInt; callback: PFunction; cb_arg: SslPtr): PRSA; cdecl;
  1249. TRSA_generate_key_ex = function (arsa: PRSA; bits: cInt; e: PBIGNUM; cb: PBN_GENCB): PRSA; cdecl;
  1250. TRSA_check_key = function (arsa: PRSA): cint; cdecl;
  1251. TRSA_public_encrypt = function (flen: cint; from_buf, to_buf: PByte; arsa: PRSA; padding: cint): cint; cdecl;
  1252. TRSA_private_encrypt = function (flen: cint; from_buf, to_buf: PByte; arsa: PRSA; padding: cint): cint; cdecl;
  1253. TRSA_public_decrypt = function (flen: cint; from_buf, to_buf: PByte; arsa: PRSA; padding: cint): cint; cdecl;
  1254. TRSA_private_decrypt = function (flen: cint; from_buf, to_buf: PByte; arsa: PRSA; padding: cint): cint; cdecl;
  1255. TRSA_free = procedure (arsa: PRSA); cdecl;
  1256. TRSA_flags = function (arsa: PRSA): Integer; cdecl;
  1257. TRSA_set_default_method = procedure (method: PRSA_METHOD); cdecl;
  1258. TRSA_get_default_method = function : PRSA_METHOD; cdecl;
  1259. TRSA_get_method = function (prsa: PRSA): PRSA_METHOD; cdecl;
  1260. TRSA_set_method = function (arsa: PRSA; method: PRSA_METHOD): PRSA_METHOD; cdecl;
  1261. // X509 Functions
  1262. Td2i_RSAPublicKey = function (arsa: PPRSA; pp: PPByte; len: cint): PRSA; cdecl;
  1263. Ti2d_RSAPublicKey = function (arsa: PRSA; pp: PPByte): cint; cdecl;
  1264. Td2i_RSAPrivateKey = function (arsa: PPRSA; pp: PPByte; len: cint): PRSA; cdecl;
  1265. Ti2d_RSAPrivateKey = function (arsa: PRSA; pp: PPByte): cint; cdecl;
  1266. // ERR Functions
  1267. TErr_Error_String = function (e: cInt; buf: PChar): PChar; cdecl;
  1268. // Crypto Functions
  1269. TSSLeay_version = function(t: cint): PChar; cdecl;
  1270. TCRYPTOcleanupAllExData = procedure; cdecl;
  1271. TOPENSSLaddallalgorithms = procedure; cdecl;
  1272. // EVP Functions
  1273. TOpenSSL_add_all_algorithms = procedure(); cdecl;
  1274. TOpenSSL_add_all_ciphers = procedure(); cdecl;
  1275. TOpenSSL_add_all_digests = procedure(); cdecl;
  1276. //
  1277. TEVP_DigestInit = function(ctx: PEVP_MD_CTX; type_: PEVP_MD): cint; cdecl;
  1278. TEVP_DigestUpdate = function(ctx: PEVP_MD_CTX; const data: Pointer; cnt: csize_t): cint; cdecl;
  1279. TEVP_DigestFinal = function(ctx: PEVP_MD_CTX; md: PByte; s: pcuint): cint; cdecl;
  1280. TEVP_SignFinal = function(ctx: pEVP_MD_CTX; sig: pointer; var s: cardinal;
  1281. key: pEVP_PKEY): integer; cdecl;
  1282. TEVP_PKEY_size = function(key: pEVP_PKEY): integer; cdecl;
  1283. TEVP_PKEY_free = Procedure(key: pEVP_PKEY); cdecl;
  1284. TEVP_VerifyFinal = function(ctx: pEVP_MD_CTX; sigbuf: pointer;
  1285. siglen: cardinal; pkey: pEVP_PKEY): integer; cdecl;
  1286. //
  1287. TEVP_CIPHERFunction = function() : PEVP_CIPHER; cdecl;
  1288. TEVP_get_cipherbyname = function(const name: PChar): PEVP_CIPHER; cdecl;
  1289. TEVP_get_digestbyname = function(const name: PChar): PEVP_MD; cdecl;
  1290. //
  1291. TEVP_CIPHER_CTX_init = procedure(a: PEVP_CIPHER_CTX); cdecl;
  1292. TEVP_CIPHER_CTX_cleanup = function(a: PEVP_CIPHER_CTX): cint; cdecl;
  1293. TEVP_CIPHER_CTX_set_key_length = function(x: PEVP_CIPHER_CTX; keylen: cint): cint; cdecl;
  1294. TEVP_CIPHER_CTX_ctrl = function(ctx: PEVP_CIPHER_CTX; type_, arg: cint; ptr: Pointer): cint; cdecl;
  1295. //
  1296. TEVP_EncryptInit = function(ctx: PEVP_CIPHER_CTX; const chipher_: PEVP_CIPHER;
  1297. const key, iv: PByte): cint; cdecl;
  1298. TEVP_EncryptUpdate = function(ctx: PEVP_CIPHER_CTX; out_: pcuchar;
  1299. outlen: pcint; const in_: pcuchar; inlen: cint): cint; cdecl;
  1300. TEVP_EncryptFinal = function(ctx: PEVP_CIPHER_CTX; out_data: PByte; outlen: pcint): cint; cdecl;
  1301. //
  1302. TEVP_DecryptInit = function(ctx: PEVP_CIPHER_CTX; chiphir_type: PEVP_CIPHER;
  1303. const key, iv: PByte): cint; cdecl;
  1304. TEVP_DecryptUpdate = function(ctx: PEVP_CIPHER_CTX; out_data: PByte;
  1305. outl: pcint; const in_: PByte; inl: cint): cint; cdecl;
  1306. TEVP_DecryptFinal = function(ctx: PEVP_CIPHER_CTX; outm: PByte; outlen: pcint): cint; cdecl;
  1307. // PEM functions
  1308. TPEM_read_bio_PrivateKey = function(bp: PBIO; X: PPEVP_PKEY;
  1309. cb: Ppem_password_cb; u: Pointer): PEVP_PKEY; cdecl;
  1310. TPEM_read_bio_PUBKEY = function(bp: pBIO; var x: pEVP_PKEY;
  1311. cb: Ppem_password_cb; u: pointer): pEVP_PKEY; cdecl;
  1312. TPEM_write_bio_PrivateKey = function(bp: pBIO; x: pEVP_PKEY;
  1313. const enc: pEVP_CIPHER; kstr: PChar; klen: Integer; cb: Ppem_password_cb;
  1314. u: pointer): integer; cdecl;
  1315. TPEM_write_bio_PUBKEY = function(bp: pBIO; x: pEVP_PKEY): integer; cdecl;
  1316. TPEM_read_bio_X509 = function(bp: pBIO; x: PPX509; cb: Ppem_password_cb; u: pointer): px509; cdecl;
  1317. // BIO Functions
  1318. TBIO_ctrl = function(bp: PBIO; cmd: cint; larg: clong; parg: Pointer): clong; cdecl;
  1319. TBIO_s_file = function: pBIO_METHOD; cdecl;
  1320. TBIO_new_file = function(const filename: PChar; const mode: PChar): pBIO; cdecl;
  1321. TBIO_new_mem_buf = function(buf: pointer; len: integer): pBIO; cdecl;
  1322. var
  1323. // libssl.dll
  1324. _SslGetError: TSslGetError = nil;
  1325. _SslLibraryInit: TSslLibraryInit = nil;
  1326. _SslLoadErrorStrings: TSslLoadErrorStrings = nil;
  1327. _SslCtxSetCipherList: TSslCtxSetCipherList = nil;
  1328. _SslCtxNew: TSslCtxNew = nil;
  1329. _SslCtxFree: TSslCtxFree = nil;
  1330. _SslSetFd: TSslSetFd = nil;
  1331. _SslCtrl: TSslCtrl = nil;
  1332. _SslCTXCtrl: TSslCTXCtrl = nil;
  1333. _SslMethodV2: TSslMethodV2 = nil;
  1334. _SslMethodV3: TSslMethodV3 = nil;
  1335. _SslMethodTLSV1: TSslMethodTLSV1 = nil;
  1336. _SslMethodV23: TSslMethodV23 = nil;
  1337. _SslCtxUsePrivateKey: TSslCtxUsePrivateKey = nil;
  1338. _SslCtxUsePrivateKeyASN1: TSslCtxUsePrivateKeyASN1 = nil;
  1339. _SslCtxUsePrivateKeyFile: TSslCtxUsePrivateKeyFile = nil;
  1340. _SslCtxUseCertificate: TSslCtxUseCertificate = nil;
  1341. _SslCtxUseCertificateASN1: TSslCtxUseCertificateASN1 = nil;
  1342. _SslCtxUseCertificateFile: TSslCtxUseCertificateFile = nil;
  1343. _SslCtxUseCertificateChainFile: TSslCtxUseCertificateChainFile = nil;
  1344. _SslCtxCheckPrivateKeyFile: TSslCtxCheckPrivateKeyFile = nil;
  1345. _SslCtxSetDefaultPasswdCb: TSslCtxSetDefaultPasswdCb = nil;
  1346. _SslCtxSetDefaultPasswdCbUserdata: TSslCtxSetDefaultPasswdCbUserdata = nil;
  1347. _SslCtxLoadVerifyLocations: TSslCtxLoadVerifyLocations = nil;
  1348. _SslNew: TSslNew = nil;
  1349. _SslFree: TSslFree = nil;
  1350. _SslAccept: TSslAccept = nil;
  1351. _SslConnect: TSslConnect = nil;
  1352. _SslShutdown: TSslShutdown = nil;
  1353. _SslRead: TSslRead = nil;
  1354. _SslPeek: TSslPeek = nil;
  1355. _SslWrite: TSslWrite = nil;
  1356. _SslPending: TSslPending = nil;
  1357. _SslGetVersion: TSslGetVersion = nil;
  1358. _SslGetPeerCertificate: TSslGetPeerCertificate = nil;
  1359. _SslCtxSetVerify: TSslCtxSetVerify = nil;
  1360. _SSLGetCurrentCipher: TSSLGetCurrentCipher = nil;
  1361. _SSLCipherGetName: TSSLCipherGetName = nil;
  1362. _SSLCipherGetBits: TSSLCipherGetBits = nil;
  1363. _SSLGetVerifyResult: TSSLGetVerifyResult = nil;
  1364. // libeay.dll
  1365. _ERR_load_crypto_strings: TERR_load_crypto_strings = nil;
  1366. _X509New: TX509New = nil;
  1367. _X509Free: TX509Free = nil;
  1368. _X509NameOneline: TX509NameOneline = nil;
  1369. _X509GetSubjectName: TX509GetSubjectName = nil;
  1370. _X509GetIssuerName: TX509GetIssuerName = nil;
  1371. _X509NameHash: TX509NameHash = nil;
  1372. _X509Digest: TX509Digest = nil;
  1373. _X509print: TX509print = nil;
  1374. _X509SetVersion: TX509SetVersion = nil;
  1375. _X509SetPubkey: TX509SetPubkey = nil;
  1376. _X509GetPubkey: TX509GetPubkey = nil;
  1377. _X509SetIssuerName: TX509SetIssuerName = nil;
  1378. _X509NameAddEntryByTxt: TX509NameAddEntryByTxt = nil;
  1379. _X509Sign: TX509Sign = nil;
  1380. _X509GmtimeAdj: TX509GmtimeAdj = nil;
  1381. _X509SetNotBefore: TX509SetNotBefore = nil;
  1382. _X509SetNotAfter: TX509SetNotAfter = nil;
  1383. _X509GetSerialNumber: TX509GetSerialNumber = nil;
  1384. _EvpPkeyNew: TEvpPkeyNew = nil;
  1385. _EvpPkeyFree: TEvpPkeyFree = nil;
  1386. _EvpPkeyAssign: TEvpPkeyAssign = nil;
  1387. _EvpGetDigestByName: TEvpGetDigestByName = nil;
  1388. _EVPcleanup: TEVPcleanup = nil;
  1389. _SSLeayversion: TSSLeayversion = nil;
  1390. _ErrErrorString: TErrErrorString = nil;
  1391. _ErrGetError: TErrGetError = nil;
  1392. _ErrClearError: TErrClearError = nil;
  1393. _ErrFreeStrings: TErrFreeStrings = nil;
  1394. _ErrRemoveState: TErrRemoveState = nil;
  1395. _RandScreen: TRandScreen = nil;
  1396. _BioNew: TBioNew = nil;
  1397. _BioFreeAll: TBioFreeAll = nil;
  1398. _BioSMem: TBioSMem = nil;
  1399. _BioCtrlPending: TBioCtrlPending = nil;
  1400. _BioRead: TBioRead = nil;
  1401. _BioWrite: TBioWrite = nil;
  1402. _d2iPKCS12bio: Td2iPKCS12bio = nil;
  1403. _PKCS12parse: TPKCS12parse = nil;
  1404. _PKCS12free: TPKCS12free = nil;
  1405. _Asn1UtctimeNew: TAsn1UtctimeNew = nil;
  1406. _Asn1UtctimeFree: TAsn1UtctimeFree = nil;
  1407. _Asn1IntegerSet: TAsn1IntegerSet = nil;
  1408. _Asn1IntegerGet: TAsn1IntegerGet = nil;
  1409. _i2dX509bio: Ti2dX509bio = nil;
  1410. _i2dPrivateKeyBio: Ti2dPrivateKeyBio = nil;
  1411. _EVP_enc_null : TEVP_CIPHERFunction = nil;
  1412. _EVP_rc2_cbc : TEVP_CIPHERFunction = nil;
  1413. _EVP_rc2_40_cbc : TEVP_CIPHERFunction = nil;
  1414. _EVP_rc2_64_cbc : TEVP_CIPHERFunction = nil;
  1415. _EVP_rc4 : TEVP_CIPHERFunction = nil;
  1416. _EVP_rc4_40 : TEVP_CIPHERFunction = nil;
  1417. _EVP_des_cbc : TEVP_CIPHERFunction = nil;
  1418. _EVP_des_ede3_cbc : TEVP_CIPHERFunction = nil;
  1419. _EVP_aes_128_cbc : TEVP_CIPHERFunction = nil;
  1420. _EVP_aes_192_cbc : TEVP_CIPHERFunction = nil;
  1421. _EVP_aes_256_cbc : TEVP_CIPHERFunction = nil;
  1422. _EVP_aes_128_cfb8 : TEVP_CIPHERFunction = nil;
  1423. _EVP_aes_192_cfb8 : TEVP_CIPHERFunction = nil;
  1424. _EVP_aes_256_cfb8 : TEVP_CIPHERFunction = nil;
  1425. _EVP_camellia_128_cbc : TEVP_CIPHERFunction = nil;
  1426. _EVP_camellia_192_cbc : TEVP_CIPHERFunction = nil;
  1427. _EVP_camellia_256_cbc : TEVP_CIPHERFunction = nil;
  1428. // 3DES functions
  1429. _DESsetoddparity: TDESsetoddparity = nil;
  1430. _DESsetkey : TDESsetkey = nil;
  1431. _DESsetkeychecked: TDESsetkeychecked = nil;
  1432. _DESecbencrypt: TDESecbencrypt = nil;
  1433. //thread lock functions
  1434. _CRYPTOnumlocks: TCRYPTOnumlocks = nil;
  1435. _CRYPTOSetLockingCallback: TCRYPTOSetLockingCallback = nil;
  1436. // RAND functions
  1437. _RAND_set_rand_method: TRAND_set_rand_method = nil;
  1438. _RAND_get_rand_method: TRAND_get_rand_method = nil;
  1439. _RAND_SSLeay: TRAND_SSLeay = nil;
  1440. _RAND_cleanup: TRAND_cleanup = nil;
  1441. _RAND_bytes: TRAND_bytes = nil;
  1442. _RAND_pseudo_bytes: TRAND_pseudo_bytes = nil;
  1443. _RAND_seed: TRAND_seed = nil;
  1444. _RAND_add: TRAND_add = nil;
  1445. _RAND_load_file: TRAND_load_file = nil;
  1446. _RAND_write_file: TRAND_write_file = nil;
  1447. _RAND_file_name: TRAND_file_name = nil;
  1448. _RAND_status: TRAND_status = nil;
  1449. _RAND_query_egd_bytes: TRAND_query_egd_bytes = nil;
  1450. _RAND_egd: TRAND_egd = nil;
  1451. _RAND_egd_bytes: TRAND_egd_bytes = nil;
  1452. _ERR_load_RAND_strings: TERR_load_RAND_strings = nil;
  1453. _RAND_poll: TRAND_poll = nil;
  1454. // RSA Functions
  1455. _RSA_new: TRSA_new = nil;
  1456. _RSA_new_method: TRSA_new_method = nil;
  1457. _RSA_size: TRSA_size = nil;
  1458. _RsaGenerateKey: TRsaGenerateKey = nil;
  1459. _RSA_generate_key_ex: TRSA_generate_key_ex = nil;
  1460. _RSA_check_key: TRSA_check_key = nil;
  1461. _RSA_public_encrypt: TRSA_public_encrypt = nil;
  1462. _RSA_private_encrypt: TRSA_private_encrypt = nil;
  1463. _RSA_public_decrypt: TRSA_public_decrypt = nil;
  1464. _RSA_private_decrypt: TRSA_private_decrypt = nil;
  1465. _RSA_free: TRSA_free = nil;
  1466. _RSA_flags: TRSA_flags = nil;
  1467. _RSA_set_default_method: TRSA_set_default_method = nil;
  1468. _RSA_get_default_method: TRSA_get_default_method = nil;
  1469. _RSA_get_method: TRSA_get_method = nil;
  1470. _RSA_set_method: TRSA_set_method = nil;
  1471. // X509 Functions
  1472. _d2i_RSAPublicKey: Td2i_RSAPublicKey = nil;
  1473. _i2d_RSAPublicKey: Ti2d_RSAPublicKey = nil;
  1474. _d2i_RSAPrivateKey: Td2i_RSAPrivateKey = nil;
  1475. _i2d_RSAPrivateKey: Ti2d_RSAPrivateKey = nil;
  1476. // ERR Functions
  1477. _Err_Error_String: TErr_Error_String = nil;
  1478. // Crypto Functions
  1479. _SSLeay_version: TSSLeay_version = nil;
  1480. _CRYPTOcleanupAllExData: TCRYPTOcleanupAllExData = nil;
  1481. _OPENSSLaddallalgorithms: TOPENSSLaddallalgorithms = nil;
  1482. // EVP Functions
  1483. _OpenSSL_add_all_algorithms: TOpenSSL_add_all_algorithms = nil;
  1484. _OpenSSL_add_all_ciphers: TOpenSSL_add_all_ciphers = nil;
  1485. _OpenSSL_add_all_digests: TOpenSSL_add_all_digests = nil;
  1486. //
  1487. _EVP_DigestInit: TEVP_DigestInit = nil;
  1488. _EVP_DigestUpdate: TEVP_DigestUpdate = nil;
  1489. _EVP_DigestFinal: TEVP_DigestFinal = nil;
  1490. _EVP_SignFinal: TEVP_SignFinal = nil;
  1491. _EVP_PKEY_size: TEVP_PKEY_size = nil;
  1492. _EVP_PKEY_free: TEVP_PKEY_free = nil;
  1493. _EVP_VerifyFinal: TEVP_VerifyFinal = nil;
  1494. //
  1495. _EVP_get_cipherbyname: TEVP_get_cipherbyname = nil;
  1496. _EVP_get_digestbyname: TEVP_get_digestbyname = nil;
  1497. //
  1498. _EVP_CIPHER_CTX_init: TEVP_CIPHER_CTX_init = nil;
  1499. _EVP_CIPHER_CTX_cleanup: TEVP_CIPHER_CTX_cleanup = nil;
  1500. _EVP_CIPHER_CTX_set_key_length: TEVP_CIPHER_CTX_set_key_length = nil;
  1501. _EVP_CIPHER_CTX_ctrl: TEVP_CIPHER_CTX_ctrl = nil;
  1502. //
  1503. _EVP_EncryptInit: TEVP_EncryptInit = nil;
  1504. _EVP_EncryptUpdate: TEVP_EncryptUpdate = nil;
  1505. _EVP_EncryptFinal: TEVP_EncryptFinal = nil;
  1506. //
  1507. _EVP_DecryptInit: TEVP_DecryptInit = nil;
  1508. _EVP_DecryptUpdate: TEVP_DecryptUpdate = nil;
  1509. _EVP_DecryptFinal: TEVP_DecryptFinal = nil;
  1510. // PEM
  1511. _PEM_read_bio_PrivateKey: TPEM_read_bio_PrivateKey = nil;
  1512. _PEM_read_bio_PUBKEY: TPEM_read_bio_PUBKEY = nil;
  1513. _PEM_write_bio_PrivateKey: TPEM_write_bio_PrivateKey = nil;
  1514. _PEM_write_bio_PUBKEY: TPEM_write_bio_PUBKEY = nil;
  1515. _PEM_read_bio_X509: TPEM_read_bio_X509 = nil;
  1516. // BIO Functions
  1517. _BIO_ctrl: TBIO_ctrl = nil;
  1518. _BIO_s_file: TBIO_s_file = nil;
  1519. _BIO_new_file: TBIO_new_file = nil;
  1520. _BIO_new_mem_buf: TBIO_new_mem_buf = nil;
  1521. // PKCS7 functions
  1522. { PKCS7_ISSUER_AND_SERIAL_it : ASN1_ITEM;cvar;external;
  1523. PKCS7_SIGNER_INFO_it : ASN1_ITEM;cvar;external;
  1524. PKCS7_RECIP_INFO_it : ASN1_ITEM;cvar;external;
  1525. PKCS7_SIGNED_it : ASN1_ITEM;cvar;external;
  1526. PKCS7_ENC_CONTENT_it : ASN1_ITEM;cvar;external;
  1527. PKCS7_ENVELOPE_it : ASN1_ITEM;cvar;external;
  1528. PKCS7_SIGN_ENVELOPE_it : ASN1_ITEM;cvar;external;
  1529. PKCS7_DIGEST_it : ASN1_ITEM;cvar;external;
  1530. PKCS7_ENCRYPT_it : ASN1_ITEM;cvar;external;
  1531. PKCS7_it : ASN1_ITEM;cvar;external;
  1532. PKCS7_ATTR_SIGN_it : ASN1_ITEM;cvar;external;
  1533. PKCS7_ATTR_VERIFY_it : ASN1_ITEM;cvar;external;
  1534. }
  1535. _PKCS7_ISSUER_AND_SERIAL_new : function: PPKCS7_ISSUER_AND_SERIAL;
  1536. _PKCS7_ISSUER_AND_SERIAL_free : procedure(a:PPKCS7_ISSUER_AND_SERIAL);
  1537. _PKCS7_ISSUER_AND_SERIAL_digest : function(data:PPKCS7_ISSUER_AND_SERIAL; _type:PEVP_MD; md:Pbyte; len:Pdword):longint;
  1538. _PKCS7_dup : function(p7:PPKCS7):PPKCS7;
  1539. _PEM_write_bio_PKCS7_stream : function(_out:PBIO; p7:PPKCS7; _in:PBIO; flags:longint):longint;
  1540. _PKCS7_SIGNER_INFO_new : function:PPKCS7_SIGNER_INFO;
  1541. _PKCS7_SIGNER_INFO_free : procedure(a:PPKCS7_SIGNER_INFO);
  1542. _PKCS7_RECIP_INFO_new : function:PPKCS7_RECIP_INFO;
  1543. _PKCS7_RECIP_INFO_free : procedure(a:PPKCS7_RECIP_INFO);
  1544. _PKCS7_SIGNED_new : function:PPKCS7_SIGNED;
  1545. _PKCS7_SIGNED_free : procedure(a:PPKCS7_SIGNED);
  1546. _PKCS7_ENC_CONTENT_new : function:PPKCS7_ENC_CONTENT;
  1547. _PKCS7_ENC_CONTENT_free : procedure(a:PPKCS7_ENC_CONTENT);
  1548. _PKCS7_ENVELOPE_new : function:PPKCS7_ENVELOPE;
  1549. _PKCS7_ENVELOPE_free : procedure(a:PPKCS7_ENVELOPE);
  1550. _PKCS7_SIGN_ENVELOPE_new : function:PPKCS7_SIGN_ENVELOPE;
  1551. _PKCS7_SIGN_ENVELOPE_free : procedure(a:PPKCS7_SIGN_ENVELOPE);
  1552. _PKCS7_DIGEST_new : function:PPKCS7_DIGEST;
  1553. _PKCS7_DIGEST_free : procedure(a:PPKCS7_DIGEST);
  1554. _PKCS7_ENCRYPT_new : function:PPKCS7_ENCRYPT;
  1555. _PKCS7_ENCRYPT_free : procedure(a:PPKCS7_ENCRYPT);
  1556. _PKCS7_new : function:PPKCS7;
  1557. _PKCS7_free : procedure(a:PPKCS7);
  1558. _PKCS7_print_ctx : function(_out:PBIO; x:PPKCS7; indent:longint; pctx:Pointer):longint;
  1559. _PKCS7_ctrl : function(p7:PPKCS7; cmd:longint; larg:longint; parg:Pchar):longint;
  1560. _PKCS7_set_type : function(p7:PPKCS7; _type:longint):longint;
  1561. _PKCS7_set0_type_other : function(p7:PPKCS7; _type:longint; other:PASN1_TYPE):longint;
  1562. _PKCS7_set_content : function(p7:PPKCS7; p7_data:PPKCS7):longint;
  1563. _PKCS7_SIGNER_INFO_set : function(p7i:PPKCS7_SIGNER_INFO; x509:PX509; pkey:PEVP_PKEY; dgst:PEVP_MD):longint;
  1564. _PKCS7_SIGNER_INFO_sign : function(si:PPKCS7_SIGNER_INFO):longint;
  1565. _PKCS7_add_signer : function(p7:PPKCS7; p7i:PPKCS7_SIGNER_INFO):longint;
  1566. _PKCS7_add_certificate : function(p7:PPKCS7; x509:PX509):longint;
  1567. _PKCS7_add_crl : function(p7:PPKCS7; x509: Pointer):longint;
  1568. _PKCS7_content_new : function(p7:PPKCS7; nid:longint):longint;
  1569. _PKCS7_add_signature : function(p7:PPKCS7; x509:PX509; pkey:PEVP_PKEY; dgst:PEVP_MD):PPKCS7_SIGNER_INFO;
  1570. _PKCS7_cert_from_signer_info : function(p7:PPKCS7; si:PPKCS7_SIGNER_INFO):PX509;
  1571. _PKCS7_set_digest : function(p7:PPKCS7; md:PEVP_MD):longint;
  1572. _PKCS7_add_recipient : function(p7:PPKCS7; x509:PX509):PPKCS7_RECIP_INFO;
  1573. _PKCS7_add_recipient_info : function(p7:PPKCS7; ri:PPKCS7_RECIP_INFO):longint;
  1574. _PKCS7_RECIP_INFO_set : function(p7i:PPKCS7_RECIP_INFO; x509:PX509):longint;
  1575. _PKCS7_set_cipher : function(p7:PPKCS7; cipher:PEVP_CIPHER):longint;
  1576. _PKCS7_get_issuer_and_serial : function(p7:PPKCS7; idx:longint):PPKCS7_ISSUER_AND_SERIAL;
  1577. _PKCS7_digest_from_attributes : function(sk:Pstack_st_X509_ATTRIBUTE):Pointer;
  1578. _PKCS7_add_signed_attribute : function(p7si:PPKCS7_SIGNER_INFO; nid:longint; _type:longint; data:pointer):longint;
  1579. _PKCS7_add_attribute : function(p7si:PPKCS7_SIGNER_INFO; nid:longint; atrtype:longint; value:pointer):longint;
  1580. _PKCS7_get_attribute : function(si:PPKCS7_SIGNER_INFO; nid:longint):PASN1_TYPE;
  1581. _PKCS7_get_signed_attribute : function(si:PPKCS7_SIGNER_INFO; nid:longint):PASN1_TYPE;
  1582. _PKCS7_set_signed_attributes : function(p7si:PPKCS7_SIGNER_INFO; sk:Pstack_st_X509_ATTRIBUTE):longint;
  1583. _PKCS7_set_attributes : function(p7si:PPKCS7_SIGNER_INFO; sk:Pstack_st_X509_ATTRIBUTE):longint;
  1584. _PKCS7_sign : function(signcert:PX509; pkey:PEVP_PKEY; certs:Pstack_st_X509; data:PBIO; flags:longint):PPKCS7;
  1585. _PKCS7_sign_add_signer : function(p7:PPKCS7; signcert:PX509; pkey:PEVP_PKEY; md:PEVP_MD; flags:longint):PPKCS7_SIGNER_INFO;
  1586. _PKCS7_final : function(p7:PPKCS7; data:PBIO; flags:longint):longint;
  1587. _PKCS7_verify : function(p7:PPKCS7; certs:Pstack_st_X509; store: Pointer; indata:PBIO; _out:PBIO; flags:longint):longint;
  1588. _PKCS7_encrypt : function(certs:Pstack_st_X509; _in:PBIO; cipher:PEVP_CIPHER; flags:longint):PPKCS7;
  1589. _PKCS7_decrypt : function(p7:PPKCS7; pkey:PEVP_PKEY; cert:PX509; data:PBIO; flags:longint):longint;
  1590. _PKCS7_add_attrib_smimecap : function(si:PPKCS7_SIGNER_INFO; cap:Pstack_st_X509_ALGOR):longint;
  1591. _PKCS7_simple_smimecap : function(sk:Pstack_st_X509_ALGOR; nid:longint; arg:longint):longint;
  1592. _PKCS7_add_attrib_content_type : function(si:PPKCS7_SIGNER_INFO; coid:Pointer):longint;
  1593. _PKCS7_add0_attrib_signing_time : function(si:PPKCS7_SIGNER_INFO; t:PASN1_TIME):longint;
  1594. _PKCS7_add1_attrib_digest : function(si:PPKCS7_SIGNER_INFO; md:Pbyte; mdlen:longint):longint;
  1595. _BIO_new_PKCS7 : function(_out:PBIO; p7:PPKCS7):PBIO;
  1596. _ERR_load_PKCS7_strings : procedure;
  1597. // libssl.dll
  1598. function SslGetError(s: PSSL; ret_code: cInt):cInt;
  1599. begin
  1600. if InitSSLInterface and Assigned(_SslGetError) then
  1601. Result := _SslGetError(s, ret_code)
  1602. else
  1603. Result := SSL_ERROR_SSL;
  1604. end;
  1605. function SslLibraryInit:cInt;
  1606. begin
  1607. if InitSSLInterface and Assigned(_SslLibraryInit) then
  1608. Result := _SslLibraryInit
  1609. else
  1610. Result := 1;
  1611. end;
  1612. procedure SslLoadErrorStrings;
  1613. begin
  1614. if InitSSLInterface and Assigned(_SslLoadErrorStrings) then
  1615. _SslLoadErrorStrings;
  1616. end;
  1617. function SslCtxSetCipherList(arg0: PSSL_CTX; var str: String):cInt;
  1618. begin
  1619. if InitSSLInterface and Assigned(_SslCtxSetCipherList) then
  1620. Result := _SslCtxSetCipherList(arg0, PChar(str))
  1621. else
  1622. Result := 0;
  1623. end;
  1624. function SslCtxNew(meth: PSSL_METHOD):PSSL_CTX;
  1625. begin
  1626. if InitSSLInterface and Assigned(_SslCtxNew) then
  1627. Result := _SslCtxNew(meth)
  1628. else
  1629. Result := nil;
  1630. end;
  1631. procedure SslCtxFree(arg0: PSSL_CTX);
  1632. begin
  1633. if InitSSLInterface and Assigned(_SslCtxFree) then
  1634. _SslCtxFree(arg0);
  1635. end;
  1636. function SslSetFd(s: PSSL; fd: cInt):cInt;
  1637. begin
  1638. if InitSSLInterface and Assigned(_SslSetFd) then
  1639. Result := _SslSetFd(s, fd)
  1640. else
  1641. Result := 0;
  1642. end;
  1643. function SslCtrl(ssl: PSSL; cmd: cInt; larg: clong; parg: Pointer): cLong;
  1644. begin
  1645. if InitSSLInterface and Assigned(_SslCtrl) then
  1646. Result := _SslCtrl(ssl, cmd, larg, parg)
  1647. else
  1648. Result := 0;
  1649. end;
  1650. function SslCTXCtrl(ctx: PSSL_CTX; cmd: cInt; larg: clong; parg: Pointer
  1651. ): cLong;
  1652. begin
  1653. if InitSSLInterface and Assigned(_SslCTXCtrl) then
  1654. Result := _SslCTXCtrl(ctx, cmd, larg, parg)
  1655. else
  1656. Result := 0;
  1657. end;
  1658. function SSLCTXSetMode(ctx: PSSL_CTX; mode: cLong): cLong;
  1659. begin
  1660. Result := SslCTXCtrl(ctx, SSL_CTRL_MODE, mode, nil);
  1661. end;
  1662. function SSLSetMode(s: PSSL; mode: cLong): cLong;
  1663. begin
  1664. Result := SSLctrl(s, SSL_CTRL_MODE, mode, nil);
  1665. end;
  1666. function SSLCTXGetMode(ctx: PSSL_CTX): cLong;
  1667. begin
  1668. Result := SSLCTXctrl(ctx, SSL_CTRL_MODE, 0, nil);
  1669. end;
  1670. function SSLGetMode(s: PSSL): cLong;
  1671. begin
  1672. Result := SSLctrl(s, SSL_CTRL_MODE, 0, nil);
  1673. end;
  1674. function SslMethodV2:PSSL_METHOD;
  1675. begin
  1676. if InitSSLInterface and Assigned(_SslMethodV2) then
  1677. Result := _SslMethodV2
  1678. else
  1679. Result := nil;
  1680. end;
  1681. function SslMethodV3:PSSL_METHOD;
  1682. begin
  1683. if InitSSLInterface and Assigned(_SslMethodV3) then
  1684. Result := _SslMethodV3
  1685. else
  1686. Result := nil;
  1687. end;
  1688. function SslMethodTLSV1:PSSL_METHOD;
  1689. begin
  1690. if InitSSLInterface and Assigned(_SslMethodTLSV1) then
  1691. Result := _SslMethodTLSV1
  1692. else
  1693. Result := nil;
  1694. end;
  1695. function SslMethodV23:PSSL_METHOD;
  1696. begin
  1697. if InitSSLInterface and Assigned(_SslMethodV23) then
  1698. Result := _SslMethodV23
  1699. else
  1700. Result := nil;
  1701. end;
  1702. function SslCtxUsePrivateKey(ctx: PSSL_CTX; pkey: SslPtr):cInt;
  1703. begin
  1704. if InitSSLInterface and Assigned(_SslCtxUsePrivateKey) then
  1705. Result := _SslCtxUsePrivateKey(ctx, pkey)
  1706. else
  1707. Result := 0;
  1708. end;
  1709. function SslCtxUsePrivateKeyASN1(pk: cInt; ctx: PSSL_CTX; d: String; len: cLong):cInt;
  1710. begin
  1711. if InitSSLInterface and Assigned(_SslCtxUsePrivateKeyASN1) then
  1712. Result := _SslCtxUsePrivateKeyASN1(pk, ctx, Sslptr(d), len)
  1713. else
  1714. Result := 0;
  1715. end;
  1716. function SslCtxUsePrivateKeyFile(ctx: PSSL_CTX; const _file: String; _type: cInt):cInt;
  1717. begin
  1718. if InitSSLInterface and Assigned(_SslCtxUsePrivateKeyFile) then
  1719. Result := _SslCtxUsePrivateKeyFile(ctx, PChar(_file), _type)
  1720. else
  1721. Result := 0;
  1722. end;
  1723. function SslCtxUseCertificate(ctx: PSSL_CTX; x: SslPtr):cInt;
  1724. begin
  1725. if InitSSLInterface and Assigned(_SslCtxUseCertificate) then
  1726. Result := _SslCtxUseCertificate(ctx, x)
  1727. else
  1728. Result := 0;
  1729. end;
  1730. function SslCtxUseCertificateASN1(ctx: PSSL_CTX; len: cLong; d: String):cInt;
  1731. begin
  1732. if InitSSLInterface and Assigned(_SslCtxUseCertificateASN1) then
  1733. Result := _SslCtxUseCertificateASN1(ctx, len, SslPtr(d))
  1734. else
  1735. Result := 0;
  1736. end;
  1737. function SslCtxUseCertificateFile(ctx: PSSL_CTX; const _file: String; _type: cInt):cInt;
  1738. begin
  1739. if InitSSLInterface and Assigned(_SslCtxUseCertificateFile) then
  1740. Result := _SslCtxUseCertificateFile(ctx, PChar(_file), _type)
  1741. else
  1742. Result := 0;
  1743. end;
  1744. function SslCtxUseCertificateChainFile(ctx: PSSL_CTX; const _file: String):cInt;
  1745. begin
  1746. if InitSSLInterface and Assigned(_SslCtxUseCertificateChainFile) then
  1747. Result := _SslCtxUseCertificateChainFile(ctx, PChar(_file))
  1748. else
  1749. Result := 0;
  1750. end;
  1751. function SslCtxCheckPrivateKeyFile(ctx: PSSL_CTX):cInt;
  1752. begin
  1753. if InitSSLInterface and Assigned(_SslCtxCheckPrivateKeyFile) then
  1754. Result := _SslCtxCheckPrivateKeyFile(ctx)
  1755. else
  1756. Result := 0;
  1757. end;
  1758. procedure SslCtxSetDefaultPasswdCb(ctx: PSSL_CTX; cb: PPasswdCb);
  1759. begin
  1760. if InitSSLInterface and Assigned(_SslCtxSetDefaultPasswdCb) then
  1761. _SslCtxSetDefaultPasswdCb(ctx, cb);
  1762. end;
  1763. procedure SslCtxSetDefaultPasswdCbUserdata(ctx: PSSL_CTX; u: SslPtr);
  1764. begin
  1765. if InitSSLInterface and Assigned(_SslCtxSetDefaultPasswdCbUserdata) then
  1766. _SslCtxSetDefaultPasswdCbUserdata(ctx, u);
  1767. end;
  1768. function SslCtxLoadVerifyLocations(ctx: PSSL_CTX; const CAfile: String; const CApath: String):cInt;
  1769. begin
  1770. if InitSSLInterface and Assigned(_SslCtxLoadVerifyLocations) then
  1771. Result := _SslCtxLoadVerifyLocations(ctx, SslPtr(CAfile), SslPtr(CApath))
  1772. else
  1773. Result := 0;
  1774. end;
  1775. function SslNew(ctx: PSSL_CTX):PSSL;
  1776. begin
  1777. if InitSSLInterface and Assigned(_SslNew) then
  1778. Result := _SslNew(ctx)
  1779. else
  1780. Result := nil;
  1781. end;
  1782. procedure SslFree(ssl: PSSL);
  1783. begin
  1784. if InitSSLInterface and Assigned(_SslFree) then
  1785. _SslFree(ssl);
  1786. end;
  1787. function SslAccept(ssl: PSSL):cInt;
  1788. begin
  1789. if InitSSLInterface and Assigned(_SslAccept) then
  1790. Result := _SslAccept(ssl)
  1791. else
  1792. Result := -1;
  1793. end;
  1794. function SslConnect(ssl: PSSL):cInt;
  1795. begin
  1796. if InitSSLInterface and Assigned(_SslConnect) then
  1797. Result := _SslConnect(ssl)
  1798. else
  1799. Result := -1;
  1800. end;
  1801. function SslShutdown(ssl: PSSL):cInt;
  1802. begin
  1803. if InitSSLInterface and Assigned(_SslShutdown) then
  1804. Result := _SslShutdown(ssl)
  1805. else
  1806. Result := -1;
  1807. end;
  1808. function SslRead(ssl: PSSL; buf: SslPtr; num: cInt):cInt;
  1809. begin
  1810. if InitSSLInterface and Assigned(_SslRead) then
  1811. Result := _SslRead(ssl, PChar(buf), num)
  1812. else
  1813. Result := -1;
  1814. end;
  1815. function SslPeek(ssl: PSSL; buf: SslPtr; num: cInt):cInt;
  1816. begin
  1817. if InitSSLInterface and Assigned(_SslPeek) then
  1818. Result := _SslPeek(ssl, PChar(buf), num)
  1819. else
  1820. Result := -1;
  1821. end;
  1822. function SslWrite(ssl: PSSL; buf: SslPtr; num: cInt):cInt;
  1823. begin
  1824. if InitSSLInterface and Assigned(_SslWrite) then
  1825. Result := _SslWrite(ssl, PChar(buf), num)
  1826. else
  1827. Result := -1;
  1828. end;
  1829. function SslPending(ssl: PSSL):cInt;
  1830. begin
  1831. if InitSSLInterface and Assigned(_SslPending) then
  1832. Result := _SslPending(ssl)
  1833. else
  1834. Result := 0;
  1835. end;
  1836. //function SslGetVersion(ssl: PSSL):PChar;
  1837. function SslGetVersion(ssl: PSSL):String;
  1838. begin
  1839. if InitSSLInterface and Assigned(_SslGetVersion) then
  1840. Result := _SslGetVersion(ssl)
  1841. else
  1842. Result := '';
  1843. end;
  1844. function SslGetPeerCertificate(ssl: PSSL):PX509;
  1845. begin
  1846. if InitSSLInterface and Assigned(_SslGetPeerCertificate) then
  1847. Result := _SslGetPeerCertificate(ssl)
  1848. else
  1849. Result := nil;
  1850. end;
  1851. procedure SslCtxSetVerify(ctx: PSSL_CTX; mode: cInt; arg2: PFunction);
  1852. begin
  1853. if InitSSLInterface and Assigned(_SslCtxSetVerify) then
  1854. _SslCtxSetVerify(ctx, mode, @arg2);
  1855. end;
  1856. function SSLGetCurrentCipher(s: PSSL):SslPtr;
  1857. begin
  1858. if InitSSLInterface and Assigned(_SSLGetCurrentCipher) then
  1859. {$IFDEF CIL}
  1860. {$ELSE}
  1861. Result := _SSLGetCurrentCipher(s)
  1862. {$ENDIF}
  1863. else
  1864. Result := nil;
  1865. end;
  1866. function SSLCipherGetName(c: SslPtr):String;
  1867. begin
  1868. if InitSSLInterface and Assigned(_SSLCipherGetName) then
  1869. Result := _SSLCipherGetName(c)
  1870. else
  1871. Result := '';
  1872. end;
  1873. function SSLCipherGetBits(c: SslPtr; var alg_bits: cInt):cInt;
  1874. begin
  1875. if InitSSLInterface and Assigned(_SSLCipherGetBits) then
  1876. Result := _SSLCipherGetBits(c, @alg_bits)
  1877. else
  1878. Result := 0;
  1879. end;
  1880. function SSLGetVerifyResult(ssl: PSSL):cLong;
  1881. begin
  1882. if InitSSLInterface and Assigned(_SSLGetVerifyResult) then
  1883. Result := _SSLGetVerifyResult(ssl)
  1884. else
  1885. Result := X509_V_ERR_APPLICATION_VERIFICATION;
  1886. end;
  1887. // libeay.dll
  1888. function SSLeayversion(t: cInt): string;
  1889. begin
  1890. if InitSSLInterface and Assigned(_SSLeayversion) then
  1891. Result := PChar(_SSLeayversion(t))
  1892. else
  1893. Result := '';
  1894. end;
  1895. procedure ERR_load_crypto_strings;
  1896. Begin
  1897. if InitSSLInterface and Assigned(_ERR_load_crypto_strings) then
  1898. _ERR_load_crypto_strings;
  1899. end;
  1900. function X509New: PX509;
  1901. begin
  1902. if InitSSLInterface and Assigned(_X509New) then
  1903. Result := _X509New
  1904. else
  1905. Result := nil;
  1906. end;
  1907. procedure X509Free(x: PX509);
  1908. begin
  1909. if InitSSLInterface and Assigned(_X509Free) then
  1910. _X509Free(x);
  1911. end;
  1912. function X509NameOneline(a: PX509_NAME; var buf: String; size: cInt):String;
  1913. begin
  1914. if InitSSLInterface and Assigned(_X509NameOneline) then
  1915. Result := _X509NameOneline(a, PChar(buf),size)
  1916. else
  1917. Result := '';
  1918. end;
  1919. function X509GetSubjectName(a: PX509):PX509_NAME;
  1920. begin
  1921. if InitSSLInterface and Assigned(_X509GetSubjectName) then
  1922. Result := _X509GetSubjectName(a)
  1923. else
  1924. Result := nil;
  1925. end;
  1926. function X509GetIssuerName(a: PX509):PX509_NAME;
  1927. begin
  1928. if InitSSLInterface and Assigned(_X509GetIssuerName) then
  1929. Result := _X509GetIssuerName(a)
  1930. else
  1931. Result := nil;
  1932. end;
  1933. function X509NameHash(x: PX509_NAME):cuLong;
  1934. begin
  1935. if InitSSLInterface and Assigned(_X509NameHash) then
  1936. Result := _X509NameHash(x)
  1937. else
  1938. Result := 0;
  1939. end;
  1940. function X509Digest(data: PX509; _type: PEVP_MD; md: String; var len: cInt):cInt;
  1941. begin
  1942. if InitSSLInterface and Assigned(_X509Digest) then
  1943. Result := _X509Digest(data, _type, PChar(md), @len)
  1944. else
  1945. Result := 0;
  1946. end;
  1947. function EvpPkeyNew: PEVP_PKEY;
  1948. begin
  1949. if InitSSLInterface and Assigned(_EvpPkeyNew) then
  1950. Result := _EvpPkeyNew
  1951. else
  1952. Result := nil;
  1953. end;
  1954. procedure EvpPkeyFree(pk: PEVP_PKEY);
  1955. begin
  1956. if InitSSLInterface and Assigned(_EvpPkeyFree) then
  1957. _EvpPkeyFree(pk);
  1958. end;
  1959. procedure ErrErrorString(e: cInt; var buf: string; len: cInt);
  1960. begin
  1961. if InitSSLInterface and Assigned(_ErrErrorString) then
  1962. _ErrErrorString(e, Pointer(buf), len);
  1963. buf := PChar(Buf);
  1964. end;
  1965. function ErrGetError: cInt;
  1966. begin
  1967. if InitSSLInterface and Assigned(_ErrGetError) then
  1968. Result := _ErrGetError
  1969. else
  1970. Result := SSL_ERROR_SSL;
  1971. end;
  1972. procedure ErrClearError;
  1973. begin
  1974. if InitSSLInterface and Assigned(_ErrClearError) then
  1975. _ErrClearError;
  1976. end;
  1977. procedure ErrFreeStrings;
  1978. begin
  1979. if InitSSLInterface and Assigned(_ErrFreeStrings) then
  1980. _ErrFreeStrings;
  1981. end;
  1982. procedure ErrRemoveState(pid: cInt);
  1983. begin
  1984. if InitSSLInterface and Assigned(_ErrRemoveState) then
  1985. _ErrRemoveState(pid);
  1986. end;
  1987. procedure EVPcleanup;
  1988. begin
  1989. if InitSSLInterface and Assigned(_EVPcleanup) then
  1990. _EVPcleanup;
  1991. end;
  1992. procedure RandScreen;
  1993. begin
  1994. if InitSSLInterface and Assigned(_RandScreen) then
  1995. _RandScreen;
  1996. end;
  1997. function BioNew(b: PBIO_METHOD): PBIO;
  1998. begin
  1999. if InitSSLInterface and Assigned(_BioNew) then
  2000. Result := _BioNew(b)
  2001. else
  2002. Result := nil;
  2003. end;
  2004. procedure BioFreeAll(b: PBIO);
  2005. begin
  2006. if InitSSLInterface and Assigned(_BioFreeAll) then
  2007. _BioFreeAll(b);
  2008. end;
  2009. function BioSMem: PBIO_METHOD;
  2010. begin
  2011. if InitSSLInterface and Assigned(_BioSMem) then
  2012. Result := _BioSMem
  2013. else
  2014. Result := nil;
  2015. end;
  2016. function BioCtrlPending(b: PBIO): cInt;
  2017. begin
  2018. if InitSSLInterface and Assigned(_BioCtrlPending) then
  2019. Result := _BioCtrlPending(b)
  2020. else
  2021. Result := 0;
  2022. end;
  2023. function BioRead(b: PBIO; var Buf: String; Len: cInt): cInt;
  2024. begin
  2025. if InitSSLInterface and Assigned(_BioRead) then
  2026. Result := _BioRead(b, PChar(Buf), Len)
  2027. else
  2028. Result := -2;
  2029. end;
  2030. //function BioWrite(b: PBIO; Buf: PChar; Len: cInt): cInt;
  2031. function BioWrite(b: PBIO; Buf: String; Len: cInt): cInt;
  2032. begin
  2033. if InitSSLInterface and Assigned(_BioWrite) then
  2034. Result := _BioWrite(b, PChar(Buf), Len)
  2035. else
  2036. Result := -2;
  2037. end;
  2038. function X509print(b: PBIO; a: PX509): cInt;
  2039. begin
  2040. if InitSSLInterface and Assigned(_X509print) then
  2041. Result := _X509print(b, a)
  2042. else
  2043. Result := 0;
  2044. end;
  2045. function d2iPKCS12bio(b:PBIO; Pkcs12: SslPtr): SslPtr;
  2046. begin
  2047. if InitSSLInterface and Assigned(_d2iPKCS12bio) then
  2048. Result := _d2iPKCS12bio(b, Pkcs12)
  2049. else
  2050. Result := nil;
  2051. end;
  2052. function PKCS12parse(p12: SslPtr; pass: string; var pkey, cert, ca: SslPtr): cInt;
  2053. begin
  2054. if InitSSLInterface and Assigned(_PKCS12parse) then
  2055. Result := _PKCS12parse(p12, SslPtr(pass), pkey, cert, ca)
  2056. else
  2057. Result := 0;
  2058. end;
  2059. procedure PKCS12free(p12: SslPtr);
  2060. begin
  2061. if InitSSLInterface and Assigned(_PKCS12free) then
  2062. _PKCS12free(p12);
  2063. end;
  2064. function EvpPkeyAssign(pkey: PEVP_PKEY; _type: cInt; key: Prsa): cInt;
  2065. begin
  2066. if InitSSLInterface and Assigned(_EvpPkeyAssign) then
  2067. Result := _EvpPkeyAssign(pkey, _type, key)
  2068. else
  2069. Result := 0;
  2070. end;
  2071. function X509SetVersion(x: PX509; version: cInt): cInt;
  2072. begin
  2073. if InitSSLInterface and Assigned(_X509SetVersion) then
  2074. Result := _X509SetVersion(x, version)
  2075. else
  2076. Result := 0;
  2077. end;
  2078. function X509SetPubkey(x: PX509; pkey: PEVP_PKEY): cInt;
  2079. begin
  2080. if InitSSLInterface and Assigned(_X509SetPubkey) then
  2081. Result := _X509SetPubkey(x, pkey)
  2082. else
  2083. Result := 0;
  2084. end;
  2085. function X509GetPubkey(x: PX509): PEVP_PKEY;
  2086. begin
  2087. if InitSSLInterface and Assigned(_X509GetPubkey) then
  2088. Result := _X509GetPubkey(x)
  2089. else
  2090. Result := 0;
  2091. end;
  2092. function X509SetIssuerName(x: PX509; name: PX509_NAME): cInt;
  2093. begin
  2094. if InitSSLInterface and Assigned(_X509SetIssuerName) then
  2095. Result := _X509SetIssuerName(x, name)
  2096. else
  2097. Result := 0;
  2098. end;
  2099. function X509NameAddEntryByTxt(name: PX509_NAME; field: string; _type: cInt;
  2100. bytes: string; len, loc, _set: cInt): cInt;
  2101. begin
  2102. if InitSSLInterface and Assigned(_X509NameAddEntryByTxt) then
  2103. Result := _X509NameAddEntryByTxt(name, PChar(field), _type, PChar(Bytes), len, loc, _set)
  2104. else
  2105. Result := 0;
  2106. end;
  2107. function X509Sign(x: PX509; pkey: PEVP_PKEY; const md: PEVP_MD): cInt;
  2108. begin
  2109. if InitSSLInterface and Assigned(_X509Sign) then
  2110. Result := _X509Sign(x, pkey, md)
  2111. else
  2112. Result := 0;
  2113. end;
  2114. function Asn1UtctimeNew: PASN1_UTCTIME;
  2115. begin
  2116. if InitSSLInterface and Assigned(_Asn1UtctimeNew) then
  2117. Result := _Asn1UtctimeNew
  2118. else
  2119. Result := nil;
  2120. end;
  2121. procedure Asn1UtctimeFree(a: PASN1_UTCTIME);
  2122. begin
  2123. if InitSSLInterface and Assigned(_Asn1UtctimeFree) then
  2124. _Asn1UtctimeFree(a);
  2125. end;
  2126. function Asn1IntegerSet(a: PASN1_INTEGER; v: integer): integer;
  2127. begin
  2128. if InitSSLInterface and Assigned(_Asn1IntegerSet) then
  2129. Result := _Asn1IntegerSet(a, v)
  2130. else
  2131. Result := 0;
  2132. end;
  2133. function Asn1IntegerGet(a: PASN1_INTEGER): integer;
  2134. begin
  2135. if InitSSLInterface and Assigned(_Asn1IntegerGet) then
  2136. Result := _Asn1IntegerGet(a)
  2137. else
  2138. Result := 0;
  2139. end;
  2140. function X509GmtimeAdj(s: PASN1_UTCTIME; adj: cInt): PASN1_UTCTIME;
  2141. begin
  2142. if InitSSLInterface and Assigned(_X509GmtimeAdj) then
  2143. Result := _X509GmtimeAdj(s, adj)
  2144. else
  2145. Result := nil;
  2146. end;
  2147. function X509SetNotBefore(x: PX509; tm: PASN1_UTCTIME): cInt;
  2148. begin
  2149. if InitSSLInterface and Assigned(_X509SetNotBefore) then
  2150. Result := _X509SetNotBefore(x, tm)
  2151. else
  2152. Result := 0;
  2153. end;
  2154. function X509SetNotAfter(x: PX509; tm: PASN1_UTCTIME): cInt;
  2155. begin
  2156. if InitSSLInterface and Assigned(_X509SetNotAfter) then
  2157. Result := _X509SetNotAfter(x, tm)
  2158. else
  2159. Result := 0;
  2160. end;
  2161. function i2dX509bio(b: PBIO; x: PX509): cInt;
  2162. begin
  2163. if InitSSLInterface and Assigned(_i2dX509bio) then
  2164. Result := _i2dX509bio(b, x)
  2165. else
  2166. Result := 0;
  2167. end;
  2168. function i2dPrivateKeyBio(b: PBIO; pkey: PEVP_PKEY): cInt;
  2169. begin
  2170. if InitSSLInterface and Assigned(_i2dPrivateKeyBio) then
  2171. Result := _i2dPrivateKeyBio(b, pkey)
  2172. else
  2173. Result := 0;
  2174. end;
  2175. function EvpGetDigestByName(Name: String): PEVP_MD;
  2176. begin
  2177. if InitSSLInterface and Assigned(_EvpGetDigestByName) then
  2178. Result := _EvpGetDigestByName(PChar(Name))
  2179. else
  2180. Result := nil;
  2181. end;
  2182. function X509GetSerialNumber(x: PX509): PASN1_cInt;
  2183. begin
  2184. if InitSSLInterface and Assigned(_X509GetSerialNumber) then
  2185. Result := _X509GetSerialNumber(x)
  2186. else
  2187. Result := nil;
  2188. end;
  2189. // 3DES functions
  2190. procedure DESsetoddparity(Key: des_cblock);
  2191. begin
  2192. if InitSSLInterface and Assigned(_DESsetoddparity) then
  2193. _DESsetoddparity(Key);
  2194. end;
  2195. function DESsetkey(key: des_cblock; schedule: des_key_schedule): cInt;
  2196. begin
  2197. if InitSSLInterface and Assigned(_DESsetkey) then
  2198. Result := _DESsetkey(key, schedule)
  2199. else
  2200. Result := -1;
  2201. end;
  2202. function DESsetkeychecked(key: des_cblock; schedule: des_key_schedule): cInt;
  2203. begin
  2204. if InitSSLInterface and Assigned(_DESsetkeychecked) then
  2205. Result := _DESsetkeychecked(key, schedule)
  2206. else
  2207. Result := -1;
  2208. end;
  2209. procedure DESecbencrypt(Input: des_cblock; output: des_cblock; ks: des_key_schedule; enc: cInt);
  2210. begin
  2211. if InitSSLInterface and Assigned(_DESecbencrypt) then
  2212. _DESecbencrypt(Input, output, ks, enc);
  2213. end;
  2214. // RAND functions
  2215. function RAND_set_rand_method(const meth: PRAND_METHOD): cint;
  2216. begin
  2217. if InitSSLInterface and Assigned(_RAND_set_rand_method) then
  2218. Result := _RAND_set_rand_method(meth)
  2219. else
  2220. Result := -1;
  2221. end;
  2222. function RAND_get_rand_method: PRAND_METHOD;
  2223. begin
  2224. if InitSSLInterface and Assigned(_RAND_get_rand_method) then
  2225. Result := _RAND_get_rand_method()
  2226. else
  2227. Result := nil;
  2228. end;
  2229. function RAND_SSLeay: PRAND_METHOD;
  2230. begin
  2231. if InitSSLInterface and Assigned(_RAND_SSLeay) then
  2232. Result := _RAND_SSLeay()
  2233. else
  2234. Result := nil;
  2235. end;
  2236. procedure RAND_cleanup;
  2237. begin
  2238. if InitSSLInterface and Assigned(_RAND_cleanup) then
  2239. _RAND_cleanup();
  2240. end;
  2241. function RAND_bytes(buf: PByte; num: cint): cint;
  2242. begin
  2243. if InitSSLInterface and Assigned(_RAND_bytes) then
  2244. Result := _RAND_bytes(buf, num)
  2245. else
  2246. Result := -1;
  2247. end;
  2248. function RAND_pseudo_bytes(buf: PByte; num: cint): cint;
  2249. begin
  2250. if InitSSLInterface and Assigned(_RAND_pseudo_bytes) then
  2251. Result := _RAND_pseudo_bytes(buf, num)
  2252. else
  2253. Result := -1;
  2254. end;
  2255. procedure RAND_seed(const buf: Pointer; num: cint);
  2256. begin
  2257. if InitSSLInterface and Assigned(_RAND_seed) then
  2258. _RAND_seed(buf, num);
  2259. end;
  2260. procedure RAND_add(const buf: Pointer; num: cint; entropy: cdouble);
  2261. begin
  2262. if InitSSLInterface and Assigned(_RAND_add) then
  2263. _RAND_add(buf, num, entropy);
  2264. end;
  2265. function RAND_load_file(const file_name: PChar; max_bytes: clong): cint;
  2266. begin
  2267. if InitSSLInterface and Assigned(_RAND_load_file) then
  2268. Result := _RAND_load_file(file_name, max_bytes)
  2269. else
  2270. Result := -1;
  2271. end;
  2272. function RAND_write_file(const file_name: PChar): cint;
  2273. begin
  2274. if InitSSLInterface and Assigned(_RAND_write_file) then
  2275. Result := _RAND_write_file(file_name)
  2276. else
  2277. Result := -1;
  2278. end;
  2279. function RAND_file_name(file_name: PChar; num: csize_t): PChar;
  2280. begin
  2281. if InitSSLInterface and Assigned(_RAND_file_name) then
  2282. Result := _RAND_file_name(file_name, num)
  2283. else
  2284. Result := nil;
  2285. end;
  2286. function RAND_status: cint;
  2287. begin
  2288. if InitSSLInterface and Assigned(_RAND_status) then
  2289. Result := _RAND_status()
  2290. else
  2291. Result := -1;
  2292. end;
  2293. function RAND_query_egd_bytes(const path: PChar; buf: PByte; bytes: cint): cint;
  2294. begin
  2295. if InitSSLInterface and Assigned(_RAND_query_egd_bytes) then
  2296. Result := _RAND_query_egd_bytes(path, buf, bytes)
  2297. else
  2298. Result := -1;
  2299. end;
  2300. function RAND_egd(const path: PChar): cint;
  2301. begin
  2302. if InitSSLInterface and Assigned(_RAND_egd) then
  2303. Result := _RAND_egd(path)
  2304. else
  2305. Result := -1;
  2306. end;
  2307. function RAND_egd_bytes(const path: PChar; bytes: cint): cint;
  2308. begin
  2309. if InitSSLInterface and Assigned(_RAND_egd_bytes) then
  2310. Result := _RAND_egd_bytes(path, bytes)
  2311. else
  2312. Result := -1;
  2313. end;
  2314. procedure ERR_load_RAND_strings;
  2315. begin
  2316. if InitSSLInterface and Assigned(_ERR_load_RAND_strings) then
  2317. _ERR_load_RAND_strings();
  2318. end;
  2319. function RAND_poll: cint;
  2320. begin
  2321. if InitSSLInterface and Assigned(_RAND_poll) then
  2322. Result := _RAND_poll()
  2323. else
  2324. Result := -1;
  2325. end;
  2326. // RSA Functions
  2327. function RSA_new(): PRSA;
  2328. begin
  2329. if InitSSLInterface and Assigned(_RSA_new) then
  2330. Result := _RSA_new()
  2331. else
  2332. Result := nil;
  2333. end;
  2334. function RSA_new_method(method: PENGINE): PRSA;
  2335. begin
  2336. if InitSSLInterface and Assigned(_RSA_new_method) then
  2337. Result := _RSA_new_method(method)
  2338. else
  2339. Result := nil;
  2340. end;
  2341. function RSA_size(arsa: PRSA): cint;
  2342. begin
  2343. if InitSSLInterface and Assigned(_RSA_size) then
  2344. Result := _RSA_size(arsa)
  2345. else
  2346. Result := -1;
  2347. end;
  2348. function RsaGenerateKey(bits, e: cInt; callback: PFunction; cb_arg: SslPtr): PRSA;
  2349. begin
  2350. if InitSSLInterface and Assigned(_RsaGenerateKey) then
  2351. Result := _RsaGenerateKey(bits, e, callback, cb_arg)
  2352. else
  2353. Result := nil;
  2354. end;
  2355. function RSA_generate_key_ex(arsa: PRSA; bits: cInt; e: PBIGNUM; cb: PBN_GENCB): PRSA;
  2356. begin
  2357. if InitSSLInterface and Assigned(_RSA_generate_key_ex) then
  2358. Result := _RSA_generate_key_ex(arsa, bits, e, cb)
  2359. else
  2360. Result := nil;
  2361. end;
  2362. function RSA_check_key(arsa: PRSA): cint;
  2363. begin
  2364. if InitSSLInterface and Assigned(_RSA_check_key) then
  2365. Result := _RSA_check_key(arsa)
  2366. else
  2367. Result := -1;
  2368. end;
  2369. function RSA_public_encrypt(flen: cint; from_buf, to_buf: PByte; arsa: PRSA; padding: cint): cint;
  2370. begin
  2371. if InitSSLInterface and Assigned(_RSA_public_encrypt) then
  2372. Result := _RSA_public_encrypt(flen, from_buf, to_buf, arsa, padding)
  2373. else
  2374. Result := -1;
  2375. end;
  2376. function RSA_private_encrypt(flen: cint; from_buf, to_buf: PByte; arsa: PRSA; padding: cint): cint;
  2377. begin
  2378. if InitSSLInterface and Assigned(_RSA_private_encrypt) then
  2379. Result := _RSA_private_encrypt(flen, from_buf, to_buf, arsa, padding)
  2380. else
  2381. Result := -1;
  2382. end;
  2383. function RSA_public_decrypt(flen: cint; from_buf, to_buf: PByte; arsa: PRSA; padding: cint): cint;
  2384. begin
  2385. if InitSSLInterface and Assigned(_RSA_public_decrypt) then
  2386. Result := _RSA_public_decrypt(flen, from_buf, to_buf, arsa, padding)
  2387. else
  2388. Result := -1;
  2389. end;
  2390. function RSA_private_decrypt(flen: cint; from_buf, to_buf: PByte; arsa: PRSA; padding: cint): cint;
  2391. begin
  2392. if InitSSLInterface and Assigned(_RSA_private_decrypt) then
  2393. Result := _RSA_private_decrypt(flen, from_buf, to_buf, arsa, padding)
  2394. else
  2395. Result := -1;
  2396. end;
  2397. procedure RSA_free(arsa: PRSA);
  2398. begin
  2399. if InitSSLInterface and Assigned(_RSA_free) then
  2400. _RSA_free(arsa);
  2401. end;
  2402. function RSA_flags(arsa: PRSA): Integer;
  2403. begin
  2404. if InitSSLInterface and Assigned(_RSA_flags) then
  2405. Result := _RSA_flags(arsa)
  2406. else
  2407. Result := -1;
  2408. end;
  2409. procedure RSA_set_default_method(method: PRSA_METHOD);
  2410. begin
  2411. if InitSSLInterface and Assigned(_RSA_set_default_method) then
  2412. _RSA_set_default_method(method);
  2413. end;
  2414. function RSA_get_default_method: PRSA_METHOD;
  2415. begin
  2416. if InitSSLInterface and Assigned(_RSA_get_default_method) then
  2417. Result := _RSA_get_default_method()
  2418. else
  2419. Result := nil;
  2420. end;
  2421. function RSA_get_method(arsa: PRSA): PRSA_METHOD;
  2422. begin
  2423. if InitSSLInterface and Assigned(_RSA_get_method) then
  2424. Result := _RSA_get_method(arsa)
  2425. else
  2426. Result := nil;
  2427. end;
  2428. function RSA_set_method(arsa: PRSA; method: PRSA_METHOD): PRSA_METHOD;
  2429. begin
  2430. if InitSSLInterface and Assigned(_RSA_set_method) then
  2431. Result := _RSA_set_method(arsa, method)
  2432. else
  2433. Result := nil;
  2434. end;
  2435. function d2i_RSAPublicKey(arsa: PPRSA; pp: PPByte; len: cint): PRSA;
  2436. begin
  2437. if InitSSLInterface and Assigned(_d2i_RSAPublicKey) then
  2438. Result := _d2i_RSAPublicKey(arsa, pp, len)
  2439. else
  2440. Result := nil;
  2441. end;
  2442. function i2d_RSAPublicKey(arsa: PRSA; pp: PPByte): cint;
  2443. begin
  2444. if InitSSLInterface and Assigned(_i2d_RSAPublicKey) then
  2445. Result := _i2d_RSAPublicKey(arsa, pp)
  2446. else
  2447. Result := -1;
  2448. end;
  2449. function d2i_RSAPrivateKey(arsa: PPRSA; pp: PPByte; len: cint): PRSA;
  2450. begin
  2451. if InitSSLInterface and Assigned(_d2i_RSAPrivateKey) then
  2452. Result := _d2i_RSAPrivateKey(arsa, pp, len)
  2453. else
  2454. Result := nil;
  2455. end;
  2456. function i2d_RSAPrivateKey(arsa: PRSA; pp: PPByte): cint;
  2457. begin
  2458. if InitSSLInterface and Assigned(_i2d_RSAPrivateKey) then
  2459. Result := _i2d_RSAPrivateKey(arsa, pp)
  2460. else
  2461. Result := -1;
  2462. end;
  2463. // ERR Functions
  2464. function Err_Error_String(e: cInt; buf: PChar): PChar;
  2465. begin
  2466. if InitSSLInterface and Assigned(_Err_Error_String) then
  2467. Result := _Err_Error_String(e, buf)
  2468. else
  2469. Result := nil;
  2470. end;
  2471. // Crypto Functions
  2472. function SSLeay_version(t: cint): PChar;
  2473. begin
  2474. if InitSSLInterface and Assigned(_SSLeay_version) then
  2475. Result := _SSLeay_version(t)
  2476. else
  2477. Result := nil;
  2478. end;
  2479. // EVP Functions
  2480. function EVP_des_ede3_cbc: PEVP_CIPHER;
  2481. begin
  2482. if InitSSLInterface and Assigned(_EVP_des_ede3_cbc) then
  2483. Result := _EVP_des_ede3_cbc()
  2484. else
  2485. Result := Nil;
  2486. end;
  2487. function EVP_enc_null: PEVP_CIPHER;
  2488. begin
  2489. if InitSSLInterface and Assigned(_EVP_enc_null) then
  2490. Result := _EVP_enc_null()
  2491. else
  2492. Result := Nil;
  2493. end;
  2494. function EVP_rc2_cbc: PEVP_CIPHER;
  2495. begin
  2496. if InitSSLInterface and Assigned(_EVP_rc2_cbc) then
  2497. Result := _EVP_rc2_cbc()
  2498. else
  2499. Result := Nil;
  2500. end;
  2501. function EVP_rc2_40_cbc: PEVP_CIPHER;
  2502. begin
  2503. if InitSSLInterface and Assigned(_EVP_rc2_40_cbc) then
  2504. Result := _EVP_rc2_40_cbc()
  2505. else
  2506. Result := Nil;
  2507. end;
  2508. function EVP_rc2_64_cbc: PEVP_CIPHER;
  2509. begin
  2510. if InitSSLInterface and Assigned(_EVP_rc2_64_cbc) then
  2511. Result := _EVP_rc2_64_cbc()
  2512. else
  2513. Result := Nil;
  2514. end;
  2515. function EVP_rc4: PEVP_CIPHER;
  2516. begin
  2517. if InitSSLInterface and Assigned(_EVP_rc4) then
  2518. Result := _EVP_rc4()
  2519. else
  2520. Result := Nil;
  2521. end;
  2522. function EVP_rc4_40: PEVP_CIPHER;
  2523. begin
  2524. if InitSSLInterface and Assigned(_EVP_rc4_40) then
  2525. Result := _EVP_rc4_40()
  2526. else
  2527. Result := Nil;
  2528. end;
  2529. function EVP_des_cbc: PEVP_CIPHER;
  2530. begin
  2531. if InitSSLInterface and Assigned(_EVP_des_cbc) then
  2532. Result := _EVP_des_cbc()
  2533. else
  2534. Result := Nil;
  2535. end;
  2536. function EVP_aes_128_cbc: PEVP_CIPHER;
  2537. begin
  2538. if InitSSLInterface and Assigned(_EVP_aes_128_cbc) then
  2539. Result := _EVP_aes_128_cbc()
  2540. else
  2541. Result := Nil;
  2542. end;
  2543. function EVP_aes_192_cbc: PEVP_CIPHER;
  2544. begin
  2545. if InitSSLInterface and Assigned(_EVP_aes_192_cbc) then
  2546. Result := _EVP_aes_192_cbc()
  2547. else
  2548. Result := Nil;
  2549. end;
  2550. function EVP_aes_256_cbc: PEVP_CIPHER;
  2551. begin
  2552. if InitSSLInterface and Assigned(_EVP_aes_256_cbc) then
  2553. Result := _EVP_aes_256_cbc()
  2554. else
  2555. Result := Nil;
  2556. end;
  2557. function EVP_aes_128_cfb8: PEVP_CIPHER;
  2558. begin
  2559. if InitSSLInterface and Assigned(_EVP_aes_128_cfb8) then
  2560. Result := _EVP_aes_128_cfb8()
  2561. else
  2562. Result := Nil;
  2563. end;
  2564. function EVP_aes_192_cfb8: PEVP_CIPHER;
  2565. begin
  2566. if InitSSLInterface and Assigned(_EVP_aes_192_cfb8) then
  2567. Result := _EVP_aes_192_cfb8()
  2568. else
  2569. Result := Nil;
  2570. end;
  2571. function EVP_aes_256_cfb8: PEVP_CIPHER;
  2572. begin
  2573. if InitSSLInterface and Assigned(_EVP_aes_256_cfb8) then
  2574. Result := _EVP_aes_256_cfb8()
  2575. else
  2576. Result := Nil;
  2577. end;
  2578. function EVP_camellia_128_cbc: PEVP_CIPHER;
  2579. begin
  2580. if InitSSLInterface and Assigned(_EVP_camellia_128_cbc) then
  2581. Result := _EVP_camellia_128_cbc()
  2582. else
  2583. Result := Nil;
  2584. end;
  2585. function EVP_camellia_192_cbc: PEVP_CIPHER;
  2586. begin
  2587. if InitSSLInterface and Assigned(_EVP_camellia_192_cbc) then
  2588. Result := _EVP_camellia_192_cbc()
  2589. else
  2590. Result := Nil;
  2591. end;
  2592. function EVP_camellia_256_cbc: PEVP_CIPHER;
  2593. begin
  2594. if InitSSLInterface and Assigned(_EVP_camellia_256_cbc) then
  2595. Result := _EVP_camellia_256_cbc()
  2596. else
  2597. Result := Nil;
  2598. end;
  2599. procedure OpenSSL_add_all_algorithms;
  2600. begin
  2601. if InitSSLInterface and Assigned(_OpenSSL_add_all_algorithms) then
  2602. _OpenSSL_add_all_algorithms();
  2603. end;
  2604. procedure OpenSSL_add_all_ciphers;
  2605. begin
  2606. if InitSSLInterface and Assigned(_OpenSSL_add_all_ciphers) then
  2607. _OpenSSL_add_all_ciphers();
  2608. end;
  2609. procedure OpenSSL_add_all_digests;
  2610. begin
  2611. if InitSSLInterface and Assigned(_OpenSSL_add_all_digests) then
  2612. _OpenSSL_add_all_digests();
  2613. end;
  2614. //
  2615. function EVP_DigestInit(ctx: PEVP_MD_CTX; type_: PEVP_MD): cint;
  2616. begin
  2617. if InitSSLInterface and Assigned(_EVP_DigestInit) then
  2618. Result := _EVP_DigestInit(ctx, type_)
  2619. else
  2620. Result := -1;
  2621. end;
  2622. function EVP_DigestUpdate(ctx: PEVP_MD_CTX; const data: Pointer; cnt: csize_t): cint;
  2623. begin
  2624. if InitSSLInterface and Assigned(_EVP_DigestUpdate) then
  2625. Result := _EVP_DigestUpdate(ctx, data, cnt)
  2626. else
  2627. Result := -1;
  2628. end;
  2629. function EVP_DigestFinal(ctx: PEVP_MD_CTX; md: PByte; s: pcuint): cint;
  2630. begin
  2631. if InitSSLInterface and Assigned(_EVP_DigestFinal) then
  2632. Result := _EVP_DigestFinal(ctx, md, s)
  2633. else
  2634. Result := -1;
  2635. end;
  2636. function EVP_SignFinal(ctx: pEVP_MD_CTX; sig: pointer; var s: cardinal;
  2637. key: pEVP_PKEY): integer;
  2638. begin
  2639. if InitSSLInterface and Assigned(_EVP_SignFinal) then
  2640. Result := _EVP_SignFinal(ctx, sig, s, key)
  2641. else
  2642. Result := -1;
  2643. end;
  2644. function EVP_PKEY_size(key: pEVP_PKEY): integer;
  2645. begin
  2646. if InitSSLInterface and Assigned(_EVP_PKEY_size) then
  2647. Result := _EVP_PKEY_size(key)
  2648. else
  2649. Result := -1;
  2650. end;
  2651. procedure EVP_PKEY_free(key: pEVP_PKEY);
  2652. begin
  2653. if InitSSLInterface and Assigned(_EVP_PKEY_free) then
  2654. _EVP_PKEY_free(key);
  2655. end;
  2656. function EVP_VerifyFinal(ctx: pEVP_MD_CTX; sigbuf: pointer;
  2657. siglen: cardinal; pkey: pEVP_PKEY): integer;
  2658. begin
  2659. if InitSSLInterface and Assigned(_EVP_VerifyFinal) then
  2660. Result := _EVP_VerifyFinal(ctx, sigbuf, siglen, pkey)
  2661. else
  2662. Result := -1;
  2663. end;
  2664. //
  2665. function EVP_get_cipherbyname(const name: PChar): PEVP_CIPHER;
  2666. begin
  2667. if InitSSLInterface and Assigned(_EVP_get_cipherbyname) then
  2668. Result := _EVP_get_cipherbyname(name)
  2669. else
  2670. Result := nil;
  2671. end;
  2672. function EVP_get_digestbyname(const name: PChar): PEVP_MD;
  2673. begin
  2674. if InitSSLInterface and Assigned(_EVP_get_digestbyname) then
  2675. Result := _EVP_get_digestbyname(name)
  2676. else
  2677. Result := nil;
  2678. end;
  2679. //
  2680. procedure EVP_CIPHER_CTX_init(a: PEVP_CIPHER_CTX);
  2681. begin
  2682. if InitSSLInterface and Assigned(_EVP_CIPHER_CTX_init) then
  2683. _EVP_CIPHER_CTX_init(a);
  2684. end;
  2685. function EVP_CIPHER_CTX_cleanup(a: PEVP_CIPHER_CTX): cint;
  2686. begin
  2687. if InitSSLInterface and Assigned(_EVP_CIPHER_CTX_cleanup) then
  2688. Result := _EVP_CIPHER_CTX_cleanup(a)
  2689. else
  2690. Result := -1;
  2691. end;
  2692. function EVP_CIPHER_CTX_set_key_length(x: PEVP_CIPHER_CTX; keylen: cint): cint;
  2693. begin
  2694. if InitSSLInterface and Assigned(_EVP_CIPHER_CTX_set_key_length) then
  2695. Result := _EVP_CIPHER_CTX_set_key_length(x, keylen)
  2696. else
  2697. Result := -1;
  2698. end;
  2699. function EVP_CIPHER_CTX_ctrl(ctx: PEVP_CIPHER_CTX; type_, arg: cint; ptr: Pointer): cint;
  2700. begin
  2701. if InitSSLInterface and Assigned(_EVP_CIPHER_CTX_ctrl) then
  2702. Result := _EVP_CIPHER_CTX_ctrl(ctx, type_, arg, ptr)
  2703. else
  2704. Result := -1;
  2705. end;
  2706. //
  2707. function EVP_EncryptInit(ctx: PEVP_CIPHER_CTX; const chipher_: PEVP_CIPHER;
  2708. const key, iv: PByte): cint;
  2709. begin
  2710. if InitSSLInterface and Assigned(_EVP_EncryptInit) then
  2711. Result := _EVP_EncryptInit(ctx, chipher_, key, iv)
  2712. else
  2713. Result := -1;
  2714. end;
  2715. function EVP_EncryptUpdate(ctx: PEVP_CIPHER_CTX; out_: pcuchar;
  2716. outlen: pcint; const in_: pcuchar; inlen: cint): cint;
  2717. begin
  2718. if InitSSLInterface and Assigned(_EVP_EncryptUpdate) then
  2719. Result := _EVP_EncryptUpdate(ctx, out_, outlen, in_, inlen)
  2720. else
  2721. Result := -1;
  2722. end;
  2723. function EVP_EncryptFinal(ctx: PEVP_CIPHER_CTX; out_data: PByte; outlen: pcint): cint;
  2724. begin
  2725. if InitSSLInterface and Assigned(_EVP_EncryptFinal) then
  2726. Result := _EVP_EncryptFinal(ctx, out_data, outlen)
  2727. else
  2728. Result := -1;
  2729. end;
  2730. //
  2731. function EVP_DecryptInit(ctx: PEVP_CIPHER_CTX; chiphir_type: PEVP_CIPHER;
  2732. const key, iv: PByte): cint;
  2733. begin
  2734. if InitSSLInterface and Assigned(_EVP_DecryptInit) then
  2735. Result := _EVP_DecryptInit(ctx, chiphir_type, key, iv)
  2736. else
  2737. Result := -1;
  2738. end;
  2739. function EVP_DecryptUpdate(ctx: PEVP_CIPHER_CTX; out_data: PByte;
  2740. outl: pcint; const in_: PByte; inl: cint): cint;
  2741. begin
  2742. if InitSSLInterface and Assigned(_EVP_DecryptUpdate) then
  2743. Result := _EVP_DecryptUpdate(ctx, out_data, outl, in_, inl)
  2744. else
  2745. Result := -1;
  2746. end;
  2747. function EVP_DecryptFinal(ctx: PEVP_CIPHER_CTX; outm: PByte; outlen: pcint): cint;
  2748. begin
  2749. if InitSSLInterface and Assigned(_EVP_DecryptFinal) then
  2750. Result := _EVP_DecryptFinal(ctx, outm, outlen)
  2751. else
  2752. Result := -1;
  2753. end;
  2754. { PEM }
  2755. function PEM_read_bio_PrivateKey(bp: PBIO; X: PPEVP_PKEY;
  2756. cb: Ppem_password_cb; u: Pointer): PEVP_PKEY;
  2757. begin
  2758. if InitSSLInterface and Assigned(_PEM_read_bio_PrivateKey) then
  2759. Result := _PEM_read_bio_PrivateKey(bp, x, cb, u)
  2760. else
  2761. Result := nil;
  2762. end;
  2763. function PEM_read_bio_PUBKEY(bp: pBIO; var x: pEVP_PKEY;
  2764. cb: Ppem_password_cb; u: pointer): pEVP_PKEY;
  2765. begin
  2766. if InitSSLInterface and Assigned(_PEM_read_bio_PUBKEY) then
  2767. Result := _PEM_read_bio_PUBKEY(bp, x, cb, u)
  2768. else
  2769. Result := nil;
  2770. end;
  2771. function PEM_write_bio_PrivateKey(bp: pBIO; x: pEVP_PKEY;
  2772. const enc: pEVP_CIPHER; kstr: PChar; klen: Integer; cb: Ppem_password_cb;
  2773. u: pointer): integer;
  2774. Begin
  2775. if InitSSLInterface and Assigned(_PEM_write_bio_PrivateKey) then
  2776. Result := _PEM_write_bio_PrivateKey(bp, x, enc ,kstr ,klen ,cb, u)
  2777. else
  2778. Result := -1;
  2779. end;
  2780. function PEM_write_bio_PUBKEY(bp: pBIO; x: pEVP_PKEY): integer;
  2781. Begin
  2782. if InitSSLInterface and Assigned(_PEM_write_bio_PUBKEY) then
  2783. Result := _PEM_write_bio_PUBKEY(bp, x)
  2784. else
  2785. Result := -1;
  2786. end;
  2787. function PEM_read_bio_X509(bp: pBIO; x: ppx509; cb: Ppem_password_cb; u: pointer): px509;
  2788. begin
  2789. if InitSSLInterface and Assigned(_PEM_read_bio_X509) then
  2790. Result := _PEM_read_bio_X509(bp, x, cb, u)
  2791. else
  2792. Result := nil;
  2793. end;
  2794. // BIO Functions
  2795. function BIO_ctrl(bp: PBIO; cmd: cint; larg: clong; parg: Pointer): clong;
  2796. begin
  2797. if InitSSLInterface and Assigned(_BIO_ctrl) then
  2798. Result := _BIO_ctrl(bp, cmd, larg, parg)
  2799. else
  2800. Result := -1;
  2801. end;
  2802. function BIO_read_filename(b: PBIO; const name: PChar): cint;
  2803. begin
  2804. Result := BIO_ctrl(b, BIO_C_SET_FILENAME, BIO_CLOSE or BIO_FP_READ, name);
  2805. end;
  2806. function BIO_s_file: PBIO_METHOD;
  2807. begin
  2808. if InitSSLInterface and Assigned(_BIO_s_file) then
  2809. Result := _BIO_s_file
  2810. else
  2811. Result := nil;
  2812. end;
  2813. function BIO_new_file(const filename: PChar; const mode: PChar): pBIO;
  2814. begin
  2815. if InitSSLInterface and Assigned(_BIO_new_file) then
  2816. Result := _BIO_new_file(filename, mode)
  2817. else
  2818. Result := nil;
  2819. end;
  2820. function BIO_new_mem_buf(buf: pointer; len: integer): pBIO;
  2821. begin
  2822. if InitSSLInterface and Assigned(_BIO_new_mem_buf) then
  2823. Result := _BIO_new_mem_buf(buf, len)
  2824. else
  2825. Result := nil;
  2826. end;
  2827. // PKCS7 Functions
  2828. function PKCS7_ISSUER_AND_SERIAL_new : PPKCS7_ISSUER_AND_SERIAL;
  2829. begin
  2830. if InitSSLInterface and Assigned(_PKCS7_ISSUER_AND_SERIAL_new) then
  2831. Result := _PKCS7_ISSUER_AND_SERIAL_new
  2832. else
  2833. Result := nil;
  2834. end;
  2835. procedure PKCS7_ISSUER_AND_SERIAL_free (a:PPKCS7_ISSUER_AND_SERIAL);
  2836. begin
  2837. if InitSSLInterface and Assigned(_PKCS7_ISSUER_AND_SERIAL_free) then
  2838. _PKCS7_ISSUER_AND_SERIAL_free(a)
  2839. end;
  2840. function PKCS7_ISSUER_AND_SERIAL_digest(data:PPKCS7_ISSUER_AND_SERIAL; _type:PEVP_MD; md:Pbyte; len:Pdword):longint;
  2841. begin
  2842. if InitSSLInterface and Assigned(_PKCS7_ISSUER_AND_SERIAL_digest) then
  2843. Result:=_PKCS7_ISSUER_AND_SERIAL_digest(data,_type,md,len)
  2844. else
  2845. Result:=-1;
  2846. end;
  2847. function PKCS7_dup(p7:PPKCS7):PPKCS7;
  2848. begin
  2849. if InitSSLInterface and Assigned(_PKCS7_dup) then
  2850. Result:=_PKCS7_dup(p7)
  2851. else
  2852. Result:=Nil;
  2853. end;
  2854. function PEM_write_bio_PKCS7_stream(_out:PBIO; p7:PPKCS7; _in:PBIO; flags:longint):longint;
  2855. begin
  2856. if InitSSLInterface and Assigned(_PEM_write_bio_PKCS7_stream) then
  2857. Result:=_PEM_write_bio_PKCS7_stream(_out,p7,_in,flags)
  2858. else
  2859. Result:=-1;
  2860. end;
  2861. function PKCS7_SIGNER_INFO_new:PPKCS7_SIGNER_INFO;
  2862. begin
  2863. if InitSSLInterface and Assigned(_PKCS7_SIGNER_INFO_new) then
  2864. Result:=_PKCS7_SIGNER_INFO_new
  2865. else
  2866. Result:=Nil;
  2867. end;
  2868. procedure PKCS7_SIGNER_INFO_free(a:PPKCS7_SIGNER_INFO);
  2869. begin
  2870. if InitSSLInterface and Assigned(_PKCS7_SIGNER_INFO_free) then
  2871. _PKCS7_SIGNER_INFO_free(a);
  2872. end;
  2873. function PKCS7_RECIP_INFO_new:PPKCS7_RECIP_INFO;
  2874. begin
  2875. if InitSSLInterface and Assigned(_PKCS7_RECIP_INFO_new) then
  2876. Result:=_PKCS7_RECIP_INFO_new
  2877. else
  2878. Result:=Nil;
  2879. end;
  2880. procedure PKCS7_RECIP_INFO_free(a:PPKCS7_RECIP_INFO);
  2881. begin
  2882. if InitSSLInterface and Assigned(_PKCS7_RECIP_INFO_free) then
  2883. _PKCS7_RECIP_INFO_free(a);
  2884. end;
  2885. function PKCS7_SIGNED_new:PPKCS7_SIGNED;
  2886. begin
  2887. if InitSSLInterface and Assigned(_PKCS7_SIGNED_new) then
  2888. Result:=_PKCS7_SIGNED_new
  2889. else
  2890. Result:=Nil;
  2891. end;
  2892. procedure PKCS7_SIGNED_free(a:PPKCS7_SIGNED);
  2893. begin
  2894. if InitSSLInterface and Assigned(_PKCS7_SIGNED_free) then
  2895. _PKCS7_SIGNED_free(a)
  2896. end;
  2897. function PKCS7_ENC_CONTENT_new:PPKCS7_ENC_CONTENT;
  2898. begin
  2899. if InitSSLInterface and Assigned(_PKCS7_ENC_CONTENT_new) then
  2900. Result:=_PKCS7_ENC_CONTENT_new
  2901. else
  2902. Result:=Nil;
  2903. end;
  2904. procedure PKCS7_ENC_CONTENT_free(a:PPKCS7_ENC_CONTENT);
  2905. begin
  2906. if InitSSLInterface and Assigned(_PKCS7_ENC_CONTENT_free) then
  2907. _PKCS7_ENC_CONTENT_free(a)
  2908. end;
  2909. function PKCS7_ENVELOPE_new:PPKCS7_ENVELOPE;
  2910. begin
  2911. if InitSSLInterface and Assigned(_PKCS7_ENVELOPE_new) then
  2912. Result:=_PKCS7_ENVELOPE_new
  2913. else
  2914. Result:=Nil;
  2915. end;
  2916. procedure PKCS7_ENVELOPE_free(a:PPKCS7_ENVELOPE);
  2917. begin
  2918. if InitSSLInterface and Assigned(_PKCS7_ENVELOPE_free) then
  2919. _PKCS7_ENVELOPE_free(a)
  2920. end;
  2921. function PKCS7_SIGN_ENVELOPE_new:PPKCS7_SIGN_ENVELOPE;
  2922. begin
  2923. if InitSSLInterface and Assigned(_PKCS7_SIGN_ENVELOPE_new) then
  2924. Result:=_PKCS7_SIGN_ENVELOPE_new
  2925. else
  2926. Result:=Nil;
  2927. end;
  2928. procedure PKCS7_SIGN_ENVELOPE_free(a:PPKCS7_SIGN_ENVELOPE);
  2929. begin
  2930. if InitSSLInterface and Assigned(_PKCS7_SIGN_ENVELOPE_free) then
  2931. _PKCS7_SIGN_ENVELOPE_free(a)
  2932. end;
  2933. function PKCS7_DIGEST_new:PPKCS7_DIGEST;
  2934. begin
  2935. if InitSSLInterface and Assigned(_PKCS7_DIGEST_new) then
  2936. Result:=_PKCS7_DIGEST_new
  2937. else
  2938. Result:=Nil;
  2939. end;
  2940. procedure PKCS7_DIGEST_free(a:PPKCS7_DIGEST);
  2941. begin
  2942. if InitSSLInterface and Assigned(_PKCS7_DIGEST_free) then
  2943. _PKCS7_DIGEST_free(a)
  2944. end;
  2945. function PKCS7_ENCRYPT_new:PPKCS7_ENCRYPT;
  2946. begin
  2947. if InitSSLInterface and Assigned(_PKCS7_ENCRYPT_new) then
  2948. Result:=_PKCS7_ENCRYPT_new
  2949. else
  2950. Result:=Nil;
  2951. end;
  2952. procedure PKCS7_ENCRYPT_free(a:PPKCS7_ENCRYPT);
  2953. begin
  2954. if InitSSLInterface and Assigned(_PKCS7_ENCRYPT_free) then
  2955. _PKCS7_ENCRYPT_free(a)
  2956. end;
  2957. function PKCS7_new:PPKCS7;
  2958. begin
  2959. if InitSSLInterface and Assigned(_PKCS7_new) then
  2960. Result:=_PKCS7_new
  2961. else
  2962. Result:=Nil;
  2963. end;
  2964. procedure PKCS7_free(a:PPKCS7);
  2965. begin
  2966. if InitSSLInterface and Assigned(_PKCS7_free) then
  2967. _PKCS7_free(a)
  2968. end;
  2969. function PKCS7_print_ctx(_out:PBIO; x:PPKCS7; indent:longint; pctx:Pointer):longint;
  2970. begin
  2971. if InitSSLInterface and Assigned(_PKCS7_print_ctx) then
  2972. Result:=PKCS7_print_ctx(_out,x,indent,pctx)
  2973. else
  2974. Result:=-1;
  2975. end;
  2976. function PKCS7_ctrl(p7:PPKCS7; cmd:longint; larg:longint; parg:Pchar):longint;
  2977. begin
  2978. if InitSSLInterface and Assigned(_PKCS7_ctrl) then
  2979. Result:=_PKCS7_ctrl(p7,cmd,larg,parg)
  2980. else
  2981. Result:=-1;
  2982. end;
  2983. function PKCS7_set_type(p7:PPKCS7; _type:longint):longint;
  2984. begin
  2985. if InitSSLInterface and Assigned(_PKCS7_set_type) then
  2986. Result:=_PKCS7_set_type(p7,_type)
  2987. else
  2988. Result:=-1;
  2989. end;
  2990. function PKCS7_set0_type_other(p7:PPKCS7; _type:longint; other:PASN1_TYPE):longint;
  2991. begin
  2992. if InitSSLInterface and Assigned(_PKCS7_set0_type_other) then
  2993. Result:=_PKCS7_set0_type_other(p7,_type,other)
  2994. else
  2995. Result:=-1;
  2996. end;
  2997. function PKCS7_set_content(p7:PPKCS7; p7_data:PPKCS7):longint;
  2998. begin
  2999. if InitSSLInterface and Assigned(_PKCS7_set_content) then
  3000. Result:=_PKCS7_set_content(p7,p7_Data)
  3001. else
  3002. Result:=-1;
  3003. end;
  3004. function PKCS7_SIGNER_INFO_set(p7i:PPKCS7_SIGNER_INFO; x509:PX509; pkey:PEVP_PKEY; dgst:PEVP_MD):longint;
  3005. begin
  3006. if InitSSLInterface and Assigned(_PKCS7_SIGNER_INFO_set) then
  3007. Result:=_PKCS7_SIGNER_INFO_set(p7i,x509,pkey,dgst)
  3008. else
  3009. Result:=-1;
  3010. end;
  3011. function PKCS7_SIGNER_INFO_sign(si:PPKCS7_SIGNER_INFO):longint;
  3012. begin
  3013. if InitSSLInterface and Assigned(_PKCS7_SIGNER_INFO_sign) then
  3014. Result:=_PKCS7_SIGNER_INFO_sign(si)
  3015. else
  3016. Result:=-1;
  3017. end;
  3018. function PKCS7_add_signer(p7:PPKCS7; p7i:PPKCS7_SIGNER_INFO):longint;
  3019. begin
  3020. if InitSSLInterface and Assigned(_PKCS7_add_signer) then
  3021. Result:=_PKCS7_add_signer(p7,p7i)
  3022. else
  3023. Result:=-1;
  3024. end;
  3025. function PKCS7_add_certificate(p7:PPKCS7; x509:PX509):longint;
  3026. begin
  3027. if InitSSLInterface and Assigned(_PKCS7_add_certificate) then
  3028. Result:=_PKCS7_add_certificate(p7,x509)
  3029. else
  3030. Result:=-1;
  3031. end;
  3032. function PKCS7_add_crl(p7:PPKCS7; x509: Pointer):longint;
  3033. begin
  3034. if InitSSLInterface and Assigned(_PKCS7_add_crl) then
  3035. Result:=PKCS7_add_crl(p7,x509)
  3036. else
  3037. Result:=-1;
  3038. end;
  3039. function PKCS7_content_new(p7:PPKCS7; nid:longint):longint;
  3040. begin
  3041. if InitSSLInterface and Assigned(_PKCS7_content_new) then
  3042. Result:=_PKCS7_content_new(p7,nid)
  3043. else
  3044. Result:=-1;
  3045. end;
  3046. function PKCS7_add_signature(p7:PPKCS7; x509:PX509; pkey:PEVP_PKEY; dgst:PEVP_MD):PPKCS7_SIGNER_INFO;
  3047. begin
  3048. if InitSSLInterface and Assigned(_PKCS7_add_signature) then
  3049. Result:=PKCS7_add_signature(p7,x509,pkey,dgst)
  3050. else
  3051. Result:=Nil;
  3052. end;
  3053. function PKCS7_cert_from_signer_info(p7:PPKCS7; si:PPKCS7_SIGNER_INFO):PX509;
  3054. begin
  3055. if InitSSLInterface and Assigned(_PKCS7_cert_from_signer_info) then
  3056. Result:=_PKCS7_cert_from_signer_info(p7,si)
  3057. else
  3058. Result:=Nil;
  3059. end;
  3060. function PKCS7_set_digest(p7:PPKCS7; md:PEVP_MD):longint;
  3061. begin
  3062. if InitSSLInterface and Assigned(_PKCS7_set_digest) then
  3063. Result:=_PKCS7_set_digest(p7,md)
  3064. else
  3065. Result:=-1;
  3066. end;
  3067. function PKCS7_add_recipient(p7:PPKCS7; x509:PX509):PPKCS7_RECIP_INFO;
  3068. begin
  3069. if InitSSLInterface and Assigned(_PKCS7_add_recipient) then
  3070. Result:=_PKCS7_add_recipient(p7,x509)
  3071. else
  3072. Result:=Nil;
  3073. end;
  3074. function PKCS7_add_recipient_info(p7:PPKCS7; ri:PPKCS7_RECIP_INFO):longint;
  3075. begin
  3076. if InitSSLInterface and Assigned(_PKCS7_add_recipient_info) then
  3077. Result:=_PKCS7_add_recipient_info(p7,ri)
  3078. else
  3079. Result:=-1;
  3080. end;
  3081. function PKCS7_RECIP_INFO_set(p7i:PPKCS7_RECIP_INFO; x509:PX509):longint;
  3082. begin
  3083. if InitSSLInterface and Assigned(_PKCS7_RECIP_INFO_set) then
  3084. Result:=_PKCS7_RECIP_INFO_set(p7i,x509)
  3085. else
  3086. Result:=-1;
  3087. end;
  3088. function PKCS7_set_cipher(p7:PPKCS7; cipher:PEVP_CIPHER):longint;
  3089. begin
  3090. if InitSSLInterface and Assigned(_PKCS7_set_cipher) then
  3091. Result:=_PKCS7_set_cipher(p7,cipher)
  3092. else
  3093. Result:=-1;
  3094. end;
  3095. function PKCS7_get_issuer_and_serial(p7:PPKCS7; idx:longint):PPKCS7_ISSUER_AND_SERIAL;
  3096. begin
  3097. if InitSSLInterface and Assigned(_PKCS7_get_issuer_and_serial) then
  3098. Result:=_PKCS7_get_issuer_and_serial(P7,idx)
  3099. else
  3100. Result:=Nil;
  3101. end;
  3102. function PKCS7_digest_from_attributes(sk:Pstack_st_X509_ATTRIBUTE):Pointer;
  3103. begin
  3104. if InitSSLInterface and Assigned(_PKCS7_digest_from_attributes) then
  3105. Result:=_PKCS7_digest_from_attributes(sk)
  3106. else
  3107. Result:=Nil;
  3108. end;
  3109. function PKCS7_add_signed_attribute(p7si:PPKCS7_SIGNER_INFO; nid:longint; _type:longint; data:pointer):longint;
  3110. begin
  3111. if InitSSLInterface and Assigned(_PKCS7_add_signed_attribute) then
  3112. Result:=_PKCS7_add_signed_attribute(p7si,nid,_type,data)
  3113. else
  3114. Result:=-1;
  3115. end;
  3116. function PKCS7_add_attribute(p7si:PPKCS7_SIGNER_INFO; nid:longint; atrtype:longint; value:pointer):longint;
  3117. begin
  3118. if InitSSLInterface and Assigned(_PKCS7_add_attribute) then
  3119. Result:=_PKCS7_add_attribute(p7si,nid,atrtype,value)
  3120. else
  3121. Result:=-1;
  3122. end;
  3123. function PKCS7_get_attribute(si:PPKCS7_SIGNER_INFO; nid:longint):PASN1_TYPE;
  3124. begin
  3125. if InitSSLInterface and Assigned(_PKCS7_get_attribute) then
  3126. Result:=_PKCS7_get_attribute(si,nid)
  3127. else
  3128. Result:=Nil;
  3129. end;
  3130. function PKCS7_get_signed_attribute(si:PPKCS7_SIGNER_INFO; nid:longint):PASN1_TYPE;
  3131. begin
  3132. if InitSSLInterface and Assigned(_PKCS7_get_signed_attribute) then
  3133. Result:=_PKCS7_get_signed_attribute(si,nid)
  3134. else
  3135. Result:=Nil;
  3136. end;
  3137. function PKCS7_set_signed_attributes(p7si:PPKCS7_SIGNER_INFO; sk:Pstack_st_X509_ATTRIBUTE):longint;
  3138. begin
  3139. if InitSSLInterface and Assigned(_PKCS7_set_signed_attributes) then
  3140. Result:=_PKCS7_set_signed_attributes(p7si,sk)
  3141. else
  3142. Result:=-1;
  3143. end;
  3144. function PKCS7_set_attributes(p7si:PPKCS7_SIGNER_INFO; sk:Pstack_st_X509_ATTRIBUTE):longint;
  3145. begin
  3146. if InitSSLInterface and Assigned(_PKCS7_set_attributes) then
  3147. Result:=_PKCS7_set_attributes(p7si,sk)
  3148. else
  3149. Result:=-1;
  3150. end;
  3151. function PKCS7_sign(signcert:PX509; pkey:PEVP_PKEY; certs:Pstack_st_X509; data:PBIO; flags:longint):PPKCS7;
  3152. begin
  3153. if InitSSLInterface and Assigned(_PKCS7_sign) then
  3154. Result:=_PKCS7_sign(signcert,pkey,certs,data,flags)
  3155. else
  3156. Result:=Nil;
  3157. end;
  3158. function PKCS7_sign_add_signer(p7:PPKCS7; signcert:PX509; pkey:PEVP_PKEY; md:PEVP_MD; flags:longint):PPKCS7_SIGNER_INFO;
  3159. begin
  3160. if InitSSLInterface and Assigned(_PKCS7_sign_add_signer) then
  3161. Result:=_PKCS7_sign_add_signer(p7,signcert,pkey,md,flags)
  3162. else
  3163. Result:=Nil;
  3164. end;
  3165. function PKCS7_final(p7:PPKCS7; data:PBIO; flags:longint):longint;
  3166. begin
  3167. if InitSSLInterface and Assigned(_PKCS7_final) then
  3168. Result:=_PKCS7_final(p7,data,Flags)
  3169. else
  3170. Result:=-1;
  3171. end;
  3172. function PKCS7_verify(p7:PPKCS7; certs:Pstack_st_X509; store: Pointer; indata:PBIO; _out:PBIO; flags:longint):longint;
  3173. begin
  3174. if InitSSLInterface and Assigned(_PKCS7_verify) then
  3175. Result:=_PKCS7_verify(p7,certs,store,indata,_out,flags)
  3176. else
  3177. Result:=-1;
  3178. end;
  3179. function PKCS7_encrypt(certs:Pstack_st_X509; _in:PBIO; cipher:PEVP_CIPHER; flags:longint):PPKCS7;
  3180. begin
  3181. if InitSSLInterface and Assigned(_PKCS7_encrypt) then
  3182. Result:=_PKCS7_encrypt(certs,_in,cipher,flags)
  3183. else
  3184. Result:=Nil;
  3185. end;
  3186. function PKCS7_decrypt(p7:PPKCS7; pkey:PEVP_PKEY; cert:PX509; data:PBIO; flags:longint):longint;
  3187. begin
  3188. if InitSSLInterface and Assigned(_PKCS7_decrypt) then
  3189. Result:=_PKCS7_decrypt(P7,pkey,cert,data,flags)
  3190. else
  3191. Result:=-1;
  3192. end;
  3193. function PKCS7_add_attrib_smimecap(si:PPKCS7_SIGNER_INFO; cap:Pstack_st_X509_ALGOR):longint;
  3194. begin
  3195. if InitSSLInterface and Assigned(_PKCS7_add_attrib_smimecap) then
  3196. Result:=_PKCS7_add_attrib_smimecap(si,cap)
  3197. else
  3198. Result:=-1;
  3199. end;
  3200. function PKCS7_simple_smimecap(sk:Pstack_st_X509_ALGOR; nid:longint; arg:longint):longint;
  3201. begin
  3202. if InitSSLInterface and Assigned(_PKCS7_simple_smimecap) then
  3203. Result:=_PKCS7_simple_smimecap(sk,nid,arg)
  3204. else
  3205. Result:=-1;
  3206. end;
  3207. function PKCS7_add_attrib_content_type(si:PPKCS7_SIGNER_INFO; coid:Pointer):longint;
  3208. begin
  3209. if InitSSLInterface and Assigned(_PKCS7_add_attrib_content_type) then
  3210. Result:=_PKCS7_add_attrib_content_type(si,coid)
  3211. else
  3212. Result:=-1;
  3213. end;
  3214. function PKCS7_add0_attrib_signing_time(si:PPKCS7_SIGNER_INFO; t:PASN1_TIME):longint;
  3215. begin
  3216. if InitSSLInterface and Assigned(_PKCS7_add0_attrib_signing_time) then
  3217. Result:=_PKCS7_add0_attrib_signing_time(si,t)
  3218. else
  3219. Result:=-1;
  3220. end;
  3221. function PKCS7_add1_attrib_digest(si:PPKCS7_SIGNER_INFO; md:Pbyte; mdlen:longint):longint;
  3222. begin
  3223. if InitSSLInterface and Assigned(_PKCS7_add1_attrib_digest) then
  3224. Result:=_PKCS7_add1_attrib_digest(si,md,mdlen)
  3225. else
  3226. Result:=-1;
  3227. end;
  3228. function BIO_new_PKCS7(_out:PBIO; p7:PPKCS7):PBIO;
  3229. begin
  3230. if InitSSLInterface and Assigned(_BIO_new_PKCS7) then
  3231. Result:=_BIO_new_PKCS7(_out,p7)
  3232. else
  3233. Result:=Nil;
  3234. end;
  3235. procedure ERR_load_PKCS7_strings;
  3236. begin
  3237. if InitSSLInterface and Assigned(_ERR_load_PKCS7_strings) then
  3238. _ERR_load_PKCS7_strings
  3239. end;
  3240. procedure CRYPTOcleanupAllExData;
  3241. begin
  3242. if InitSSLInterface and Assigned(_CRYPTOcleanupAllExData) then
  3243. _CRYPTOcleanupAllExData;
  3244. end;
  3245. procedure OPENSSLaddallalgorithms;
  3246. begin
  3247. if InitSSLInterface and Assigned(_OPENSSLaddallalgorithms) then
  3248. _OPENSSLaddallalgorithms;
  3249. end;
  3250. {$IFNDEF WINDOWS}
  3251. {$IFNDEF OS2}
  3252. { Try to load all library versions until you find or run out }
  3253. function LoadLibHack(const Value: String): HModule;
  3254. var
  3255. i: cInt;
  3256. begin
  3257. Result := NilHandle;
  3258. for i := Low(DLLVersions) to High(DLLVersions) do begin
  3259. {$IFDEF DARWIN}
  3260. Result := LoadLibrary(Value + DLLVersions[i] + '.dylib');
  3261. {$ELSE}
  3262. Result := LoadLibrary(Value + '.so' + DLLVersions[i]);
  3263. {$ENDIF}
  3264. if Result <> NilHandle then
  3265. Break;
  3266. end;
  3267. end;
  3268. {$ENDIF OS2}
  3269. {$ENDIF WINDOWS}
  3270. function LoadLib(const Value: String): HModule;
  3271. begin
  3272. {$IFDEF WINDOWS}
  3273. Result := LoadLibrary(Value);
  3274. {$ELSE WINDOWS}
  3275. {$IFDEF OS2}
  3276. Result := LoadLibrary(Value);
  3277. {$ELSE OS2}
  3278. Result := LoadLibHack(Value);
  3279. {$ENDIF OS2}
  3280. {$ENDIF WINDOWS}
  3281. end;
  3282. function GetProcAddr(module: HModule; const ProcName: string): SslPtr;
  3283. begin
  3284. Result := GetProcAddress(module, PChar(ProcName));
  3285. if LoadVerbose and (Result = nil) then
  3286. OpenSSL_unavailable_functions := OpenSSL_unavailable_functions + ProcName + LineEnding;
  3287. end;
  3288. // The AVerboseLoading parameter can be used to check which particular
  3289. // functions weren't loaded correctly. They will be available in the
  3290. // global variable OpenSSL_unavailable_functions
  3291. function IsSSLloaded: Boolean;
  3292. begin
  3293. Result := SSLLoaded;
  3294. end;
  3295. Procedure LoadSSLEntryPoints;
  3296. begin
  3297. _SslGetError := GetProcAddr(SSLLibHandle, 'SSL_get_error');
  3298. _SslLibraryInit := GetProcAddr(SSLLibHandle, 'SSL_library_init');
  3299. _SslLoadErrorStrings := GetProcAddr(SSLLibHandle, 'SSL_load_error_strings');
  3300. _SslCtxSetCipherList := GetProcAddr(SSLLibHandle, 'SSL_CTX_set_cipher_list');
  3301. _SslCtxNew := GetProcAddr(SSLLibHandle, 'SSL_CTX_new');
  3302. _SslCtxFree := GetProcAddr(SSLLibHandle, 'SSL_CTX_free');
  3303. _SslSetFd := GetProcAddr(SSLLibHandle, 'SSL_set_fd');
  3304. _SslCtrl := GetProcAddr(SSLLibHandle, 'SSL_ctrl');
  3305. _SslCTXCtrl := GetProcAddr(SSLLibHandle, 'SSL_CTX_ctrl');
  3306. _SslMethodV2 := GetProcAddr(SSLLibHandle, 'SSLv2_method');
  3307. _SslMethodV3 := GetProcAddr(SSLLibHandle, 'SSLv3_method');
  3308. _SslMethodTLSV1 := GetProcAddr(SSLLibHandle, 'TLSv1_method');
  3309. _SslMethodV23 := GetProcAddr(SSLLibHandle, 'SSLv23_method');
  3310. _SslCtxUsePrivateKey := GetProcAddr(SSLLibHandle, 'SSL_CTX_use_PrivateKey');
  3311. _SslCtxUsePrivateKeyASN1 := GetProcAddr(SSLLibHandle, 'SSL_CTX_use_PrivateKey_ASN1');
  3312. //use SSL_CTX_use_RSAPrivateKey_file instead SSL_CTX_use_PrivateKey_file,
  3313. //because SSL_CTX_use_PrivateKey_file not support DER format. :-O
  3314. _SslCtxUsePrivateKeyFile := GetProcAddr(SSLLibHandle, 'SSL_CTX_use_RSAPrivateKey_file');
  3315. _SslCtxUseCertificate := GetProcAddr(SSLLibHandle, 'SSL_CTX_use_certificate');
  3316. _SslCtxUseCertificateASN1 := GetProcAddr(SSLLibHandle, 'SSL_CTX_use_certificate_ASN1');
  3317. _SslCtxUseCertificateFile := GetProcAddr(SSLLibHandle, 'SSL_CTX_use_certificate_file');
  3318. _SslCtxUseCertificateChainFile := GetProcAddr(SSLLibHandle, 'SSL_CTX_use_certificate_chain_file');
  3319. _SslCtxCheckPrivateKeyFile := GetProcAddr(SSLLibHandle, 'SSL_CTX_check_private_key');
  3320. _SslCtxSetDefaultPasswdCb := GetProcAddr(SSLLibHandle, 'SSL_CTX_set_default_passwd_cb');
  3321. _SslCtxSetDefaultPasswdCbUserdata := GetProcAddr(SSLLibHandle, 'SSL_CTX_set_default_passwd_cb_userdata');
  3322. _SslCtxLoadVerifyLocations := GetProcAddr(SSLLibHandle, 'SSL_CTX_load_verify_locations');
  3323. _SslNew := GetProcAddr(SSLLibHandle, 'SSL_new');
  3324. _SslFree := GetProcAddr(SSLLibHandle, 'SSL_free');
  3325. _SslAccept := GetProcAddr(SSLLibHandle, 'SSL_accept');
  3326. _SslConnect := GetProcAddr(SSLLibHandle, 'SSL_connect');
  3327. _SslShutdown := GetProcAddr(SSLLibHandle, 'SSL_shutdown');
  3328. _SslRead := GetProcAddr(SSLLibHandle, 'SSL_read');
  3329. _SslPeek := GetProcAddr(SSLLibHandle, 'SSL_peek');
  3330. _SslWrite := GetProcAddr(SSLLibHandle, 'SSL_write');
  3331. _SslPending := GetProcAddr(SSLLibHandle, 'SSL_pending');
  3332. _SslGetPeerCertificate := GetProcAddr(SSLLibHandle, 'SSL_get_peer_certificate');
  3333. _SslGetVersion := GetProcAddr(SSLLibHandle, 'SSL_get_version');
  3334. _SslCtxSetVerify := GetProcAddr(SSLLibHandle, 'SSL_CTX_set_verify');
  3335. _SslGetCurrentCipher := GetProcAddr(SSLLibHandle, 'SSL_get_current_cipher');
  3336. _SslCipherGetName := GetProcAddr(SSLLibHandle, 'SSL_CIPHER_get_name');
  3337. _SslCipherGetBits := GetProcAddr(SSLLibHandle, 'SSL_CIPHER_get_bits');
  3338. _SslGetVerifyResult := GetProcAddr(SSLLibHandle, 'SSL_get_verify_result');
  3339. end;
  3340. Procedure LoadUtilEntryPoints;
  3341. begin
  3342. _ERR_load_crypto_strings := GetProcAddr(SSLUtilHandle, 'ERR_load_crypto_strings');
  3343. _X509New := GetProcAddr(SSLUtilHandle, 'X509_new');
  3344. _X509Free := GetProcAddr(SSLUtilHandle, 'X509_free');
  3345. _X509NameOneline := GetProcAddr(SSLUtilHandle, 'X509_NAME_oneline');
  3346. _X509GetSubjectName := GetProcAddr(SSLUtilHandle, 'X509_get_subject_name');
  3347. _X509GetIssuerName := GetProcAddr(SSLUtilHandle, 'X509_get_issuer_name');
  3348. _X509NameHash := GetProcAddr(SSLUtilHandle, 'X509_NAME_hash');
  3349. _X509Digest := GetProcAddr(SSLUtilHandle, 'X509_digest');
  3350. _X509print := GetProcAddr(SSLUtilHandle, 'X509_print');
  3351. _X509SetVersion := GetProcAddr(SSLUtilHandle, 'X509_set_version');
  3352. _X509SetPubkey := GetProcAddr(SSLUtilHandle, 'X509_set_pubkey');
  3353. _X509GetPubkey := GetProcAddr(SSLUtilHandle, 'X509_get_pubkey');
  3354. _X509SetIssuerName := GetProcAddr(SSLUtilHandle, 'X509_set_issuer_name');
  3355. _X509NameAddEntryByTxt := GetProcAddr(SSLUtilHandle, 'X509_NAME_add_entry_by_txt');
  3356. _X509Sign := GetProcAddr(SSLUtilHandle, 'X509_sign');
  3357. _X509GmtimeAdj := GetProcAddr(SSLUtilHandle, 'X509_gmtime_adj');
  3358. _X509SetNotBefore := GetProcAddr(SSLUtilHandle, 'X509_set_notBefore');
  3359. _X509SetNotAfter := GetProcAddr(SSLUtilHandle, 'X509_set_notAfter');
  3360. _X509GetSerialNumber := GetProcAddr(SSLUtilHandle, 'X509_get_serialNumber');
  3361. _EvpPkeyNew := GetProcAddr(SSLUtilHandle, 'EVP_PKEY_new');
  3362. _EvpPkeyFree := GetProcAddr(SSLUtilHandle, 'EVP_PKEY_free');
  3363. _EvpPkeyAssign := GetProcAddr(SSLUtilHandle, 'EVP_PKEY_assign');
  3364. _EVPCleanup := GetProcAddr(SSLUtilHandle, 'EVP_cleanup');
  3365. _EvpGetDigestByName := GetProcAddr(SSLUtilHandle, 'EVP_get_digestbyname');
  3366. _SSLeayversion := GetProcAddr(SSLUtilHandle, 'SSLeay_version');
  3367. _ErrErrorString := GetProcAddr(SSLUtilHandle, 'ERR_error_string_n');
  3368. _ErrGetError := GetProcAddr(SSLUtilHandle, 'ERR_get_error');
  3369. _ErrClearError := GetProcAddr(SSLUtilHandle, 'ERR_clear_error');
  3370. _ErrFreeStrings := GetProcAddr(SSLUtilHandle, 'ERR_free_strings');
  3371. _ErrRemoveState := GetProcAddr(SSLUtilHandle, 'ERR_remove_state');
  3372. _RandScreen := GetProcAddr(SSLUtilHandle, 'RAND_screen');
  3373. _BioNew := GetProcAddr(SSLUtilHandle, 'BIO_new');
  3374. _BioFreeAll := GetProcAddr(SSLUtilHandle, 'BIO_free_all');
  3375. _BioSMem := GetProcAddr(SSLUtilHandle, 'BIO_s_mem');
  3376. _BioCtrlPending := GetProcAddr(SSLUtilHandle, 'BIO_ctrl_pending');
  3377. _BioRead := GetProcAddr(SSLUtilHandle, 'BIO_read');
  3378. _BioWrite := GetProcAddr(SSLUtilHandle, 'BIO_write');
  3379. _d2iPKCS12bio := GetProcAddr(SSLUtilHandle, 'd2i_PKCS12_bio');
  3380. _PKCS12parse := GetProcAddr(SSLUtilHandle, 'PKCS12_parse');
  3381. _PKCS12free := GetProcAddr(SSLUtilHandle, 'PKCS12_free');
  3382. _Asn1UtctimeNew := GetProcAddr(SSLUtilHandle, 'ASN1_UTCTIME_new');
  3383. _Asn1UtctimeFree := GetProcAddr(SSLUtilHandle, 'ASN1_UTCTIME_free');
  3384. _Asn1IntegerSet := GetProcAddr(SSLUtilHandle, 'ASN1_INTEGER_set');
  3385. _Asn1IntegerGet := GetProcAddr(SSLUtilHandle, 'ASN1_INTEGER_get');
  3386. _i2dX509bio := GetProcAddr(SSLUtilHandle, 'i2d_X509_bio');
  3387. _i2dPrivateKeyBio := GetProcAddr(SSLUtilHandle, 'i2d_PrivateKey_bio');
  3388. _EVP_enc_null := GetProcAddr(SSLUtilHandle, 'EVP_enc_null');
  3389. _EVP_rc2_cbc := GetProcAddr(SSLUtilHandle, 'EVP_rc2_cbc');
  3390. _EVP_rc2_40_cbc := GetProcAddr(SSLUtilHandle, 'EVP_rc2_40_cbc');
  3391. _EVP_rc2_64_cbc := GetProcAddr(SSLUtilHandle, 'EVP_rc2_64_cbc');
  3392. _EVP_rc4 := GetProcAddr(SSLUtilHandle, 'EVP_rc4');
  3393. _EVP_rc4_40 := GetProcAddr(SSLUtilHandle, 'EVP_rc4_40');
  3394. _EVP_des_cbc := GetProcAddr(SSLUtilHandle, 'EVP_des_cbc');
  3395. _EVP_des_ede3_cbc := GetProcAddr(SSLUtilHandle, 'EVP_des_ede3_cbc');
  3396. _EVP_aes_128_cbc := GetProcAddr(SSLUtilHandle, 'EVP_aes_128_cbc');
  3397. _EVP_aes_192_cbc := GetProcAddr(SSLUtilHandle, 'EVP_aes_192_cbc');
  3398. _EVP_aes_256_cbc := GetProcAddr(SSLUtilHandle, 'EVP_aes_256_cbc');
  3399. _EVP_aes_128_cfb8 := GetProcAddr(SSLUtilHandle, 'EVP_aes_128_cfb8');
  3400. _EVP_aes_192_cfb8 := GetProcAddr(SSLUtilHandle, 'EVP_aes_192_cfb8');
  3401. _EVP_aes_256_cfb8 := GetProcAddr(SSLUtilHandle, 'EVP_aes_256_cfb8');
  3402. _EVP_camellia_128_cbc := GetProcAddr(SSLUtilHandle, 'EVP_camellia_128_cbc');
  3403. _EVP_camellia_192_cbc := GetProcAddr(SSLUtilHandle, 'EVP_camellia_192_cbc');
  3404. _EVP_camellia_256_cbc := GetProcAddr(SSLUtilHandle, 'EVP_camellia_256_cbc');
  3405. // 3DES functions
  3406. _DESsetoddparity := GetProcAddr(SSLUtilHandle, 'des_set_odd_parity');
  3407. _DESsetkeychecked := GetProcAddr(SSLUtilHandle, 'des_set_key_checked');
  3408. _DESsetkey := GetProcAddr(SSLUtilHandle, 'des_set_key');
  3409. _DESecbencrypt := GetProcAddr(SSLUtilHandle, 'des_ecb_encrypt');
  3410. //
  3411. _CRYPTOnumlocks := GetProcAddr(SSLUtilHandle, 'CRYPTO_num_locks');
  3412. _CRYPTOsetlockingcallback := GetProcAddr(SSLUtilHandle, 'CRYPTO_set_locking_callback');
  3413. // RAND functions
  3414. _RAND_set_rand_method := GetProcAddr(SSLUtilHandle, 'RAND_set_rand_method');
  3415. _RAND_get_rand_method := GetProcAddr(SSLUtilHandle, 'RAND_get_rand_method');
  3416. _RAND_SSLeay := GetProcAddr(SSLUtilHandle, 'RAND_SSLeay');
  3417. _RAND_cleanup := GetProcAddr(SSLUtilHandle, 'RAND_cleanup');
  3418. _RAND_bytes := GetProcAddr(SSLUtilHandle, 'RAND_bytes');
  3419. _RAND_pseudo_bytes := GetProcAddr(SSLUtilHandle, 'RAND_pseudo_bytes');
  3420. _RAND_seed := GetProcAddr(SSLUtilHandle, 'RAND_seed');
  3421. _RAND_add := GetProcAddr(SSLUtilHandle, 'RAND_add');
  3422. _RAND_load_file := GetProcAddr(SSLUtilHandle, 'RAND_load_file');
  3423. _RAND_write_file := GetProcAddr(SSLUtilHandle, 'RAND_write_file');
  3424. _RAND_file_name := GetProcAddr(SSLUtilHandle, 'RAND_file_name');
  3425. _RAND_status := GetProcAddr(SSLUtilHandle, 'RAND_status');
  3426. _RAND_query_egd_bytes := GetProcAddr(SSLUtilHandle, 'RAND_query_egd_bytes'); // 0.9.7+
  3427. _RAND_egd := GetProcAddr(SSLUtilHandle, 'RAND_egd');
  3428. _RAND_egd_bytes := GetProcAddr(SSLUtilHandle, 'RAND_egd_bytes');
  3429. _ERR_load_RAND_strings := GetProcAddr(SSLUtilHandle, 'ERR_load_RAND_strings');
  3430. _RAND_poll := GetProcAddr(SSLUtilHandle, 'RAND_poll');
  3431. // RSA Functions
  3432. _RSA_new := GetProcAddr(SSLUtilHandle, 'RSA_new');
  3433. _RSA_new_method := GetProcAddr(SSLUtilHandle, 'RSA_new_method');
  3434. _RSA_size := GetProcAddr(SSLUtilHandle, 'RSA_size');
  3435. _RsaGenerateKey := GetProcAddr(SSLUtilHandle, 'RSA_generate_key');
  3436. _RSA_generate_key_ex := GetProcAddr(SSLUtilHandle, 'RSA_generate_key_ex');
  3437. _RSA_check_key := GetProcAddr(SSLUtilHandle, 'RSA_check_key');
  3438. _RSA_public_encrypt := GetProcAddr(SSLUtilHandle, 'RSA_public_encrypt');
  3439. _RSA_private_encrypt := GetProcAddr(SSLUtilHandle, 'RSA_private_encrypt');
  3440. _RSA_public_decrypt := GetProcAddr(SSLUtilHandle, 'RSA_public_decrypt');
  3441. _RSA_private_decrypt := GetProcAddr(SSLUtilHandle, 'RSA_private_decrypt');
  3442. _RSA_free := GetProcAddr(SSLUtilHandle, 'RSA_free');
  3443. _RSA_flags := GetProcAddr(SSLUtilHandle, 'RSA_flags');
  3444. _RSA_set_default_method := GetProcAddr(SSLUtilHandle, 'RSA_set_default_method');
  3445. _RSA_get_default_method := GetProcAddr(SSLUtilHandle, 'RSA_get_default_method');
  3446. _RSA_get_method := GetProcAddr(SSLUtilHandle, 'RSA_get_method');
  3447. _RSA_set_method := GetProcAddr(SSLUtilHandle, 'RSA_set_method');
  3448. // X509 Functions
  3449. _d2i_RSAPublicKey := GetProcAddr(SSLUtilHandle, 'd2i_RSAPublicKey');
  3450. _i2d_RSAPublicKey := GetProcAddr(SSLUtilHandle, 'i2d_RSAPublicKey');
  3451. _d2i_RSAPrivateKey := GetProcAddr(SSLUtilHandle, 'd2i_RSAPrivateKey');
  3452. _i2d_RSAPrivateKey := GetProcAddr(SSLUtilHandle, 'i2d_RSAPrivateKey');
  3453. // ERR Functions
  3454. _ERR_error_string := GetProcAddr(SSLUtilHandle, 'ERR_error_string');
  3455. // EVP Functions
  3456. _OpenSSL_add_all_algorithms := GetProcAddr(SSLUtilHandle, 'OpenSSL_add_all_algorithms');
  3457. _OpenSSL_add_all_ciphers := GetProcAddr(SSLUtilHandle, 'OpenSSL_add_all_ciphers');
  3458. _OpenSSL_add_all_digests := GetProcAddr(SSLUtilHandle, 'OpenSSL_add_all_digests');
  3459. _EVP_DigestInit := GetProcAddr(SSLUtilHandle, 'EVP_DigestInit');
  3460. _EVP_DigestUpdate := GetProcAddr(SSLUtilHandle, 'EVP_DigestUpdate');
  3461. _EVP_DigestFinal := GetProcAddr(SSLUtilHandle, 'EVP_DigestFinal');
  3462. _EVP_SignFinal := GetProcAddr(SSLUtilHandle, 'EVP_SignFinal');
  3463. _EVP_PKEY_size := GetProcAddr(SSLUtilHandle,'EVP_PKEY_size');
  3464. _EVP_PKEY_free := GetProcAddr(SSLUtilHandle,'EVP_PKEY_free');
  3465. _EVP_VerifyFinal := GetProcAddr(SSLUtilHandle,'EVP_VerifyFinal');
  3466. _EVP_get_cipherbyname := GetProcAddr(SSLUtilHandle, 'EVP_get_cipherbyname');
  3467. _EVP_get_digestbyname := GetProcAddr(SSLUtilHandle, 'EVP_get_digestbyname');
  3468. _EVP_CIPHER_CTX_init := GetProcAddr(SSLUtilHandle, 'EVP_CIPHER_CTX_init');
  3469. _EVP_CIPHER_CTX_cleanup := GetProcAddr(SSLUtilHandle, 'EVP_CIPHER_CTX_cleanup');
  3470. _EVP_CIPHER_CTX_set_key_length := GetProcAddr(SSLUtilHandle, 'EVP_CIPHER_CTX_set_key_length');
  3471. _EVP_CIPHER_CTX_ctrl := GetProcAddr(SSLUtilHandle, 'EVP_CIPHER_CTX_ctrl');
  3472. _EVP_EncryptInit := GetProcAddr(SSLUtilHandle, 'EVP_EncryptInit');
  3473. _EVP_EncryptUpdate := GetProcAddr(SSLUtilHandle, 'EVP_EncryptUpdate');
  3474. _EVP_EncryptFinal := GetProcAddr(SSLUtilHandle, 'EVP_EncryptFinal');
  3475. _EVP_DecryptInit := GetProcAddr(SSLUtilHandle, 'EVP_DecryptInit');
  3476. _EVP_DecryptUpdate := GetProcAddr(SSLUtilHandle, 'EVP_DecryptUpdate');
  3477. _EVP_DecryptFinal := GetProcAddr(SSLUtilHandle, 'EVP_DecryptFinal');
  3478. // PEM
  3479. _PEM_read_bio_PrivateKey := GetProcAddr(SSLUtilHandle, 'PEM_read_bio_PrivateKey');
  3480. _PEM_read_bio_PUBKEY := GetProcAddr(SSLUtilHandle, 'PEM_read_bio_PUBKEY');
  3481. _PEM_write_bio_PrivateKey := GetProcAddr(SSLUtilHandle, 'PEM_write_bio_PrivateKey');
  3482. _PEM_write_bio_PUBKEY := GetProcAddr(SSLUtilHandle, 'PEM_write_bio_PUBKEY');
  3483. _PEM_read_bio_X509 := GetProcAddr(SSLUtilHandle, 'PEM_read_bio_X509');
  3484. // BIO
  3485. _BIO_ctrl := GetProcAddr(SSLUtilHandle, 'BIO_ctrl');
  3486. _BIO_s_file := GetProcAddr(SSLUtilHandle, 'BIO_s_file');
  3487. _BIO_new_file := GetProcAddr(SSLUtilHandle, 'BIO_new_file');
  3488. _BIO_new_mem_buf := GetProcAddr(SSLUtilHandle, 'BIO_new_mem_buf');
  3489. // Crypto Functions
  3490. _SSLeay_version := GetProcAddr(SSLUtilHandle, 'SSLeay_version');
  3491. // PKCS7
  3492. _PKCS7_ISSUER_AND_SERIAL_new:=GetProcAddr(SSLUtilHandle,'PKCS7_ISSUER_AND_SERIAL_new');
  3493. _PKCS7_ISSUER_AND_SERIAL_free:=GetProcAddr(SSLUtilHandle,'PKCS7_ISSUER_AND_SERIAL_free');
  3494. _PKCS7_ISSUER_AND_SERIAL_digest:=GetProcAddr(SSLUtilHandle,'PKCS7_ISSUER_AND_SERIAL_digest');
  3495. _PKCS7_dup:=GetProcAddr(SSLUtilHandle,'PKCS7_dup');
  3496. _PEM_write_bio_PKCS7_stream:=GetProcAddr(SSLUtilHandle,'PEM_write_bio_PKCS7_stream');
  3497. _PKCS7_SIGNER_INFO_new:=GetProcAddr(SSLUtilHandle,'PKCS7_SIGNER_INFO_new');
  3498. _PKCS7_SIGNER_INFO_free:=GetProcAddr(SSLUtilHandle,'PKCS7_SIGNER_INFO_free');
  3499. _PKCS7_RECIP_INFO_new:=GetProcAddr(SSLUtilHandle,'PKCS7_RECIP_INFO_new');
  3500. _PKCS7_RECIP_INFO_free:=GetProcAddr(SSLUtilHandle,'PKCS7_RECIP_INFO_free');
  3501. _PKCS7_SIGNED_new:=GetProcAddr(SSLUtilHandle,'PKCS7_SIGNED_new');
  3502. _PKCS7_SIGNED_free:=GetProcAddr(SSLUtilHandle,'PKCS7_SIGNED_free');
  3503. _PKCS7_ENC_CONTENT_new:=GetProcAddr(SSLUtilHandle,'PKCS7_ENC_CONTENT_new');
  3504. _PKCS7_ENC_CONTENT_free:=GetProcAddr(SSLUtilHandle,'PKCS7_ENC_CONTENT_free');
  3505. _PKCS7_ENVELOPE_new:=GetProcAddr(SSLUtilHandle,'PKCS7_ENVELOPE_new');
  3506. _PKCS7_ENVELOPE_free:=GetProcAddr(SSLUtilHandle,'PKCS7_ENVELOPE_free');
  3507. _PKCS7_SIGN_ENVELOPE_new:=GetProcAddr(SSLUtilHandle,'PKCS7_SIGN_ENVELOPE_new');
  3508. _PKCS7_SIGN_ENVELOPE_free:=GetProcAddr(SSLUtilHandle,'PKCS7_SIGN_ENVELOPE_free');
  3509. _PKCS7_DIGEST_new:=GetProcAddr(SSLUtilHandle,'PKCS7_DIGEST_new');
  3510. _PKCS7_DIGEST_free:=GetProcAddr(SSLUtilHandle,'PKCS7_DIGEST_free');
  3511. _PKCS7_ENCRYPT_new:=GetProcAddr(SSLUtilHandle,'PKCS7_ENCRYPT_new');
  3512. _PKCS7_ENCRYPT_free:=GetProcAddr(SSLUtilHandle,'PKCS7_ENCRYPT_free');
  3513. _PKCS7_new:=GetProcAddr(SSLUtilHandle,'PKCS7_new');
  3514. _PKCS7_free:=GetProcAddr(SSLUtilHandle,'PKCS7_free');
  3515. _PKCS7_print_ctx:=GetProcAddr(SSLUtilHandle,'PKCS7_print_ctx');
  3516. _PKCS7_ctrl:=GetProcAddr(SSLUtilHandle,'PKCS7_ctrl');
  3517. _PKCS7_set_type:=GetProcAddr(SSLUtilHandle,'PKCS7_set_type');
  3518. _PKCS7_set0_type_other:=GetProcAddr(SSLUtilHandle,'PKCS7_set0_type_other');
  3519. _PKCS7_set_content:=GetProcAddr(SSLUtilHandle,'PKCS7_set_content');
  3520. _PKCS7_SIGNER_INFO_set:=GetProcAddr(SSLUtilHandle,'PKCS7_SIGNER_INFO_set');
  3521. _PKCS7_SIGNER_INFO_sign:=GetProcAddr(SSLUtilHandle,'PKCS7_SIGNER_INFO_sign');
  3522. _PKCS7_add_signer:=GetProcAddr(SSLUtilHandle,'PKCS7_add_signer');
  3523. _PKCS7_add_certificate:=GetProcAddr(SSLUtilHandle,'PKCS7_add_certificate');
  3524. _PKCS7_add_crl:=GetProcAddr(SSLUtilHandle,'PKCS7_add_crl');
  3525. _PKCS7_content_new:=GetProcAddr(SSLUtilHandle,'PKCS7_content_new');
  3526. _PKCS7_add_signature:=GetProcAddr(SSLUtilHandle,'PKCS7_add_signature');
  3527. _PKCS7_cert_from_signer_info:=GetProcAddr(SSLUtilHandle,'PKCS7_cert_from_signer_info');
  3528. _PKCS7_set_digest:=GetProcAddr(SSLUtilHandle,'PKCS7_set_digest');
  3529. _PKCS7_add_recipient:=GetProcAddr(SSLUtilHandle,'PKCS7_add_recipient');
  3530. _PKCS7_add_recipient_info:=GetProcAddr(SSLUtilHandle,'PKCS7_add_recipient_info');
  3531. _PKCS7_RECIP_INFO_set:=GetProcAddr(SSLUtilHandle,'PKCS7_RECIP_INFO_set');
  3532. _PKCS7_set_cipher:=GetProcAddr(SSLUtilHandle,'PKCS7_set_cipher');
  3533. _PKCS7_get_issuer_and_serial:=GetProcAddr(SSLUtilHandle,'PKCS7_get_issuer_and_serial');
  3534. _PKCS7_digest_from_attributes:=GetProcAddr(SSLUtilHandle,'PKCS7_digest_from_attributes');
  3535. _PKCS7_add_signed_attribute:=GetProcAddr(SSLUtilHandle,'PKCS7_add_signed_attribute');
  3536. _PKCS7_add_attribute:=GetProcAddr(SSLUtilHandle,'PKCS7_add_attribute');
  3537. _PKCS7_get_attribute:=GetProcAddr(SSLUtilHandle,'PKCS7_get_attribute');
  3538. _PKCS7_get_signed_attribute:=GetProcAddr(SSLUtilHandle,'PKCS7_get_signed_attribute');
  3539. _PKCS7_set_signed_attributes:=GetProcAddr(SSLUtilHandle,'PKCS7_set_signed_attributes');
  3540. _PKCS7_set_attributes:=GetProcAddr(SSLUtilHandle,'PKCS7_set_attributes');
  3541. _PKCS7_sign:=GetProcAddr(SSLUtilHandle,'PKCS7_sign');
  3542. _PKCS7_sign_add_signer:=GetProcAddr(SSLUtilHandle,'PKCS7_sign_add_signer');
  3543. _PKCS7_final:=GetProcAddr(SSLUtilHandle,'PKCS7_final');
  3544. _PKCS7_verify:=GetProcAddr(SSLUtilHandle,'PKCS7_verify');
  3545. _PKCS7_encrypt:=GetProcAddr(SSLUtilHandle,'PKCS7_encrypt');
  3546. _PKCS7_decrypt:=GetProcAddr(SSLUtilHandle,'PKCS7_decrypt');
  3547. _PKCS7_add_attrib_smimecap:=GetProcAddr(SSLUtilHandle,'PKCS7_add_attrib_smimecap');
  3548. _PKCS7_simple_smimecap:=GetProcAddr(SSLUtilHandle,'PKCS7_simple_smimecap');
  3549. _PKCS7_add_attrib_content_type:=GetProcAddr(SSLUtilHandle,'PKCS7_add_attrib_content_type');
  3550. _PKCS7_add0_attrib_signing_time:=GetProcAddr(SSLUtilHandle,'PKCS7_add0_attrib_signing_time');
  3551. _PKCS7_add1_attrib_digest:=GetProcAddr(SSLUtilHandle,'PKCS7_add1_attrib_digest');
  3552. _BIO_new_PKCS7:=GetProcAddr(SSLUtilHandle,'BIO_new_PKCS7');
  3553. _ERR_load_PKCS7_strings:=GetProcAddr(SSLUtilHandle,'ERR_load_PKCS7_strings');
  3554. end;
  3555. Function LoadUtilLibrary : Boolean;
  3556. begin
  3557. Result:=(SSLUtilHandle<>0);
  3558. if not Result then
  3559. begin
  3560. SSLUtilHandle := LoadLib(DLLUtilName);
  3561. Result:=(SSLUtilHandle<>0);
  3562. end;
  3563. end;
  3564. Procedure ClearSSLEntryPoints;
  3565. begin
  3566. _SslGetError := nil;
  3567. _SslLibraryInit := nil;
  3568. _SslLoadErrorStrings := nil;
  3569. _SslCtxSetCipherList := nil;
  3570. _SslCtxNew := nil;
  3571. _SslCtxFree := nil;
  3572. _SslSetFd := nil;
  3573. _SslCtrl := nil;
  3574. _SslCTXCtrl := nil;
  3575. _SslMethodV2 := nil;
  3576. _SslMethodV3 := nil;
  3577. _SslMethodTLSV1 := nil;
  3578. _SslMethodV23 := nil;
  3579. _SslCtxUsePrivateKey := nil;
  3580. _SslCtxUsePrivateKeyASN1 := nil;
  3581. _SslCtxUsePrivateKeyFile := nil;
  3582. _SslCtxUseCertificate := nil;
  3583. _SslCtxUseCertificateASN1 := nil;
  3584. _SslCtxUseCertificateFile := nil;
  3585. _SslCtxUseCertificateChainFile := nil;
  3586. _SslCtxCheckPrivateKeyFile := nil;
  3587. _SslCtxSetDefaultPasswdCb := nil;
  3588. _SslCtxSetDefaultPasswdCbUserdata := nil;
  3589. _SslCtxLoadVerifyLocations := nil;
  3590. _SslNew := nil;
  3591. _SslFree := nil;
  3592. _SslAccept := nil;
  3593. _SslConnect := nil;
  3594. _SslShutdown := nil;
  3595. _SslRead := nil;
  3596. _SslPeek := nil;
  3597. _SslWrite := nil;
  3598. _SslPending := nil;
  3599. _SslGetPeerCertificate := nil;
  3600. _SslGetVersion := nil;
  3601. _SslCtxSetVerify := nil;
  3602. _SslGetCurrentCipher := nil;
  3603. _SslCipherGetName := nil;
  3604. _SslCipherGetBits := nil;
  3605. _SslGetVerifyResult := nil;
  3606. _PKCS7_ISSUER_AND_SERIAL_new:=nil;
  3607. _PKCS7_ISSUER_AND_SERIAL_free:=nil;
  3608. _PKCS7_ISSUER_AND_SERIAL_digest:=nil;
  3609. _PKCS7_dup:=nil;
  3610. _PEM_write_bio_PKCS7_stream:=nil;
  3611. _PKCS7_SIGNER_INFO_new:=nil;
  3612. _PKCS7_SIGNER_INFO_free:=nil;
  3613. _PKCS7_RECIP_INFO_new:=nil;
  3614. _PKCS7_RECIP_INFO_free:=nil;
  3615. _PKCS7_SIGNED_new:=nil;
  3616. _PKCS7_SIGNED_free:=nil;
  3617. _PKCS7_ENC_CONTENT_new:=nil;
  3618. _PKCS7_ENC_CONTENT_free:=nil;
  3619. _PKCS7_ENVELOPE_new:=nil;
  3620. _PKCS7_ENVELOPE_free:=nil;
  3621. _PKCS7_SIGN_ENVELOPE_new:=nil;
  3622. _PKCS7_SIGN_ENVELOPE_free:=nil;
  3623. _PKCS7_DIGEST_new:=nil;
  3624. _PKCS7_DIGEST_free:=nil;
  3625. _PKCS7_ENCRYPT_new:=nil;
  3626. _PKCS7_ENCRYPT_free:=nil;
  3627. _PKCS7_new:=nil;
  3628. _PKCS7_free:=nil;
  3629. _PKCS7_print_ctx:=nil;
  3630. _PKCS7_ctrl:=nil;
  3631. _PKCS7_set_type:=nil;
  3632. _PKCS7_set0_type_other:=nil;
  3633. _PKCS7_set_content:=nil;
  3634. _PKCS7_SIGNER_INFO_set:=nil;
  3635. _PKCS7_SIGNER_INFO_sign:=nil;
  3636. _PKCS7_add_signer:=nil;
  3637. _PKCS7_add_certificate:=nil;
  3638. _PKCS7_add_crl:=nil;
  3639. _PKCS7_content_new:=nil;
  3640. _PKCS7_add_signature:=nil;
  3641. _PKCS7_cert_from_signer_info:=nil;
  3642. _PKCS7_set_digest:=nil;
  3643. _PKCS7_add_recipient:=nil;
  3644. _PKCS7_add_recipient_info:=nil;
  3645. _PKCS7_RECIP_INFO_set:=nil;
  3646. _PKCS7_set_cipher:=nil;
  3647. _PKCS7_get_issuer_and_serial:=nil;
  3648. _PKCS7_digest_from_attributes:=nil;
  3649. _PKCS7_add_signed_attribute:=nil;
  3650. _PKCS7_add_attribute:=nil;
  3651. _PKCS7_get_attribute:=nil;
  3652. _PKCS7_get_signed_attribute:=nil;
  3653. _PKCS7_set_signed_attributes:=nil;
  3654. _PKCS7_set_attributes:=nil;
  3655. _PKCS7_sign:=nil;
  3656. _PKCS7_sign_add_signer:=nil;
  3657. _PKCS7_final:=nil;
  3658. _PKCS7_verify:=nil;
  3659. _PKCS7_encrypt:=nil;
  3660. _PKCS7_decrypt:=nil;
  3661. _PKCS7_add_attrib_smimecap:=nil;
  3662. _PKCS7_simple_smimecap:=nil;
  3663. _PKCS7_add_attrib_content_type:=nil;
  3664. _PKCS7_add0_attrib_signing_time:=nil;
  3665. _PKCS7_add1_attrib_digest:=nil;
  3666. _BIO_new_PKCS7:=nil;
  3667. _ERR_load_PKCS7_strings:=nil;
  3668. end;
  3669. Procedure UnloadSSLLib;
  3670. begin
  3671. if (SSLLibHandle<>0) then
  3672. begin
  3673. FreeLibrary(SSLLibHandle);
  3674. SSLLibHandle:=0;
  3675. end;
  3676. end;
  3677. Procedure UnloadUtilLib;
  3678. begin
  3679. if (SSLUtilHandle<>0) then
  3680. begin
  3681. FreeLibrary(SSLUtilHandle);
  3682. SSLUtilHandle := 0;
  3683. end;
  3684. end;
  3685. Procedure ClearUtilEntryPoints;
  3686. begin
  3687. _SSLeayversion := nil;
  3688. _ERR_load_crypto_strings := nil;
  3689. _X509New := nil;
  3690. _X509Free := nil;
  3691. _X509NameOneline := nil;
  3692. _X509GetSubjectName := nil;
  3693. _X509GetIssuerName := nil;
  3694. _X509NameHash := nil;
  3695. _X509Digest := nil;
  3696. _X509print := nil;
  3697. _X509SetVersion := nil;
  3698. _X509SetPubkey := nil;
  3699. _X509GetPubkey := nil;
  3700. _X509SetIssuerName := nil;
  3701. _X509NameAddEntryByTxt := nil;
  3702. _X509Sign := nil;
  3703. _X509GmtimeAdj := nil;
  3704. _X509SetNotBefore := nil;
  3705. _X509SetNotAfter := nil;
  3706. _X509GetSerialNumber := nil;
  3707. _EvpPkeyNew := nil;
  3708. _EvpPkeyFree := nil;
  3709. _EvpPkeyAssign := nil;
  3710. _EVPCleanup := nil;
  3711. _EvpGetDigestByName := nil;
  3712. _ErrErrorString := nil;
  3713. _ErrGetError := nil;
  3714. _ErrClearError := nil;
  3715. _ErrFreeStrings := nil;
  3716. _ErrRemoveState := nil;
  3717. _RandScreen := nil;
  3718. _BioNew := nil;
  3719. _BioFreeAll := nil;
  3720. _BioSMem := nil;
  3721. _BioCtrlPending := nil;
  3722. _BioRead := nil;
  3723. _BioWrite := nil;
  3724. _d2iPKCS12bio := nil;
  3725. _PKCS12parse := nil;
  3726. _PKCS12free := nil;
  3727. _Asn1UtctimeNew := nil;
  3728. _Asn1UtctimeFree := nil;
  3729. _Asn1IntegerSet:= nil;
  3730. _Asn1IntegerGet:= nil;
  3731. _i2dX509bio := nil;
  3732. _i2dPrivateKeyBio := nil;
  3733. // 3DES functions
  3734. _DESsetoddparity := nil;
  3735. _DESsetkeychecked := nil;
  3736. _DESecbencrypt := nil;
  3737. //
  3738. _CRYPTOnumlocks := nil;
  3739. _CRYPTOsetlockingcallback := nil;
  3740. // RAND functions
  3741. _RAND_set_rand_method := nil;
  3742. _RAND_get_rand_method := nil;
  3743. _RAND_SSLeay := nil;
  3744. _RAND_cleanup := nil;
  3745. _RAND_bytes := nil;
  3746. _RAND_pseudo_bytes := nil;
  3747. _RAND_seed := nil;
  3748. _RAND_add := nil;
  3749. _RAND_load_file := nil;
  3750. _RAND_write_file := nil;
  3751. _RAND_file_name := nil;
  3752. _RAND_status := nil;
  3753. _RAND_query_egd_bytes := nil;
  3754. _RAND_egd := nil;
  3755. _RAND_egd_bytes := nil;
  3756. _ERR_load_RAND_strings := nil;
  3757. _RAND_poll := nil;
  3758. // RSA Functions
  3759. _RSA_new := nil;
  3760. _RSA_new_method := nil;
  3761. _RSA_size := nil;
  3762. _RsaGenerateKey := nil;
  3763. _RSA_generate_key_ex := nil;
  3764. _RSA_check_key := nil;
  3765. _RSA_public_encrypt := nil;
  3766. _RSA_private_encrypt := nil;
  3767. _RSA_public_decrypt := nil;
  3768. _RSA_private_decrypt := nil;
  3769. _RSA_free := nil;
  3770. _RSA_flags := nil;
  3771. _RSA_set_default_method := nil;
  3772. _RSA_get_default_method := nil;
  3773. _RSA_get_method := nil;
  3774. _RSA_set_method := nil;
  3775. // X509 Functions
  3776. _d2i_RSAPublicKey := nil;
  3777. _i2d_RSAPublicKey := nil;
  3778. _d2i_RSAPrivateKey := nil;
  3779. _i2d_RSAPrivateKey := nil;
  3780. // ERR Functions
  3781. _ERR_error_string := nil;
  3782. // EVP Functions
  3783. _OpenSSL_add_all_algorithms := nil;
  3784. _OpenSSL_add_all_ciphers := nil;
  3785. _OpenSSL_add_all_digests := nil;
  3786. //
  3787. _EVP_DigestInit := nil;
  3788. _EVP_DigestUpdate := nil;
  3789. _EVP_DigestFinal := nil;
  3790. _EVP_SignFinal := nil;
  3791. _EVP_PKEY_size := nil;
  3792. _EVP_PKEY_free := nil;
  3793. _EVP_VerifyFinal := nil;
  3794. //
  3795. _EVP_get_cipherbyname := nil;
  3796. _EVP_get_digestbyname := nil;
  3797. //
  3798. _EVP_CIPHER_CTX_init := nil;
  3799. _EVP_CIPHER_CTX_cleanup := nil;
  3800. _EVP_CIPHER_CTX_set_key_length := nil;
  3801. _EVP_CIPHER_CTX_ctrl := nil;
  3802. //
  3803. _EVP_EncryptInit := nil;
  3804. _EVP_EncryptUpdate := nil;
  3805. _EVP_EncryptFinal := nil;
  3806. //
  3807. _EVP_DecryptInit := nil;
  3808. _EVP_DecryptUpdate := nil;
  3809. _EVP_DecryptFinal := nil;
  3810. // PEM
  3811. _PEM_read_bio_PrivateKey := nil;
  3812. _PEM_read_bio_PrivateKey := nil;
  3813. _PEM_read_bio_PUBKEY := nil;
  3814. _PEM_write_bio_PrivateKey := nil;
  3815. _PEM_read_bio_X509 := nil;
  3816. // BIO
  3817. _BIO_ctrl := nil;
  3818. _BIO_s_file := nil;
  3819. _BIO_new_file := nil;
  3820. _BIO_new_mem_buf := nil;
  3821. // Crypto Functions
  3822. _SSLeay_version := nil;
  3823. end;
  3824. procedure locking_callback(mode, ltype: integer; lfile: PChar; line: integer); cdecl;
  3825. begin
  3826. if (mode and 1) > 0 then
  3827. EnterCriticalSection(Locks[ltype])
  3828. else
  3829. LeaveCriticalSection(Locks[ltype]);
  3830. end;
  3831. procedure InitLocks;
  3832. var
  3833. n: integer;
  3834. max: integer;
  3835. begin
  3836. max:=_CRYPTOnumlocks;
  3837. SetLength(Locks,Max);
  3838. for n := 0 to max-1 do
  3839. InitCriticalSection(Locks[n]);
  3840. _CRYPTOsetlockingcallback(@locking_callback);
  3841. end;
  3842. procedure FreeLocks;
  3843. var
  3844. n: integer;
  3845. begin
  3846. _CRYPTOsetlockingcallback(nil);
  3847. for n := 0 to Length(Locks)-1 do
  3848. DoneCriticalSection(Locks[n]);
  3849. SetLength(Locks,0);
  3850. end;
  3851. Procedure UnloadLibraries;
  3852. begin
  3853. SSLloaded := false;
  3854. if SSLLibHandle <> 0 then
  3855. begin
  3856. FreeLibrary(SSLLibHandle);
  3857. SSLLibHandle := 0;
  3858. end;
  3859. if SSLUtilHandle <> 0 then
  3860. begin
  3861. FreeLibrary(SSLUtilHandle);
  3862. SSLUtilHandle := 0;
  3863. end;
  3864. end;
  3865. Function LoadLibraries : Boolean;
  3866. begin
  3867. Result:=False;
  3868. SSLUtilHandle := LoadLib(DLLUtilName);
  3869. SSLLibHandle := LoadLib(DLLSSLName);
  3870. {$IFDEF MSWINDOWS}
  3871. if (SSLLibHandle = 0) then
  3872. SSLLibHandle := LoadLib(DLLSSLName2);
  3873. {$ELSE MSWINDOWS}
  3874. {$IFDEF OS2}
  3875. if (SSLUtilHandle = 0) then
  3876. SSLUtilHandle := LoadLib(DLLUtilName2);
  3877. if (SSLLibHandle = 0) then
  3878. SSLLibHandle := LoadLib(DLLSSLName2);
  3879. {$ENDIF OS2}
  3880. {$ENDIF MSWINDOWS}
  3881. Result:=(SSLLibHandle<>0) and (SSLUtilHandle<>0);
  3882. end;
  3883. function InitSSLInterface: Boolean;
  3884. begin
  3885. Result:=SSLLoaded;
  3886. if Result then
  3887. exit;
  3888. EnterCriticalSection(SSLCS);
  3889. try
  3890. if SSLloaded then
  3891. Exit;
  3892. Result:=LoadLibraries;
  3893. if Not Result then
  3894. begin
  3895. UnloadLibraries;
  3896. Exit;
  3897. end;
  3898. LoadSSLEntryPoints;
  3899. LoadUtilEntryPoints;
  3900. //init library
  3901. if assigned(_SslLibraryInit) then
  3902. _SslLibraryInit;
  3903. if assigned(_SslLoadErrorStrings) then
  3904. _SslLoadErrorStrings;
  3905. if assigned(_OPENSSLaddallalgorithms) then
  3906. _OPENSSLaddallalgorithms;
  3907. if assigned(_RandScreen) then
  3908. _RandScreen;
  3909. if assigned(_CRYPTOnumlocks) and assigned(_CRYPTOsetlockingcallback) then
  3910. InitLocks;
  3911. SSLloaded := True;
  3912. {$IFDEF OS2}
  3913. Result := InitEMXHandles;
  3914. {$ELSE OS2}
  3915. Result := True;
  3916. {$ENDIF OS2}
  3917. finally
  3918. LeaveCriticalSection(SSLCS);
  3919. end;
  3920. end;
  3921. function DestroySSLInterface: Boolean;
  3922. begin
  3923. Result:=Not isSSLLoaded;
  3924. if Result then
  3925. exit;
  3926. EnterCriticalSection(SSLCS);
  3927. try
  3928. if assigned(_CRYPTOnumlocks) and assigned(_CRYPTOsetlockingcallback) then
  3929. FreeLocks;
  3930. EVPCleanup;
  3931. CRYPTOcleanupAllExData;
  3932. ErrRemoveState(0);
  3933. ClearUtilEntryPoints;
  3934. ClearSSLEntryPoints;
  3935. UnloadLibraries;
  3936. Result := True;
  3937. finally
  3938. LeaveCriticalSection(SSLCS);
  3939. end;
  3940. end;
  3941. initialization
  3942. InitCriticalSection(SSLCS);
  3943. finalization
  3944. DestroySSLInterface;
  3945. DoneCriticalSection(SSLCS);
  3946. end.