From 674aaaed7c23069a8bbba67115ddc7c61204c2a5 Mon Sep 17 00:00:00 2001 From: geoffrey Date: Tue, 5 Mar 2024 14:16:00 +0100 Subject: [PATCH] remove backup files --- prng.cpp_bck | 98 ---------------------------------------------- prng.h_bck | 28 ------------- rsa.c_bck | 108 --------------------------------------------------- 3 files changed, 234 deletions(-) delete mode 100644 prng.cpp_bck delete mode 100644 prng.h_bck delete mode 100644 rsa.c_bck diff --git a/prng.cpp_bck b/prng.cpp_bck deleted file mode 100644 index f825cbb..0000000 --- a/prng.cpp_bck +++ /dev/null @@ -1,98 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include "prng.h" -#include - -#define MAX_ENTRIES_ENTROPY 100 - -void init_entropy(){ - struct entropy_pool s_pool; - randomSeed(analogRead(0)); - while (s_entropy.pool_size < BUFSIZE){ - s_entropy.buf[s_entropy.pool_size++] = random(300); - } -} - -// Define a range ??? -unsigned long prng(int seed){ - //int32_t p = 4242; - unsigned long p = seed; - - //p = 4242; - //p ^= p << 3; // XOR - // 1000010010010 -> 4242 - // 1000010010010000 -> 33936 - // 1001010000000010 -> 37890 - //printf("%d\n", p); - - // For small value, increase the value ? - p ^= (p << 1) | (p << 2); - - // Generate number between 1000 and 5000 ??? - // Or to add X bits to have the key number, for instance 32 bits - - return p; -} - -int prng2 () { - double *pool_entropy = entropy_pool(); - int pos = 0; - - entropy_cpu_clock(pool_entropy, 0, MAX_ENTRIES_ENTROPY); - pos++; - - for(int i = 0; i < MAX_ENTRIES_ENTROPY; i++){ - //printf("%f\n", pool_entropy[i]); - } - - // Get from pool - // Generate an integer from 0 to 100 (with clock CPU) for instance - // And to pick up to the pool - - // Generate entropy with the network ? - - free(pool_entropy); - return(0); -} -double *entropy_pool(){ - double *pool_entropy = (double *)malloc(sizeof(double) * MAX_ENTRIES_ENTROPY); - - if (pool_entropy == NULL){ - //printf("Failed to allocate variables\n"); - exit(-1); - } - return pool_entropy; -} -void entropy_cpu_clock(double *entropy, int pos, int max){ - clock_t start_t, end_t; - double total_t; - double res = 0; - - start_t = clock(); - //printf("Starting of the program, start_t = %ld\n", start_t); - - //printf("Going to scan a big loop, start_t = %ld\n", start_t); - for(int i = 0; i < 10000000; i++) { - } - end_t = clock(); - //printf("End of the big loop, end_t = %ld\n", end_t); - - total_t = (double)(end_t - start_t) / CLOCKS_PER_SEC; - //printf("Total time taken by CPU: %f\n", total_t ); - //printf("Exiting of the program...\n"); - - entropy[pos] = total_t; - - // Test - generate an iteger from 0 to 100 - - // Multiply the 10 first entries - for (int i = 0; i < 10; i++){ - res += entropy[0]; - } - - //printf("Pos: %f\n", ceil(res * 100)); -} diff --git a/prng.h_bck b/prng.h_bck deleted file mode 100644 index ac1e78d..0000000 --- a/prng.h_bck +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef H_PRNG -#define H_PRNG - -#define BUFSIZE 128 - -struct entropy_pool{ - unsigned long buf[BUFSIZE]; - int pool_size; -}; - -extern struct entropy_pool s_entropy; - -void init_entropy(); -unsigned long prng(int); -int prng2(); -static void readDevRandom(char *); -double *entropy_pool(); -void entropy_cpu_clock(double *, int, int); - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/rsa.c_bck b/rsa.c_bck deleted file mode 100644 index 9d8e926..0000000 --- a/rsa.c_bck +++ /dev/null @@ -1,108 +0,0 @@ -#include -#include -#include "rsa.h" -#include "prng.h" - -void generateKeys(unsigned long *e, unsigned long *d, unsigned long *n){ - unsigned long p = prng(25); - unsigned long q = prng(47); - unsigned long phi = 0; - - // Generate big numbers of p and q - //generateBigNumber(&p); - //generateBigNumber(&q); - - // Check if p and q are prime numbers - if (isPrimeNumber(p) != 0) - prime_number_finder(&p); - - if (isPrimeNumber(q) != 0) - prime_number_finder(&q); - - // Calculate n - *n = p * q; - - // We're going to calcule the Euler's totient - // Our number are prime number, so, phi = (p - 1) * (q - 1) - phi = (p - 1)*(q - 1); - - /* We will calculate e for the public key */ - generatePublicKey(phi, e); - - /* We will calcuate d for the private key */ - generatePrivateKey(d, phi, e); - - /* For encrypting - m = ( message ** e) % n - exemple!: A -> 0x65 - (65 ** 4033) % 6938083 = 1140958 - For decrypting - ( m ** d) % n - Exemple: - (1140958 ** 830257) % 6938083 = 65 - */ -} -static void generateBigNumber(unsigned long *v){ - /*if (*v < 100) - *v = *v << 6; - else if (*v >= 100 || *v < 1000) - *v = *v << 4; - else - *v = *v << 2;*/ -} -/* - * This function will identify all the divider of the variable a - * with the Euclidean algorithm - */ -static int gcd(unsigned long a, unsigned long b){ - // Ou utiliser l'algorithme d'Euclide ? - int done = 0; - while (!done){ - if (b == 0) - done = 1; - else{ - int tmp = b; - b = a % b; - a = tmp; - } - } - return a; -} -/* - * This function will check if te variable e is a prime number - * is not, we increment the value to 1 and continue until is a prime number - */ -static void prime_number_finder(unsigned long *e){ - while(isPrimeNumber(*e) != 0) - *e += 1; -} -static int isPrimeNumber(unsigned long x){ - for (int i = 2; i < x; i++){ - if (x % i == 0) - return 1; - } - return 0; -} -static unsigned long generatePublicKey(unsigned long phi, unsigned long *e){ - // Generate e - *e = prng(61); - //generateBigNumber(e); - - // Get the coprime with phi - while ((gcd(phi, *e)) != 1) - *e += 1; - - return *e; -} -static unsigned long generatePrivateKey(unsigned long *d, unsigned long phi, unsigned long *e){ - // Calculate the modular inverse - int i = 0; - for (i = 0; i <= phi; i++){ - if ((i * (*e)) % phi == 1){ - *d = i; - break; - } - } - //*d = *e; - return *d; -}