ceremonyclient/bedlam/apps/garbled/examples/aesgcm.qcl
Cassandra Heart e51992f3e8
OT
2025-03-23 21:11:16 -05:00

29 lines
633 B
Go

// -*- go -*-
package main
import (
"bytes"
"crypto/cipher/gcm"
)
func main(a, b byte) (string, int) {
key := []byte{
0x06, 0xa9, 0x21, 0x40, 0x36, 0xb8, 0xa1, 0x5b,
0x51, 0x2e, 0x03, 0xd5, 0x34, 0x12, 0x00, 0x06,
}
nonce := []byte{
0x3d, 0xaf, 0xba, 0x42, 0x9d, 0x9e, 0xb4, 0x30,
0xb4, 0x22, 0xda, 0x80,
}
plain := []byte("Single block msgSingle block msg")
additional := []byte("additional data to be authenticated")
c := gcm.EncryptAES128(key, nonce, plain, additional)
p, ok := gcm.DecryptAES128(key, nonce, c, additional)
if !ok {
return "Open failed", 0
}
return string(p), bytes.Compare(plain, p)
}