Download src/php/php-src/ext/hash/hash_tiger.c from meddyrat/dis-bench: direct link, hf CLI and curl.
- Browser
- Download file 8.08 kB
-
https://huggingface.co/datasets/meddyrat/dis-bench/resolve/main/src/php/php-src/ext/hash/hash_tiger.c
- Command line
-
hf download hf://datasets/meddyrat/dis-bench/src/php/php-src/ext/hash/hash_tiger.c
-
curl -L -o hash_tiger.c https://huggingface.co/datasets/meddyrat/dis-bench/resolve/main/src/php/php-src/ext/hash/hash_tiger.c
8.08 kB
| /* | |
| +----------------------------------------------------------------------+ | |
| | Copyright (c) The PHP Group | | |
| +----------------------------------------------------------------------+ | |
| | This source file is subject to version 3.01 of the PHP license, | | |
| | that is bundled with this package in the file LICENSE, and is | | |
| | available through the world-wide-web at the following url: | | |
| | https://www.php.net/license/3_01.txt | | |
| | If you did not receive a copy of the PHP license and are unable to | | |
| | obtain it through the world-wide-web, please send a note to | | |
| | license@php.net so we can mail you a copy immediately. | | |
| +----------------------------------------------------------------------+ | |
| | Authors: Michael Wallner <mike@php.net> | | |
| | Sara Golemon <pollita@php.net> | | |
| +----------------------------------------------------------------------+ | |
| */ | |
| /* {{{ */ | |
| /* }}} */ | |
| static inline void TigerFinalize(PHP_TIGER_CTX *context) | |
| { | |
| context->passed += (uint64_t) context->length << 3; | |
| context->buffer[context->length++] = 0x1; | |
| if (context->length % 8) { | |
| memset(&context->buffer[context->length], 0, 8-context->length%8); | |
| context->length += 8-context->length%8; | |
| } | |
| if (context->length > 56) { | |
| memset(&context->buffer[context->length], 0, 64 - context->length); | |
| tiger_compress(context->passes, ((uint64_t *) context->buffer), context->state); | |
| memset(context->buffer, 0, 56); | |
| } else { | |
| memset(&context->buffer[context->length], 0, 56 - context->length); | |
| } | |
| memcpy(&context->buffer[56], &context->passed, sizeof(uint64_t)); | |
| context->buffer[56] = (unsigned char) (context->passed & 0xff); | |
| context->buffer[57] = (unsigned char) ((context->passed >> 8) & 0xff); | |
| context->buffer[58] = (unsigned char) ((context->passed >> 16) & 0xff); | |
| context->buffer[59] = (unsigned char) ((context->passed >> 24) & 0xff); | |
| context->buffer[60] = (unsigned char) ((context->passed >> 32) & 0xff); | |
| context->buffer[61] = (unsigned char) ((context->passed >> 40) & 0xff); | |
| context->buffer[62] = (unsigned char) ((context->passed >> 48) & 0xff); | |
| context->buffer[63] = (unsigned char) ((context->passed >> 56) & 0xff); | |
| tiger_compress(context->passes, ((uint64_t *) context->buffer), context->state); | |
| } | |
| static inline void TigerDigest(unsigned char *digest_str, unsigned int digest_len, PHP_TIGER_CTX *context) | |
| { | |
| unsigned int i; | |
| for (i = 0; i < digest_len; ++i) { | |
| digest_str[i] = (unsigned char) ((context->state[i/8] >> (8 * (i%8))) & 0xff); | |
| } | |
| } | |
| PHP_HASH_API void PHP_3TIGERInit(PHP_TIGER_CTX *context, ZEND_ATTRIBUTE_UNUSED HashTable *args) | |
| { | |
| memset(context, 0, sizeof(*context)); | |
| context->state[0] = L64(0x0123456789ABCDEF); | |
| context->state[1] = L64(0xFEDCBA9876543210); | |
| context->state[2] = L64(0xF096A5B4C3B2E187); | |
| } | |
| PHP_HASH_API void PHP_4TIGERInit(PHP_TIGER_CTX *context, ZEND_ATTRIBUTE_UNUSED HashTable *args) | |
| { | |
| memset(context, 0, sizeof(*context)); | |
| context->passes = 1; | |
| context->state[0] = L64(0x0123456789ABCDEF); | |
| context->state[1] = L64(0xFEDCBA9876543210); | |
| context->state[2] = L64(0xF096A5B4C3B2E187); | |
| } | |
| PHP_HASH_API void PHP_TIGERUpdate(PHP_TIGER_CTX *context, const unsigned char *input, size_t len) | |
| { | |
| if (context->length + len < 64) { | |
| memcpy(&context->buffer[context->length], input, len); | |
| context->length += len; | |
| } else { | |
| size_t i = 0, r = (context->length + len) % 64; | |
| if (context->length) { | |
| i = 64 - context->length; | |
| memcpy(&context->buffer[context->length], input, i); | |
| tiger_compress(context->passes, ((const uint64_t *) context->buffer), context->state); | |
| ZEND_SECURE_ZERO(context->buffer, 64); | |
| context->passed += 512; | |
| } | |
| for (; i + 64 <= len; i += 64) { | |
| memcpy(context->buffer, &input[i], 64); | |
| tiger_compress(context->passes, ((const uint64_t *) context->buffer), context->state); | |
| context->passed += 512; | |
| } | |
| ZEND_SECURE_ZERO(&context->buffer[r], 64-r); | |
| memcpy(context->buffer, &input[i], r); | |
| context->length = r; | |
| } | |
| } | |
| PHP_HASH_API void PHP_TIGER128Final(unsigned char digest[16], PHP_TIGER_CTX *context) | |
| { | |
| TigerFinalize(context); | |
| TigerDigest(digest, 16, context); | |
| ZEND_SECURE_ZERO(context, sizeof(*context)); | |
| } | |
| PHP_HASH_API void PHP_TIGER160Final(unsigned char digest[20], PHP_TIGER_CTX *context) | |
| { | |
| TigerFinalize(context); | |
| TigerDigest(digest, 20, context); | |
| ZEND_SECURE_ZERO(context, sizeof(*context)); | |
| } | |
| PHP_HASH_API void PHP_TIGER192Final(unsigned char digest[24], PHP_TIGER_CTX *context) | |
| { | |
| TigerFinalize(context); | |
| TigerDigest(digest, 24, context); | |
| ZEND_SECURE_ZERO(context, sizeof(*context)); | |
| } | |
| static int php_tiger_unserialize(php_hashcontext_object *hash, zend_long magic, const zval *zv) | |
| { | |
| PHP_TIGER_CTX *ctx = (PHP_TIGER_CTX *) hash->context; | |
| int r = FAILURE; | |
| if (magic == PHP_HASH_SERIALIZE_MAGIC_SPEC | |
| && (r = php_hash_unserialize_spec(hash, zv, PHP_TIGER_SPEC)) == SUCCESS | |
| && ctx->length < sizeof(ctx->buffer)) { | |
| return SUCCESS; | |
| } else { | |
| return r != SUCCESS ? r : -2000; | |
| } | |
| } | |
| PHP_HASH_TIGER_OPS(3, 128); | |
| PHP_HASH_TIGER_OPS(3, 160); | |
| PHP_HASH_TIGER_OPS(3, 192); | |
| PHP_HASH_TIGER_OPS(4, 128); | |
| PHP_HASH_TIGER_OPS(4, 160); | |
| PHP_HASH_TIGER_OPS(4, 192); | |