2018-04-21 23:04:07 +00:00
|
|
|
package keyset
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/rand"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
/* (2) Generates a pseudo-random KeySet
|
|
|
|
*
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
func (s *T) generate() {
|
|
|
|
|
|
|
|
/* (1) Seed randomness */
|
|
|
|
rand.Seed(time.Now().UTC().UnixNano())
|
|
|
|
|
|
|
|
/* (1) Generate new secret
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) Reset current secret */
|
|
|
|
s.sec = make([]byte, SecretSize)
|
|
|
|
|
|
|
|
/* (2) Generate each char. until same length as hash digest */
|
|
|
|
for i := uint16(0); i < SecretSize; i++ {
|
|
|
|
s.sec[i] = byte(rand.Int() % 256)
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (2) Manage other attributes
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) Random depth pick init */
|
2018-09-06 14:41:03 +00:00
|
|
|
var randMin, randMax = s.ctx.MinDepth() + (s.ctx.MaxDepth()-s.ctx.MinDepth())/2, s.ctx.MaxDepth()
|
2018-04-21 23:04:07 +00:00
|
|
|
|
|
|
|
/* (2) Select "random" depth */
|
2018-04-23 16:02:19 +00:00
|
|
|
s.depth = randMin + uint16(rand.Intn(int(randMax+1-randMin)))
|
2018-04-21 23:04:07 +00:00
|
|
|
|
|
|
|
/* (3) Reset comsumption level */
|
2018-04-22 15:13:08 +00:00
|
|
|
s.mcode = 0
|
2018-04-21 23:04:07 +00:00
|
|
|
|
2018-09-06 14:41:03 +00:00
|
|
|
}
|