cryptocore: remove lastNonce check

This check would need locking to be multithreading-safe.
But as it is in the fastpath, just remove it.
rand.Read() already guarantees that the value is random.
This commit is contained in:
Jakob Unterwurzacher 2017-06-07 23:08:43 +02:00
parent 294628b384
commit d2be22a07f
1 changed files with 1 additions and 13 deletions

View File

@ -1,14 +1,9 @@
package cryptocore
import (
"bytes"
"crypto/rand"
"encoding/binary"
"encoding/hex"
"fmt"
"log"
"github.com/rfjakob/gocryptfs/internal/tlog"
)
// RandBytes gets "n" random bytes from /dev/urandom or panics
@ -28,18 +23,11 @@ func RandUint64() uint64 {
}
type nonceGenerator struct {
lastNonce []byte
nonceLen int // bytes
nonceLen int // bytes
}
// Get a random "nonceLen"-byte nonce
func (n *nonceGenerator) Get() []byte {
nonce := RandBytes(n.nonceLen)
tlog.Debug.Printf("nonceGenerator.Get(): %s\n", hex.EncodeToString(nonce))
if bytes.Equal(nonce, n.lastNonce) {
m := fmt.Sprintf("Got the same nonce twice: %s. This should never happen!", hex.EncodeToString(nonce))
log.Panic(m)
}
n.lastNonce = nonce
return nonce
}