A cross-platform C library which depends on OpenSSL that allows to easily and quickly add crypto capabilities to your projects.
A cross-platform C11 library which depends on OpenSSL that allows to easily and quickly add crypto capabilities to your projects.
Its main purpose is to be the crypto module of LibUnknownEcho library.
The goal is NOT to wrap all features of Openssl, but only the most widely used features.
data encryption
file encryption
certificate management
hashing
pkcs12 keystore
signing
crypto random
encoding
compression
Clone the repository:
git clone http://github.com/swasun/LibUnknownEchoUtilsModule
Build in release mode:
mkdir -p build/release
cmake -Bbuild/release -H. -DCMAKE_BUILD_TYPE=Release
cd build/release
cmake --build . --config Release
Or build in debug mode:
mkdir -p build/debug
cmake -Bbuild/debug -H. -DCMAKE_BUILD_TYPE=Debug
cd build/debug
cmake --build . --config Debug
By default, dependencies are built and install in the build
directoy.
To specify an other path, add -DLIBEI_INSTALL=/usr
flag (LIBUEUM_INSTALL for LIBUEUM) in cmake
command.
To build with LIBEI already installed in the system, add -DLIBEI_SYSTEM=TRUE
flag in cmake
command.
To build with LIBUEUM already installed in the system, add -DLIBUEUM_SYSTEM=TRUE
flag in cmake
command.
Alternatively, you can build using build_release.<sh|bat>
and build_debug.<sh|bat>
scripts.
Finally, to install in the system:
cd build/release
<sudo> cmake --build . --config Release --target install
Some examples are available in examples
directory.
./bin/release/examples/progress_bar_example
The following basic_usage.c
is an example of a simple usage of the library (for the sake of clarity, error handling are omitted here, but complete example file is availabe in ̀examples
directory):
#include <uecm/uecm.h> /* Include LibUnknownEchoCryptoModule */
#include <ueum/ueum.h> /* Include LibUnknownEchoUtilsModule */
#include <ei/ei.h> /* Include LibErrorInterceptor */
#include <stddef.h>
#include <string.h>
int main(int argc, char **argv) {
unsigned char *plain_data, *cipher_data, *decipher_data;
size_t plain_data_size, cipher_data_size, decipher_data_size;
uecm_asym_key *key;
int key_size;
ei_init_or_die(); /* Initialize LibErrorInterceptor */
uecm_init_or_die(); /* Initialize LibUnknownEchoCryptoModule */
/* Use LibUnknownEchoCryptoModule */
plain_data = NULL;
cipher_data = NULL;
decipher_data = NULL;
key_size = 4096;
/* Convert the string input in bytes */
plain_data = ueum_bytes_create_from_string(argv[1]);
plain_data_size = strlen(argv[1]);
/* Generate a random RSA key pair */
key = uecm_rsa_asym_key_create(key_size);
/**
* Cipher plain data using both asymmetric (4096-RSA) and
* symmetric encryption (AES-256-CBC), compression
* (inflate/deflate of zlib), signing (SHA-256).
* The private key parameter (key->sk) is optional,
* and used to sign the cipher data.
*/
uecm_cipher_plain_data(plain_data, plain_data_size, key->pk, key->sk, &cipher_data, &cipher_data_size, "aes-256-cbc", "sha256");
/**
* Decipher cipher data using both asymmetric (4096-RSA) and
* symmetric encryption (AES-256-CBC), compression
* (inflate/deflate of zlib), signing (SHA-256).
* The public key parameter (key->pk) is optional,
* and used to verify the signature of the cipher data.
*/
uecm_decipher_cipher_data(cipher_data, cipher_data_size, key->sk, key->pk, &decipher_data, &decipher_data_size,
"aes-256-cbc", "sha256");
/* Check if decipher data and plain data are equals */
ei_logger_info("Comparing decipher data with plain data...");
if (plain_data_size == decipher_data_size && memcmp(decipher_data, plain_data, plain_data_size) == 0) {
ei_logger_info("Plain data and decipher data match");
} else {
ei_logger_error("Plain data and decipher data doesn't match");
}
clean_up:
/* Clean_up variables */
ueum_safe_free(plain_data);
ueum_safe_free(cipher_data);
ueum_safe_free(decipher_data);
uecm_asym_key_destroy_all(key);
/**
* Each time ei_stacktrace API is used in libueum or libuecm,
* an error is record to the stacktrace of the current thread.
*/
if (ei_stacktrace_is_filled()) {
ei_logger_error("Error(s) occurred with the following stacktrace(s):");
ei_stacktrace_print_all();
}
uecm_uninit(); /* uninitialize LibUnknownEchoCryptoModule */
ei_uninit(); /* uninitialize LibErrorInterceptor */
return 0;
}
Compile statically:
gcc -o basic_usage examples/basic_usage.c -lei_static -luecm_static -lueum_static -pthread lib/openssl/lib/libssl.a lib/openssl/lib/libcrypto.a lib/zlib/lib/libz.a -ldl
Run:
./basic_usage "Hello world !"
note: -pthread
and -ldl
flags are necessary for Unix systems.
The facade design pattern is use to simplify the complexity of a module.
In the module, we have 2 to 4 sub folders which are:
Successfully tested on the following OS (on 64 bits):