Skip to content

Commit

Permalink
avoid panic while encrypting empty data (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
rameshrv authored and zeebo committed Oct 17, 2018
1 parent a66df3e commit c2dcc5c
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ciphers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit c2dcc5c

Please sign in to comment.