summaryrefslogtreecommitdiff
path: root/cryptfs/nonce.go
diff options
context:
space:
mode:
Diffstat (limited to 'cryptfs/nonce.go')
-rw-r--r--cryptfs/nonce.go9
1 files changed, 5 insertions, 4 deletions
diff --git a/cryptfs/nonce.go b/cryptfs/nonce.go
index f93f59c..3e464a3 100644
--- a/cryptfs/nonce.go
+++ b/cryptfs/nonce.go
@@ -16,8 +16,9 @@ type nonce96 struct {
var gcmNonce nonce96
-func (n *nonce96) randBytes(len int) []byte {
- b := make([]byte, len)
+// Get "n" random bytes from /dev/urandom or panic
+func RandBytes(n int) []byte {
+ b := make([]byte, n)
_, err := rand.Read(b)
if err != nil {
panic("Could not get random bytes for nonce")
@@ -26,9 +27,9 @@ func (n *nonce96) randBytes(len int) []byte {
}
func (n *nonce96) init() {
- b := n.randBytes(8)
+ b := RandBytes(8)
n.low64 = binary.BigEndian.Uint64(b)
- b = n.randBytes(4)
+ b = RandBytes(4)
n.high32 = binary.BigEndian.Uint32(b)
n.ready = 1
return