blob: c5890b22e2a0682cd409f4a62d604bc1a5874b30 [file] [log] [blame]
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
#include <string.h>
#include "test.h"
#include "amcl/mta.h"
/* MTA Range Proof challenge unit tests */
#define LINE_LEN 2048
int main(int argc, char **argv)
if (argc != 2)
printf("usage: ./test_mta_rp_challenge [path to test vector file]\n");
int test_run = 0;
FILE *fp;
char line[LINE_LEN] = {0};
const char *TESTline = "TEST = ";
int testNo = 0;
MTA_RP_commitment co;
const char *Zline = "Z = ";
const char *Uline = "U = ";
const char *Wline = "W = ";
COMMITMENTS_BC_pub_modulus mod;
const char *NTline = "NT = ";
const char *H1line = "H1 = ";
const char *H2line = "H2 = ";
PAILLIER_public_key pub;
const char *Nline = "N = ";
char c[2*FS_2048];
octet C = {0, sizeof(c), c};
const char *Cline = "C = ";
char e_golden[MODBYTES_512_60];
octet E_GOLDEN = {0, sizeof(e_golden), e_golden};
const char *Eline = "E = ";
char e[MODBYTES_512_60];
octet E = {0, sizeof(e), e};
// Line terminating a test vector
const char *last_line = Eline;
/* Test happy path using test vectors */
fp = fopen(argv[1], "r");
if (fp == NULL)
printf("ERROR opening test vector file\n");
while (fgets(line, LINE_LEN, fp) != NULL)
scan_int(&testNo, line, TESTline);
// Read inputs
scan_OCTET(fp, &C, line, Cline);
scan_FF_2048(fp, mod.b0, line, H1line, FFLEN_2048);
scan_FF_2048(fp, mod.b1, line, H2line, FFLEN_2048);
scan_FF_2048(fp, mod.N, line, NTline, FFLEN_2048);
scan_FF_2048(fp, co.z, line, Zline, FFLEN_2048);
scan_FF_4096(fp, co.u, line, Uline, FFLEN_4096);
scan_FF_2048(fp, co.w, line, Wline, FFLEN_2048);
scan_FF_4096(fp, pub.n, line, Nline, HFLEN_4096);
// Read ground truth
scan_OCTET(fp, &E_GOLDEN, line, Eline);
if (!strncmp(line, last_line, strlen(last_line)))
MTA_RP_challenge(&pub, &mod, &C, &co, &E);
compare_OCT(fp, testNo, "MTA_RP_challenge. E", &E, &E_GOLDEN);
// Mark that at least one test vector was executed
test_run = 1;
if (test_run == 0)
printf("ERROR no test vector was executed\n");