Remove fixed message length from UI
This commit is contained in:
parent
dd1ae2a6aa
commit
d340e0700d
@ -1,8 +1,9 @@
|
|||||||
#include "../params.h"
|
|
||||||
#include "../xmss.h"
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "../params.h"
|
||||||
|
#include "../xmss.h"
|
||||||
|
|
||||||
#ifdef XMSSMT
|
#ifdef XMSSMT
|
||||||
#define XMSS_STR_TO_OID xmssmt_str_to_oid
|
#define XMSS_STR_TO_OID xmssmt_str_to_oid
|
||||||
#define XMSS_PARSE_OID xmssmt_parse_oid
|
#define XMSS_PARSE_OID xmssmt_parse_oid
|
||||||
|
50
ui/open.c
50
ui/open.c
@ -1,8 +1,7 @@
|
|||||||
#include "../params.h"
|
|
||||||
#include "../xmss.h"
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#define MLEN 32
|
#include "../params.h"
|
||||||
|
#include "../xmss.h"
|
||||||
|
|
||||||
#ifdef XMSSMT
|
#ifdef XMSSMT
|
||||||
#define XMSS_PARSE_OID xmssmt_parse_oid
|
#define XMSS_PARSE_OID xmssmt_parse_oid
|
||||||
@ -13,37 +12,53 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
FILE *keypair;
|
FILE *keypair_file;
|
||||||
|
FILE *sm_file;
|
||||||
|
|
||||||
xmss_params params;
|
xmss_params params;
|
||||||
uint32_t oid;
|
uint32_t oid;
|
||||||
|
|
||||||
|
unsigned long long smlen;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (argc != 2) {
|
if (argc != 3) {
|
||||||
fprintf(stderr, "Expected keypair filename as only parameter, "
|
fprintf(stderr, "Expected keypair and signature + message filenames "
|
||||||
"and the signature + message via stdin.\n"
|
"as two parameters.\n"
|
||||||
"Keypair file needs only to contain the public key.\n"
|
"Keypair file needs only to contain the public key.\n"
|
||||||
"The return code 0 indicates verification success.\n");
|
"The return code 0 indicates verification success.\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
keypair = fopen(argv[1], "rb");
|
keypair_file = fopen(argv[1], "rb");
|
||||||
if (keypair == NULL) {
|
if (keypair_file == NULL) {
|
||||||
|
fprintf(stderr, "Could not open keypair file.\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fread(&oid, 1, XMSS_OID_LEN, keypair);
|
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);
|
||||||
XMSS_PARSE_OID(¶ms, oid);
|
XMSS_PARSE_OID(¶ms, oid);
|
||||||
|
|
||||||
unsigned char pk[XMSS_OID_LEN + params.pk_bytes];
|
unsigned char pk[XMSS_OID_LEN + params.pk_bytes];
|
||||||
unsigned char sm[params.sig_bytes + MLEN];
|
unsigned char sm[smlen];
|
||||||
unsigned char m[params.sig_bytes + MLEN];
|
unsigned char m[smlen];
|
||||||
unsigned long long mlen;
|
unsigned long long mlen;
|
||||||
|
|
||||||
fseek(keypair, 0, SEEK_SET);
|
fseek(keypair_file, 0, SEEK_SET);
|
||||||
fread(pk, 1, XMSS_OID_LEN + params.pk_bytes, keypair);
|
fseek(sm_file, 0, SEEK_SET);
|
||||||
fread(sm, 1, params.sig_bytes + MLEN, stdin);
|
fread(pk, 1, XMSS_OID_LEN + params.pk_bytes, keypair_file);
|
||||||
|
fread(sm, 1, smlen, sm_file);
|
||||||
|
|
||||||
ret = XMSS_SIGN_OPEN(m, &mlen, sm, params.sig_bytes + MLEN, pk);
|
ret = XMSS_SIGN_OPEN(m, &mlen, sm, smlen, pk);
|
||||||
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
printf("Verification failed!\n");
|
printf("Verification failed!\n");
|
||||||
@ -52,5 +67,8 @@ int main(int argc, char **argv) {
|
|||||||
printf("Verification succeeded.\n");
|
printf("Verification succeeded.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fclose(keypair_file);
|
||||||
|
fclose(sm_file);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
60
ui/sign.c
60
ui/sign.c
@ -1,8 +1,7 @@
|
|||||||
#include "../params.h"
|
|
||||||
#include "../xmss.h"
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#define MLEN 32
|
#include "../params.h"
|
||||||
|
#include "../xmss.h"
|
||||||
|
|
||||||
#ifdef XMSSMT
|
#ifdef XMSSMT
|
||||||
#define XMSS_PARSE_OID xmssmt_parse_oid
|
#define XMSS_PARSE_OID xmssmt_parse_oid
|
||||||
@ -13,51 +12,66 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
FILE *keypair;
|
FILE *keypair_file;
|
||||||
|
FILE *m_file;
|
||||||
|
|
||||||
xmss_params params;
|
xmss_params params;
|
||||||
uint32_t oid_pk;
|
uint32_t oid_pk;
|
||||||
uint32_t oid_sk;
|
uint32_t oid_sk;
|
||||||
|
|
||||||
if (argc != 2) {
|
unsigned long long mlen;
|
||||||
fprintf(stderr, "Expected keypair filename as only parameter, "
|
|
||||||
"and the message via stdin.\n"
|
if (argc != 3) {
|
||||||
|
fprintf(stderr, "Expected keypair and message filenames as two "
|
||||||
|
"parameters.\n"
|
||||||
"The keypair is updated with the changed state, "
|
"The keypair is updated with the changed state, "
|
||||||
"and the message + signature is output via stdout.\n");
|
"and the message + signature is output via stdout.\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
keypair = fopen(argv[1], "r+b");
|
keypair_file = fopen(argv[1], "r+b");
|
||||||
if (keypair == NULL) {
|
if (keypair_file == NULL) {
|
||||||
fprintf(stderr, "Could not open keypair file.\n");
|
fprintf(stderr, "Could not open keypair file.\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_file = fopen(argv[2], "rb");
|
||||||
|
if (m_file == NULL) {
|
||||||
|
fprintf(stderr, "Could not open message file.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Find out the message length. */
|
||||||
|
fseek(m_file, 0, SEEK_END);
|
||||||
|
mlen = ftell(m_file);
|
||||||
|
|
||||||
/* Read the OID from the public key, as we need its length to seek past it */
|
/* Read the OID from the public key, as we need its length to seek past it */
|
||||||
fread(&oid_pk, 1, XMSS_OID_LEN, keypair);
|
fread(&oid_pk, 1, XMSS_OID_LEN, keypair_file);
|
||||||
XMSS_PARSE_OID(¶ms, oid_pk);
|
XMSS_PARSE_OID(¶ms, oid_pk);
|
||||||
|
|
||||||
/* fseek past the public key */
|
/* fseek past the public key */
|
||||||
fseek(keypair, params.pk_bytes, SEEK_CUR);
|
fseek(keypair_file, params.pk_bytes, SEEK_CUR);
|
||||||
/* This is the OID we're actually going to use. Likely the same, but still. */
|
/* This is the OID we're actually going to use. Likely the same, but still. */
|
||||||
fread(&oid_sk, 1, XMSS_OID_LEN, keypair);
|
fread(&oid_sk, 1, XMSS_OID_LEN, keypair_file);
|
||||||
XMSS_PARSE_OID(¶ms, oid_sk);
|
XMSS_PARSE_OID(¶ms, oid_sk);
|
||||||
|
|
||||||
unsigned char sk[XMSS_OID_LEN + params.sk_bytes];
|
unsigned char sk[XMSS_OID_LEN + params.sk_bytes];
|
||||||
unsigned char m[MLEN];
|
unsigned char m[mlen];
|
||||||
unsigned char sm[params.sig_bytes + MLEN];
|
unsigned char sm[params.sig_bytes + mlen];
|
||||||
unsigned long long smlen;
|
unsigned long long smlen;
|
||||||
|
|
||||||
/* fseek back to start of sk. */
|
/* fseek back to start of sk. */
|
||||||
fseek(keypair, -((long int)XMSS_OID_LEN), SEEK_CUR);
|
fseek(keypair_file, -((long int)XMSS_OID_LEN), SEEK_CUR);
|
||||||
fread(sk, 1, XMSS_OID_LEN + params.sk_bytes, keypair);
|
fseek(m_file, 0, SEEK_SET);
|
||||||
fread(m, 1, MLEN, stdin);
|
fread(sk, 1, XMSS_OID_LEN + params.sk_bytes, keypair_file);
|
||||||
|
fread(m, 1, mlen, m_file);
|
||||||
|
|
||||||
XMSS_SIGN(sk, sm, &smlen, m, MLEN);
|
XMSS_SIGN(sk, sm, &smlen, m, mlen);
|
||||||
|
|
||||||
fseek(keypair, -((long int)params.sk_bytes), SEEK_CUR);
|
fseek(keypair_file, -((long int)params.sk_bytes), SEEK_CUR);
|
||||||
fwrite(sk + XMSS_OID_LEN, 1, params.sk_bytes, keypair);
|
fwrite(sk + XMSS_OID_LEN, 1, params.sk_bytes, keypair_file);
|
||||||
fwrite(sm, 1, params.sig_bytes + MLEN, stdout);
|
fwrite(sm, 1, smlen, stdout);
|
||||||
|
|
||||||
fclose(keypair);
|
fclose(keypair_file);
|
||||||
fclose(stdout);
|
fclose(m_file);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user