Browse Source

improved testing programs

master
root 5 years ago
parent
commit
a6417425ae
2 changed files with 25 additions and 13 deletions
  1. 2
    1
      src/bootstrap.c
  2. 23
    12
      src/test.c

+ 2
- 1
src/bootstrap.c View File



#include <arpa/inet.h> #include <arpa/inet.h>


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


const char bootlist[4][50] = { const char bootlist[4][50] = {
"127.0.0.1", "127.0.0.1",
if ( argc == 2 ) { if ( argc == 2 ) {
int i = 0;; int i = 0;;


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



+ 23
- 12
src/test.c View File



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




int main(int argc, char **argv) { 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_data = NULL;
unsigned char *ptr_data2 = NULL; unsigned char *ptr_data2 = NULL;
unsigned char *ptr_nonce = NULL; unsigned char *ptr_nonce = NULL;
int i, len; int i, len;
LC6_CTX *conf;
LC6_USER *user; LC6_USER *user;


lc6helpers_banner("libchat6 test programm");

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

lc6helpers_banner("Generating random bytes..."); lc6helpers_banner("Generating random bytes...");
for(i=0; i<8; i++) { for(i=0; i<8; i++) {
printf("random bytes... "); printf("random bytes... ");
printf("\n"); printf("\n");
} }
lc6helpers_banner("Generating SHA256 hashs...");
lc6helpers_banner("Generating hashs...");
for(i=0; i<8; i++) { for(i=0; i<8; i++) {
unsigned char *hash; unsigned char *hash;
lc6crypto_random(data, 16); lc6crypto_random(data, 16);
lc6helpers_banner("Generating new user and keys..."); lc6helpers_banner("Generating new user and keys...");
user = lc6user_create(); user = lc6user_create();


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


printf("Private key\n"); printf("Private key\n");
lc6helpers_printhex(user->priv_key, crypto_box_SECRETKEYBYTES); lc6helpers_printhex(user->priv_key, crypto_box_SECRETKEYBYTES);
printf("plain data: %s\n", data); 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 : "); printf("encrypted : ");
lc6helpers_printhex(ptr_data, len); lc6helpers_printhex(ptr_data, len);
printf("\n"); 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_data);
free(ptr_nonce); free(ptr_nonce);
printf("plain data: %s\n", data); 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 : "); printf("encrypted : ");
lc6helpers_printhex(ptr_data, len); lc6helpers_printhex(ptr_data, len);
printf("\n"); 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_data);
free(ptr_nonce); free(ptr_nonce);
free(ptr_data2); free(ptr_data2);


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


return 0; return 0;
} }

Loading…
Cancel
Save