Changeset View
Changeset View
Standalone View
Standalone View
sys/crypto/sha2/sha512c.c
Show All 34 Lines | |||||
#include <sys/systm.h> | #include <sys/systm.h> | ||||
#else | #else | ||||
#include <string.h> | #include <string.h> | ||||
#endif | #endif | ||||
#include "sha512.h" | #include "sha512.h" | ||||
#include "sha512t.h" | #include "sha512t.h" | ||||
#include "sha384.h" | #include "sha384.h" | ||||
#include "sha512c_impl.h" | |||||
#if defined(ARM64_SHA512) | |||||
#include <sys/auxv.h> | |||||
#include <machine/ifunc.h> | |||||
#endif | |||||
#if BYTE_ORDER == BIG_ENDIAN | #if BYTE_ORDER == BIG_ENDIAN | ||||
/* Copy a vector of big-endian uint64_t into a vector of bytes */ | /* Copy a vector of big-endian uint64_t into a vector of bytes */ | ||||
#define be64enc_vect(dst, src, len) \ | #define be64enc_vect(dst, src, len) \ | ||||
memcpy((void *)dst, (const void *)src, (size_t)len) | memcpy((void *)dst, (const void *)src, (size_t)len) | ||||
/* Copy a vector of bytes into a vector of big-endian uint64_t */ | /* Copy a vector of bytes into a vector of big-endian uint64_t */ | ||||
#define be64dec_vect(dst, src, len) \ | #define be64dec_vect(dst, src, len) \ | ||||
▲ Show 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | |||||
#define MSCH(W, ii, i) \ | #define MSCH(W, ii, i) \ | ||||
W[i + ii + 16] = s1(W[i + ii + 14]) + W[i + ii + 9] + s0(W[i + ii + 1]) + W[i + ii] | W[i + ii + 16] = s1(W[i + ii + 14]) + W[i + ii + 9] + s0(W[i + ii + 1]) + W[i + ii] | ||||
/* | /* | ||||
* SHA512 block compression function. The 512-bit state is transformed via | * SHA512 block compression function. The 512-bit state is transformed via | ||||
* the 512-bit input block to produce a new state. | * the 512-bit input block to produce a new state. | ||||
*/ | */ | ||||
static void | static void | ||||
#if defined(ARM64_SHA512) | |||||
SHA512_Transform_c(uint64_t * state, const unsigned char block[SHA512_BLOCK_LENGTH]) | |||||
#else | |||||
SHA512_Transform(uint64_t * state, const unsigned char block[SHA512_BLOCK_LENGTH]) | SHA512_Transform(uint64_t * state, const unsigned char block[SHA512_BLOCK_LENGTH]) | ||||
#endif | |||||
{ | { | ||||
uint64_t W[80]; | uint64_t W[80]; | ||||
uint64_t S[8]; | uint64_t S[8]; | ||||
int i; | int i; | ||||
/* 1. Prepare the first part of the message schedule W. */ | /* 1. Prepare the first part of the message schedule W. */ | ||||
be64dec_vect(W, block, SHA512_BLOCK_LENGTH); | be64dec_vect(W, block, SHA512_BLOCK_LENGTH); | ||||
Show All 38 Lines | for (i = 0; i < 80; i += 16) { | ||||
MSCH(W, 14, i); | MSCH(W, 14, i); | ||||
MSCH(W, 15, i); | MSCH(W, 15, i); | ||||
} | } | ||||
/* 4. Mix local working variables into global state */ | /* 4. Mix local working variables into global state */ | ||||
for (i = 0; i < 8; i++) | for (i = 0; i < 8; i++) | ||||
state[i] += S[i]; | state[i] += S[i]; | ||||
} | } | ||||
#if defined(ARM64_SHA512) | |||||
static void | |||||
SHA512_Transform_arm64(uint64_t * state, | |||||
const unsigned char block[SHA512_BLOCK_LENGTH]) | |||||
{ | |||||
SHA512_Transform_arm64_impl(state, block, K); | |||||
} | |||||
DEFINE_UIFUNC(static, void, SHA512_Transform, | |||||
(uint64_t * state, const unsigned char block[SHA512_BLOCK_LENGTH])) | |||||
{ | |||||
u_long hwcap; | |||||
if (elf_aux_info(AT_HWCAP, &hwcap, sizeof(hwcap)) == 0) { | |||||
if ((hwcap & HWCAP_SHA512) != 0) { | |||||
return (SHA512_Transform_arm64); | |||||
} | |||||
} | |||||
return (SHA512_Transform_c); | |||||
} | |||||
#endif | |||||
static unsigned char PAD[SHA512_BLOCK_LENGTH] = { | static unsigned char PAD[SHA512_BLOCK_LENGTH] = { | ||||
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||||
▲ Show 20 Lines • Show All 280 Lines • Show Last 20 Lines |