From 6487ea8b85847c2c2ea68d4f01790440a3eaac72 Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Sat, 13 Apr 2024 13:30:52 +0200 Subject: [PATCH] defined why2_chat_rsa_pub_encrypt pog --- src/chat/crypto.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/chat/crypto.c b/src/chat/crypto.c index c7511c5..8267c50 100644 --- a/src/chat/crypto.c +++ b/src/chat/crypto.c @@ -168,4 +168,28 @@ char *why2_get_chat_modulus(void) char *why2_get_chat_d(void) { return rsa_d; +} + +char *why2_chat_rsa_pub_encrypt(long to_encrypt) +{ + //VARIABLES + char *output; + mpz_t m, c, n, e; + mpz_init(c); + + //GET ALL STUFF + mpz_init_set_si(m, to_encrypt); + mpz_init_set_str(n, why2_get_chat_modulus(), WHY2_CHAT_KEY_BASE); + mpz_init_set_si(e, WHY2_CHAT_RSA_EXPONENT); + + //ENCRYPT MESSAGE + mpz_powm(c, m, e, n); + + output = why2_malloc(mpz_sizeinbase(c, WHY2_CHAT_KEY_BASE) + 2); //ALLOCATE OUTPUT + mpz_get_str(output, WHY2_CHAT_KEY_BASE, c); //GET OUTPUT + + //DEALLOCATION + mpz_clears(m, c, n, e, NULL); + + return output; } \ No newline at end of file