sign.c (1258B)
1 #include "clcommon.h" 2 #include "slh.h" 3 #include <stdio.h> 4 5 #define RANDOMIZE 0 // randomisation off 6 7 static void print_usage(char *command) { 8 printf("usage: %s <sk_file>\n\n", command); 9 printf(" sk_file: secret key input filename\n\n"); 10 printf("The program will read the data to sign from standard\n"); 11 printf("input and write the signature to standard output.\n"); 12 } 13 14 int main(int argc, char *argv[]) { 15 if (argc != 2) { 16 print_usage(argv[0]); 17 return 1; 18 } 19 20 uint8_t sk[4 * ENN]; 21 22 FILE *sk_file = fopen(argv[1], "r"); 23 if (sk_file == NULL) { 24 fprintf(stderr, "Error! Could not open file %s\n", argv[1]); 25 return 1; 26 } 27 28 size_t r = fread(sk, sizeof(*sk), 4 * ENN, sk_file); 29 if (r < 4 * ENN) { 30 fprintf(stderr, "Error! Failed to read secret key from %s\n", argv[1]); 31 return 1; 32 } 33 34 size_t mlen; 35 uint8_t *m; 36 if (read_message_from_stdin(&m, &mlen)) { 37 fprintf(stderr, "Error! Failed to read message from stdin.\n"); 38 return 1; 39 } 40 41 uint8_t sig[SLH_SIGNATURE_LEN]; 42 slh_sign(sig, m, mlen, sk, RANDOMIZE); 43 44 free(m); 45 46 r = fwrite(sig, sizeof(*sig), SLH_SIGNATURE_LEN, stdout); 47 48 if (r != SLH_SIGNATURE_LEN) { 49 fprintf(stderr, "Error! An error occured on write!\n"); 50 return 1; 51 } 52 53 return 0; 54 }