The short version, for everyone: When an activist presses "I'm safe" or "help" in Kengele, a small message goes to their trusted contacts. That message can travel over the internet, by SMS, or hop phone to phone. Whoever carries it (a relay server, a phone company, a stranger's phone) must not be able to read it, fake it, or even tell a cry for help from a routine check-in. This post shows exactly how that works, byte by byte, with code you can run.

Kengele is an open-source alarm for activists in East Africa. If an activist goes quiet during a watch window, each of their guardians' devices raises the alarm on its own. There is no Kengele server: messages travel over public Nostr relays, an encrypted SMS fallback, and (in v0.2) a Bluetooth mesh.

GitHub logo altradits / kengele

An alarm for when an activist goes missing. No servers, works through shutdowns. Swahili first.

Kengele

When an activist goes silent, the right people know within minutes, and nobody can switch the alarm off.

Ukinyamaza, kengele inalia. ("If you go quiet, the bell rings.")

Warning

Status: design stage. Not for real use. There is no working app yet. Do not rely on Kengele to protect anyone until an independent security review is complete and published here. People's lives may depend on this tool, so we will not cut corners to ship it sooner.

Why

When an activist disappears, how fast the public finds out often decides how quickly they are freed.

The first post in this series covered the deadline engine that decides when to raise an alarm:

This one is about the message itself: the 228 bytes every check-in, duress check-in and panic is made of, and the three layers of Nostr wrapping around them.

Kengele is still in design and not for real use until an independent security review is published. All code is at commit e10d277.

Contents

  1. Who is the adversary on the wire?
  2. Five goals for one message
  3. The layout, byte by byte
  4. Signing: BIP-340 with a domain tag
  5. Encrypting: NIP-44 v2 per guardian
  6. No sender key on the wire
  7. Why 228 bytes and 304 characters
  8. Strict decoding
  9. The Nostr layer: rumor, seal, gift wrap
  10. Run it yourself: what a relay sees
  11. Sending through outages
  12. What a carrier can still see

Who is the adversary on the wire?

The threat model names several, and the wire format has to hold against all of them at once:

Adversary What they want What they can do
A relay operator Read check-ins, map who protects whom Store and inspect every event they carry
A telecom operator or state Spot panics, block alarms, trace activists See every SMS: numbers, timing, content
A stranger's phone in a mesh Read or alter what it carries Hold and forward messages for hours
Captors with the activist's phone Send a convincing "I'm safe" Use the activist's real keys under coercion
A compromised guardian Forge the activist's events Hold one guardian's key

Two things follow. First, every carrier is untrusted: the message must be secure end to end, independent of the path. Second, the path changes: the same bytes must work over a websocket to a relay, inside two SMS segments, and through a Bluetooth hop. So the format is defined once, in internal/message, and the transports only carry it.

Five goals for one message

From docs/message-format.md:

  1. Nobody can fake it. Each event is signed by its sender with a BIP-340 Schnorr key, the same kind of key Nostr uses.
  2. Carriers can't read it. Each event is encrypted separately to each guardian with NIP-44 v2.
  3. Carriers can't tell kinds apart. Every message is exactly the same size. A duress check-in or a panic looks like an ordinary check-in to everyone except the guardian who decrypts it.
  4. It fits in two SMS. The text form is 304 characters from the GSM-7 basic set: two concatenated SMS hold 306.
  5. The original time survives. The sender's timestamp is inside the signature, so a message delivered days later still proves when it was made.

Goal 3 is the one people underestimate. If a panic message were even one byte longer than a check-in (because it carried a location, say), a telecom could flag every panic in real time without decrypting anything. Size is metadata.

The layout, byte by byte

There are seven event kinds. Their numbers are part of the format and never change:

const ( KindCheckIn Kind = 1 // activist: "I am safe" KindDuressCheckIn Kind = 2 // activist, forced: looks like a check-in to everyone but guardians KindPanic Kind = 3 // activist: panic trigger KindMissed Kind = 4 // guardian: a check-in deadline passed KindGuardianConfirm Kind = 5 // guardian: confirms the alarm (towards 2 of 3) KindAllClear Kind = 6 // activist or guardian: found safe, stand down KindGoingDark Kind = 7 // activist: pre-arming before a shutdown ) 

The kind travels only inside the encryption. From the outside, every message is this:

Wire message: 228 bytes

Offset Size Field
0 1 Format version, 0x01
1 227 NIP-44 v2 payload

NIP-44 v2 payload: 227 bytes

Offset Size Field
0 1 NIP-44 version, 0x02
1 32 Random nonce
33 162 ChaCha20 ciphertext of a 2-byte length (always 160) and the 160-byte signed plaintext
195 32 HMAC-SHA256

Signed plaintext: 160 bytes, inside the encryption

Offset Size Field
0 1 Kind
1 4 Created at: Unix seconds, big-endian
5 4 Sequence number, big-endian
9 1 Body length, 0 to 86
10 86 Body, then zero padding to 86 bytes
96 64 BIP-340 signature

The sizes are constants in code, derived from each other so that changing one breaks the build of the others:

const ( Version byte = 1 MaxBodySize = 86 innerSize = 1 + 4 + 4 + 1 + MaxBodySize + schnorr.SignatureSize // 160 signedSize = innerSize - schnorr.SignatureSize // 96 // version + nonce + (2-byte length + padded plaintext) + mac nip44Size = 1 + 32 + 2 + innerSize + 32 // 227 WireSize = 1 + nip44Size // 228 TextSize = (WireSize*8 + 5) / 6 // 304 base64url characters MaxSMSChars = 306 // two concatenated GSM-7 segments MaxClockSkew = 10 * time.Minute ) 

Why 86 bytes of body? Because 160 is a NIP-44 padding boundary. NIP-44 pads plaintexts to hide their length; by choosing a plaintext that is already exactly on a boundary, padding adds nothing, and the whole thing still fits in 304 characters. 86 bytes is enough for a typed place name ("Milimani law courts"), a 32-byte key plus a sequence number for guardian messages, or a 70-byte guardian confirmation carrying a Shamir share.

Signing: BIP-340 with a domain tag

sign builds the 160-byte plaintext and signs its first 96 bytes:

func sign(e Event, sender *btcec.PrivateKey) ([]byte, error) { ... inner := make([]byte, innerSize) inner[0] = byte(e.Kind) binary.BigEndian.PutUint32(inner[1:5], uint32(ts)) binary.BigEndian.PutUint32(inner[5:9], e.Seq) inner[9] = byte(len(e.Body)) copy(inner[10:10+MaxBodySize], e.Body) h := signedHash(inner[:signedSize]) sig, err := schnorr.Sign(sender, h[:]) ... copy(inner[signedSize:], sig.Serialize()) return inner, nil } 

The hash is a BIP-340 tagged hash:

// signTag separates Kengele signatures from Nostr event signatures and any // other protocol that uses the same keys (BIP-340 tagged hash). const signTag = "kengele/event/v1" func signedHash(data []byte) [32]byte { tag := sha256.Sum256([]byte(signTag)) h := sha256.New() h.Write(tag[:]) h.Write(tag[:]) h.Write(data) ... } 

This matters because Kengele keys are secp256k1 keys, the same curve and signature scheme as Nostr and Bitcoin Taproot. Without domain separation, a Kengele signature over some 96 bytes could, in principle, be presented as a valid signature in another protocol that hashes differently, or the other way round. With the tag kengele/event/v1, a Kengele signature is only ever valid as a Kengele signature.

Two deliberate choices:

  • The signature does not cover the recipient. The same signed event goes to every guardian, and can later be handed to a lawyer, a court or OpenTimestamps as proof of what the activist sent and when. If the signature were bound to one guardian, that proof would be per-guardian and harder to present.
  • The time is signed. CreatedAt is inside the signed bytes, so a message carried through a three-day shutdown still proves it was made at 14:07 on day one.

Encrypting: NIP-44 v2 per guardian

NIP-44 v2 is Nostr's audited encryption scheme: ECDH on secp256k1 gives a shared secret, HKDF turns it into a conversation key, each message gets a random 32-byte nonce, ChaCha20 encrypts and HMAC-SHA256 authenticates.

SealAll signs once and encrypts once per guardian:

func SealAll(e Event, sender *btcec.PrivateKey, recipients [][32]byte) ([][]byte, error) { inner, err := sign(e, sender) if err != nil { return nil, err } out := make([][]byte, 0, len(recipients)) for _, r := range recipients { w, err := encrypt(inner, sender, r, nil) ... out = append(out, w) } return out, nil } 

Per-guardian encryption costs a few hundred bytes more per event than encrypting once to a group key, but it means there is no group key to leak, add guardians to or revoke. Removing a guardian is just not encrypting to them any more.

encrypt also checks that the NIP-44 output is exactly the size the format promises, and refuses to send anything else:

if len(payload) != nip44Size { return nil, ErrSize } 

That is a cheap, permanent guard against a library upgrade silently changing padding and breaking goal 3.

No sender key on the wire

Look at the wire layout again: there is no sender public key. A carrier sees 228 random-looking bytes and nothing else. So how does a guardian know who sent it?

They try. A guardian watches over a handful of people, and Open tries each one's conversation key until one authenticates:

func Open(wire []byte, recipient *btcec.PrivateKey, senders [][32]byte, now time.Time) (*Event, error) { if len(wire) != WireSize { return nil, ErrSize } if wire[0] != Version { return nil, ErrVersion } b64 := base64.StdEncoding.EncodeToString(wire[1:]) for _, s := range senders { ck, err := conversationKey(recipient, s) if err != nil { continue } plain, err := nip44.Decrypt(b64, ck) if err != nil { continue // wrong sender or altered message: try the next key } return parse([]byte(plain), s, now) } return nil, ErrNoSender } 

NIP-44's MAC check makes this safe: a wrong key fails authentication, so there is no risk of "decrypting" garbage with the wrong sender. And because the signature inside is then verified against the same key that decrypted it, a compromised guardian cannot forge an activist's event: they could encrypt to another guardian, but they cannot produce the activist's Schnorr signature.

The cost is linear in the number of senders. For a family guardian with three people, that is nothing. For an organisation running a watcher for hundreds of activists, it might need a short rotating recipient hint, which would leak a little metadata. That trade-off is listed as an open question in the docs rather than decided silently.

Why 228 bytes and 304 characters

The SMS fallback is not an afterthought; in Tanzania in 2025 SMS kept working while data was off. The text form is unpadded base64url:

// EncodeText turns a wire message into the SMS-safe text form: unpadded // base64url, whose alphabet is entirely in the GSM-7 basic character set. func EncodeText(wire []byte) string { return base64.RawURLEncoding.EncodeToString(wire) } 

Why base64url and not standard base64? Standard base64 uses + and /, which are in GSM-7, but its = padding and some phones' habit of joining segments with whitespace cause trouble. More importantly, every base64url character (A–Z a–z 0–9 - _) is in the GSM-7 basic set, so none costs two septets. 228 bytes become exactly 304 characters, and two concatenated SMS hold 2 × 153 = 306.

A single SMS is impossible, and the docs say why: the 64-byte signature plus NIP-44's 32-byte nonce and 32-byte MAC already take 171 characters before any content. Two SMS is the floor for a message that is both authenticated and confidential.

There is deliberately no "KENGELE:" prefix on the SMS. A fixed marker would let a filter at the telecom find and drop every Kengele message.

Strict decoding

Everything that comes off the wire is treated as hostile. parse checks, in order: the length, the signature, the kind, the timestamp, the body length, and that every padding byte after the body is zero.

k := Kind(inner[0]) if !k.Valid() { return nil, ErrKind } ts := binary.BigEndian.Uint32(inner[1:5]) created := time.Unix(int64(ts), 0).UTC() if ts == 0 || created.After(now.Add(MaxClockSkew)) { return nil, ErrTime } n := int(inner[9]) if n > MaxBodySize { return nil, ErrBody } for _, b := range inner[10+n : 10+MaxBodySize] { if b != 0 { return nil, ErrBody } } 

Why insist on zero padding when the signature already covers it? Because strict parsing removes whole classes of "two encodings, one meaning" bugs. If non-zero padding were allowed, the same logical event would have many valid byte forms, and every system that hashes events (deduplication, OpenTimestamps) would have to agree on which one counts.

Old timestamps are accepted on purpose: store-and-forward means a real panic can arrive days late. Future timestamps more than 10 minutes ahead are rejected, so a captor cannot pre-sign a week of "I'm safe" check-ins with future dates. Replays of old ones are stopped above this layer, by the watcher's per-sender sequence numbers.

DecodeText is just as strict on the SMS side: the wrong length, any = or any whitespace is rejected, and the SMS transport is responsible for stripping what phones add when they join segments.

The Nostr layer: rumor, seal, gift wrap

The Kengele message is already signed and encrypted. Why wrap it again for Nostr?

Because a plain Nostr event leaks a lot. Every Nostr event has a pubkey (who sent it), a created_at (when), tags (to whom) and a signature. If an activist published their encrypted check-in as a normal event, every relay would see "this key sent something to that key at 14:07, then again at 15:37, then at 17:07". That rhythm alone reveals a watch window, and the sender key links the activist to their guardians.

NIP-59 gift wraps and NIP-17 private messages fix most of this with three layers. internal/transport/nostr/wrap.go builds them:

Layer Kind Signed by Encrypted to created_at
Rumor 14 nobody (unsigned) — real time
Seal 13 the sender's key recipient (NIP-44) real time minus random 0–48 h
Gift wrap 1059 a fresh one-time key recipient (NIP-44) real time minus random 0–48 h
rumor := gn.Event{ Kind: gn.KindDirectMessage, // 14 PubKey: senderPubHex, CreatedAt: gn.Timestamp(now.Unix()), Tags: gn.Tags{{"p", recipientHex}}, Content: message.EncodeText(wire), // the 304-character Kengele message } rumor.ID = rumor.GetID() 

The rumor is unsigned on purpose. If it leaked, it would not be a signed statement anyone could prove the sender made. (The Kengele message inside it is signed, but only a guardian can decrypt that.)

The seal encrypts the rumor to the guardian and is signed with the sender's real key, so the guardian knows who it is from. Its timestamp is moved back by a random amount:

sealAt, err := jitter(now, rnd) seal := gn.Event{Kind: gn.KindSeal, CreatedAt: sealAt, Tags: gn.Tags{}, Content: sealContent} if err := seal.Sign(senderSec); err != nil { ... } 

The gift wrap encrypts the seal again, this time with a brand-new key generated for this one message, and is signed by that throwaway key:

oneTime := gn.GeneratePrivateKey() ck2, err := nip44.GenerateConversationKey(recipientHex, oneTime) wrapContent, err := nip44.Encrypt(seal.String(), ck2) gw := gn.Event{ Kind: gn.KindGiftWrap, // 1059 CreatedAt: wrapAt, // jittered again, independently Tags: gn.Tags{{"p", recipientHex}}, Content: wrapContent, } if err := gw.Sign(oneTime); err != nil { ... } 

A relay sees only the outer layer: a kind 1059 event from a key it has never seen and will never see again, addressed to the guardian, with a timestamp somewhere in the last two days.

The jitter uses crypto/rand, not math/rand, because a predictable jitter is no jitter at all:

func jitter(now time.Time, rnd io.Reader) (gn.Timestamp, error) { n, err := rand.Int(rnd, big.NewInt(int64(MaxJitter/time.Second))) if err != nil { return 0, fmt.Errorf("nostr: jitter: %w", err) } return Source:https://dev.to/altradits/228-bytes-that-cant-be-read-faked-or-told-apart-kengeles-wire-format-and-nostr-gift-wraps-in-go-1ghd

Related posts