| ... |
... |
@@ -29,7 +29,10 @@ |
|
29
|
29
|
#include <string.h>
|
|
30
|
30
|
#include <errno.h>
|
|
31
|
31
|
#include <openssl/sha.h>
|
|
|
32
|
+#include <openssl/evp.h>
|
|
32
|
33
|
#include <fcntl.h>
|
|
|
34
|
+
|
|
|
35
|
+#define PY_SSIZE_T_CLEAN
|
|
33
|
36
|
#include <Python.h>
|
|
34
|
37
|
|
|
35
|
38
|
#define SHA1SIZE 20
|
| ... |
... |
@@ -60,11 +63,10 @@ static PyObject *hash_file(PyObject *self, PyObject *args) |
|
60
|
63
|
int fd, num_read;
|
|
61
|
64
|
unsigned char ibuf[BLOCKSIZE];
|
|
62
|
65
|
unsigned char obuf[SHA1SIZE];
|
|
63
|
|
- SHA_CTX ctx;
|
|
64
|
66
|
PyObject *res = NULL;
|
|
65
|
67
|
PyThreadState *_save;
|
|
66
|
68
|
char res_s[2*SHA1SIZE + 1];
|
|
67
|
|
- int r;
|
|
|
69
|
+ unsigned int r;
|
|
68
|
70
|
|
|
69
|
71
|
if (!PyArg_ParseTuple(args, "s", &filename))
|
|
70
|
72
|
goto done;
|
| ... |
... |
@@ -79,8 +81,11 @@ static PyObject *hash_file(PyObject *self, PyObject *args) |
|
79
|
81
|
//posix_fadvise(fd, 0, 0, POSIX_FADV_WILLNEED);
|
|
80
|
82
|
posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL);
|
|
81
|
83
|
|
|
82
|
|
- if (SHA1_Init(&ctx) != 1)
|
|
83
|
|
- py_err("SHA1_Init()", NULL);
|
|
|
84
|
+ EVP_MD_CTX *sha1_ctx = EVP_MD_CTX_new();
|
|
|
85
|
+ if (!sha1_ctx)
|
|
|
86
|
+ py_err("EVP_MD_CTX_new()", NULL);
|
|
|
87
|
+ if (EVP_DigestInit(sha1_ctx, EVP_sha1()) != 1)
|
|
|
88
|
+ py_err("EVP_DigestInit()", NULL);
|
|
84
|
89
|
while ((num_read = read(fd, ibuf, BLOCKSIZE))) {
|
|
85
|
90
|
if (num_read < 0) {
|
|
86
|
91
|
if (errno == EINTR)
|
| ... |
... |
@@ -88,10 +93,10 @@ static PyObject *hash_file(PyObject *self, PyObject *args) |
|
88
|
93
|
else
|
|
89
|
94
|
py_err("During read", filename);
|
|
90
|
95
|
}
|
|
91
|
|
- if (SHA1_Update(&ctx, ibuf, num_read) != 1)
|
|
92
|
|
- py_err("SHA1_Update", NULL);
|
|
|
96
|
+ if (EVP_DigestUpdate(sha1_ctx, ibuf, num_read) != 1)
|
|
|
97
|
+ py_err("EVP_DigestUpdate", NULL);
|
|
93
|
98
|
}
|
|
94
|
|
- if (SHA1_Final(obuf, &ctx) != 1)
|
|
|
99
|
+ if (EVP_DigestFinal(sha1_ctx, obuf, NULL) != 1)
|
|
95
|
100
|
py_err("SHA1_Final", NULL);
|
|
96
|
101
|
posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED);
|
|
97
|
102
|
if (close(fd) < 0)
|
| ... |
... |
@@ -110,6 +115,7 @@ static PyObject *hash_file(PyObject *self, PyObject *args) |
|
110
|
115
|
printf("%d vs %ld\n", r, sizeof(res_s));
|
|
111
|
116
|
py_err("snprintf failure", filename);
|
|
112
|
117
|
}
|
|
|
118
|
+ EVP_MD_CTX_free(sha1_ctx);
|
|
113
|
119
|
|
|
114
|
120
|
/** reacquire GIL **/
|
|
115
|
121
|
Py_BLOCK_THREADS
|