Files
zeekayandHanzo Dev 37e2940ead mesh is the peer layer, network is the validator set
Two packages were named for the same word and meant different things. network/
dialed peers, exchanged keys, throttled and tracked them; nets/ tracked which
chains share a validator set and when they have all bootstrapped. One letter
apart, and neither name said which was which.

The peer layer is mesh — the word this estate already uses for it, in
lux-rs/node's own mesh.rs. That frees network for the thing that is actually a
network: a set of chains sharing a validator set. A network holds chains; a
chain belongs to one network.

github.com/luxfi/p2p stays what it is, the gossip library the VMs use. Three
concerns, three names, none of them borrowed from another.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-07 21:17:09 -07:00

71 lines
2.1 KiB
Go

// Copyright (C) 2019-2026, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package kem
import (
"crypto/cipher"
"errors"
"fmt"
"golang.org/x/crypto/chacha20poly1305"
)
// AEADID is the wire byte identifying the authenticated cipher used on
// post-handshake frames. Only FIPS-approved primitives are admitted; the
// production default is ChaCha20-Poly1305 (RFC 8439) because the Lux
// strict-PQ profile pairs lattice KEM with a stream cipher that is not
// vulnerable to the same lattice attack surface.
//
// Numbering:
//
// 0x00 — None (rejected)
// 0x01 — ChaCha20-Poly1305 (RFC 8439, FIPS 140 module-approved)
type AEADID uint8
const (
AEADNone AEADID = 0x00
AEADChaCha20Poly1305 AEADID = 0x01
)
// String returns the canonical wire name.
func (a AEADID) String() string {
switch a {
case AEADNone:
return "none"
case AEADChaCha20Poly1305:
return "chacha20-poly1305"
default:
return fmt.Sprintf("aead(0x%02x)", uint8(a))
}
}
// ErrUnsupportedAEAD is returned by NewAEAD when an unknown / forbidden
// AEAD byte is requested.
var ErrUnsupportedAEAD = errors.New("kem: unsupported AEAD")
// NewAEAD constructs a cipher.AEAD bound to key. Caller produces key via
// KEMSession.DeriveAEADKey or KEMSession.DeriveDKGAEADKey. Returns
// ErrUnsupportedAEAD for any byte other than AEADChaCha20Poly1305.
//
// This is the single dispatch point that maps an AEADID byte to a
// concrete cipher; transport code routes through it instead of importing
// chacha20poly1305 directly so a future AEAD addition (e.g. AES-256-GCM
// at 0x02) lands in one place.
func NewAEAD(id AEADID, key []byte) (cipher.AEAD, error) {
switch id {
case AEADChaCha20Poly1305:
if len(key) != chacha20poly1305.KeySize {
return nil, fmt.Errorf("kem: ChaCha20-Poly1305 key size=%d want=%d",
len(key), chacha20poly1305.KeySize)
}
aead, err := chacha20poly1305.New(key)
if err != nil {
return nil, fmt.Errorf("kem: chacha20poly1305.New: %w", err)
}
return aead, nil
default:
return nil, fmt.Errorf("%w: id=%s", ErrUnsupportedAEAD, id)
}
}