Skip to content

Commit

Permalink
Bug 1613238 - POWER SHA-2 digest vector acceleration. r=jcj,kjacobs
Browse files Browse the repository at this point in the history
Differential Revision: https://phabricator.services.mozilla.com/D70519

--HG--
extra : moz-landing-system : lando
  • Loading branch information
clbr committed Apr 21, 2020
1 parent 23dc96b commit 7d4b0ba
Show file tree
Hide file tree
Showing 11 changed files with 1,940 additions and 100 deletions.
3 changes: 3 additions & 0 deletions lib/freebl/Makefile
Expand Up @@ -267,6 +267,7 @@ ifeq ($(CPU_ARCH),arm)
endif
ifeq ($(CPU_ARCH),ppc)
EXTRA_SRCS += gcm-ppc.c
ASFILES += sha512-p8.s
ifdef USE_64
DEFINES += -DNSS_NO_INIT_SUPPORT
endif # USE_64
Expand Down Expand Up @@ -794,6 +795,8 @@ ifndef NSS_DISABLE_ALTIVEC
$(OBJDIR)/$(PROG_PREFIX)gcm-ppc$(OBJ_SUFFIX): CFLAGS += -mcrypto -maltivec -mvsx
$(OBJDIR)/$(PROG_PREFIX)gcm$(OBJ_SUFFIX): CFLAGS += -mcrypto -maltivec -mvsx
$(OBJDIR)/$(PROG_PREFIX)rijndael$(OBJ_SUFFIX): CFLAGS += -mcrypto -maltivec -mvsx
$(OBJDIR)/$(PROG_PREFIX)sha512$(OBJ_SUFFIX): CFLAGS += -mcrypto -maltivec -mvsx \
-funroll-loops -fpeel-loops
endif
endif

