summaryrefslogtreecommitdiff
path: root/internal/stupidgcm/stupidgcm.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2018-02-18 12:33:48 +0100
committerJakob Unterwurzacher2018-02-18 12:35:51 +0100
commit72ddbae1e60470943aaae0bfce74ebdc88c07cd2 (patch)
tree7a420ca2e534e18e8d869ef6e5c3ac6a6aab2906 /internal/stupidgcm/stupidgcm.go
parent18f6c6106c66ba1fe6e7b48aaa5dd444ba0f9b09 (diff)
stupidgcm: create private copy of the key
Relieves the caller from worrying about whether they can overwrite the key.
Diffstat (limited to 'internal/stupidgcm/stupidgcm.go')
-rw-r--r--internal/stupidgcm/stupidgcm.go6
1 files changed, 4 insertions, 2 deletions
diff --git a/internal/stupidgcm/stupidgcm.go b/internal/stupidgcm/stupidgcm.go
index 77d6770..c8aecca 100644
--- a/internal/stupidgcm/stupidgcm.go
+++ b/internal/stupidgcm/stupidgcm.go
@@ -33,10 +33,12 @@ type StupidGCM struct {
var _ cipher.AEAD = &StupidGCM{}
// New returns a new cipher.AEAD implementation..
-func New(key []byte, forceDecode bool) cipher.AEAD {
- if len(key) != keyLen {
+func New(keyIn []byte, forceDecode bool) cipher.AEAD {
+ if len(keyIn) != keyLen {
log.Panicf("Only %d-byte keys are supported", keyLen)
}
+ // Create a private copy of the key
+ key := append([]byte{}, keyIn...)
return &StupidGCM{key: key, forceDecode: forceDecode}
}