diff --git a/Cargo.toml b/Cargo.toml index 8c530db..ebc2ed4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "chacha20stream" -version = "1.0.3" +version = "1.2.0" keywords = ["chacha20_poly1305", "stream", "wrapper", "encryption", "decryption"] description = "A writable wrapper stream for encryption and decryption with the stream cipher chacha20_poly1305" homepage = "https://git.flanchan.moe/flanchan/chacha20stream" @@ -28,7 +28,7 @@ async = ["tokio", "pin-project"] # Explicitly clear in-memory buffers with `explicit_bzero()` instead of normal `bzero()`. explicit_clear = [] -# Add C interface bindings +# Build with C interface bindings ffi = ["libc"] [dependencies] diff --git a/include/cc20.h b/include/cc20.h index a462d24..020a45c 100644 --- a/include/cc20.h +++ b/include/cc20.h @@ -9,8 +9,19 @@ extern "C" { #include #include -#define KEY_SIZE 32 -#define IV_SIZE 12 +/// CC20 C interface versioning macro. +/// Most significant 8 bits is major, then next 8 is minor, then bugfix, then revision. +/// The componants should never exceed 255, or that is undefined behaviour. They should also be unsigned int (uint32_t), or that is undefined behaviour. +/// This macro is not intended to be used. +#define _CC20_VERSION(ma,mi,bu,r) (((ma) << 24) | ((mi) << 16) | ((bu) << 8) | (r)) + +/// C interface API version +#define CC20_C_API_VERSION 0 +/// The last library version as unsigned int. +#define CC20_MIN_LIBRARY_VERSION _CC20_VERSION(1u, 2u, 0, 0) + +#define CC20_KEY_SIZE 32 +#define CC20_IV_SIZE 12 enum cc20_mode { /// Encrypt the data written to this stream @@ -40,9 +51,9 @@ typedef enum cc20_error { #define CC20_ERR(v) ((v)!=CC20_ERR_NONE) /// A chacha20_poly1305 key -typedef uint8_t cc20_key_t[KEY_SIZE]; +typedef uint8_t cc20_key_t[CC20_KEY_SIZE]; /// A chacha20_poly1305 IV -typedef uint8_t cc20_iv_t[IV_SIZE]; +typedef uint8_t cc20_iv_t[CC20_IV_SIZE]; /// Metadata used to construct an instance of `cc20_sink_t`. typedef struct cc20_metadata { diff --git a/test.sh b/test.sh index badc71a..b43c0f8 100755 --- a/test.sh +++ b/test.sh @@ -1,6 +1,6 @@ #!/bin/bash -gcc test.c -Iinclude -Wall --std=gnu11 -pedantic -Wextra -Og -g -o test-ffi -l:target/debug/libchacha20stream.a -lssl -lcrypto -lpthread -ldl || exit +gcc test.c -Iinclude -Wall --std=gnu11 -pedantic -Wextra -Og -g -o test-ffi -l:target/release/libchacha20stream.a -lssl -lcrypto -lpthread -ldl || exit valgrind ./test-ffi # test-ffi-output #hexview test-ffi-output rm -f test-ffi{,-output}