From 0d47261c512cd918a07bd383d6ef7ccfad5e66fe Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Sat, 23 Mar 2024 04:22:01 +0400 Subject: [PATCH] Current state of main. --- src/main.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 7 deletions(-) diff --git a/src/main.c b/src/main.c index a834585..941fee5 100644 --- a/src/main.c +++ b/src/main.c @@ -1,6 +1,7 @@ +#include #include -#include #include +#include #include "audio.h" #include "crypt.h" @@ -20,25 +21,64 @@ int main(int argc, char **argv) { return -1; } - crypt_key_t own; + crypt_key_t own, ownr; if (crypt_key_gen(&own) < 0) { fprintf(stderr, "Failed to generate the keys."); return -1; } - FILE *fp = fopen("own_pub_key", "w"); - FILE *fs = fopen("own_sec_key", "w"); + FILE *fp = fopen("own_pub_key", "w+"); + FILE *fs = fopen("own_sec_key", "w+"); - crypt_store_public_key(&own, fp); - crypt_store_secret_key(&own, fs); + if (fp == NULL) { + fprintf(stderr, "fp err: %s\n", strerror(errno)); + return 0; + } + + if (fs == NULL) { + fprintf(stderr, "fs err: %s\n", strerror(errno)); + return 0; + } + + char phex[CRYPT_PKEY_HEXLEN], shex[CRYPT_SKEY_HEXLEN]; + + crypt_key_export_public(&own, phex); + crypt_key_export_secret(&own, shex); + + crypt_store_key(&own, fp, fs); + + printf("p1 = [%s]\ns1 = [%s]\n", phex, shex); + + + fflush(fp); + fflush(fs); + fseek(fp, 0, SEEK_SET); + fseek(fs, 0, SEEK_SET); + + crypt_load_key(&ownr, fp, fs); + + char phexr[CRYPT_PKEY_HEXLEN], shexr[CRYPT_SKEY_HEXLEN]; + + crypt_key_export_public(&ownr, phexr); + crypt_key_export_secret(&ownr, shexr); + + printf("p2 = [%s]\ns2 = [%s]\n", phexr, shexr); fclose(fp); fclose(fs); + crypt_key_destroy(&own); + crypt_key_destroy(&ownr); + + sodium_memzero(phex, CRYPT_PKEY_HEXLEN); + sodium_memzero(phexr, CRYPT_PKEY_HEXLEN); + sodium_memzero(shex, CRYPT_SKEY_HEXLEN); + sodium_memzero(shexr, CRYPT_SKEY_HEXLEN); + // audio_t aud; - // uint8_t buf[BUF_SIZE]; + // unsigned char buf[BUF_SIZE]; // memset(buf, 0, BUF_SIZE); // audio_init(&aud, CHANNELS, SAMPLE_RATE, FRAMES_PER_BUFFFER);