From 55550e4ea4f4c0245d12323d7e15b22ae426d7d5 Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Fri, 23 Feb 2024 10:25:47 +0100 Subject: [PATCH] defined why2_chat_generate_keys fn and guess what! it doesn't save the keys, yet :dd --- src/chat/crypto.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/chat/crypto.c b/src/chat/crypto.c index 742266d..72612b7 100644 --- a/src/chat/crypto.c +++ b/src/chat/crypto.c @@ -21,6 +21,8 @@ along with this program. If not, see . #include #include +#include + #include //LOCAL @@ -43,4 +45,33 @@ void generate_prime(mpz_t x) //DEALLOCATION gmp_randclear(state); +} + +//GLOBAL +void why2_chat_generate_keys(void) +{ + //VARIABLES + mpz_t p, q, e, d, n, phi_n, buffer_1, buffer_2; + mpz_inits(p, q, e, d, n, phi_n, buffer_1, buffer_2, NULL); + + //GENERATE PRIMES + generate_prime(p); + generate_prime(q); + + //SET e + mpz_set_ui(e, 65537); + + //GET n + mpz_mul(n, p, q); + + //GET phi + mpz_sub_ui(buffer_1, p, 1); + mpz_sub_ui(buffer_2, q, 1); + mpz_mul(phi_n, buffer_1, buffer_2); + + //COUNT d + mpz_invert(d, e, phi_n); + + //DEALLOCATION + mpz_clears(p, q, e, d, n, phi_n, buffer_1, buffer_2, NULL); } \ No newline at end of file