Latest update
This commit is contained in:
@@ -731,7 +731,7 @@ $code.=<<___;
|
||||
blo .Lprocess_block_ce
|
||||
ldr d31,[$inp],#8 // *inp++
|
||||
#ifdef __AARCH64EB__
|
||||
rev v31.16b,v31.16b
|
||||
rev64 v31.16b,v31.16b
|
||||
#endif
|
||||
eor $A[$j/5][$j%5],$A[$j/5][$j%5],v31.16b
|
||||
beq .Lprocess_block_ce
|
||||
@@ -740,7 +740,7 @@ ___
|
||||
$code.=<<___;
|
||||
ldr d31,[$inp],#8 // *inp++
|
||||
#ifdef __AARCH64EB__
|
||||
rev v31.16b,v31.16b
|
||||
rev64 v31.16b,v31.16b
|
||||
#endif
|
||||
eor $A[4][4],$A[4][4],v31.16b
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
# over 2x than 32-bit code. X[16] resides on stack, but access to it
|
||||
# is scheduled for L2 latency and staged through 32 least significant
|
||||
# bits of %l0-%l7. The latter is done to achieve 32-/64-bit ABI
|
||||
# duality. Nevetheless it's ~40% faster than SHA256, which is pretty
|
||||
# duality. Nevertheless it's ~40% faster than SHA256, which is pretty
|
||||
# good [optimal coefficient is 50%].
|
||||
#
|
||||
# SHA512 on UltraSPARC T1.
|
||||
|
||||
+78
-4
@@ -1,9 +1,83 @@
|
||||
LIBS=../../libcrypto
|
||||
SOURCE[../../libcrypto]=\
|
||||
sha1dgst.c sha1_one.c sha256.c sha512.c {- $target{sha1_asm_src} -} \
|
||||
{- $target{keccak1600_asm_src} -}
|
||||
|
||||
SOURCE[../../providers/fips]= sha256.c
|
||||
$SHA1ASM=
|
||||
IF[{- !$disabled{asm} -}]
|
||||
$SHA1ASM_x86=sha1-586.s sha256-586.s sha512-586.s
|
||||
$SHA1DEF_x86=SHA1_ASM SHA256_ASM SHA512_ASM
|
||||
$SHA1ASM_x86_64=\
|
||||
sha1-x86_64.s sha256-x86_64.s sha512-x86_64.s sha1-mb-x86_64.s \
|
||||
sha256-mb-x86_64.s
|
||||
$SHA1DEF_x86_64=SHA1_ASM SHA256_ASM SHA512_ASM
|
||||
|
||||
$SHA1ASM_ia64=sha1-ia64.s sha256-ia64.s sha512-ia64.s
|
||||
$SHA1DEF_ia64=SHA1_ASM SHA256_ASM SHA512_ASM
|
||||
|
||||
$SHA1ASM_sparcv9=sha1-sparcv9.S sha256-sparcv9.S sha512-sparcv9.S
|
||||
$SHA1DEF_sparcv9=SHA1_ASM SHA256_ASM SHA512_ASM
|
||||
|
||||
$SHA1ASM_alpha=sha1-alpha.S
|
||||
$SHA1DEF_alpha=SHA1_ASM
|
||||
|
||||
$SHA1ASM_mips32=sha1-mips.S sha256-mips.S
|
||||
$SHA1DEF_mips32=SHA1_ASM SHA256_ASM
|
||||
$SHA1ASM_mips64=$SHA1ASM_mips32 sha512-mips.S
|
||||
$SHA1DEF_mips64=$SHA1DEF_mips32 SHA512_ASM
|
||||
|
||||
$SHA1ASM_s390x=sha1-s390x.S sha256-s390x.S sha512-s390x.S
|
||||
$SHA1DEF_s390x=SHA1_ASM SHA256_ASM SHA512_ASM
|
||||
|
||||
$SHA1ASM_armv4=sha1-armv4-large.S sha256-armv4.S sha512-armv4.S
|
||||
$SHA1DEF_armv4=SHA1_ASM SHA256_ASM SHA512_ASM
|
||||
$SHA1ASM_aarch64=sha1-armv8.S sha256-armv8.S sha512-armv8.S
|
||||
$SHA1DEF_aarch64=SHA1_ASM SHA256_ASM SHA512_ASM
|
||||
|
||||
$SHA1ASM_parisc11=sha1-parisc.s sha256-parisc.s sha512-parisc.s
|
||||
$SHA1DEF_parisc11=SHA1_ASM SHA256_ASM SHA512_ASM
|
||||
$SHA1ASM_parisc20_64=$SHA1ASM_parisc11
|
||||
$SHA1DEF_parisc20_64=$SHA1DEF_parisc11
|
||||
|
||||
$SHA1ASM_ppc32=\
|
||||
sha1-ppc.s sha256-ppc.s sha512-ppc.s sha256p8-ppc.s sha512p8-ppc.s
|
||||
$SHA1DEF_ppc32=SHA1_ASM SHA256_ASM SHA512_ASM
|
||||
$SHA1ASM_ppc64=$SHA1ASM_ppc32
|
||||
$SHA1DEF_ppc64=$SHA1DEF_ppc32
|
||||
|
||||
$SHA1ASM_c64xplus=sha1-c64xplus.s sha256-c64xplus.s sha512-c64xplus.s
|
||||
$SHA1DEF_c64xplus=SHA1_ASM SHA256_ASM SHA512_ASM
|
||||
|
||||
# Now that we have defined all the arch specific variables, use the
|
||||
# appropriate one, and define the appropriate macros
|
||||
IF[$SHA1ASM_{- $target{asm_arch} -}]
|
||||
$SHA1ASM=$SHA1ASM_{- $target{asm_arch} -}
|
||||
$SHA1DEF=$SHA1DEF_{- $target{asm_arch} -}
|
||||
ENDIF
|
||||
ENDIF
|
||||
|
||||
$KECCAK1600ASM=keccak1600.c
|
||||
IF[{- !$disabled{asm} -}]
|
||||
$KECCAK1600ASM_x86=
|
||||
$KECCAK1600ASM_x86_64=keccak1600-x86_64.s
|
||||
|
||||
$KECCAK1600ASM_s390x=keccak1600-s390x.S
|
||||
|
||||
$KECCAK1600ASM_armv4=keccak1600-armv4.S
|
||||
$KECCAK1600ASM_aarch64=keccak1600-armv8.S
|
||||
|
||||
$KECCAK1600ASM_ppc64=keccak1600-ppc64.s
|
||||
|
||||
# Now that we have defined all the arch specific variables, use the
|
||||
# appropriate one, and define the appropriate macros
|
||||
IF[$KECCAK1600ASM_{- $target{asm_arch} -}]
|
||||
$KECCAK1600ASM=$KECCAK1600ASM_{- $target{asm_arch} -}
|
||||
$KECCAK1600DEF=KECCAK1600_ASM
|
||||
ENDIF
|
||||
ENDIF
|
||||
|
||||
$COMMON=sha1dgst.c sha256.c sha512.c sha3.c $SHA1ASM $KECCAK1600ASM
|
||||
SOURCE[../../libcrypto]=$COMMON sha1_one.c
|
||||
DEFINE[../../libcrypto]=$SHA1DEF $KECCAK1600DEF
|
||||
SOURCE[../../providers/fips]= $COMMON
|
||||
DEFINE[../../providers/fips]= $SHA1DEF $KECCAK1600DEF
|
||||
|
||||
GENERATE[sha1-586.s]=asm/sha1-586.pl \
|
||||
$(PERLASM_SCHEME) $(LIB_CFLAGS) $(LIB_CPPFLAGS) $(PROCESSOR)
|
||||
|
||||
@@ -1090,7 +1090,7 @@ size_t SHA3_absorb(uint64_t A[5][5], const unsigned char *inp, size_t len,
|
||||
}
|
||||
|
||||
/*
|
||||
* SHA3_squeeze is called once at the end to generate |out| hash value
|
||||
* sha3_squeeze is called once at the end to generate |out| hash value
|
||||
* of |len| bytes.
|
||||
*/
|
||||
void SHA3_squeeze(uint64_t A[5][5], unsigned char *out, size_t len, size_t r)
|
||||
|
||||
+59
-2
@@ -10,8 +10,65 @@
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/opensslconf.h>
|
||||
|
||||
# include <openssl/opensslv.h>
|
||||
#include <openssl/opensslv.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/sha.h>
|
||||
|
||||
/* The implementation is in ../md32_common.h */
|
||||
|
||||
# include "sha_locl.h"
|
||||
#include "sha_locl.h"
|
||||
#include "internal/sha.h"
|
||||
|
||||
int sha1_ctrl(SHA_CTX *sha1, int cmd, int mslen, void *ms)
|
||||
{
|
||||
unsigned char padtmp[40];
|
||||
unsigned char sha1tmp[SHA_DIGEST_LENGTH];
|
||||
|
||||
if (cmd != EVP_CTRL_SSL3_MASTER_SECRET)
|
||||
return -2;
|
||||
|
||||
if (sha1 == NULL)
|
||||
return 0;
|
||||
|
||||
/* SSLv3 client auth handling: see RFC-6101 5.6.8 */
|
||||
if (mslen != 48)
|
||||
return 0;
|
||||
|
||||
/* At this point hash contains all handshake messages, update
|
||||
* with master secret and pad_1.
|
||||
*/
|
||||
|
||||
if (SHA1_Update(sha1, ms, mslen) <= 0)
|
||||
return 0;
|
||||
|
||||
/* Set padtmp to pad_1 value */
|
||||
memset(padtmp, 0x36, sizeof(padtmp));
|
||||
|
||||
if (!SHA1_Update(sha1, padtmp, sizeof(padtmp)))
|
||||
return 0;
|
||||
|
||||
if (!SHA1_Final(sha1tmp, sha1))
|
||||
return 0;
|
||||
|
||||
/* Reinitialise context */
|
||||
|
||||
if (!SHA1_Init(sha1))
|
||||
return 0;
|
||||
|
||||
if (SHA1_Update(sha1, ms, mslen) <= 0)
|
||||
return 0;
|
||||
|
||||
/* Set padtmp to pad_2 value */
|
||||
memset(padtmp, 0x5c, sizeof(padtmp));
|
||||
|
||||
if (!SHA1_Update(sha1, padtmp, sizeof(padtmp)))
|
||||
return 0;
|
||||
|
||||
if (!SHA1_Update(sha1, sha1tmp, sizeof(sha1tmp)))
|
||||
return 0;
|
||||
|
||||
/* Now when ctx is finalised it will return the SSL v3 hash value */
|
||||
OPENSSL_cleanse(sha1tmp, sizeof(sha1tmp));
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright 2017-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (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
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "internal/sha3.h"
|
||||
|
||||
void SHA3_squeeze(uint64_t A[5][5], unsigned char *out, size_t len, size_t r);
|
||||
|
||||
void sha3_reset(KECCAK1600_CTX *ctx)
|
||||
{
|
||||
memset(ctx->A, 0, sizeof(ctx->A));
|
||||
ctx->bufsz = 0;
|
||||
}
|
||||
|
||||
int sha3_init(KECCAK1600_CTX *ctx, unsigned char pad, size_t bitlen)
|
||||
{
|
||||
size_t bsz = SHA3_BLOCKSIZE(bitlen);
|
||||
|
||||
if (bsz <= sizeof(ctx->buf)) {
|
||||
sha3_reset(ctx);
|
||||
ctx->block_size = bsz;
|
||||
ctx->md_size = bitlen / 8;
|
||||
ctx->pad = pad;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int keccak_kmac_init(KECCAK1600_CTX *ctx, unsigned char pad, size_t bitlen)
|
||||
{
|
||||
int ret = sha3_init(ctx, pad, bitlen);
|
||||
|
||||
if (ret)
|
||||
ctx->md_size *= 2;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int sha3_update(KECCAK1600_CTX *ctx, const void *_inp, size_t len)
|
||||
{
|
||||
const unsigned char *inp = _inp;
|
||||
size_t bsz = ctx->block_size;
|
||||
size_t num, rem;
|
||||
|
||||
if (len == 0)
|
||||
return 1;
|
||||
|
||||
if ((num = ctx->bufsz) != 0) { /* process intermediate buffer? */
|
||||
rem = bsz - num;
|
||||
|
||||
if (len < rem) {
|
||||
memcpy(ctx->buf + num, inp, len);
|
||||
ctx->bufsz += len;
|
||||
return 1;
|
||||
}
|
||||
/*
|
||||
* We have enough data to fill or overflow the intermediate
|
||||
* buffer. So we append |rem| bytes and process the block,
|
||||
* leaving the rest for later processing...
|
||||
*/
|
||||
memcpy(ctx->buf + num, inp, rem);
|
||||
inp += rem, len -= rem;
|
||||
(void)SHA3_absorb(ctx->A, ctx->buf, bsz, bsz);
|
||||
ctx->bufsz = 0;
|
||||
/* ctx->buf is processed, ctx->num is guaranteed to be zero */
|
||||
}
|
||||
|
||||
if (len >= bsz)
|
||||
rem = SHA3_absorb(ctx->A, inp, len, bsz);
|
||||
else
|
||||
rem = len;
|
||||
|
||||
if (rem) {
|
||||
memcpy(ctx->buf, inp + len - rem, rem);
|
||||
ctx->bufsz = rem;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int sha3_final(unsigned char *md, KECCAK1600_CTX *ctx)
|
||||
{
|
||||
size_t bsz = ctx->block_size;
|
||||
size_t num = ctx->bufsz;
|
||||
|
||||
/*
|
||||
* Pad the data with 10*1. Note that |num| can be |bsz - 1|
|
||||
* in which case both byte operations below are performed on
|
||||
* same byte...
|
||||
*/
|
||||
memset(ctx->buf + num, 0, bsz - num);
|
||||
ctx->buf[num] = ctx->pad;
|
||||
ctx->buf[bsz - 1] |= 0x80;
|
||||
|
||||
(void)SHA3_absorb(ctx->A, ctx->buf, bsz, bsz);
|
||||
|
||||
SHA3_squeeze(ctx->A, md, ctx->md_size, bsz);
|
||||
|
||||
return 1;
|
||||
}
|
||||
Reference in New Issue
Block a user