/bitcoin/src/crypto/hmac_sha512.cpp
Line | Count | Source |
1 | | // Copyright (c) 2014-2018 The Bitcoin Core developers |
2 | | // Distributed under the MIT software license, see the accompanying |
3 | | // file COPYING or http://www.opensource.org/licenses/mit-license.php. |
4 | | |
5 | | #include <crypto/hmac_sha512.h> |
6 | | |
7 | | #include <string.h> |
8 | | |
9 | | CHMAC_SHA512::CHMAC_SHA512(const unsigned char* key, size_t keylen) |
10 | 1.25M | { |
11 | 1.25M | unsigned char rkey[128]; |
12 | 1.25M | if (keylen <= 128) { Branch (12:9): [True: 1.25M, False: 0]
|
13 | 1.25M | memcpy(rkey, key, keylen); |
14 | 1.25M | memset(rkey + keylen, 0, 128 - keylen); |
15 | 1.25M | } else { |
16 | 0 | CSHA512().Write(key, keylen).Finalize(rkey); |
17 | 0 | memset(rkey + 64, 0, 64); |
18 | 0 | } |
19 | | |
20 | 161M | for (int n = 0; n < 128; n++) Branch (20:21): [True: 160M, False: 1.25M]
|
21 | 160M | rkey[n] ^= 0x5c; |
22 | 1.25M | outer.Write(rkey, 128); |
23 | | |
24 | 161M | for (int n = 0; n < 128; n++) Branch (24:21): [True: 160M, False: 1.25M]
|
25 | 160M | rkey[n] ^= 0x5c ^ 0x36; |
26 | 1.25M | inner.Write(rkey, 128); |
27 | 1.25M | } |
28 | | |
29 | | void CHMAC_SHA512::Finalize(unsigned char hash[OUTPUT_SIZE]) |
30 | 1.25M | { |
31 | 1.25M | unsigned char temp[64]; |
32 | 1.25M | inner.Finalize(temp); |
33 | 1.25M | outer.Write(temp, 64).Finalize(hash); |
34 | 1.25M | } |