1
0

Current state of main.

This commit is contained in:
Alexander Andreev 2024-03-23 04:22:01 +04:00
parent a875891088
commit 0d47261c51
Signed by: Arav
GPG Key ID: 25969B23DCB5CA34

View File

@ -1,6 +1,7 @@
#include <sodium/utils.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <errno.h>
#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);