Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / crypto / openssl_util.cc
index 5bc3ce5..f41b55a 100644 (file)
@@ -6,19 +6,27 @@
 
 #include <openssl/err.h>
 #include <openssl/ssl.h>
+#include <openssl/cpu.h>
 
 #include "base/logging.h"
 #include "base/memory/scoped_vector.h"
 #include "base/memory/singleton.h"
 #include "base/strings/string_piece.h"
 #include "base/synchronization/lock.h"
+#include "build/build_config.h"
+
+#if defined(OS_ANDROID) && defined(ARCH_CPU_ARMEL)
+#include <cpu-features.h>
+#include "base/cpu.h"
+#endif
 
 namespace crypto {
 
 namespace {
 
-unsigned long CurrentThreadId() {
-  return static_cast<unsigned long>(base::PlatformThread::CurrentId());
+void CurrentThreadId(CRYPTO_THREADID* id) {
+  CRYPTO_THREADID_set_numeric(
+      id, static_cast<unsigned long>(base::PlatformThread::CurrentId()));
 }
 
 // Singleton for initializing and cleaning up the OpenSSL library.
@@ -42,13 +50,22 @@ class OpenSSLInitSingleton {
   OpenSSLInitSingleton() {
     SSL_load_error_strings();
     SSL_library_init();
-    OpenSSL_add_all_algorithms();
     int num_locks = CRYPTO_num_locks();
     locks_.reserve(num_locks);
     for (int i = 0; i < num_locks; ++i)
       locks_.push_back(new base::Lock());
     CRYPTO_set_locking_callback(LockingCallback);
-    CRYPTO_set_id_callback(CurrentThreadId);
+    CRYPTO_THREADID_set_callback(CurrentThreadId);
+
+#if defined(OS_ANDROID) && defined(ARCH_CPU_ARMEL)
+    const bool has_neon =
+        (android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) != 0;
+    if (has_neon)
+      CRYPTO_set_NEON_capable(1);
+    // See https://code.google.com/p/chromium/issues/detail?id=341598
+    base::CPU cpu;
+    CRYPTO_set_NEON_functional(!cpu.has_broken_neon());
+#endif
   }
 
   ~OpenSSLInitSingleton() {