Mercurial > hg > nginx
comparison src/core/ngx_crypt.c @ 6586:1064ea81ed3a
An internal SHA1 implementation.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 09 Jun 2016 16:55:38 +0300 |
parents | 2cd019520210 |
children |
comparison
equal
deleted
inserted
replaced
6585:e511e3d581bb | 6586:1064ea81ed3a |
---|---|
6 | 6 |
7 #include <ngx_config.h> | 7 #include <ngx_config.h> |
8 #include <ngx_core.h> | 8 #include <ngx_core.h> |
9 #include <ngx_crypt.h> | 9 #include <ngx_crypt.h> |
10 #include <ngx_md5.h> | 10 #include <ngx_md5.h> |
11 #if (NGX_HAVE_SHA1) | |
12 #include <ngx_sha1.h> | 11 #include <ngx_sha1.h> |
13 #endif | |
14 | 12 |
15 | 13 |
16 #if (NGX_CRYPT) | 14 #if (NGX_CRYPT) |
17 | 15 |
18 static ngx_int_t ngx_crypt_apr1(ngx_pool_t *pool, u_char *key, u_char *salt, | 16 static ngx_int_t ngx_crypt_apr1(ngx_pool_t *pool, u_char *key, u_char *salt, |
19 u_char **encrypted); | 17 u_char **encrypted); |
20 static ngx_int_t ngx_crypt_plain(ngx_pool_t *pool, u_char *key, u_char *salt, | 18 static ngx_int_t ngx_crypt_plain(ngx_pool_t *pool, u_char *key, u_char *salt, |
21 u_char **encrypted); | 19 u_char **encrypted); |
22 | |
23 #if (NGX_HAVE_SHA1) | |
24 | |
25 static ngx_int_t ngx_crypt_ssha(ngx_pool_t *pool, u_char *key, u_char *salt, | 20 static ngx_int_t ngx_crypt_ssha(ngx_pool_t *pool, u_char *key, u_char *salt, |
26 u_char **encrypted); | 21 u_char **encrypted); |
27 static ngx_int_t ngx_crypt_sha(ngx_pool_t *pool, u_char *key, u_char *salt, | 22 static ngx_int_t ngx_crypt_sha(ngx_pool_t *pool, u_char *key, u_char *salt, |
28 u_char **encrypted); | 23 u_char **encrypted); |
29 | |
30 #endif | |
31 | 24 |
32 | 25 |
33 static u_char *ngx_crypt_to64(u_char *p, uint32_t v, size_t n); | 26 static u_char *ngx_crypt_to64(u_char *p, uint32_t v, size_t n); |
34 | 27 |
35 | 28 |
40 return ngx_crypt_apr1(pool, key, salt, encrypted); | 33 return ngx_crypt_apr1(pool, key, salt, encrypted); |
41 | 34 |
42 } else if (ngx_strncmp(salt, "{PLAIN}", sizeof("{PLAIN}") - 1) == 0) { | 35 } else if (ngx_strncmp(salt, "{PLAIN}", sizeof("{PLAIN}") - 1) == 0) { |
43 return ngx_crypt_plain(pool, key, salt, encrypted); | 36 return ngx_crypt_plain(pool, key, salt, encrypted); |
44 | 37 |
45 #if (NGX_HAVE_SHA1) | |
46 } else if (ngx_strncmp(salt, "{SSHA}", sizeof("{SSHA}") - 1) == 0) { | 38 } else if (ngx_strncmp(salt, "{SSHA}", sizeof("{SSHA}") - 1) == 0) { |
47 return ngx_crypt_ssha(pool, key, salt, encrypted); | 39 return ngx_crypt_ssha(pool, key, salt, encrypted); |
48 | 40 |
49 } else if (ngx_strncmp(salt, "{SHA}", sizeof("{SHA}") - 1) == 0) { | 41 } else if (ngx_strncmp(salt, "{SHA}", sizeof("{SHA}") - 1) == 0) { |
50 return ngx_crypt_sha(pool, key, salt, encrypted); | 42 return ngx_crypt_sha(pool, key, salt, encrypted); |
51 #endif | |
52 } | 43 } |
53 | 44 |
54 /* fallback to libc crypt() */ | 45 /* fallback to libc crypt() */ |
55 | 46 |
56 return ngx_libc_crypt(pool, key, salt, encrypted); | 47 return ngx_libc_crypt(pool, key, salt, encrypted); |
191 | 182 |
192 return NGX_OK; | 183 return NGX_OK; |
193 } | 184 } |
194 | 185 |
195 | 186 |
196 #if (NGX_HAVE_SHA1) | |
197 | |
198 static ngx_int_t | 187 static ngx_int_t |
199 ngx_crypt_ssha(ngx_pool_t *pool, u_char *key, u_char *salt, u_char **encrypted) | 188 ngx_crypt_ssha(ngx_pool_t *pool, u_char *key, u_char *salt, u_char **encrypted) |
200 { | 189 { |
201 size_t len; | 190 size_t len; |
202 ngx_int_t rc; | 191 ngx_int_t rc; |
276 encoded.data[encoded.len] = '\0'; | 265 encoded.data[encoded.len] = '\0'; |
277 | 266 |
278 return NGX_OK; | 267 return NGX_OK; |
279 } | 268 } |
280 | 269 |
281 #endif /* NGX_HAVE_SHA1 */ | |
282 | |
283 #endif /* NGX_CRYPT */ | 270 #endif /* NGX_CRYPT */ |