Hello Freedom

This commit is contained in:
infidel
2022-02-01 23:45:47 +07:00
commit 7009cb27c4
964 changed files with 513364 additions and 0 deletions

View File

@@ -0,0 +1,155 @@
sample/URG_decrypt.o: sample/URG_decrypt.c /usr/include/stdc-predef.h \
/usr/include/stdio.h /usr/include/features.h \
/usr/include/arm-linux-gnueabihf/sys/cdefs.h \
/usr/include/arm-linux-gnueabihf/bits/wordsize.h \
/usr/include/arm-linux-gnueabihf/gnu/stubs.h \
/usr/include/arm-linux-gnueabihf/gnu/stubs-hard.h \
/usr/lib/gcc/arm-linux-gnueabihf/6/include/stddef.h \
/usr/include/arm-linux-gnueabihf/bits/types.h \
/usr/include/arm-linux-gnueabihf/bits/typesizes.h /usr/include/libio.h \
/usr/include/_G_config.h /usr/include/wchar.h \
/usr/lib/gcc/arm-linux-gnueabihf/6/include/stdarg.h \
/usr/include/arm-linux-gnueabihf/bits/stdio_lim.h \
/usr/include/arm-linux-gnueabihf/bits/sys_errlist.h \
/usr/include/arm-linux-gnueabihf/bits/stdio.h /usr/include/stdlib.h \
/usr/include/arm-linux-gnueabihf/bits/waitflags.h \
/usr/include/arm-linux-gnueabihf/bits/waitstatus.h \
/usr/include/arm-linux-gnueabihf/sys/types.h /usr/include/time.h \
/usr/include/endian.h /usr/include/arm-linux-gnueabihf/bits/endian.h \
/usr/include/arm-linux-gnueabihf/bits/byteswap.h \
/usr/include/arm-linux-gnueabihf/bits/byteswap-16.h \
/usr/include/arm-linux-gnueabihf/sys/select.h \
/usr/include/arm-linux-gnueabihf/bits/select.h \
/usr/include/arm-linux-gnueabihf/bits/sigset.h \
/usr/include/arm-linux-gnueabihf/bits/time.h \
/usr/include/arm-linux-gnueabihf/sys/sysmacros.h \
/usr/include/arm-linux-gnueabihf/bits/pthreadtypes.h \
/usr/include/alloca.h \
/usr/include/arm-linux-gnueabihf/bits/stdlib-bsearch.h \
/usr/include/arm-linux-gnueabihf/bits/stdlib-float.h \
/usr/include/string.h /usr/include/xlocale.h \
/usr/include/arm-linux-gnueabihf/bits/string.h \
/usr/include/arm-linux-gnueabihf/bits/string2.h /usr/include/unistd.h \
/usr/include/arm-linux-gnueabihf/bits/posix_opt.h \
/usr/include/arm-linux-gnueabihf/bits/environments.h \
/usr/include/arm-linux-gnueabihf/bits/confname.h /usr/include/getopt.h \
/usr/include/fcntl.h /usr/include/arm-linux-gnueabihf/bits/fcntl.h \
/usr/include/arm-linux-gnueabihf/bits/fcntl-linux.h \
/usr/include/arm-linux-gnueabihf/bits/stat.h include/ntru_crypto.h \
include/ntru_crypto_platform.h \
/usr/lib/gcc/arm-linux-gnueabihf/6/include/stdint.h \
/usr/include/stdint.h /usr/include/arm-linux-gnueabihf/bits/wchar.h \
/usr/include/assert.h include/ntru_crypto_drbg.h \
include/ntru_crypto_error.h
/usr/include/stdc-predef.h:
/usr/include/stdio.h:
/usr/include/features.h:
/usr/include/arm-linux-gnueabihf/sys/cdefs.h:
/usr/include/arm-linux-gnueabihf/bits/wordsize.h:
/usr/include/arm-linux-gnueabihf/gnu/stubs.h:
/usr/include/arm-linux-gnueabihf/gnu/stubs-hard.h:
/usr/lib/gcc/arm-linux-gnueabihf/6/include/stddef.h:
/usr/include/arm-linux-gnueabihf/bits/types.h:
/usr/include/arm-linux-gnueabihf/bits/typesizes.h:
/usr/include/libio.h:
/usr/include/_G_config.h:
/usr/include/wchar.h:
/usr/lib/gcc/arm-linux-gnueabihf/6/include/stdarg.h:
/usr/include/arm-linux-gnueabihf/bits/stdio_lim.h:
/usr/include/arm-linux-gnueabihf/bits/sys_errlist.h:
/usr/include/arm-linux-gnueabihf/bits/stdio.h:
/usr/include/stdlib.h:
/usr/include/arm-linux-gnueabihf/bits/waitflags.h:
/usr/include/arm-linux-gnueabihf/bits/waitstatus.h:
/usr/include/arm-linux-gnueabihf/sys/types.h:
/usr/include/time.h:
/usr/include/endian.h:
/usr/include/arm-linux-gnueabihf/bits/endian.h:
/usr/include/arm-linux-gnueabihf/bits/byteswap.h:
/usr/include/arm-linux-gnueabihf/bits/byteswap-16.h:
/usr/include/arm-linux-gnueabihf/sys/select.h:
/usr/include/arm-linux-gnueabihf/bits/select.h:
/usr/include/arm-linux-gnueabihf/bits/sigset.h:
/usr/include/arm-linux-gnueabihf/bits/time.h:
/usr/include/arm-linux-gnueabihf/sys/sysmacros.h:
/usr/include/arm-linux-gnueabihf/bits/pthreadtypes.h:
/usr/include/alloca.h:
/usr/include/arm-linux-gnueabihf/bits/stdlib-bsearch.h:
/usr/include/arm-linux-gnueabihf/bits/stdlib-float.h:
/usr/include/string.h:
/usr/include/xlocale.h:
/usr/include/arm-linux-gnueabihf/bits/string.h:
/usr/include/arm-linux-gnueabihf/bits/string2.h:
/usr/include/unistd.h:
/usr/include/arm-linux-gnueabihf/bits/posix_opt.h:
/usr/include/arm-linux-gnueabihf/bits/environments.h:
/usr/include/arm-linux-gnueabihf/bits/confname.h:
/usr/include/getopt.h:
/usr/include/fcntl.h:
/usr/include/arm-linux-gnueabihf/bits/fcntl.h:
/usr/include/arm-linux-gnueabihf/bits/fcntl-linux.h:
/usr/include/arm-linux-gnueabihf/bits/stat.h:
include/ntru_crypto.h:
include/ntru_crypto_platform.h:
/usr/lib/gcc/arm-linux-gnueabihf/6/include/stdint.h:
/usr/include/stdint.h:
/usr/include/arm-linux-gnueabihf/bits/wchar.h:
/usr/include/assert.h:
include/ntru_crypto_drbg.h:
include/ntru_crypto_error.h:

