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);