aboutsummaryrefslogtreecommitdiff
path: root/include/openssl/crypto.h
AgeCommit message (Collapse)AuthorFilesLines
2018-04-20Ensure the thread keys are always allocated in the same orderBernd Edlinger1-1/+2
Fixes: #5899 Reviewed-by: Rich Salz <rsalz@openssl.org> Reviewed-by: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/5911)
2018-02-13Update copyright yearMatt Caswell1-1/+1
Reviewed-by: Richard Levitte <levitte@openssl.org>
2018-02-09Remove redundant declarations of ERR_load_*_strings()Nick Mathewson1-1/+0
In commit 52df25cf2e656146cb3b206d8220124f0417d03f, the ERR_load_FOO_strings() functions were moved from their original location in foo.h into new headers called fooerr.h. But they were never removed from their original locations. This duplication causes redundant-declaration warnings on programs that use OpenSSL's headers with such warnings enabled. Reviewed-by: Rich Salz <rsalz@openssl.org> Reviewed-by: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/5150)
2018-01-31Revert the crypto "global lock" implementationBenjamin Kaduk1-1/+0
Conceptually, this is a squashed version of: Revert "Address feedback" This reverts commit 75551e07bd2339dfea06ef1d31d69929e13a4495. and Revert "Add CRYPTO_thread_glock_new" This reverts commit ed6b2c7938ec6f07b15745d4183afc276e74c6dd. But there were some intervening commits that made neither revert apply cleanly, so instead do it all as one shot. The crypto global locks were an attempt to cope with the awkward POSIX semantics for pthread_atfork(); its documentation (the "RATIONALE" section) indicates that the expected usage is to have the prefork handler lock all "global" locks, and the parent and child handlers release those locks, to ensure that forking happens with a consistent (lock) state. However, the set of functions available in the child process is limited to async-signal-safe functions, and pthread_mutex_unlock() is not on the list of async-signal-safe functions! The only synchronization primitives that are async-signal-safe are the semaphore primitives, which are not really appropriate for general-purpose usage. However, the state consistency problem that the global locks were attempting to solve is not actually a serious problem, particularly for OpenSSL. That is, we can consider four cases of forking application that might use OpenSSL: (1) Single-threaded, does not call into OpenSSL in the child (e.g., the child calls exec() immediately) For this class of process, no locking is needed at all, since there is only ever a single thread of execution and the only reentrancy is due to signal handlers (which are themselves limited to async-signal-safe operation and should not be doing much work at all). (2) Single-threaded, calls into OpenSSL after fork() The application must ensure that it does not fork() with an unexpected lock held (that is, one that would get unlocked in the parent but accidentally remain locked in the child and cause deadlock). Since OpenSSL does not expose any of its internal locks to the application and the application is single-threaded, the OpenSSL internal locks will be unlocked for the fork(), and the state will be consistent. (OpenSSL will need to reseed its PRNG in the child, but that is an orthogonal issue.) If the application makes use of locks from libcrypto, proper handling for those locks is the responsibility of the application, as for any other locking primitive that is available for application programming. (3) Multi-threaded, does not call into OpenSSL after fork() As for (1), the OpenSSL state is only relevant in the parent, so no particular fork()-related handling is needed. The internal locks are relevant, but there is no interaction with the child to consider. (4) Multi-threaded, calls into OpenSSL after fork() This is the case where the pthread_atfork() hooks to ensure that all global locks are in a known state across fork() would come into play, per the above discussion. However, these "calls into OpenSSL after fork()" are still subject to the restriction to async-signal-safe functions. Since OpenSSL uses all sorts of locking and libc functions that are not on the list of safe functions (e.g., malloc()), this case is not currently usable and is unlikely to ever be usable, independently of the locking situation. So, there is no need to go through contortions to attempt to support this case in the one small area of locking interaction with fork(). In light of the above analysis (thanks @davidben and @achernya), go back to the simpler implementation that does not need to distinguish "library-global" locks or to have complicated atfork handling for locks. Reviewed-by: Kurt Roeckx <kurt@roeckx.be> Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com> (Merged from https://github.com/openssl/openssl/pull/5089)
2017-10-12Add CRYPTO_get_alloc_counts.Rich Salz1-0/+1
Use atomic operations for the counters Rename malloc_lock to memdbg_lock Also fix some style errors in mem_dbg.c Reviewed-by: Paul Dale <paul.dale@oracle.com> (Merged from https://github.com/openssl/openssl/pull/4359)
2017-10-10Fix typosKeshav Kini1-1/+1
CLA: trivial Reviewed-by: Rich Salz <rsalz@openssl.org> Reviewed-by: Ben Kaduk <kaduk@mit.edu> (Merged from https://github.com/openssl/openssl/pull/4513)
2017-10-10Add atomic write callPauli1-0/+1
Reviewed-by: Rich Salz <rsalz@openssl.org> (Merged from https://github.com/openssl/openssl/pull/4414)
2017-10-10Add a CRYPTO_atomic_read call which allows an int variable to be readPauli1-0/+1
in an atomic fashion. Reviewed-by: Rich Salz <rsalz@openssl.org> (Merged from https://github.com/openssl/openssl/pull/4414)
2017-09-28Use safestack.h exclusively internally.Pauli1-2/+1
Remove all stack headers from some includes that don't use them. Avoid a genearic untyped stack use. Update stack POD file to include the OPENSSL_sk_ API functions in the notes section. They were mentioned in the name section but not defined anywhere. Reviewed-by: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/4430)
2017-08-31Add CRYPTO_thread_glock_newRich Salz1-0/+1
Reviewed-by: Paul Dale <paul.dale@oracle.com> (Merged from https://github.com/openssl/openssl/pull/4294)
2017-07-29Implement the CRYPTO_secure_clear_free functionBernd Edlinger1-0/+4
Reviewed-by: Rich Salz <rsalz@openssl.org> (Merged from https://github.com/openssl/openssl/pull/4044)
2017-07-19Add DRBG random methodRich Salz1-1/+2
Ported from the last FIPS release, with DUAL_EC and SHA1 and the self-tests removed. Since only AES-CTR is supported, other code simplifications were done. Removed the "entropy blocklen" concept. Moved internal functions to new include/internal/rand.h. Reviewed-by: Paul Dale <paul.dale@oracle.com> (Merged from https://github.com/openssl/openssl/pull/3789)
2017-06-30Fix atfork flag. Avoid double-negatives :)Rich Salz1-1/+1
Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de> (Merged from https://github.com/openssl/openssl/pull/3815)
2017-06-29Add fork handlers, based on pthread_atforkRich Salz1-1/+7
Only for Unix platforms Reviewed-by: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/3754)
2017-06-20Modify Sun copyright to follow OpenSSL styleRich Salz1-6/+1
Approved by Oracle. Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de> (Merged from https://github.com/openssl/openssl/pull/3585)
2017-06-07make error tables const and separate header fileRich Salz1-26/+1
Run perltidy on util/mkerr Change some mkerr flags, write some doc comments Make generated tables "const" when genearting lib-internal ones. Add "state" file for mkerr Renerate error tables and headers Rationalize declaration of ERR_load_XXX_strings Fix out-of-tree build Add -static; sort flags/vars for options. Also tweak code output Moved engines/afalg to engines (from master) Use -static flag Standard engine #include's of errors Don't linewrap err string tables unless necessary Reviewed-by: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/3392)
2017-04-24Add CRYPTO_mem_leaks_cbRichard Levitte1-0/+2
Reviewed-by: Rich Salz <rsalz@openssl.org> (Merged from https://github.com/openssl/openssl/pull/3243)
2017-03-20Fix the error handling in CRYPTO_dup_ex_data.Bernd Edlinger1-1/+1
Fix a strict aliasing issue in ui_dup_method_data. Add test coverage for CRYPTO_dup_ex_data, use OPENSSL_assert. Reviewed-by: Rich Salz <rsalz@openssl.org> Reviewed-by: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/2988)
2017-03-19Make the CRYPTO_memcmp() prototype match memcmp()Kurt Roeckx1-3/+1
Reviewed-by: Andy Polyakov <appro@openssl.org> GH: #2633
2017-01-11Add an application data field in the UI_METHODRichard Levitte1-1/+2
Reviewed-by: Rich Salz <rsalz@openssl.org> (Merged from https://github.com/openssl/openssl/pull/2204)
2016-08-17Don't try to init dasync internallyRichard Levitte1-2/+1
Since dasync isn't installed, and is only ever used as a dynamic engine, there's no reason to consider it for initialization when building static engines. Reviewed-by: Ben Laurie <ben@openssl.org>
2016-08-01Const the ex data stuff too to fix warningsRichard J. Moore1-2/+2
Reviewed-by: Rich Salz <rsalz@openssl.org> Reviewed-by: Richard Levitte <levitte@openssl.org>
2016-07-20Check for errors allocating the error strings.Kurt Roeckx1-1/+1
Reviewed-by: Richard Levitte <levitte@openssl.org> GH: #1330
2016-07-08include/openssl: don't include <windows.h> in public headers.Andy Polyakov1-15/+19
If application uses any of Windows-specific interfaces, make it application developer's respondibility to include <windows.h>. Rationale is that <windows.h> is quite "toxic" and is sensitive to inclusion order (most notably in relation to <winsock2.h>). It's only natural to give complete control to the application developer. Reviewed-by: Rich Salz <rsalz@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org>
2016-07-01Add old locking constants backKurt Roeckx1-0/+10
Fixes #1260 Reviewed-by: Matt Caswell <matt@openssl.org> GH: #1266
2016-07-01Make CRYPTO_num_locks() return 1Kurt Roeckx1-1/+1
malloc(0) might return NULL and code for the old callbacks might fail, instead just say they should allocate 1 entry. Reviewed-by: Matt Caswell <matt@openssl.org> GH: #1266
2016-06-22crypto/cryptlib.c: omit OPENSSL_ia32cap_loc().Andy Polyakov1-2/+0
Reviewed-by: Rich Salz <rsalz@openssl.org>
2016-06-14RT4562: Fix misleading doc on OPENSSL_configRich Salz1-2/+2
Also changed the code to use "appname" not "filename" Reviewed-by: Matt Caswell <matt@openssl.org>
2016-05-23Add error return for OPENSSL_INIT_set_config_filename()Matt Caswell1-2/+2
The OPENSSL_INIT_set_config_filename() function can fail so ensure that it provides a suitable error code. GitHub Issue #920 Reviewed-by: Rich Salz <rsalz@openssl.org>
2016-05-23Remove unused error/function codes.Rich Salz1-11/+4
Add script to find unused err/reason codes Remove unused reason codes. Remove entries for unused functions Reviewed-by: Matt Caswell <matt@openssl.org>
2016-05-20Fix Windows 64 bit crashesMatt Caswell1-6/+1
The function InitOnceExceuteOnce is the best way to support the implementation of CRYPTO_THREAD_run_once() on Windows. Unfortunately WinXP doesn't have it. To get around that we had two different implementations: one for WinXP and one for later versions. Which one was used was based on the value of _WIN32_WINNT. This approach was starting to cause problems though because other parts of OpenSSL assume _WIN32_WINNT is going to be 0x0501 and crashes were occurring dependant on include file ordering. In addition a conditional based on _WIN32_WINNT had made its way into a public header file through commit 5c4328f. This is problematic because the value of this macro can vary between OpenSSL build time and application build time. The simplest solution to this mess is just to always use the WinXP version of CRYPTO_THREAD_run_once(). Its perhaps slightly sub-optimal but probably not noticably. GitHub Issue #1086 Reviewed-by: Richard Levitte <levitte@openssl.org>
2016-05-18Make OPENSSL_die as noreturnhesiod1-1/+1
Reviewed-by: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/526)
2016-05-17Copyright consolidation 03/10Rich Salz1-107/+7
Reviewed-by: Richard Levitte <levitte@openssl.org>
2016-05-16Fold threads.h into crypto.h making API publicViktor Dukhovni1-0/+38
Document thread-safe lock creation Reviewed-by: Richard Levitte <levitte@openssl.org>
2016-05-02Secure memory fixesTodd Short1-1/+1
Fix some of the variables to be (s)size_t, so that more than 1GB of secure memory can be allocated. The arena has to be a power of 2, and 2GB fails because it ends up being a negative 32-bit signed number. The |too_late| flag is not strictly necessary; it is easy to figure out if something is secure memory by looking at the arena. As before, secure memory allocations will not fail, but now they can be freed correctly. Once initialized, secure memory can still be used, even if allocations occured before initialization. Reviewed-by: Richard Levitte <levitte@openssl.org> Reviewed-by: Rich Salz <rsalz@openssl.org>
2016-04-29Remove BIO_dummy, it's old cruftRichard Levitte1-3/+0
Reviewed-by: Rich Salz <rsalz@openssl.org>
2016-04-29Make header signature of CRYPTO_mem_leaks BIO instead of struct bio_stPaul Kehrer1-1/+1
Reviewed-by: Rich Salz <rsalz@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/1012)
2016-04-18Make string_to_hex/hex_to_string publicRich Salz1-1/+7
Give the API new names, document it. Reviewed-by: Richard Levitte <levitte@openssl.org>
2016-04-13Fix explicit de-init macrosMatt Caswell1-1/+1
The no-op de-init macros may fail because of extraneous ";", so we use a slightly different construct instead. Reviewed-by: Tim Hudson <tjh@openssl.org> Reviewed-by: Richard Levitte <levitte@openssl.org>
2016-04-13Deprecate CRYPTO_cleanup_all_ex_data() and make it a no-opMatt Caswell1-2/+3
CRYPTO_cleanup_all_ex_data() should not be called expicitly - we should leave auto-deinit to clean this up instead. Reviewed-by: Tim Hudson <tjh@openssl.org> Reviewed-by: Richard Levitte <levitte@openssl.org>
2016-04-03Removed no-ops for the old locking APIMichał Trojnara1-24/+8
Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Rich Salz <rsalz@openssl.org>
2016-03-29Fixup SSL EX_DATA indexTodd Short1-3/+2
The SSL, SSL_CTX, and SSL_SESSION indices were being referenced incorrectly in the "_get_ex_new_index" functions. Remove the STORE EX_DATA index; that functionality is gone. Reviewed-by: Emilia Käsper <emilia@openssl.org> Reviewed-by: Rich Salz <rsalz@openssl.org>
2016-03-09Remove the old threading APIMatt Caswell1-100/+56
All OpenSSL code has now been transferred to use the new threading API, so the old one is no longer used and can be removed. We provide some compat macros for removed functions which are all no-ops. There is now no longer a need to set locking callbacks!! Reviewed-by: Richard Levitte <levitte@openssl.org>
2016-03-09Convert rand code to new threading APIMatt Caswell1-2/+0
Replace the CRYPTO_LOCK_RAND and CRYPTO_LOCK_RAND2 locks with new thread API style locks. Reviewed-by: Rich Salz <rsalz@openssl.org>
2016-03-08Convert RSA blinding to new multi-threading APIAlessandro Ghedini1-1/+0
Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Rich Salz <rsalz@openssl.org>
2016-03-08Convert CRYPTO_LOCK_SSL_* to new multi-threading APIAlessandro Ghedini1-7/+0
Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Rich Salz <rsalz@openssl.org>
2016-03-08Convert mem_dbg and mem_sec to the new Thread APIMatt Caswell1-2/+0
Use new Thread API style locks, and thread local storage for mem_dbg Reviewed-by: Rich Salz <rsalz@openssl.org>
2016-03-08OpenSSLDie --> OPENSSL_dieRich Salz1-2/+6
Also removed a bunch of unused define's from e_os.h Reviewed-by: Richard Levitte <levitte@openssl.org>
2016-03-08Convert CRYPTO_LOCK_X509_* to new multi-threading APIAlessandro Ghedini1-5/+0
Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Rich Salz <rsalz@openssl.org>
2016-03-08Convert CRYPTO_LOCK_UI to new multi-threading APIAlessandro Ghedini1-1/+0
Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Rich Salz <rsalz@openssl.org>