Separate UI and test files
This commit is contained in:
parent
342dc1c50c
commit
3c802756aa
12
.gitignore
vendored
12
.gitignore
vendored
@ -14,9 +14,9 @@ test/test_xmssmt_core_fast_XMSSMT*
|
||||
test/test_determinism
|
||||
test/speed
|
||||
test/gen_testvectors
|
||||
test/xmss_keypair
|
||||
test/xmss_open
|
||||
test/xmss_sign
|
||||
test/xmssmt_keypair
|
||||
test/xmssmt_open
|
||||
test/xmssmt_sign
|
||||
ui/xmss_keypair
|
||||
ui/xmss_open
|
||||
ui/xmss_sign
|
||||
ui/xmssmt_keypair
|
||||
ui/xmssmt_open
|
||||
ui/xmssmt_sign
|
||||
|
18
Makefile
18
Makefile
@ -17,12 +17,12 @@ TESTS = test/test_wots \
|
||||
test/test_xmssmt \
|
||||
test/test_determinism \
|
||||
|
||||
UI = test/xmss_keypair \
|
||||
test/xmss_sign \
|
||||
test/xmss_open \
|
||||
test/xmssmt_keypair \
|
||||
test/xmssmt_sign \
|
||||
test/xmssmt_open \
|
||||
UI = ui/xmss_keypair \
|
||||
ui/xmss_sign \
|
||||
ui/xmss_open \
|
||||
ui/xmssmt_keypair \
|
||||
ui/xmssmt_sign \
|
||||
ui/xmssmt_open \
|
||||
|
||||
all: $(TESTS) $(UI)
|
||||
|
||||
@ -37,6 +37,12 @@ test/%: test/%.c $(SOURCES) $(OBJS) $(HEADERS)
|
||||
test/test_wots: params.c hash.c fips202.c hash_address.c randombytes.c wots.c xmss_commons.c test/test_wots.c params.h hash.h fips202.h hash_address.h randombytes.h wots.h xmss_commons.h
|
||||
$(CC) $(CFLAGS) params.c hash.c fips202.c hash_address.c randombytes.c wots.c xmss_commons.c test/test_wots.c -o $@ -lcrypto
|
||||
|
||||
ui/xmss_%: ui/%.c $(SOURCES) $(OBJS) $(HEADERS)
|
||||
$(CC) $(CFLAGS) -o $@ $(SOURCES) $< $(LDLIBS)
|
||||
|
||||
ui/xmssmt_%: ui/%.c $(SOURCES) $(OBJS) $(HEADERS)
|
||||
$(CC) -DXMSSMT $(CFLAGS) -o $@ $(SOURCES) $< $(LDLIBS)
|
||||
|
||||
clean:
|
||||
-$(RM) $(TESTS)
|
||||
-$(RM) $(UI)
|
||||
|
@ -1,30 +0,0 @@
|
||||
#include "../params.h"
|
||||
#include "../xmss.h"
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
xmss_params params;
|
||||
uint32_t oid;
|
||||
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Expected parameter string (e.g. 'XMSS-SHA2_10_256')"
|
||||
" as only parameter.\n"
|
||||
"The keypair is written to stdout.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
xmssmt_str_to_oid(&oid, argv[1]);
|
||||
xmssmt_parse_oid(¶ms, oid);
|
||||
|
||||
unsigned char pk[XMSS_OID_LEN + params.pk_bytes];
|
||||
unsigned char sk[XMSS_OID_LEN + params.sk_bytes];
|
||||
|
||||
xmssmt_keypair(pk, sk, oid);
|
||||
|
||||
fwrite(pk, 1, XMSS_OID_LEN + params.pk_bytes, stdout);
|
||||
fwrite(sk, 1, XMSS_OID_LEN + params.sk_bytes, stdout);
|
||||
|
||||
fclose(stdout);
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
#include "../params.h"
|
||||
#include "../xmss_core.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#define MLEN 32
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
FILE *keypair;
|
||||
xmss_params params;
|
||||
uint32_t oid;
|
||||
int ret;
|
||||
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Expected keypair filename as only parameter, "
|
||||
"and the signature + message via stdin.\n"
|
||||
"Keypair file needs only to contain the public key.\n"
|
||||
"The return code 0 indicates verification success.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
keypair = fopen(argv[1], "rb");
|
||||
if (keypair == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
fread(&oid, 1, XMSS_OID_LEN, keypair);
|
||||
xmssmt_parse_oid(¶ms, oid);
|
||||
|
||||
unsigned char pk[params.pk_bytes];
|
||||
unsigned char sm[params.sig_bytes + MLEN];
|
||||
unsigned char m[params.sig_bytes + MLEN];
|
||||
unsigned long long mlen;
|
||||
|
||||
fread(pk, 1, params.pk_bytes, keypair);
|
||||
fread(sm, 1, params.sig_bytes + MLEN, stdin);
|
||||
|
||||
ret = xmssmt_core_sign_open(¶ms, m, &mlen, sm, params.sig_bytes + MLEN, pk);
|
||||
|
||||
if (ret) {
|
||||
printf("Verification failed!\n");
|
||||
}
|
||||
else {
|
||||
printf("Verification succeeded.\n");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
#include "../params.h"
|
||||
#include "../xmss_core.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#define MLEN 32
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
FILE *keypair;
|
||||
xmss_params params;
|
||||
uint32_t oid_pk;
|
||||
uint32_t oid_sk;
|
||||
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Expected keypair filename as only parameter, "
|
||||
"and the message via stdin.\n"
|
||||
"The keypair is updated with the changed state, "
|
||||
"and the message + signature is output via stdout.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
keypair = fopen(argv[1], "r+b");
|
||||
if (keypair == NULL) {
|
||||
fprintf(stderr, "Could not open keypair file.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Read the OID from the public key, as we need its length to seek past it. */
|
||||
fread(&oid_pk, 1, XMSS_OID_LEN, keypair);
|
||||
xmssmt_parse_oid(¶ms, oid_pk);
|
||||
|
||||
/* fseek past the public key. */
|
||||
fseek(keypair, params.pk_bytes, SEEK_CUR);
|
||||
/* This is the OID we're actually going to use. Likely the same, but still.. */
|
||||
fread(&oid_sk, 1, XMSS_OID_LEN, keypair);
|
||||
xmssmt_parse_oid(¶ms, oid_sk);
|
||||
|
||||
unsigned char sk[params.sk_bytes];
|
||||
unsigned char m[MLEN];
|
||||
unsigned char sm[params.sig_bytes + MLEN];
|
||||
unsigned long long smlen;
|
||||
|
||||
fread(sk, 1, params.sk_bytes, keypair);
|
||||
fread(m, 1, MLEN, stdin);
|
||||
xmssmt_core_sign(¶ms, sk, sm, &smlen, m, MLEN);
|
||||
|
||||
fseek(keypair, -((long int)params.sk_bytes), SEEK_CUR);
|
||||
fwrite(sk, 1, params.sk_bytes, keypair);
|
||||
fwrite(sm, 1, params.sig_bytes + MLEN, stdout);
|
||||
|
||||
fclose(keypair);
|
||||
fclose(stdout);
|
||||
}
|
@ -3,6 +3,16 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef XMSSMT
|
||||
#define XMSS_STR_TO_OID xmssmt_str_to_oid
|
||||
#define XMSS_PARSE_OID xmssmt_parse_oid
|
||||
#define XMSS_KEYPAIR xmssmt_keypair
|
||||
#else
|
||||
#define XMSS_STR_TO_OID xmss_str_to_oid
|
||||
#define XMSS_PARSE_OID xmss_parse_oid
|
||||
#define XMSS_KEYPAIR xmss_keypair
|
||||
#endif
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
xmss_params params;
|
||||
@ -15,13 +25,13 @@ int main(int argc, char **argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
xmss_str_to_oid(&oid, argv[1]);
|
||||
xmss_parse_oid(¶ms, oid);
|
||||
XMSS_STR_TO_OID(&oid, argv[1]);
|
||||
XMSS_PARSE_OID(¶ms, oid);
|
||||
|
||||
unsigned char pk[XMSS_OID_LEN + params.pk_bytes];
|
||||
unsigned char sk[XMSS_OID_LEN + params.sk_bytes];
|
||||
|
||||
xmss_keypair(pk, sk, oid);
|
||||
XMSS_KEYPAIR(pk, sk, oid);
|
||||
|
||||
fwrite(pk, 1, XMSS_OID_LEN + params.pk_bytes, stdout);
|
||||
fwrite(sk, 1, XMSS_OID_LEN + params.sk_bytes, stdout);
|
@ -4,6 +4,14 @@
|
||||
|
||||
#define MLEN 32
|
||||
|
||||
#ifdef XMSSMT
|
||||
#define XMSS_PARSE_OID xmssmt_parse_oid
|
||||
#define XMSS_CORE_SIGN_OPEN xmssmt_core_sign_open
|
||||
#else
|
||||
#define XMSS_PARSE_OID xmss_parse_oid
|
||||
#define XMSS_CORE_SIGN_OPEN xmss_core_sign_open
|
||||
#endif
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
FILE *keypair;
|
||||
xmss_params params;
|
||||
@ -24,7 +32,7 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
|
||||
fread(&oid, 1, XMSS_OID_LEN, keypair);
|
||||
xmss_parse_oid(¶ms, oid);
|
||||
XMSS_PARSE_OID(¶ms, oid);
|
||||
|
||||
unsigned char pk[params.pk_bytes];
|
||||
unsigned char sm[params.sig_bytes + MLEN];
|
||||
@ -34,7 +42,7 @@ int main(int argc, char **argv) {
|
||||
fread(pk, 1, params.pk_bytes, keypair);
|
||||
fread(sm, 1, params.sig_bytes + MLEN, stdin);
|
||||
|
||||
ret = xmss_core_sign_open(¶ms, m, &mlen, sm, params.sig_bytes + MLEN, pk);
|
||||
ret = XMSS_CORE_SIGN_OPEN(¶ms, m, &mlen, sm, params.sig_bytes + MLEN, pk);
|
||||
|
||||
if (ret) {
|
||||
printf("Verification failed!\n");
|
@ -4,6 +4,14 @@
|
||||
|
||||
#define MLEN 32
|
||||
|
||||
#ifdef XMSSMT
|
||||
#define XMSS_PARSE_OID xmssmt_parse_oid
|
||||
#define XMSS_CORE_SIGN xmssmt_core_sign
|
||||
#else
|
||||
#define XMSS_PARSE_OID xmss_parse_oid
|
||||
#define XMSS_CORE_SIGN xmss_core_sign
|
||||
#endif
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
FILE *keypair;
|
||||
xmss_params params;
|
||||
@ -26,13 +34,13 @@ int main(int argc, char **argv) {
|
||||
|
||||
/* Read the OID from the public key, as we need its length to seek past it */
|
||||
fread(&oid_pk, 1, XMSS_OID_LEN, keypair);
|
||||
xmss_parse_oid(¶ms, oid_pk);
|
||||
XMSS_PARSE_OID(¶ms, oid_pk);
|
||||
|
||||
/* fseek past the public key */
|
||||
fseek(keypair, params.pk_bytes, SEEK_CUR);
|
||||
/* This is the OID we're actually going to use. Likely the same, but still. */
|
||||
fread(&oid_sk, 1, XMSS_OID_LEN, keypair);
|
||||
xmss_parse_oid(¶ms, oid_sk);
|
||||
XMSS_PARSE_OID(¶ms, oid_sk);
|
||||
|
||||
unsigned char sk[params.sk_bytes];
|
||||
unsigned char m[MLEN];
|
||||
@ -41,7 +49,7 @@ int main(int argc, char **argv) {
|
||||
|
||||
fread(sk, 1, params.sk_bytes, keypair);
|
||||
fread(m, 1, MLEN, stdin);
|
||||
xmss_core_sign(¶ms, sk, sm, &smlen, m, MLEN);
|
||||
XMSS_CORE_SIGN(¶ms, sk, sm, &smlen, m, MLEN);
|
||||
|
||||
fseek(keypair, -((long int)params.sk_bytes), SEEK_CUR);
|
||||
fwrite(sk, 1, params.sk_bytes, keypair);
|
Loading…
Reference in New Issue
Block a user