54 return 0 != memcmp(&
a, &b,
sizeof(
ec_point));
63 int
main(
int argc,
char *argv[]) {
71 cerr <<
"invalid arguments" << endl;
74 input.open(argv[1], ios_base::in);
77 input.exceptions(ios_base::badbit);
78 if (!(input >> cmd)) {
81 input.exceptions(ios_base::badbit | ios_base::failbit | ios_base::eofbit);
82 if (cmd ==
"check_scalar") {
84 bool expected, actual;
85 get(input, scalar, expected);
87 if (expected != actual) {
90 }
else if (cmd ==
"random_scalar") {
94 if (expected != actual) {
97 }
else if (cmd ==
"hash_to_scalar") {
100 get(input, data, expected);
102 if (expected != actual) {
105 }
else if (cmd ==
"generate_keys") {
108 get(input, expected1, expected2);
110 if (expected1 != actual1 || expected2 != actual2) {
113 }
else if (cmd ==
"check_key") {
115 bool expected, actual;
116 get(input,
key, expected);
118 if (expected != actual) {
121 }
else if (cmd ==
"secret_key_to_public_key") {
123 bool expected1, actual1;
125 get(input, sec, expected1);
127 get(input, expected2);
130 if (expected1 != actual1 || (expected1 && expected2 != actual2)) {
133 }
else if (cmd ==
"generate_key_derivation") {
136 bool expected1, actual1;
138 get(input, key1, key2, expected1);
140 get(input, expected2);
143 if (expected1 != actual1 || (expected1 && expected2 != actual2)) {
146 }
else if (cmd ==
"derive_public_key") {
150 bool expected1, actual1;
154 get(input, expected2);
157 if (expected1 != actual1 || (expected1 && expected2 != actual2)) {
160 }
else if (cmd ==
"derive_secret_key") {
167 if (expected != actual) {
170 }
else if (cmd ==
"generate_signature") {
175 get(input, prefix_hash, pub, sec, expected);
177 if (expected != actual) {
180 }
else if (cmd ==
"check_signature") {
184 bool expected, actual;
185 get(input, prefix_hash, pub, sig, expected);
187 if (expected != actual) {
190 }
else if (cmd ==
"hash_to_point") {
193 get(input, h, expected);
195 if (expected != actual) {
198 }
else if (cmd ==
"hash_to_ec") {
201 get(input,
key, expected);
203 if (expected != actual) {
206 }
else if (cmd ==
"generate_key_image") {
210 get(input, pub, sec, expected);
212 if (expected != actual) {
215 }
else if (cmd ==
"generate_ring_signature") {
218 vector<public_key> vpubs;
219 vector<const public_key *> pubs;
223 vector<signature> expected, actual;
225 get(input, prefix_hash, image, pubs_count);
226 vpubs.resize(pubs_count);
227 pubs.resize(pubs_count);
228 for (i = 0; i < pubs_count; i++) {
229 get(input, vpubs[i]);
232 get(input, sec, sec_index);
233 expected.resize(pubs_count);
235 actual.resize(pubs_count);
237 if (expected != actual) {
240 }
else if (cmd ==
"check_ring_signature") {
243 vector<public_key> vpubs;
244 vector<const public_key *> pubs;
246 vector<signature> sigs;
247 bool expected, actual;
249 get(input, prefix_hash, image, pubs_count);
250 vpubs.resize(pubs_count);
251 pubs.resize(pubs_count);
252 for (i = 0; i < pubs_count; i++) {
253 get(input, vpubs[i]);
256 sigs.resize(pubs_count);
258 get(input, expected);
260 if (expected != actual) {
264 throw ios_base::failure(
"Unknown function: " + cmd);
268 cerr <<
"Wrong result on test " << test << endl;
271 return error ? 1 : 0;
#define DISABLE_GCC_WARNING
void derive_secret_key(const key_derivation &derivation, std::size_t output_index, const secret_key &base, secret_key &derived_key)
int main(int argc, char *argv[])
void hash_to_ec(const crypto::public_key &key, crypto::ec_point &res)
bool check_ring_signature(const hash &prefix_hash, const key_image &image, const public_key *const *pubs, std::size_t pubs_count, const signature *sig)
void generate_signature(const hash &prefix_hash, const public_key &pub, const secret_key &sec, signature &sig)
bool generate_key_derivation(const public_key &key1, const secret_key &key2, key_derivation &derivation)
void hash_to_point(const crypto::hash &h, crypto::ec_point &res)
void generate_key_image(const public_key &pub, const secret_key &sec, key_image &image)
void getvar(std::istream &input, std::size_t length, void *res)
void generate_ring_signature(const hash &prefix_hash, const key_image &image, const public_key *const *pubs, std::size_t pubs_count, const secret_key &sec, std::size_t sec_index, signature *sig)
bool check_scalar(const crypto::ec_scalar &scalar)
secret_key generate_keys(public_key &pub, secret_key &sec, const secret_key &recovery_key=secret_key(), bool recover=false)
bool operator!=(const ec_scalar &a, const ec_scalar &b)
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
bool derive_public_key(const key_derivation &derivation, std::size_t output_index, const public_key &base, public_key &derived_key)
bool check_key(const public_key &key)
void hash_to_scalar(const void *data, size_t length, ec_scalar &res)
bool secret_key_to_public_key(const secret_key &sec, public_key &pub)
#define CATCH_ENTRY_L0(lacation, return_val)
error
Tracks LMDB error codes.
bool check_signature(const hash &prefix_hash, const public_key &pub, const signature &sig)
void random_scalar(ec_scalar &res)