]> Git Repo - VerusCoin.git/blob - src/zcash/prf.cpp
Auto merge of #1268 - ThisIsNotOfficialCodeItsJustForks:t1130-upgrade-libsodium,...
[VerusCoin.git] / src / zcash / prf.cpp
1 #include "prf.h"
2 #include "crypto/sha256.h"
3
4 uint256 PRF(bool a, bool b, bool c, bool d,
5             const uint252& x,
6             const uint256& y)
7 {
8     uint256 res;
9     unsigned char blob[64];
10
11     memcpy(&blob[0], x.begin(), 32);
12     memcpy(&blob[32], y.begin(), 32);
13
14     blob[0] &= 0x0F;
15     blob[0] |= (a ? 1 << 7 : 0) | (b ? 1 << 6 : 0) | (c ? 1 << 5 : 0) | (d ? 1 << 4 : 0);
16
17     CSHA256 hasher;
18     hasher.Write(blob, 64);
19     hasher.FinalizeNoPadding(res.begin());
20
21     return res;
22 }
23
24 uint256 PRF_addr(const uint252& a_sk, unsigned char t)
25 {
26     uint256 y;
27     *(y.begin()) = t;
28
29     return PRF(1, 1, 0, 0, a_sk, y);
30 }
31
32 uint256 PRF_addr_a_pk(const uint252& a_sk)
33 {
34     return PRF_addr(a_sk, 0);
35 }
36
37 uint256 PRF_addr_sk_enc(const uint252& a_sk)
38 {
39     return PRF_addr(a_sk, 1);
40 }
41
42 uint256 PRF_nf(const uint252& a_sk, const uint256& rho)
43 {
44     return PRF(1, 1, 1, 0, a_sk, rho);
45 }
46
47 uint256 PRF_pk(const uint252& a_sk, size_t i0, const uint256& h_sig)
48 {
49     if ((i0 != 0) && (i0 != 1)) {
50         throw std::domain_error("PRF_pk invoked with index out of bounds");
51     }
52
53     return PRF(0, i0, 0, 0, a_sk, h_sig);
54 }
55
56 uint256 PRF_rho(const uint252& phi, size_t i0, const uint256& h_sig)
57 {
58     if ((i0 != 0) && (i0 != 1)) {
59         throw std::domain_error("PRF_rho invoked with index out of bounds");
60     }
61
62     return PRF(0, i0, 1, 0, phi, h_sig);
63 }
This page took 0.028763 seconds and 4 git commands to generate.