rct: add serialization machinery to rct types

This commit is contained in:
moneromooo-monero 2016-05-27 16:05:24 +01:00
parent 0ff8305426
commit d02f9995a8
No known key found for this signature in database
GPG key ID: 686F07454D6CEFC3
2 changed files with 61 additions and 10 deletions

View file

@ -47,6 +47,9 @@ extern "C" {
} }
#include "crypto/crypto.h" #include "crypto/crypto.h"
#include "serialization/serialization.h"
//Define this flag when debugging to get additional info on the console //Define this flag when debugging to get additional info on the console
#ifdef DBG #ifdef DBG
#define DP(x) dp(x) #define DP(x) dp(x)
@ -106,6 +109,12 @@ namespace rct {
key mask; key mask;
key amount; key amount;
key senderPk; key senderPk;
BEGIN_SERIALIZE_OBJECT()
FIELD(mask)
FIELD(amount)
FIELD(senderPk)
END_SERIALIZE()
}; };
//containers for representing amounts //containers for representing amounts
@ -132,6 +141,12 @@ namespace rct {
keyM ss; keyM ss;
key cc; key cc;
keyV II; keyV II;
BEGIN_SERIALIZE_OBJECT()
FIELD(ss)
FIELD(cc)
FIELD(II)
END_SERIALIZE()
}; };
//contains the data for an asnl sig //contains the data for an asnl sig
// also contains the "Ci" values such that // also contains the "Ci" values such that
@ -142,6 +157,11 @@ namespace rct {
struct rangeSig { struct rangeSig {
asnlSig asig; asnlSig asig;
key64 Ci; key64 Ci;
BEGIN_SERIALIZE_OBJECT()
FIELD(asig)
FIELD(Ci)
END_SERIALIZE()
}; };
//A container to hold all signatures necessary for RingCT //A container to hold all signatures necessary for RingCT
// rangeSigs holds all the rangeproof data of a transaction // rangeSigs holds all the rangeproof data of a transaction
@ -157,15 +177,14 @@ namespace rct {
//pairs that you mix with //pairs that you mix with
vector<ecdhTuple> ecdhInfo; vector<ecdhTuple> ecdhInfo;
ctkeyV outPk; ctkeyV outPk;
};
struct rmsSig { BEGIN_SERIALIZE_OBJECT()
vector<rangeSig> rangeSigs; FIELD(rangeSigs)
mgSig MG; FIELD(MG)
ctkeyM mixRing; FIELD(mixRing)
vector<ecdhTuple> destinationEcdhInfo; FIELD(ecdhInfo)
vector<ecdhTuple> participantEcdhInfo; FIELD(outPk)
ctkeyV outPk; END_SERIALIZE()
}; };
//other basepoint H = toPoint(cn_fast_hash(G)), G the basepoint //other basepoint H = toPoint(cn_fast_hash(G)), G the basepoint
@ -270,4 +289,7 @@ namespace rct {
xmr_amount b2d(bits amountb); xmr_amount b2d(bits amountb);
} }
template<typename T> 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 */ #endif /* RCTTYPES_H */

View file

@ -37,6 +37,7 @@
#include "crypto/chacha8.h" #include "crypto/chacha8.h"
#include "crypto/crypto.h" #include "crypto/crypto.h"
#include "crypto/hash.h" #include "crypto/hash.h"
#include "ringct/rctTypes.h"
// read // read
template <template <bool> class Archive> template <template <bool> class Archive>
@ -92,3 +93,31 @@ VARIANT_TAG(debug_archive, crypto::secret_key, "secret_key");
VARIANT_TAG(debug_archive, crypto::key_derivation, "key_derivation"); VARIANT_TAG(debug_archive, crypto::key_derivation, "key_derivation");
VARIANT_TAG(debug_archive, crypto::key_image, "key_image"); VARIANT_TAG(debug_archive, crypto::key_image, "key_image");
VARIANT_TAG(debug_archive, crypto::signature, "signature"); VARIANT_TAG(debug_archive, crypto::signature, "signature");
BLOB_SERIALIZER(rct::key);
BLOB_SERIALIZER(rct::key64);
BLOB_SERIALIZER(rct::ctkey);
BLOB_SERIALIZER(rct::ecdhTuple);
BLOB_SERIALIZER(rct::asnlSig);
VARIANT_TAG(debug_archive, rct::key, "rct::key");
VARIANT_TAG(debug_archive, rct::key64, "rct::key64");
VARIANT_TAG(debug_archive, rct::ctkey, "rct::ctkey");
VARIANT_TAG(debug_archive, rct::ecdhTuple, "rct::ecdhTuple");
VARIANT_TAG(debug_archive, rct::asnlSig, "rct::asnlSig");
VARIANT_TAG(debug_archive, rct::rctSig, "rct::rctSig");
VARIANT_TAG(binary_archive, rct::key, 0x90);
VARIANT_TAG(binary_archive, rct::key64, 0x91);
VARIANT_TAG(binary_archive, rct::ctkey, 0x92);
VARIANT_TAG(binary_archive, rct::ecdhTuple, 0x93);
VARIANT_TAG(binary_archive, rct::asnlSig, 0x94);
VARIANT_TAG(binary_archive, rct::rctSig, 0x95);
VARIANT_TAG(json_archive, rct::key, "rct_key");
VARIANT_TAG(json_archive, rct::key64, "rct_key64");
VARIANT_TAG(json_archive, rct::ctkey, "rct_ctkey");
VARIANT_TAG(json_archive, rct::ecdhTuple, "rct_ecdhTuple");
VARIANT_TAG(json_archive, rct::asnlSig, "rct_asnlSig");
VARIANT_TAG(json_archive, rct::rctSig, "rct_rctSig");