Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(123)

Side by Side Diff: crypto/openssl_util.cc

Issue 401153002: Switch to BoringSSL. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase across DEPS change Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « crypto/openssl_bio_string_unittest.cc ('k') | crypto/rsa_private_key_openssl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "crypto/openssl_util.h" 5 #include "crypto/openssl_util.h"
6 6
7 #include <openssl/err.h> 7 #include <openssl/err.h>
8 #include <openssl/ssl.h> 8 #include <openssl/ssl.h>
9 #include <openssl/cpu.h>
9 10
10 #include "base/logging.h" 11 #include "base/logging.h"
11 #include "base/memory/scoped_vector.h" 12 #include "base/memory/scoped_vector.h"
12 #include "base/memory/singleton.h" 13 #include "base/memory/singleton.h"
13 #include "base/strings/string_piece.h" 14 #include "base/strings/string_piece.h"
14 #include "base/synchronization/lock.h" 15 #include "base/synchronization/lock.h"
15 #include "build/build_config.h" 16 #include "build/build_config.h"
16 17
17 #if defined(OS_ANDROID) && defined(ARCH_CPU_ARMEL) 18 #if defined(OS_ANDROID) && defined(ARCH_CPU_ARMEL)
18 #include <cpu-features.h> 19 #include <cpu-features.h>
19 #endif 20 #endif
20 21
21 namespace crypto { 22 namespace crypto {
22 23
23 namespace { 24 namespace {
24 25
25 unsigned long CurrentThreadId() { 26 void CurrentThreadId(CRYPTO_THREADID* id) {
26 return static_cast<unsigned long>(base::PlatformThread::CurrentId()); 27 CRYPTO_THREADID_set_numeric(
28 id, static_cast<unsigned long>(base::PlatformThread::CurrentId()));
27 } 29 }
28 30
29 // Singleton for initializing and cleaning up the OpenSSL library. 31 // Singleton for initializing and cleaning up the OpenSSL library.
30 class OpenSSLInitSingleton { 32 class OpenSSLInitSingleton {
31 public: 33 public:
32 static OpenSSLInitSingleton* GetInstance() { 34 static OpenSSLInitSingleton* GetInstance() {
33 // We allow the SSL environment to leak for multiple reasons: 35 // We allow the SSL environment to leak for multiple reasons:
34 // - it is used from a non-joinable worker thread that is not stopped on 36 // - it is used from a non-joinable worker thread that is not stopped on
35 // shutdown, hence may still be using OpenSSL library after the AtExit 37 // shutdown, hence may still be using OpenSSL library after the AtExit
36 // runner has completed. 38 // runner has completed.
37 // - There are other OpenSSL related singletons (e.g. the client socket 39 // - There are other OpenSSL related singletons (e.g. the client socket
38 // context) who's cleanup depends on the global environment here, but 40 // context) who's cleanup depends on the global environment here, but
39 // we can't control the order the AtExit handlers will run in so 41 // we can't control the order the AtExit handlers will run in so
40 // allowing the global environment to leak at least ensures it is 42 // allowing the global environment to leak at least ensures it is
41 // available for those other singletons to reliably cleanup. 43 // available for those other singletons to reliably cleanup.
42 return Singleton<OpenSSLInitSingleton, 44 return Singleton<OpenSSLInitSingleton,
43 LeakySingletonTraits<OpenSSLInitSingleton> >::get(); 45 LeakySingletonTraits<OpenSSLInitSingleton> >::get();
44 } 46 }
45 private: 47 private:
46 friend struct DefaultSingletonTraits<OpenSSLInitSingleton>; 48 friend struct DefaultSingletonTraits<OpenSSLInitSingleton>;
47 OpenSSLInitSingleton() { 49 OpenSSLInitSingleton() {
48 SSL_load_error_strings(); 50 SSL_load_error_strings();
49 SSL_library_init(); 51 SSL_library_init();
50 OpenSSL_add_all_algorithms(); 52 OpenSSL_add_all_algorithms();
51 int num_locks = CRYPTO_num_locks(); 53 int num_locks = CRYPTO_num_locks();
52 locks_.reserve(num_locks); 54 locks_.reserve(num_locks);
53 for (int i = 0; i < num_locks; ++i) 55 for (int i = 0; i < num_locks; ++i)
54 locks_.push_back(new base::Lock()); 56 locks_.push_back(new base::Lock());
55 CRYPTO_set_locking_callback(LockingCallback); 57 CRYPTO_set_locking_callback(LockingCallback);
56 CRYPTO_set_id_callback(CurrentThreadId); 58 CRYPTO_THREADID_set_callback(CurrentThreadId);
57 59
58 #if defined(OS_ANDROID) && defined(ARCH_CPU_ARMEL) 60 #if defined(OS_ANDROID) && defined(ARCH_CPU_ARMEL)
59 const bool has_neon = 61 const bool has_neon =
60 (android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) != 0; 62 (android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) != 0;
61 if (has_neon) 63 if (has_neon)
62 CRYPTO_set_NEON_capable(1); 64 CRYPTO_set_NEON_capable(1);
63 #endif 65 #endif
64 } 66 }
65 67
66 ~OpenSSLInitSingleton() { 68 ~OpenSSLInitSingleton() {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 std::string message; 118 std::string message;
117 location.Write(true, true, &message); 119 location.Write(true, true, &message);
118 DVLOG(1) << "OpenSSL ERR_get_error stack from " << message; 120 DVLOG(1) << "OpenSSL ERR_get_error stack from " << message;
119 ERR_print_errors_cb(&OpenSSLErrorCallback, NULL); 121 ERR_print_errors_cb(&OpenSSLErrorCallback, NULL);
120 } else { 122 } else {
121 ERR_clear_error(); 123 ERR_clear_error();
122 } 124 }
123 } 125 }
124 126
125 } // namespace crypto 127 } // namespace crypto
OLDNEW
« no previous file with comments | « crypto/openssl_bio_string_unittest.cc ('k') | crypto/rsa_private_key_openssl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698