summaryrefslogtreecommitdiff
path: root/src/sp_php_compat.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/sp_php_compat.h')
-rw-r--r--src/sp_php_compat.h36
1 files changed, 35 insertions, 1 deletions
diff --git a/src/sp_php_compat.h b/src/sp_php_compat.h
index 09d9a1f..d1102a8 100644
--- a/src/sp_php_compat.h
+++ b/src/sp_php_compat.h
@@ -1,3 +1,7 @@
1/* code in this file is licensed under its original license
2The PHP License, version 3.01 (https://www.php.net/license/3_01.txt)
3which is also included with these sources in the file `PHP_LICENSE` */
4
1#if PHP_VERSION_ID < 80000 5#if PHP_VERSION_ID < 80000
2 6
3// copied from PHP 8.0.9 sources 7// copied from PHP 8.0.9 sources
@@ -93,4 +97,34 @@ static zend_always_inline void zend_string_efree(zend_string *s)
93 __ht->nNumUsed = _idx; \ 97 __ht->nNumUsed = _idx; \
94 } while (0) 98 } while (0)
95 99
96#endif \ No newline at end of file 100#endif
101
102// copied from PHP 8.0.11 sources, ext/hash/hash.c
103
104static inline void php_hash_string_xor_char(unsigned char *out, const unsigned char *in, const unsigned char xor_with, const size_t length) {
105 size_t i;
106 for (i=0; i < length; i++) {
107 out[i] = in[i] ^ xor_with;
108 }
109}
110
111static inline void php_hash_hmac_prep_key(unsigned char *K, const php_hash_ops *ops, void *context, const unsigned char *key, const size_t key_len) {
112 memset(K, 0, ops->block_size);
113 if (key_len > ops->block_size) {
114 /* Reduce the key first */
115 ops->hash_init(context);
116 ops->hash_update(context, key, key_len);
117 ops->hash_final(K, context);
118 } else {
119 memcpy(K, key, key_len);
120 }
121 /* XOR the key with 0x36 to get the ipad) */
122 php_hash_string_xor_char(K, K, 0x36, ops->block_size);
123}
124
125static inline void php_hash_hmac_round(unsigned char *final, const php_hash_ops *ops, void *context, const unsigned char *key, const unsigned char *data, const zend_long data_size) {
126 ops->hash_init(context);
127 ops->hash_update(context, key, ops->block_size);
128 ops->hash_update(context, data, data_size);
129 ops->hash_final(final, context);
130}