Klaus Demo nginx / 336943d
use ngx_sha1.h Igor Sysoev 14 years ago
1 changed file(s) with 15 addition(s) and 20 deletion(s). Raw diff Collapse all Expand all
1111 #include <ngx_event.h>
1212 #include <ngx_event_connect.h>
1313 #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>
2015
2116
2217 #define NGX_MYSQL_LONG_PASSWORD 0x0001
141136 ngx_mysql_greeting1_pkt_t *gr1;
142137 ngx_mysql_greeting2_pkt_t *gr2;
143138 ngx_mysql_auth_pkt_t *auth;
144 SHA_CTX sha;
139 ngx_sha1_t sha;
145140 u_char hash1[20], hash2[20];
146141
147142 c = rev->data;
240235
241236 *p++ = (u_char) 20;
242237
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);
256251
257252 for (i = 0; i < 20; i++) {
258253 *p++ = (u_char) (hash1[i] ^ hash2[i]);