From 7caf3ea7d0c716b7e123f3734ddca77196fd84a6 Mon Sep 17 00:00:00 2001 From: orignal Date: Fri, 10 Mar 2017 13:21:22 -0500 Subject: [PATCH] eliminate dependancy from GOST engine for GOST R 34.10 --- Crypto.cpp | 61 ++------------------------------------ Crypto.h | 3 -- Daemon.cpp | 2 -- android/jni/Android.mk | 7 ----- android/jni/Application.mk | 1 - 5 files changed, 3 insertions(+), 71 deletions(-) diff --git a/Crypto.cpp b/Crypto.cpp index 9ca5928c..791968d3 100644 --- a/Crypto.cpp +++ b/Crypto.cpp @@ -802,70 +802,15 @@ namespace crypto } }*/ - static ENGINE * g_GostEngine = nullptr; - static const EVP_MD * g_Gost3411 = nullptr; - static EVP_PKEY * g_GostPKEY = nullptr; - - const EVP_PKEY * GetGostPKEY () - { - return g_GostPKEY; - } uint8_t * GOSTR3411 (const uint8_t * buf, size_t len, uint8_t * digest) { - if (!g_Gost3411) return nullptr; - auto ctx = EVP_MD_CTX_new (); - EVP_DigestInit_ex (ctx, g_Gost3411, g_GostEngine); - EVP_DigestUpdate (ctx, buf, len); - EVP_DigestFinal_ex (ctx, digest, nullptr); - EVP_MD_CTX_free (ctx); + // TODO: implement actual GOST R 34.11 + // SHA-256 is used for testing only + SHA256 (buf, len, digest); return digest; } - bool InitGost () - { -#ifndef OPENSSL_NO_ENGINE -#if (OPENSSL_VERSION_NUMBER < 0x010100000) || defined(LIBRESSL_VERSION_NUMBER) - ENGINE_load_builtin_engines (); - ENGINE_load_dynamic (); -#else - OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_ALL_BUILTIN, NULL); -#endif - g_GostEngine = ENGINE_by_id ("gost"); - if (!g_GostEngine) return false; - - ENGINE_init (g_GostEngine); - ENGINE_set_default (g_GostEngine, ENGINE_METHOD_ALL); - g_Gost3411 = ENGINE_get_digest(g_GostEngine, NID_id_GostR3411_94); - - auto ctx = EVP_PKEY_CTX_new_id(NID_id_GostR3410_2001, g_GostEngine); - if (!ctx) return false; - EVP_PKEY_keygen_init (ctx); - EVP_PKEY_CTX_ctrl_str (ctx, "paramset", "A"); // possible values 'A', 'B', 'C', 'XA', 'XB' - EVP_PKEY_keygen (ctx, &g_GostPKEY); // it seems only way to fill with correct params - EVP_PKEY_CTX_free (ctx); - return true; -#else - LogPrint (eLogError, "Can't initialize GOST. Engines are not supported"); - return false; -#endif - } - - void TerminateGost () - { - if (g_GostPKEY) - EVP_PKEY_free (g_GostPKEY); -#ifndef OPENSSL_NO_ENGINE - if (g_GostEngine) - { - ENGINE_finish (g_GostEngine); - ENGINE_free (g_GostEngine); -#if (OPENSSL_VERSION_NUMBER < 0x010100000) || defined(LIBRESSL_VERSION_NUMBER) - ENGINE_cleanup(); -#endif - } -#endif - } void InitCrypto (bool precomputation, bool withGost) { diff --git a/Crypto.h b/Crypto.h index fca7b073..748a7f48 100644 --- a/Crypto.h +++ b/Crypto.h @@ -280,9 +280,6 @@ namespace crypto }; // GOST - bool InitGost (); - void TerminateGost (); - const EVP_PKEY * GetGostPKEY (); uint8_t * GOSTR3411 (const uint8_t * buf, size_t len, uint8_t * digest); // hash void InitCrypto (bool precomputation, bool withGost = false); diff --git a/Daemon.cpp b/Daemon.cpp index 74d3f859..c7aaa279 100644 --- a/Daemon.cpp +++ b/Daemon.cpp @@ -122,7 +122,6 @@ namespace i2p i2p::crypto::InitCrypto (precomputation); int netID; i2p::config::GetOption("netid", netID); - if (netID != 2) i2p::crypto::InitGost (); // init GOST for own darknet i2p::context.SetNetID (netID); i2p::context.Init (); @@ -350,7 +349,6 @@ namespace i2p d.m_WebsocketServer = nullptr; } #endif - if (i2p::context.GetNetID () != 2) i2p::crypto::TerminateGost (); i2p::crypto::TerminateCrypto (); i2p::log::Logger().Stop(); diff --git a/android/jni/Android.mk b/android/jni/Android.mk index ad2592ee..1bba69f0 100755 --- a/android/jni/Android.mk +++ b/android/jni/Android.mk @@ -109,13 +109,6 @@ LOCAL_EXPORT_C_INCLUDES := $(OPENSSL_PATH)/openssl-1.1.0e/include LOCAL_STATIC_LIBRARIES := crypto include $(PREBUILT_STATIC_LIBRARY) -LOCAL_PATH := $(call my-dir) -include $(CLEAR_VARS) -LOCAL_MODULE := gost_engine -LOCAL_SRC_FILES := $(GOST_PATH)/gost-engine/$(TARGET_ARCH_ABI)/lib/libgost.a -LOCAL_EXPORT_C_INCLUDES := $(GOST_PATH)/gost-engine/include -include $(PREBUILT_STATIC_LIBRARY) - LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := miniupnpc diff --git a/android/jni/Application.mk b/android/jni/Application.mk index ee031efc..e8a51add 100755 --- a/android/jni/Application.mk +++ b/android/jni/Application.mk @@ -30,4 +30,3 @@ BOOST_PATH = $(I2PD_LIBS_PATH)/Boost-for-Android-Prebuilt OPENSSL_PATH = $(I2PD_LIBS_PATH)/OpenSSL-for-Android-Prebuilt MINIUPNP_PATH = $(I2PD_LIBS_PATH)/MiniUPnP-for-Android-Prebuilt IFADDRS_PATH = $(I2PD_LIBS_PATH)/android-ifaddrs -GOST_PATH = $(I2PD_LIBS_PATH)/GOST-Engine-for-Android-Prebuilt