if test "$PHP_HASH" != "no"; then
AC_DEFINE(HAVE_HASH_EXT,1,[Have HASH Extension])
PHP_NEW_EXTENSION(hash, hash.c hash_md.c hash_sha.c hash_ripemd.c hash_haval.c, $ext_shared)
+ ifdef([PHP_INSTALL_HEADERS], [
+ PHP_INSTALL_HEADERS(ext/hash, php_hash.h php_hash_md.h php_hash_sha.h php_hash_ripemd.h php_hash_haval.h)
+ ], [ ])
fi
PHP_HASH_API php_hash_ops *php_hash_fetch_ops(const char *algo, int algo_len)
{
php_hash_ops *ops;
+ char *lower = estrndup(algo, algo_len);
- if (zend_hash_find(&php_hash_hashtable, algo, algo_len + 1, (void**)&ops) == SUCCESS) {
- return ops;
+ zend_str_tolower(lower, algo_len);
+ if (SUCCESS != zend_hash_find(&php_hash_hashtable, lower, algo_len + 1, (void**)&ops)) {
+ ops = NULL;
}
+ efree(lower);
- return NULL;
+ return ops;
}
PHP_HASH_API void php_hash_register_algo(const char *algo, php_hash_ops *ops)
{
- zend_hash_add(&php_hash_hashtable, algo, strlen(algo) + 1, ops, sizeof(php_hash_ops), NULL);
+ int algo_len = strlen(algo);
+ char *lower = estrndup(algo, algo_len);
+
+ zend_str_tolower(lower, algo_len);
+ zend_hash_add(&php_hash_hashtable, lower, algo_len + 1, ops, sizeof(php_hash_ops), NULL);
+ efree(lower);
}
/* Userspace */
-inline void php_hash_bin2hex(char *out, unsigned char *in, int in_len)
-{
- static const char hexits[16] = "0123456789abcdef";
- int i;
-
- for(i = 0; i < in_len; i++) {
- out[i * 2] = hexits[in[i] >> 4];
- out[(i * 2) + 1] = hexits[in[i] & 0x0F];
- }
-}
-
static void php_hash_do_hash(INTERNAL_FUNCTION_PARAMETERS, int isfilename)
{
char *algo, *data, *digest;
/* }}} */
/* {{{ proto bool hash_update_file(resource context, string filename[, resource context])
-Pump data into the hashing algorithm from an open stream */
+Pump data into the hashing algorithm from a file */
PHP_FUNCTION(hash_update_file)
{
zval *zhash, *zcontext = NULL;
PHP_HASH_API void make_digest(char *md5str, unsigned char *digest)
{
- int i;
-
- for (i = 0; i < 16; i++) {
- sprintf(md5str, "%02x", digest[i]);
- md5str += 2;
- }
-
- *md5str = '\0';
+ php_hash_bin2hex(md5str, digest, 16);
+ md5str[16] = '\0';
}
/* {{{ proto string md5(string str, [ bool raw_output])
PHP_HASH_API void make_sha1_digest(char *sha1str, unsigned char *digest)
{
- int i;
-
- for (i = 0; i < 20; i++) {
- sprintf(sha1str, "%02x", digest[i]);
- sha1str += 2;
- }
-
- *sha1str = '\0';
+ php_hash_bin2hex(sha1str, digest, 20);
+ sha1str[20] = '\0';
}
/* {{{ proto string sha1(string str [, bool raw_output])
PHP_HASH_API php_hash_ops *php_hash_fetch_ops(const char *algo, int algo_len);
PHP_HASH_API void php_hash_register_algo(const char *algo, php_hash_ops *ops);
+static inline void php_hash_bin2hex(char *out, unsigned char *in, int in_len)
+{
+ static const char hexits[16] = "0123456789abcdef";
+ int i;
+
+ for(i = 0; i < in_len; i++) {
+ out[i * 2] = hexits[in[i] >> 4];
+ out[(i * 2) + 1] = hexits[in[i] & 0x0F];
+ }
+}
+
#endif /* PHP_HASH_H */