Changeset View
Changeset View
Standalone View
Standalone View
cipher/sha512.c
Show First 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | |||||
#include <config.h> | #include <config.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include "g10lib.h" | #include "g10lib.h" | ||||
#include "bithelp.h" | #include "bithelp.h" | ||||
#include "bufhelp.h" | #include "bufhelp.h" | ||||
#include "cipher.h" | #include "cipher.h" | ||||
#include "hash-common.h" | #include "hash-common.h" | ||||
#include "sha2-common.h" | |||||
/* USE_ARM_NEON_ASM indicates whether to enable ARM NEON assembly code. */ | |||||
#undef USE_ARM_NEON_ASM | |||||
#ifdef ENABLE_NEON_SUPPORT | |||||
# if defined(HAVE_ARM_ARCH_V6) && defined(__ARMEL__) \ | |||||
&& defined(HAVE_COMPATIBLE_GCC_ARM_PLATFORM_AS) \ | |||||
&& defined(HAVE_GCC_INLINE_ASM_NEON) | |||||
# define USE_ARM_NEON_ASM 1 | |||||
# endif | |||||
#endif /*ENABLE_NEON_SUPPORT*/ | |||||
/* USE_ARM_ASM indicates whether to enable ARM assembly code. */ | |||||
#undef USE_ARM_ASM | |||||
#if defined(__ARMEL__) && defined(HAVE_COMPATIBLE_GCC_ARM_PLATFORM_AS) | |||||
# define USE_ARM_ASM 1 | |||||
#endif | |||||
/* USE_SSSE3 indicates whether to compile with Intel SSSE3 code. */ | |||||
#undef USE_SSSE3 | |||||
#if defined(__x86_64__) && defined(HAVE_GCC_INLINE_ASM_SSSE3) && \ | |||||
defined(HAVE_INTEL_SYNTAX_PLATFORM_AS) && \ | |||||
(defined(HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS) || \ | |||||
defined(HAVE_COMPATIBLE_GCC_WIN64_PLATFORM_AS)) | |||||
# define USE_SSSE3 1 | |||||
#endif | |||||
/* USE_AVX indicates whether to compile with Intel AVX code. */ | |||||
#undef USE_AVX | |||||
#if defined(__x86_64__) && defined(HAVE_GCC_INLINE_ASM_AVX) && \ | |||||
defined(HAVE_INTEL_SYNTAX_PLATFORM_AS) && \ | |||||
(defined(HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS) || \ | |||||
defined(HAVE_COMPATIBLE_GCC_WIN64_PLATFORM_AS)) | |||||
# define USE_AVX 1 | |||||
#endif | |||||
/* USE_AVX2 indicates whether to compile with Intel AVX2/rorx code. */ | |||||
#undef USE_AVX2 | |||||
#if defined(__x86_64__) && defined(HAVE_GCC_INLINE_ASM_AVX2) && \ | |||||
defined(HAVE_GCC_INLINE_ASM_BMI2) && \ | |||||
defined(HAVE_INTEL_SYNTAX_PLATFORM_AS) && \ | |||||
(defined(HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS) || \ | |||||
defined(HAVE_COMPATIBLE_GCC_WIN64_PLATFORM_AS)) | |||||
# define USE_AVX2 1 | |||||
#endif | |||||
typedef struct | typedef struct | ||||
{ | { | ||||
u64 h0, h1, h2, h3, h4, h5, h6, h7; | u64 h0, h1, h2, h3, h4, h5, h6, h7; | ||||
} SHA512_STATE; | } SHA512_STATE; | ||||
typedef struct | typedef struct | ||||
{ | { | ||||
gcry_md_block_ctx_t bctx; | gcry_md_block_ctx_t bctx; | ||||
SHA512_STATE state; | SHA512_STATE state; | ||||
} SHA512_CONTEXT; | } SHA512_CONTEXT; | ||||
static const u64 k[] = | |||||
{ | |||||
U64_C(0x428a2f98d728ae22), U64_C(0x7137449123ef65cd), | |||||
U64_C(0xb5c0fbcfec4d3b2f), U64_C(0xe9b5dba58189dbbc), | |||||
U64_C(0x3956c25bf348b538), U64_C(0x59f111f1b605d019), | |||||
U64_C(0x923f82a4af194f9b), U64_C(0xab1c5ed5da6d8118), | |||||
U64_C(0xd807aa98a3030242), U64_C(0x12835b0145706fbe), | |||||
U64_C(0x243185be4ee4b28c), U64_C(0x550c7dc3d5ffb4e2), | |||||
U64_C(0x72be5d74f27b896f), U64_C(0x80deb1fe3b1696b1), | |||||
U64_C(0x9bdc06a725c71235), U64_C(0xc19bf174cf692694), | |||||
U64_C(0xe49b69c19ef14ad2), U64_C(0xefbe4786384f25e3), | |||||
U64_C(0x0fc19dc68b8cd5b5), U64_C(0x240ca1cc77ac9c65), | |||||
U64_C(0x2de92c6f592b0275), U64_C(0x4a7484aa6ea6e483), | |||||
U64_C(0x5cb0a9dcbd41fbd4), U64_C(0x76f988da831153b5), | |||||
U64_C(0x983e5152ee66dfab), U64_C(0xa831c66d2db43210), | |||||
U64_C(0xb00327c898fb213f), U64_C(0xbf597fc7beef0ee4), | |||||
U64_C(0xc6e00bf33da88fc2), U64_C(0xd5a79147930aa725), | |||||
U64_C(0x06ca6351e003826f), U64_C(0x142929670a0e6e70), | |||||
U64_C(0x27b70a8546d22ffc), U64_C(0x2e1b21385c26c926), | |||||
U64_C(0x4d2c6dfc5ac42aed), U64_C(0x53380d139d95b3df), | |||||
U64_C(0x650a73548baf63de), U64_C(0x766a0abb3c77b2a8), | |||||
U64_C(0x81c2c92e47edaee6), U64_C(0x92722c851482353b), | |||||
U64_C(0xa2bfe8a14cf10364), U64_C(0xa81a664bbc423001), | |||||
U64_C(0xc24b8b70d0f89791), U64_C(0xc76c51a30654be30), | |||||
U64_C(0xd192e819d6ef5218), U64_C(0xd69906245565a910), | |||||
U64_C(0xf40e35855771202a), U64_C(0x106aa07032bbd1b8), | |||||
U64_C(0x19a4c116b8d2d0c8), U64_C(0x1e376c085141ab53), | |||||
U64_C(0x2748774cdf8eeb99), U64_C(0x34b0bcb5e19b48a8), | |||||
U64_C(0x391c0cb3c5c95a63), U64_C(0x4ed8aa4ae3418acb), | |||||
U64_C(0x5b9cca4f7763e373), U64_C(0x682e6ff3d6b2b8a3), | |||||
U64_C(0x748f82ee5defb2fc), U64_C(0x78a5636f43172f60), | |||||
U64_C(0x84c87814a1f0ab72), U64_C(0x8cc702081a6439ec), | |||||
U64_C(0x90befffa23631e28), U64_C(0xa4506cebde82bde9), | |||||
U64_C(0xbef9a3f7b2c67915), U64_C(0xc67178f2e372532b), | |||||
U64_C(0xca273eceea26619c), U64_C(0xd186b8c721c0c207), | |||||
U64_C(0xeada7dd6cde0eb1e), U64_C(0xf57d4f7fee6ed178), | |||||
U64_C(0x06f067aa72176fba), U64_C(0x0a637dc5a2c898a6), | |||||
U64_C(0x113f9804bef90dae), U64_C(0x1b710b35131c471b), | |||||
U64_C(0x28db77f523047d84), U64_C(0x32caab7b40c72493), | |||||
U64_C(0x3c9ebe0a15c9bebc), U64_C(0x431d67c49c100d4c), | |||||
U64_C(0x4cc5d4becb3e42b6), U64_C(0x597f299cfc657e2a), | |||||
U64_C(0x5fcb6fab3ad6faec), U64_C(0x6c44198c4a475817) | |||||
}; | |||||
/* AMD64 assembly implementations use SystemV ABI, ABI conversion and additional | /* AMD64 assembly implementations use SystemV ABI, ABI conversion and additional | ||||
* stack to store XMM6-XMM15 needed on Win64. */ | * stack to store XMM6-XMM15 needed on Win64. */ | ||||
#undef ASM_FUNC_ABI | #undef ASM_FUNC_ABI | ||||
#undef ASM_EXTRA_STACK | #undef ASM_EXTRA_STACK | ||||
#if defined(USE_SSSE3) || defined(USE_AVX) || defined(USE_AVX2) | #if defined(USE_SSSE3) || defined(USE_AVX) || defined(USE_AVX2) | ||||
# ifdef HAVE_COMPATIBLE_GCC_WIN64_PLATFORM_AS | # ifdef HAVE_COMPATIBLE_GCC_WIN64_PLATFORM_AS | ||||
# define ASM_FUNC_ABI __attribute__((sysv_abi)) | # define ASM_FUNC_ABI __attribute__((sysv_abi)) | ||||
# define ASM_EXTRA_STACK (10 * 16 + 4 * sizeof(void *)) | # define ASM_EXTRA_STACK (10 * 16 + 4 * sizeof(void *)) | ||||
Show All 13 Lines | |||||
do_sha512_transform_armv7_neon(void *ctx, const unsigned char *data, | do_sha512_transform_armv7_neon(void *ctx, const unsigned char *data, | ||||
size_t nblks) | size_t nblks) | ||||
{ | { | ||||
SHA512_CONTEXT *hd = ctx; | SHA512_CONTEXT *hd = ctx; | ||||
return _gcry_sha512_transform_armv7_neon (&hd->state, data, k, nblks); | return _gcry_sha512_transform_armv7_neon (&hd->state, data, k, nblks); | ||||
} | } | ||||
#endif | #endif | ||||
#ifdef USE_PPC_ASM | |||||
void sha512_block_p8 (SHA512_STATE *hd, | |||||
const unsigned char *data, | |||||
size_t len, const u64 k[]); | |||||
static unsigned int | |||||
do_sha512_transform_ppc8 (void *ctx, const unsigned char *data, | |||||
size_t nblks) | |||||
{ | |||||
SHA512_CONTEXT *hd = ctx; | |||||
sha512_block_p8 (&hd->state, data, nblks, k); | |||||
return 128; /* uses 128 bytes of stack space */ | |||||
} | |||||
#endif | |||||
#ifdef USE_SSSE3 | #ifdef USE_SSSE3 | ||||
unsigned int _gcry_sha512_transform_amd64_ssse3(const void *input_data, | unsigned int _gcry_sha512_transform_amd64_ssse3(const void *input_data, | ||||
void *state, | void *state, | ||||
size_t num_blks) ASM_FUNC_ABI; | size_t num_blks) ASM_FUNC_ABI; | ||||
static unsigned int | static unsigned int | ||||
do_sha512_transform_amd64_ssse3(void *ctx, const unsigned char *data, | do_sha512_transform_amd64_ssse3(void *ctx, const unsigned char *data, | ||||
size_t nblks) | size_t nblks) | ||||
▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Lines | sha512_init_common (SHA512_CONTEXT *ctx, unsigned int flags) | ||||
/* Order of feature checks is important here; last match will be | /* Order of feature checks is important here; last match will be | ||||
* selected. Keep slower implementations at the top and faster at | * selected. Keep slower implementations at the top and faster at | ||||
* the bottom. */ | * the bottom. */ | ||||
ctx->bctx.bwrite = do_transform_generic; | ctx->bctx.bwrite = do_transform_generic; | ||||
#ifdef USE_ARM_NEON_ASM | #ifdef USE_ARM_NEON_ASM | ||||
if ((features & HWF_ARM_NEON) != 0) | if ((features & HWF_ARM_NEON) != 0) | ||||
ctx->bctx.bwrite = do_sha512_transform_armv7_neon; | ctx->bctx.bwrite = do_sha512_transform_armv7_neon; | ||||
#endif | #endif | ||||
#ifdef USE_PPC_ASM | |||||
if ((features & HWF_PPC_VCRYPTO) != 0) | |||||
ctx->bctx.bwrite = do_sha512_transform_ppc8; | |||||
#endif | |||||
#ifdef USE_SSSE3 | #ifdef USE_SSSE3 | ||||
if ((features & HWF_INTEL_SSSE3) != 0) | if ((features & HWF_INTEL_SSSE3) != 0) | ||||
ctx->bctx.bwrite = do_sha512_transform_amd64_ssse3; | ctx->bctx.bwrite = do_sha512_transform_amd64_ssse3; | ||||
#endif | #endif | ||||
#ifdef USE_AVX | #ifdef USE_AVX | ||||
if ((features & HWF_INTEL_AVX) && (features & HWF_INTEL_FAST_SHLD)) | if ((features & HWF_INTEL_AVX) && (features & HWF_INTEL_FAST_SHLD)) | ||||
ctx->bctx.bwrite = do_sha512_transform_amd64_avx; | ctx->bctx.bwrite = do_sha512_transform_amd64_avx; | ||||
#endif | #endif | ||||
▲ Show 20 Lines • Show All 888 Lines • Show Last 20 Lines |