diff --git a/README.md b/README.md index 4c1d0c2..0f12528 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,13 @@ a single pair of c & h file. Deployment options: - Download [release from Github](https://github.com/DavyLandman/compact25519/releases) and copy into your project directory -- TODO: Use PlatformIO and take a dependency on compact25519 + +## Usage with PlatformIO + +To use this library in a platformio project, add this to `platformio.ini`: + + lib_deps = + compact25519=https://github.com/DavyLandman/compact25519 ## License and origins The implementation of the X25519 and Ed25519 is extracted from @@ -38,4 +44,4 @@ operations to reduce binary size. |----|----| | `COMPACT_DISABLE_ED25519` | Disable Ed25519 feature and the related code, shaves of 32% | | `COMPACT_DISABLE_X25519` | Disable X25519 feature and the related code, shaves of 25% | -| `COMPACT_DISABLE_X25519_DERIVE` | Disable custom derive secret feature, extra useful combined with `COMPACT_DISABLE_ED25519`, in itself only saves 3%, combined with disabling Ed25519: 45%| \ No newline at end of file +| `COMPACT_DISABLE_X25519_DERIVE` | Disable custom derive secret feature, extra useful combined with `COMPACT_DISABLE_ED25519`, in itself only saves 3%, combined with disabling Ed25519: 45%| diff --git a/algamize.sh b/algamize.sh index e299bb0..7c7d055 100644 --- a/algamize.sh +++ b/algamize.sh @@ -60,9 +60,14 @@ function make_everything_static() { } function add_decl_spec() { + # Add COMPACT_25519_DECL prefix to: + # - static functions + # - other lines that don't start with space, #, {, }, / or s + # - but not to line extern "C" sed \ -e 's/^static /static COMPACT_25519_DECL /' \ - -e 's/^\([^\ \t#{}()\/*s]\)/COMPACT_25519_DECL \1/' # non static stuff like global header + -e 's/^\([^\ \t#{}()\/*s]\)/COMPACT_25519_DECL \1/' \ + -e 's/COMPACT_25519_DECL\s*\(extern "C" {\)/\1/' } echo "// compact25519 $VERSION @@ -73,9 +78,6 @@ echo "// compact25519 $VERSION #ifndef __COMPACT_25519_H #define __COMPACT_25519_H -#if defined(__cplusplus) -extern \"C\" { -#endif // provide your own decl specificier like "-DCOMPACT_25519_DECL=ICACHE_RAM_ATTR" #ifndef COMPACT_25519_DECL @@ -87,10 +89,7 @@ for h in "${COMPACT_FILES[@]}"; do cat "$SRC_DIR/$h.h" | remove_header_guard done | merge_includes | remove_double_blank_lines | add_decl_spec >> "$DST_HEADER" -echo "#if defined(__cplusplus) -} -#endif -#endif" >> "$DST_HEADER" +echo "#endif" >> "$DST_HEADER" echo "// compact25519 $VERSION @@ -123,4 +122,4 @@ for h in "${COMPACT_FILES[@]}"; do cat "$SRC_DIR/$h.c" | remove_local_imports | \ remove_double_blank_lines | add_decl_spec echo "// ******* END: $h.c ********" -done >> "$DST_SOURCE" \ No newline at end of file +done >> "$DST_SOURCE" diff --git a/library.json b/library.json new file mode 100644 index 0000000..b0b65c8 --- /dev/null +++ b/library.json @@ -0,0 +1,16 @@ +{ + "name": "compact25519", + "version": "1.1.0", + "repository": { "type": "git", "url": "https://github.com/DavyLandman/compact25519"}, + "authors": [ + { "name": "Daniel Beer", "email": "dlbeer@gmail.com" }, + { "name": "Davy Landman", "email": "davy.landman@gmail.com" } + ], + "license": "CC0-1.0", + "frameworks": "*", + "platforms": "*", + "build": { + "srcDir": "src", + "includeDir": "src" + } +} diff --git a/src/compact_ed25519.h b/src/compact_ed25519.h index a78a601..423adb0 100644 --- a/src/compact_ed25519.h +++ b/src/compact_ed25519.h @@ -25,6 +25,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + #define ED25519_SEED_SIZE (32) #define ED25519_PUBLIC_KEY_SIZE (32) #define ED25519_PRIVATE_KEY_SIZE (64) @@ -105,6 +109,11 @@ bool compact_ed25519_verify( const void *message, size_t msg_length ); + +#ifdef __cplusplus +} +#endif + #endif #endif diff --git a/src/compact_wipe.h b/src/compact_wipe.h index cd348e0..a913d86 100644 --- a/src/compact_wipe.h +++ b/src/compact_wipe.h @@ -2,6 +2,11 @@ #define __COMPACT_WIPE_H #include #include + +#ifdef __cplusplus +extern "C" { +#endif + /* Try to wipe contents of a buffer, as best as we can. (memset can be ignored by the compiler) @@ -11,4 +16,9 @@ returns the data pointer, makes for easier chaining */ void *compact_wipe(void *data, size_t length); + +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/compact_x25519.h b/src/compact_x25519.h index 41879b8..5cc1d3f 100644 --- a/src/compact_x25519.h +++ b/src/compact_x25519.h @@ -26,6 +26,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + #define X25519_KEY_SIZE (32) #define X25519_SHARED_SIZE (32) @@ -96,6 +100,11 @@ void compact_x25519_derive_encryption_key( const uint8_t public_key1[X25519_KEY_SIZE], const uint8_t public_key2[X25519_KEY_SIZE] ); + +#ifdef __cplusplus +} +#endif + #endif #endif #endif