summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorJakob Unterwurzacher2017-06-07 23:08:43 +0200
committerJakob Unterwurzacher2017-06-07 23:08:43 +0200
commitd2be22a07f32d5c41223419314c9fb6b8ad2ab42 (patch)
tree99f2c42cc06be5e635a63a9378083a02aa3242f8 /internal
parent294628b38435698ec63f2b13044ec993af1563f1 (diff)
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.
Diffstat (limited to 'internal')
-rw-r--r--internal/cryptocore/nonce.go14
1 files changed, 1 insertions, 13 deletions
diff --git a/internal/cryptocore/nonce.go b/internal/cryptocore/nonce.go
index 3f56cc9..412cdbb 100644
--- a/internal/cryptocore/nonce.go
+++ b/internal/cryptocore/nonce.go
@@ -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
}