From c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 Mon Sep 17 00:00:00 2001 From: Ramesh V Rayaprolu Date: Wed, 17 Oct 2018 13:33:07 -0700 Subject: [PATCH] avoid panic while encrypting empty data (#109) --- ciphers.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ciphers.go b/ciphers.go index 2cb87d05..509bf641 100644 --- a/ciphers.go +++ b/ciphers.go @@ -287,6 +287,9 @@ func NewDecryptionCipherCtx(c *Cipher, e *Engine, key, iv []byte) ( } func (ctx *encryptionCipherCtx) EncryptUpdate(input []byte) ([]byte, error) { + if len(input) == 0 { + return nil, nil + } outbuf := make([]byte, len(input)+ctx.BlockSize()) outlen := C.int(len(outbuf)) res := C.EVP_EncryptUpdate(ctx.ctx, (*C.uchar)(&outbuf[0]), &outlen, @@ -298,6 +301,9 @@ func (ctx *encryptionCipherCtx) EncryptUpdate(input []byte) ([]byte, error) { } func (ctx *decryptionCipherCtx) DecryptUpdate(input []byte) ([]byte, error) { + if len(input) == 0 { + return nil, nil + } outbuf := make([]byte, len(input)+ctx.BlockSize()) outlen := C.int(len(outbuf)) res := C.EVP_DecryptUpdate(ctx.ctx, (*C.uchar)(&outbuf[0]), &outlen,