Phase 8 B: real Ed25519 keygen/signing, verified against OpenSSL
Extends the previously verify-only ed25519.c with ed25519_keygen() and ed25519_sign() per RFC 8032 5.1.5/5.1.6, reusing every point-arithmetic primitive verify already had -- only seed expansion/clamping and per-message nonce derivation are new. Signing is deterministic; only keygen ever touches entropy, via a caller-supplied seed (virtio_rng, Phase A) -- keygen still generates nothing itself. New scalar_muladd() (scalar25519.c) for signing's S = (k*a + r) mod L, the one scalar op verify never needed. Schoolbook multiply into a u128 wide accumulator with one final carry pass -- deliberately the same shape as fe25519.c's existing multiply, which has a documented history of a real bug from carrying mid-accumulation instead of in one pass. Verified against an independent implementation, not self-consistency: a throwaway host harness against Python's cryptography library (OpenSSL- backed) across 6 trials (5 random seed/message pairs + the empty-message case) produced byte-for-byte identical pubkeys and signatures every time. Clean compile on all three architectures and a full 3-arch QEMU acceptance boot, conservation intact, no panics or guest errors. Nothing calls the new functions from the live kernel path yet -- that's Phase C (the MINT word itself), still open, documented in FABRIC-3.md. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01U14ET9CWAtbQMbYqomKgXd
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
309e792f07
commit
53e6c5709f
@@ -1,11 +1,22 @@
|
||||
/* ed25519.h -- EdDSA signature VERIFICATION only (RFC 8032), freestanding
|
||||
* C99. No signing, no key generation, no RNG -- this kernel never signs;
|
||||
* signing happens in the host-side build tool, which can link
|
||||
* libsodium/OpenSSL because it's a normal Linux binary. That halves the
|
||||
* implementation surface here: no scalar clamping, no key derivation, no
|
||||
* constant-time discipline (verify operates only on public data --
|
||||
* public key, message, signature -- there's no secret-dependent branch
|
||||
* to leak).
|
||||
/* ed25519.h -- EdDSA (RFC 8032), freestanding C99.
|
||||
*
|
||||
* Originally verify-only ("this kernel never signs; signing happens in
|
||||
* the host-side build tool") -- that was correct for capsule signing
|
||||
* (build-time, offline, a normal Linux binary can link libsodium/
|
||||
* OpenSSL) but conflicts with an on-device Zuse session minting new
|
||||
* user certs live at runtime, which requires the kernel itself to sign.
|
||||
* Decided (Phase 8, 2026-08-26): add real keygen/signing rather than
|
||||
* reshape that flow around verify-only. Entropy for keygen comes from
|
||||
* virtio_rng.h -- this header still has no RNG of its own, and takes a
|
||||
* caller-supplied seed rather than generating one, deliberately: keygen
|
||||
* has no business deciding how the seed's randomness quality is
|
||||
* guaranteed, that's the caller's job.
|
||||
*
|
||||
* Signing is NOT constant-time (same non-constant-time double-and-add
|
||||
* scalar_mult() verify already used) -- acceptable for this project's
|
||||
* actual threat model (an emulated/embedded kernel with no untrusted
|
||||
* co-tenant able to observe timing), not acceptable if this code is
|
||||
* ever reused somewhere with a real timing-attack surface.
|
||||
*/
|
||||
#ifndef ED25519_H
|
||||
#define ED25519_H
|
||||
@@ -20,4 +31,17 @@
|
||||
int ed25519_verify(const uint8_t pubkey[32], const uint8_t *msg, size_t msg_len,
|
||||
const uint8_t sig[64]);
|
||||
|
||||
/* Derive the public key (compressed point A = [a]B) from a 32-byte
|
||||
* seed. seed must be real, uniformly random entropy -- see this file's
|
||||
* header comment; ed25519_keygen() does not check or generate it. */
|
||||
void ed25519_keygen(const uint8_t seed[32], uint8_t pubkey_out[32]);
|
||||
|
||||
/* Sign msg with the keypair derived from seed (the same seed passed to
|
||||
* ed25519_keygen() to obtain the matching public key). Deterministic
|
||||
* per RFC 8032 (the nonce is derived from seed + message, not fresh
|
||||
* randomness at sign time) -- only keygen needs real entropy, signing
|
||||
* needs none. */
|
||||
void ed25519_sign(const uint8_t seed[32], const uint8_t *msg, size_t msg_len,
|
||||
uint8_t sig_out[64]);
|
||||
|
||||
#endif /* ED25519_H */
|
||||
|
||||
@@ -26,4 +26,12 @@ void scalar_reduce512(uint8_t out[32], const uint8_t in[64]);
|
||||
* non-malleable signature component per RFC 8032), else 0. */
|
||||
int scalar_lt_L(const uint8_t s[32]);
|
||||
|
||||
/* out = (a*b + c) mod L, all 32-byte little-endian scalars (a, b, c need
|
||||
* not already be reduced mod L, though every caller in this codebase
|
||||
* passes already-reduced inputs). Needed for EdDSA signing's
|
||||
* S = (k*a + r) mod L step -- verify never needed scalar multiplication,
|
||||
* only reduction, so this didn't exist until signing did. */
|
||||
void scalar_muladd(uint8_t out[32], const uint8_t a[32], const uint8_t b[32],
|
||||
const uint8_t c[32]);
|
||||
|
||||
#endif /* SCALAR25519_H */
|
||||
|
||||
Reference in New Issue
Block a user