Re: [PATCH 1/2] crypto: vmx - Adding asm subroutines for XTS

2016-07-13 Thread Paulo Flabiano Smorigo
Thu, Jul 14, 2016 at 01:11:58AM +1000, Stephen Rothwell wrote:
> Hi Paulo,
> 
> On Wed, 13 Jul 2016 10:34:27 -0300 Paulo Flabiano Smorigo 
>  wrote:
> >
> > Wed, Jul 13, 2016 at 01:05:03PM +1000, Stewart Smith wrote:
> > > Stephen Rothwell  writes:  
> > > > On Mon, 11 Jul 2016 16:07:39 -0300 Paulo Flabiano Smorigo 
> > > >  wrote:  
> > > >>
> > > >> diff --git a/drivers/crypto/vmx/aesp8-ppc.pl 
> > > >> b/drivers/crypto/vmx/aesp8-ppc.pl
> > > >> index 2280539..813ffcc 100644
> > > >> --- a/drivers/crypto/vmx/aesp8-ppc.pl
> > > >> +++ b/drivers/crypto/vmx/aesp8-ppc.pl
> > > >> @@ -1,4 +1,11 @@
> > > >> -#!/usr/bin/env perl
> > > >> +#! /usr/bin/env perl
> > > >> +# Copyright 2014-2016 The OpenSSL Project Authors. All Rights 
> > > >> Reserved.
> > > >> +#
> > > >> +# Licensed under the OpenSSL license (the "License").  You may not use
> > > >> +# this file except in compliance with the License.  You can obtain a 
> > > >> copy
> > > >> +# in the file LICENSE in the source distribution or at
> > > >> +# https://www.openssl.org/source/license.html  
> > > >
> > > > So, I assume that this license is compatible with the GPLv2?  
> > 
> > Andy released this code under the cryptogams license:
> > 
> > # 
> > # Written by Andy Polyakov  for the OpenSSL
> > # project. The module is, however, dual licensed under OpenSSL and
> > # CRYPTOGAMS licenses depending on where you obtain it. For further
> > # details see http://www.openssl.org/~appro/cryptogams/.
> > # 
> 
> Yeah, this license statement is already in the file being patched, so
> why is the above license (and Copyright notice) being added above the
> existing one?

aesp8-ppc.pl from Linux is almost the same as the one from OpenSSL and we do
that so we can keep it updated on both projects.
The above license lines were added to all pl files in OpenSSL so it ended up
here but since the author published it as cryptogams too we are ok.

> 
> > The license is GPL compatible:
> 
> Good, thanks.
> 
> > ALTERNATIVELY, provided that this notice is retained in full, this
> > product may be distributed under the terms of the GNU General Public
> > License (GPL), in which case the provisions of the GPL apply INSTEAD OF
> > those given above.
> 
> Which is not in this file or the patch, but presumably in the referred
> to web page.

Yes, that comment is from the url pointed in the code.

> 
> Of course, I am not a lawyer :-)
> -- 
> Cheers,
> Stephen Rothwell
> 

-- 
Paulo Flabiano Smorigo
IBM Linux Technology Center



Re: [PATCH 1/2] crypto: vmx - Adding asm subroutines for XTS

2016-07-13 Thread Stephen Rothwell
Hi Paulo,

On Wed, 13 Jul 2016 10:34:27 -0300 Paulo Flabiano Smorigo 
 wrote:
