Klaus Demo nginx / 4341d79
r1573, r1574, r1575 merge: ngx_md5.h and ngx_sha1.h Igor Sysoev 14 years ago
4 changed file(s) with 87 addition(s) and 20 deletion(s). Raw diff Collapse all Expand all
2020 src/core/ngx_file.h \
2121 src/core/ngx_crc.h \
2222 src/core/ngx_crc32.h \
23 src/core/ngx_md5.h \
24 src/core/ngx_sha1.h \
2325 src/core/ngx_rbtree.h \
2426 src/core/ngx_radix_tree.h \
2527 src/core/ngx_slab.h \
0
1 /*
2 * Copyright (C) Igor Sysoev
3 */
4
5
6 #ifndef _NGX_MD5_H_INCLUDED_
7 #define _NGX_MD5_H_INCLUDED_
8
9
10 #include <ngx_config.h>
11 #include <ngx_core.h>
12
13
14 #if (NGX_HAVE_OPENSSL_MD5_H)
15 #include <openssl/md5.h>
16 #else
17 #include <md5.h>
18 #endif
19
20
21 typedef MD5_CTX ngx_md5_t;
22
23
24 #if (NGX_OPENSSL_MD5)
25
26 #define ngx_md5_init MD5_Init
27 #define ngx_md5_update MD5_Update
28 #define ngx_md5_final MD5_Final
29
30 #else
31
32 #define ngx_md5_init MD5Init
33 #define ngx_md5_update MD5Update
34 #define ngx_md5_final MD5Final
35
36 #endif
37
38
39 #endif /* _NGX_MD5_H_INCLUDED_ */
0
1 /*
2 * Copyright (C) Igor Sysoev
3 */
4
5
6 #ifndef _NGX_SHA1_H_INCLUDED_
7 #define _NGX_SHA1_H_INCLUDED_
8
9
10 #include <ngx_config.h>
11 #include <ngx_core.h>
12
13
14 #if (NGX_HAVE_OPENSSL_SHA1_H)
15 #include <openssl/sha.h>
16 #else
17 #include <sha.h>
18 #endif
19
20
21 typedef SHA_CTX ngx_sha1_t;
22
23
24 #define ngx_sha1_init SHA1_Init
25 #define ngx_sha1_update SHA1_Update
26 #define ngx_sha1_final SHA1_Final
27
28
29 #endif /* _NGX_SHA1_H_INCLUDED_ */
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]);