blob: ad80b9aeff25d4e227f91a8bfe0c02a162918086 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
package gocryptfs
import (
"crypto/cipher"
"crypto/aes"
)
const (
NONCE_LEN = 12
AUTH_TAG_LEN = 16
DEFAULT_PLAINBS = 4096
ENCRYPT = true
DECRYPT = false
)
type Backend struct {
blockCipher cipher.Block
gcm cipher.AEAD
plainBS int64
cipherBS int64
}
func New(key [16]byte) *Backend {
b, err := aes.NewCipher(key[:])
if err != nil {
panic(err)
}
g, err := cipher.NewGCM(b)
if err != nil {
panic(err)
}
return &Backend{
blockCipher: b,
gcm: g,
plainBS: DEFAULT_PLAINBS,
cipherBS: DEFAULT_PLAINBS + NONCE_LEN + AUTH_TAG_LEN,
}
}
|