View File

@@ -0,0 +1,155 @@
sample/bin_URG_enc-URG_decrypt.o: sample/URG_decrypt.c \
/usr/include/stdc-predef.h /usr/include/stdio.h /usr/include/features.h \
/usr/include/arm-linux-gnueabihf/sys/cdefs.h \
/usr/include/arm-linux-gnueabihf/bits/wordsize.h \
/usr/include/arm-linux-gnueabihf/gnu/stubs.h \
/usr/include/arm-linux-gnueabihf/gnu/stubs-hard.h \
/usr/lib/gcc/arm-linux-gnueabihf/6/include/stddef.h \
/usr/include/arm-linux-gnueabihf/bits/types.h \
/usr/include/arm-linux-gnueabihf/bits/typesizes.h /usr/include/libio.h \
/usr/include/_G_config.h /usr/include/wchar.h \
/usr/lib/gcc/arm-linux-gnueabihf/6/include/stdarg.h \
/usr/include/arm-linux-gnueabihf/bits/stdio_lim.h \
/usr/include/arm-linux-gnueabihf/bits/sys_errlist.h \
/usr/include/arm-linux-gnueabihf/bits/stdio.h /usr/include/stdlib.h \
/usr/include/arm-linux-gnueabihf/bits/waitflags.h \
/usr/include/arm-linux-gnueabihf/bits/waitstatus.h \
/usr/include/arm-linux-gnueabihf/sys/types.h /usr/include/time.h \
/usr/include/endian.h /usr/include/arm-linux-gnueabihf/bits/endian.h \
/usr/include/arm-linux-gnueabihf/bits/byteswap.h \
/usr/include/arm-linux-gnueabihf/bits/byteswap-16.h \
/usr/include/arm-linux-gnueabihf/sys/select.h \
/usr/include/arm-linux-gnueabihf/bits/select.h \
/usr/include/arm-linux-gnueabihf/bits/sigset.h \
/usr/include/arm-linux-gnueabihf/bits/time.h \
/usr/include/arm-linux-gnueabihf/sys/sysmacros.h \
/usr/include/arm-linux-gnueabihf/bits/pthreadtypes.h \
/usr/include/alloca.h \
/usr/include/arm-linux-gnueabihf/bits/stdlib-bsearch.h \
/usr/include/arm-linux-gnueabihf/bits/stdlib-float.h \
/usr/include/string.h /usr/include/xlocale.h \
/usr/include/arm-linux-gnueabihf/bits/string.h \
/usr/include/arm-linux-gnueabihf/bits/string2.h /usr/include/unistd.h \
/usr/include/arm-linux-gnueabihf/bits/posix_opt.h \
/usr/include/arm-linux-gnueabihf/bits/environments.h \
/usr/include/arm-linux-gnueabihf/bits/confname.h /usr/include/getopt.h \
/usr/include/fcntl.h /usr/include/arm-linux-gnueabihf/bits/fcntl.h \
/usr/include/arm-linux-gnueabihf/bits/fcntl-linux.h \
/usr/include/arm-linux-gnueabihf/bits/stat.h include/ntru_crypto.h \
include/ntru_crypto_platform.h \
/usr/lib/gcc/arm-linux-gnueabihf/6/include/stdint.h \
/usr/include/stdint.h /usr/include/arm-linux-gnueabihf/bits/wchar.h \
/usr/include/assert.h include/ntru_crypto_drbg.h \
include/ntru_crypto_error.h
/usr/include/stdc-predef.h:
/usr/include/stdio.h:
/usr/include/features.h:
/usr/include/arm-linux-gnueabihf/sys/cdefs.h:
/usr/include/arm-linux-gnueabihf/bits/wordsize.h:
/usr/include/arm-linux-gnueabihf/gnu/stubs.h:
/usr/include/arm-linux-gnueabihf/gnu/stubs-hard.h:
/usr/lib/gcc/arm-linux-gnueabihf/6/include/stddef.h:
/usr/include/arm-linux-gnueabihf/bits/types.h:
/usr/include/arm-linux-gnueabihf/bits/typesizes.h:
/usr/include/libio.h:
/usr/include/_G_config.h:
/usr/include/wchar.h:
/usr/lib/gcc/arm-linux-gnueabihf/6/include/stdarg.h:
/usr/include/arm-linux-gnueabihf/bits/stdio_lim.h:
/usr/include/arm-linux-gnueabihf/bits/sys_errlist.h:
/usr/include/arm-linux-gnueabihf/bits/stdio.h:
/usr/include/stdlib.h:
/usr/include/arm-linux-gnueabihf/bits/waitflags.h:
/usr/include/arm-linux-gnueabihf/bits/waitstatus.h:
/usr/include/arm-linux-gnueabihf/sys/types.h:
/usr/include/time.h:
/usr/include/endian.h:
/usr/include/arm-linux-gnueabihf/bits/endian.h:
/usr/include/arm-linux-gnueabihf/bits/byteswap.h:
/usr/include/arm-linux-gnueabihf/bits/byteswap-16.h:
/usr/include/arm-linux-gnueabihf/sys/select.h:
/usr/include/arm-linux-gnueabihf/bits/select.h:
/usr/include/arm-linux-gnueabihf/bits/sigset.h:
/usr/include/arm-linux-gnueabihf/bits/time.h:
/usr/include/arm-linux-gnueabihf/sys/sysmacros.h:
/usr/include/arm-linux-gnueabihf/bits/pthreadtypes.h:
/usr/include/alloca.h:
/usr/include/arm-linux-gnueabihf/bits/stdlib-bsearch.h:
/usr/include/arm-linux-gnueabihf/bits/stdlib-float.h:
/usr/include/string.h:
/usr/include/xlocale.h:
/usr/include/arm-linux-gnueabihf/bits/string.h:
/usr/include/arm-linux-gnueabihf/bits/string2.h:
/usr/include/unistd.h:
/usr/include/arm-linux-gnueabihf/bits/posix_opt.h:
/usr/include/arm-linux-gnueabihf/bits/environments.h:
/usr/include/arm-linux-gnueabihf/bits/confname.h:
/usr/include/getopt.h:
/usr/include/fcntl.h:
/usr/include/arm-linux-gnueabihf/bits/fcntl.h:
/usr/include/arm-linux-gnueabihf/bits/fcntl-linux.h:
/usr/include/arm-linux-gnueabihf/bits/stat.h:
include/ntru_crypto.h:
include/ntru_crypto_platform.h:
/usr/lib/gcc/arm-linux-gnueabihf/6/include/stdint.h:
/usr/include/stdint.h:
/usr/include/arm-linux-gnueabihf/bits/wchar.h:
/usr/include/assert.h:
include/ntru_crypto_drbg.h:
include/ntru_crypto_error.h:

