seedhammer-v1-companion/bc/xoshiro256/xoshiro.go
mineracks 9261cf368a Lift composer substrate from upstream v1.3.0
Twelve packages lifted from seedhammer/seedhammer @ v1.3.0
(commit 2f071c1d8f23eb7fd39b15fc0acb8874113f801e):

  address/     — bitcoin address parsing
  backup/      — v1 plate dimensions + UR-coded multi-plate backup
  bc/          — Blockchain Commons: ur, fountain, bytewords, urtypes,
                 xoshiro256 (5 subpkgs)
  bip32/       — HD-key derivation
  bip39/       — mnemonic seed phrases + 2048-word wordlist
  engrave/     — text/QR → MoveTo/LineTo command stream conversion
  seedqr/      — SeedQR / CompactSeedQR encoders
  image/       — paletted, rgb565, alpha4, ninepatch image formats
  nonstandard/ — bitcoin descriptor + script parsing
  font/        — bitmap + vector font runtime
  font/{comfortaa,poppins,constant,bitmap,vector}/  — actual fonts
  driver/mjolnir/  — MarkingWay USB-serial engraver driver

Plus an earlier-aside backup_test.go restored (its deps are now lifted).

Import paths globally rewritten seedhammer.com → mineracks namespace
via single sed pass; verified no orphan refs remain. go.mod adopts
upstream's full dep set plus the replace-directive for the patched
kortschak/qr fork.

  go build ./...     clean (all 27 packages)
  go test ./...      clean (12 packages with tests, all passing)

NOT lifted in this commit:
  - driver/{wshat,drm,libcamera}  (hardware-specific GPIO/LCD/camera —
    will be platform-v1/-shaped abstractions instead)
  - gui/                (depends on the above; lifts in Phase 2)
  - cmd/{controller,...} (Pi binary entrypoints — not needed for the
    companion repo)
  - zbar/               (QR scanner — needs libcamera)

Next:
  - Write the SH1E reference encoder/decoder in engrave/wire/sh1e/
  - Lift Gangleri42's cmd/webnfc/ shell + retune to v1 plates
  - First buildable composer WASM with a working preview

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-28 18:36:40 +10:00

52 lines
1.1 KiB
Go

// Package xoshiro256 implements the xoshiro256** pseudo-random
// number generator. The implementation is based on the public domain
// [C implementation].
//
// [C implementation]: https://xoshiro.di.unimi.it/xoshiro256starstar.c
package xoshiro256
import (
"encoding/binary"
"math"
)
type Source struct {
state [4]uint64
}
func (s *Source) Seed(seed [32]byte) {
s.state[0] = binary.BigEndian.Uint64(seed[0:8])
s.state[1] = binary.BigEndian.Uint64(seed[8:16])
s.state[2] = binary.BigEndian.Uint64(seed[16:24])
s.state[3] = binary.BigEndian.Uint64(seed[24:32])
}
func (s *Source) Uint64() uint64 {
result := rotl(s.state[1]*5, 7) * 9
t := s.state[1] << 17
s.state[2] ^= s.state[0]
s.state[3] ^= s.state[1]
s.state[1] ^= s.state[2]
s.state[0] ^= s.state[3]
s.state[2] ^= t
s.state[3] = rotl(s.state[3], 45)
return result
}
func (s *Source) Intn(n int) int {
return int(s.Float64() * float64(n))
}
func (s *Source) Float64() float64 {
return float64(s.Uint64()) / (float64(math.MaxUint64) + 1)
}
func rotl(x uint64, k int) uint64 {
return (x << k) | (x >> (64 - k))
}