aboutsummaryrefslogtreecommitdiff
path: root/backend_nonce.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2015-09-03 18:57:28 +0200
committerJakob Unterwurzacher2015-09-03 19:09:11 +0200
commitf8fddff7694b2cb9487fd4b5cbe9f97a136600b0 (patch)
treec592e59683165d9af1116e65fa16ffddff1bb7c5 /backend_nonce.go
parent4e93fdf820695c6afb38d525b5cf1dcc64080305 (diff)
Split into FS and File
Diffstat (limited to 'backend_nonce.go')
-rw-r--r--backend_nonce.go55
1 files changed, 0 insertions, 55 deletions
diff --git a/backend_nonce.go b/backend_nonce.go
deleted file mode 100644
index 835a80f..0000000
--- a/backend_nonce.go
+++ /dev/null
@@ -1,55 +0,0 @@
-package gocryptfs
-
-import (
- "encoding/binary"
- "encoding/hex"
- "sync"
- "crypto/rand"
-)
-
-type nonce96 struct {
- lock sync.Mutex
- high32 uint32
- low64 uint64
- ready int
-}
-
-var gcmNonce nonce96
-
-func (n *nonce96) randBytes(len int) []byte {
- b := make([]byte, len)
- _, err := rand.Read(b)
- if err != nil {
- panic("Could not get random bytes for nonce")
- }
- return b
-}
-
-func (n *nonce96) init() {
- b := n.randBytes(8)
- n.low64 = binary.BigEndian.Uint64(b)
- b = n.randBytes(4)
- n.high32 = binary.BigEndian.Uint32(b)
- n.ready = 1
- return
-}
-
-func (n *nonce96) Get() []byte {
- n.lock.Lock()
- if n.ready == 0 {
- n.init()
- }
- n.low64++
- if n.low64 == 0 {
- // Counter has wrapped
- n.high32++
- }
- r := make([]byte, 12)
- binary.BigEndian.PutUint32(r[0:4], n.high32)
- binary.BigEndian.PutUint64(r[4:12], n.low64)
- n.lock.Unlock()
-
- debug.Printf("nonce96.Get(): %s\n", hex.EncodeToString(r))
-
- return r
-}