2017-10-17 16:11:18 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2017-10-26 13:47:34 +01:00
|
|
|
#include "../params.h"
|
|
|
|
#include "../xmss.h"
|
2017-10-17 16:11:18 +01:00
|
|
|
|
2017-10-26 12:47:29 +01:00
|
|
|
#ifdef XMSSMT
|
|
|
|
#define XMSS_PARSE_OID xmssmt_parse_oid
|
2017-10-26 13:24:10 +01:00
|
|
|
#define XMSS_SIGN_OPEN xmssmt_sign_open
|
2017-10-26 12:47:29 +01:00
|
|
|
#else
|
|
|
|
#define XMSS_PARSE_OID xmss_parse_oid
|
2017-10-26 13:24:10 +01:00
|
|
|
#define XMSS_SIGN_OPEN xmss_sign_open
|
2017-10-26 12:47:29 +01:00
|
|
|
#endif
|
|
|
|
|
2017-10-17 16:11:18 +01:00
|
|
|
int main(int argc, char **argv) {
|
2017-10-26 13:47:34 +01:00
|
|
|
FILE *keypair_file;
|
|
|
|
FILE *sm_file;
|
|
|
|
|
2017-10-17 16:11:18 +01:00
|
|
|
xmss_params params;
|
|
|
|
uint32_t oid;
|
2017-10-26 13:47:34 +01:00
|
|
|
|
|
|
|
unsigned long long smlen;
|
2017-10-17 16:11:18 +01:00
|
|
|
int ret;
|
|
|
|
|
2017-10-26 13:47:34 +01:00
|
|
|
if (argc != 3) {
|
|
|
|
fprintf(stderr, "Expected keypair and signature + message filenames "
|
|
|
|
"as two parameters.\n"
|
2017-10-17 16:11:18 +01:00
|
|
|
"Keypair file needs only to contain the public key.\n"
|
|
|
|
"The return code 0 indicates verification success.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-10-26 13:47:34 +01:00
|
|
|
keypair_file = fopen(argv[1], "rb");
|
|
|
|
if (keypair_file == NULL) {
|
|
|
|
fprintf(stderr, "Could not open keypair file.\n");
|
2017-10-17 16:11:18 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-10-26 13:47:34 +01:00
|
|
|
sm_file = fopen(argv[2], "rb");
|
|
|
|
if (sm_file == NULL) {
|
|
|
|
fprintf(stderr, "Could not open signature + message file.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find out the message length. */
|
|
|
|
fseek(sm_file, 0, SEEK_END);
|
|
|
|
smlen = ftell(sm_file);
|
|
|
|
|
|
|
|
fread(&oid, 1, XMSS_OID_LEN, keypair_file);
|
2017-10-26 12:47:29 +01:00
|
|
|
XMSS_PARSE_OID(¶ms, oid);
|
2017-10-17 16:11:18 +01:00
|
|
|
|
2017-10-26 13:24:10 +01:00
|
|
|
unsigned char pk[XMSS_OID_LEN + params.pk_bytes];
|
2017-10-26 13:47:34 +01:00
|
|
|
unsigned char sm[smlen];
|
|
|
|
unsigned char m[smlen];
|
2017-10-17 16:11:18 +01:00
|
|
|
unsigned long long mlen;
|
|
|
|
|
2017-10-26 13:47:34 +01:00
|
|
|
fseek(keypair_file, 0, SEEK_SET);
|
|
|
|
fseek(sm_file, 0, SEEK_SET);
|
|
|
|
fread(pk, 1, XMSS_OID_LEN + params.pk_bytes, keypair_file);
|
|
|
|
fread(sm, 1, smlen, sm_file);
|
2017-10-17 16:11:18 +01:00
|
|
|
|
2017-10-26 13:47:34 +01:00
|
|
|
ret = XMSS_SIGN_OPEN(m, &mlen, sm, smlen, pk);
|
2017-10-17 16:11:18 +01:00
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
printf("Verification failed!\n");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf("Verification succeeded.\n");
|
|
|
|
}
|
|
|
|
|
2017-10-26 13:47:34 +01:00
|
|
|
fclose(keypair_file);
|
|
|
|
fclose(sm_file);
|
|
|
|
|
2017-10-17 16:11:18 +01:00
|
|
|
return ret;
|
|
|
|
}
|