aboutsummaryrefslogtreecommitdiff
path: root/src/key.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2014-04-20 17:36:25 +0200
committerPieter Wuille <pieter.wuille@gmail.com>2014-06-21 19:47:39 +0200
commit977cdadea8a77eed04f1f0fd341ba9dedc3fa783 (patch)
tree842e2239a98d6f5c329e639f4ca953e5ea865f82 /src/key.cpp
parent540ce6aa10996661a62853797538d2a703664ea2 (diff)
Add a built-in SHA256/SHA512 implementation.
This also moves the HMAC-SHA512 implementation to sha2.cpp.
Diffstat (limited to 'src/key.cpp')
-rw-r--r--src/key.cpp19
1 files changed, 8 insertions, 11 deletions
diff --git a/src/key.cpp b/src/key.cpp
index 4747beffb4..0685948922 100644
--- a/src/key.cpp
+++ b/src/key.cpp
@@ -4,6 +4,8 @@
#include "key.h"
+#include "sha2.h"
+
#include <openssl/bn.h>
#include <openssl/ecdsa.h>
#include <openssl/obj_mac.h>
@@ -510,12 +512,10 @@ void static BIP32Hash(const unsigned char chainCode[32], unsigned int nChild, un
num[1] = (nChild >> 16) & 0xFF;
num[2] = (nChild >> 8) & 0xFF;
num[3] = (nChild >> 0) & 0xFF;
- HMAC_SHA512_CTX ctx;
- HMAC_SHA512_Init(&ctx, chainCode, 32);
- HMAC_SHA512_Update(&ctx, &header, 1);
- HMAC_SHA512_Update(&ctx, data, 32);
- HMAC_SHA512_Update(&ctx, num, 4);
- HMAC_SHA512_Final(output, &ctx);
+ CHMAC_SHA512(chainCode, 32).Write(&header, 1)
+ .Write(data, 32)
+ .Write(num, 4)
+ .Finalize(output);
}
bool CKey::Derive(CKey& keyChild, unsigned char ccChild[32], unsigned int nChild, const unsigned char cc[32]) const {
@@ -562,13 +562,10 @@ bool CExtKey::Derive(CExtKey &out, unsigned int nChild) const {
}
void CExtKey::SetMaster(const unsigned char *seed, unsigned int nSeedLen) {
- static const char hashkey[] = {'B','i','t','c','o','i','n',' ','s','e','e','d'};
- HMAC_SHA512_CTX ctx;
- HMAC_SHA512_Init(&ctx, hashkey, sizeof(hashkey));
- HMAC_SHA512_Update(&ctx, seed, nSeedLen);
+ static const unsigned char hashkey[] = {'B','i','t','c','o','i','n',' ','s','e','e','d'};
unsigned char out[64];
LockObject(out);
- HMAC_SHA512_Final(out, &ctx);
+ CHMAC_SHA512(hashkey, sizeof(hashkey)).Write(seed, nSeedLen).Finalize(out);
key.Set(&out[0], &out[32], true);
memcpy(vchChainCode, &out[32], 32);
UnlockObject(out);