CodeRigor

LESSON

Verify a framed authenticated record before using its payload

Bind version/context to exact bounded bytes, enforce canonical fields and reject altered records before releasing payload data.

The capstone is a complete tamper-evident record format and local CLI. A record contains version, context, a Base64 message and a lowercase-hex HMAC tag. The payload remains readable.

The CLI’s sign command computes a shared-key MAC; it is not a public-key digital signature. Every holder of the key can create a valid record. The library verifier releases payload bytes only after accepting the format, caller’s intended context and tag.

The acceptance boundary precedes payload use
start / 3
Check the record format and intended context, decode canonical bounded fields, authenticate framed bytes, then release the payload.
The acceptance boundary precedes payload use
Check the record format and intended context, decode canonical bounded fields, authenticate framed bytes, then release the payload.

Authenticate an unambiguous byte frame, not a casual concatenation. The supplied helper prefixes coderigor.record.v1 plus a zero byte, then a uint64 big-endian context length, context bytes, a uint64 message length and message bytes. The bounds make these allocations small and deliberate.

Version 1 is the only accepted version. The expected context comes from the caller’s operation, not merely from the record itself. An attacker must not move a valid record from one purpose into another.

Go
package main
import ("fmt";"encoding/binary")
func main(){
label,message:="ab",[]byte("c");frame:=binary.BigEndian.AppendUint64(nil,uint64(len(label)));frame=append(frame,[]byte(label)...);frame=binary.BigEndian.AppendUint64(frame,uint64(len(message)));frame=append(frame,message...);fmt.Println(len(frame))
}

The MAC covers decoded semantic fields under the fixed v1 framing. Reordering JSON keys or whitespace can preserve those fields; duplicate JSON keys are rejected by the local adapter to avoid ambiguous parsing. Message and tag encodings must be canonical before authentication.

The download supplies the working reference, starter, standard-library Go module, random-key command, bounded strict JSON adapter, original records, published primitive vectors and tampering tests. It stores a newly generated key in a newly created private file and refuses overwrite. Tests use public fixture keys or an owned temporary directory; no real account secret is needed.

This artifact does not hide payloads or prevent replay. It does not rotate keys, establish human identity or implement a password store. Those require additional protocol/application boundaries. The AEAD lesson supplies the separate maintained encryption operation, while the final CLI remains an integrity-focused artifact.

Failures release no accepted bytes
start / 3
Wrong key, changed message/tag, unsupported version, wrong purpose and malformed encoding all terminate before payload use.
Failures release no accepted bytes
Wrong key, changed message/tag, unsupported version, wrong purpose and malformed encoding all terminate before payload use.
Go
package main
import ("fmt";"encoding/base64";"bytes")
func main(){
payload:=[]byte{0,255,1};raw:=base64.StdEncoding.EncodeToString(payload);decoded,_:=base64.StdEncoding.DecodeString(raw);fmt.Println(raw,bytes.Equal(payload,decoded))
}

Complete the verifier, download the lab and run its tests and documented keygen/sign/verify sequence in an owned directory. Change the message, tag, context, version or key; verification must fail without outputting accepted payload bytes.

Keep the key private and remove the owned lab key when finished. The visible Boot.dev continuation broadens the cryptographic primitive set; retain these explicit format, context and failure boundaries as you continue.

Download the complete authenticated-record lab: standard-library Go CLI, published vectors, original fixtures, starter, tests and key cleanup instructions.

Actual Go verifier results · Public fixture key

A checksum can match while the record is rejected.

Choose an original or altered fixture. The replay recomputes an ordinary checksum of the shown payload, then runs the actual record verifier with its key, version and expected-context gates. This uses an intentionally public test key, never an application secret.

Payload bytes shown as textamount=99Caller expects lab.notes

Unkeyed checksum

Consistent

The advertised digest was computed from these bytes. This needs no secret and does not establish trusted origin.

Text
264c0e0d03dec862da5298c837428b4e1e5f6940f23234a51f7f371f062c06d6

Authenticated record

Rejected

The checksum matches the changed bytes, but the original HMAC no longer authenticates them.

Accepted payload outputNone — verification failed
Inspect the actual record fields
JSON
{
  "version": 1,
  "context": "lab.notes",
  "message": "YW1vdW50PTk5",
  "tag": "186780a104a57a54b70ce2db7f88b9e310874ecdd184a071e1af14fabde64b7e"
}

The record’s Base64 message remains readable. Acceptance means the complete format/context/MAC contract passed; rejection can occur before MAC comparison. This replay does not claim encryption, unique-sender identity or replay protection.

Download the CLI, published vectors and corruption tests →

Watch & read

Free lectures, talks and readings that cover this skill from another angle. All resources →

Optional expert discussion of how Go cryptography is engineered and tested. It supports the choice of maintained libraries; the course itself supplies the introductory explanations, vectors and complete lab.