Переглянути джерело

improved testing programs

master
root 5 роки тому
джерело
коміт
a6417425ae
2 змінених файлів з 25 додано та 13 видалено
  1. 2
    1
      src/bootstrap.c
  2. 23
    12
      src/test.c

+ 2
- 1
src/bootstrap.c Переглянути файл

@@ -5,9 +5,9 @@

#include <arpa/inet.h>

#include "../inc/lc6_bootstrap.h"
#include "../inc/lc6_config.h"
#include "../inc/lc6_time.h"
#include "../inc/lc6_bootstrap.h"

const char bootlist[4][50] = {
"127.0.0.1",
@@ -23,6 +23,7 @@ int main(int argc, char **argv) {
if ( argc == 2 ) {
int i = 0;;

lc6helpers_banner("libchat6 bootstrapping programm");
printf("Loading configuration files...\n");
conf = lc6config_load(argv[1], "");


+ 23
- 12
src/test.c Переглянути файл

@@ -8,18 +8,25 @@

#include "../inc/lc6_helpers.h"
#include "../inc/lc6_crypto.h"
#include "../inc/lc6_config.h"
#include "../inc/lc6_user.h"


int main(int argc, char **argv) {
unsigned char data[1024];
unsigned char data2[1024];
unsigned char data[1024] = {0};
unsigned char data2[1024] = {0};
unsigned char *ptr_data = NULL;
unsigned char *ptr_data2 = NULL;
unsigned char *ptr_nonce = NULL;
int i, len;
LC6_CTX *conf;
LC6_USER *user;

lc6helpers_banner("libchat6 test programm");

lc6helpers_banner("Loading configuration...");
conf = lc6config_load("/tmp/","");

lc6helpers_banner("Generating random bytes...");
for(i=0; i<8; i++) {
printf("random bytes... ");
@@ -28,7 +35,7 @@ int main(int argc, char **argv) {
printf("\n");
}
lc6helpers_banner("Generating SHA256 hashs...");
lc6helpers_banner("Generating hashs...");
for(i=0; i<8; i++) {
unsigned char *hash;
lc6crypto_random(data, 16);
@@ -45,7 +52,7 @@ int main(int argc, char **argv) {
lc6helpers_banner("Generating new user and keys...");
user = lc6user_create();

strcpy(user->nickname,"Päscu");
strcpy(user->nickname,"Pascu");

printf("Private key\n");
lc6helpers_printhex(user->priv_key, crypto_box_SECRETKEYBYTES);
@@ -59,13 +66,15 @@ int main(int argc, char **argv) {
printf("plain data: %s\n", data);


len = lc6crypto_public_encrypt(data, strlen(data), user->priv_key, user->pub_key, &ptr_data, &ptr_nonce);
len = lc6crypto_encrypt(data, strlen(data)+1, user->priv_key, user->pub_key, &ptr_data, &ptr_nonce);
printf("encrypted length: %i\n", len);
printf("encrypted : ");
lc6helpers_printhex(ptr_data, len);
printf("\n");

len = lc6crypto_private_decrypt(ptr_data, len, user->priv_key, user->pub_key, &ptr_data, ptr_nonce);
printf("decrypted : %s\n", ptr_data);
len = lc6crypto_decrypt(ptr_data, len, user->priv_key, user->pub_key, &ptr_data2, ptr_nonce);
printf("decrypted length: %i\n", len);
printf("decrypted : %s\n", ptr_data2);

free(ptr_data);
free(ptr_nonce);
@@ -77,20 +86,22 @@ int main(int argc, char **argv) {
printf("plain data: %s\n", data);


len = lc6crypto_private_encrypt(data, strlen(data), user->priv_key, user->pub_key, &ptr_data, &ptr_nonce);
len = lc6crypto_encrypt(data, strlen(data)+1, user->pub_key, user->priv_key, &ptr_data, &ptr_nonce);
printf("encrypted length: %i\n", len);
printf("encrypted : ");
lc6helpers_printhex(ptr_data, len);
printf("\n");

len = lc6crypto_public_decrypt(ptr_data, len, user->priv_key, user->pub_key, &ptr_data, ptr_nonce);
printf("decrypted : %s\n", ptr_data);
len = lc6crypto_decrypt(ptr_data, len, user->pub_key, user->priv_key, &ptr_data2, ptr_nonce);
printf("decrypted length: %i\n", len);
printf("decrypted : %s\n", ptr_data2);

free(ptr_data);
free(ptr_nonce);
free(ptr_data2);

lc6user_free(NULL, user);
user = NULL;
lc6user_free(conf, user);
lc6config_free(conf);

return 0;
}

Завантаження…
Відмінити
Зберегти