forked from mmcloughlin/avo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stadtx.go
64 lines (51 loc) · 1.39 KB
/
stadtx.go
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
53
54
55
56
57
58
59
60
61
62
63
64
// Code generated by downloading from https://github.com/dgryski/go-stadtx/raw/3c3d9b328c24a9b5ecd370654cd6e9d60a85752d/stadtx.go. DO NOT EDIT.
// Package stadtx implements Stadtx Hash
/*
https://github.com/demerphq/BeagleHash
*/
package stadtx
func rotl64(x uint64, r uint64) uint64 {
return (((x) << (r)) | ((x) >> (64 - r)))
}
func rotr64(x uint64, r uint64) uint64 {
return (((x) >> (r)) | ((x) << (64 - r)))
}
func scramble64(v, prime uint64) uint64 {
v ^= (v >> 13)
v ^= (v << 35)
v ^= (v >> 30)
v *= prime
v ^= (v >> 19)
v ^= (v << 15)
v ^= (v >> 46)
return v
}
func SeedState(seed []uint64) State {
var state State
state[0] = seed[0] ^ 0x43f6a8885a308d31
state[1] = seed[1] ^ 0x3198a2e03707344a
state[2] = seed[0] ^ 0x4093822299f31d00
state[3] = seed[1] ^ 0x82efa98ec4e6c894
if state[0] == 0 {
state[0] = 1
}
if state[1] == 0 {
state[1] = 2
}
if state[2] == 0 {
state[2] = 4
}
if state[3] == 0 {
state[3] = 8
}
state[0] = scramble64(state[0], 0x801178846e899d17)
state[0] = scramble64(state[0], 0xdd51e5d1c9a5a151)
state[1] = scramble64(state[1], 0x93a7d6c8c62e4835)
state[1] = scramble64(state[1], 0x803340f36895c2b5)
state[2] = scramble64(state[2], 0xbea9344eb7565eeb)
state[2] = scramble64(state[2], 0xcd95d1e509b995cd)
state[3] = scramble64(state[3], 0x9999791977e30c13)
state[3] = scramble64(state[3], 0xaab8b6b05abfc6cd)
return state
}
type State [4]uint64