#include "ntru_crypto.h" #include #include #include #include #include #include uint32_t get_rand(uint8_t *out, uint32_t num_bytes) { int rng = 50; int urnd = open("/dev/random", O_RDONLY); read(urnd, &rng, sizeof(int)); *out = urnd; close(urnd); return 0; } char *main(char *user_input) { uint8_t public_key[557]; /* sized for EES401EP2 */ uint16_t public_key_len; /* no. of octets in public key */ uint8_t private_key[638]; /* sized for EES401EP2 */ uint16_t private_key_len; /* no. of octets in private key */ uint16_t expected_private_key_len; uint16_t expected_encoded_public_key_len; uint8_t encoded_public_key[593]; /* sized for EES401EP2 */ uint16_t encoded_public_key_len; /* no. of octets in encoded public key */ uint8_t ciphertext[552]; /* sized fof EES401EP2 */ uint16_t ciphertext_len; /* no. of octets in ciphertext */ uint8_t plaintext[16]; /* size of AES-128 key */ uint16_t plaintext_len; /* no. of octets in plaintext */ uint8_t *next = NULL; /* points to next cert field to parse */ uint32_t next_len; /* no. of octets it next */ DRBG_HANDLE drbg; /* handle for instantiated DRBG */ uint32_t rc; /* return code */ bool error = FALSE; /* records if error occurred */ FILE *Handle = NULL; /* File Handle for writing NTRU key to file */ char *filename[33]; char **ptr = filename; char buffer[638]; char *buffer2 = 0; char *c = malloc(16); int r; int s; double cpu_time_used; rc = ntru_crypto_drbg_uninstantiate(drbg); FILE *f = fopen("keys/key-401.priv", "rb"); r = fread(buffer, 1, 638, f); fclose(f); // printf("C Log DEC: %d bytes Private Key\n", r); // printf("C Log DEC: user_input Len %d\n", sizeof(user_input)); rc = ntru_crypto_ntru_decrypt(r, buffer, 552, user_input, &plaintext_len, NULL); if (rc != NTRU_OK) printf("ERROR 1\n"); rc = ntru_crypto_ntru_decrypt(r, buffer, 552, user_input, &plaintext_len, plaintext); if (rc != NTRU_OK) printf("ERROR 2\n"); // printf("C Log DEC : your plain: %s\n", plaintext); // printf("C Log DEC : your plain LEN: %d\n", plaintext_len); // printf("your time spent: %lf\n", cpu_time_used); // snprintf(c, sizeof(c), "%s", plaintext); strcpy(c, plaintext); return c; error: printf("PROBLEM BUDDY %d\n", rc); exit(EXIT_FAILURE); return 0; }