File 04_secp256k1.patch of Package ethereum-cpp

From: Adam Mizerski <adam@mizerski.pl>
Date: 2019-02-12 20:48:31
Upstream: no
Subject: fix secp256k1 usage

ethereum-cpp uses patched and older version of secp256k1. Current upstream
version allows to pass custom hash function, so no patching is required.

Index: ethereum-cpp-1.8.0/libdevcrypto/Common.cpp
===================================================================
--- ethereum-cpp-1.8.0.orig/libdevcrypto/Common.cpp
+++ ethereum-cpp-1.8.0/libdevcrypto/Common.cpp
@@ -381,6 +381,13 @@ Secret Nonce::next()
     return sha3(~m_value);
 }
 
+static int secp256k1_ecdh_hash_function_save_compressed(unsigned char* output, const unsigned char* x, const unsigned char* y, void*)
+{
+    output[0] = 0x02 | (y[31] & 1);
+    std::memcpy(output+1, x, 32);
+    return 1;
+}
+
 bool ecdh::agree(Secret const& _s, Public const& _r, Secret& o_s) noexcept
 {
     auto* ctx = getCtx();
@@ -393,7 +400,7 @@ bool ecdh::agree(Secret const& _s, Publi
     // FIXME: We should verify the public key when constructed, maybe even keep
     //        secp256k1_pubkey as the internal data of Public.
     std::array<byte, 33> compressedPoint;
-    if (!secp256k1_ecdh_raw(ctx, compressedPoint.data(), &rawPubkey, _s.data()))
+    if (!secp256k1_ecdh(ctx, compressedPoint.data(), &rawPubkey, _s.data(), secp256k1_ecdh_hash_function_save_compressed, nullptr))
         return false;  // Invalid secret key.
     std::copy(compressedPoint.begin() + 1, compressedPoint.end(), o_s.writable().data());
     return true;
@@ -407,7 +414,7 @@ bytes ecies::kdf(Secret const& _z, bytes
     // the 4 bytes is okay. NIST specifies 4 bytes.
     std::array<byte, 4> ctr{{0, 0, 0, 1}};
     bytes k;
-    secp256k1_sha256_t ctx;
+    secp256k1_sha256 ctx;
     for (unsigned i = 0; i <= reps; i++)
     {
         secp256k1_sha256_initialize(&ctx);
Index: ethereum-cpp-1.8.0/libdevcrypto/Hash.cpp
===================================================================
--- ethereum-cpp-1.8.0.orig/libdevcrypto/Hash.cpp
+++ ethereum-cpp-1.8.0/libdevcrypto/Hash.cpp
@@ -13,7 +13,7 @@ namespace dev
 
 h256 sha256(bytesConstRef _input) noexcept
 {
-	secp256k1_sha256_t ctx;
+	secp256k1_sha256 ctx;
 	secp256k1_sha256_initialize(&ctx);
 	secp256k1_sha256_write(&ctx, _input.data(), _input.size());
 	h256 hash;
openSUSE Build Service is sponsored by