diff options
Diffstat (limited to 'ext/hash/hash.c')
| -rw-r--r-- | ext/hash/hash.c | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/ext/hash/hash.c b/ext/hash/hash.c index e92185c4d5..0ac643160a 100644 --- a/ext/hash/hash.c +++ b/ext/hash/hash.c @@ -194,14 +194,14 @@ PHP_FUNCTION(hash_file) } /* }}} */ -static inline void php_hash_string_xor_char(unsigned char *out, const unsigned char *in, const unsigned char xor_with, const int length) { +static inline void php_hash_string_xor_char(unsigned char *out, const unsigned char *in, const unsigned char xor_with, const size_t length) { int i; for (i=0; i < length; i++) { out[i] = in[i] ^ xor_with; } } -static inline void php_hash_string_xor(unsigned char *out, const unsigned char *in, const unsigned char *xor_with, const int length) { +static inline void php_hash_string_xor(unsigned char *out, const unsigned char *in, const unsigned char *xor_with, const size_t length) { int i; for (i=0; i < length; i++) { out[i] = in[i] ^ xor_with[i]; @@ -210,7 +210,7 @@ static inline void php_hash_string_xor(unsigned char *out, const unsigned char * static 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) { memset(K, 0, ops->block_size); - if (key_len > (size_t)ops->block_size) { + if (key_len > ops->block_size) { /* Reduce the key first */ ops->hash_init(context); ops->hash_update(context, key, key_len); @@ -373,11 +373,11 @@ static void php_hashcontext_ctor(INTERNAL_FUNCTION_PARAMETERS, zval *objval) { if (options & PHP_HASH_HMAC) { char *K = emalloc(ops->block_size); - int i, block_size; + size_t i, block_size; memset(K, 0, ops->block_size); - if (ZSTR_LEN(key) > (size_t)ops->block_size) { + if (ZSTR_LEN(key) > ops->block_size) { /* Reduce the key first */ ops->hash_update(context, (unsigned char *) ZSTR_VAL(key), ZSTR_LEN(key)); ops->hash_final((unsigned char *) K, context); @@ -389,7 +389,7 @@ static void php_hashcontext_ctor(INTERNAL_FUNCTION_PARAMETERS, zval *objval) { /* XOR ipad */ block_size = ops->block_size; - for(i=0; i < block_size; i++) { + for(i = 0; i < block_size; i++) { K[i] ^= 0x36; } ops->hash_update(context, (unsigned char *) K, ops->block_size); @@ -514,7 +514,7 @@ PHP_FUNCTION(hash_final) php_hashcontext_object *hash; zend_bool raw_output = 0; zend_string *digest; - int digest_len; + size_t digest_len; if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|b", &zhash, php_hashcontext_ce, &raw_output) == FAILURE) { return; @@ -527,11 +527,11 @@ PHP_FUNCTION(hash_final) digest = zend_string_alloc(digest_len, 0); hash->ops->hash_final((unsigned char *) ZSTR_VAL(digest), hash->context); if (hash->options & PHP_HASH_HMAC) { - int i, block_size; + size_t i, block_size; /* Convert K to opad -- 0x6A = 0x36 ^ 0x5C */ block_size = hash->ops->block_size; - for(i=0; i < block_size; i++) { + for(i = 0; i < block_size; i++) { hash->key[i] ^= 0x6A; } @@ -620,7 +620,8 @@ PHP_FUNCTION(hash_hkdf) zend_string *returnval, *ikm, *algo, *info = NULL, *salt = NULL; zend_long length = 0; unsigned char *prk, *digest, *K; - int i, rounds; + int i; + size_t rounds; const php_hash_ops *ops; void *context; @@ -649,7 +650,7 @@ PHP_FUNCTION(hash_hkdf) RETURN_FALSE; } else if (length == 0) { length = ops->digest_size; - } else if (length > ops->digest_size * 255) { + } else if (length > (zend_long) (ops->digest_size * 255)) { php_error_docref(NULL, E_WARNING, "Length must be less than or equal to %d: " ZEND_LONG_FMT, ops->digest_size * 255, length); RETURN_FALSE; } @@ -671,7 +672,7 @@ PHP_FUNCTION(hash_hkdf) // Expand returnval = zend_string_alloc(length, 0); digest = emalloc(ops->digest_size); - for (i = 1, rounds = (int) (length - 1) / ops->digest_size + 1; i <= rounds; i++) { + for (i = 1, rounds = (length - 1) / ops->digest_size + 1; i <= rounds; i++) { // chr(i) unsigned char c[1]; c[0] = (i & 0xFF); @@ -831,7 +832,7 @@ PHP_FUNCTION(hash_pbkdf2) if (raw_output) { memcpy(ZSTR_VAL(returnval), result, length); } else { - php_hash_bin2hex(ZSTR_VAL(returnval), result, (int) digest_length); + php_hash_bin2hex(ZSTR_VAL(returnval), result, digest_length); } ZSTR_VAL(returnval)[length] = 0; efree(result); @@ -1067,9 +1068,12 @@ PHP_FUNCTION(mhash_keygen_s2k) void *context; char *key, *digest; int i = 0, j = 0; - int block_size = ops->digest_size; - int times = bytes / block_size; - if (bytes % block_size != 0) times++; + size_t block_size = ops->digest_size; + size_t times = bytes / block_size; + + if ((bytes % block_size) != 0) { + times++; + } context = emalloc(ops->context_size); ops->hash_init(context); |
