Skip to content

Instantly share code, notes, and snippets.

View Staars's full-sized avatar

Christian Baars Staars

View GitHub Profile
@Staars
Staars / _ec_c25519_m15.c
Created September 12, 2025 14:45
Save some more space
/*
* _ec_c25519_m15.c — BearSSL Curve25519 (X25519) implementation using ESP32 ROM-backed Montgomery arithmetic
*
* This file provides a fast Montgomery ladder implementation for Curve25519 scalar
* multiplication (X25519), leveraging the ESP32's ROM bigint accelerator for modular
* multiplication in the prime field p = 2^255 - 19.
*
* Key features:
* - Field arithmetic in the normal domain using single-step ROM-backed multiply/square.
* - 8×32-bit little-endian limb representation for all field elements.
@Staars
Staars / _ec_p256_m15.c
Last active September 11, 2025 05:45
some conversion test
/*
* _ec_p256_m15.c — BearSSL P-256 implementation using ESP32 ROM-backed Montgomery arithmetic
*
* This file provides a fast elliptic curve implementation for secp256r1 (P-256),
* leveraging the ESP32's ROM bigint accelerator for modular multiplication.
*
* Key features:
* - Field arithmetic in normal domain using Montgomery-backed multiply/square.
* - Jacobian point representation with full group law (point add/double).
* - Scalar multiplication via double-and-add, supporting arbitrary base points.
@Staars
Staars / _sha_hal_idf5x.c
Last active September 11, 2025 05:45
Drop in driver for BearSSL hw acceleration
/*
* _sha_hal_idf5x.c — BearSSL drop‑in with ESP32 HAL SHA acceleration
*
* This file provides hardware-accelerated implementations of BearSSL-compatible
* hash functions (SHA-1, SHA-224, SHA-256, SHA-384, SHA-512) using the ESP-IDF 5.x
* SHA HAL. It replaces the software digest core with direct access to the ESP32's
* SHA engine, preserving BearSSL's context structure and API semantics.
*
* Each hash context uses a minimal layout:
* - val[] holds the midstate as a raw little-endian byte image.
@Staars
Staars / sha_combi_test.be
Created September 7, 2025 05:01
Combi test for SHA in Berry
import crypto
var start = tasmota.millis()
print("=== SHA256 ===")
var h = crypto.SHA256()
assert(h.out() == bytes("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"))
print("=== SHA256 (abc after 'empty')===")
h.update( bytes().fromstring("abc") )
assert(h.out() == bytes("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"))
@Staars
Staars / matter_crypto_test.be
Created September 7, 2025 05:00
Test for matter related SHA function
import crypto
var start = tasmota.millis()
import crypto
var w0 = bytes("bb8e1bbcf3c48f62c08db243652ae55d3e5586053fca77102994f23ad95491b3")
var w1 = bytes("7e945f34d78785b8a3ef44d0df5a1a97d6b3b460409a345ca7830387a74b1dba")
var L = bytes("04eb7c9db3d9a9eb1f8adab81b5794c1f13ae3e225efbe91ea487425854c7fc00f00bfedcbd09b2400142d40a14f2064ef31dfaa903b91d1faea7093d835966efd")
var spake_matter = crypto.SPAKE2P_Matter(w0, w1, L)
@Staars
Staars / SHA_stress_test.be
Created September 7, 2025 04:59
SHA stress test in Berry
import crypto
def sha256_of_bytes(b)
var h = crypto.SHA256()
h.update(b)
return h.out()
end
# 1) Non-destructive out(): repeated out() must match; further updates must continue the stream
def test_non_destructive_out()
@Staars
Staars / ec_p256_m15.c
Created September 4, 2025 15:47
Playing with BIGINT ... just experiments
/*
* Copyright (c) 2017 Thomas Pornin <pornin@bolet.org>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
@Staars
Staars / sha256_bench.be
Created August 21, 2025 12:57
Simple Benchmark for SHA256
# Tasmota Berry SHA-256 benchmark (multi-size)
# Uses crypto.SHA256 with update()/out()
# Timing via tasmota.millis()
# Compares hashes in uppercase
import crypto
# Hash utility: returns uppercase hex (native .tohex())
def sha256_hex(data)
var h = crypto.SHA256()
@Staars
Staars / _rom_idf53_sha.c
Last active September 7, 2025 04:58
sha rom functions
#include "t_inner.h"
#if defined(USE_SHA_ROM)
#if defined(ESP_PLATFORM) && !defined(ESP8266)
#include <stdint.h>
#include <stddef.h>
#include <string.h>
#include "freertos/FreeRTOS.h"
@Staars
Staars / mble.be
Last active March 17, 2026 21:03
Matter tests
#------------------------------------------------------------------------------
- Matter BLE
-------------------------------------------------------------------------------#
import BLE
import matter
var cbuf = bytes(-255)
class BTP_CONTROL_FLAGS
static var H_BIT = 6 # Handshake
static var M_BIT = 5 # Management Message