Raven Core  3.0.0
P2P Digital Currency
hmac_sha512.cpp
Go to the documentation of this file.
1 // Copyright (c) 2014 The Bitcoin Core developers
2 // Copyright (c) 2017-2019 The Raven Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #include "crypto/hmac_sha512.h"
7 
8 #include <string.h>
9 
10 CHMAC_SHA512::CHMAC_SHA512(const unsigned char* key, size_t keylen)
11 {
12  unsigned char rkey[128];
13  if (keylen <= 128) {
14  memcpy(rkey, key, keylen);
15  memset(rkey + keylen, 0, 128 - keylen);
16  } else {
17  CSHA512().Write(key, keylen).Finalize(rkey);
18  memset(rkey + 64, 0, 64);
19  }
20 
21  for (int n = 0; n < 128; n++)
22  rkey[n] ^= 0x5c;
23  outer.Write(rkey, 128);
24 
25  for (int n = 0; n < 128; n++)
26  rkey[n] ^= 0x5c ^ 0x36;
27  inner.Write(rkey, 128);
28 }
29 
30 void CHMAC_SHA512::Finalize(unsigned char hash[OUTPUT_SIZE])
31 {
32  unsigned char temp[64];
33  inner.Finalize(temp);
34  outer.Write(temp, 64).Finalize(hash);
35 }
void Finalize(unsigned char hash[OUTPUT_SIZE])
Definition: hmac_sha512.cpp:30
static const size_t OUTPUT_SIZE
Definition: hmac_sha512.h:22
void Finalize(unsigned char hash[OUTPUT_SIZE])
Definition: sha512.cpp:186
CSHA512 outer
Definition: hmac_sha512.h:18
void * memcpy(void *a, const void *b, size_t c)
CSHA512 & Write(const unsigned char *data, size_t len)
Definition: sha512.cpp:160
CHMAC_SHA512(const unsigned char *key, size_t keylen)
Definition: hmac_sha512.cpp:10
A hasher class for SHA-512.
Definition: sha512.h:13
CSHA512 inner
Definition: hmac_sha512.h:19