@@ -11,28 +11,28 @@ import (
11
11
)
12
12
13
13
const (
14
- // AESGCMNonceSize is the size of an AES-GCM nonce
14
+ // AESGCMNonceSize is the size of an AES-GCM nonce.
15
15
AESGCMNonceSize = 12
16
- // unit32Size is the number of bytes in the uint32 type
16
+ // unit32Size is the number of bytes in the uint32 type.
17
17
uint32Size = 4
18
18
)
19
19
20
- // AESGCMNonce represents the nonce used by the AES-GCM protocol
20
+ // AESGCMNonce represents the nonce used by the AES-GCM protocol.
21
21
type AESGCMNonce [AESGCMNonceSize ]byte
22
22
23
- // ToAESGCMNonce returns the nonce as a AES-GCM nonce
23
+ // ToAESGCMNonce returns the nonce as a AES-GCM nonce.
24
24
func ToAESGCMNonce (nonce * storj.Nonce ) * AESGCMNonce {
25
25
aes := new (AESGCMNonce )
26
26
copy ((* aes )[:], nonce [:AESGCMNonceSize ])
27
27
return aes
28
28
}
29
29
30
- // Increment increments the nonce with the given amount
30
+ // Increment increments the nonce with the given amount.
31
31
func Increment (nonce * storj.Nonce , amount int64 ) (truncated bool , err error ) {
32
32
return incrementBytes (nonce [:], amount )
33
33
}
34
34
35
- // Encrypt encrypts data with the given cipher, key and nonce
35
+ // Encrypt encrypts data with the given cipher, key and nonce.
36
36
func Encrypt (data []byte , cipher storj.CipherSuite , key * storj.Key , nonce * storj.Nonce ) (cipherData []byte , err error ) {
37
37
// Don't encrypt empty slice
38
38
if len (data ) == 0 {
@@ -53,7 +53,7 @@ func Encrypt(data []byte, cipher storj.CipherSuite, key *storj.Key, nonce *storj
53
53
}
54
54
}
55
55
56
- // Decrypt decrypts cipherData with the given cipher, key and nonce
56
+ // Decrypt decrypts cipherData with the given cipher, key and nonce.
57
57
func Decrypt (cipherData []byte , cipher storj.CipherSuite , key * storj.Key , nonce * storj.Nonce ) (data []byte , err error ) {
58
58
// Don't decrypt empty slice
59
59
if len (cipherData ) == 0 {
@@ -74,7 +74,7 @@ func Decrypt(cipherData []byte, cipher storj.CipherSuite, key *storj.Key, nonce
74
74
}
75
75
}
76
76
77
- // NewEncrypter creates a Transformer using the given cipher, key and nonce to encrypt data passing through it
77
+ // NewEncrypter creates a Transformer using the given cipher, key and nonce to encrypt data passing through it.
78
78
func NewEncrypter (cipher storj.CipherSuite , key * storj.Key , startingNonce * storj.Nonce , encryptedBlockSize int ) (Transformer , error ) {
79
79
switch cipher {
80
80
case storj .EncNull :
@@ -90,7 +90,7 @@ func NewEncrypter(cipher storj.CipherSuite, key *storj.Key, startingNonce *storj
90
90
}
91
91
}
92
92
93
- // NewDecrypter creates a Transformer using the given cipher, key and nonce to decrypt data passing through it
93
+ // NewDecrypter creates a Transformer using the given cipher, key and nonce to decrypt data passing through it.
94
94
func NewDecrypter (cipher storj.CipherSuite , key * storj.Key , startingNonce * storj.Nonce , encryptedBlockSize int ) (Transformer , error ) {
95
95
switch cipher {
96
96
case storj .EncNull :
@@ -106,12 +106,12 @@ func NewDecrypter(cipher storj.CipherSuite, key *storj.Key, startingNonce *storj
106
106
}
107
107
}
108
108
109
- // EncryptKey encrypts keyToEncrypt with the given cipher, key and nonce
109
+ // EncryptKey encrypts keyToEncrypt with the given cipher, key and nonce.
110
110
func EncryptKey (keyToEncrypt * storj.Key , cipher storj.CipherSuite , key * storj.Key , nonce * storj.Nonce ) (storj.EncryptedPrivateKey , error ) {
111
111
return Encrypt (keyToEncrypt [:], cipher , key , nonce )
112
112
}
113
113
114
- // DecryptKey decrypts keyToDecrypt with the given cipher, key and nonce
114
+ // DecryptKey decrypts keyToDecrypt with the given cipher, key and nonce.
115
115
func DecryptKey (keyToDecrypt storj.EncryptedPrivateKey , cipher storj.CipherSuite , key * storj.Key , nonce * storj.Nonce ) (* storj.Key , error ) {
116
116
plainData , err := Decrypt (keyToDecrypt , cipher , key , nonce )
117
117
if err != nil {
@@ -124,7 +124,7 @@ func DecryptKey(keyToDecrypt storj.EncryptedPrivateKey, cipher storj.CipherSuite
124
124
return & decryptedKey , nil
125
125
}
126
126
127
- // DeriveKey derives new key from the given key and message using HMAC-SHA512
127
+ // DeriveKey derives new key from the given key and message using HMAC-SHA512.
128
128
func DeriveKey (key * storj.Key , message string ) (* storj.Key , error ) {
129
129
mac := hmac .New (sha512 .New , key [:])
130
130
_ , err := mac .Write ([]byte (message ))
0 commit comments