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.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "../params.h"
  4. #include "../xmss.h"
  5. #ifdef XMSSMT
  6. #define XMSS_PARSE_OID xmssmt_parse_oid
  7. #define XMSS_SIGN xmssmt_sign
  8. #else
  9. #define XMSS_PARSE_OID xmss_parse_oid
  10. #define XMSS_SIGN xmss_sign
  11. #endif
  12. int main(int argc, char **argv) {
  13. FILE *keypair_file;
  14. FILE *m_file;
  15. xmss_params params;
  16. uint32_t oid_pk;
  17. uint32_t oid_sk;
  18. unsigned long long mlen;
  19. if (argc != 3) {
  20. fprintf(stderr, "Expected keypair and message filenames as two "
  21. "parameters.\n"
  22. "The keypair is updated with the changed state, "
  23. "and the message + signature is output via stdout.\n");
  24. return -1;
  25. }
  26. keypair_file = fopen(argv[1], "r+b");
  27. if (keypair_file == NULL) {
  28. fprintf(stderr, "Could not open keypair file.\n");
  29. return -1;
  30. }
  31. m_file = fopen(argv[2], "rb");
  32. if (m_file == NULL) {
  33. fprintf(stderr, "Could not open message file.\n");
  34. return -1;
  35. }
  36. /* Find out the message length. */
  37. fseek(m_file, 0, SEEK_END);
  38. mlen = ftell(m_file);
  39. /* Read the OID from the public key, as we need its length to seek past it */
  40. fread(&oid_pk, 1, XMSS_OID_LEN, keypair_file);
  41. XMSS_PARSE_OID(&params, oid_pk);
  42. /* fseek past the public key */
  43. fseek(keypair_file, params.pk_bytes, SEEK_CUR);
  44. /* This is the OID we're actually going to use. Likely the same, but still. */
  45. fread(&oid_sk, 1, XMSS_OID_LEN, keypair_file);
  46. XMSS_PARSE_OID(&params, oid_sk);
  47. unsigned char sk[XMSS_OID_LEN + params.sk_bytes];
  48. unsigned char *m = malloc(mlen);
  49. unsigned char *sm = malloc(params.sig_bytes + mlen);
  50. unsigned long long smlen;
  51. /* fseek back to start of sk. */
  52. fseek(keypair_file, -((long int)XMSS_OID_LEN), SEEK_CUR);
  53. fseek(m_file, 0, SEEK_SET);
  54. fread(sk, 1, XMSS_OID_LEN + params.sk_bytes, keypair_file);
  55. fread(m, 1, mlen, m_file);
  56. XMSS_SIGN(sk, sm, &smlen, m, mlen);
  57. fseek(keypair_file, -((long int)params.sk_bytes), SEEK_CUR);
  58. fwrite(sk + XMSS_OID_LEN, 1, params.sk_bytes, keypair_file);
  59. fwrite(sm, 1, smlen, stdout);
  60. fclose(keypair_file);
  61. fclose(m_file);
  62. free(m);
  63. free(sm);
  64. return 0;
  65. }