created sha256 function returning string

This commit is contained in:
Václav Šmejkal 2024-09-01 20:40:21 +02:00
parent b836bf47d7
commit 642ef37016
Signed by: ENGO150
GPG Key ID: 4A57E86482968843

View File

@ -30,6 +30,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <gmp.h> #include <gmp.h>
#include <openssl/sha.h>
//DO NOT TOUCH THESE PLS :3 //DO NOT TOUCH THESE PLS :3
char *rsa_modulus = NULL; //THE RSA MODULUS char *rsa_modulus = NULL; //THE RSA MODULUS
char *rsa_d = NULL; //THE RSA d char *rsa_d = NULL; //THE RSA d
@ -203,3 +205,23 @@ 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());
} }
char *why2_sha256(char *input)
{
unsigned char *output = why2_malloc(SHA256_DIGEST_LENGTH + 1);
char *formatted_output = why2_malloc(SHA256_DIGEST_LENGTH * 2 + 2);
SHA256((unsigned char*) input, strlen(input), output);
//SAVE AS STRING IN HEX
for (int i = 0; i < SHA256_DIGEST_LENGTH; i++)
{
sprintf(formatted_output + (i * 2), "%02x", output[i]);
}
formatted_output[SHA256_DIGEST_LENGTH * 2] = '\0';
//DEALLOCATION
why2_deallocate(output);
return formatted_output;
}