Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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_OPEN xmssmt_sign_open
  8. #else
  9. #define XMSS_PARSE_OID xmss_parse_oid
  10. #define XMSS_SIGN_OPEN xmss_sign_open
  11. #endif
  12. int main(int argc, char **argv) {
  13. FILE *keypair_file;
  14. FILE *sm_file;
  15. xmss_params params;
  16. uint32_t oid;
  17. unsigned long long smlen;
  18. int ret;
  19. if (argc != 3) {
  20. fprintf(stderr, "Expected keypair and signature + message filenames "
  21. "as two parameters.\n"
  22. "Keypair file needs only to contain the public key.\n"
  23. "The return code 0 indicates verification success.\n");
  24. return -1;
  25. }
  26. keypair_file = fopen(argv[1], "rb");
  27. if (keypair_file == NULL) {
  28. fprintf(stderr, "Could not open keypair file.\n");
  29. return -1;
  30. }
  31. sm_file = fopen(argv[2], "rb");
  32. if (sm_file == NULL) {
  33. fprintf(stderr, "Could not open signature + message file.\n");
  34. return -1;
  35. }
  36. /* Find out the message length. */
  37. fseek(sm_file, 0, SEEK_END);
  38. smlen = ftell(sm_file);
  39. fread(&oid, 1, XMSS_OID_LEN, keypair_file);
  40. XMSS_PARSE_OID(&params, oid);
  41. unsigned char pk[XMSS_OID_LEN + params.pk_bytes];
  42. unsigned char *sm = malloc(smlen);
  43. unsigned char *m = malloc(smlen);
  44. unsigned long long mlen;
  45. fseek(keypair_file, 0, SEEK_SET);
  46. fseek(sm_file, 0, SEEK_SET);
  47. fread(pk, 1, XMSS_OID_LEN + params.pk_bytes, keypair_file);
  48. fread(sm, 1, smlen, sm_file);
  49. ret = XMSS_SIGN_OPEN(m, &mlen, sm, smlen, pk);
  50. if (ret) {
  51. printf("Verification failed!\n");
  52. }
  53. else {
  54. printf("Verification succeeded.\n");
  55. }
  56. fclose(keypair_file);
  57. fclose(sm_file);
  58. free(m);
  59. free(sm);
  60. return ret;
  61. }