cryptlib.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. /* crypto/cryptlib.c */
  2. /* ====================================================================
  3. * Copyright (c) 1998-2003 The OpenSSL Project. All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in
  14. * the documentation and/or other materials provided with the
  15. * distribution.
  16. *
  17. * 3. All advertising materials mentioning features or use of this
  18. * software must display the following acknowledgment:
  19. * "This product includes software developed by the OpenSSL Project
  20. * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
  21. *
  22. * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
  23. * endorse or promote products derived from this software without
  24. * prior written permission. For written permission, please contact
  25. * openssl-core@openssl.org.
  26. *
  27. * 5. Products derived from this software may not be called "OpenSSL"
  28. * nor may "OpenSSL" appear in their names without prior written
  29. * permission of the OpenSSL Project.
  30. *
  31. * 6. Redistributions of any form whatsoever must retain the following
  32. * acknowledgment:
  33. * "This product includes software developed by the OpenSSL Project
  34. * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
  35. *
  36. * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
  37. * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  38. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  39. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
  40. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  42. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  43. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  44. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  45. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  46. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  47. * OF THE POSSIBILITY OF SUCH DAMAGE.
  48. * ====================================================================
  49. *
  50. * This product includes cryptographic software written by Eric Young
  51. * (eay@cryptsoft.com). This product includes software written by Tim
  52. * Hudson (tjh@cryptsoft.com).
  53. *
  54. */
  55. /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  56. * All rights reserved.
  57. *
  58. * This package is an SSL implementation written
  59. * by Eric Young (eay@cryptsoft.com).
  60. * The implementation was written so as to conform with Netscapes SSL.
  61. *
  62. * This library is free for commercial and non-commercial use as long as
  63. * the following conditions are aheared to. The following conditions
  64. * apply to all code found in this distribution, be it the RC4, RSA,
  65. * lhash, DES, etc., code; not just the SSL code. The SSL documentation
  66. * included with this distribution is covered by the same copyright terms
  67. * except that the holder is Tim Hudson (tjh@cryptsoft.com).
  68. *
  69. * Copyright remains Eric Young's, and as such any Copyright notices in
  70. * the code are not to be removed.
  71. * If this package is used in a product, Eric Young should be given attribution
  72. * as the author of the parts of the library used.
  73. * This can be in the form of a textual message at program startup or
  74. * in documentation (online or textual) provided with the package.
  75. *
  76. * Redistribution and use in source and binary forms, with or without
  77. * modification, are permitted provided that the following conditions
  78. * are met:
  79. * 1. Redistributions of source code must retain the copyright
  80. * notice, this list of conditions and the following disclaimer.
  81. * 2. Redistributions in binary form must reproduce the above copyright
  82. * notice, this list of conditions and the following disclaimer in the
  83. * documentation and/or other materials provided with the distribution.
  84. * 3. All advertising materials mentioning features or use of this software
  85. * must display the following acknowledgement:
  86. * "This product includes cryptographic software written by
  87. * Eric Young (eay@cryptsoft.com)"
  88. * The word 'cryptographic' can be left out if the rouines from the library
  89. * being used are not cryptographic related :-).
  90. * 4. If you include any Windows specific code (or a derivative thereof) from
  91. * the apps directory (application code) you must include an acknowledgement:
  92. * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
  93. *
  94. * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
  95. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  96. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  97. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  98. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  99. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  100. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  101. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  102. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  103. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  104. * SUCH DAMAGE.
  105. *
  106. * The licence and distribution terms for any publically available version or
  107. * derivative of this code cannot be changed. i.e. this code cannot simply be
  108. * copied and put under another distribution licence
  109. * [including the GNU Public Licence.]
  110. */
  111. /* ====================================================================
  112. * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
  113. * ECDH support in OpenSSL originally developed by
  114. * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
  115. */
  116. #include "cryptlib.h"
  117. #include <openssl/safestack.h>
  118. #if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN16)
  119. static double SSLeay_MSVC5_hack = 0.0; /* and for VC1.5 */
  120. #endif
  121. static void (MS_FAR *locking_callback) (int mode, int type,
  122. const char *file, int line) = NULL;
  123. static int (MS_FAR *add_lock_callback) (int *pointer, int amount,
  124. int type, const char *file,
  125. int line) = NULL;
  126. static unsigned long (MS_FAR *id_callback) (void) = NULL;
  127. int CRYPTO_num_locks(void)
  128. {
  129. return CRYPTO_NUM_LOCKS;
  130. }
  131. void (*CRYPTO_get_locking_callback(void)) (int mode, int type,
  132. const char *file, int line) {
  133. return (locking_callback);
  134. }
  135. int (*CRYPTO_get_add_lock_callback(void)) (int *num, int mount, int type,
  136. const char *file, int line) {
  137. return (add_lock_callback);
  138. }
  139. void CRYPTO_set_locking_callback(void (*func) (int mode, int type,
  140. const char *file, int line))
  141. {
  142. locking_callback = func;
  143. }
  144. void CRYPTO_set_add_lock_callback(int (*func) (int *num, int mount, int type,
  145. const char *file, int line))
  146. {
  147. add_lock_callback = func;
  148. }
  149. unsigned long (*CRYPTO_get_id_callback(void)) (void) {
  150. return (id_callback);
  151. }
  152. void CRYPTO_set_id_callback(unsigned long (*func) (void))
  153. {
  154. id_callback = func;
  155. }
  156. unsigned long CRYPTO_thread_id(void)
  157. {
  158. unsigned long ret = 0;
  159. if (id_callback == NULL) {
  160. #ifdef OPENSSL_SYS_WIN16
  161. ret = (unsigned long)GetCurrentTask();
  162. #elif defined(OPENSSL_SYS_WIN32)
  163. ret = (unsigned long)GetCurrentThreadId();
  164. #elif defined(GETPID_IS_MEANINGLESS)
  165. ret = 1L;
  166. #else
  167. ret = (unsigned long)getpid();
  168. #endif
  169. } else
  170. ret = id_callback();
  171. return (ret);
  172. }
  173. static void (*do_dynlock_cb) (int mode, int type, const char *file, int line);
  174. void int_CRYPTO_set_do_dynlock_callback(void (*dyn_cb)
  175. (int mode, int type,
  176. const char *file, int line))
  177. {
  178. do_dynlock_cb = dyn_cb;
  179. }
  180. void CRYPTO_lock(int mode, int type, const char *file, int line)
  181. {
  182. #ifdef LOCK_DEBUG
  183. {
  184. char *rw_text, *operation_text;
  185. if (mode & CRYPTO_LOCK)
  186. operation_text = "lock ";
  187. else if (mode & CRYPTO_UNLOCK)
  188. operation_text = "unlock";
  189. else
  190. operation_text = "ERROR ";
  191. if (mode & CRYPTO_READ)
  192. rw_text = "r";
  193. else if (mode & CRYPTO_WRITE)
  194. rw_text = "w";
  195. else
  196. rw_text = "ERROR";
  197. fprintf(stderr, "lock:%08lx:(%s)%s %-18s %s:%d\n",
  198. CRYPTO_thread_id(), rw_text, operation_text,
  199. CRYPTO_get_lock_name(type), file, line);
  200. }
  201. #endif
  202. if (type < 0) {
  203. if (do_dynlock_cb)
  204. do_dynlock_cb(mode, type, file, line);
  205. } else if (locking_callback != NULL)
  206. locking_callback(mode, type, file, line);
  207. }
  208. int CRYPTO_add_lock(int *pointer, int amount, int type, const char *file,
  209. int line)
  210. {
  211. int ret = 0;
  212. if (add_lock_callback != NULL) {
  213. #ifdef LOCK_DEBUG
  214. int before = *pointer;
  215. #endif
  216. ret = add_lock_callback(pointer, amount, type, file, line);
  217. #ifdef LOCK_DEBUG
  218. fprintf(stderr, "ladd:%08lx:%2d+%2d->%2d %-18s %s:%d\n",
  219. CRYPTO_thread_id(),
  220. before, amount, ret, CRYPTO_get_lock_name(type), file, line);
  221. #endif
  222. } else {
  223. CRYPTO_lock(CRYPTO_LOCK | CRYPTO_WRITE, type, file, line);
  224. ret = *pointer + amount;
  225. #ifdef LOCK_DEBUG
  226. fprintf(stderr, "ladd:%08lx:%2d+%2d->%2d %-18s %s:%d\n",
  227. CRYPTO_thread_id(),
  228. *pointer, amount, ret,
  229. CRYPTO_get_lock_name(type), file, line);
  230. #endif
  231. *pointer = ret;
  232. CRYPTO_lock(CRYPTO_UNLOCK | CRYPTO_WRITE, type, file, line);
  233. }
  234. return (ret);
  235. }
  236. #if defined(__i386) || defined(__i386__) || defined(_M_IX86) || \
  237. defined(__INTEL__) || \
  238. defined(__x86_64) || defined(__x86_64__) || \
  239. defined(_M_AMD64) || defined(_M_X64)
  240. unsigned long OPENSSL_ia32cap_P = 0;
  241. unsigned long *OPENSSL_ia32cap_loc(void)
  242. {
  243. return &OPENSSL_ia32cap_P;
  244. }
  245. # if defined(OPENSSL_CPUID_OBJ) && !defined(OPENSSL_NO_ASM) && !defined(I386_ONLY)
  246. # define OPENSSL_CPUID_SETUP
  247. void OPENSSL_cpuid_setup(void)
  248. {
  249. static int trigger = 0;
  250. unsigned long OPENSSL_ia32_cpuid(void);
  251. char *env;
  252. if (trigger)
  253. return;
  254. trigger = 1;
  255. if ((env = getenv("OPENSSL_ia32cap")))
  256. OPENSSL_ia32cap_P = strtoul(env, NULL, 0) | (1 << 10);
  257. else
  258. OPENSSL_ia32cap_P = OPENSSL_ia32_cpuid() | (1 << 10);
  259. /*
  260. * |(1<<10) sets a reserved bit to signal that variable
  261. * was initialized already... This is to avoid interference
  262. * with cpuid snippets in ELF .init segment.
  263. */
  264. }
  265. # endif
  266. #else
  267. unsigned long *OPENSSL_ia32cap_loc(void)
  268. {
  269. return NULL;
  270. }
  271. #endif
  272. int OPENSSL_NONPIC_relocated = 0;
  273. #if !defined(OPENSSL_CPUID_SETUP)
  274. void OPENSSL_cpuid_setup(void)
  275. {
  276. }
  277. #endif
  278. #if (defined(_WIN32) || defined(__CYGWIN__)) && defined(_WINDLL)
  279. # ifdef OPENSSL_FIPS
  280. # include <tlhelp32.h>
  281. # if defined(__GNUC__) && __GNUC__>=2
  282. static int DllInit(void) __attribute__ ((constructor));
  283. # elif defined(_MSC_VER)
  284. static int DllInit(void);
  285. # ifdef _WIN64
  286. # pragma section(".CRT$XCU",read)
  287. __declspec(allocate(".CRT$XCU"))
  288. # else
  289. # pragma data_seg(".CRT$XCU")
  290. # endif
  291. static int (*p) (void) = DllInit;
  292. # pragma data_seg()
  293. # endif
  294. static int DllInit(void)
  295. {
  296. # if defined(_WIN32_WINNT)
  297. union {
  298. int (*f) (void);
  299. BYTE *p;
  300. } t = {
  301. DllInit
  302. };
  303. HANDLE hModuleSnap = INVALID_HANDLE_VALUE;
  304. IMAGE_DOS_HEADER *dos_header;
  305. IMAGE_NT_HEADERS *nt_headers;
  306. MODULEENTRY32 me32 = { sizeof(me32) };
  307. hModuleSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, 0);
  308. if (hModuleSnap != INVALID_HANDLE_VALUE &&
  309. Module32First(hModuleSnap, &me32))
  310. do {
  311. if (t.p >= me32.modBaseAddr &&
  312. t.p < me32.modBaseAddr + me32.modBaseSize) {
  313. dos_header = (IMAGE_DOS_HEADER *) me32.modBaseAddr;
  314. if (dos_header->e_magic == IMAGE_DOS_SIGNATURE) {
  315. nt_headers = (IMAGE_NT_HEADERS *)
  316. ((BYTE *) dos_header + dos_header->e_lfanew);
  317. if (nt_headers->Signature == IMAGE_NT_SIGNATURE &&
  318. me32.modBaseAddr !=
  319. (BYTE *) nt_headers->OptionalHeader.ImageBase)
  320. OPENSSL_NONPIC_relocated = 1;
  321. }
  322. break;
  323. }
  324. } while (Module32Next(hModuleSnap, &me32));
  325. if (hModuleSnap != INVALID_HANDLE_VALUE)
  326. CloseHandle(hModuleSnap);
  327. # endif
  328. OPENSSL_cpuid_setup();
  329. return 0;
  330. }
  331. # else
  332. # ifdef __CYGWIN__
  333. /* pick DLL_[PROCESS|THREAD]_[ATTACH|DETACH] definitions */
  334. # include <windows.h>
  335. # endif
  336. /*
  337. * All we really need to do is remove the 'error' state when a thread
  338. * detaches
  339. */
  340. BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
  341. {
  342. switch (fdwReason) {
  343. case DLL_PROCESS_ATTACH:
  344. OPENSSL_cpuid_setup();
  345. # if defined(_WIN32_WINNT)
  346. {
  347. IMAGE_DOS_HEADER *dos_header = (IMAGE_DOS_HEADER *) hinstDLL;
  348. IMAGE_NT_HEADERS *nt_headers;
  349. if (dos_header->e_magic == IMAGE_DOS_SIGNATURE) {
  350. nt_headers = (IMAGE_NT_HEADERS *) ((char *)dos_header
  351. + dos_header->e_lfanew);
  352. if (nt_headers->Signature == IMAGE_NT_SIGNATURE &&
  353. hinstDLL !=
  354. (HINSTANCE) (nt_headers->OptionalHeader.ImageBase))
  355. OPENSSL_NONPIC_relocated = 1;
  356. }
  357. }
  358. # endif
  359. break;
  360. case DLL_THREAD_ATTACH:
  361. break;
  362. case DLL_THREAD_DETACH:
  363. break;
  364. case DLL_PROCESS_DETACH:
  365. break;
  366. }
  367. return (TRUE);
  368. }
  369. # endif
  370. #endif
  371. #if defined(_WIN32) && !defined(__CYGWIN__)
  372. # include <tchar.h>
  373. # if defined(_WIN32_WINNT) && _WIN32_WINNT>=0x0333
  374. int OPENSSL_isservice(void)
  375. {
  376. HWINSTA h;
  377. DWORD len;
  378. WCHAR *name;
  379. (void)GetDesktopWindow(); /* return value is ignored */
  380. h = GetProcessWindowStation();
  381. if (h == NULL)
  382. return -1;
  383. if (GetUserObjectInformationW(h, UOI_NAME, NULL, 0, &len) ||
  384. GetLastError() != ERROR_INSUFFICIENT_BUFFER)
  385. return -1;
  386. if (len > 512)
  387. return -1; /* paranoia */
  388. len++, len &= ~1; /* paranoia */
  389. # ifdef _MSC_VER
  390. name = (WCHAR *)_alloca(len + sizeof(WCHAR));
  391. # else
  392. name = (WCHAR *)alloca(len + sizeof(WCHAR));
  393. # endif
  394. if (!GetUserObjectInformationW(h, UOI_NAME, name, len, &len))
  395. return -1;
  396. len++, len &= ~1; /* paranoia */
  397. name[len / sizeof(WCHAR)] = L'\0'; /* paranoia */
  398. # if 1
  399. /*
  400. * This doesn't cover "interactive" services [working with real
  401. * WinSta0's] nor programs started non-interactively by Task Scheduler
  402. * [those are working with SAWinSta].
  403. */
  404. if (wcsstr(name, L"Service-0x"))
  405. return 1;
  406. # else
  407. /* This covers all non-interactive programs such as services. */
  408. if (!wcsstr(name, L"WinSta0"))
  409. return 1;
  410. # endif
  411. else
  412. return 0;
  413. }
  414. # else
  415. int OPENSSL_isservice(void)
  416. {
  417. return 0;
  418. }
  419. # endif
  420. void OPENSSL_showfatal(const char *fmta, ...)
  421. {
  422. va_list ap;
  423. TCHAR buf[256];
  424. const TCHAR *fmt;
  425. # ifdef STD_ERROR_HANDLE /* what a dirty trick! */
  426. HANDLE h;
  427. if ((h = GetStdHandle(STD_ERROR_HANDLE)) != NULL &&
  428. GetFileType(h) != FILE_TYPE_UNKNOWN) {
  429. /* must be console application */
  430. va_start(ap, fmta);
  431. vfprintf(stderr, fmta, ap);
  432. va_end(ap);
  433. return;
  434. }
  435. # endif
  436. if (sizeof(TCHAR) == sizeof(char))
  437. fmt = (const TCHAR *)fmta;
  438. else
  439. do {
  440. int keepgoing;
  441. size_t len_0 = strlen(fmta) + 1, i;
  442. WCHAR *fmtw;
  443. # ifdef _MSC_VER
  444. fmtw = (WCHAR *)_alloca(len_0 * sizeof(WCHAR));
  445. # else
  446. fmtw = (WCHAR *)alloca(len_0 * sizeof(WCHAR));
  447. # endif
  448. if (fmtw == NULL) {
  449. fmt = (const TCHAR *)L"no stack?";
  450. break;
  451. }
  452. # ifndef OPENSSL_NO_MULTIBYTE
  453. if (!MultiByteToWideChar(CP_ACP, 0, fmta, len_0, fmtw, len_0))
  454. # endif
  455. for (i = 0; i < len_0; i++)
  456. fmtw[i] = (WCHAR)fmta[i];
  457. for (i = 0; i < len_0; i++) {
  458. if (fmtw[i] == L'%')
  459. do {
  460. keepgoing = 0;
  461. switch (fmtw[i + 1]) {
  462. case L'0':
  463. case L'1':
  464. case L'2':
  465. case L'3':
  466. case L'4':
  467. case L'5':
  468. case L'6':
  469. case L'7':
  470. case L'8':
  471. case L'9':
  472. case L'.':
  473. case L'*':
  474. case L'-':
  475. i++;
  476. keepgoing = 1;
  477. break;
  478. case L's':
  479. fmtw[i + 1] = L'S';
  480. break;
  481. case L'S':
  482. fmtw[i + 1] = L's';
  483. break;
  484. case L'c':
  485. fmtw[i + 1] = L'C';
  486. break;
  487. case L'C':
  488. fmtw[i + 1] = L'c';
  489. break;
  490. }
  491. } while (keepgoing);
  492. }
  493. fmt = (const TCHAR *)fmtw;
  494. } while (0);
  495. va_start(ap, fmta);
  496. _vsntprintf(buf, sizeof(buf) / sizeof(TCHAR) - 1, fmt, ap);
  497. buf[sizeof(buf) / sizeof(TCHAR) - 1] = _T('\0');
  498. va_end(ap);
  499. # if defined(_WIN32_WINNT) && _WIN32_WINNT>=0x0333
  500. /* this -------------v--- guards NT-specific calls */
  501. if (check_winnt() && OPENSSL_isservice() > 0) {
  502. HANDLE h = RegisterEventSource(0, _T("OPENSSL"));
  503. const TCHAR *pmsg = buf;
  504. ReportEvent(h, EVENTLOG_ERROR_TYPE, 0, 0, 0, 1, 0, &pmsg, 0);
  505. DeregisterEventSource(h);
  506. } else
  507. # endif
  508. MessageBox(NULL, buf, _T("OpenSSL: FATAL"), MB_OK | MB_ICONSTOP);
  509. }
  510. #else
  511. void OPENSSL_showfatal(const char *fmta, ...)
  512. {
  513. va_list ap;
  514. va_start(ap, fmta);
  515. vfprintf(stderr, fmta, ap);
  516. va_end(ap);
  517. }
  518. int OPENSSL_isservice(void)
  519. {
  520. return 0;
  521. }
  522. #endif
  523. void OpenSSLDie(const char *file, int line, const char *assertion)
  524. {
  525. OPENSSL_showfatal
  526. ("%s(%d): OpenSSL internal error, assertion failed: %s\n", file, line,
  527. assertion);
  528. abort();
  529. }
  530. void *OPENSSL_stderr(void)
  531. {
  532. return stderr;
  533. }
  534. #ifndef OPENSSL_FIPS
  535. int CRYPTO_memcmp(const void *in_a, const void *in_b, size_t len)
  536. {
  537. size_t i;
  538. const unsigned char *a = in_a;
  539. const unsigned char *b = in_b;
  540. unsigned char x = 0;
  541. for (i = 0; i < len; i++)
  542. x |= a[i] ^ b[i];
  543. return x;
  544. }
  545. #endif