Expand Down
58 changes: 56 additions & 2 deletions lib/freebl/freebl.gyp
Expand Up @@ -258,7 +258,8 @@
'target_name': 'gcm-aes-ppc_c_lib',
'type': 'static_library',
'sources': [
'gcm-ppc.c'
'gcm-ppc.c',
'sha512-p8.s',
],
'dependencies': [
'<(DEPTH)/exports.gyp:nss_exports'
Expand All @@ -270,7 +271,58 @@
'cflags_mozilla': [
'-mcrypto',
'-maltivec'
]
],
},
{
'target_name': 'gcm-sha512-nodepend-ppc_c_lib',
'type': 'static_library',
'sources': [
'sha512.c',
],
'dependencies': [
'<(DEPTH)/exports.gyp:nss_exports'
],
'cflags': [
'-mcrypto',
'-maltivec',
'-mvsx',
'-funroll-loops',
'-fpeel-loops',
],
'cflags_mozilla': [
'-mcrypto',
'-maltivec',
'-mvsx',
'-funroll-loops',
'-fpeel-loops',
],
},
{
'target_name': 'gcm-sha512-ppc_c_lib',
'type': 'static_library',
'sources': [
'sha512.c',
],
'dependencies': [
'<(DEPTH)/exports.gyp:nss_exports'
],
'cflags': [
'-mcrypto',
'-maltivec',
'-mvsx',
'-funroll-loops',
'-fpeel-loops',
],
'cflags_mozilla': [
'-mcrypto',
'-maltivec',
'-mvsx',
'-funroll-loops',
'-fpeel-loops',
],
'defines!': [
'FREEBL_NO_DEPEND',
],
},
{
'target_name': 'armv8_c_lib',
Expand Down Expand Up @@ -355,6 +407,7 @@
[ 'disable_altivec==0 and (target_arch=="ppc64" or target_arch=="ppc64le")', {
'dependencies': [
'gcm-aes-ppc_c_lib',
'gcm-sha512-ppc_c_lib',
],
}],
[ 'disable_altivec==1 and (target_arch=="ppc64" or target_arch=="ppc64le")', {
Expand Down Expand Up @@ -422,6 +475,7 @@
[ 'disable_altivec==0 and (target_arch=="ppc64" or target_arch=="ppc64le")', {
'dependencies': [
'gcm-aes-ppc_c_lib',
'gcm-sha512-nodepend-ppc_c_lib',
],
}],
[ 'disable_altivec==1 and (target_arch=="ppc64" or target_arch=="ppc64le")', {
Expand Down
8 changes: 7 additions & 1 deletion lib/freebl/freebl_base.gypi
Expand Up @@ -56,7 +56,6 @@
'rsa.c',
'rsapkcs.c',
'seed.c',
'sha512.c',
'sha_fast.c',
'shvfy.c',
'sysrand.c',
Expand Down Expand Up @@ -146,6 +145,13 @@
'ecl/curve25519_32.c',
],
}],
['(target_arch!="ppc64" and target_arch!="ppc64le") or disable_altivec==1', {
'sources': [
# Gyp does not support per-file cflags, so working around like this.
# ppc performance greatly benefits from specific flags.
'sha512.c',
],
}],
[ 'disable_chachapoly==0', {
# The ChaCha20 code is linked in through the static ssse3-crypto lib on
# all platforms that support SSSE3. There are runtime checks in place to
Expand Down
22 changes: 2 additions & 20 deletions lib/freebl/gcm.h
Expand Up @@ -31,26 +31,8 @@
#include <arm_neon.h>
#endif

#if defined(__powerpc64__) && !defined(NSS_DISABLE_ALTIVEC)
#include "altivec-types.h"

/* The ghash freebl test tries to use this in C++, and gcc defines conflict. */
#ifdef __cplusplus
#undef pixel
#undef vector
#undef bool
#endif

/*
* PPC CRYPTO requires at least gcc 8 or clang. The LE check is purely
* because it's only been tested on LE. If you're interested in BE,
* please send a patch.
*/
#if (defined(__clang__) || (defined(__GNUC__) && __GNUC__ >= 8)) && \
defined(IS_LITTLE_ENDIAN)
#define USE_PPC_CRYPTO
#endif

#if defined(__powerpc64__)
#include "ppc-crypto.h"
#endif

SEC_BEGIN_PROTOS
Expand Down
30 changes: 30 additions & 0 deletions lib/freebl/ppc-crypto.h
@@ -0,0 +1,30 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef PPC_CRYPTO_H
#define PPC_CRYPTO_H 1

#if defined(__powerpc64__) && !defined(NSS_DISABLE_ALTIVEC)
#include "altivec-types.h"

/* The ghash freebl test tries to use this in C++, and gcc defines conflict. */
#ifdef __cplusplus
#undef pixel
#undef vector
#undef bool
#endif

/*
* PPC CRYPTO requires at least gcc 8 or clang. The LE check is purely
* because it's only been tested on LE. If you're interested in BE,
* please send a patch.
*/
#if (defined(__clang__) || (defined(__GNUC__) && __GNUC__ >= 8)) && \
defined(IS_LITTLE_ENDIAN)
#define USE_PPC_CRYPTO
#endif

#endif /* defined(__powerpc64__) && !defined(NSS_DISABLE_ALTIVEC) */

#endif
36 changes: 36 additions & 0 deletions lib/freebl/scripts/LICENSE
@@ -0,0 +1,36 @@
Copyright (c) 2006, CRYPTOGAMS by <appro@openssl.org>
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

* Redistributions of source code must retain copyright notices,
this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials
provided with the distribution.

* Neither the name of the CRYPTOGAMS nor the names of its
copyright holder and contributors may be used to endorse or
promote products derived from this software without specific
prior written permission.

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.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
19 changes: 19 additions & 0 deletions lib/freebl/scripts/gen.sh
@@ -0,0 +1,19 @@
#!/bin/sh
#
# Run the scripts in this folder, generating the assembly,
#

perl sha512p8-ppc.pl linux64le sha512-p8.s

# Add the license mention
cat > hdr << "EOF"
# Copyright (c) 2006, CRYPTOGAMS by <appro@openssl.org>
# All rights reserved.
# See the full LICENSE under scripts/.
EOF

cat hdr sha512-p8.s > ../sha512-p8.s

# Cleanup
rm hdr sha512-p8.s

0 comments on commit 7d4b0ba

Please sign in to comment.