@@ -56,6 +56,9 @@ func (g *stupidGCM) Seal(dst, iv, in, authData []byte) []byte {
56
56
if len (in ) == 0 {
57
57
log .Panic ("Zero-length input data is not supported" )
58
58
}
59
+ if len (g .key ) != keyLen {
60
+ log .Panicf ("Wrong key length: %d. Key has been wiped?" , len (g .key ))
61
+ }
59
62
60
63
// If the "dst" slice is large enough we can use it as our output buffer
61
64
outLen := len (in ) + tagLen
@@ -140,6 +143,9 @@ func (g *stupidGCM) Open(dst, iv, in, authData []byte) ([]byte, error) {
140
143
if len (in ) <= tagLen {
141
144
log .Panic ("Input data too short" )
142
145
}
146
+ if len (g .key ) != keyLen {
147
+ log .Panicf ("Wrong key length: %d. Key has been wiped?" , len (g .key ))
148
+ }
143
149
144
150
// If the "dst" slice is large enough we can use it as our output buffer
145
151
outLen := len (in ) - tagLen
@@ -224,3 +230,15 @@ func (g *stupidGCM) Open(dst, iv, in, authData []byte) ([]byte, error) {
224
230
}
225
231
return append (dst , buf ... ), nil
226
232
}
233
+
234
+ // Wipe wipes the AES key from memory by overwriting it with zeros and
235
+ // setting the reference to nil.
236
+ //
237
+ // This is not bulletproof due to possible GC copies, but
238
+ // still raises to bar for extracting the key.
239
+ func (g * stupidGCM ) Wipe () {
240
+ for i := range g .key {
241
+ g .key [i ] = 0
242
+ }
243
+ g .key = nil
244
+ }
0 commit comments