summaryrefslogtreecommitdiff
path: root/internal/stupidgcm/stupidgcm.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2018-05-10 22:44:03 +0200
committerJakob Unterwurzacher2018-05-10 23:00:02 +0200
commita276321dea04eaa0cfc80c56e8faca4b8ded0b7a (patch)
treed809216c05d7b8abe020068c9e66ada225b59f57 /internal/stupidgcm/stupidgcm.go
parent5ccc06d5cb321b1400e33a7d0819bf617c52600d (diff)
stupidgcm: return error on too short input instead of panicing
This is what Go GCM does as well.
Diffstat (limited to 'internal/stupidgcm/stupidgcm.go')
-rw-r--r--internal/stupidgcm/stupidgcm.go7
1 files changed, 4 insertions, 3 deletions
diff --git a/internal/stupidgcm/stupidgcm.go b/internal/stupidgcm/stupidgcm.go
index 59636c0..82d0323 100644
--- a/internal/stupidgcm/stupidgcm.go
+++ b/internal/stupidgcm/stupidgcm.go
@@ -10,6 +10,7 @@ import "C"
import (
"crypto/cipher"
+ "fmt"
"log"
"unsafe"
)
@@ -144,12 +145,12 @@ func (g *StupidGCM) Open(dst, iv, in, authData []byte) ([]byte, error) {
if len(iv) != ivLen {
log.Panicf("Only %d-byte IVs are supported", ivLen)
}
- if len(in) <= tagLen {
- log.Panic("Input data too short")
- }
if len(g.key) != keyLen {
log.Panicf("Wrong key length: %d. Key has been wiped?", len(g.key))
}
+ if len(in) <= tagLen {
+ return nil, fmt.Errorf("stupidgcm: input data too short (%d bytes)", len(in))
+ }
// If the "dst" slice is large enough we can use it as our output buffer
outLen := len(in) - tagLen