forked from usbarmory/armory-drive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdcp.go
56 lines (45 loc) · 1.39 KB
/
dcp.go
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright (c) F-Secure Corporation
// https://foundry.f-secure.com
//
// Use of this source code is governed by the license
// that can be found in the LICENSE file.
package main
import (
"crypto/aes"
"crypto/cipher"
"github.com/f-secure-foundry/tamago/soc/imx6/dcp"
)
type dcpCipher struct {
keyIndex int
}
// NewDCPKeyRAMCipher creates and returns a new cipher.Block. The keyIndex
// argument represents a key RAM slot, set with either dcp.DeriveKey() or
// dcp.SetKey(), for hardware accelerated AES-128 encryption.
func NewDCPKeyRAMCipher(keyIndex int) (c cipher.Block, err error) {
c = &dcpCipher{
keyIndex: keyIndex,
}
return
}
// NewDCPCipher creates and returns a new cipher.Block. The key argument should
// be a 16 bytes AES key for hardware accelerated AES-128.
//
// The passed key is placed in DCP RAM slot 0 for use.
func NewDCPCipher(key []byte) (c cipher.Block, err error) {
c = &dcpCipher{
keyIndex: BLOCK_KEY,
}
return c, dcp.SetKey(BLOCK_KEY, key)
}
// BlockSize returns the AES block size in bytes.
func (c *dcpCipher) BlockSize() int {
return aes.BlockSize
}
// Encrypt performs in-place buffer encryption using AES-128-CBC.
func (c *dcpCipher) Encrypt(_ []byte, buf []byte) {
dcp.Encrypt(buf, c.keyIndex, zero)
}
// Decrypt performs in-place buffer decryption using AES-128-CBC.
func (c *dcpCipher) Decrypt(_ []byte, buf []byte) {
dcp.Decrypt(buf, c.keyIndex, zero)
}