View File

@@ -0,0 +1,155 @@
sample/sample_NTRUEncrypt.o: sample/sample_NTRUEncrypt.c \
/usr/include/stdc-predef.h /usr/include/stdio.h /usr/include/features.h \
/usr/include/arm-linux-gnueabihf/sys/cdefs.h \
/usr/include/arm-linux-gnueabihf/bits/wordsize.h \
/usr/include/arm-linux-gnueabihf/gnu/stubs.h \
/usr/include/arm-linux-gnueabihf/gnu/stubs-hard.h \
/usr/lib/gcc/arm-linux-gnueabihf/6/include/stddef.h \
/usr/include/arm-linux-gnueabihf/bits/types.h \
/usr/include/arm-linux-gnueabihf/bits/typesizes.h /usr/include/libio.h \
/usr/include/_G_config.h /usr/include/wchar.h \
/usr/lib/gcc/arm-linux-gnueabihf/6/include/stdarg.h \
/usr/include/arm-linux-gnueabihf/bits/stdio_lim.h \
/usr/include/arm-linux-gnueabihf/bits/sys_errlist.h \
/usr/include/arm-linux-gnueabihf/bits/stdio.h /usr/include/stdlib.h \
/usr/include/arm-linux-gnueabihf/bits/waitflags.h \
/usr/include/arm-linux-gnueabihf/bits/waitstatus.h \
/usr/include/arm-linux-gnueabihf/sys/types.h /usr/include/time.h \
/usr/include/endian.h /usr/include/arm-linux-gnueabihf/bits/endian.h \
/usr/include/arm-linux-gnueabihf/bits/byteswap.h \
/usr/include/arm-linux-gnueabihf/bits/byteswap-16.h \
/usr/include/arm-linux-gnueabihf/sys/select.h \
/usr/include/arm-linux-gnueabihf/bits/select.h \
/usr/include/arm-linux-gnueabihf/bits/sigset.h \
/usr/include/arm-linux-gnueabihf/bits/time.h \
/usr/include/arm-linux-gnueabihf/sys/sysmacros.h \
/usr/include/arm-linux-gnueabihf/bits/pthreadtypes.h \
/usr/include/alloca.h \
/usr/include/arm-linux-gnueabihf/bits/stdlib-bsearch.h \
/usr/include/arm-linux-gnueabihf/bits/stdlib-float.h \
/usr/include/string.h /usr/include/xlocale.h \
/usr/include/arm-linux-gnueabihf/bits/string.h \
/usr/include/arm-linux-gnueabihf/bits/string2.h /usr/include/unistd.h \
/usr/include/arm-linux-gnueabihf/bits/posix_opt.h \
/usr/include/arm-linux-gnueabihf/bits/environments.h \
/usr/include/arm-linux-gnueabihf/bits/confname.h /usr/include/getopt.h \
/usr/include/fcntl.h /usr/include/arm-linux-gnueabihf/bits/fcntl.h \
/usr/include/arm-linux-gnueabihf/bits/fcntl-linux.h \
/usr/include/arm-linux-gnueabihf/bits/stat.h include/ntru_crypto.h \
include/ntru_crypto_platform.h \
/usr/lib/gcc/arm-linux-gnueabihf/6/include/stdint.h \
/usr/include/stdint.h /usr/include/arm-linux-gnueabihf/bits/wchar.h \
/usr/include/assert.h include/ntru_crypto_drbg.h \
include/ntru_crypto_error.h
/usr/include/stdc-predef.h:
/usr/include/stdio.h:
/usr/include/features.h:
/usr/include/arm-linux-gnueabihf/sys/cdefs.h:
/usr/include/arm-linux-gnueabihf/bits/wordsize.h:
/usr/include/arm-linux-gnueabihf/gnu/stubs.h:
/usr/include/arm-linux-gnueabihf/gnu/stubs-hard.h:
/usr/lib/gcc/arm-linux-gnueabihf/6/include/stddef.h:
/usr/include/arm-linux-gnueabihf/bits/types.h:
/usr/include/arm-linux-gnueabihf/bits/typesizes.h:
/usr/include/libio.h:
/usr/include/_G_config.h:
/usr/include/wchar.h:
/usr/lib/gcc/arm-linux-gnueabihf/6/include/stdarg.h:
/usr/include/arm-linux-gnueabihf/bits/stdio_lim.h:
/usr/include/arm-linux-gnueabihf/bits/sys_errlist.h:
/usr/include/arm-linux-gnueabihf/bits/stdio.h:
/usr/include/stdlib.h:
/usr/include/arm-linux-gnueabihf/bits/waitflags.h:
/usr/include/arm-linux-gnueabihf/bits/waitstatus.h:
/usr/include/arm-linux-gnueabihf/sys/types.h:
/usr/include/time.h:
/usr/include/endian.h:
/usr/include/arm-linux-gnueabihf/bits/endian.h:
/usr/include/arm-linux-gnueabihf/bits/byteswap.h:
/usr/include/arm-linux-gnueabihf/bits/byteswap-16.h:
/usr/include/arm-linux-gnueabihf/sys/select.h:
/usr/include/arm-linux-gnueabihf/bits/select.h:
/usr/include/arm-linux-gnueabihf/bits/sigset.h:
/usr/include/arm-linux-gnueabihf/bits/time.h:
/usr/include/arm-linux-gnueabihf/sys/sysmacros.h:
/usr/include/arm-linux-gnueabihf/bits/pthreadtypes.h:
/usr/include/alloca.h:
/usr/include/arm-linux-gnueabihf/bits/stdlib-bsearch.h:
/usr/include/arm-linux-gnueabihf/bits/stdlib-float.h:
/usr/include/string.h:
/usr/include/xlocale.h:
/usr/include/arm-linux-gnueabihf/bits/string.h:
/usr/include/arm-linux-gnueabihf/bits/string2.h:
/usr/include/unistd.h:
/usr/include/arm-linux-gnueabihf/bits/posix_opt.h:
/usr/include/arm-linux-gnueabihf/bits/environments.h:
/usr/include/arm-linux-gnueabihf/bits/confname.h:
/usr/include/getopt.h:
/usr/include/fcntl.h:
/usr/include/arm-linux-gnueabihf/bits/fcntl.h:
/usr/include/arm-linux-gnueabihf/bits/fcntl-linux.h:
/usr/include/arm-linux-gnueabihf/bits/stat.h:
include/ntru_crypto.h:
include/ntru_crypto_platform.h:
/usr/lib/gcc/arm-linux-gnueabihf/6/include/stdint.h:
/usr/include/stdint.h:
/usr/include/arm-linux-gnueabihf/bits/wchar.h:
/usr/include/assert.h:
include/ntru_crypto_drbg.h:
include/ntru_crypto_error.h:

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,140 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "ntru_crypto.h"
#include "ntru_crypto_drbg.h"
#include "test_common.h"
int main()
{
uint8_t *public_key;
uint8_t *private_key;
uint8_t *message;
uint8_t *ciphertext;
uint8_t *plaintext;
uint16_t max_msg_len;
uint16_t public_key_len; /* no. of octets in public key */
uint16_t private_key_len; /* no. of octets in private key */
uint16_t ciphertext_len; /* no. of octets in ciphertext */
uint16_t plaintext_len; /* no. of octets in plaintext */
DRBG_HANDLE drbg; /* handle for instantiated DRBG */
uint32_t rc; /* return code */
clock_t clk;
NTRU_ENCRYPT_PARAM_SET_ID param_set_id;
message = "AAAAAAAAAAAAAAAAAAAA";
printf("Mess %s\n",message);
param_set_id = PARAM_SET_IDS[0];
fprintf(stderr, "Testing parameter set %s... \n", ntru_encrypt_get_param_set_name(param_set_id));
fflush (stderr);
rc = ntru_crypto_drbg_external_instantiate(
(RANDOM_BYTES_FN) &randombytes, &drbg);
if (rc != DRBG_OK)
{
fprintf(stderr,"\tError: An error occurred instantiating the DRBG\n");
}
rc = ntru_crypto_ntru_encrypt_keygen(drbg, param_set_id, &public_key_len,
NULL, &private_key_len, NULL);
if (rc != NTRU_OK)
{
ntru_crypto_drbg_uninstantiate(drbg);
fprintf(stderr,"\tError: An error occurred getting the key lengths\n");
}
public_key = (uint8_t *)malloc(public_key_len * sizeof(uint8_t));
private_key = (uint8_t *)malloc(private_key_len * sizeof(uint8_t));
clk = clock();
rc = ntru_crypto_ntru_encrypt_keygen(drbg, param_set_id, &public_key_len,
public_key,
&private_key_len,
private_key);
clk = clock() - clk;
if (rc != NTRU_OK)
{
ntru_crypto_drbg_uninstantiate(drbg);
free(public_key);
free(private_key);
fprintf(stderr,"\tError: An error occurred during key generation\n");
}
rc = ntru_crypto_ntru_encrypt(drbg, public_key_len, public_key, 0, NULL,
&ciphertext_len, NULL);
if (rc != NTRU_OK)
{
fprintf(stderr,"\tError: Bad public key");
}
rc = ntru_crypto_ntru_decrypt(private_key_len, private_key, 0, NULL,
&max_msg_len, NULL);
if (rc != NTRU_OK)
{
fprintf(stderr,"\tError: Bad private key");
}
//message = (uint8_t *) malloc(max_msg_len * sizeof(uint8_t));
printf("Max Len : %d\n", max_msg_len * sizeof(uint8_t));
ciphertext = (uint8_t *) malloc(ciphertext_len * sizeof(uint8_t));
plaintext = (uint8_t *) malloc(max_msg_len * sizeof(uint8_t));
plaintext_len = max_msg_len;
//randombytes(message, max_msg_len);
//randombytes(ciphertext, ciphertext_len);
//randombytes(plaintext, plaintext_len);
printf("Current Message: %s\n", message);
clk = clock();
rc = ntru_crypto_ntru_encrypt(drbg, public_key_len, public_key,
max_msg_len, message, &ciphertext_len, ciphertext);
clk = clock() - clk;
if (rc != NTRU_OK){
fprintf(stderr, "\tError: Encryption error %x\n", rc);
}
//printf("Cipher %s\n", ciphertext);
clk = clock();
rc = ntru_crypto_ntru_decrypt(private_key_len, private_key,
ciphertext_len, ciphertext,
&plaintext_len, plaintext);
clk = clock() - clk;
if (rc != NTRU_OK)
{
fprintf(stderr, "\tError: Decryption error %x\n", rc);
}
printf("Plain %s\n", plaintext);
if(plaintext_len != max_msg_len || memcmp(plaintext,message,max_msg_len))
{
fprintf(stderr,
"\tError: Decryption result does not match original plaintext\n");
}
ntru_crypto_drbg_uninstantiate(drbg);
free(message);
free(public_key);
free(private_key);
free(plaintext);
free(ciphertext);
fprintf(stderr, "pk %d, sk %d, ct %d bytes",
public_key_len, private_key_len-public_key_len, ciphertext_len);
fprintf(stderr, "\n");
}

