Debian Codegraph @

src/ringct/rctSigs.h

raw symbols SCIP
1 // Copyright (c) 2016, Monero Research Labs
2 //
3 // Author: Shen Noether <[email protected]>
4 //
5 // All rights reserved.
6 //
7 // Redistribution and use in source and binary forms, with or without modification, are
8 // permitted provided that the following conditions are met:
9 //
10 // 1. Redistributions of source code must retain the above copyright notice, this list of
11 // conditions and the following disclaimer.
12 //
13 // 2. Redistributions in binary form must reproduce the above copyright notice, this list
14 // of conditions and the following disclaimer in the documentation and/or other
15 // materials provided with the distribution.
16 //
17 // 3. Neither the name of the copyright holder nor the names of its contributors may be
18 // used to endorse or promote products derived from this software without specific
19 // prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
22 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
24 // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
29 // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31 #pragma once
32
33 //#define DBG
34
35 #ifndef RCTSIGS_H
36 #define RCTSIGS_H
37
38 #include <cstddef>
39 #include <vector>
40 #include <tuple>
41
42 #include "crypto/generic-ops.h"
43
44 extern "C" {
45 #include "crypto/random.h"
46 #include "crypto/keccak.h"
47 }
48 #include "crypto/crypto.h"
49
50
51 #include "rctTypes.h"
52 #include "rctOps.h"
53
54 //Define this flag when debugging to get additional info on the console
55 #ifdef DBG
56 #define DP(x) dp(x)
57 #else
58 #define DP(x)
59 #endif
60
61 namespace hw {
62 class device;
63 }
64
65
66 namespace rct {
67
68 boroSig genBorromean(const key64 x, const key64 P1, const key64 P2, const bits indices);
69 bool verifyBorromean(const boroSig &bb, const key64 P1, const key64 P2);
70
71 //Multilayered Spontaneous Anonymous Group Signatures (MLSAG signatures)
72 //These are aka MG signatutes in earlier drafts of the ring ct paper
73 // c.f. https://eprint.iacr.org/2015/1098 section 2.
74 // Gen creates a signature which proves that for some column in the keymatrix "pk"
75 // the signer knows a secret key for each row in that column
76 // Ver verifies that the MG sig was created correctly
77 mgSig MLSAG_Gen(const key &message, const keyM & pk, const keyV & xx, const unsigned int index, size_t dsRows, hw::device &hwdev);
78 bool MLSAG_Ver(const key &message, const keyM &pk, const mgSig &sig, size_t dsRows);
79
80 clsag CLSAG_Gen(const key &message, const keyV & P, const key & p, const keyV & C, const key & z, const keyV & C_nonzero, const key & C_offset, const unsigned int l, hw::device &hwdev);
81 clsag CLSAG_Gen(const key &message, const keyV & P, const key & p, const keyV & C, const key & z, const keyV & C_nonzero, const key & C_offset, const unsigned int l);
82 clsag proveRctCLSAGSimple(const key &, const ctkeyV &, const ctkey &, const key &, const key &, unsigned int, hw::device &);
83 bool verRctCLSAGSimple(const key &, const clsag &, const ctkeyV &, const key &);
84
85 //proveRange and verRange
86 //proveRange gives C, and mask such that \sumCi = C
87 // c.f. https://eprint.iacr.org/2015/1098 section 5.1
88 // and Ci is a commitment to either 0 or 2^i, i=0,...,63
89 // thus this proves that "amount" is in [0, 2^64]
90 // mask is a such that C = aG + bH, and b = amount
91 //verRange verifies that \sum Ci = C and that each Ci is a commitment to 0 or 2^i
92 rangeSig proveRange(key & C, key & mask, const xmr_amount & amount);
93 bool verRange(const key & C, const rangeSig & as);
94
95 //Ring-ct MG sigs
96 //Prove:
97 // c.f. https://eprint.iacr.org/2015/1098 section 4. definition 10.
98 // This does the MG sig on the "dest" part of the given key matrix, and
99 // the last row is the sum of input commitments from that column - sum output commitments
100 // this shows that sum inputs = sum outputs
101 //Ver:
102 // verifies the above sig is created corretly
103 mgSig proveRctMG(const ctkeyM & pubs, const ctkeyV & inSk, const keyV &outMasks, const ctkeyV & outPk, unsigned int index, const key &txnFee, const key &message, hw::device &hwdev);
104 mgSig proveRctMGSimple(const key & message, const ctkeyV & pubs, const ctkey & inSk, const key &a , const key &Cout, unsigned int index, hw::device &hwdev);
105 bool verRctMG(const mgSig &mg, const ctkeyM & pubs, const ctkeyV & outPk, const key &txnFee, const key &message);
106 bool verRctMGSimple(const key &message, const mgSig &mg, const ctkeyV & pubs, const key & C);
107
108 //These functions get keys from blockchain
109 //replace these when connecting blockchain
110 //getKeyFromBlockchain grabs a key from the blockchain at "reference_index" to mix with
111 //populateFromBlockchain creates a keymatrix with "mixin" columns and one of the columns is inPk
112 // the return value are the key matrix, and the index where inPk was put (random).
113 void getKeyFromBlockchain(ctkey & a, size_t reference_index);
114 std::tuple<ctkeyM, xmr_amount> populateFromBlockchain(ctkeyV inPk, int mixin);
115
116 //RingCT protocol
117 //genRct:
118 // creates an rctSig with all data necessary to verify the rangeProofs and that the signer owns one of the
119 // columns that are claimed as inputs, and that the sum of inputs = sum of outputs.
120 // Also contains masked "amount" and "mask" so the receiver can see how much they received
121 //verRct:
122 // verifies that all signatures (rangeProogs, MG sig, sum inputs = outputs) are correct
123 //decodeRct: (c.f. https://eprint.iacr.org/2015/1098 section 5.1.1)
124 // uses the attached ecdh info to find the amounts represented by each output commitment
125 // must know the destination private key to find the correct amount, else will return a random number
126 rctSig genRct(const key &message, const ctkeyV & inSk, const keyV & destinations, const std::vector<xmr_amount> & amounts, const ctkeyM &mixRing, const keyV &amount_keys, unsigned int index, ctkeyV &outSk, const RCTConfig &rct_config, hw::device &hwdev);
127 rctSig genRct(const key &message, const ctkeyV & inSk, const ctkeyV & inPk, const keyV & destinations, const std::vector<xmr_amount> & amounts, const keyV &amount_keys, const int mixin, const RCTConfig &rct_config, hw::device &hwdev);
128 rctSig genRctSimple(const key & message, const ctkeyV & inSk, const ctkeyV & inPk, const keyV & destinations, const std::vector<xmr_amount> & inamounts, const std::vector<xmr_amount> & outamounts, const keyV &amount_keys, xmr_amount txnFee, unsigned int mixin, const RCTConfig &rct_config, hw::device &hwdev);
129 rctSig genRctSimple(const key & message, const ctkeyV & inSk, const keyV & destinations, const std::vector<xmr_amount> & inamounts, const std::vector<xmr_amount> & outamounts, xmr_amount txnFee, const ctkeyM & mixRing, const keyV &amount_keys, const std::vector<unsigned int> & index, ctkeyV &outSk, const RCTConfig &rct_config, hw::device &hwdev);
130 bool verRct(const rctSig & rv, bool semantics);
131 static inline bool verRct(const rctSig & rv) { return verRct(rv, true) && verRct(rv, false); }
132 bool verRctSemanticsSimple(const rctSig & rv);
133 bool verRctSemanticsSimple(const std::vector<const rctSig*> & rv);
134 bool verRctNonSemanticsSimple(const rctSig & rv);
135 static inline bool verRctSimple(const rctSig & rv) { return verRctSemanticsSimple(rv) && verRctNonSemanticsSimple(rv); }
136 xmr_amount decodeRct(const rctSig & rv, const key & sk, unsigned int i, key & mask, hw::device &hwdev);
137 xmr_amount decodeRct(const rctSig & rv, const key & sk, unsigned int i, hw::device &hwdev);
138 xmr_amount decodeRctSimple(const rctSig & rv, const key & sk, unsigned int i, key & mask, hw::device &hwdev);
139 xmr_amount decodeRctSimple(const rctSig & rv, const key & sk, unsigned int i, hw::device &hwdev);
140 key get_pre_mlsag_hash(const rctSig &rv, hw::device &hwdev);
141 }
142 #endif /* RCTSIGS_H */
143