2017-10-17 16:11:18 +01:00
|
|
|
#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;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
xmss_parse_oid(¶ms, oid_pk);
|
|
|
|
|
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);
|
|
|
|
xmss_parse_oid(¶ms, oid_sk);
|
|
|
|
|
2017-10-24 16:51:56 +01:00
|
|
|
unsigned char sk[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-24 16:51:56 +01:00
|
|
|
fread(sk, 1, params.sk_bytes, keypair);
|
2017-10-17 16:11:18 +01:00
|
|
|
fread(m, 1, MLEN, stdin);
|
|
|
|
xmss_core_sign(¶ms, sk, sm, &smlen, m, MLEN);
|
|
|
|
|
2017-10-24 16:51:56 +01:00
|
|
|
fseek(keypair, -((long int)params.sk_bytes), SEEK_CUR);
|
|
|
|
fwrite(sk, 1, params.sk_bytes, keypair);
|
|
|
|
fwrite(sm, 1, params.sig_bytes + MLEN, stdout);
|
2017-10-17 16:11:18 +01:00
|
|
|
|
|
|
|
fclose(keypair);
|
|
|
|
fclose(stdout);
|
|
|
|
}
|