Lines Matching refs:ops
101 php_hash_ops *ops = zend_hash_find_ptr(&php_hash_hashtable, lower); in php_hash_fetch_ops() local
104 return ops; in php_hash_fetch_ops()
108 PHP_HASH_API void php_hash_register_algo(const char *algo, const php_hash_ops *ops) /* {{{ */ in php_hash_register_algo() argument
112 …zend_hash_add_ptr(&php_hash_hashtable, zend_string_init_interned(lower, algo_len, 1), (void *) ops… in php_hash_register_algo()
117 PHP_HASH_API int php_hash_copy(const void *ops, void *orig_context, void *dest_context) /* {{{ */ in php_hash_copy() argument
119 php_hash_ops *hash_ops = (php_hash_ops *)ops; in php_hash_copy()
237 if (pos + count * sz > hash->ops->context_size) { in php_hash_serialize_spec()
260 if (*spec == '.' && align_to(pos, max_alignment) != hash->ops->context_size) { in php_hash_serialize_spec()
284 if (pos + count * sz > hash->ops->context_size) { in php_hash_unserialize_spec()
320 if (*spec == '.' && align_to(pos, max_alignment) != hash->ops->context_size) { in php_hash_unserialize_spec()
329 if (hash->ops->serialize_spec) { in php_hash_serialize()
331 return php_hash_serialize_spec(hash, zv, hash->ops->serialize_spec); in php_hash_serialize()
340 if (hash->ops->serialize_spec in php_hash_unserialize()
342 return php_hash_unserialize_spec(hash, zv, hash->ops->serialize_spec); in php_hash_unserialize()
355 const php_hash_ops *ops; in php_hash_do_hash() local
359 ops = php_hash_fetch_ops(algo); in php_hash_do_hash()
360 if (!ops) { in php_hash_do_hash()
376 context = php_hash_alloc_context(ops); in php_hash_do_hash()
377 ops->hash_init(context); in php_hash_do_hash()
384 ops->hash_update(context, (unsigned char *) buf, n); in php_hash_do_hash()
392 ops->hash_update(context, (unsigned char *) data, data_len); in php_hash_do_hash()
395 digest = zend_string_alloc(ops->digest_size, 0); in php_hash_do_hash()
396 ops->hash_final((unsigned char *) ZSTR_VAL(digest), context); in php_hash_do_hash()
400 ZSTR_VAL(digest)[ops->digest_size] = 0; in php_hash_do_hash()
403 zend_string *hex_digest = zend_string_safe_alloc(ops->digest_size, 2, 0, 0); in php_hash_do_hash()
405 php_hash_bin2hex(ZSTR_VAL(hex_digest), (unsigned char *) ZSTR_VAL(digest), ops->digest_size); in php_hash_do_hash()
406 ZSTR_VAL(hex_digest)[2 * ops->digest_size] = 0; in php_hash_do_hash()
467 static inline void php_hash_hmac_prep_key(unsigned char *K, const php_hash_ops *ops, void *context,… in php_hash_hmac_prep_key() argument
468 memset(K, 0, ops->block_size); in php_hash_hmac_prep_key()
469 if (key_len > ops->block_size) { in php_hash_hmac_prep_key()
471 ops->hash_init(context); in php_hash_hmac_prep_key()
472 ops->hash_update(context, key, key_len); in php_hash_hmac_prep_key()
473 ops->hash_final(K, context); in php_hash_hmac_prep_key()
478 php_hash_string_xor_char(K, K, 0x36, ops->block_size); in php_hash_hmac_prep_key()
481 static inline void php_hash_hmac_round(unsigned char *final, const php_hash_ops *ops, void *context… in php_hash_hmac_round() argument
482 ops->hash_init(context); in php_hash_hmac_round()
483 ops->hash_update(context, key, ops->block_size); in php_hash_hmac_round()
484 ops->hash_update(context, data, data_size); in php_hash_hmac_round()
485 ops->hash_final(final, context); in php_hash_hmac_round()
493 const php_hash_ops *ops; in php_hash_do_hash_hmac() local
497 ops = php_hash_fetch_ops(algo); in php_hash_do_hash_hmac()
498 if (!ops || !ops->is_crypto) { in php_hash_do_hash_hmac()
515 context = php_hash_alloc_context(ops); in php_hash_do_hash_hmac()
517 K = emalloc(ops->block_size); in php_hash_do_hash_hmac()
518 digest = zend_string_alloc(ops->digest_size, 0); in php_hash_do_hash_hmac()
520 php_hash_hmac_prep_key(K, ops, context, (unsigned char *) key, key_len); in php_hash_do_hash_hmac()
525 ops->hash_init(context); in php_hash_do_hash_hmac()
526 ops->hash_update(context, K, ops->block_size); in php_hash_do_hash_hmac()
528 ops->hash_update(context, (unsigned char *) buf, n); in php_hash_do_hash_hmac()
538 ops->hash_final((unsigned char *) ZSTR_VAL(digest), context); in php_hash_do_hash_hmac()
540 …php_hash_hmac_round((unsigned char *) ZSTR_VAL(digest), ops, context, K, (unsigned char *) data, d… in php_hash_do_hash_hmac()
543 php_hash_string_xor_char(K, K, 0x6A, ops->block_size); in php_hash_do_hash_hmac()
545 …_hmac_round((unsigned char *) ZSTR_VAL(digest), ops, context, K, (unsigned char *) ZSTR_VAL(digest… in php_hash_do_hash_hmac()
548 ZEND_SECURE_ZERO(K, ops->block_size); in php_hash_do_hash_hmac()
553 ZSTR_VAL(digest)[ops->digest_size] = 0; in php_hash_do_hash_hmac()
556 zend_string *hex_digest = zend_string_safe_alloc(ops->digest_size, 2, 0, 0); in php_hash_do_hash_hmac()
558 php_hash_bin2hex(ZSTR_VAL(hex_digest), (unsigned char *) ZSTR_VAL(digest), ops->digest_size); in php_hash_do_hash_hmac()
559 ZSTR_VAL(hex_digest)[2 * ops->digest_size] = 0; in php_hash_do_hash_hmac()
606 const php_hash_ops *ops; in PHP_FUNCTION() local
613 ops = php_hash_fetch_ops(algo); in PHP_FUNCTION()
614 if (!ops) { in PHP_FUNCTION()
620 if (!ops->is_crypto) { in PHP_FUNCTION()
634 context = php_hash_alloc_context(ops); in PHP_FUNCTION()
635 ops->hash_init(context); in PHP_FUNCTION()
637 hash->ops = ops; in PHP_FUNCTION()
643 char *K = emalloc(ops->block_size); in PHP_FUNCTION()
646 memset(K, 0, ops->block_size); in PHP_FUNCTION()
648 if (ZSTR_LEN(key) > ops->block_size) { in PHP_FUNCTION()
650 ops->hash_update(context, (unsigned char *) ZSTR_VAL(key), ZSTR_LEN(key)); in PHP_FUNCTION()
651 ops->hash_final((unsigned char *) K, context); in PHP_FUNCTION()
653 ops->hash_init(context); in PHP_FUNCTION()
659 block_size = ops->block_size; in PHP_FUNCTION()
663 ops->hash_update(context, (unsigned char *) K, ops->block_size); in PHP_FUNCTION()
689 hash->ops->hash_update(hash->context, (unsigned char *) ZSTR_VAL(data), ZSTR_LEN(data)); in PHP_FUNCTION()
723 hash->ops->hash_update(hash->context, (unsigned char *) buf, n); in PHP_FUNCTION()
758 hash->ops->hash_update(hash->context, (unsigned char *) buf, n); in PHP_FUNCTION()
782 digest_len = hash->ops->digest_size; in PHP_FUNCTION()
784 hash->ops->hash_final((unsigned char *) ZSTR_VAL(digest), hash->context); in PHP_FUNCTION()
789 block_size = hash->ops->block_size; in PHP_FUNCTION()
795 hash->ops->hash_init(hash->context); in PHP_FUNCTION()
796 hash->ops->hash_update(hash->context, hash->key, hash->ops->block_size); in PHP_FUNCTION()
797 hash->ops->hash_update(hash->context, (unsigned char *) ZSTR_VAL(digest), hash->ops->digest_size); in PHP_FUNCTION()
798 hash->ops->hash_final((unsigned char *) ZSTR_VAL(digest), hash->context); in PHP_FUNCTION()
801 ZEND_SECURE_ZERO(hash->key, hash->ops->block_size); in PHP_FUNCTION()
864 const php_hash_ops *ops; in PHP_FUNCTION() local
871 ZEND_HASH_FOREACH_STR_KEY_PTR(&php_hash_hashtable, str, ops) { in PHP_FUNCTION()
872 if (ops->is_crypto) { in PHP_FUNCTION()
887 const php_hash_ops *ops; in PHP_FUNCTION() local
894 ops = php_hash_fetch_ops(algo); in PHP_FUNCTION()
895 if (!ops || !ops->is_crypto) { in PHP_FUNCTION()
909 length = ops->digest_size; in PHP_FUNCTION()
910 } else if (length > (zend_long) (ops->digest_size * 255)) { in PHP_FUNCTION()
911 zend_argument_value_error(3, "must be less than or equal to %zd", ops->digest_size * 255); in PHP_FUNCTION()
915 context = php_hash_alloc_context(ops); in PHP_FUNCTION()
918 ops->hash_init(context); in PHP_FUNCTION()
919 K = emalloc(ops->block_size); in PHP_FUNCTION()
920 php_hash_hmac_prep_key(K, ops, context, in PHP_FUNCTION()
923 prk = emalloc(ops->digest_size); in PHP_FUNCTION()
924 php_hash_hmac_round(prk, ops, context, K, (unsigned char *) ZSTR_VAL(ikm), ZSTR_LEN(ikm)); in PHP_FUNCTION()
925 php_hash_string_xor_char(K, K, 0x6A, ops->block_size); in PHP_FUNCTION()
926 php_hash_hmac_round(prk, ops, context, K, prk, ops->digest_size); in PHP_FUNCTION()
927 ZEND_SECURE_ZERO(K, ops->block_size); in PHP_FUNCTION()
931 digest = emalloc(ops->digest_size); in PHP_FUNCTION()
932 for (i = 1, rounds = (length - 1) / ops->digest_size + 1; i <= rounds; i++) { in PHP_FUNCTION()
937 php_hash_hmac_prep_key(K, ops, context, prk, ops->digest_size); in PHP_FUNCTION()
938 ops->hash_init(context); in PHP_FUNCTION()
939 ops->hash_update(context, K, ops->block_size); in PHP_FUNCTION()
942 ops->hash_update(context, digest, ops->digest_size); in PHP_FUNCTION()
946 ops->hash_update(context, (unsigned char *) ZSTR_VAL(info), ZSTR_LEN(info)); in PHP_FUNCTION()
949 ops->hash_update(context, c, 1); in PHP_FUNCTION()
950 ops->hash_final(digest, context); in PHP_FUNCTION()
951 php_hash_string_xor_char(K, K, 0x6A, ops->block_size); in PHP_FUNCTION()
952 php_hash_hmac_round(digest, ops, context, K, digest, ops->digest_size); in PHP_FUNCTION()
954 ZSTR_VAL(returnval) + ((i - 1) * ops->digest_size), in PHP_FUNCTION()
956 (i == rounds ? length - ((i - 1) * ops->digest_size) : ops->digest_size) in PHP_FUNCTION()
960 ZEND_SECURE_ZERO(K, ops->block_size); in PHP_FUNCTION()
961 ZEND_SECURE_ZERO(digest, ops->digest_size); in PHP_FUNCTION()
962 ZEND_SECURE_ZERO(prk, ops->digest_size); in PHP_FUNCTION()
981 const php_hash_ops *ops; in PHP_FUNCTION() local
988 ops = php_hash_fetch_ops(algo); in PHP_FUNCTION()
989 if (!ops || !ops->is_crypto) { in PHP_FUNCTION()
1009 context = php_hash_alloc_context(ops); in PHP_FUNCTION()
1010 ops->hash_init(context); in PHP_FUNCTION()
1012 K1 = emalloc(ops->block_size); in PHP_FUNCTION()
1013 K2 = emalloc(ops->block_size); in PHP_FUNCTION()
1014 digest = emalloc(ops->digest_size); in PHP_FUNCTION()
1015 temp = emalloc(ops->digest_size); in PHP_FUNCTION()
1018 php_hash_hmac_prep_key(K1, ops, context, (unsigned char *) pass, pass_len); in PHP_FUNCTION()
1020 php_hash_string_xor_char(K2, K1, 0x6A, ops->block_size); in PHP_FUNCTION()
1024 length = ops->digest_size; in PHP_FUNCTION()
1034 loops = (zend_long) ceil((float) digest_length / (float) ops->digest_size); in PHP_FUNCTION()
1036 result = safe_emalloc(loops, ops->digest_size, 0); in PHP_FUNCTION()
1050 php_hash_hmac_round(digest, ops, context, K1, computed_salt, (zend_long) salt_len + 4); in PHP_FUNCTION()
1051 php_hash_hmac_round(digest, ops, context, K2, digest, ops->digest_size); in PHP_FUNCTION()
1055 memcpy(temp, digest, ops->digest_size); in PHP_FUNCTION()
1063 php_hash_hmac_round(digest, ops, context, K1, digest, ops->digest_size); in PHP_FUNCTION()
1064 php_hash_hmac_round(digest, ops, context, K2, digest, ops->digest_size); in PHP_FUNCTION()
1067 php_hash_string_xor(temp, temp, digest, ops->digest_size); in PHP_FUNCTION()
1070 memcpy(result + ((i - 1) * ops->digest_size), temp, ops->digest_size); in PHP_FUNCTION()
1073 ZEND_SECURE_ZERO(K1, ops->block_size); in PHP_FUNCTION()
1074 ZEND_SECURE_ZERO(K2, ops->block_size); in PHP_FUNCTION()
1266 …const php_hash_ops *ops = zend_hash_str_find_ptr(&php_hash_hashtable, algorithm_lookup.hash_name, … in PHP_FUNCTION() local
1267 if (ops) { in PHP_FUNCTION()
1268 RETVAL_LONG(ops->digest_size); in PHP_FUNCTION()
1308 …const php_hash_ops *ops = zend_hash_str_find_ptr(&php_hash_hashtable, algorithm_lookup.hash_name, … in PHP_FUNCTION() local
1309 if (ops) { in PHP_FUNCTION()
1314 size_t block_size = ops->digest_size; in PHP_FUNCTION()
1321 context = php_hash_alloc_context(ops); in PHP_FUNCTION()
1322 ops->hash_init(context); in PHP_FUNCTION()
1325 digest = emalloc(ops->digest_size + 1); in PHP_FUNCTION()
1328 ops->hash_init(context); in PHP_FUNCTION()
1331 ops->hash_update(context, &null, 1); in PHP_FUNCTION()
1333 ops->hash_update(context, (unsigned char *)padded_salt, salt_len); in PHP_FUNCTION()
1334 ops->hash_update(context, (unsigned char *)password, password_len); in PHP_FUNCTION()
1335 ops->hash_final((unsigned char *)digest, context); in PHP_FUNCTION()
1377 ZEND_SECURE_ZERO(hash->key, hash->ops->block_size); in php_hashcontext_dtor()
1392 newobj->ops = oldobj->ops; in php_hashcontext_clone()
1394 newobj->context = php_hash_alloc_context(newobj->ops); in php_hashcontext_clone()
1395 newobj->ops->hash_init(newobj->context); in php_hashcontext_clone()
1397 if (SUCCESS != newobj->ops->hash_copy(newobj->ops, oldobj->context, newobj->context)) { in php_hashcontext_clone()
1403 newobj->key = ecalloc(1, newobj->ops->block_size); in php_hashcontext_clone()
1405 memcpy(newobj->key, oldobj->key, newobj->ops->block_size); in php_hashcontext_clone()
1445 if (!hash->ops->hash_serialize) { in PHP_METHOD()
1452 ZVAL_STRING(&tmp, hash->ops->algo); in PHP_METHOD()
1458 if (hash->ops->hash_serialize(hash, &magic, &tmp) != SUCCESS) { in PHP_METHOD()
1474 …ow_exception_ex(NULL, 0, "HashContext for algorithm \"%s\" cannot be serialized", hash->ops->algo); in PHP_METHOD()
1488 const php_hash_ops *ops; in PHP_METHOD() local
1521 ops = php_hash_fetch_ops(Z_STR_P(algo_zv)); in PHP_METHOD()
1522 if (!ops) { in PHP_METHOD()
1525 } else if (!ops->hash_unserialize) { in PHP_METHOD()
1526 zend_throw_exception_ex(NULL, 0, "Hash algorithm \"%s\" cannot be unserialized", ops->algo); in PHP_METHOD()
1530 hash->ops = ops; in PHP_METHOD()
1531 hash->context = php_hash_alloc_context(ops); in PHP_METHOD()
1532 ops->hash_init(hash->context); in PHP_METHOD()
1535 unserialize_result = ops->hash_unserialize(hash, magic, hash_zv); in PHP_METHOD()
1537 …x(NULL, 0, "Incomplete or ill-formed serialization data (\"%s\" code %d)", ops->algo, unserialize_… in PHP_METHOD()