use ngx_sha1.h
Igor Sysoev
14 years ago
11 | 11 | #include <ngx_event.h> |
12 | 12 | #include <ngx_event_connect.h> |
13 | 13 | #include <ngx_mysql.h> |
14 | ||
15 | #if (NGX_HAVE_OPENSSL_SHA1_H) | |
16 | #include <openssl/sha.h> | |
17 | #else | |
18 | #include <sha.h> | |
19 | #endif | |
14 | #include <ngx_sha1.h> | |
20 | 15 | |
21 | 16 | |
22 | 17 | #define NGX_MYSQL_LONG_PASSWORD 0x0001 |
141 | 136 | ngx_mysql_greeting1_pkt_t *gr1; |
142 | 137 | ngx_mysql_greeting2_pkt_t *gr2; |
143 | 138 | ngx_mysql_auth_pkt_t *auth; |
144 | SHA_CTX sha; | |
139 | ngx_sha1_t sha; | |
145 | 140 | u_char hash1[20], hash2[20]; |
146 | 141 | |
147 | 142 | c = rev->data; |
240 | 235 | |
241 | 236 | *p++ = (u_char) 20; |
242 | 237 | |
243 | SHA1_Init(&sha); | |
244 | SHA1_Update(&sha, m->passwd->data, m->passwd->len); | |
245 | SHA1_Final(hash1, &sha); | |
246 | ||
247 | SHA1_Init(&sha); | |
248 | SHA1_Update(&sha, hash1, 20); | |
249 | SHA1_Final(hash2, &sha); | |
250 | ||
251 | SHA1_Init(&sha); | |
252 | SHA1_Update(&sha, gr2->salt1, 8); | |
253 | SHA1_Update(&sha, gr2->salt2, 12); | |
254 | SHA1_Update(&sha, hash2, 20); | |
255 | SHA1_Final(hash2, &sha); | |
238 | ngx_sha1_init(&sha); | |
239 | ngx_sha1_update(&sha, m->passwd->data, m->passwd->len); | |
240 | ngx_sha1_final(hash1, &sha); | |
241 | ||
242 | ngx_sha1_init(&sha); | |
243 | ngx_sha1_update(&sha, hash1, 20); | |
244 | ngx_sha1_final(hash2, &sha); | |
245 | ||
246 | ngx_sha1_init(&sha); | |
247 | ngx_sha1_update(&sha, gr2->salt1, 8); | |
248 | ngx_sha1_update(&sha, gr2->salt2, 12); | |
249 | ngx_sha1_update(&sha, hash2, 20); | |
250 | ngx_sha1_final(hash2, &sha); | |
256 | 251 | |
257 | 252 | for (i = 0; i < 20; i++) { |
258 | 253 | *p++ = (u_char) (hash1[i] ^ hash2[i]); |