Skip to content

Repository files navigation

LibNgU

All the things needed to make Bitcoin work on embedded µpy platforms like ESP32.

Name is "Number Go Up" ... because need that.

Absoletely none of SHITCOINS allowed here

NEW POLICY If I don't know you, I don't merge you! Thanks XZ!

Primitives

  • using libsecp256k1 for everything, except:
  • mbedtls if already present on target (ESP32 uses for TLS)
  • otherwise use cifra
  • generic EC, certificates stuff, disabled if no mbedtls
  • AES submodule disabled if you have mbedtls, because ucryptolib is same
  • libwally-core used for testing only

Notes

  • might need, see issue

    export PKG_CONFIG_PATH=/usr/local/opt/libffi/lib/pkgconfig setenv PKG_CONFIG_PATH /usr/local/opt/libffi/lib/pkgconfig

Install

  • make one-time does submodule bullshit, configures K1 lib
  • make quick compiles Unix micropython port, runs tests
  • can play with ./ngu-micropython binary on your desktop
  • ESP32 builds stop until the integrator attests that true entropy stays active whenever ngu.random is used (see below). Once that is established, compile and burn onto the TTGO board:
make -f makefile.esp32
make -f makefile.esp32 deploy
  • on target, do:
>>> import ngu_tests.run

or for single test:

>>> import ngu_tests.test_hash
  • STM32 port builds, but untested:
make -f makefile.stm32 

Random number integration

ngu.random uses Cifra Hash_DRBG, initially seeded with 128 bytes from the target entropy source. Generated bytes are also XORed with fresh source words. There is no software fallback:

  • STM32 uses rng_get() only when the board enables MicroPython's hardware RNG with MICROPY_HW_ENABLE_RNG=1, or supplies an external implementation and sets NGU_STM32_EXTERNAL_RNG_GET=1. Without either source, the build fails. A zero word is rejected; MicroPython's STM32 implementation uses zero to report a peripheral timeout.
  • ESP32 uses esp_random() only when the build sets NGU_ESP32_RNG_IS_TRUE_RANDOM=1. This is the integrator's attestation that a true entropy source remains active whenever random data is requested. Without active RF or another enabled entropy source, ESP-IDF documents the output as pseudo-random. See the ESP-IDF RNG documentation.
  • macOS and FreeBSD use arc4random(). Linux uses getrandom(2). Unknown targets fail to build.

The runtime rejects zero and an immediate repeated word. This is a narrow failure check, not a substitute for validating the raw entropy source on each hardware target.

ngu.random.reseed() accepts bytes-like values of at least 32 bytes and mixes them into the existing state. The module keeps mutable DRBG and source-check state, so calls must be serialized. Python calls require the VM's GIL when threads are enabled; direct C callers own that synchronization.

About

libNgU

Resources

Stars

7 stars

Watchers

4 watching

Forks

Releases

Packages

Contributors

Languages