{
HASHobject *self = HASHobject_CAST(op);
long block_size = EVP_MD_CTX_block_size(self->ctx);
+ assert(block_size > 0);
return PyLong_FromLong(block_size);
}
{
HASHobject *self = HASHobject_CAST(op);
long size = EVP_MD_CTX_size(self->ctx);
+ assert(size > 0);
return PyLong_FromLong(size);
}
*
* On error, set an exception and return BAD_DIGEST_SIZE.
*/
-static unsigned int
+static int
_hashlib_hmac_digest_size(HMACobject *self)
{
assert(EVP_MAX_MD_SIZE < INT_MAX);
}
int digest_size = EVP_MD_size(md);
/* digest_size < 0 iff EVP_MD context is NULL (which is impossible here) */
- assert(digest_size >= 0);
assert(digest_size <= (int)EVP_MAX_MD_SIZE);
+ if (digest_size < 0) {
+ raise_ssl_error(PyExc_SystemError, "invalid digest size");
+ return BAD_DIGEST_SIZE;
+ }
#endif
/* digest_size == 0 means that the context is not entirely initialized */
if (digest_size == 0) {
- raise_ssl_error(PyExc_ValueError, "missing digest size");
+ raise_ssl_error(PyExc_SystemError, "missing digest size");
return BAD_DIGEST_SIZE;
}
- return (unsigned int)digest_size;
+ return (int)digest_size;
}
static int
static Py_ssize_t
_hmac_digest(HMACobject *self, unsigned char *buf)
{
- unsigned int digest_size = _hashlib_hmac_digest_size(self);
+ int digest_size = _hashlib_hmac_digest_size(self);
assert(digest_size <= EVP_MAX_MD_SIZE);
if (digest_size == BAD_DIGEST_SIZE) {
assert(PyErr_Occurred());
_hashlib_hmac_get_digest_size(PyObject *op, void *Py_UNUSED(closure))
{
HMACobject *self = HMACobject_CAST(op);
- unsigned int size = _hashlib_hmac_digest_size(self);
+ int size = _hashlib_hmac_digest_size(self);
return size == BAD_DIGEST_SIZE ? NULL : PyLong_FromLong(size);
}