Reduce nRF52 Companion flash and stream Reader chapters

Use a 960-byte constant-time Ed25519 base table, compact hash/scalar code and unused-library trims while retaining Reader, BLE P-256 and the 8 KiB stack. RAK4631 Full saves 57,496 flash bytes and 3,152 static RAM bytes versus preview3.

Support complete chapters and verse ranges with bounded app continuation replies and cooperative terminal output. Use nonblocking TCP writes under reader backpressure. Add scalar/signature comparisons and a linked ARM crypto/stack CI gate.

Validated clean RAK4631, T1000-E, T096 and V4 Full builds, host regressions, and physical RAK chapter/reconnect and signing comparisons. Physical signing averages 35.9 ms versus 14.4 ms with the original table.
This commit is contained in:
mikecarper committed 2026-10-13 01:02:30 -07:00
1 parent 65820d0dd2
commit d2bea5fb10
21 files changed
+803 -86

No files matched your search

+23
View File
@@ -412,6 +412,28 @@ void ge_scalarmult_base(ge_p3 *h, const unsigned char *a) {
/* each e[i] is between -8 and 8 */
ge_p3_0(h);
#if defined(ED25519_SMALL_BASE) && ED25519_SMALL_BASE
/* Keep only the existing 1B..8B row (960 bytes) in flash. Evaluate the
* same signed radix-16 digits from most to least significant instead of
* keeping 32 shifted rows (30 KiB). The selection still scans all eight
* entries with cmov; no loop count/address depends on a secret digit.
* Unlike the RAM-built compact option, this uses the ordinary scratch
* objects above and does not add a multiples[] table to the stack.
*/
for (i = 63; i >= 0; --i) {
ge_p3_dbl(&r, h);
ge_p1p1_to_p2(&s, &r);
ge_p2_dbl(&r, &s);
ge_p1p1_to_p2(&s, &r);
ge_p2_dbl(&r, &s);
ge_p1p1_to_p2(&s, &r);
ge_p2_dbl(&r, &s);
ge_p1p1_to_p3(h, &r);
select(&t, 0, e[i]);
ge_madd(&r, h, &t);
ge_p1p1_to_p3(h, &r);
}
#else
for (i = 1; i < 64; i += 2) {
select(&t, i / 2, e[i]);
ge_madd(&r, h, &t);
@@ -432,6 +454,7 @@ void ge_scalarmult_base(ge_p3 *h, const unsigned char *a) {
ge_madd(&r, h, &t);
ge_p1p1_to_p3(h, &r);
}
#endif
}
#else
/*
+6 -1
View File
@@ -43,8 +43,11 @@ static const ge_precomp Bi[8] = {
/* base[i][j] = (j+1)*256^i*B */
#if defined(ED25519_SMALL_BASE) && ED25519_SMALL_BASE && defined(ED25519_COMPACT_BASE)
#error "Choose either the small flash table or the RAM-built compact table"
#endif
#ifndef ED25519_COMPACT_BASE
static const ge_precomp base[32][8] = {
static const ge_precomp base[][8] = {
{
{
{ 25967493, -14356035, 29566456, 3660896, -12694345, 4014787, 27544626, -11754271, -6079156, 2047605 },
@@ -87,6 +90,7 @@ static const ge_precomp base[32][8] = {
{ 27431194, 8222322, 16448760, -3907995, -18707002, 11938355, -32961401, -2970515, 29551813, 10109425 },
},
},
#if !defined(ED25519_SMALL_BASE) || !ED25519_SMALL_BASE
{
{
{ -13657040, -13155431, -31283750, 11777098, 21447386, 6519384, -2378284, -1627556, 10092783, -4764171 },
@@ -1389,5 +1393,6 @@ static const ge_precomp base[32][8] = {
{ -20430234, 14955537, -24126347, 8124619, -5369288, -5990470, 30468147, -13900640, 18423289, 4177476 },
},
},
#endif
};
#endif