Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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.pk_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.sk_bytes];
  31. unsigned char m[MLEN];
  32. unsigned char sm[params.sig_bytes + MLEN];
  33. unsigned long long smlen;
  34. fread(sk, 1, params.sk_bytes, keypair);
  35. fread(m, 1, MLEN, stdin);
  36. xmss_core_sign(&params, sk, sm, &smlen, m, MLEN);
  37. fseek(keypair, -((long int)params.sk_bytes), SEEK_CUR);
  38. fwrite(sk, 1, params.sk_bytes, keypair);
  39. fwrite(sm, 1, params.sig_bytes + MLEN, stdout);
  40. fclose(keypair);
  41. fclose(stdout);
  42. }