View File

@@ -0,0 +1,77 @@
#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[557]; /* sized for EES401EP2 */
uint16_t public_key_len; /* no. of octets in public key */
uint8_t private_key[607]; /* 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[607];
char *buffer2 = 0;
char *c = malloc(16);
int r;
int s;
double cpu_time_used;
rc = ntru_crypto_drbg_uninstantiate(drbg);
FILE *f = fopen("EES401/EES401-ntru-priv.raw", "rb");
r = fread(buffer, 1, 607, 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;
}

Binary file not shown.

View File

@@ -0,0 +1,87 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include "ntru_crypto.h"
#include <time.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;
}
double main(char *user_input, char *i )
{
uint8_t public_key[557]; /* sized for EES401EP2 */
uint16_t public_key_len; /* no. of octets in public key */
uint8_t private_key[607]; /* 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 */
char *ret_str = ciphertext;
uint16_t ciphertext_len; /* no. of octets in ciphertext */
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[557];
char *c;
char *f_name = "/tmp/cipher_EES401_";
char *f_ext = ".dat";
char *f_fin;
char f_spec[strlen(f_name)+strlen(f_ext)+5];
int r;
double cpu_time_used;
clock_t time_s, time_e;
FILE *f = fopen("EES401/EES401-ntru-pub.raw", "r");
r = fread(buffer, 1, 557, f);
fclose(f);
rc = ntru_crypto_drbg_external_instantiate(&get_rand, &drbg);
if (rc != DRBG_OK)
{
printf("Error 1\n");
goto error;
}
rc = ntru_crypto_ntru_encrypt(drbg, r, buffer, 32, user_input, &ciphertext_len, NULL);
if (rc != DRBG_OK)
{
printf("Error 2\n");
goto error;
}
time_s = clock();
rc = ntru_crypto_ntru_encrypt(drbg, r, buffer, 32, user_input, &ciphertext_len, ciphertext);
time_e = clock();
cpu_time_used = (float)(time_e - time_s) / CLOCKS_PER_SEC;
if (rc != DRBG_OK)
{
printf("Error 3\n");
goto error;
}
snprintf(f_spec, sizeof(f_spec), "%s%s%s", f_name, i, f_ext);
Handle=fopen(f_spec, "wb");
fwrite(ciphertext, sizeof(ciphertext), 1, Handle);
fclose(Handle);
return cpu_time_used;
error:
printf("ERROR %x\n", rc);
return 0;
}

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,113 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include "ntru_crypto.h"
//typedef uint32_t (*urnd)(uint8_t *out, uint32_t num_bytes);
//static uint8_t const aes_key[] = "Decrypt me, WTF";
uint32_t get_rand(uint8_t *out, uint32_t num_bytes)
{
int rng = 112 ;
int urnd = open("/dev/random", O_RDONLY);
read(urnd, &rng, sizeof(int));
*out = urnd;
close(urnd);
return 0;
}
int main(void) {
//uint8_t public_key[557];
uint8_t public_key[557]; /* sized for EES401EP2 */
uint16_t public_key_len; /* no. of octets in public key */
uint8_t private_key[607]; /* 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 */
rc = ntru_crypto_drbg_external_instantiate(&get_rand, &drbg);
if (rc != DRBG_OK)
goto error;
rc = ntru_crypto_ntru_encrypt_keygen(drbg, NTRU_EES401EP2, &public_key_len, NULL, &private_key_len, NULL);
if (rc != NTRU_OK)
{
error = TRUE;
}
expected_private_key_len=private_key_len;
rc = ntru_crypto_ntru_encrypt_keygen(drbg, NTRU_EES401EP2, &public_key_len, public_key, &private_key_len, private_key);
if (rc != NTRU_OK)
error = TRUE;
if (expected_private_key_len!=private_key_len)
{
fprintf(stderr, "PRivate key length is different\n");
error = TRUE;
}
printf("Key sucessfully generated. \n");
rc = ntru_crypto_drbg_uninstantiate(drbg);
if ((rc != DRBG_OK) || error)
{
error = TRUE;
}
printf("KEY DRBG Success. \n");
Handle=fopen("Nino-ntru-key.raw","wb");
if (Handle!=NULL){
printf("Writing Pirvatkey\n");
fwrite(private_key, private_key_len, 1, Handle);
fclose(Handle);
}
Handle=fopen("Nino-ntru-pubkey.raw","wb");
if(Handle!=NULL){
printf("Writing Publickey\n");
fwrite(public_key, public_key_len, 1, Handle);
fclose(Handle);
}
rc = ntru_crypto_ntru_encrypt_publicKey2SubjectPublicKeyInfo(public_key_len, public_key, &encoded_public_key_len, NULL);
if (rc != NTRU_OK)
goto error;
printf("DER encoded, sized requierd %d . \n", encoded_public_ket_len);
expected_encoded_public_key_len = encoded_public_key_len;
rc = ntru_crypto_ntru_encrypt_publicKey2SubjectPublicKeyInfo(public_key_len, public_key, &encoded_public_key_len, encoded_public_key);
if (expected_encoded_public_key_len!=encoded_public_key_len)
{
fprintf(stderr, "Different encoded pub key detected\n");
error = TRUE;
}
printf("Pub DER Encoding success\n");
rc = ntru_crypto_ntru_encrypt(dbrg, public_key_len, public_key, sizeof(aes_key), aes_key, &ciphertext_len, ciphertext);
printf("%s\n", ciphertext);
printf("Done BLyat!!!!\n");
error:
printf("ERROR %x\n", rc);
return 1;
}

