Skip to content

Commit a382c92

Browse files
authored
Merge pull request #4 from davidgraeff/patch-1
Use nginx internal md5 and sha1 implementations
2 parents 98a7e91 + 2a75363 commit a382c92

File tree

1 file changed

+12
-28
lines changed

1 file changed

+12
-28
lines changed

ngx_http_upload_module.c

+12-28
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,10 @@
99
#include <ngx_config.h>
1010
#include <ngx_core.h>
1111
#include <ngx_http.h>
12+
#include <ngx_md5.h>
13+
#include <ngx_sha1.h>
1214
#include <nginx.h>
1315

14-
#if (NGX_HAVE_OPENSSL_MD5_H)
15-
#include <openssl/md5.h>
16-
#else
17-
#include <md5.h>
18-
#endif
19-
20-
#if (NGX_HAVE_OPENSSL_SHA1_H)
21-
#include <openssl/sha.h>
22-
#else
23-
#include <sha.h>
24-
#endif
25-
26-
27-
#if (NGX_OPENSSL_MD5)
28-
#define MD5Init MD5_Init
29-
#define MD5Update MD5_Update
30-
#define MD5Final MD5_Final
31-
#endif
32-
3316
#define MULTIPART_FORM_DATA_STRING "multipart/form-data"
3417
#define BOUNDARY_STRING "boundary="
3518
#define CONTENT_DISPOSITION_STRING "Content-Disposition:"
@@ -152,13 +135,15 @@ typedef struct {
152135
unsigned int crc32:1;
153136
} ngx_http_upload_loc_conf_t;
154137

138+
#define MD5_DIGEST_LENGTH 16
155139
typedef struct ngx_http_upload_md5_ctx_s {
156-
MD5_CTX md5;
140+
ngx_md5_t md5;
157141
u_char md5_digest[MD5_DIGEST_LENGTH * 2];
158142
} ngx_http_upload_md5_ctx_t;
159143

144+
#define SHA_DIGEST_LENGTH 20
160145
typedef struct ngx_http_upload_sha1_ctx_s {
161-
SHA_CTX sha1;
146+
ngx_sha1_t sha1;
162147
u_char sha1_digest[SHA_DIGEST_LENGTH * 2];
163148
} ngx_http_upload_sha1_ctx_t;
164149

@@ -1855,10 +1840,10 @@ static ngx_int_t ngx_http_upload_start_handler(ngx_http_upload_ctx_t *u) { /* {{
18551840
}
18561841

18571842
if(u->md5_ctx != NULL)
1858-
MD5Init(&u->md5_ctx->md5);
1843+
ngx_md5_init(&u->md5_ctx->md5);
18591844

18601845
if(u->sha1_ctx != NULL)
1861-
SHA1_Init(&u->sha1_ctx->sha1);
1846+
ngx_sha1_init(&u->sha1_ctx->sha1);
18621847

18631848
if(u->calculate_crc32)
18641849
ngx_crc32_init(u->crc32);
@@ -1945,10 +1930,10 @@ static void ngx_http_upload_finish_handler(ngx_http_upload_ctx_t *u) { /* {{{ */
19451930
ngx_close_file(u->output_file.fd);
19461931

19471932
if(u->md5_ctx)
1948-
MD5Final(u->md5_ctx->md5_digest, &u->md5_ctx->md5);
1933+
ngx_md5_final(u->md5_ctx->md5_digest, &u->md5_ctx->md5);
19491934

19501935
if(u->sha1_ctx)
1951-
SHA1_Final(u->sha1_ctx->sha1_digest, &u->sha1_ctx->sha1);
1936+
ngx_sha1_final(u->sha1_ctx->sha1_digest, &u->sha1_ctx->sha1);
19521937

19531938
if(u->calculate_crc32)
19541939
ngx_crc32_final(u->crc32);
@@ -2107,10 +2092,10 @@ static ngx_int_t ngx_http_upload_flush_output_buffer(ngx_http_upload_ctx_t *u, u
21072092
}
21082093

21092094
if(u->md5_ctx)
2110-
MD5Update(&u->md5_ctx->md5, buf, len);
2095+
ngx_md5_update(&u->md5_ctx->md5, buf, len);
21112096

21122097
if(u->sha1_ctx)
2113-
SHA1_Update(&u->sha1_ctx->sha1, buf, len);
2098+
ngx_sha1_update(&u->sha1_ctx->sha1, buf, len);
21142099

21152100
if(u->calculate_crc32)
21162101
ngx_crc32_update(&u->crc32, buf, len);
@@ -4018,4 +4003,3 @@ ngx_upload_cleanup_handler(void *data)
40184003
}
40194004
}
40204005
} /* }}} */
4021-

0 commit comments

Comments
 (0)