Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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%|
| `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%|
17 changes: 8 additions & 9 deletions algamize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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"
done >> "$DST_SOURCE"
16 changes: 16 additions & 0 deletions library.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
9 changes: 9 additions & 0 deletions src/compact_ed25519.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
#include <stddef.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

#define ED25519_SEED_SIZE (32)
#define ED25519_PUBLIC_KEY_SIZE (32)
#define ED25519_PRIVATE_KEY_SIZE (64)
Expand Down Expand Up @@ -105,6 +109,11 @@ bool compact_ed25519_verify(
const void *message,
size_t msg_length
);

#ifdef __cplusplus
}
#endif

#endif

#endif
10 changes: 10 additions & 0 deletions src/compact_wipe.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
#define __COMPACT_WIPE_H
#include <stdint.h>
#include <stddef.h>

#ifdef __cplusplus
extern "C" {
#endif

/*
Try to wipe contents of a buffer, as best as we can.
(memset can be ignored by the compiler)
Expand All @@ -11,4 +16,9 @@
returns the data pointer, makes for easier chaining
*/
void *compact_wipe(void *data, size_t length);

#ifdef __cplusplus
}
#endif

#endif
9 changes: 9 additions & 0 deletions src/compact_x25519.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
#include <stddef.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

#define X25519_KEY_SIZE (32)
#define X25519_SHARED_SIZE (32)

Expand Down Expand Up @@ -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