PRCYCoin
2.0.0.7rc1
P2P Digital Currency
src
crypto
rfc6979_hmac_sha256.cpp
Go to the documentation of this file.
1
// Copyright (c) 2014 The Bitcoin 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/rfc6979_hmac_sha256.h
"
6
7
#include <string.h>
8
9
#include <algorithm>
10
11
static
const
unsigned
char
zero[1] = {0x00};
12
static
const
unsigned
char
one[1] = {0x01};
13
14
RFC6979_HMAC_SHA256::RFC6979_HMAC_SHA256
(
const
unsigned
char
*
key
,
size_t
keylen,
const
unsigned
char
* msg,
size_t
msglen) : retry(false)
15
{
16
memset(
V
, 0x01,
sizeof
(
V
));
17
memset(
K
, 0x00,
sizeof
(
K
));
18
19
CHMAC_SHA256
(
K
,
sizeof
(
K
)).
Write
(
V
,
sizeof
(
V
)).
Write
(zero,
sizeof
(zero)).
Write
(
key
, keylen).
Write
(msg, msglen).
Finalize
(
K
);
20
CHMAC_SHA256
(
K
,
sizeof
(
K
)).
Write
(
V
,
sizeof
(
V
)).
Finalize
(
V
);
21
CHMAC_SHA256
(
K
,
sizeof
(
K
)).
Write
(
V
,
sizeof
(
V
)).
Write
(one,
sizeof
(one)).
Write
(
key
, keylen).
Write
(msg, msglen).
Finalize
(
K
);
22
CHMAC_SHA256
(
K
,
sizeof
(
K
)).
Write
(
V
,
sizeof
(
V
)).
Finalize
(
V
);
23
}
24
25
RFC6979_HMAC_SHA256::~RFC6979_HMAC_SHA256
()
26
{
27
memset(
V
, 0x01,
sizeof
(
V
));
28
memset(
K
, 0x00,
sizeof
(
K
));
29
}
30
31
void
RFC6979_HMAC_SHA256::Generate
(
unsigned
char
* output,
size_t
outputlen)
32
{
33
if
(
retry
) {
34
CHMAC_SHA256
(
K
,
sizeof
(
K
)).
Write
(
V
,
sizeof
(
V
)).
Write
(zero,
sizeof
(zero)).
Finalize
(
K
);
35
CHMAC_SHA256
(
K
,
sizeof
(
K
)).
Write
(
V
,
sizeof
(
V
)).
Finalize
(
V
);
36
}
37
38
while
(outputlen > 0) {
39
CHMAC_SHA256
(
K
,
sizeof
(
K
)).
Write
(
V
,
sizeof
(
V
)).
Finalize
(
V
);
40
size_t
len = std::min(outputlen,
sizeof
(
V
));
41
memcpy
(output,
V
, len);
42
output += len;
43
outputlen -= len;
44
}
45
46
retry
=
true
;
47
}
CHMAC_SHA256::Finalize
void Finalize(unsigned char hash[OUTPUT_SIZE])
Definition:
hmac_sha256.cpp:29
RFC6979_HMAC_SHA256::RFC6979_HMAC_SHA256
RFC6979_HMAC_SHA256(const unsigned char *key, size_t keylen, const unsigned char *msg, size_t msglen)
Construct a new RFC6979 PRNG, using the given key and message.
Definition:
rfc6979_hmac_sha256.cpp:14
CHMAC_SHA256
A hasher class for HMAC-SHA-256.
Definition:
hmac_sha256.h:14
RFC6979_HMAC_SHA256::retry
bool retry
Definition:
rfc6979_hmac_sha256.h:19
memcpy
void * memcpy(void *a, const void *b, size_t c)
Definition:
glibc_compat.cpp:15
RFC6979_HMAC_SHA256::Generate
void Generate(unsigned char *output, size_t outputlen)
Generate a byte array.
Definition:
rfc6979_hmac_sha256.cpp:31
RFC6979_HMAC_SHA256::V
unsigned char V[CHMAC_SHA256::OUTPUT_SIZE]
Definition:
rfc6979_hmac_sha256.h:17
rfc6979_hmac_sha256.h
CHMAC_SHA256::Write
CHMAC_SHA256 & Write(const unsigned char *data, size_t len)
Definition:
hmac_sha256.h:24
RFC6979_HMAC_SHA256::K
unsigned char K[CHMAC_SHA256::OUTPUT_SIZE]
Definition:
rfc6979_hmac_sha256.h:18
RFC6979_HMAC_SHA256::~RFC6979_HMAC_SHA256
~RFC6979_HMAC_SHA256()
Definition:
rfc6979_hmac_sha256.cpp:25
key
CKey key
Definition:
bip38tooldialog.cpp:173
Generated on Tue Apr 28 2026 00:02:50 for PRCYCoin by
1.8.17