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
57
|
//go:build !without_aegis && cgo
// +build !without_aegis,cgo
package stupidgcm
import (
"crypto/cipher"
"log"
"github.com/aegis-aead/go-libaegis/aegis128x2"
"github.com/aegis-aead/go-libaegis/common"
)
const (
// BuiltWithoutAegis indicates if aegis been disabled at compile-time
BuiltWithoutAegis = !common.Available
// Aegis supports 16 and 32 bit tags
AegisTagLen = 16
)
type stupidAegis struct {
aead cipher.AEAD
}
// Verify that we satisfy the cipher.AEAD interface
var _ cipher.AEAD = &stupidAegis{}
func (*stupidAegis) NonceSize() int {
return aegis128x2.NonceSize
}
func (*stupidAegis) Overhead() int {
return AegisTagLen
}
func NewAegis(key []byte) cipher.AEAD {
aead, err := aegis128x2.New(key, AegisTagLen)
if err != nil {
log.Panic(err)
}
return &stupidAegis{
aead: aead,
}
}
func (x *stupidAegis) Seal(dst, nonce, plaintext, additionalData []byte) []byte {
return x.aead.Seal(dst, nonce, plaintext, additionalData)
}
func (x *stupidAegis) Open(dst, nonce, ciphertext, additionalData []byte) ([]byte, error) {
return x.aead.Open(dst, nonce, ciphertext, additionalData)
}
func (x *stupidAegis) Wipe() {
x.aead.(*aegis128x2.Aegis128X2).Wipe()
}
|