|
|
@@ -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; |
|
|
|
} |