2017-10-17 16:11:18 +01:00
|
|
|
#include "../params.h"
|
2017-10-26 13:24:10 +01:00
|
|
|
#include "../xmss.h"
|
2017-10-17 16:11:18 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#define MLEN 32
|
|
|
|
|
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 xmssmt_sign
|
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 xmss_sign
|
2017-10-26 12:47:29 +01:00
|
|
|
#endif
|
|
|
|
|
2017-10-17 16:11:18 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-10-19 15:08:09 +01:00
|
|
|
keypair = fopen(argv[1], "r+b");
|
2017-10-17 16:11:18 +01:00
|
|
|
if (keypair == NULL) {
|
|
|
|
fprintf(stderr, "Could not open keypair file.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-10-23 13:10:39 +01:00
|
|
|
/* Read the OID from the public key, as we need its length to seek past it */
|
2017-10-17 16:11:18 +01:00
|
|
|
fread(&oid_pk, 1, XMSS_OID_LEN, keypair);
|
2017-10-26 12:47:29 +01:00
|
|
|
XMSS_PARSE_OID(¶ms, oid_pk);
|
2017-10-17 16:11:18 +01:00
|
|
|
|
2017-10-23 13:10:39 +01:00
|
|
|
/* fseek past the public key */
|
2017-10-24 16:51:56 +01:00
|
|
|
fseek(keypair, params.pk_bytes, SEEK_CUR);
|
2017-10-23 13:10:39 +01:00
|
|
|
/* This is the OID we're actually going to use. Likely the same, but still. */
|
2017-10-17 16:11:18 +01:00
|
|
|
fread(&oid_sk, 1, XMSS_OID_LEN, keypair);
|
2017-10-26 12:47:29 +01:00
|
|
|
XMSS_PARSE_OID(¶ms, oid_sk);
|
2017-10-17 16:11:18 +01:00
|
|
|
|
2017-10-26 13:24:10 +01:00
|
|
|
unsigned char sk[XMSS_OID_LEN + params.sk_bytes];
|
2017-10-17 16:11:18 +01:00
|
|
|
unsigned char m[MLEN];
|
2017-10-24 16:51:56 +01:00
|
|
|
unsigned char sm[params.sig_bytes + MLEN];
|
2017-10-17 16:11:18 +01:00
|
|
|
unsigned long long smlen;
|
|
|
|
|
2017-10-26 13:24:10 +01:00
|
|
|
/* fseek back to start of sk. */
|
|
|
|
fseek(keypair, -((long int)XMSS_OID_LEN), SEEK_CUR);
|
|
|
|
fread(sk, 1, XMSS_OID_LEN + params.sk_bytes, keypair);
|
2017-10-17 16:11:18 +01:00
|
|
|
fread(m, 1, MLEN, stdin);
|
2017-10-26 13:24:10 +01:00
|
|
|
|
|
|
|
XMSS_SIGN(sk, sm, &smlen, m, MLEN);
|
2017-10-17 16:11:18 +01:00
|
|
|
|
2017-10-24 16:51:56 +01:00
|
|
|
fseek(keypair, -((long int)params.sk_bytes), SEEK_CUR);
|
2017-10-26 13:24:10 +01:00
|
|
|
fwrite(sk + XMSS_OID_LEN, 1, params.sk_bytes, keypair);
|
2017-10-24 16:51:56 +01:00
|
|
|
fwrite(sm, 1, params.sig_bytes + MLEN, stdout);
|
2017-10-17 16:11:18 +01:00
|
|
|
|
|
|
|
fclose(keypair);
|
|
|
|
fclose(stdout);
|
|
|
|
}
|