>
> Wed, Jul 13, 2016 at 01:05:03PM +1000, Stewart Smith wrote:
> > Stephen Rothwell  writes:  
> > > On Mon, 11 Jul 2016 16:07:39 -0300 Paulo Flabiano Smorigo 
> > >  wrote:  
> > >>
> > >> diff --git a/drivers/crypto/vmx/aesp8-ppc.pl 
> > >> b/drivers/crypto/vmx/aesp8-ppc.pl
> > >> index 2280539..813ffcc 100644
> > >> --- a/drivers/crypto/vmx/aesp8-ppc.pl
> > >> +++ b/drivers/crypto/vmx/aesp8-ppc.pl
> > >> @@ -1,4 +1,11 @@
> > >> -#!/usr/bin/env perl
> > >> +#! /usr/bin/env perl
> > >> +# Copyright 2014-2016 The OpenSSL Project Authors. All Rights Reserved.
> > >> +#
> > >> +# Licensed under the OpenSSL license (the "License").  You may not use
> > >> +# this file except in compliance with the License.  You can obtain a 
> > >> copy
> > >> +# in the file LICENSE in the source distribution or at
> > >> +# https://www.openssl.org/source/license.html  
> > >
> > > So, I assume that this license is compatible with the GPLv2?  
> 
> Andy released this code under the cryptogams license:
> 
> # 
> # Written by Andy Polyakov  for the OpenSSL
> # project. The module is, however, dual licensed under OpenSSL and
> # CRYPTOGAMS licenses depending on where you obtain it. For further
> # details see http://www.openssl.org/~appro/cryptogams/.
> # 

Yeah, this license statement is already in the file being patched, so
why is the above license (and Copyright notice) being added above the
existing one?

> The license is GPL compatible:

Good, thanks.

> ALTERNATIVELY, provided that this notice is retained in full, this
> product may be distributed under the terms of the GNU General Public
> License (GPL), in which case the provisions of the GPL apply INSTEAD OF
> those given above.

Which is not in this file or the patch, but presumably in the referred
to web page.

Of course, I am not a lawyer :-)
-- 
Cheers,
Stephen Rothwell


Re: [PATCH 1/2] crypto: vmx - Adding asm subroutines for XTS

2016-07-13 Thread Paulo Flabiano Smorigo
Wed, Jul 13, 2016 at 01:05:03PM +1000, Stewart Smith wrote:
> Stephen Rothwell  writes:
> > On Mon, 11 Jul 2016 16:07:39 -0300 Paulo Flabiano Smorigo 
> >  wrote:
> >>
> >> diff --git a/drivers/crypto/vmx/aesp8-ppc.pl 
> >> b/drivers/crypto/vmx/aesp8-ppc.pl
> >> index 2280539..813ffcc 100644
> >> --- a/drivers/crypto/vmx/aesp8-ppc.pl
> >> +++ b/drivers/crypto/vmx/aesp8-ppc.pl
> >> @@ -1,4 +1,11 @@
> >> -#!/usr/bin/env perl
> >> +#! /usr/bin/env perl
> >> +# Copyright 2014-2016 The OpenSSL Project Authors. All Rights Reserved.
> >> +#
> >> +# Licensed under the OpenSSL license (the "License").  You may not use
> >> +# this file except in compliance with the License.  You can obtain a copy
> >> +# in the file LICENSE in the source distribution or at
> >> +# https://www.openssl.org/source/license.html
> >
> > So, I assume that this license is compatible with the GPLv2?

Andy released this code under the cryptogams license:

# 
# Written by Andy Polyakov  for the OpenSSL
# project. The module is, however, dual licensed under OpenSSL and
# CRYPTOGAMS licenses depending on where you obtain it. For further
# details see http://www.openssl.org/~appro/cryptogams/.
# 

The license is GPL compatible:

ALTERNATIVELY, provided that this notice is retained in full, this
product may be distributed under the terms of the GNU General Public
License (GPL), in which case the provisions of the GPL apply INSTEAD OF
those given above.

> 
> https://people.gnome.org/~markmc/openssl-and-the-gpl.html has an
> explanation and points to:
> https://www.openssl.org/docs/faq.html#LEGAL2
> 
> which makes it anything but clearer.
> 
> it appears the answer is "probably not, unless you have an explicit
> exemption in your license"
> 
> -- 
> Stewart Smith
> OPAL Architect, IBM.

-- 
Paulo Flabiano Smorigo
IBM Linux Technology Center



Re: [PATCH 1/2] crypto: vmx - Adding asm subroutines for XTS

