21
21
#include "crypto.h"
22
22
#include <ext/standard/sha1.h>
23
23
24
- 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 ) /* {{{ */
25
25
{
26
- php_hash_ops * hash_ops = (php_hash_ops * )ops ;
26
+ php_mongo_hash_ops * hash_ops = (php_mongo_hash_ops * )ops ;
27
27
28
28
memcpy (dest_context , orig_context , hash_ops -> context_size );
29
29
return SUCCESS ;
30
30
}
31
31
/* }}} */
32
32
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 ,
38
38
20 ,
39
39
64 ,
40
40
sizeof (PHP_SHA1_CTX )
41
41
};
42
42
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 ) {
44
44
int i ;
45
45
for (i = 0 ; i < length ; i ++ ) {
46
46
out [i ] = in [i ] ^ xor_with ;
47
47
}
48
48
}
49
49
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 ) {
51
51
int i ;
52
52
for (i = 0 ; i < length ; i ++ ) {
53
53
out [i ] = in [i ] ^ xor_with [i ];
54
54
}
55
55
}
56
56
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 ) {
58
58
memset (K , 0 , ops -> block_size );
59
59
if (key_len > ops -> block_size ) {
60
60
/* Reduce the key first */
@@ -65,10 +65,10 @@ static inline void php_hash_hmac_prep_key(unsigned char *K, const php_hash_ops *
65
65
memcpy (K , key , key_len );
66
66
}
67
67
/* 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 );
69
69
}
70
70
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 ) {
72
72
ops -> hash_init (context );
73
73
ops -> hash_update (context , key , ops -> block_size );
74
74
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
80
80
{
81
81
char * K ;
82
82
void * context ;
83
- const php_hash_ops * ops = & sha1_hash_ops ;
83
+ const php_mongo_hash_ops * ops = & sha1_hash_ops ;
84
84
85
85
context = emalloc (ops -> context_size );
86
86
87
87
K = emalloc (ops -> block_size );
88
88
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 );
90
90
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 );
92
92
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 );
94
94
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 );
96
96
97
97
/* Zero the key */
98
98
memset (K , 0 , ops -> block_size );
@@ -118,7 +118,7 @@ int php_mongo_hash_pbkdf2_sha1(char *password, int password_len, unsigned char *
118
118
long loops , i , j , length = 0 , digest_length ;
119
119
zend_bool raw_output = 1 ;
120
120
void * context ;
121
- const php_hash_ops * ops = & sha1_hash_ops ;
121
+ const php_mongo_hash_ops * ops = & sha1_hash_ops ;
122
122
123
123
124
124
if (iterations <= 0 ) {
@@ -140,9 +140,9 @@ int php_mongo_hash_pbkdf2_sha1(char *password, int password_len, unsigned char *
140
140
temp = emalloc (ops -> digest_size );
141
141
142
142
/* 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 );
144
144
/* 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 );
146
146
147
147
/* Setup Main Loop to build a long enough result */
148
148
if (length == 0 ) {
@@ -172,8 +172,8 @@ int php_mongo_hash_pbkdf2_sha1(char *password, int password_len, unsigned char *
172
172
computed_salt [salt_len + 2 ] = (unsigned char ) ((i & 0xFF00 ) >> 8 );
173
173
computed_salt [salt_len + 3 ] = (unsigned char ) (i & 0xFF );
174
174
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 );
177
177
/* } */
178
178
179
179
/* temp = digest */
@@ -185,11 +185,11 @@ int php_mongo_hash_pbkdf2_sha1(char *password, int password_len, unsigned char *
185
185
*/
186
186
for (j = 1 ; j < iterations ; j ++ ) {
187
187
/* 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 );
190
190
/* } */
191
191
/* 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 );
193
193
}
194
194
/* result += temp */
195
195
memcpy (result + ((i - 1 ) * ops -> digest_size ), temp , ops -> digest_size );
0 commit comments