vpaes-x86[_64].pl: handle zero length in vpaes_cbc_encrypt.
authorAndy Polyakov <appro@openssl.org>
Sat, 31 Mar 2012 16:53:34 +0000 (16:53 +0000)
committerAndy Polyakov <appro@openssl.org>
Sat, 31 Mar 2012 16:53:34 +0000 (16:53 +0000)
PR: 2775

crypto/aes/asm/vpaes-x86.pl
crypto/aes/asm/vpaes-x86_64.pl

index 84a6f6d336ca421b9e22de2515b5dbef6e6f45db..1533e2c3042c7f8e0112cd9e30a676babf3c6b47 100644 (file)
@@ -843,6 +843,8 @@ $k_dsbo=0x2c0;              # decryption sbox final output
        &mov    ($out,&wparam(1));              # out
        &mov    ($round,&wparam(2));            # len
        &mov    ($key,&wparam(3));              # key
+       &sub    ($round,16);
+       &jc     (&label("cbc_abort"));
        &lea    ($base,&DWP(-56,"esp"));
        &mov    ($const,&wparam(4));            # ivp
        &and    ($base,-16);
@@ -853,7 +855,6 @@ $k_dsbo=0x2c0;              # decryption sbox final output
        &mov    (&DWP(48,"esp"),$base);
 
        &mov    (&DWP(0,"esp"),$out);           # save out
-       &sub    ($round,16);
        &mov    (&DWP(4,"esp"),$key)            # save key
        &mov    (&DWP(8,"esp"),$const);         # save ivp
        &mov    ($out,$round);                  # $out works as $len
@@ -896,6 +897,7 @@ $k_dsbo=0x2c0;              # decryption sbox final output
        &mov    ($base,&DWP(8,"esp"));          # restore ivp
        &mov    ("esp",&DWP(48,"esp"));
        &movdqu (&QWP(0,$base),"xmm1");         # write IV
+&set_label("cbc_abort");
 &function_end("${PREFIX}_cbc_encrypt");
 
 &asm_finish();
index a6d8d02e75e6a541c03bc2524023ee83ba780cde..37998db5e139eb320874ab917391855a28ae4879 100644 (file)
@@ -869,6 +869,8 @@ ${PREFIX}_cbc_encrypt:
 ___
 ($len,$key)=($key,$len);
 $code.=<<___;
+       sub     \$16,$len
+       jc      .Lcbc_abort
 ___
 $code.=<<___ if ($win64);
        lea     -0xb8(%rsp),%rsp
@@ -887,7 +889,6 @@ ___
 $code.=<<___;
        movdqu  ($ivp),%xmm6            # load IV
        sub     $inp,$out
-       sub     \$16,$len
        call    _vpaes_preheat
        cmp     \$0,${enc}d
        je      .Lcbc_dec_loop
@@ -932,6 +933,7 @@ $code.=<<___ if ($win64);
 .Lcbc_epilogue:
 ___
 $code.=<<___;
+.Lcbc_abort:
        ret
 .size  ${PREFIX}_cbc_encrypt,.-${PREFIX}_cbc_encrypt
 ___