mkdef.pl 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729
  1. #!/usr/local/bin/perl -w
  2. #
  3. # generate a .def file
  4. #
  5. # It does this by parsing the header files and looking for the
  6. # prototyped functions: it then prunes the output.
  7. #
  8. # Intermediary files are created, call libeay.num and ssleay.num,
  9. # The format of these files is:
  10. #
  11. # routine-name nnnn vers info
  12. #
  13. # The "nnnn" and "vers" fields are the numeric id and version for the symbol
  14. # respectively. The "info" part is actually a colon-separated string of fields
  15. # with the following meaning:
  16. #
  17. # existence:platform:kind:algorithms
  18. #
  19. # - "existence" can be "EXIST" or "NOEXIST" depending on if the symbol is
  20. # found somewhere in the source,
  21. # - "platforms" is empty if it exists on all platforms, otherwise it contains
  22. # comma-separated list of the platform, just as they are if the symbol exists
  23. # for those platforms, or prepended with a "!" if not. This helps resolve
  24. # symbol name variants for platforms where the names are too long for the
  25. # compiler or linker, or if the systems is case insensitive and there is a
  26. # clash, or the symbol is implemented differently (see
  27. # EXPORT_VAR_AS_FUNCTION). This script assumes renaming of symbols is found
  28. # in the file crypto/symhacks.h.
  29. # The semantics for the platforms is that every item is checked against the
  30. # environment. For the negative items ("!FOO"), if any of them is false
  31. # (i.e. "FOO" is true) in the environment, the corresponding symbol can't be
  32. # used. For the positive itms, if all of them are false in the environment,
  33. # the corresponding symbol can't be used. Any combination of positive and
  34. # negative items are possible, and of course leave room for some redundancy.
  35. # - "kind" is "FUNCTION" or "VARIABLE". The meaning of that is obvious.
  36. # - "algorithms" is a comma-separated list of algorithm names. This helps
  37. # exclude symbols that are part of an algorithm that some user wants to
  38. # exclude.
  39. #
  40. my $debug=0;
  41. my $crypto_num= "util/libeay.num";
  42. my $ssl_num= "util/ssleay.num";
  43. my $libname;
  44. my $do_update = 0;
  45. my $do_rewrite = 1;
  46. my $do_crypto = 0;
  47. my $do_ssl = 0;
  48. my $do_ctest = 0;
  49. my $do_ctestall = 0;
  50. my $do_checkexist = 0;
  51. my $VMSVAX=0;
  52. my $VMSNonVAX=0;
  53. my $VMS=0;
  54. my $W32=0;
  55. my $NT=0;
  56. my $OS2=0;
  57. my $linux=0;
  58. # Set this to make typesafe STACK definitions appear in DEF
  59. my $safe_stack_def = 0;
  60. my @known_platforms = ( "__FreeBSD__", "PERL5",
  61. "EXPORT_VAR_AS_FUNCTION", "ZLIB"
  62. );
  63. my @known_ossl_platforms = ( "VMS", "WIN32", "WINNT", "OS2" );
  64. my @known_algorithms = ( "RC2", "RC4", "RC5", "IDEA", "DES", "BF",
  65. "CAST", "MD2", "MD4", "MD5", "SHA", "SHA0", "SHA1",
  66. "SHA256", "SHA512", "RMD160",
  67. "MDC2", "WHIRLPOOL", "RSA", "DSA", "DH", "EC", "EC2M",
  68. "HMAC", "AES", "CAMELLIA", "SEED", "GOST",
  69. "SCRYPT", "CHACHA", "POLY1305",
  70. # EC_NISTP_64_GCC_128
  71. "EC_NISTP_64_GCC_128",
  72. # Envelope "algorithms"
  73. "EVP", "X509", "ASN1_TYPEDEFS",
  74. # Helper "algorithms"
  75. "BIO", "COMP", "BUFFER", "LHASH", "STACK", "ERR",
  76. "LOCKING",
  77. # External "algorithms"
  78. "FP_API", "STDIO", "SOCK", "DGRAM",
  79. # Engines
  80. "STATIC_ENGINE", "ENGINE", "HW", "GMP",
  81. # X.509v3 Signed Certificate Timestamps
  82. "SCT",
  83. # RFC3779
  84. "RFC3779",
  85. # TLS
  86. "PSK", "SRP", "HEARTBEATS",
  87. # CMS
  88. "CMS",
  89. # CryptoAPI Engine
  90. "CAPIENG",
  91. # SSL v3 method
  92. "SSL3_METHOD",
  93. # JPAKE
  94. "JPAKE",
  95. # NEXTPROTONEG
  96. "NEXTPROTONEG",
  97. # Deprecated functions
  98. "DEPRECATED",
  99. # SCTP
  100. "SCTP",
  101. # SRTP
  102. "SRTP",
  103. # SSL TRACE
  104. "SSL_TRACE",
  105. # Unit testing
  106. "UNIT_TEST",
  107. # OCB mode
  108. "OCB",
  109. # APPLINK (win build feature?)
  110. "APPLINK"
  111. );
  112. my $options="";
  113. open(IN,"<Makefile") || die "unable to open Makefile!\n";
  114. while(<IN>) {
  115. $options=$1 if (/^OPTIONS=(.*)$/);
  116. }
  117. close(IN);
  118. # The following ciphers may be excluded (by Configure). This means functions
  119. # defined with ifndef(NO_XXX) are not included in the .def file, and everything
  120. # in directory xxx is ignored.
  121. my $no_rc2; my $no_rc4; my $no_rc5; my $no_idea; my $no_des; my $no_bf;
  122. my $no_cast; my $no_whirlpool; my $no_camellia; my $no_seed;
  123. my $no_md2; my $no_md4; my $no_md5; my $no_sha; my $no_ripemd; my $no_mdc2;
  124. my $no_rsa; my $no_dsa; my $no_dh; my $no_aes; my $no_scrypt;
  125. my $no_ec; my $no_engine; my $no_hw;
  126. my $no_chacha; my $no_poly1305;
  127. my $no_fp_api; my $no_static_engine=1; my $no_deprecated;
  128. my $no_sct; my $no_rfc3779; my $no_psk; my $no_cms; my $no_capieng;
  129. my $no_jpake; my $no_srp; my $no_ec2m; my $no_nistp_gcc;
  130. my $no_nextprotoneg; my $no_sctp; my $no_srtp; my $no_ssl_trace;
  131. my $no_unit_test; my $no_ssl3_method; my $no_ocb;
  132. my $zlib;
  133. foreach (@ARGV, split(/ /, $options))
  134. {
  135. $debug=1 if $_ eq "debug";
  136. $W32=1 if $_ eq "32";
  137. die "win16 not supported" if $_ eq "16";
  138. if($_ eq "NT") {
  139. $W32 = 1;
  140. $NT = 1;
  141. }
  142. if ($_ eq "VMS-VAX") {
  143. $VMS=1;
  144. $VMSVAX=1;
  145. }
  146. if ($_ eq "VMS-NonVAX") {
  147. $VMS=1;
  148. $VMSNonVAX=1;
  149. }
  150. if ($_ eq "linux") {
  151. $linux=1;
  152. }
  153. $VMS=1 if $_ eq "VMS";
  154. $OS2=1 if $_ eq "OS2";
  155. if ($_ eq "zlib" || $_ eq "enable-zlib" || $_ eq "zlib-dynamic"
  156. || $_ eq "enable-zlib-dynamic") {
  157. $zlib = 1;
  158. }
  159. $do_ssl=1 if $_ eq "ssleay";
  160. if ($_ eq "ssl") {
  161. $do_ssl=1;
  162. $libname=$_
  163. }
  164. $do_crypto=1 if $_ eq "libeay";
  165. if ($_ eq "crypto") {
  166. $do_crypto=1;
  167. $libname=$_;
  168. }
  169. $no_static_engine=1 if $_ eq "no-static-engine";
  170. $no_static_engine=0 if $_ eq "enable-static-engine";
  171. $do_update=1 if $_ eq "update";
  172. $do_rewrite=1 if $_ eq "rewrite";
  173. $do_ctest=1 if $_ eq "ctest";
  174. $do_ctestall=1 if $_ eq "ctestall";
  175. $do_checkexist=1 if $_ eq "exist";
  176. #$safe_stack_def=1 if $_ eq "-DDEBUG_SAFESTACK";
  177. if (/^no-rc2$/) { $no_rc2=1; }
  178. elsif (/^no-rc4$/) { $no_rc4=1; }
  179. elsif (/^no-rc5$/) { $no_rc5=1; }
  180. elsif (/^no-idea$/) { $no_idea=1; }
  181. elsif (/^no-des$/) { $no_des=1; $no_mdc2=1; }
  182. elsif (/^no-bf$/) { $no_bf=1; }
  183. elsif (/^no-cast$/) { $no_cast=1; }
  184. elsif (/^no-whirlpool$/) { $no_whirlpool=1; }
  185. elsif (/^no-md2$/) { $no_md2=1; }
  186. elsif (/^no-md4$/) { $no_md4=1; }
  187. elsif (/^no-md5$/) { $no_md5=1; }
  188. elsif (/^no-sha$/) { $no_sha=1; }
  189. elsif (/^no-ripemd$/) { $no_ripemd=1; }
  190. elsif (/^no-mdc2$/) { $no_mdc2=1; }
  191. elsif (/^no-rsa$/) { $no_rsa=1; }
  192. elsif (/^no-dsa$/) { $no_dsa=1; }
  193. elsif (/^no-dh$/) { $no_dh=1; }
  194. elsif (/^no-ec$/) { $no_ec=1; }
  195. elsif (/^no-aes$/) { $no_aes=1; }
  196. elsif (/^no-camellia$/) { $no_camellia=1; }
  197. elsif (/^no-seed$/) { $no_seed=1; }
  198. elsif (/^no-scrypt$/) { $no_scrypt=1; }
  199. elsif (/^no-chacha$/) { $no_chacha=1; }
  200. elsif (/^no-poly1305$/) { $no_poly1305=1; }
  201. elsif (/^no-evp$/) { $no_evp=1; }
  202. elsif (/^no-lhash$/) { $no_lhash=1; }
  203. elsif (/^no-stack$/) { $no_stack=1; }
  204. elsif (/^no-err$/) { $no_err=1; }
  205. elsif (/^no-buffer$/) { $no_buffer=1; }
  206. elsif (/^no-bio$/) { $no_bio=1; }
  207. #elsif (/^no-locking$/) { $no_locking=1; }
  208. elsif (/^no-comp$/) { $no_comp=1; }
  209. elsif (/^no-dso$/) { $no_dso=1; }
  210. elsif (/^no-engine$/) { $no_engine=1; }
  211. elsif (/^no-hw$/) { $no_hw=1; }
  212. elsif (/^no-sct$/) { $no_sct=1; }
  213. elsif (/^no-rfc3779$/) { $no_rfc3779=1; }
  214. elsif (/^no-cms$/) { $no_cms=1; }
  215. elsif (/^no-ec2m$/) { $no_ec2m=1; }
  216. elsif (/^no-ec-nistp224-64-gcc-128$/) { $no_nistp_gcc=1; }
  217. elsif (/^no-nextprotoneg$/) { $no_nextprotoneg=1; }
  218. elsif (/^no-ssl3-method$/) { $no_ssl3_method=1; }
  219. elsif (/^no-ssl-trace$/) { $no_ssl_trace=1; }
  220. elsif (/^no-capieng$/) { $no_capieng=1; }
  221. elsif (/^no-jpake$/) { $no_jpake=1; }
  222. elsif (/^no-srp$/) { $no_srp=1; }
  223. elsif (/^no-sctp$/) { $no_sctp=1; }
  224. elsif (/^no-srtp$/) { $no_srtp=1; }
  225. elsif (/^no-unit-test$/){ $no_unit_test=1; }
  226. elsif (/^no-deprecated$/) { $no_deprecated=1; }
  227. elsif (/^no-ocb/){ $no_ocb=1; }
  228. }
  229. if (!$libname) {
  230. if ($do_ssl) {
  231. $libname="SSLEAY";
  232. }
  233. if ($do_crypto) {
  234. $libname="LIBEAY";
  235. }
  236. }
  237. # If no platform is given, assume WIN32
  238. if ($W32 + $VMS + $OS2 + $linux == 0) {
  239. $W32 = 1;
  240. }
  241. if (!$do_ssl && !$do_crypto)
  242. {
  243. print STDERR "usage: $0 ( ssl | crypto ) [ 16 | 32 | NT | OS2 ]\n";
  244. exit(1);
  245. }
  246. %ssl_list=&load_numbers($ssl_num);
  247. $max_ssl = $max_num;
  248. %crypto_list=&load_numbers($crypto_num);
  249. $max_crypto = $max_num;
  250. my $ssl="include/openssl/ssl.h";
  251. $ssl.=" include/openssl/tls1.h";
  252. $ssl.=" include/openssl/srtp.h";
  253. my $crypto ="include/openssl/crypto.h";
  254. $crypto.=" crypto/include/internal/cryptlib.h";
  255. $crypto.=" crypto/include/internal/chacha.h"; # unless $no_chacha;
  256. $crypto.=" crypto/include/internal/poly1305.h"; # unless $no_poly1305;
  257. $crypto.=" include/internal/o_dir.h";
  258. $crypto.=" include/internal/o_str.h";
  259. $crypto.=" include/openssl/des.h" ; # unless $no_des;
  260. $crypto.=" include/openssl/idea.h" ; # unless $no_idea;
  261. $crypto.=" include/openssl/rc4.h" ; # unless $no_rc4;
  262. $crypto.=" include/openssl/rc5.h" ; # unless $no_rc5;
  263. $crypto.=" include/openssl/rc2.h" ; # unless $no_rc2;
  264. $crypto.=" include/openssl/blowfish.h" ; # unless $no_bf;
  265. $crypto.=" include/openssl/cast.h" ; # unless $no_cast;
  266. $crypto.=" include/openssl/whrlpool.h" ;
  267. $crypto.=" include/openssl/md2.h" ; # unless $no_md2;
  268. $crypto.=" include/openssl/md4.h" ; # unless $no_md4;
  269. $crypto.=" include/openssl/md5.h" ; # unless $no_md5;
  270. $crypto.=" include/openssl/mdc2.h" ; # unless $no_mdc2;
  271. $crypto.=" include/openssl/sha.h" ; # unless $no_sha;
  272. $crypto.=" include/openssl/ripemd.h" ; # unless $no_ripemd;
  273. $crypto.=" include/openssl/aes.h" ; # unless $no_aes;
  274. $crypto.=" include/openssl/camellia.h" ; # unless $no_camellia;
  275. $crypto.=" include/openssl/seed.h"; # unless $no_seed;
  276. $crypto.=" include/openssl/bn.h";
  277. $crypto.=" include/openssl/rsa.h" ; # unless $no_rsa;
  278. $crypto.=" include/openssl/dsa.h" ; # unless $no_dsa;
  279. $crypto.=" include/openssl/dh.h" ; # unless $no_dh;
  280. $crypto.=" include/openssl/ec.h" ; # unless $no_ec;
  281. $crypto.=" include/openssl/hmac.h" ; # unless $no_hmac;
  282. $crypto.=" include/openssl/cmac.h" ;
  283. $crypto.=" include/openssl/engine.h"; # unless $no_engine;
  284. $crypto.=" include/openssl/stack.h" ; # unless $no_stack;
  285. $crypto.=" include/openssl/buffer.h" ; # unless $no_buffer;
  286. $crypto.=" include/openssl/bio.h" ; # unless $no_bio;
  287. $crypto.=" include/openssl/dso.h" ; # unless $no_dso;
  288. $crypto.=" include/openssl/lhash.h" ; # unless $no_lhash;
  289. $crypto.=" include/openssl/conf.h";
  290. $crypto.=" include/openssl/txt_db.h";
  291. $crypto.=" include/openssl/evp.h" ; # unless $no_evp;
  292. $crypto.=" include/openssl/objects.h";
  293. $crypto.=" include/openssl/pem.h";
  294. #$crypto.=" include/openssl/meth.h";
  295. $crypto.=" include/openssl/asn1.h";
  296. $crypto.=" include/openssl/asn1t.h";
  297. $crypto.=" include/openssl/err.h" ; # unless $no_err;
  298. $crypto.=" include/openssl/pkcs7.h";
  299. $crypto.=" include/openssl/pkcs12.h";
  300. $crypto.=" include/openssl/x509.h";
  301. $crypto.=" include/openssl/x509_vfy.h";
  302. $crypto.=" include/openssl/x509v3.h";
  303. $crypto.=" include/openssl/ts.h";
  304. $crypto.=" include/openssl/rand.h";
  305. $crypto.=" include/openssl/comp.h" ; # unless $no_comp;
  306. $crypto.=" include/openssl/ocsp.h";
  307. $crypto.=" include/openssl/ui.h";
  308. #$crypto.=" include/openssl/store.h";
  309. $crypto.=" include/openssl/pqueue.h";
  310. $crypto.=" include/openssl/cms.h";
  311. $crypto.=" include/openssl/jpake.h";
  312. $crypto.=" include/openssl/srp.h";
  313. $crypto.=" include/openssl/modes.h";
  314. $crypto.=" include/openssl/async.h";
  315. my $symhacks="include/openssl/symhacks.h";
  316. my @ssl_symbols = &do_defs("SSLEAY", $ssl, $symhacks);
  317. my @crypto_symbols = &do_defs("LIBEAY", $crypto, $symhacks);
  318. if ($do_update) {
  319. if ($do_ssl == 1) {
  320. &maybe_add_info("SSLEAY",*ssl_list,@ssl_symbols);
  321. if ($do_rewrite == 1) {
  322. open(OUT, ">$ssl_num");
  323. &rewrite_numbers(*OUT,"SSLEAY",*ssl_list,@ssl_symbols);
  324. } else {
  325. open(OUT, ">>$ssl_num");
  326. }
  327. &update_numbers(*OUT,"SSLEAY",*ssl_list,$max_ssl,@ssl_symbols);
  328. close OUT;
  329. }
  330. if($do_crypto == 1) {
  331. &maybe_add_info("LIBEAY",*crypto_list,@crypto_symbols);
  332. if ($do_rewrite == 1) {
  333. open(OUT, ">$crypto_num");
  334. &rewrite_numbers(*OUT,"LIBEAY",*crypto_list,@crypto_symbols);
  335. } else {
  336. open(OUT, ">>$crypto_num");
  337. }
  338. &update_numbers(*OUT,"LIBEAY",*crypto_list,$max_crypto,@crypto_symbols);
  339. close OUT;
  340. }
  341. } elsif ($do_checkexist) {
  342. &check_existing(*ssl_list, @ssl_symbols)
  343. if $do_ssl == 1;
  344. &check_existing(*crypto_list, @crypto_symbols)
  345. if $do_crypto == 1;
  346. } elsif ($do_ctest || $do_ctestall) {
  347. print <<"EOF";
  348. /* Test file to check all DEF file symbols are present by trying
  349. * to link to all of them. This is *not* intended to be run!
  350. */
  351. int main()
  352. {
  353. EOF
  354. &print_test_file(*STDOUT,"SSLEAY",*ssl_list,$do_ctestall,@ssl_symbols)
  355. if $do_ssl == 1;
  356. &print_test_file(*STDOUT,"LIBEAY",*crypto_list,$do_ctestall,@crypto_symbols)
  357. if $do_crypto == 1;
  358. print "}\n";
  359. } else {
  360. &print_def_file(*STDOUT,$libname,*ssl_list,@ssl_symbols)
  361. if $do_ssl == 1;
  362. &print_def_file(*STDOUT,$libname,*crypto_list,@crypto_symbols)
  363. if $do_crypto == 1;
  364. }
  365. sub do_defs
  366. {
  367. my($name,$files,$symhacksfile)=@_;
  368. my $file;
  369. my @ret;
  370. my %syms;
  371. my %platform; # For anything undefined, we assume ""
  372. my %kind; # For anything undefined, we assume "FUNCTION"
  373. my %algorithm; # For anything undefined, we assume ""
  374. my %variant;
  375. my %variant_cnt; # To be able to allocate "name{n}" if "name"
  376. # is the same name as the original.
  377. my $cpp;
  378. my %unknown_algorithms = ();
  379. my $parens = 0;
  380. foreach $file (split(/\s+/,$symhacksfile." ".$files))
  381. {
  382. print STDERR "DEBUG: starting on $file:\n" if $debug;
  383. open(IN,"<$file") || die "unable to open $file:$!\n";
  384. my $line = "", my $def= "";
  385. my %tag = (
  386. (map { $_ => 0 } @known_platforms),
  387. (map { "OPENSSL_SYS_".$_ => 0 } @known_ossl_platforms),
  388. (map { "OPENSSL_NO_".$_ => 0 } @known_algorithms),
  389. (map { "OPENSSL_USE_".$_ => 0 } @known_algorithms),
  390. NOPROTO => 0,
  391. PERL5 => 0,
  392. _WINDLL => 0,
  393. CONST_STRICT => 0,
  394. TRUE => 1,
  395. );
  396. my $symhacking = $file eq $symhacksfile;
  397. my @current_platforms = ();
  398. my @current_algorithms = ();
  399. # params: symbol, alias, platforms, kind
  400. # The reason to put this subroutine in a variable is that
  401. # it will otherwise create it's own, unshared, version of
  402. # %tag and %variant...
  403. my $make_variant = sub
  404. {
  405. my ($s, $a, $p, $k) = @_;
  406. my ($a1, $a2);
  407. print STDERR "DEBUG: make_variant: Entered with ",$s,", ",$a,", ",(defined($p)?$p:""),", ",(defined($k)?$k:""),"\n" if $debug;
  408. if (defined($p))
  409. {
  410. $a1 = join(",",$p,
  411. grep(!/^$/,
  412. map { $tag{$_} == 1 ? $_ : "" }
  413. @known_platforms));
  414. }
  415. else
  416. {
  417. $a1 = join(",",
  418. grep(!/^$/,
  419. map { $tag{$_} == 1 ? $_ : "" }
  420. @known_platforms));
  421. }
  422. $a2 = join(",",
  423. grep(!/^$/,
  424. map { $tag{"OPENSSL_SYS_".$_} == 1 ? $_ : "" }
  425. @known_ossl_platforms));
  426. print STDERR "DEBUG: make_variant: a1 = $a1; a2 = $a2\n" if $debug;
  427. if ($a1 eq "") { $a1 = $a2; }
  428. elsif ($a1 ne "" && $a2 ne "") { $a1 .= ",".$a2; }
  429. if ($a eq $s)
  430. {
  431. if (!defined($variant_cnt{$s}))
  432. {
  433. $variant_cnt{$s} = 0;
  434. }
  435. $variant_cnt{$s}++;
  436. $a .= "{$variant_cnt{$s}}";
  437. }
  438. my $toadd = $a.":".$a1.(defined($k)?":".$k:"");
  439. my $togrep = $s.'(\{[0-9]+\})?:'.$a1.(defined($k)?":".$k:"");
  440. if (!grep(/^$togrep$/,
  441. split(/;/, defined($variant{$s})?$variant{$s}:""))) {
  442. if (defined($variant{$s})) { $variant{$s} .= ";"; }
  443. $variant{$s} .= $toadd;
  444. }
  445. print STDERR "DEBUG: make_variant: Exit with variant of ",$s," = ",$variant{$s},"\n" if $debug;
  446. };
  447. print STDERR "DEBUG: parsing ----------\n" if $debug;
  448. while(<IN>) {
  449. if($parens > 0) {
  450. #Inside a DECLARE_DEPRECATED
  451. $stored_multiline .= $_;
  452. chomp $stored_multiline;
  453. print STDERR "DEBUG: Continuing multiline DEPRECATED: $stored_multiline\n" if $debug;
  454. $parens = count_parens($stored_multiline);
  455. if ($parens == 0) {
  456. $stored_multiline =~ /^\s*DECLARE_DEPRECATED\s*\(\s*(\w*(\s|\*|\w)*)/;
  457. $def .= "$1(void);";
  458. }
  459. next;
  460. }
  461. if (/\/\* Error codes for the \w+ functions\. \*\//)
  462. {
  463. undef @tag;
  464. last;
  465. }
  466. if ($line ne '') {
  467. $_ = $line . $_;
  468. $line = '';
  469. }
  470. if (/\\$/) {
  471. chomp; # remove eol
  472. chop; # remove ending backslash
  473. $line = $_;
  474. next;
  475. }
  476. if(/\/\*/) {
  477. if (not /\*\//) { # multiline comment...
  478. $line = $_; # ... just accumulate
  479. next;
  480. } else {
  481. s/\/\*.*?\*\///gs;# wipe it
  482. }
  483. }
  484. if ($cpp) {
  485. $cpp++ if /^#\s*if/;
  486. $cpp-- if /^#\s*endif/;
  487. next;
  488. }
  489. $cpp = 1 if /^#.*ifdef.*cplusplus/;
  490. s/{[^{}]*}//gs; # ignore {} blocks
  491. print STDERR "DEBUG: \$def=\"$def\"\n" if $debug && $def ne "";
  492. print STDERR "DEBUG: \$_=\"$_\"\n" if $debug;
  493. if (/^\#\s*ifndef\s+(.*)/) {
  494. push(@tag,"-");
  495. push(@tag,$1);
  496. $tag{$1}=-1;
  497. print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug;
  498. } elsif (/^\#\s*if\s+!defined\(([^\)]+)\)/) {
  499. push(@tag,"-");
  500. if (/^\#\s*if\s+(!defined\(([^\)]+)\)(\s+\&\&\s+!defined\(([^\)]+)\))*)$/) {
  501. my $tmp_1 = $1;
  502. my $tmp_;
  503. foreach $tmp_ (split '\&\&',$tmp_1) {
  504. $tmp_ =~ /!defined\(([^\)]+)\)/;
  505. print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug;
  506. push(@tag,$1);
  507. $tag{$1}=-1;
  508. }
  509. } else {
  510. print STDERR "Warning: $file: complicated expression: $_" if $debug; # because it is O...
  511. print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug;
  512. push(@tag,$1);
  513. $tag{$1}=-1;
  514. }
  515. } elsif (/^\#\s*ifdef\s+(\S*)/) {
  516. push(@tag,"-");
  517. push(@tag,$1);
  518. $tag{$1}=1;
  519. print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug;
  520. } elsif (/^\#\s*if\s+defined\(([^\)]+)\)/) {
  521. push(@tag,"-");
  522. if (/^\#\s*if\s+(defined\(([^\)]+)\)(\s+\|\|\s+defined\(([^\)]+)\))*)$/) {
  523. my $tmp_1 = $1;
  524. my $tmp_;
  525. foreach $tmp_ (split '\|\|',$tmp_1) {
  526. $tmp_ =~ /defined\(([^\)]+)\)/;
  527. print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug;
  528. push(@tag,$1);
  529. $tag{$1}=1;
  530. }
  531. } else {
  532. print STDERR "Warning: $file: complicated expression: $_\n" if $debug; # because it is O...
  533. print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug;
  534. push(@tag,$1);
  535. $tag{$1}=1;
  536. }
  537. } elsif (/^\#\s*error\s+(\w+) is disabled\./) {
  538. my $tag_i = $#tag;
  539. while($tag[$tag_i] ne "-") {
  540. if ($tag[$tag_i] eq "OPENSSL_NO_".$1) {
  541. $tag{$tag[$tag_i]}=2;
  542. print STDERR "DEBUG: $file: chaged tag $1 = 2\n" if $debug;
  543. }
  544. $tag_i--;
  545. }
  546. } elsif (/^\#\s*endif/) {
  547. my $tag_i = $#tag;
  548. while($tag_i > 0 && $tag[$tag_i] ne "-") {
  549. my $t=$tag[$tag_i];
  550. print STDERR "DEBUG: \$t=\"$t\"\n" if $debug;
  551. if ($tag{$t}==2) {
  552. $tag{$t}=-1;
  553. } else {
  554. $tag{$t}=0;
  555. }
  556. print STDERR "DEBUG: $file: changed tag ",$t," = ",$tag{$t},"\n" if $debug;
  557. pop(@tag);
  558. if ($t =~ /^OPENSSL_NO_([A-Z0-9_]+)$/) {
  559. $t=$1;
  560. } elsif($t =~ /^OPENSSL_USE_([A-Z0-9_]+)$/) {
  561. $t=$1;
  562. } else {
  563. $t="";
  564. }
  565. if ($t ne ""
  566. && !grep(/^$t$/, @known_algorithms)) {
  567. $unknown_algorithms{$t} = 1;
  568. #print STDERR "DEBUG: Added as unknown algorithm: $t\n" if $debug;
  569. }
  570. $tag_i--;
  571. }
  572. pop(@tag);
  573. } elsif (/^\#\s*else/) {
  574. my $tag_i = $#tag;
  575. while($tag[$tag_i] ne "-") {
  576. my $t=$tag[$tag_i];
  577. $tag{$t}= -$tag{$t};
  578. print STDERR "DEBUG: $file: changed tag ",$t," = ",$tag{$t},"\n" if $debug;
  579. $tag_i--;
  580. }
  581. } elsif (/^\#\s*if\s+1/) {
  582. push(@tag,"-");
  583. # Dummy tag
  584. push(@tag,"TRUE");
  585. $tag{"TRUE"}=1;
  586. print STDERR "DEBUG: $file: found 1\n" if $debug;
  587. } elsif (/^\#\s*if\s+0/) {
  588. push(@tag,"-");
  589. # Dummy tag
  590. push(@tag,"TRUE");
  591. $tag{"TRUE"}=-1;
  592. print STDERR "DEBUG: $file: found 0\n" if $debug;
  593. } elsif (/^\#\s*define\s+(\w+)\s+(\w+)/
  594. && $symhacking && $tag{'TRUE'} != -1) {
  595. # This is for aliasing. When we find an alias,
  596. # we have to invert
  597. &$make_variant($1,$2);
  598. print STDERR "DEBUG: $file: defined $1 = $2\n" if $debug;
  599. }
  600. if (/^\#/) {
  601. @current_platforms =
  602. grep(!/^$/,
  603. map { $tag{$_} == 1 ? $_ :
  604. $tag{$_} == -1 ? "!".$_ : "" }
  605. @known_platforms);
  606. push @current_platforms
  607. , grep(!/^$/,
  608. map { $tag{"OPENSSL_SYS_".$_} == 1 ? $_ :
  609. $tag{"OPENSSL_SYS_".$_} == -1 ? "!".$_ : "" }
  610. @known_ossl_platforms);
  611. @current_algorithms = ();
  612. @current_algorithms =
  613. grep(!/^$/,
  614. map { $tag{"OPENSSL_NO_".$_} == -1 ? $_ : "" }
  615. @known_algorithms);
  616. push @current_algorithms
  617. , grep(!/^$/,
  618. map { $tag{"OPENSSL_USE_".$_} == 1 ? $_ : "" }
  619. @known_algorithms);
  620. $def .=
  621. "#INFO:"
  622. .join(',',@current_platforms).":"
  623. .join(',',@current_algorithms).";";
  624. next;
  625. }
  626. if ($tag{'TRUE'} != -1) {
  627. if (/^\s*DECLARE_STACK_OF\s*\(\s*(\w*)\s*\)/) {
  628. next;
  629. } elsif (/^\s*DECLARE_ASN1_ENCODE_FUNCTIONS\s*\(\s*(\w*)\s*,\s*(\w*)\s*,\s*(\w*)\s*\)/) {
  630. $def .= "int d2i_$3(void);";
  631. $def .= "int i2d_$3(void);";
  632. # Variant for platforms that do not
  633. # have to access globale variables
  634. # in shared libraries through functions
  635. $def .=
  636. "#INFO:"
  637. .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
  638. .join(',',@current_algorithms).";";
  639. $def .= "OPENSSL_EXTERN int $2_it;";
  640. $def .=
  641. "#INFO:"
  642. .join(',',@current_platforms).":"
  643. .join(',',@current_algorithms).";";
  644. # Variant for platforms that have to
  645. # access globale variables in shared
  646. # libraries through functions
  647. &$make_variant("$2_it","$2_it",
  648. "EXPORT_VAR_AS_FUNCTION",
  649. "FUNCTION");
  650. next;
  651. } elsif (/^\s*DECLARE_ASN1_FUNCTIONS_fname\s*\(\s*(\w*)\s*,\s*(\w*)\s*,\s*(\w*)\s*\)/) {
  652. $def .= "int d2i_$3(void);";
  653. $def .= "int i2d_$3(void);";
  654. $def .= "int $3_free(void);";
  655. $def .= "int $3_new(void);";
  656. # Variant for platforms that do not
  657. # have to access globale variables
  658. # in shared libraries through functions
  659. $def .=
  660. "#INFO:"
  661. .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
  662. .join(',',@current_algorithms).";";
  663. $def .= "OPENSSL_EXTERN int $2_it;";
  664. $def .=
  665. "#INFO:"
  666. .join(',',@current_platforms).":"
  667. .join(',',@current_algorithms).";";
  668. # Variant for platforms that have to
  669. # access globale variables in shared
  670. # libraries through functions
  671. &$make_variant("$2_it","$2_it",
  672. "EXPORT_VAR_AS_FUNCTION",
  673. "FUNCTION");
  674. next;
  675. } elsif (/^\s*DECLARE_ASN1_FUNCTIONS\s*\(\s*(\w*)\s*\)/ ||
  676. /^\s*DECLARE_ASN1_FUNCTIONS_const\s*\(\s*(\w*)\s*\)/) {
  677. $def .= "int d2i_$1(void);";
  678. $def .= "int i2d_$1(void);";
  679. $def .= "int $1_free(void);";
  680. $def .= "int $1_new(void);";
  681. # Variant for platforms that do not
  682. # have to access globale variables
  683. # in shared libraries through functions
  684. $def .=
  685. "#INFO:"
  686. .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
  687. .join(',',@current_algorithms).";";
  688. $def .= "OPENSSL_EXTERN int $1_it;";
  689. $def .=
  690. "#INFO:"
  691. .join(',',@current_platforms).":"
  692. .join(',',@current_algorithms).";";
  693. # Variant for platforms that have to
  694. # access globale variables in shared
  695. # libraries through functions
  696. &$make_variant("$1_it","$1_it",
  697. "EXPORT_VAR_AS_FUNCTION",
  698. "FUNCTION");
  699. next;
  700. } elsif (/^\s*DECLARE_ASN1_ENCODE_FUNCTIONS_const\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
  701. $def .= "int d2i_$2(void);";
  702. $def .= "int i2d_$2(void);";
  703. # Variant for platforms that do not
  704. # have to access globale variables
  705. # in shared libraries through functions
  706. $def .=
  707. "#INFO:"
  708. .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
  709. .join(',',@current_algorithms).";";
  710. $def .= "OPENSSL_EXTERN int $2_it;";
  711. $def .=
  712. "#INFO:"
  713. .join(',',@current_platforms).":"
  714. .join(',',@current_algorithms).";";
  715. # Variant for platforms that have to
  716. # access globale variables in shared
  717. # libraries through functions
  718. &$make_variant("$2_it","$2_it",
  719. "EXPORT_VAR_AS_FUNCTION",
  720. "FUNCTION");
  721. next;
  722. } elsif (/^\s*DECLARE_ASN1_ALLOC_FUNCTIONS\s*\(\s*(\w*)\s*\)/) {
  723. $def .= "int $1_free(void);";
  724. $def .= "int $1_new(void);";
  725. next;
  726. } elsif (/^\s*DECLARE_ASN1_FUNCTIONS_name\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
  727. $def .= "int d2i_$2(void);";
  728. $def .= "int i2d_$2(void);";
  729. $def .= "int $2_free(void);";
  730. $def .= "int $2_new(void);";
  731. # Variant for platforms that do not
  732. # have to access globale variables
  733. # in shared libraries through functions
  734. $def .=
  735. "#INFO:"
  736. .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
  737. .join(',',@current_algorithms).";";
  738. $def .= "OPENSSL_EXTERN int $2_it;";
  739. $def .=
  740. "#INFO:"
  741. .join(',',@current_platforms).":"
  742. .join(',',@current_algorithms).";";
  743. # Variant for platforms that have to
  744. # access globale variables in shared
  745. # libraries through functions
  746. &$make_variant("$2_it","$2_it",
  747. "EXPORT_VAR_AS_FUNCTION",
  748. "FUNCTION");
  749. next;
  750. } elsif (/^\s*DECLARE_ASN1_ITEM\s*\(\s*(\w*)\s*\)/) {
  751. # Variant for platforms that do not
  752. # have to access globale variables
  753. # in shared libraries through functions
  754. $def .=
  755. "#INFO:"
  756. .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
  757. .join(',',@current_algorithms).";";
  758. $def .= "OPENSSL_EXTERN int $1_it;";
  759. $def .=
  760. "#INFO:"
  761. .join(',',@current_platforms).":"
  762. .join(',',@current_algorithms).";";
  763. # Variant for platforms that have to
  764. # access globale variables in shared
  765. # libraries through functions
  766. &$make_variant("$1_it","$1_it",
  767. "EXPORT_VAR_AS_FUNCTION",
  768. "FUNCTION");
  769. next;
  770. } elsif (/^\s*DECLARE_ASN1_NDEF_FUNCTION\s*\(\s*(\w*)\s*\)/) {
  771. $def .= "int i2d_$1_NDEF(void);";
  772. } elsif (/^\s*DECLARE_ASN1_SET_OF\s*\(\s*(\w*)\s*\)/) {
  773. next;
  774. } elsif (/^\s*DECLARE_ASN1_PRINT_FUNCTION\s*\(\s*(\w*)\s*\)/) {
  775. $def .= "int $1_print_ctx(void);";
  776. next;
  777. } elsif (/^\s*DECLARE_ASN1_PRINT_FUNCTION_name\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
  778. $def .= "int $2_print_ctx(void);";
  779. next;
  780. } elsif (/^\s*DECLARE_PKCS12_STACK_OF\s*\(\s*(\w*)\s*\)/) {
  781. next;
  782. } elsif (/^DECLARE_PEM_rw\s*\(\s*(\w*)\s*,/ ||
  783. /^DECLARE_PEM_rw_cb\s*\(\s*(\w*)\s*,/ ||
  784. /^DECLARE_PEM_rw_const\s*\(\s*(\w*)\s*,/ ) {
  785. $def .=
  786. "#INFO:"
  787. .join(',',@current_platforms).":"
  788. .join(',',@current_algorithms).";";
  789. $def .= "int PEM_read_$1(void);";
  790. $def .= "int PEM_write_$1(void);";
  791. $def .=
  792. "#INFO:"
  793. .join(',',@current_platforms).":"
  794. .join(',',@current_algorithms).";";
  795. # Things that are everywhere
  796. $def .= "int PEM_read_bio_$1(void);";
  797. $def .= "int PEM_write_bio_$1(void);";
  798. next;
  799. } elsif (/^DECLARE_PEM_write\s*\(\s*(\w*)\s*,/ ||
  800. /^DECLARE_PEM_write_const\s*\(\s*(\w*)\s*,/ ||
  801. /^DECLARE_PEM_write_cb\s*\(\s*(\w*)\s*,/ ) {
  802. $def .=
  803. "#INFO:"
  804. .join(',',@current_platforms).":"
  805. .join(',',@current_algorithms).";";
  806. $def .= "int PEM_write_$1(void);";
  807. $def .=
  808. "#INFO:"
  809. .join(',',@current_platforms).":"
  810. .join(',',@current_algorithms).";";
  811. # Things that are everywhere
  812. $def .= "int PEM_write_bio_$1(void);";
  813. next;
  814. } elsif (/^DECLARE_PEM_read\s*\(\s*(\w*)\s*,/ ||
  815. /^DECLARE_PEM_read_cb\s*\(\s*(\w*)\s*,/ ) {
  816. $def .=
  817. "#INFO:"
  818. .join(',',@current_platforms).":"
  819. .join(',',@current_algorithms).";";
  820. $def .= "int PEM_read_$1(void);";
  821. $def .=
  822. "#INFO:"
  823. .join(',',@current_platforms).":"
  824. .join(',',@current_algorithms).";";
  825. # Things that are everywhere
  826. $def .= "int PEM_read_bio_$1(void);";
  827. next;
  828. } elsif (/^OPENSSL_DECLARE_GLOBAL\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
  829. # Variant for platforms that do not
  830. # have to access globale variables
  831. # in shared libraries through functions
  832. $def .=
  833. "#INFO:"
  834. .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
  835. .join(',',@current_algorithms).";";
  836. $def .= "OPENSSL_EXTERN int _shadow_$2;";
  837. $def .=
  838. "#INFO:"
  839. .join(',',@current_platforms).":"
  840. .join(',',@current_algorithms).";";
  841. # Variant for platforms that have to
  842. # access globale variables in shared
  843. # libraries through functions
  844. &$make_variant("_shadow_$2","_shadow_$2",
  845. "EXPORT_VAR_AS_FUNCTION",
  846. "FUNCTION");
  847. } elsif (/^\s*DECLARE_DEPRECATED\s*\(\s*(\w*(\s|\*|\w)*)/) {
  848. $parens = count_parens($_);
  849. if ($parens == 0) {
  850. $def .= "$1(void);";
  851. } else {
  852. $stored_multiline = $_;
  853. chomp $stored_multiline;
  854. print STDERR "DEBUG: Found multiline DEPRECATED starting with: $stored_multiline\n" if $debug;
  855. next;
  856. }
  857. } elsif ($tag{'CONST_STRICT'} != 1) {
  858. if (/\{|\/\*|\([^\)]*$/) {
  859. $line = $_;
  860. } else {
  861. $def .= $_;
  862. }
  863. }
  864. }
  865. }
  866. close(IN);
  867. my $algs;
  868. my $plays;
  869. print STDERR "DEBUG: postprocessing ----------\n" if $debug;
  870. foreach (split /;/, $def) {
  871. my $s; my $k = "FUNCTION"; my $p; my $a;
  872. s/^[\n\s]*//g;
  873. s/[\n\s]*$//g;
  874. next if(/\#undef/);
  875. next if(/typedef\W/);
  876. next if(/\#define/);
  877. # Reduce argument lists to empty ()
  878. # fold round brackets recursively: (t(*v)(t),t) -> (t{}{},t) -> {}
  879. while(/\(.*\)/s) {
  880. s/\([^\(\)]+\)/\{\}/gs;
  881. s/\(\s*\*\s*(\w+)\s*\{\}\s*\)/$1/gs; #(*f{}) -> f
  882. }
  883. # pretend as we didn't use curly braces: {} -> ()
  884. s/\{\}/\(\)/gs;
  885. s/STACK_OF\(\)/void/gs;
  886. s/LHASH_OF\(\)/void/gs;
  887. print STDERR "DEBUG: \$_ = \"$_\"\n" if $debug;
  888. if (/^\#INFO:([^:]*):(.*)$/) {
  889. $plats = $1;
  890. $algs = $2;
  891. print STDERR "DEBUG: found info on platforms ($plats) and algorithms ($algs)\n" if $debug;
  892. next;
  893. } elsif (/^\s*OPENSSL_EXTERN\s.*?(\w+(\{[0-9]+\})?)(\[[0-9]*\])*\s*$/) {
  894. $s = $1;
  895. $k = "VARIABLE";
  896. print STDERR "DEBUG: found external variable $s\n" if $debug;
  897. } elsif (/TYPEDEF_\w+_OF/s) {
  898. next;
  899. } elsif (/(\w+)\s*\(\).*/s) { # first token prior [first] () is
  900. $s = $1; # a function name!
  901. print STDERR "DEBUG: found function $s\n" if $debug;
  902. } elsif (/\(/ and not (/=/)) {
  903. print STDERR "File $file: cannot parse: $_;\n";
  904. next;
  905. } else {
  906. next;
  907. }
  908. $syms{$s} = 1;
  909. $kind{$s} = $k;
  910. $p = $plats;
  911. $a = $algs;
  912. $a .= ",BF" if($s =~ /EVP_bf/);
  913. $a .= ",CAST" if($s =~ /EVP_cast/);
  914. $a .= ",DES" if($s =~ /EVP_des/);
  915. $a .= ",DSA" if($s =~ /EVP_dss/);
  916. $a .= ",IDEA" if($s =~ /EVP_idea/);
  917. $a .= ",MD2" if($s =~ /EVP_md2/);
  918. $a .= ",MD4" if($s =~ /EVP_md4/);
  919. $a .= ",MD5" if($s =~ /EVP_md5/);
  920. $a .= ",RC2" if($s =~ /EVP_rc2/);
  921. $a .= ",RC4" if($s =~ /EVP_rc4/);
  922. $a .= ",RC5" if($s =~ /EVP_rc5/);
  923. $a .= ",RMD160" if($s =~ /EVP_ripemd/);
  924. $a .= ",RSA" if($s =~ /EVP_(Open|Seal)(Final|Init)/);
  925. $a .= ",RSA" if($s =~ /PEM_Seal(Final|Init|Update)/);
  926. $a .= ",RSA" if($s =~ /RSAPrivateKey/);
  927. $a .= ",RSA" if($s =~ /SSLv23?_((client|server)_)?method/);
  928. $platform{$s} =
  929. &reduce_platforms((defined($platform{$s})?$platform{$s}.',':"").$p);
  930. $algorithm{$s} .= ','.$a;
  931. if (defined($variant{$s})) {
  932. foreach $v (split /;/,$variant{$s}) {
  933. (my $r, my $p, my $k) = split(/:/,$v);
  934. my $ip = join ',',map({ /^!(.*)$/ ? $1 : "!".$_ } split /,/, $p);
  935. $syms{$r} = 1;
  936. if (!defined($k)) { $k = $kind{$s}; }
  937. $kind{$r} = $k."(".$s.")";
  938. $algorithm{$r} = $algorithm{$s};
  939. $platform{$r} = &reduce_platforms($platform{$s}.",".$p.",".$p);
  940. $platform{$s} = &reduce_platforms($platform{$s}.','.$ip.','.$ip);
  941. print STDERR "DEBUG: \$variant{\"$s\"} = ",$v,"; \$r = $r; \$p = ",$platform{$r},"; \$a = ",$algorithm{$r},"; \$kind = ",$kind{$r},"\n" if $debug;
  942. }
  943. }
  944. print STDERR "DEBUG: \$s = $s; \$p = ",$platform{$s},"; \$a = ",$algorithm{$s},"; \$kind = ",$kind{$s},"\n" if $debug;
  945. }
  946. }
  947. # Prune the returned symbols
  948. delete $syms{"bn_dump1"};
  949. $platform{"BIO_s_log"} .= ",!WIN32,!macintosh";
  950. $platform{"PEM_read_NS_CERT_SEQ"} = "VMS";
  951. $platform{"PEM_write_NS_CERT_SEQ"} = "VMS";
  952. $platform{"PEM_read_P8_PRIV_KEY_INFO"} = "VMS";
  953. $platform{"PEM_write_P8_PRIV_KEY_INFO"} = "VMS";
  954. $platform{"EVP_sha384"} = "!VMSVAX";
  955. $platform{"EVP_sha512"} = "!VMSVAX";
  956. $platform{"SHA384_Init"} = "!VMSVAX";
  957. $platform{"SHA384_Transform"} = "!VMSVAX";
  958. $platform{"SHA384_Update"} = "!VMSVAX";
  959. $platform{"SHA384_Final"} = "!VMSVAX";
  960. $platform{"SHA384"} = "!VMSVAX";
  961. $platform{"SHA512_Init"} = "!VMSVAX";
  962. $platform{"SHA512_Transform"} = "!VMSVAX";
  963. $platform{"SHA512_Update"} = "!VMSVAX";
  964. $platform{"SHA512_Final"} = "!VMSVAX";
  965. $platform{"SHA512"} = "!VMSVAX";
  966. # Info we know about
  967. push @ret, map { $_."\\".&info_string($_,"EXIST",
  968. $platform{$_},
  969. $kind{$_},
  970. $algorithm{$_}) } keys %syms;
  971. if (keys %unknown_algorithms) {
  972. print STDERR "WARNING: mkdef.pl doesn't know the following algorithms:\n";
  973. print STDERR "\t",join("\n\t",keys %unknown_algorithms),"\n";
  974. }
  975. return(@ret);
  976. }
  977. # Param: string of comma-separated platform-specs.
  978. sub reduce_platforms
  979. {
  980. my ($platforms) = @_;
  981. my $pl = defined($platforms) ? $platforms : "";
  982. my %p = map { $_ => 0 } split /,/, $pl;
  983. my $ret;
  984. print STDERR "DEBUG: Entered reduce_platforms with \"$platforms\"\n"
  985. if $debug;
  986. # We do this, because if there's code like the following, it really
  987. # means the function exists in all cases and should therefore be
  988. # everywhere. By increasing and decreasing, we may attain 0:
  989. #
  990. # ifndef WIN16
  991. # int foo();
  992. # else
  993. # int _fat foo();
  994. # endif
  995. foreach $platform (split /,/, $pl) {
  996. if ($platform =~ /^!(.*)$/) {
  997. $p{$1}--;
  998. } else {
  999. $p{$platform}++;
  1000. }
  1001. }
  1002. foreach $platform (keys %p) {
  1003. if ($p{$platform} == 0) { delete $p{$platform}; }
  1004. }
  1005. delete $p{""};
  1006. $ret = join(',',sort(map { $p{$_} < 0 ? "!".$_ : $_ } keys %p));
  1007. print STDERR "DEBUG: Exiting reduce_platforms with \"$ret\"\n"
  1008. if $debug;
  1009. return $ret;
  1010. }
  1011. sub info_string {
  1012. (my $symbol, my $exist, my $platforms, my $kind, my $algorithms) = @_;
  1013. my %a = defined($algorithms) ?
  1014. map { $_ => 1 } split /,/, $algorithms : ();
  1015. my $k = defined($kind) ? $kind : "FUNCTION";
  1016. my $ret;
  1017. my $p = &reduce_platforms($platforms);
  1018. delete $a{""};
  1019. $ret = $exist;
  1020. $ret .= ":".$p;
  1021. $ret .= ":".$k;
  1022. $ret .= ":".join(',',sort keys %a);
  1023. return $ret;
  1024. }
  1025. sub maybe_add_info {
  1026. (my $name, *nums, my @symbols) = @_;
  1027. my $sym;
  1028. my $new_info = 0;
  1029. my %syms=();
  1030. print STDERR "Updating $name info\n";
  1031. foreach $sym (@symbols) {
  1032. (my $s, my $i) = split /\\/, $sym;
  1033. if (defined($nums{$s})) {
  1034. $i =~ s/^(.*?:.*?:\w+)(\(\w+\))?/$1/;
  1035. (my $n, my $vers, my $dummy) = split /\\/, $nums{$s};
  1036. if (!defined($dummy) || $i ne $dummy) {
  1037. $nums{$s} = $n."\\".$vers."\\".$i;
  1038. $new_info++;
  1039. print STDERR "DEBUG: maybe_add_info for $s: \"$dummy\" => \"$i\"\n" if $debug;
  1040. }
  1041. }
  1042. $syms{$s} = 1;
  1043. }
  1044. my @s=sort { &parse_number($nums{$a},"n") <=> &parse_number($nums{$b},"n") } keys %nums;
  1045. foreach $sym (@s) {
  1046. (my $n, my $vers, my $i) = split /\\/, $nums{$sym};
  1047. if (!defined($syms{$sym}) && $i !~ /^NOEXIST:/) {
  1048. $new_info++;
  1049. print STDERR "DEBUG: maybe_add_info for $sym: -> undefined\n" if $debug;
  1050. }
  1051. }
  1052. if ($new_info) {
  1053. print STDERR "$new_info old symbols got an info update\n";
  1054. if (!$do_rewrite) {
  1055. print STDERR "You should do a rewrite to fix this.\n";
  1056. }
  1057. } else {
  1058. print STDERR "No old symbols needed info update\n";
  1059. }
  1060. }
  1061. # Param: string of comma-separated keywords, each possibly prefixed with a "!"
  1062. sub is_valid
  1063. {
  1064. my ($keywords_txt,$platforms) = @_;
  1065. my (@keywords) = split /,/,$keywords_txt;
  1066. my ($falsesum, $truesum) = (0, 1);
  1067. # Param: one keyword
  1068. sub recognise
  1069. {
  1070. my ($keyword,$platforms) = @_;
  1071. if ($platforms) {
  1072. # platforms
  1073. if ($keyword eq "VMSVAX" && $VMSVAX) { return 1; }
  1074. if ($keyword eq "VMSNonVAX" && $VMSNonVAX) { return 1; }
  1075. if ($keyword eq "VMS" && $VMS) { return 1; }
  1076. if ($keyword eq "WIN32" && $W32) { return 1; }
  1077. if ($keyword eq "WINNT" && $NT) { return 1; }
  1078. if ($keyword eq "OS2" && $OS2) { return 1; }
  1079. # Special platforms:
  1080. # EXPORT_VAR_AS_FUNCTION means that global variables
  1081. # will be represented as functions. This currently
  1082. # only happens on VMS-VAX.
  1083. if ($keyword eq "EXPORT_VAR_AS_FUNCTION" && ($VMSVAX || $W32)) {
  1084. return 1;
  1085. }
  1086. if ($keyword eq "ZLIB" && $zlib) { return 1; }
  1087. return 0;
  1088. } else {
  1089. # algorithms
  1090. if ($keyword eq "RC2" && $no_rc2) { return 0; }
  1091. if ($keyword eq "RC4" && $no_rc4) { return 0; }
  1092. if ($keyword eq "RC5" && $no_rc5) { return 0; }
  1093. if ($keyword eq "IDEA" && $no_idea) { return 0; }
  1094. if ($keyword eq "DES" && $no_des) { return 0; }
  1095. if ($keyword eq "BF" && $no_bf) { return 0; }
  1096. if ($keyword eq "CAST" && $no_cast) { return 0; }
  1097. if ($keyword eq "MD2" && $no_md2) { return 0; }
  1098. if ($keyword eq "MD4" && $no_md4) { return 0; }
  1099. if ($keyword eq "MD5" && $no_md5) { return 0; }
  1100. if ($keyword eq "SHA" && $no_sha) { return 0; }
  1101. if ($keyword eq "RMD160" && $no_ripemd) { return 0; }
  1102. if ($keyword eq "MDC2" && $no_mdc2) { return 0; }
  1103. if ($keyword eq "WHIRLPOOL" && $no_whirlpool) { return 0; }
  1104. if ($keyword eq "RSA" && $no_rsa) { return 0; }
  1105. if ($keyword eq "DSA" && $no_dsa) { return 0; }
  1106. if ($keyword eq "DH" && $no_dh) { return 0; }
  1107. if ($keyword eq "EC" && $no_ec) { return 0; }
  1108. if ($keyword eq "AES" && $no_aes) { return 0; }
  1109. if ($keyword eq "CAMELLIA" && $no_camellia) { return 0; }
  1110. if ($keyword eq "SEED" && $no_seed) { return 0; }
  1111. if ($keyword eq "SCRYPT" && $no_scrypt) { return 0; }
  1112. if ($keyword eq "CHACHA" && $no_chacha) { return 0; }
  1113. if ($keyword eq "POLY1305" && $no_poly1305) { return 0; }
  1114. if ($keyword eq "EVP" && $no_evp) { return 0; }
  1115. if ($keyword eq "LHASH" && $no_lhash) { return 0; }
  1116. if ($keyword eq "STACK" && $no_stack) { return 0; }
  1117. if ($keyword eq "ERR" && $no_err) { return 0; }
  1118. if ($keyword eq "BUFFER" && $no_buffer) { return 0; }
  1119. if ($keyword eq "BIO" && $no_bio) { return 0; }
  1120. if ($keyword eq "COMP" && $no_comp) { return 0; }
  1121. if ($keyword eq "DSO" && $no_dso) { return 0; }
  1122. if ($keyword eq "ENGINE" && $no_engine) { return 0; }
  1123. if ($keyword eq "HW" && $no_hw) { return 0; }
  1124. if ($keyword eq "FP_API" && $no_fp_api) { return 0; }
  1125. if ($keyword eq "STATIC_ENGINE" && $no_static_engine) { return 0; }
  1126. if ($keyword eq "SCT" && $no_sct) { return 0; }
  1127. if ($keyword eq "RFC3779" && $no_rfc3779) { return 0; }
  1128. if ($keyword eq "PSK" && $no_psk) { return 0; }
  1129. if ($keyword eq "CMS" && $no_cms) { return 0; }
  1130. if ($keyword eq "EC_NISTP_64_GCC_128" && $no_nistp_gcc)
  1131. { return 0; }
  1132. if ($keyword eq "EC2M" && $no_ec2m) { return 0; }
  1133. if ($keyword eq "NEXTPROTONEG" && $no_nextprotoneg) { return 0; }
  1134. if ($keyword eq "SSL3_METHOD" && $no_ssl3_method) { return 0; }
  1135. if ($keyword eq "SSL_TRACE" && $no_ssl_trace) { return 0; }
  1136. if ($keyword eq "CAPIENG" && $no_capieng) { return 0; }
  1137. if ($keyword eq "JPAKE" && $no_jpake) { return 0; }
  1138. if ($keyword eq "SRP" && $no_srp) { return 0; }
  1139. if ($keyword eq "SCTP" && $no_sctp) { return 0; }
  1140. if ($keyword eq "SRTP" && $no_srtp) { return 0; }
  1141. if ($keyword eq "UNIT_TEST" && $no_unit_test) { return 0; }
  1142. if ($keyword eq "DEPRECATED" && $no_deprecated) { return 0; }
  1143. if ($keyword eq "OCB" && $no_ocb) { return 0; }
  1144. # Nothing recognise as true
  1145. return 1;
  1146. }
  1147. }
  1148. foreach $k (@keywords) {
  1149. if ($k =~ /^!(.*)$/) {
  1150. $falsesum += &recognise($1,$platforms);
  1151. } else {
  1152. $truesum *= &recognise($k,$platforms);
  1153. }
  1154. }
  1155. print STDERR "DEBUG: [",$#keywords,",",$#keywords < 0,"] is_valid($keywords_txt) => (\!$falsesum) && $truesum = ",(!$falsesum) && $truesum,"\n" if $debug;
  1156. return (!$falsesum) && $truesum;
  1157. }
  1158. sub print_test_file
  1159. {
  1160. (*OUT,my $name,*nums,my $testall,my @symbols)=@_;
  1161. my $n = 1; my @e; my @r;
  1162. my $sym; my $prev = ""; my $prefSSLeay;
  1163. (@e)=grep(/^SSLeay(\{[0-9]+\})?\\.*?:.*?:.*/,@symbols);
  1164. (@r)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:.*/ && !/^SSLeay(\{[0-9]+\})?\\.*?:.*?:.*/,@symbols);
  1165. @symbols=((sort @e),(sort @r));
  1166. foreach $sym (@symbols) {
  1167. (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
  1168. my $v = 0;
  1169. $v = 1 if $i=~ /^.*?:.*?:VARIABLE/;
  1170. my $p = ($i =~ /^[^:]*:([^:]*):/,$1);
  1171. my $a = ($i =~ /^[^:]*:[^:]*:[^:]*:([^:]*)/,$1);
  1172. if (!defined($nums{$s})) {
  1173. print STDERR "Warning: $s does not have a number assigned\n"
  1174. if(!$do_update);
  1175. } elsif (is_valid($p,1) && is_valid($a,0)) {
  1176. my $s2 = ($s =~ /^(.*?)(\{[0-9]+\})?$/, $1);
  1177. if ($prev eq $s2) {
  1178. print OUT "\t/* The following has already appeared previously */\n";
  1179. print STDERR "Warning: Symbol '",$s2,"' redefined. old=",($nums{$prev} =~ /^(.*?)\\/,$1),", new=",($nums{$s2} =~ /^(.*?)\\/,$1),"\n";
  1180. }
  1181. $prev = $s2; # To warn about duplicates...
  1182. (my $nn, my $vers, my $ni) = split /\\/, $nums{$s2};
  1183. if ($v) {
  1184. print OUT "\textern int $s2; /* type unknown */ /* $nn $ni */\n";
  1185. } else {
  1186. print OUT "\textern int $s2(); /* type unknown */ /* $nn $ni */\n";
  1187. }
  1188. }
  1189. }
  1190. }
  1191. sub get_version {
  1192. local *MF;
  1193. my $v = '?';
  1194. open MF, 'Makefile' or return $v;
  1195. while (<MF>) {
  1196. $v = $1, last if /^VERSION=(.*?)\s*$/;
  1197. }
  1198. close MF;
  1199. return $v;
  1200. }
  1201. sub print_def_file
  1202. {
  1203. (*OUT,my $name,*nums,my @symbols)=@_;
  1204. my $n = 1; my @e; my @r; my @v; my $prev="";
  1205. my $liboptions="";
  1206. my $libname = $name;
  1207. my $http_vendor = 'www.openssl.org/';
  1208. my $version = get_version();
  1209. my $what = "OpenSSL: implementation of Secure Socket Layer";
  1210. my $description = "$what $version, $name - http://$http_vendor";
  1211. my $prevsymversion = "", $prevprevsymversion = "";
  1212. if (!$linux)
  1213. {
  1214. if ($W32)
  1215. { $libname.="32"; }
  1216. elsif ($OS2)
  1217. { # DLL names should not clash on the whole system.
  1218. # However, they should not have any particular relationship
  1219. # to the name of the static library. Chose descriptive names
  1220. # (must be at most 8 chars).
  1221. my %translate = (ssl => 'open_ssl', crypto => 'cryptssl');
  1222. $libname = $translate{$name} || $name;
  1223. $liboptions = <<EOO;
  1224. INITINSTANCE
  1225. DATA MULTIPLE NONSHARED
  1226. EOO
  1227. # Vendor field can't contain colon, drat; so we omit http://
  1228. $description = "\@#$http_vendor:$version#\@$what; DLL for library $name. Build for EMX -Zmtd";
  1229. }
  1230. print OUT <<"EOF";
  1231. ;
  1232. ; Definition file for the DLL version of the $name library from OpenSSL
  1233. ;
  1234. LIBRARY $libname $liboptions
  1235. EOF
  1236. print "EXPORTS\n";
  1237. }
  1238. (@r)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:FUNCTION/,@symbols);
  1239. (@v)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:VARIABLE/,@symbols);
  1240. @symbols=((sort @e),(sort @r), (sort @v));
  1241. my ($baseversion, $currversion) = get_openssl_version();
  1242. my $thisversion;
  1243. do {
  1244. if (!defined($thisversion)) {
  1245. $thisversion = $baseversion;
  1246. } else {
  1247. $thisversion = get_next_version($thisversion);
  1248. }
  1249. foreach $sym (@symbols) {
  1250. (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
  1251. my $v = 0;
  1252. $v = 1 if $i =~ /^.*?:.*?:VARIABLE/;
  1253. if (!defined($nums{$s})) {
  1254. die "Error: $s does not have a number assigned\n"
  1255. if(!$do_update);
  1256. } else {
  1257. (my $n, my $symversion, my $dummy) = split /\\/, $nums{$s};
  1258. next if $symversion ne $thisversion;
  1259. my %pf = ();
  1260. my $p = ($i =~ /^[^:]*:([^:]*):/,$1);
  1261. my $a = ($i =~ /^[^:]*:[^:]*:[^:]*:([^:]*)/,$1);
  1262. if (is_valid($p,1) && is_valid($a,0)) {
  1263. my $s2 = ($s =~ /^(.*?)(\{[0-9]+\})?$/, $1);
  1264. if ($prev eq $s2) {
  1265. print STDERR "Warning: Symbol '",$s2,
  1266. "' redefined. old=",($nums{$prev} =~ /^(.*?)\\/,$1),
  1267. ", new=",($nums{$s2} =~ /^(.*?)\\/,$1),"\n";
  1268. }
  1269. $prev = $s2; # To warn about duplicates...
  1270. if($linux) {
  1271. if ($symversion ne $prevsymversion) {
  1272. if ($prevsymversion ne "") {
  1273. if ($prevprevsymversion ne "") {
  1274. print OUT "} OPENSSL_"
  1275. ."$prevprevsymversion;\n\n";
  1276. } else {
  1277. print OUT "};\n\n";
  1278. }
  1279. }
  1280. print OUT "OPENSSL_$symversion {\n global:\n";
  1281. $prevprevsymversion = $prevsymversion;
  1282. $prevsymversion = $symversion;
  1283. }
  1284. print OUT " $s2;\n";
  1285. } elsif($v && !$OS2) {
  1286. printf OUT " %s%-39s @%-8d DATA\n",
  1287. ($W32)?"":"_",$s2,$n;
  1288. } else {
  1289. printf OUT " %s%-39s @%d\n",
  1290. ($W32||$OS2)?"":"_",$s2,$n;
  1291. }
  1292. }
  1293. }
  1294. }
  1295. } while ($thisversion ne $currversion);
  1296. if ($linux) {
  1297. if ($prevprevsymversion ne "") {
  1298. print OUT " local: *;\n} OPENSSL_$prevprevsymversion;\n\n";
  1299. } else {
  1300. print OUT " local: *;\n};\n\n";
  1301. }
  1302. }
  1303. printf OUT "\n";
  1304. }
  1305. sub load_numbers
  1306. {
  1307. my($name)=@_;
  1308. my(@a,%ret);
  1309. my $prevversion;
  1310. $max_num = 0;
  1311. $num_noinfo = 0;
  1312. $prev = "";
  1313. $prev_cnt = 0;
  1314. my ($baseversion, $currversion) = get_openssl_version();
  1315. open(IN,"<$name") || die "unable to open $name:$!\n";
  1316. while (<IN>) {
  1317. chop;
  1318. s/#.*$//;
  1319. next if /^\s*$/;
  1320. @a=split;
  1321. if (defined $ret{$a[0]}) {
  1322. # This is actually perfectly OK
  1323. #print STDERR "Warning: Symbol '",$a[0],"' redefined. old=",$ret{$a[0]},", new=",$a[1],"\n";
  1324. }
  1325. if ($max_num > $a[1]) {
  1326. print STDERR "Warning: Number decreased from ",$max_num," to ",$a[1],"\n";
  1327. }
  1328. elsif ($max_num == $a[1]) {
  1329. # This is actually perfectly OK
  1330. #print STDERR "Warning: Symbol ",$a[0]," has same number as previous ",$prev,": ",$a[1],"\n";
  1331. if ($a[0] eq $prev) {
  1332. $prev_cnt++;
  1333. $a[0] .= "{$prev_cnt}";
  1334. }
  1335. }
  1336. else {
  1337. $prev_cnt = 0;
  1338. }
  1339. if ($#a < 2) {
  1340. # Existence will be proven later, in do_defs
  1341. $ret{$a[0]}=$a[1];
  1342. $num_noinfo++;
  1343. } else {
  1344. #Sanity check the version number
  1345. if (defined $prevversion) {
  1346. check_version_lte($prevversion, $a[2]);
  1347. }
  1348. check_version_lte($a[2], $currversion);
  1349. $prevversion = $a[2];
  1350. $ret{$a[0]}=$a[1]."\\".$a[2]."\\".$a[3]; # \\ is a special marker
  1351. }
  1352. $max_num = $a[1] if $a[1] > $max_num;
  1353. $prev=$a[0];
  1354. }
  1355. if ($num_noinfo) {
  1356. print STDERR "Warning: $num_noinfo symbols were without info.";
  1357. if ($do_rewrite) {
  1358. printf STDERR " The rewrite will fix this.\n";
  1359. } else {
  1360. printf STDERR " You should do a rewrite to fix this.\n";
  1361. }
  1362. }
  1363. close(IN);
  1364. return(%ret);
  1365. }
  1366. sub parse_number
  1367. {
  1368. (my $str, my $what) = @_;
  1369. (my $n, my $v, my $i) = split(/\\/,$str);
  1370. if ($what eq "n") {
  1371. return $n;
  1372. } else {
  1373. return $i;
  1374. }
  1375. }
  1376. sub rewrite_numbers
  1377. {
  1378. (*OUT,$name,*nums,@symbols)=@_;
  1379. my $thing;
  1380. print STDERR "Rewriting $name\n";
  1381. my @r = grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:\w+\(\w+\)/,@symbols);
  1382. my $r; my %r; my %rsyms;
  1383. foreach $r (@r) {
  1384. (my $s, my $i) = split /\\/, $r;
  1385. my $a = $1 if $i =~ /^.*?:.*?:\w+\((\w+)\)/;
  1386. $i =~ s/^(.*?:.*?:\w+)\(\w+\)/$1/;
  1387. $r{$a} = $s."\\".$i;
  1388. $rsyms{$s} = 1;
  1389. }
  1390. my %syms = ();
  1391. foreach $_ (@symbols) {
  1392. (my $n, my $i) = split /\\/;
  1393. $syms{$n} = 1;
  1394. }
  1395. my @s=sort {
  1396. &parse_number($nums{$a},"n") <=> &parse_number($nums{$b},"n")
  1397. || $a cmp $b
  1398. } keys %nums;
  1399. foreach $sym (@s) {
  1400. (my $n, my $vers, my $i) = split /\\/, $nums{$sym};
  1401. next if defined($i) && $i =~ /^.*?:.*?:\w+\(\w+\)/;
  1402. next if defined($rsyms{$sym});
  1403. print STDERR "DEBUG: rewrite_numbers for sym = ",$sym,": i = ",$i,", n = ",$n,", rsym{sym} = ",$rsyms{$sym},"syms{sym} = ",$syms{$sym},"\n" if $debug;
  1404. $i="NOEXIST::FUNCTION:"
  1405. if !defined($i) || $i eq "" || !defined($syms{$sym});
  1406. my $s2 = $sym;
  1407. $s2 =~ s/\{[0-9]+\}$//;
  1408. printf OUT "%s%-39s %d\t%s\t%s\n","",$s2,$n,$vers,$i;
  1409. if (exists $r{$sym}) {
  1410. (my $s, $i) = split /\\/,$r{$sym};
  1411. my $s2 = $s;
  1412. $s2 =~ s/\{[0-9]+\}$//;
  1413. printf OUT "%s%-39s %d\t%s\t%s\n","",$s2,$n,$vers,$i;
  1414. }
  1415. }
  1416. }
  1417. sub update_numbers
  1418. {
  1419. (*OUT,$name,*nums,my $start_num, my @symbols)=@_;
  1420. my $new_syms = 0;
  1421. my $basevers;
  1422. my $vers;
  1423. ($basevers, $vers) = get_openssl_version();
  1424. print STDERR "Updating $name numbers\n";
  1425. my @r = grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:\w+\(\w+\)/,@symbols);
  1426. my $r; my %r; my %rsyms;
  1427. foreach $r (@r) {
  1428. (my $s, my $i) = split /\\/, $r;
  1429. my $a = $1 if $i =~ /^.*?:.*?:\w+\((\w+)\)/;
  1430. $i =~ s/^(.*?:.*?:\w+)\(\w+\)/$1/;
  1431. $r{$a} = $s."\\".$i;
  1432. $rsyms{$s} = 1;
  1433. }
  1434. foreach $sym (@symbols) {
  1435. (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
  1436. next if $i =~ /^.*?:.*?:\w+\(\w+\)/;
  1437. next if defined($rsyms{$sym});
  1438. die "ERROR: Symbol $sym had no info attached to it."
  1439. if $i eq "";
  1440. if (!exists $nums{$s}) {
  1441. $new_syms++;
  1442. my $s2 = $s;
  1443. $s2 =~ s/\{[0-9]+\}$//;
  1444. printf OUT "%s%-39s %d\t%s\t%s\n","",$s2, ++$start_num,$vers,$i;
  1445. if (exists $r{$s}) {
  1446. ($s, $i) = split /\\/,$r{$s};
  1447. $s =~ s/\{[0-9]+\}$//;
  1448. printf OUT "%s%-39s %d\t%s\t%s\n","",$s, $start_num,$vers,$i;
  1449. }
  1450. }
  1451. }
  1452. if($new_syms) {
  1453. print STDERR "$new_syms New symbols added\n";
  1454. } else {
  1455. print STDERR "No New symbols Added\n";
  1456. }
  1457. }
  1458. sub check_existing
  1459. {
  1460. (*nums, my @symbols)=@_;
  1461. my %existing; my @remaining;
  1462. @remaining=();
  1463. foreach $sym (@symbols) {
  1464. (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
  1465. $existing{$s}=1;
  1466. }
  1467. foreach $sym (keys %nums) {
  1468. if (!exists $existing{$sym}) {
  1469. push @remaining, $sym;
  1470. }
  1471. }
  1472. if(@remaining) {
  1473. print STDERR "The following symbols do not seem to exist:\n";
  1474. foreach $sym (@remaining) {
  1475. print STDERR "\t",$sym,"\n";
  1476. }
  1477. }
  1478. }
  1479. sub count_parens
  1480. {
  1481. my $line = shift(@_);
  1482. my $open = $line =~ tr/\(//;
  1483. my $close = $line =~ tr/\)//;
  1484. return $open - $close;
  1485. }
  1486. #Parse opensslv.h to get the current version number. Also work out the base
  1487. #version, i.e. the lowest version number that is binary compatible with this
  1488. #version
  1489. sub get_openssl_version()
  1490. {
  1491. open (IN, "include/openssl/opensslv.h") || die "Can't open opensslv.h";
  1492. while(<IN>) {
  1493. if (/OPENSSL_VERSION_TEXT\s+"OpenSSL (\d\.\d\.)(\d[a-z]*)(-| )/) {
  1494. my $suffix = $2;
  1495. my $baseversion = $1 =~ s/\./_/gr;
  1496. close IN;
  1497. return ($baseversion."0", $baseversion.$suffix);
  1498. }
  1499. }
  1500. die "Can't find OpenSSL version number\n";
  1501. }
  1502. #Given an OpenSSL version number, calculate the next version number. If the
  1503. #version number gets to a.b.czz then we go to a.b.(c+1)
  1504. sub get_next_version()
  1505. {
  1506. my $thisversion = shift;
  1507. my ($base, $letter) = $thisversion =~ /^(\d_\d_\d)([a-z]{0,2})$/;
  1508. if ($letter eq "zz") {
  1509. my $lastnum = substr($base, -1);
  1510. return substr($base, 0, length($base)-1).(++$lastnum);
  1511. }
  1512. return $base.get_next_letter($letter);
  1513. }
  1514. #Given the letters off the end of an OpenSSL version string, calculate what
  1515. #the letters for the next release would be.
  1516. sub get_next_letter()
  1517. {
  1518. my $thisletter = shift;
  1519. my $baseletter = "";
  1520. my $endletter;
  1521. if ($thisletter eq "") {
  1522. return "a";
  1523. }
  1524. if ((length $thisletter) > 1) {
  1525. ($baseletter, $endletter) = $thisletter =~ /([a-z]+)([a-z])/;
  1526. } else {
  1527. $endletter = $thisletter;
  1528. }
  1529. if ($endletter eq "z") {
  1530. return $thisletter."a";
  1531. } else {
  1532. return $baseletter.(++$endletter);
  1533. }
  1534. }
  1535. #Check if a version is less than or equal to the current version. Its a fatal
  1536. #error if not. They must also only differ in letters, or the last number (i.e.
  1537. #the first two numbers must be the same)
  1538. sub check_version_lte()
  1539. {
  1540. my ($testversion, $currversion) = @_;
  1541. my $lentv;
  1542. my $lencv;
  1543. my $cvbase;
  1544. my ($cvnums) = $currversion =~ /^(\d_\d_\d)[a-z]*$/;
  1545. my ($tvnums) = $testversion =~ /^(\d_\d_\d)[a-z]*$/;
  1546. #Die if we can't parse the version numbers or they don't look sane
  1547. die "Invalid version number: $testversion and $currversion\n"
  1548. if (!defined($cvnums) || !defined($tvnums)
  1549. || length($cvnums) != 5
  1550. || length($tvnums) != 5);
  1551. #If the base versions (without letters) don't match check they only differ
  1552. #in the last number
  1553. if ($cvnums ne $tvnums) {
  1554. die "Invalid version number: $testversion "
  1555. ."for current version $currversion\n"
  1556. if (substr($cvnums, -1) < substr($tvnums, -1)
  1557. || substr($cvnums, 0, 4) ne substr($tvnums, 0, 4));
  1558. return;
  1559. }
  1560. #If we get here then the base version (i.e. the numbers) are the same - they
  1561. #only differ in the letters
  1562. $lentv = length $testversion;
  1563. $lencv = length $currversion;
  1564. #If the testversion has more letters than the current version then it must
  1565. #be later (or malformed)
  1566. if ($lentv > $lencv) {
  1567. die "Invalid version number: $testversion "
  1568. ."is greater than $currversion\n";
  1569. }
  1570. #Get the last letter from the current version
  1571. my ($cvletter) = $currversion =~ /([a-z])$/;
  1572. if (defined $cvletter) {
  1573. ($cvbase) = $currversion =~ /(\d_\d_\d[a-z]*)$cvletter$/;
  1574. } else {
  1575. $cvbase = $currversion;
  1576. }
  1577. die "Unable to parse version number $currversion" if (!defined $cvbase);
  1578. my $tvbase;
  1579. my ($tvletter) = $testversion =~ /([a-z])$/;
  1580. if (defined $tvletter) {
  1581. ($tvbase) = $testversion =~ /(\d_\d_\d[a-z]*)$tvletter$/;
  1582. } else {
  1583. $tvbase = $testversion;
  1584. }
  1585. die "Unable to parse version number $testversion" if (!defined $tvbase);
  1586. if ($lencv > $lentv) {
  1587. #If current version has more letters than testversion then testversion
  1588. #minus the final letter must be a substring of the current version
  1589. die "Invalid version number $testversion "
  1590. ."is greater than $currversion or is invalid\n"
  1591. if (index($cvbase, $tvbase) != 0);
  1592. } else {
  1593. #If both versions have the same number of letters then they must be
  1594. #equal up to the last letter, and the last letter in testversion must
  1595. #be less than or equal to the last letter in current version.
  1596. die "Invalid version number $testversion "
  1597. ."is greater than $currversion\n"
  1598. if (($cvbase ne $tvbase) && ($tvletter gt $cvletter));
  1599. }
  1600. }