2016-07-12 Thread Stewart Smith
Stephen Rothwell  writes:
> On Mon, 11 Jul 2016 16:07:39 -0300 Paulo Flabiano Smorigo 
>  wrote:
>>
>> diff --git a/drivers/crypto/vmx/aesp8-ppc.pl 
>> b/drivers/crypto/vmx/aesp8-ppc.pl
>> index 2280539..813ffcc 100644
>> --- a/drivers/crypto/vmx/aesp8-ppc.pl
>> +++ b/drivers/crypto/vmx/aesp8-ppc.pl
>> @@ -1,4 +1,11 @@
>> -#!/usr/bin/env perl
>> +#! /usr/bin/env perl
>> +# Copyright 2014-2016 The OpenSSL Project Authors. All Rights Reserved.
>> +#
>> +# Licensed under the OpenSSL license (the "License").  You may not use
>> +# this file except in compliance with the License.  You can obtain a copy
>> +# in the file LICENSE in the source distribution or at
>> +# https://www.openssl.org/source/license.html
>
> So, I assume that this license is compatible with the GPLv2?

https://people.gnome.org/~markmc/openssl-and-the-gpl.html has an
explanation and points to:
https://www.openssl.org/docs/faq.html#LEGAL2

which makes it anything but clearer.

it appears the answer is "probably not, unless you have an explicit
exemption in your license"

-- 
Stewart Smith
OPAL Architect, IBM.



RE: [PATCH 1/2] crypto: vmx - Adding asm subroutines for XTS

2016-07-12 Thread David Laight
From: Paulo Flabiano Smorigo
> Sent: 11 July 2016 20:08
> 
> This patch add XTS subroutines using VMX-crypto driver.
> 
> It gives a boost of 20 times using XTS.
> 
> These code has been adopted from OpenSSL project in collaboration
> with the original author (Andy Polyakov ).

Yep, typical openssl code. 1000+ lines of uncommented impenetrable assembler.
There is 0 chance of anyone ever checking this does what it should.

David



Re: [PATCH 1/2] crypto: vmx - Adding asm subroutines for XTS

2016-07-11 Thread Stephen Rothwell
Hi Paulo,

On Mon, 11 Jul 2016 16:07:39 -0300 Paulo Flabiano Smorigo 
 wrote:
>
> diff --git a/drivers/crypto/vmx/aesp8-ppc.pl b/drivers/crypto/vmx/aesp8-ppc.pl
> index 2280539..813ffcc 100644
> --- a/drivers/crypto/vmx/aesp8-ppc.pl
> +++ b/drivers/crypto/vmx/aesp8-ppc.pl
> @@ -1,4 +1,11 @@
> -#!/usr/bin/env perl
> +#! /usr/bin/env perl
> +# Copyright 2014-2016 The OpenSSL Project Authors. All Rights Reserved.
> +#
> +# Licensed under the OpenSSL license (the "License").  You may not use
> +# this file except in compliance with the License.  You can obtain a copy
> +# in the file LICENSE in the source distribution or at
> +# https://www.openssl.org/source/license.html

So, I assume that this license is compatible with the GPLv2?

-- 
Cheers,
Stephen Rothwell


[PATCH 1/2] crypto: vmx - Adding asm subroutines for XTS

2016-07-11 Thread Paulo Flabiano Smorigo
This patch add XTS subroutines using VMX-crypto driver.

It gives a boost of 20 times using XTS.

These code has been adopted from OpenSSL project in collaboration
with the original author (Andy Polyakov ).

Signed-off-by: Leonidas S. Barbosa 
Signed-off-by: Paulo Flabiano Smorigo 
---
 drivers/crypto/vmx/aesp8-ppc.h  |4 +
 drivers/crypto/vmx/aesp8-ppc.pl | 1865 ++-
 2 files changed, 1867 insertions(+), 2 deletions(-)

