gestumblinde

Gestumblinde - reference implementation of SLH-DSA
git clone git://www.tkruger.se/gestumblinde.git
Log | Files | Refs | README

verif.c (1423B)


      1 #include "clcommon.h"
      2 #include "slh.h"
      3 #include <stdio.h>
      4 
      5 static void print_usage(char *command) {
      6   printf("usage: %s <pk_file> <sig_file>\n\n", command);
      7   printf("    pk_file:   public key input filename\n");
      8   printf("    sig_file:  signature input filename\n\n");
      9   printf("The program will read the message from standard\n");
     10   printf("input and print \"TRUE\" to standard output if\n");
     11   printf("the verification succeeds, otherwise \"FALSE\"\n");
     12 }
     13 
     14 int main(int argc, char *argv[]) {
     15   if (argc != 3) {
     16     print_usage(argv[0]);
     17     return 1;
     18   }
     19 
     20   uint8_t pk[2 * ENN];
     21   FILE *pk_file = fopen(argv[1], "r");
     22   if (pk_file == NULL) {
     23     fprintf(stderr, "Error! Could not open file %s\n", argv[1]);
     24     return 1;
     25   }
     26 
     27   size_t r = fread(pk, sizeof(*pk), 2 * ENN, pk_file);
     28   if (r < 2 * ENN) {
     29     fprintf(stderr, "Error! Failed to read public key from %s\n", argv[1]);
     30     return 1;
     31   }
     32 
     33   uint8_t sig[SLH_SIGNATURE_LEN];
     34   FILE *sig_file = fopen(argv[2], "r");
     35   if (sig_file == NULL) {
     36     fprintf(stderr, "Error! Could not open file %s\n", argv[2]);
     37     return 1;
     38   }
     39 
     40   r = fread(sig, sizeof(*sig), SLH_SIGNATURE_LEN, sig_file);
     41 
     42   size_t mlen;
     43   uint8_t *m;
     44   if (read_message_from_stdin(&m, &mlen)) {
     45     fprintf(stderr, "Error! Failed to read message from stdin.\n");
     46     return 1;
     47   }
     48 
     49   if (slh_verify(m, mlen, sig, r, pk)) {
     50     printf("TRUE\n");
     51   } else {
     52     printf("FALSE\n");
     53   }
     54 
     55   return 0;
     56 }