added key dir check into why2_chat_generate_keys

This commit is contained in:
Václav Šmejkal 2024-02-23 10:59:38 +01:00
parent 0e2da6ccb7
commit 0c03ed3785
Signed by: ENGO150
GPG Key ID: 4A57E86482968843

View File

@ -19,8 +19,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <why2/chat/crypto.h> #include <why2/chat/crypto.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/random.h> #include <sys/random.h>
#include <why2/memory.h>
#include <why2/misc.h> #include <why2/misc.h>
#include <gmp.h> #include <gmp.h>
@ -50,6 +54,17 @@ void generate_prime(mpz_t x)
//GLOBAL //GLOBAL
void why2_chat_generate_keys(void) void why2_chat_generate_keys(void)
{ {
//GET PATH TO KEY DIR
char *path = why2_replace(WHY2_CHAT_PUB_KEY_LOCATION, "{USER}", getenv("USER"));
//CHECK IF KEYS EXIST
if (access(path, R_OK) != 0)
{
mkdir(path, 0700);
//SOME USER OUTPUT
printf("You are probably running WHY2-Chat for the first time now.\nGenerating RSA keys...\n");
//VARIABLES //VARIABLES
mpz_t p, q, e, d, n, phi_n, buffer_1, buffer_2; 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); mpz_inits(p, q, e, d, n, phi_n, buffer_1, buffer_2, NULL);
@ -72,6 +87,10 @@ void why2_chat_generate_keys(void)
//COUNT d //COUNT d
mpz_invert(d, e, phi_n); mpz_invert(d, e, phi_n);
//DEALLOCATION //KEY DEALLOCATION
mpz_clears(p, q, e, d, n, phi_n, buffer_1, buffer_2, NULL); mpz_clears(p, q, e, d, n, phi_n, buffer_1, buffer_2, NULL);
}
//DEALLOCATION
why2_deallocate(path);
} }