Browse Source

eliminate dependancy from GOST engine for GOST R 34.10

pull/824/head
orignal 8 years ago
parent
commit
7caf3ea7d0
  1. 61
      Crypto.cpp
  2. 3
      Crypto.h
  3. 2
      Daemon.cpp
  4. 7
      android/jni/Android.mk
  5. 1
      android/jni/Application.mk

61
Crypto.cpp

@ -802,70 +802,15 @@ namespace crypto @@ -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)
{

3
Crypto.h

@ -280,9 +280,6 @@ namespace crypto @@ -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);

2
Daemon.cpp

@ -122,7 +122,6 @@ namespace i2p @@ -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 @@ -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();

7
android/jni/Android.mk

@ -109,13 +109,6 @@ LOCAL_EXPORT_C_INCLUDES := $(OPENSSL_PATH)/openssl-1.1.0e/include @@ -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

1
android/jni/Application.mk

@ -30,4 +30,3 @@ BOOST_PATH = $(I2PD_LIBS_PATH)/Boost-for-Android-Prebuilt @@ -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

Loading…
Cancel
Save