22#define round(L, C, N, SB) \
32void ph(uint32_t h[16])
35 for (i = 0; i < 16; i++)
40static inline void Snefru(uint32_t input[16])
42 static const int shifts[4] = {16, 8, 16, 24};
43 int b, index, rshift, lshift;
44 const uint32_t *t0,*
t1;
45 uint32_t SBE,B00,B01,B02,B03,B04,B05,B06,B07,B08,B09,B10,B11,B12,B13,B14,B15;
64 for (index = 0; index < 8; index++) {
65 t0 = tables[2*index+0];
66 t1 = tables[2*index+1];
67 for (b = 0; b < 4; b++) {
68 round(B15, B00, B01, t0);
69 round(B00, B01, B02, t0);
72 round(B03, B04, B05, t0);
73 round(B04, B05, B06, t0);
76 round(B07, B08, B09, t0);
77 round(B08, B09, B10, t0);
80 round(B11, B12, B13, t0);
81 round(B12, B13, B14, t0);
88 B00 = (B00 >> rshift) | (B00 << lshift);
89 B01 = (B01 >> rshift) | (B01 << lshift);
90 B02 = (B02 >> rshift) | (B02 << lshift);
91 B03 = (B03 >> rshift) | (B03 << lshift);
92 B04 = (B04 >> rshift) | (B04 << lshift);
93 B05 = (B05 >> rshift) | (B05 << lshift);
94 B06 = (B06 >> rshift) | (B06 << lshift);
95 B07 = (B07 >> rshift) | (B07 << lshift);
96 B08 = (B08 >> rshift) | (B08 << lshift);
97 B09 = (B09 >> rshift) | (B09 << lshift);
98 B10 = (B10 >> rshift) | (B10 << lshift);
99 B11 = (B11 >> rshift) | (B11 << lshift);
100 B12 = (B12 >> rshift) | (B12 << lshift);
101 B13 = (B13 >> rshift) | (B13 << lshift);
102 B14 = (B14 >> rshift) | (B14 << lshift);
103 B15 = (B15 >> rshift) | (B15 << lshift);
123 for (i = 0,
j = 0; i < 32; i += 4, ++
j) {
124 context->state[8+
j] = ((unsigned)input[i] << 24) | ((
unsigned)input[i+1] << 16) |
125 ((unsigned)input[i+2] << 8) | (
unsigned)input[i+3];
136static const uint32_t MAX32 = 0xffffffffLU;
140 if ((MAX32 -
context->count[1]) < (
len * 8)) {
152 size_t i = 0, r = (
context->length +
len) % 32;
160 for (; i + 32 <=
len; i += 32) {
161 SnefruTransform(
context, input + i);
166 context->length = (
unsigned char)r;
182 for (i = 0,
j = 0;
j < 32; i++,
j += 4) {
183 digest[
j] = (
unsigned char) ((
context->state[i] >> 24) & 0xff);
184 digest[
j + 1] = (
unsigned char) ((
context->state[i] >> 16) & 0xff);
185 digest[
j + 2] = (
unsigned char) ((
context->state[i] >> 8) & 0xff);
186 digest[
j + 3] = (
unsigned char) (
context->state[i] & 0xff);
198 && ctx->length <
sizeof(ctx->buffer)) {
201 return r !=
SUCCESS ? r : -2000;
212 php_snefru_unserialize,
printf(string $format, mixed ... $values)
memset(ptr, 0, type->size)
PHP_HASH_API zend_result php_hash_serialize(const php_hashcontext_object *hash, zend_long *magic, zval *zv)
PHP_HASH_API zend_result php_hash_copy(const void *ops, const void *orig_context, void *dest_context)
PHP_HASH_API int php_hash_unserialize_spec(php_hashcontext_object *hash, const zval *zv, const char *spec)
hash(string $algo, string $data, bool $binary=false, array $options=[])
#define round(L, C, N, SB)
PHP_HASH_API void PHP_SNEFRUUpdate(PHP_SNEFRU_CTX *context, const unsigned char *input, size_t len)
PHP_HASH_API void PHP_SNEFRUInit(PHP_SNEFRU_CTX *context, ZEND_ATTRIBUTE_UNUSED HashTable *args)
PHP_HASH_API void PHP_SNEFRUFinal(unsigned char digest[32], PHP_SNEFRU_CTX *context)
const php_hash_ops php_hash_snefru_ops
void(* php_hash_final_func_t)(unsigned char *digest, void *context)
struct _php_hashcontext_object php_hashcontext_object
void(* php_hash_init_func_t)(void *context, HashTable *args)
void(* php_hash_update_func_t)(void *context, const unsigned char *buf, size_t count)
struct _php_hash_ops php_hash_ops
#define PHP_HASH_SERIALIZE_MAGIC_SPEC
#define ZEND_ATTRIBUTE_UNUSED
#define ZEND_SECURE_ZERO(var, size)
struct _zend_array HashTable