2121#include "crypto.h"
2222#include <ext/standard/sha1.h>
2323
24- static int php_hash_copy (const void * ops , void * orig_context , void * dest_context ) /* {{{ */
24+ static int php_mongo_hash_copy (const void * ops , void * orig_context , void * dest_context ) /* {{{ */
2525{
26- php_hash_ops * hash_ops = (php_hash_ops * )ops ;
26+ php_mongo_hash_ops * hash_ops = (php_mongo_hash_ops * )ops ;
2727
2828 memcpy (dest_context , orig_context , hash_ops -> context_size );
2929 return SUCCESS ;
3030}
3131/* }}} */
3232
33- const php_hash_ops sha1_hash_ops = {
34- (php_hash_init_func_t ) PHP_SHA1Init ,
35- (php_hash_update_func_t ) PHP_SHA1Update ,
36- (php_hash_final_func_t ) PHP_SHA1Final ,
37- (php_hash_copy_func_t ) php_hash_copy ,
33+ const php_mongo_hash_ops sha1_hash_ops = {
34+ (php_mongo_hash_init_func_t ) PHP_SHA1Init ,
35+ (php_mongo_hash_update_func_t ) PHP_SHA1Update ,
36+ (php_mongo_hash_final_func_t ) PHP_SHA1Final ,
37+ (php_mongo_hash_copy_func_t ) php_mongo_hash_copy ,
3838 20 ,
3939 64 ,
4040 sizeof (PHP_SHA1_CTX )
4141};
4242
43- static inline void php_hash_string_xor_char (unsigned char * out , const unsigned char * in , const unsigned char xor_with , const int length ) {
43+ static inline void php_mongo_hash_string_xor_char (unsigned char * out , const unsigned char * in , const unsigned char xor_with , const int length ) {
4444 int i ;
4545 for (i = 0 ; i < length ; i ++ ) {
4646 out [i ] = in [i ] ^ xor_with ;
4747 }
4848}
4949
50- static inline void php_hash_string_xor (unsigned char * out , const unsigned char * in , const unsigned char * xor_with , const int length ) {
50+ static inline void php_mongo_hash_string_xor (unsigned char * out , const unsigned char * in , const unsigned char * xor_with , const int length ) {
5151 int i ;
5252 for (i = 0 ; i < length ; i ++ ) {
5353 out [i ] = in [i ] ^ xor_with [i ];
5454 }
5555}
5656
57- static inline void php_hash_hmac_prep_key (unsigned char * K , const php_hash_ops * ops , void * context , const unsigned char * key , const int key_len ) {
57+ static inline void php_mongo_hash_hmac_prep_key (unsigned char * K , const php_mongo_hash_ops * ops , void * context , const unsigned char * key , const int key_len ) {
5858 memset (K , 0 , ops -> block_size );
5959 if (key_len > ops -> block_size ) {
6060 /* Reduce the key first */
@@ -65,10 +65,10 @@ static inline void php_hash_hmac_prep_key(unsigned char *K, const php_hash_ops *
6565 memcpy (K , key , key_len );
6666 }
6767 /* XOR the key with 0x36 to get the ipad) */
68- php_hash_string_xor_char (K , K , 0x36 , ops -> block_size );
68+ php_mongo_hash_string_xor_char (K , K , 0x36 , ops -> block_size );
6969}
7070
71- static 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 long data_size ) {
71+ static inline void php_mongo_hash_hmac_round (unsigned char * final , const php_mongo_hash_ops * ops , void * context , const unsigned char * key , const unsigned char * data , const long data_size ) {
7272 ops -> hash_init (context );
7373 ops -> hash_update (context , key , ops -> block_size );
7474 ops -> hash_update (context , data , data_size );
@@ -80,19 +80,19 @@ void php_mongo_hmac(unsigned char *data, int data_len, char *key, int key_len, u
8080{
8181 char * K ;
8282 void * context ;
83- const php_hash_ops * ops = & sha1_hash_ops ;
83+ const php_mongo_hash_ops * ops = & sha1_hash_ops ;
8484
8585 context = emalloc (ops -> context_size );
8686
8787 K = emalloc (ops -> block_size );
8888
89- php_hash_hmac_prep_key ((unsigned char * ) K , ops , context , (unsigned char * ) key , key_len );
89+ php_mongo_hash_hmac_prep_key ((unsigned char * ) K , ops , context , (unsigned char * ) key , key_len );
9090
91- php_hash_hmac_round ((unsigned char * ) return_value , ops , context , (unsigned char * ) K , (unsigned char * ) data , data_len );
91+ php_mongo_hash_hmac_round ((unsigned char * ) return_value , ops , context , (unsigned char * ) K , (unsigned char * ) data , data_len );
9292
93- php_hash_string_xor_char ((unsigned char * ) K , (unsigned char * ) K , 0x6A , ops -> block_size );
93+ php_mongo_hash_string_xor_char ((unsigned char * ) K , (unsigned char * ) K , 0x6A , ops -> block_size );
9494
95- php_hash_hmac_round ((unsigned char * ) return_value , ops , context , (unsigned char * ) K , (unsigned char * ) return_value , ops -> digest_size );
95+ php_mongo_hash_hmac_round ((unsigned char * ) return_value , ops , context , (unsigned char * ) K , (unsigned char * ) return_value , ops -> digest_size );
9696
9797 /* Zero the key */
9898 memset (K , 0 , ops -> block_size );
@@ -118,7 +118,7 @@ int php_mongo_hash_pbkdf2_sha1(char *password, int password_len, unsigned char *
118118 long loops , i , j , length = 0 , digest_length ;
119119 zend_bool raw_output = 1 ;
120120 void * context ;
121- const php_hash_ops * ops = & sha1_hash_ops ;
121+ const php_mongo_hash_ops * ops = & sha1_hash_ops ;
122122
123123
124124 if (iterations <= 0 ) {
@@ -140,9 +140,9 @@ int php_mongo_hash_pbkdf2_sha1(char *password, int password_len, unsigned char *
140140 temp = emalloc (ops -> digest_size );
141141
142142 /* Setup Keys that will be used for all hmac rounds */
143- php_hash_hmac_prep_key (K1 , ops , context , (unsigned char * ) password , password_len );
143+ php_mongo_hash_hmac_prep_key (K1 , ops , context , (unsigned char * ) password , password_len );
144144 /* Convert K1 to opad -- 0x6A = 0x36 ^ 0x5C */
145- php_hash_string_xor_char (K2 , K1 , 0x6A , ops -> block_size );
145+ php_mongo_hash_string_xor_char (K2 , K1 , 0x6A , ops -> block_size );
146146
147147 /* Setup Main Loop to build a long enough result */
148148 if (length == 0 ) {
@@ -172,8 +172,8 @@ int php_mongo_hash_pbkdf2_sha1(char *password, int password_len, unsigned char *
172172 computed_salt [salt_len + 2 ] = (unsigned char ) ((i & 0xFF00 ) >> 8 );
173173 computed_salt [salt_len + 3 ] = (unsigned char ) (i & 0xFF );
174174
175- php_hash_hmac_round (digest , ops , context , K1 , computed_salt , (long ) salt_len + 4 );
176- php_hash_hmac_round (digest , ops , context , K2 , digest , ops -> digest_size );
175+ php_mongo_hash_hmac_round (digest , ops , context , K1 , computed_salt , (long ) salt_len + 4 );
176+ php_mongo_hash_hmac_round (digest , ops , context , K2 , digest , ops -> digest_size );
177177 /* } */
178178
179179 /* temp = digest */
@@ -185,11 +185,11 @@ int php_mongo_hash_pbkdf2_sha1(char *password, int password_len, unsigned char *
185185 */
186186 for (j = 1 ; j < iterations ; j ++ ) {
187187 /* digest = hash_hmac(digest, password) { */
188- php_hash_hmac_round (digest , ops , context , K1 , digest , ops -> digest_size );
189- php_hash_hmac_round (digest , ops , context , K2 , digest , ops -> digest_size );
188+ php_mongo_hash_hmac_round (digest , ops , context , K1 , digest , ops -> digest_size );
189+ php_mongo_hash_hmac_round (digest , ops , context , K2 , digest , ops -> digest_size );
190190 /* } */
191191 /* temp ^= digest */
192- php_hash_string_xor (temp , temp , digest , ops -> digest_size );
192+ php_mongo_hash_string_xor (temp , temp , digest , ops -> digest_size );
193193 }
194194 /* result += temp */
195195 memcpy (result + ((i - 1 ) * ops -> digest_size ), temp , ops -> digest_size );
0 commit comments