-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathctr.go
More file actions
29 lines (25 loc) · 666 Bytes
/
Copy pathctr.go
File metadata and controls
29 lines (25 loc) · 666 Bytes
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
package aes
import (
stdaes "crypto/aes"
"crypto/cipher"
"github.com/colduction/aes-go/padding"
)
func encryptCTR(block cipher.Block, src, iv []byte, pad padding.Padding) ([]byte, error) {
var err error
if pad != nil {
if src, err = pad.Pad(src, stdaes.BlockSize); err != nil {
return nil, err
}
}
dst := make([]byte, len(src))
cipher.NewCTR(block, iv).XORKeyStream(dst, src)
return dst, nil
}
func decryptCTR(block cipher.Block, src, iv []byte, pad padding.Padding) ([]byte, error) {
dst := make([]byte, len(src))
cipher.NewCTR(block, iv).XORKeyStream(dst, src)
if pad != nil {
return pad.Unpad(dst, stdaes.BlockSize)
}
return dst, nil
}