From d02f9995a8b7edb932c61265bef9dfea718a3657 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Fri, 27 May 2016 16:05:24 +0100 Subject: [PATCH] rct: add serialization machinery to rct types --- src/ringct/rctTypes.h | 42 +++++++++++++++++++++++++++++--------- src/serialization/crypto.h | 29 ++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 10 deletions(-) diff --git a/src/ringct/rctTypes.h b/src/ringct/rctTypes.h index b56a330b1..ee0b7a6d4 100644 --- a/src/ringct/rctTypes.h +++ b/src/ringct/rctTypes.h @@ -47,6 +47,9 @@ extern "C" { } #include "crypto/crypto.h" +#include "serialization/serialization.h" + + //Define this flag when debugging to get additional info on the console #ifdef DBG #define DP(x) dp(x) @@ -106,6 +109,12 @@ namespace rct { key mask; key amount; key senderPk; + + BEGIN_SERIALIZE_OBJECT() + FIELD(mask) + FIELD(amount) + FIELD(senderPk) + END_SERIALIZE() }; //containers for representing amounts @@ -132,6 +141,12 @@ namespace rct { keyM ss; key cc; keyV II; + + BEGIN_SERIALIZE_OBJECT() + FIELD(ss) + FIELD(cc) + FIELD(II) + END_SERIALIZE() }; //contains the data for an asnl sig // also contains the "Ci" values such that @@ -142,6 +157,11 @@ namespace rct { struct rangeSig { asnlSig asig; key64 Ci; + + BEGIN_SERIALIZE_OBJECT() + FIELD(asig) + FIELD(Ci) + END_SERIALIZE() }; //A container to hold all signatures necessary for RingCT // rangeSigs holds all the rangeproof data of a transaction @@ -157,15 +177,14 @@ namespace rct { //pairs that you mix with vector ecdhInfo; ctkeyV outPk; - }; - - struct rmsSig { - vector rangeSigs; - mgSig MG; - ctkeyM mixRing; - vector destinationEcdhInfo; - vector participantEcdhInfo; - ctkeyV outPk; + + BEGIN_SERIALIZE_OBJECT() + FIELD(rangeSigs) + FIELD(MG) + FIELD(mixRing) + FIELD(ecdhInfo) + FIELD(outPk) + END_SERIALIZE() }; //other basepoint H = toPoint(cn_fast_hash(G)), G the basepoint @@ -173,7 +192,7 @@ namespace rct { //H2 contains 2^i H in each index, i.e. H, 2H, 4H, 8H, ... //This is used for the range proofG - //You can regenerate this by running python2 Test.py HPow2 in the MiniNero repo + //You can regenerate this by running python2 Test.py HPow2 in the MiniNero repo static const key64 H2 = {{0x8b, 0x65, 0x59, 0x70, 0x15, 0x37, 0x99, 0xaf, 0x2a, 0xea, 0xdc, 0x9f, 0xf1, 0xad, 0xd0, 0xea, 0x6c, 0x72, 0x51, 0xd5, 0x41, 0x54, 0xcf, 0xa9, 0x2c, 0x17, 0x3a, 0x0d, 0xd3, 0x9c, 0x1f, 0x94}, {0x8f, 0xaa, 0x44, 0x8a, 0xe4, 0xb3, 0xe2, 0xbb, 0x3d, 0x4d, 0x13, 0x09, 0x09, 0xf5, 0x5f, 0xcd, 0x79, 0x71, 0x1c, 0x1c, 0x83, 0xcd, 0xbc, 0xca, 0xdd, 0x42, 0xcb, 0xe1, 0x51, 0x5e, 0x87, 0x12}, {0x12, 0xa7, 0xd6, 0x2c, 0x77, 0x91, 0x65, 0x4a, 0x57, 0xf3, 0xe6, 0x76, 0x94, 0xed, 0x50, 0xb4, 0x9a, 0x7d, 0x9e, 0x3f, 0xc1, 0xe4, 0xc7, 0xa0, 0xbd, 0xe2, 0x9d, 0x18, 0x7e, 0x9c, 0xc7, 0x1d}, @@ -270,4 +289,7 @@ namespace rct { xmr_amount b2d(bits amountb); } +template std::ostream &print256(std::ostream &o, const T &v); +inline std::ostream &operator <<(std::ostream &o, const rct::key &v) { return print256(o, v); } + #endif /* RCTTYPES_H */ diff --git a/src/serialization/crypto.h b/src/serialization/crypto.h index 3644b0e03..9babe698d 100644 --- a/src/serialization/crypto.h +++ b/src/serialization/crypto.h @@ -37,6 +37,7 @@ #include "crypto/chacha8.h" #include "crypto/crypto.h" #include "crypto/hash.h" +#include "ringct/rctTypes.h" // read template