fixed rsa crypto input strings & output base

This commit is contained in:
Václav Šmejkal 2024-04-13 13:45:40 +02:00
parent 9cf062565a
commit d9483f02ca
Signed by: ENGO150
GPG Key ID: 4A57E86482968843
2 changed files with 8 additions and 8 deletions

View File

@ -41,8 +41,8 @@ void why2_chat_deallocate_keys(void); //DEALLOCATE :) (NO SLUR HERE)
char *why2_get_chat_modulus(void); //GET THE RSA MODULUS char *why2_get_chat_modulus(void); //GET THE RSA MODULUS
char *why2_get_chat_d(void); //GET THE RSA d char *why2_get_chat_d(void); //GET THE RSA d
char *why2_chat_rsa_pub_encrypt(long to_encrypt); //RSA ENCRYPT USING PUBLIC KEY char *why2_chat_rsa_pub_encrypt(char *to_encrypt); //RSA ENCRYPT USING PUBLIC KEY
char *why2_chat_rsa_pri_decrypt(long to_decrypt); //RSA DECRYPT USING PRIVATE KEY char *why2_chat_rsa_pri_decrypt(char *to_decrypt); //RSA DECRYPT USING PRIVATE KEY
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -76,7 +76,7 @@ void read_file(FILE *file, char **output)
*output = buffer; *output = buffer;
} }
char *exp_mod(long to_encrypt, char *exponent) char *exp_mod(char *to_exp, char *exponent)
{ {
//VARIABLES //VARIABLES
char *output; char *output;
@ -84,15 +84,15 @@ char *exp_mod(long to_encrypt, char *exponent)
mpz_init(c); mpz_init(c);
//GET ALL STUFF //GET ALL STUFF
mpz_init_set_si(m, to_encrypt); mpz_init_set_str(m, to_exp, 10);
mpz_init_set_str(n, why2_get_chat_modulus(), WHY2_CHAT_KEY_BASE); mpz_init_set_str(n, why2_get_chat_modulus(), WHY2_CHAT_KEY_BASE);
mpz_init_set_str(e, exponent, 10); mpz_init_set_str(e, exponent, 10);
//ENCRYPT MESSAGE //ENCRYPT MESSAGE
mpz_powm(c, m, e, n); mpz_powm(c, m, e, n);
output = why2_malloc(mpz_sizeinbase(c, WHY2_CHAT_KEY_BASE) + 2); //ALLOCATE OUTPUT output = why2_malloc(mpz_sizeinbase(c, 10) + 2); //ALLOCATE OUTPUT
mpz_get_str(output, WHY2_CHAT_KEY_BASE, c); //GET OUTPUT mpz_get_str(output, 10, c); //GET OUTPUT
//DEALLOCATION //DEALLOCATION
mpz_clears(m, c, n, e, NULL); mpz_clears(m, c, n, e, NULL);
@ -194,12 +194,12 @@ char *why2_get_chat_d(void)
return rsa_d; return rsa_d;
} }
char *why2_chat_rsa_pub_encrypt(long to_encrypt) char *why2_chat_rsa_pub_encrypt(char *to_encrypt)
{ {
return exp_mod(to_encrypt, WHY2_CHAT_RSA_EXPONENT); return exp_mod(to_encrypt, WHY2_CHAT_RSA_EXPONENT);
} }
char *why2_chat_rsa_pri_decrypt(long to_decrypt) char *why2_chat_rsa_pri_decrypt(char *to_decrypt)
{ {
return exp_mod(to_decrypt, why2_get_chat_d()); return exp_mod(to_decrypt, why2_get_chat_d());
} }