Skip to content

Commit

Permalink
Add basic support for Particle targets
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan-Kouba committed Sep 24, 2019
1 parent 46f083e commit de3f2cf
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 2 deletions.
40 changes: 40 additions & 0 deletions Makefile.particle
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
PARTICLE_PACKAGE ?= hydrogen-crypto.zip
SRC = \
hydrogen.c \
hydrogen.h \
impl/common.h \
impl/core.h \
impl/gimli-core.h \
impl/hash.h \
impl/hydrogen_p.h \
impl/kdf.h \
impl/kx.h \
impl/pwhash.h \
impl/random.h \
impl/secretbox.h \
impl/sign.h \
impl/x25519.h \
impl/gimli-core/portable.h

all: package

package: $(PARTICLE_PACKAGE)

$(PARTICLE_PACKAGE):
mkdir particle
mkdir particle/src
cp library.properties particle/.
cp README.md particle/.
cp LICENSE particle/.
cp -r impl particle/src/.
cp hydrogen.h particle/src/.
cp hydrogen.c particle/src/hydrogen.cpp
7z a -tzip -mx=9 -r $(PARTICLE_PACKAGE) particle/.
rm -rf particle

.PHONY: clean

clean:
rm -f tests/tests
rm -rf particle
rm -f $(PARTICLE_PACKAGE)
30 changes: 30 additions & 0 deletions impl/random.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,36 @@ hydro_random_init(void)
return 0;
}

#elif defined(PARTICLE) && defined(PLATFORM_ID) && PLATFORM_ID > 2 && !defined(__unix__)

// Note: All particle platforms except for the Spark Core have a HW RNG. Only allow building on supported platforms for now.
// PLATFORM_ID definitions: https://github.com/particle-iot/device-os/blob/mesh-develop/hal/shared/platforms.h

#include "Particle.h"

static int
hydro_random_init(void)
{
const char ctx[hydro_hash_CONTEXTBYTES] = { 'h', 'y', 'd', 'r', 'o', 'P', 'R', 'G' };
hydro_hash_state st;
uint16_t ebits = 0;

hydro_hash_init(&st, ctx, NULL);

while (ebits < 256) {
uint32_t r = HAL_RNG_GetRandomNumber();

delay(10);
hydro_hash_update(&st, (const uint32_t *) &r, sizeof r);
ebits += 32;
}

hydro_hash_final(&st, hydro_random_context.state, sizeof hydro_random_context.state);
hydro_random_context.counter = ~LOAD64_LE(hydro_random_context.state);

return 0;
}

#elif (defined(NRF52832_XXAA) || defined(NRF52832_XXAB)) && !defined(__unix__)

// Important: The SoftDevice *must* be activated to enable reading from the RNG
Expand Down
4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
architectures=avr,nrf52
architectures=avr,nrf52,particle-photon,particle-electron,particle-p1
author=Frank Denis <libhydrogen@pureftpd.org>
category=Other
includes=hydrogen.h
Expand All @@ -7,4 +7,4 @@ name=hydrogen-crypto
paragraph=Consistent high-level API, inspired by libsodium. Instead of low-level primitives, it exposes simple functions to solve common problems that cryptography can solve.
sentence=An easy-to-use, hard-to-misuse cryptographic library
url=https://github.com/jedisct1/libhydrogen
version=0.1
version=0.1.0

0 comments on commit de3f2cf

Please sign in to comment.