-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseed.go
More file actions
52 lines (45 loc) · 2.04 KB
/
Copy pathseed.go
File metadata and controls
52 lines (45 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package itb
import (
"crypto/rand"
"fmt"
"sync/atomic"
)
// testNonceOverride is set only by test code (see setTestNonce in *_test.go).
// Production callers never set this — generateNonceCfg falls through to
// crypto/rand. One atomic load per encryption in the hot path; negligible
// overhead in production, critical for nonce-reuse attack simulation in
// Probe 1 of the red-team plan.
var testNonceOverride atomic.Pointer[[]byte]
// testInterlockNonceOverride is the interlock-nonce counterpart of
// [testNonceOverride], set only by test code. Keeping the two overrides
// separate lets red-team fixtures force the three collision classes
// independently (main-only / interlock-only / both) when validating the
// quadratic reuse bound of the dual-nonce header. Production callers
// never set this — generateInterlockNonceCfg falls through to
// crypto/rand.
var testInterlockNonceOverride atomic.Pointer[[]byte]
// NonceSize is the default per-message nonce size in bytes (512 bits).
// 512-bit nonce eliminates the birthday-bound concern for any realistic
// deployment volume; users who explicitly need 128 / 256 bits set
// [Config.NonceBits] on the per-Pipeline Config.
// The compile-in default surfaces through [DefaultNonceBits]. Birthday
// collision at ~2^(nonceBits/2) messages.
const NonceSize = 64
// MaxKeyBits is the maximum supported key size in bits.
// Effective security depends on hash function's internal state width.
const MaxKeyBits = 2048
// secureWipe zeroes a byte slice to minimize sensitive data exposure in memory.
// clear() lowers to runtime.memclrNoHeapPointers — an observable side-effect
// the compiler cannot elide, replacing the prior manual-loop + KeepAlive
// pattern with a single intrinsic that widens to vector stores on amd64.
func secureWipe(b []byte) {
clear(b)
}
// generateRandomBytes returns n cryptographically random bytes.
func generateRandomBytes(n int) ([]byte, error) {
b := make([]byte, n)
if _, err := rand.Read(b); err != nil {
return nil, fmt.Errorf("itb: crypto/rand: %w", err)
}
return b, nil
}