/bitcoin/src/crypto/hmac_sha256.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_sha256.h> |
6 | | |
7 | | #include <string.h> |
8 | | |
9 | | CHMAC_SHA256::CHMAC_SHA256(const unsigned char* key, size_t keylen) |
10 | 2.36M | { |
11 | 2.36M | unsigned char rkey[64]; |
12 | 2.36M | if (keylen <= 64) { Branch (12:9): [True: 2.36M, False: 0]
|
13 | 2.36M | memcpy(rkey, key, keylen); |
14 | 2.36M | memset(rkey + keylen, 0, 64 - keylen); |
15 | 2.36M | } else { |
16 | 0 | CSHA256().Write(key, keylen).Finalize(rkey); |
17 | 0 | memset(rkey + 32, 0, 32); |
18 | 0 | } |
19 | | |
20 | 154M | for (int n = 0; n < 64; n++) Branch (20:21): [True: 151M, False: 2.36M]
|
21 | 151M | rkey[n] ^= 0x5c; |
22 | 2.36M | outer.Write(rkey, 64); |
23 | | |
24 | 154M | for (int n = 0; n < 64; n++) Branch (24:21): [True: 151M, False: 2.36M]
|
25 | 151M | rkey[n] ^= 0x5c ^ 0x36; |
26 | 2.36M | inner.Write(rkey, 64); |
27 | 2.36M | } |
28 | | |
29 | | void CHMAC_SHA256::Finalize(unsigned char hash[OUTPUT_SIZE]) |
30 | 2.36M | { |
31 | 2.36M | unsigned char temp[32]; |
32 | 2.36M | inner.Finalize(temp); |
33 | 2.36M | outer.Write(temp, 32).Finalize(hash); |
34 | 2.36M | } |