diff --git a/drivers/crypto/vmx/aesp8-ppc.h b/drivers/crypto/vmx/aesp8-ppc.h
index 4cd34ee..01972e1 100644
--- a/drivers/crypto/vmx/aesp8-ppc.h
+++ b/drivers/crypto/vmx/aesp8-ppc.h
@@ -19,3 +19,7 @@ void aes_p8_cbc_encrypt(const u8 *in, u8 *out, size_t len,
 void aes_p8_ctr32_encrypt_blocks(const u8 *in, u8 *out,
 size_t len, const struct aes_key *key,
 const u8 *iv);
+void aes_p8_xts_encrypt(const u8 *in, u8 *out, size_t len,
+   const struct aes_key *key1, const struct aes_key *key2, 
u8 *iv);
+void aes_p8_xts_decrypt(const u8 *in, u8 *out, size_t len,
+   const struct aes_key *key1, const struct aes_key *key2, 
u8 *iv);
diff --git a/drivers/crypto/vmx/aesp8-ppc.pl b/drivers/crypto/vmx/aesp8-ppc.pl
index 2280539..813ffcc 100644
--- a/drivers/crypto/vmx/aesp8-ppc.pl
+++ b/drivers/crypto/vmx/aesp8-ppc.pl
@@ -1,4 +1,11 @@
-#!/usr/bin/env perl
+#! /usr/bin/env perl
+# Copyright 2014-2016 The OpenSSL Project Authors. All Rights Reserved.
+#
+# Licensed under the OpenSSL license (the "License").  You may not use
+# this file except in compliance with the License.  You can obtain a copy
+# in the file LICENSE in the source distribution or at
+# https://www.openssl.org/source/license.html
+
 #
 # 
 # Written by Andy Polyakov  for the OpenSSL
@@ -20,6 +27,19 @@
 # instructions are interleaved. It's reckoned that eventual
 # misalignment penalties at page boundaries are in average lower
 # than additional overhead in pure AltiVec approach.
+#
+# May 2016
+#
+# Add XTS subroutine, 9x on little- and 12x improvement on big-endian
+# systems were measured.
+#
+##
+# Current large-block performance in cycles per byte processed with
+# 128-bit key (less is better).
+#
+#  CBC en-/decrypt CTR XTS
+# POWER8[le]   3.96/0.72   0.741.1
+# POWER8[be]   3.75/0.65   0.661.0
 
 $flavour = shift;
 
@@ -1875,6 +1895,1847 @@ Lctr32_enc8x_done:
 ___
 }} }}}
 
+#
+{{{# XTS procedures#
+# int aes_p8_xts_[en|de]crypt(const char *inp, char *out, size_t len,  #
+# const AES_KEY *key1, const AES_KEY *key2,
#
+# [const] unsigned char iv[16]);   #
+# If $key2 is NULL, then a "tweak chaining" mode is engaged, in which  #
+# input tweak value is assumed to be encrypted already, and last tweak #
+# value, one suitable for consecutive call on same chunk of data, is   #
+# written back to original buffer. In addition, in "tweak chaining"#
+# mode only complete input blocks are processed.   #
+
+my ($inp,$out,$len,$key1,$key2,$ivp,$rounds,$idx) =map("r$_",(3..10));
+my ($rndkey0,$rndkey1,$inout) =
map("v$_",(0..2));
+my ($output,$inptail,$inpperm,$leperm,$keyperm) =  map("v$_",(3..7));
+my ($tweak,$seven,$eighty7,$tmp,$tweak1) = map("v$_",(8..12));
+my $taillen = $key2;
+
+   ($inp,$idx) = ($idx,$inp);  # reassign
+
+$code.=<<___;
+.globl .${prefix}_xts_encrypt
+   mr  $inp,r3 # reassign
+   li  r3,-1
+   ${UCMP}i$len,16
+   bltlr-
+
+   lis r0,0xfff0
+   mfspr   r12,256 # save vrsave
+   li  r11,0
+   mtspr   256,r0
+
+   vspltisb$seven,0x07 # 0x070707..07
+   le?lvsl $leperm,r11,r11
+   le?vspltisb $tmp,0x0f
+   le?vxor $leperm,$leperm,$seven
+
+   li  $idx,15
+   lvx $tweak,0,$ivp   # load [unaligned] iv
+   lvsl$inpperm,0,$ivp
+   lvx $inptail,$idx,$ivp
+   le?vxor $inpperm,$inpperm,$tmp
+   vperm   $tweak,$tweak,$inptail,$inpperm
+
+   neg r11,$inp
+   lvsr$inpperm,0,r11  # prepare for unaligned 
load
+   lvx $inout,0,$inp
+   addi$inp,$inp,15# 15 is not typo
+   le?vxor $inpperm,$inpperm,$tmp
+
+   ${UCMP}i$key2,0 # key2==NULL?
+   beq Lxts_enc_no_key