72 lines
2.5 KiB
C
72 lines
2.5 KiB
C
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <string.h>
|
||
|
#include <unistd.h>
|
||
|
#include <fcntl.h>
|
||
|
#include <time.h>
|
||
|
#include "ntru_crypto.h"
|
||
|
|
||
|
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[821]; /* sized for EES401EP2 */
|
||
|
uint16_t public_key_len; /* no. of octets in public key */
|
||
|
uint8_t private_key[891]; /* 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[855]; /* sized for EES401EP2 */
|
||
|
uint16_t encoded_public_key_len; /* no. of octets in encoded public key */
|
||
|
uint8_t ciphertext[816]; /* sized fof EES401EP2 */
|
||
|
uint16_t ciphertext_len; /* no. of octets in ciphertext */
|
||
|
uint8_t plaintext[86]; /* 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 buffer[891];
|
||
|
char *buffer2 = 0;
|
||
|
char *c = malloc(86);
|
||
|
char *d = malloc(816);
|
||
|
int r;
|
||
|
int s;
|
||
|
|
||
|
double cpu_time_used;
|
||
|
Handle=fopen("EES593/EES593-ntru-priv.raw", "rb");
|
||
|
r = fread(buffer, 1,891, Handle);
|
||
|
fclose(Handle);
|
||
|
|
||
|
|
||
|
printf("C Log DEC: %d bytes Private Key\n", r);
|
||
|
printf("C Log DEC: user_input Len %d\n", sizeof(user_input));
|
||
|
|
||
|
strcpy(d, user_input);
|
||
|
rc = ntru_crypto_ntru_decrypt(r, buffer, 816,user_input, &plaintext_len, NULL);
|
||
|
|
||
|
rc = ntru_crypto_ntru_decrypt(r, buffer, 816,user_input, &plaintext_len, plaintext);
|
||
|
|
||
|
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;
|
||
|
}
|
||
|
|