process = MUNCH_SIZE;
else
process = Py_SAFE_DOWNCAST(len, Py_ssize_t, unsigned int);
- EVP_DigestUpdate(self->ctx, (const void*)cp, process);
+ if (!EVP_DigestUpdate(self->ctx, (const void*)cp, process)) {
+ _setException(PyExc_ValueError);
+ break;
+ }
len -= process;
cp += process;
}
return _setException(PyExc_ValueError);
}
digest_size = EVP_MD_CTX_size(temp_ctx);
- EVP_DigestFinal(temp_ctx, digest, NULL);
+ if (!EVP_DigestFinal(temp_ctx, digest, NULL)) {
+ _setException(PyExc_ValueError);
+ return NULL;
+ }
retval = PyBytes_FromStringAndSize((const char *)digest, digest_size);
EVP_MD_CTX_free(temp_ctx);
return _setException(PyExc_ValueError);
}
digest_size = EVP_MD_CTX_size(temp_ctx);
- EVP_DigestFinal(temp_ctx, digest, NULL);
+ if (!EVP_DigestFinal(temp_ctx, digest, NULL)) {
+ _setException(PyExc_ValueError);
+ return NULL;
+ }
EVP_MD_CTX_free(temp_ctx);
PyBuffer_Release(&view);
return -1;
}
- EVP_DigestInit(self->ctx, digest);
+ if (!EVP_DigestInit(self->ctx, digest)) {
+ _setException(PyExc_ValueError);
+ if (data_obj)
+ PyBuffer_Release(&view);
+ return -1;
+ }
self->name = name_obj;
Py_INCREF(self->name);
if (initial_ctx) {
EVP_MD_CTX_copy(self->ctx, initial_ctx);
} else {
- EVP_DigestInit(self->ctx, digest);
+ if (!EVP_DigestInit(self->ctx, digest)) {
+ _setException(PyExc_ValueError);
+ Py_DECREF(self);
+ return NULL;
+ }
}
if (cp && len) {
* the generic one passing it a python string and are noticeably
* faster than calling a python new() wrapper. Thats important for
* code that wants to make hashes of a bunch of small strings.
+ * The first call will lazy-initialize, which reports an exception
+ * if initialization fails.
*/
#define GEN_CONSTRUCTOR(NAME) \
static PyObject * \
if (!_PyArg_NoStackKeywords(#NAME, kwnames)) { \
return NULL; \
} \
+ \
+ if (CONST_new_ ## NAME ## _ctx_p == NULL) { \
+ EVP_MD_CTX *ctx_p = EVP_MD_CTX_new(); \
+ if (!EVP_get_digestbyname(#NAME) || \
+ !EVP_DigestInit(ctx_p, EVP_get_digestbyname(#NAME))) { \
+ _setException(PyExc_ValueError); \
+ EVP_MD_CTX_free(ctx_p); \
+ return NULL; \
+ } \
+ CONST_new_ ## NAME ## _ctx_p = ctx_p; \
+ } \
\
if (data_obj) \
GET_BUFFER_VIEW_OR_ERROUT(data_obj, &view); \
#define INIT_CONSTRUCTOR_CONSTANTS(NAME) do { \
if (CONST_ ## NAME ## _name_obj == NULL) { \
CONST_ ## NAME ## _name_obj = PyUnicode_FromString(#NAME); \
- if (EVP_get_digestbyname(#NAME)) { \
- CONST_new_ ## NAME ## _ctx_p = EVP_MD_CTX_new(); \
- EVP_DigestInit(CONST_new_ ## NAME ## _ctx_p, EVP_get_digestbyname(#NAME)); \
- } \
} \
} while (0);