Changeset View
Changeset View
Standalone View
Standalone View
sys/crypto/sha2/sha256c.c
Show All 32 Lines | |||||
#ifdef _KERNEL | #ifdef _KERNEL | ||||
#include <sys/systm.h> | #include <sys/systm.h> | ||||
#else | #else | ||||
#include <string.h> | #include <string.h> | ||||
#endif | #endif | ||||
#include "sha224.h" | #include "sha224.h" | ||||
#include "sha256.h" | #include "sha256.h" | ||||
#include "sha256c_impl.h" | |||||
#if defined(ARM64_SHA2) | |||||
#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 uint32_t into a vector of bytes */ | /* Copy a vector of big-endian uint32_t into a vector of bytes */ | ||||
#define be32enc_vect(dst, src, len) \ | #define be32enc_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 uint32_t */ | /* Copy a vector of bytes into a vector of big-endian uint32_t */ | ||||
#define be32dec_vect(dst, src, len) \ | #define be32dec_vect(dst, src, len) \ | ||||
▲ Show 20 Lines • Show All 77 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] | ||||
/* | /* | ||||
* SHA256 block compression function. The 256-bit state is transformed via | * SHA256 block compression function. The 256-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 | ||||
SHA256_Transform(uint32_t * state, const unsigned char block[64]) | SHA256_Transform_c(uint32_t * state, const unsigned char block[64]) | ||||
{ | { | ||||
uint32_t W[64]; | uint32_t W[64]; | ||||
uint32_t S[8]; | uint32_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. */ | ||||
be32dec_vect(W, block, 64); | be32dec_vect(W, block, 64); | ||||
Show All 38 Lines | for (i = 0; i < 64; 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_SHA2) | |||||
static void | |||||
SHA256_Transform_arm64(uint32_t * state, const unsigned char block[64]) | |||||
cem: I might throw this in a header file. | |||||
Done Inline ActionsThe only reason I didn't is because I didn't want to add it to sha256.h as it shouldn't be used outside of this code and I didn't want to create a new header just for 2 lines. andrew: The only reason I didn't is because I didn't want to add it to `sha256.h` as it shouldn't be… | |||||
{ | |||||
SHA256_Transform_arm64_impl(state, block, K); | |||||
} | |||||
Done Inline ActionsStatic? cem: Static? | |||||
DEFINE_UIFUNC(static, void, SHA256_Transform, | |||||
(uint32_t * state, const unsigned char block[64])) | |||||
{ | |||||
u_long hwcap; | |||||
if (elf_aux_info(AT_HWCAP, &hwcap, sizeof(hwcap)) == 0) { | |||||
if ((hwcap & HWCAP_SHA2) != 0) | |||||
return (SHA256_Transform_arm64); | |||||
} | |||||
return (SHA256_Transform_c); | |||||
} | |||||
#else | |||||
static void | |||||
SHA256_Transform(uint32_t * state, const unsigned char block[64]) | |||||
{ | |||||
SHA256_Transform_c(state, block); | |||||
} | |||||
#endif | |||||
static unsigned char PAD[64] = { | static unsigned char PAD[64] = { | ||||
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 | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 177 Lines • Show Last 20 Lines |
I might throw this in a header file.