summaryrefslogtreecommitdiff
path: root/cryptfs/nonce.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2015-09-13 17:55:07 +0200
committerJakob Unterwurzacher2015-09-13 17:55:07 +0200
commit4acaeb668ea236ded06157fd312463b5faafbdab (patch)
tree33642be24fd265e9d071176f92d52a63e1b4f2b8 /cryptfs/nonce.go
parente7ba3c61f1055d740539d608cc521d816d07cddd (diff)
Implement json config storage (not yet encrypted)
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