CRYPTO-C v1.1.3
C/C++ Documentation
CRYPTO-C

Adequate Systems
Crypto C/C++/CUDA Library
tests status codeql status coverage status
GitHub tag (latest by date) Creative Commons Zero v1.0 Universal

Originally based on various contributions released into the Public Domain, this repository contains Cryptographic C/C++/CUDA support intended for continued use in the Open Source community.

Usage

Generally, hashing functions may be used by declaring an algorithms "context", and calling initial, update and final hash functions as required, OR; by simply calling the convenient "all-in-one" function that handles the algorithm's steps internally.

For example, the popular SHA256 algorithm may be used with a single call:

#include "sha256.h"
void simple_hash(void *data, size_t datalen, void *out)
{
sha256(data, datalen, out);
}
SHA256 hash function support.
void sha256(const void *in, size_t inlen, void *out)
Convenient all-in-one SHA256 computation.
Definition: sha256.c:177

OR; it may be used with more control:

#include "sha256.h"
void thrice_hash(void *data, size_t datalen, void *out)
{
sha256_init(&ctx);
sha256_update(&ctx, data, datalen);
sha256_update(&ctx, data, datalen);
sha256_update(&ctx, data, datalen);
sha256_final(&ctx, out);
}
void sha256_final(SHA256_CTX *ctx, void *out)
Finalize a SHA256 message digest.
Definition: sha256.c:129
void sha256_init(SHA256_CTX *ctx)
Initialize a SHA256 context.
Definition: sha256.c:82
void sha256_update(SHA256_CTX *ctx, const void *in, size_t inlen)
Add inlen bytes from in to a SHA256 context for hashing.
Definition: sha256.c:102
Definition: sha256.h:66

Most hashing algorithms follow the same syntax. For specific usage information, see the documentation.

Module Installation

The Crypto C/C++ Library was designed to be included in other projects as a Git Submodule. For C projects utilizing a similar structure and makefile, it is recommended to add submodules to the include/ directory of "superproject".

Add Crypto C as Submodule

git submodule add https://github.com/adequatesystems/crypto-c include/crypto-c
git commit -m "include crypto-c submodule"

Update Crypto C Submodule to latest revision

git -C include/crypto-c pull origin main
git commit -m "update crypto-c to latest revision"

Change Crypto C Submodule to specific hash or version tag

git -C include/crypto-c fetch
git -C include/crypto-c checkout <hash or version tag>
git commit -m "checkout crypto-c submodule to <hash or version tag>"

License

The source for Blake2b, CRC16, CRC32, MD2, MD5, SHA1, SHA256 and the associated device utility header is released into the Public Domain under the Creative Commons Zero v1.0 Universal license.

The source for SHA3 is (re)released under the MIT license (MIT) which can be viewed in the relevant sha3.c and sha3.h files.

The remaining build and workflow utilities are components of Adequate Systems' build-c repository, which is licensed separately to this repository. See https://github.com/adequatesystems/build-c/ for more information on that license.