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 "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<ecdhTuple> ecdhInfo;
ctkeyV outPk;
};
struct rmsSig {
vector<rangeSig> rangeSigs;
mgSig MG;
ctkeyM mixRing;
vector<ecdhTuple> destinationEcdhInfo;
vector<ecdhTuple> 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
@ -270,4 +289,7 @@ namespace rct {
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 */

View File

@ -37,6 +37,7 @@
#include "crypto/chacha8.h"
#include "crypto/crypto.h"
#include "crypto/hash.h"
#include "ringct/rctTypes.h"
// read
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_image, "key_image");
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");