Skip to content

Commit 22bfce6

Browse files
committed
optimize createprng
1 parent 725ecbc commit 22bfce6

File tree

1 file changed

+1
-9
lines changed

1 file changed

+1
-9
lines changed

qpp.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,23 +109,15 @@ func (qpp *QuantumPermutationPad) CreatePRNG(seed []byte) *Rand {
109109
mac.Write([]byte(PM_SELECTOR_IDENTIFIER))
110110
sum := mac.Sum(nil)
111111

112-
// Derive a key for PRNG
113-
dk := pbkdf2.Key(sum, []byte(PRNG_SALT), PBKDF2_LOOPS, 8, sha1.New)
114-
seed64 := binary.LittleEndian.Uint64(dk)
115-
if seed64 == 0 {
116-
seed64 = MAGIC
117-
}
118-
119112
// Derive a key for xoroshiro256**
120113
xoshiro := pbkdf2.Key(sum, []byte(PRNG_SALT), PBKDF2_LOOPS, 32, sha1.New)
121-
122114
// Create and return PRNG
123115
rd := &Rand{}
124-
rd.seed64 = seed64 // initial random number
125116
rd.xoshiro[0] = binary.LittleEndian.Uint64(xoshiro[0:8])
126117
rd.xoshiro[1] = binary.LittleEndian.Uint64(xoshiro[8:16])
127118
rd.xoshiro[2] = binary.LittleEndian.Uint64(xoshiro[16:24])
128119
rd.xoshiro[3] = binary.LittleEndian.Uint64(xoshiro[24:32])
120+
rd.seed64 = xoshiro256ss(&rd.xoshiro)
129121
return rd
130122
}
131123

0 commit comments

Comments
 (0)