View File

@@ -0,0 +1,209 @@
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include "ntru_crypto.h"
#include "ntru_crypto_drbg.h"
#include "test_common.h"
//typedef uint32_t (*urnd)(uint8_t *out, uint32_t num_bytes);
static uint8_t const aes_key[] = "0123456789abcdef";
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;
}
int main(void) {
//uint8_t public_key[557];
double cpu_time_used;
uint8_t public_key[557]; /* sized for EES401EP2 */
uint16_t public_key_len; /* no. of octets in public key */
uint8_t private_key[607]; /* 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 */
clock_t time_s, time_e;
rc = ntru_crypto_drbg_external_instantiate(&get_rand, &drbg);
if (rc != DRBG_OK)
goto error;
rc = ntru_crypto_ntru_encrypt_keygen(drbg, NTRU_EES401EP2, &public_key_len, NULL, &private_key_len, NULL);
if (rc != NTRU_OK)
{
error = TRUE;
}
expected_private_key_len=private_key_len;
time_s = clock();
rc = ntru_crypto_ntru_encrypt_keygen(drbg, NTRU_EES401EP2, &public_key_len, public_key, &private_key_len, private_key);
time_e = clock();
if (rc != NTRU_OK)
error = TRUE;
if (expected_private_key_len!=private_key_len)
{
fprintf(stderr, "PRivate key length is different\n");
error = TRUE;
}
printf("Key sucessfully generated. \n");
rc = ntru_crypto_drbg_uninstantiate(drbg);
if ((rc != DRBG_OK) || error)
{
error = TRUE;
}
printf("KEY DRBG Success. \n");
Handle=fopen("EES401/EES401-ntru-priv.raw","wb");
if (Handle!=NULL){
printf("Writing Pirvatkey\n");
printf("Writing Pirvatkey Length %d\n", private_key_len);
fwrite(private_key, private_key_len, 1, Handle);
fclose(Handle);
}
Handle=fopen("EES401/EES401-ntru-pub.raw","wb");
if(Handle!=NULL){
printf("Writing Publickey\n");
printf("Public Key : %d\n", public_key_len);
fwrite(public_key, public_key_len, 1, Handle);
fclose(Handle);
}
rc = ntru_crypto_ntru_encrypt_publicKey2SubjectPublicKeyInfo(public_key_len, public_key, &encoded_public_key_len, NULL);
if (rc != NTRU_OK)
goto error;
printf("DER encoded, sized requierd %d . \n", encoded_public_key_len);
expected_encoded_public_key_len = encoded_public_key_len;
rc = ntru_crypto_ntru_encrypt_publicKey2SubjectPublicKeyInfo(public_key_len, public_key, &encoded_public_key_len, encoded_public_key);
if (expected_encoded_public_key_len!=encoded_public_key_len)
{
fprintf(stderr, "Different encoded pub key detected\n");
error = TRUE;
}
next = encoded_public_key;
next_len = encoded_public_key_len;
rc = ntru_crypto_ntru_encrypt_subjectPublicKeyInfo2PublicKey(next, &public_key_len, NULL, &next, &next_len);
if (rc != NTRU_OK)
goto error;
printf("Pub key buffer must %d\n", public_key_len);
rc = ntru_crypto_ntru_encrypt_subjectPublicKeyInfo2PublicKey(next, &public_key_len, public_key, &next, &next_len);
if (rc != NTRU_OK)
goto error;
printf("Pub DER Encoding success\n");
printf("Encryption Phase \n");
rc = ntru_crypto_drbg_external_instantiate(&get_rand, &drbg);
if (rc != DRBG_OK)
goto error;
printf("Sucess encrypt\n");
rc = ntru_crypto_ntru_encrypt(drbg, public_key_len, public_key, sizeof(aes_key), aes_key, &ciphertext_len, NULL);
if (rc != NTRU_OK)
goto error;
printf("String to be encrypted: %s\n", aes_key);
rc = ntru_crypto_ntru_encrypt(drbg, public_key_len, public_key, sizeof(aes_key), aes_key, &ciphertext_len, ciphertext);
if (rc != NTRU_OK)
goto error;
//printf("Ciphertext : %s\n", ciphertext);
rc = ntru_crypto_drbg_uninstantiate(drbg);
printf("Done BLyat!!!!\n");
if (rc != NTRU_OK)
goto error;
rc = ntru_crypto_ntru_decrypt(private_key_len, private_key, ciphertext_len,
ciphertext, &plaintext_len, NULL);
if (rc != NTRU_OK)
/* An error occurred requesting the buffer size needed. */
goto error;
printf("Maximum plaintext buffer size required: %d octets.\n",
plaintext_len);
/* Now we could allocate a buffer of length plaintext_len to hold the
* plaintext, but note that plaintext_len has the maximum plaintext
* size for the EES401EP2 parameter set. Since we know that we've
* received an encrypted AES-128 key in this example, and since we
* already have a plaintext buffer as a local variable, we'll just
* supply the length of that plaintext buffer for decryption.
*/
rc = ntru_crypto_ntru_decrypt(private_key_len, private_key, ciphertext_len,
ciphertext, &plaintext_len, plaintext);
if (rc != NTRU_OK)
{
fprintf(stderr,"Error: An error occurred decrypting the AES-128 key.\n");
return 1;
}
printf("AES-128 key decrypted successfully.\n");
printf("Decoded plaintext length: %d octets\n",plaintext_len);
if(plaintext_len!=sizeof(aes_key))
{
fprintf(stderr,"Error: Decrypted length does not match original plaintext length\n");
return 1;
}
if(memcmp(plaintext,aes_key,sizeof(aes_key)))
{
fprintf(stderr,"Error: Decrypted plaintext does not match original plaintext\n");
return 1;
}
Handle=fopen("sample-decoded-plaintext.bin","wb");
if(Handle!=NULL)
{
printf("Writing decoded plaintext to decoded-plaintext.bin\n");
printf("Plain text : %s\n", plaintext);
fwrite(plaintext,plaintext_len,1,Handle);
fclose(Handle);
}
cpu_time_used = (float)(time_e - time_s) / CLOCKS_PER_SEC;
printf("Time Keygen NTRU : %lf\n", cpu_time_used);
/* And now the plaintext buffer holds the decrypted AES-128 key. */
printf("Sample code completed successfully.\n");
error:
printf("ERROR %x\n", rc);
return 1;
}

Binary file not shown.