You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.6 KiB

  1. #include "../params.h"
  2. #include "../xmss_core.h"
  3. #include <stdio.h>
  4. #define MLEN 32
  5. int main(int argc, char **argv) {
  6. FILE *keypair;
  7. xmss_params params;
  8. uint32_t oid_pk;
  9. uint32_t oid_sk;
  10. if (argc != 2) {
  11. fprintf(stderr, "Expected keypair filename as only parameter, "
  12. "and the message via stdin.\n"
  13. "The keypair is updated with the changed state, "
  14. "and the message + signature is output via stdout.\n");
  15. return -1;
  16. }
  17. keypair = fopen(argv[1], "r+b");
  18. if (keypair == NULL) {
  19. fprintf(stderr, "Could not open keypair file.\n");
  20. return -1;
  21. }
  22. /* Read the OID from the public key, as we need its length to seek past it */
  23. fread(&oid_pk, 1, XMSS_OID_LEN, keypair);
  24. xmss_parse_oid(&params, oid_pk);
  25. /* fseek past the public key */
  26. fseek(keypair, params.publickey_bytes, SEEK_CUR);
  27. /* This is the OID we're actually going to use. Likely the same, but still. */
  28. fread(&oid_sk, 1, XMSS_OID_LEN, keypair);
  29. xmss_parse_oid(&params, oid_sk);
  30. unsigned char sk[params.privatekey_bytes];
  31. unsigned char m[MLEN];
  32. unsigned char sm[params.bytes + MLEN];
  33. unsigned long long smlen;
  34. fread(sk, 1, params.privatekey_bytes, keypair);
  35. fread(m, 1, MLEN, stdin);
  36. xmss_core_sign(&params, sk, sm, &smlen, m, MLEN);
  37. fseek(keypair, -((long int)params.privatekey_bytes), SEEK_CUR);
  38. fwrite(sk, 1, params.privatekey_bytes, keypair);
  39. fwrite(sm, 1, params.bytes + MLEN, stdout);
  40. fclose(keypair);
  41. fclose(stdout);
  42. }