mirror of
https://github.com/CPunch/Laika.git
synced 2025-10-08 17:00:11 +00:00
Added LibSodium, new tools/, genKey, sLaika_peer::type
- sLaika_peer has a new member, (PEERTYPE)type - LibSodium dependency added
This commit is contained in:
17
tools/genkey/CMakeLists.txt
Normal file
17
tools/genkey/CMakeLists.txt
Normal file
@@ -0,0 +1,17 @@
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
set(CMAKE_C_STANDARD 99)
|
||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||
|
||||
project(genKey VERSION 1.0)
|
||||
|
||||
# Put CMake targets (ALL_BUILD/ZERO_CHECK) into a folder
|
||||
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
||||
|
||||
# compile genKey
|
||||
file(GLOB_RECURSE GENKEYSOURCE ${CMAKE_CURRENT_SOURCE_DIR}/src/**.c)
|
||||
add_executable(genKey ${GENKEYSOURCE})
|
||||
target_link_libraries(genKey PUBLIC LaikaLib)
|
||||
|
||||
# add the 'DEBUG' preprocessor definition if we're compiling as Debug
|
||||
target_compile_definitions(genKey PUBLIC "$<$<CONFIG:Debug>:DEBUG>")
|
42
tools/genkey/src/main.c
Normal file
42
tools/genkey/src/main.c
Normal file
@@ -0,0 +1,42 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "lerror.h"
|
||||
#include "lrsa.h"
|
||||
|
||||
#define DATA "Encryption/Decryption test passed!\n"
|
||||
#define DATALEN 35
|
||||
#define CIPHERLEN crypto_box_SEALBYTES + DATALEN
|
||||
|
||||
int main(int argv, char **argc) {
|
||||
unsigned char priv[crypto_box_SECRETKEYBYTES], pub[crypto_box_PUBLICKEYBYTES];
|
||||
char buf[256];
|
||||
unsigned char enc[CIPHERLEN];
|
||||
unsigned char dec[DATALEN];
|
||||
|
||||
if (sodium_init() < 0) {
|
||||
printf("Libsodium failed to init!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
crypto_box_keypair(pub, priv);
|
||||
|
||||
printf("[~] Generated keypair!\n");
|
||||
sodium_bin2hex(buf, 256, pub, crypto_box_PUBLICKEYBYTES);
|
||||
printf("[~] public key: %s\n", buf);
|
||||
sodium_bin2hex(buf, 256, priv, crypto_box_SECRETKEYBYTES);
|
||||
printf("[~] private key: %s\n\n", buf);
|
||||
|
||||
if (crypto_box_seal(enc, DATA, DATALEN, pub) != 0) {
|
||||
printf("Failed to encrypt!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (crypto_box_seal_open(dec, enc, CIPHERLEN, pub, priv) != 0) {
|
||||
printf("Failed to decrypt!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("%s", dec);
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user