defined why2_chat_rsa_pub_encrypt

pog
This commit is contained in:
Václav Šmejkal 2024-04-13 13:30:52 +02:00
parent ee3f319dd7
commit 6487ea8b85
Signed by: ENGO150
GPG Key ID: 4A57E86482968843

View File

@ -169,3 +169,27 @@ char *why2_get_chat_d(void)
{ {
return rsa_d; 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;
}