Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 1 | /* Module that wraps all OpenSSL hash algorithms */ |
| 2 | |
| 3 | /* |
Benjamin Peterson | 46a9900 | 2010-01-09 18:45:30 +0000 | [diff] [blame] | 4 | * Copyright (C) 2005-2010 Gregory P. Smith (greg@krypto.org) |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 5 | * Licensed to PSF under a Contributor Agreement. |
| 6 | * |
| 7 | * Derived from a skeleton of shamodule.c containing work performed by: |
| 8 | * |
| 9 | * Andrew Kuchling (amk@amk.ca) |
| 10 | * Greg Stein (gstein@lyra.org) |
| 11 | * |
| 12 | */ |
| 13 | |
Thomas Wouters | 9bc844e | 2006-03-01 21:50:07 +0000 | [diff] [blame] | 14 | #define PY_SSIZE_T_CLEAN |
| 15 | |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 16 | #include "Python.h" |
| 17 | #include "structmember.h" |
Gregory P. Smith | 365a186 | 2009-02-12 07:35:29 +0000 | [diff] [blame] | 18 | #include "hashlib.h" |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 19 | |
Antoine Pitrou | bcd5cbe | 2009-01-08 21:17:16 +0000 | [diff] [blame] | 20 | #ifdef WITH_THREAD |
Gregory P. Smith | 3f61d61 | 2009-05-04 00:45:33 +0000 | [diff] [blame] | 21 | #include "pythread.h" |
Antoine Pitrou | bcd5cbe | 2009-01-08 21:17:16 +0000 | [diff] [blame] | 22 | #define ENTER_HASHLIB(obj) \ |
| 23 | if ((obj)->lock) { \ |
| 24 | if (!PyThread_acquire_lock((obj)->lock, 0)) { \ |
| 25 | Py_BEGIN_ALLOW_THREADS \ |
| 26 | PyThread_acquire_lock((obj)->lock, 1); \ |
| 27 | Py_END_ALLOW_THREADS \ |
| 28 | } \ |
| 29 | } |
| 30 | #define LEAVE_HASHLIB(obj) \ |
| 31 | if ((obj)->lock) { \ |
| 32 | PyThread_release_lock((obj)->lock); \ |
| 33 | } |
| 34 | #else |
| 35 | #define ENTER_HASHLIB(obj) |
| 36 | #define LEAVE_HASHLIB(obj) |
| 37 | #endif |
| 38 | |
Gregory P. Smith | 3f61d61 | 2009-05-04 00:45:33 +0000 | [diff] [blame] | 39 | /* EVP is the preferred interface to hashing in OpenSSL */ |
| 40 | #include <openssl/evp.h> |
| 41 | |
| 42 | #define MUNCH_SIZE INT_MAX |
| 43 | |
| 44 | /* TODO(gps): We should probably make this a module or EVPobject attribute |
| 45 | * to allow the user to optimize based on the platform they're using. */ |
| 46 | #define HASHLIB_GIL_MINSIZE 2048 |
| 47 | |
| 48 | #ifndef HASH_OBJ_CONSTRUCTOR |
| 49 | #define HASH_OBJ_CONSTRUCTOR 0 |
| 50 | #endif |
| 51 | |
Benjamin Peterson | 5e55b3e | 2010-02-03 02:35:45 +0000 | [diff] [blame] | 52 | /* Minimum OpenSSL version needed to support sha224 and higher. */ |
| 53 | #if defined(OPENSSL_VERSION_NUMBER) && (OPENSSL_VERSION_NUMBER >= 0x00908000) |
| 54 | #define _OPENSSL_SUPPORTS_SHA2 |
| 55 | #endif |
Gregory P. Smith | 3f61d61 | 2009-05-04 00:45:33 +0000 | [diff] [blame] | 56 | |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 57 | typedef struct { |
| 58 | PyObject_HEAD |
| 59 | PyObject *name; /* name of this hash algorithm */ |
Antoine Pitrou | bcd5cbe | 2009-01-08 21:17:16 +0000 | [diff] [blame] | 60 | EVP_MD_CTX ctx; /* OpenSSL message digest context */ |
| 61 | #ifdef WITH_THREAD |
| 62 | PyThread_type_lock lock; /* OpenSSL context lock */ |
| 63 | #endif |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 64 | } EVPobject; |
| 65 | |
| 66 | |
| 67 | static PyTypeObject EVPtype; |
| 68 | |
| 69 | |
| 70 | #define DEFINE_CONSTS_FOR_NEW(Name) \ |
| 71 | static PyObject *CONST_ ## Name ## _name_obj; \ |
| 72 | static EVP_MD_CTX CONST_new_ ## Name ## _ctx; \ |
| 73 | static EVP_MD_CTX *CONST_new_ ## Name ## _ctx_p = NULL; |
| 74 | |
Neal Norwitz | f045914 | 2006-01-07 21:20:24 +0000 | [diff] [blame] | 75 | DEFINE_CONSTS_FOR_NEW(md5) |
| 76 | DEFINE_CONSTS_FOR_NEW(sha1) |
Benjamin Peterson | 5e55b3e | 2010-02-03 02:35:45 +0000 | [diff] [blame] | 77 | #ifdef _OPENSSL_SUPPORTS_SHA2 |
Neal Norwitz | f045914 | 2006-01-07 21:20:24 +0000 | [diff] [blame] | 78 | DEFINE_CONSTS_FOR_NEW(sha224) |
| 79 | DEFINE_CONSTS_FOR_NEW(sha256) |
| 80 | DEFINE_CONSTS_FOR_NEW(sha384) |
| 81 | DEFINE_CONSTS_FOR_NEW(sha512) |
Benjamin Peterson | 5e55b3e | 2010-02-03 02:35:45 +0000 | [diff] [blame] | 82 | #endif |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 83 | |
| 84 | |
| 85 | static EVPobject * |
| 86 | newEVPobject(PyObject *name) |
| 87 | { |
| 88 | EVPobject *retval = (EVPobject *)PyObject_New(EVPobject, &EVPtype); |
| 89 | |
| 90 | /* save the name for .name to return */ |
| 91 | if (retval != NULL) { |
| 92 | Py_INCREF(name); |
| 93 | retval->name = name; |
Antoine Pitrou | bcd5cbe | 2009-01-08 21:17:16 +0000 | [diff] [blame] | 94 | #ifdef WITH_THREAD |
| 95 | retval->lock = NULL; |
| 96 | #endif |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | return retval; |
| 100 | } |
| 101 | |
Antoine Pitrou | bcd5cbe | 2009-01-08 21:17:16 +0000 | [diff] [blame] | 102 | static void |
| 103 | EVP_hash(EVPobject *self, const void *vp, Py_ssize_t len) |
| 104 | { |
| 105 | unsigned int process; |
| 106 | const unsigned char *cp = (const unsigned char *)vp; |
| 107 | while (0 < len) { |
| 108 | if (len > (Py_ssize_t)MUNCH_SIZE) |
| 109 | process = MUNCH_SIZE; |
| 110 | else |
| 111 | process = Py_SAFE_DOWNCAST(len, Py_ssize_t, unsigned int); |
| 112 | EVP_DigestUpdate(&self->ctx, (const void*)cp, process); |
| 113 | len -= process; |
| 114 | cp += process; |
| 115 | } |
| 116 | } |
| 117 | |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 118 | /* Internal methods for a hash object */ |
| 119 | |
| 120 | static void |
Antoine Pitrou | bcd5cbe | 2009-01-08 21:17:16 +0000 | [diff] [blame] | 121 | EVP_dealloc(EVPobject *self) |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 122 | { |
Antoine Pitrou | bcd5cbe | 2009-01-08 21:17:16 +0000 | [diff] [blame] | 123 | #ifdef WITH_THREAD |
| 124 | if (self->lock != NULL) |
| 125 | PyThread_free_lock(self->lock); |
| 126 | #endif |
| 127 | EVP_MD_CTX_cleanup(&self->ctx); |
| 128 | Py_XDECREF(self->name); |
| 129 | PyObject_Del(self); |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 130 | } |
| 131 | |
Gregory P. Smith | 3f61d61 | 2009-05-04 00:45:33 +0000 | [diff] [blame] | 132 | static void locked_EVP_MD_CTX_copy(EVP_MD_CTX *new_ctx_p, EVPobject *self) |
| 133 | { |
| 134 | ENTER_HASHLIB(self); |
| 135 | EVP_MD_CTX_copy(new_ctx_p, &self->ctx); |
| 136 | LEAVE_HASHLIB(self); |
| 137 | } |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 138 | |
| 139 | /* External methods for a hash object */ |
| 140 | |
| 141 | PyDoc_STRVAR(EVP_copy__doc__, "Return a copy of the hash object."); |
| 142 | |
Gregory P. Smith | 3f61d61 | 2009-05-04 00:45:33 +0000 | [diff] [blame] | 143 | |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 144 | static PyObject * |
Thomas Wouters | 4d70c3d | 2006-06-08 14:42:34 +0000 | [diff] [blame] | 145 | EVP_copy(EVPobject *self, PyObject *unused) |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 146 | { |
| 147 | EVPobject *newobj; |
| 148 | |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 149 | if ( (newobj = newEVPobject(self->name))==NULL) |
| 150 | return NULL; |
| 151 | |
Gregory P. Smith | 3f61d61 | 2009-05-04 00:45:33 +0000 | [diff] [blame] | 152 | locked_EVP_MD_CTX_copy(&newobj->ctx, self); |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 153 | return (PyObject *)newobj; |
| 154 | } |
| 155 | |
| 156 | PyDoc_STRVAR(EVP_digest__doc__, |
| 157 | "Return the digest value as a string of binary data."); |
| 158 | |
| 159 | static PyObject * |
Thomas Wouters | 4d70c3d | 2006-06-08 14:42:34 +0000 | [diff] [blame] | 160 | EVP_digest(EVPobject *self, PyObject *unused) |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 161 | { |
| 162 | unsigned char digest[EVP_MAX_MD_SIZE]; |
| 163 | EVP_MD_CTX temp_ctx; |
| 164 | PyObject *retval; |
| 165 | unsigned int digest_size; |
| 166 | |
Gregory P. Smith | 3f61d61 | 2009-05-04 00:45:33 +0000 | [diff] [blame] | 167 | locked_EVP_MD_CTX_copy(&temp_ctx, self); |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 168 | digest_size = EVP_MD_CTX_size(&temp_ctx); |
Neal Norwitz | f045914 | 2006-01-07 21:20:24 +0000 | [diff] [blame] | 169 | EVP_DigestFinal(&temp_ctx, digest, NULL); |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 170 | |
Christian Heimes | 72b710a | 2008-05-26 13:28:38 +0000 | [diff] [blame] | 171 | retval = PyBytes_FromStringAndSize((const char *)digest, digest_size); |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 172 | EVP_MD_CTX_cleanup(&temp_ctx); |
| 173 | return retval; |
| 174 | } |
| 175 | |
| 176 | PyDoc_STRVAR(EVP_hexdigest__doc__, |
| 177 | "Return the digest value as a string of hexadecimal digits."); |
| 178 | |
| 179 | static PyObject * |
Thomas Wouters | 4d70c3d | 2006-06-08 14:42:34 +0000 | [diff] [blame] | 180 | EVP_hexdigest(EVPobject *self, PyObject *unused) |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 181 | { |
| 182 | unsigned char digest[EVP_MAX_MD_SIZE]; |
| 183 | EVP_MD_CTX temp_ctx; |
| 184 | PyObject *retval; |
| 185 | char *hex_digest; |
| 186 | unsigned int i, j, digest_size; |
| 187 | |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 188 | /* Get the raw (binary) digest value */ |
Gregory P. Smith | 3f61d61 | 2009-05-04 00:45:33 +0000 | [diff] [blame] | 189 | locked_EVP_MD_CTX_copy(&temp_ctx, self); |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 190 | digest_size = EVP_MD_CTX_size(&temp_ctx); |
| 191 | EVP_DigestFinal(&temp_ctx, digest, NULL); |
| 192 | |
| 193 | EVP_MD_CTX_cleanup(&temp_ctx); |
| 194 | |
Guido van Rossum | f895307 | 2007-07-10 13:20:29 +0000 | [diff] [blame] | 195 | /* Allocate a new buffer */ |
| 196 | hex_digest = PyMem_Malloc(digest_size * 2 + 1); |
| 197 | if (!hex_digest) |
Antoine Pitrou | bcd5cbe | 2009-01-08 21:17:16 +0000 | [diff] [blame] | 198 | return PyErr_NoMemory(); |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 199 | |
| 200 | /* Make hex version of the digest */ |
| 201 | for(i=j=0; i<digest_size; i++) { |
| 202 | char c; |
| 203 | c = (digest[i] >> 4) & 0xf; |
Antoine Pitrou | bcd5cbe | 2009-01-08 21:17:16 +0000 | [diff] [blame] | 204 | c = (c>9) ? c+'a'-10 : c + '0'; |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 205 | hex_digest[j++] = c; |
| 206 | c = (digest[i] & 0xf); |
Antoine Pitrou | bcd5cbe | 2009-01-08 21:17:16 +0000 | [diff] [blame] | 207 | c = (c>9) ? c+'a'-10 : c + '0'; |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 208 | hex_digest[j++] = c; |
| 209 | } |
Guido van Rossum | f895307 | 2007-07-10 13:20:29 +0000 | [diff] [blame] | 210 | retval = PyUnicode_FromStringAndSize(hex_digest, digest_size * 2); |
| 211 | PyMem_Free(hex_digest); |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 212 | return retval; |
| 213 | } |
| 214 | |
| 215 | PyDoc_STRVAR(EVP_update__doc__, |
| 216 | "Update this hash object's state with the provided string."); |
| 217 | |
| 218 | static PyObject * |
| 219 | EVP_update(EVPobject *self, PyObject *args) |
| 220 | { |
Gregory P. Smith | 9406f5c | 2007-08-26 02:58:36 +0000 | [diff] [blame] | 221 | PyObject *obj; |
Travis E. Oliphant | 8ae62b6 | 2007-09-23 02:00:13 +0000 | [diff] [blame] | 222 | Py_buffer view; |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 223 | |
Gregory P. Smith | 9406f5c | 2007-08-26 02:58:36 +0000 | [diff] [blame] | 224 | if (!PyArg_ParseTuple(args, "O:update", &obj)) |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 225 | return NULL; |
| 226 | |
Gregory P. Smith | 365a186 | 2009-02-12 07:35:29 +0000 | [diff] [blame] | 227 | GET_BUFFER_VIEW_OR_ERROUT(obj, &view); |
Antoine Pitrou | bcd5cbe | 2009-01-08 21:17:16 +0000 | [diff] [blame] | 228 | |
| 229 | #ifdef WITH_THREAD |
| 230 | if (self->lock == NULL && view.len >= HASHLIB_GIL_MINSIZE) { |
| 231 | self->lock = PyThread_allocate_lock(); |
Gregory P. Smith | 3f61d61 | 2009-05-04 00:45:33 +0000 | [diff] [blame] | 232 | /* fail? lock = NULL and we fail over to non-threaded code. */ |
Benjamin Peterson | 78cb491 | 2008-09-24 22:53:33 +0000 | [diff] [blame] | 233 | } |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 234 | |
Antoine Pitrou | bcd5cbe | 2009-01-08 21:17:16 +0000 | [diff] [blame] | 235 | if (self->lock != NULL) { |
| 236 | Py_BEGIN_ALLOW_THREADS |
| 237 | PyThread_acquire_lock(self->lock, 1); |
| 238 | EVP_hash(self, view.buf, view.len); |
| 239 | PyThread_release_lock(self->lock); |
| 240 | Py_END_ALLOW_THREADS |
| 241 | } else { |
| 242 | EVP_hash(self, view.buf, view.len); |
| 243 | } |
| 244 | #else |
| 245 | EVP_hash(self, view.buf, view.len); |
| 246 | #endif |
| 247 | |
| 248 | PyBuffer_Release(&view); |
| 249 | Py_RETURN_NONE; |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | static PyMethodDef EVP_methods[] = { |
Antoine Pitrou | bcd5cbe | 2009-01-08 21:17:16 +0000 | [diff] [blame] | 253 | {"update", (PyCFunction)EVP_update, METH_VARARGS, EVP_update__doc__}, |
| 254 | {"digest", (PyCFunction)EVP_digest, METH_NOARGS, EVP_digest__doc__}, |
Thomas Wouters | 4d70c3d | 2006-06-08 14:42:34 +0000 | [diff] [blame] | 255 | {"hexdigest", (PyCFunction)EVP_hexdigest, METH_NOARGS, EVP_hexdigest__doc__}, |
Antoine Pitrou | bcd5cbe | 2009-01-08 21:17:16 +0000 | [diff] [blame] | 256 | {"copy", (PyCFunction)EVP_copy, METH_NOARGS, EVP_copy__doc__}, |
| 257 | {NULL, NULL} /* sentinel */ |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 258 | }; |
| 259 | |
| 260 | static PyObject * |
| 261 | EVP_get_block_size(EVPobject *self, void *closure) |
| 262 | { |
Antoine Pitrou | bcd5cbe | 2009-01-08 21:17:16 +0000 | [diff] [blame] | 263 | long block_size; |
Antoine Pitrou | bcd5cbe | 2009-01-08 21:17:16 +0000 | [diff] [blame] | 264 | block_size = EVP_MD_CTX_block_size(&self->ctx); |
Antoine Pitrou | bcd5cbe | 2009-01-08 21:17:16 +0000 | [diff] [blame] | 265 | return PyLong_FromLong(block_size); |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | static PyObject * |
| 269 | EVP_get_digest_size(EVPobject *self, void *closure) |
| 270 | { |
Antoine Pitrou | bcd5cbe | 2009-01-08 21:17:16 +0000 | [diff] [blame] | 271 | long size; |
Antoine Pitrou | bcd5cbe | 2009-01-08 21:17:16 +0000 | [diff] [blame] | 272 | size = EVP_MD_CTX_size(&self->ctx); |
Antoine Pitrou | bcd5cbe | 2009-01-08 21:17:16 +0000 | [diff] [blame] | 273 | return PyLong_FromLong(size); |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | static PyMemberDef EVP_members[] = { |
| 277 | {"name", T_OBJECT, offsetof(EVPobject, name), READONLY, PyDoc_STR("algorithm name.")}, |
| 278 | {NULL} /* Sentinel */ |
| 279 | }; |
| 280 | |
| 281 | static PyGetSetDef EVP_getseters[] = { |
| 282 | {"digest_size", |
| 283 | (getter)EVP_get_digest_size, NULL, |
| 284 | NULL, |
| 285 | NULL}, |
| 286 | {"block_size", |
| 287 | (getter)EVP_get_block_size, NULL, |
| 288 | NULL, |
| 289 | NULL}, |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 290 | {NULL} /* Sentinel */ |
| 291 | }; |
| 292 | |
| 293 | |
| 294 | static PyObject * |
Antoine Pitrou | bcd5cbe | 2009-01-08 21:17:16 +0000 | [diff] [blame] | 295 | EVP_repr(EVPobject *self) |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 296 | { |
Victor Stinner | 3f1af5c | 2010-03-12 17:00:41 +0000 | [diff] [blame] | 297 | return PyUnicode_FromFormat("<%U HASH object @ %p>", self->name, self); |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | #if HASH_OBJ_CONSTRUCTOR |
| 301 | static int |
| 302 | EVP_tp_init(EVPobject *self, PyObject *args, PyObject *kwds) |
| 303 | { |
Martin v. Löwis | 15e6274 | 2006-02-27 16:46:16 +0000 | [diff] [blame] | 304 | static char *kwlist[] = {"name", "string", NULL}; |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 305 | PyObject *name_obj = NULL; |
Gregory P. Smith | 9406f5c | 2007-08-26 02:58:36 +0000 | [diff] [blame] | 306 | PyObject *data_obj = NULL; |
Travis E. Oliphant | 8ae62b6 | 2007-09-23 02:00:13 +0000 | [diff] [blame] | 307 | Py_buffer view; |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 308 | char *nameStr; |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 309 | const EVP_MD *digest; |
| 310 | |
Gregory P. Smith | 9406f5c | 2007-08-26 02:58:36 +0000 | [diff] [blame] | 311 | if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O:HASH", kwlist, |
| 312 | &name_obj, &data_obj)) { |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 313 | return -1; |
| 314 | } |
| 315 | |
Gregory P. Smith | 9406f5c | 2007-08-26 02:58:36 +0000 | [diff] [blame] | 316 | if (data_obj) |
Gregory P. Smith | 365a186 | 2009-02-12 07:35:29 +0000 | [diff] [blame] | 317 | GET_BUFFER_VIEW_OR_ERROUT(data_obj, &view); |
Gregory P. Smith | 9406f5c | 2007-08-26 02:58:36 +0000 | [diff] [blame] | 318 | |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 319 | if (!PyArg_Parse(name_obj, "s", &nameStr)) { |
| 320 | PyErr_SetString(PyExc_TypeError, "name must be a string"); |
Gregory P. Smith | 9406f5c | 2007-08-26 02:58:36 +0000 | [diff] [blame] | 321 | if (data_obj) |
Martin v. Löwis | 423be95 | 2008-08-13 15:53:07 +0000 | [diff] [blame] | 322 | PyBuffer_Release(&view); |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 323 | return -1; |
| 324 | } |
| 325 | |
| 326 | digest = EVP_get_digestbyname(nameStr); |
| 327 | if (!digest) { |
| 328 | PyErr_SetString(PyExc_ValueError, "unknown hash function"); |
Gregory P. Smith | 9406f5c | 2007-08-26 02:58:36 +0000 | [diff] [blame] | 329 | if (data_obj) |
Martin v. Löwis | 423be95 | 2008-08-13 15:53:07 +0000 | [diff] [blame] | 330 | PyBuffer_Release(&view); |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 331 | return -1; |
| 332 | } |
| 333 | EVP_DigestInit(&self->ctx, digest); |
| 334 | |
| 335 | self->name = name_obj; |
| 336 | Py_INCREF(self->name); |
| 337 | |
Gregory P. Smith | 9406f5c | 2007-08-26 02:58:36 +0000 | [diff] [blame] | 338 | if (data_obj) { |
Antoine Pitrou | bcd5cbe | 2009-01-08 21:17:16 +0000 | [diff] [blame] | 339 | if (view.len >= HASHLIB_GIL_MINSIZE) { |
| 340 | Py_BEGIN_ALLOW_THREADS |
| 341 | EVP_hash(self, view.buf, view.len); |
| 342 | Py_END_ALLOW_THREADS |
Benjamin Peterson | 78cb491 | 2008-09-24 22:53:33 +0000 | [diff] [blame] | 343 | } else { |
Antoine Pitrou | bcd5cbe | 2009-01-08 21:17:16 +0000 | [diff] [blame] | 344 | EVP_hash(self, view.buf, view.len); |
Benjamin Peterson | 78cb491 | 2008-09-24 22:53:33 +0000 | [diff] [blame] | 345 | } |
Martin v. Löwis | 423be95 | 2008-08-13 15:53:07 +0000 | [diff] [blame] | 346 | PyBuffer_Release(&view); |
Gregory P. Smith | 9406f5c | 2007-08-26 02:58:36 +0000 | [diff] [blame] | 347 | } |
Antoine Pitrou | bcd5cbe | 2009-01-08 21:17:16 +0000 | [diff] [blame] | 348 | |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 349 | return 0; |
| 350 | } |
| 351 | #endif |
| 352 | |
| 353 | |
| 354 | PyDoc_STRVAR(hashtype_doc, |
| 355 | "A hash represents the object used to calculate a checksum of a\n\ |
| 356 | string of information.\n\ |
| 357 | \n\ |
| 358 | Methods:\n\ |
| 359 | \n\ |
| 360 | update() -- updates the current digest with an additional string\n\ |
| 361 | digest() -- return the current digest value\n\ |
| 362 | hexdigest() -- return the current digest as a string of hexadecimal digits\n\ |
| 363 | copy() -- return a copy of the current hash object\n\ |
| 364 | \n\ |
| 365 | Attributes:\n\ |
| 366 | \n\ |
| 367 | name -- the hash algorithm being used by this object\n\ |
| 368 | digest_size -- number of bytes in this hashes output\n"); |
| 369 | |
| 370 | static PyTypeObject EVPtype = { |
Martin v. Löwis | 9f2e346 | 2007-07-21 17:22:18 +0000 | [diff] [blame] | 371 | PyVarObject_HEAD_INIT(NULL, 0) |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 372 | "_hashlib.HASH", /*tp_name*/ |
Antoine Pitrou | bcd5cbe | 2009-01-08 21:17:16 +0000 | [diff] [blame] | 373 | sizeof(EVPobject), /*tp_basicsize*/ |
| 374 | 0, /*tp_itemsize*/ |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 375 | /* methods */ |
Antoine Pitrou | bcd5cbe | 2009-01-08 21:17:16 +0000 | [diff] [blame] | 376 | (destructor)EVP_dealloc, /*tp_dealloc*/ |
| 377 | 0, /*tp_print*/ |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 378 | 0, /*tp_getattr*/ |
| 379 | 0, /*tp_setattr*/ |
Mark Dickinson | e94c679 | 2009-02-02 20:36:42 +0000 | [diff] [blame] | 380 | 0, /*tp_reserved*/ |
Antoine Pitrou | bcd5cbe | 2009-01-08 21:17:16 +0000 | [diff] [blame] | 381 | (reprfunc)EVP_repr, /*tp_repr*/ |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 382 | 0, /*tp_as_number*/ |
| 383 | 0, /*tp_as_sequence*/ |
| 384 | 0, /*tp_as_mapping*/ |
| 385 | 0, /*tp_hash*/ |
| 386 | 0, /*tp_call*/ |
| 387 | 0, /*tp_str*/ |
| 388 | 0, /*tp_getattro*/ |
| 389 | 0, /*tp_setattro*/ |
| 390 | 0, /*tp_as_buffer*/ |
| 391 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ |
| 392 | hashtype_doc, /*tp_doc*/ |
| 393 | 0, /*tp_traverse*/ |
Antoine Pitrou | bcd5cbe | 2009-01-08 21:17:16 +0000 | [diff] [blame] | 394 | 0, /*tp_clear*/ |
| 395 | 0, /*tp_richcompare*/ |
| 396 | 0, /*tp_weaklistoffset*/ |
| 397 | 0, /*tp_iter*/ |
| 398 | 0, /*tp_iternext*/ |
| 399 | EVP_methods, /* tp_methods */ |
| 400 | EVP_members, /* tp_members */ |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 401 | EVP_getseters, /* tp_getset */ |
| 402 | #if 1 |
| 403 | 0, /* tp_base */ |
| 404 | 0, /* tp_dict */ |
| 405 | 0, /* tp_descr_get */ |
| 406 | 0, /* tp_descr_set */ |
| 407 | 0, /* tp_dictoffset */ |
| 408 | #endif |
| 409 | #if HASH_OBJ_CONSTRUCTOR |
| 410 | (initproc)EVP_tp_init, /* tp_init */ |
| 411 | #endif |
| 412 | }; |
| 413 | |
| 414 | static PyObject * |
| 415 | EVPnew(PyObject *name_obj, |
| 416 | const EVP_MD *digest, const EVP_MD_CTX *initial_ctx, |
Benjamin Peterson | 78cb491 | 2008-09-24 22:53:33 +0000 | [diff] [blame] | 417 | const unsigned char *cp, Py_ssize_t len) |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 418 | { |
| 419 | EVPobject *self; |
| 420 | |
| 421 | if (!digest && !initial_ctx) { |
| 422 | PyErr_SetString(PyExc_ValueError, "unsupported hash type"); |
| 423 | return NULL; |
| 424 | } |
| 425 | |
| 426 | if ((self = newEVPobject(name_obj)) == NULL) |
| 427 | return NULL; |
| 428 | |
| 429 | if (initial_ctx) { |
| 430 | EVP_MD_CTX_copy(&self->ctx, initial_ctx); |
| 431 | } else { |
| 432 | EVP_DigestInit(&self->ctx, digest); |
| 433 | } |
| 434 | |
Benjamin Peterson | 78cb491 | 2008-09-24 22:53:33 +0000 | [diff] [blame] | 435 | if (cp && len) { |
Antoine Pitrou | bcd5cbe | 2009-01-08 21:17:16 +0000 | [diff] [blame] | 436 | if (len >= HASHLIB_GIL_MINSIZE) { |
| 437 | Py_BEGIN_ALLOW_THREADS |
| 438 | EVP_hash(self, cp, len); |
| 439 | Py_END_ALLOW_THREADS |
Benjamin Peterson | 78cb491 | 2008-09-24 22:53:33 +0000 | [diff] [blame] | 440 | } else { |
Antoine Pitrou | bcd5cbe | 2009-01-08 21:17:16 +0000 | [diff] [blame] | 441 | EVP_hash(self, cp, len); |
Benjamin Peterson | 78cb491 | 2008-09-24 22:53:33 +0000 | [diff] [blame] | 442 | } |
| 443 | } |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 444 | |
| 445 | return (PyObject *)self; |
| 446 | } |
| 447 | |
| 448 | |
| 449 | /* The module-level function: new() */ |
| 450 | |
| 451 | PyDoc_STRVAR(EVP_new__doc__, |
| 452 | "Return a new hash object using the named algorithm.\n\ |
| 453 | An optional string argument may be provided and will be\n\ |
| 454 | automatically hashed.\n\ |
| 455 | \n\ |
| 456 | The MD5 and SHA1 algorithms are always supported.\n"); |
| 457 | |
| 458 | static PyObject * |
| 459 | EVP_new(PyObject *self, PyObject *args, PyObject *kwdict) |
| 460 | { |
Martin v. Löwis | 15e6274 | 2006-02-27 16:46:16 +0000 | [diff] [blame] | 461 | static char *kwlist[] = {"name", "string", NULL}; |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 462 | PyObject *name_obj = NULL; |
Gregory P. Smith | 9406f5c | 2007-08-26 02:58:36 +0000 | [diff] [blame] | 463 | PyObject *data_obj = NULL; |
Travis E. Oliphant | 8ae62b6 | 2007-09-23 02:00:13 +0000 | [diff] [blame] | 464 | Py_buffer view = { 0 }; |
Gregory P. Smith | 9406f5c | 2007-08-26 02:58:36 +0000 | [diff] [blame] | 465 | PyObject *ret_obj; |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 466 | char *name; |
| 467 | const EVP_MD *digest; |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 468 | |
Gregory P. Smith | 9406f5c | 2007-08-26 02:58:36 +0000 | [diff] [blame] | 469 | if (!PyArg_ParseTupleAndKeywords(args, kwdict, "O|O:new", kwlist, |
| 470 | &name_obj, &data_obj)) { |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 471 | return NULL; |
| 472 | } |
| 473 | |
| 474 | if (!PyArg_Parse(name_obj, "s", &name)) { |
| 475 | PyErr_SetString(PyExc_TypeError, "name must be a string"); |
| 476 | return NULL; |
| 477 | } |
| 478 | |
Gregory P. Smith | 9406f5c | 2007-08-26 02:58:36 +0000 | [diff] [blame] | 479 | if (data_obj) |
Gregory P. Smith | 365a186 | 2009-02-12 07:35:29 +0000 | [diff] [blame] | 480 | GET_BUFFER_VIEW_OR_ERROUT(data_obj, &view); |
Gregory P. Smith | 9406f5c | 2007-08-26 02:58:36 +0000 | [diff] [blame] | 481 | |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 482 | digest = EVP_get_digestbyname(name); |
| 483 | |
Benjamin Peterson | 78cb491 | 2008-09-24 22:53:33 +0000 | [diff] [blame] | 484 | ret_obj = EVPnew(name_obj, digest, NULL, (unsigned char*)view.buf, view.len); |
Gregory P. Smith | 9406f5c | 2007-08-26 02:58:36 +0000 | [diff] [blame] | 485 | |
| 486 | if (data_obj) |
Martin v. Löwis | 423be95 | 2008-08-13 15:53:07 +0000 | [diff] [blame] | 487 | PyBuffer_Release(&view); |
Gregory P. Smith | 9406f5c | 2007-08-26 02:58:36 +0000 | [diff] [blame] | 488 | return ret_obj; |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | /* |
| 492 | * This macro generates constructor function definitions for specific |
| 493 | * hash algorithms. These constructors are much faster than calling |
| 494 | * the generic one passing it a python string and are noticably |
| 495 | * faster than calling a python new() wrapper. Thats important for |
| 496 | * code that wants to make hashes of a bunch of small strings. |
| 497 | */ |
| 498 | #define GEN_CONSTRUCTOR(NAME) \ |
| 499 | static PyObject * \ |
| 500 | EVP_new_ ## NAME (PyObject *self, PyObject *args) \ |
| 501 | { \ |
Gregory P. Smith | 9406f5c | 2007-08-26 02:58:36 +0000 | [diff] [blame] | 502 | PyObject *data_obj = NULL; \ |
Travis E. Oliphant | 8ae62b6 | 2007-09-23 02:00:13 +0000 | [diff] [blame] | 503 | Py_buffer view = { 0 }; \ |
Gregory P. Smith | 9406f5c | 2007-08-26 02:58:36 +0000 | [diff] [blame] | 504 | PyObject *ret_obj; \ |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 505 | \ |
Gregory P. Smith | 9406f5c | 2007-08-26 02:58:36 +0000 | [diff] [blame] | 506 | if (!PyArg_ParseTuple(args, "|O:" #NAME , &data_obj)) { \ |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 507 | return NULL; \ |
| 508 | } \ |
| 509 | \ |
Gregory P. Smith | 9406f5c | 2007-08-26 02:58:36 +0000 | [diff] [blame] | 510 | if (data_obj) \ |
Gregory P. Smith | 365a186 | 2009-02-12 07:35:29 +0000 | [diff] [blame] | 511 | GET_BUFFER_VIEW_OR_ERROUT(data_obj, &view); \ |
Gregory P. Smith | 9406f5c | 2007-08-26 02:58:36 +0000 | [diff] [blame] | 512 | \ |
| 513 | ret_obj = EVPnew( \ |
| 514 | CONST_ ## NAME ## _name_obj, \ |
| 515 | NULL, \ |
| 516 | CONST_new_ ## NAME ## _ctx_p, \ |
| 517 | (unsigned char*)view.buf, \ |
Benjamin Peterson | 78cb491 | 2008-09-24 22:53:33 +0000 | [diff] [blame] | 518 | view.len); \ |
Gregory P. Smith | 9406f5c | 2007-08-26 02:58:36 +0000 | [diff] [blame] | 519 | \ |
| 520 | if (data_obj) \ |
Martin v. Löwis | 423be95 | 2008-08-13 15:53:07 +0000 | [diff] [blame] | 521 | PyBuffer_Release(&view); \ |
Gregory P. Smith | 9406f5c | 2007-08-26 02:58:36 +0000 | [diff] [blame] | 522 | return ret_obj; \ |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | /* a PyMethodDef structure for the constructor */ |
| 526 | #define CONSTRUCTOR_METH_DEF(NAME) \ |
| 527 | {"openssl_" #NAME, (PyCFunction)EVP_new_ ## NAME, METH_VARARGS, \ |
| 528 | PyDoc_STR("Returns a " #NAME \ |
| 529 | " hash object; optionally initialized with a string") \ |
| 530 | } |
| 531 | |
| 532 | /* used in the init function to setup a constructor */ |
| 533 | #define INIT_CONSTRUCTOR_CONSTANTS(NAME) do { \ |
Neal Norwitz | d6d2f2f | 2007-08-23 20:28:10 +0000 | [diff] [blame] | 534 | CONST_ ## NAME ## _name_obj = PyUnicode_FromString(#NAME); \ |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 535 | if (EVP_get_digestbyname(#NAME)) { \ |
| 536 | CONST_new_ ## NAME ## _ctx_p = &CONST_new_ ## NAME ## _ctx; \ |
| 537 | EVP_DigestInit(CONST_new_ ## NAME ## _ctx_p, EVP_get_digestbyname(#NAME)); \ |
| 538 | } \ |
| 539 | } while (0); |
| 540 | |
| 541 | GEN_CONSTRUCTOR(md5) |
| 542 | GEN_CONSTRUCTOR(sha1) |
Benjamin Peterson | 5e55b3e | 2010-02-03 02:35:45 +0000 | [diff] [blame] | 543 | #ifdef _OPENSSL_SUPPORTS_SHA2 |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 544 | GEN_CONSTRUCTOR(sha224) |
| 545 | GEN_CONSTRUCTOR(sha256) |
| 546 | GEN_CONSTRUCTOR(sha384) |
| 547 | GEN_CONSTRUCTOR(sha512) |
Benjamin Peterson | 5e55b3e | 2010-02-03 02:35:45 +0000 | [diff] [blame] | 548 | #endif |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 549 | |
| 550 | /* List of functions exported by this module */ |
| 551 | |
| 552 | static struct PyMethodDef EVP_functions[] = { |
| 553 | {"new", (PyCFunction)EVP_new, METH_VARARGS|METH_KEYWORDS, EVP_new__doc__}, |
| 554 | CONSTRUCTOR_METH_DEF(md5), |
| 555 | CONSTRUCTOR_METH_DEF(sha1), |
Benjamin Peterson | 5e55b3e | 2010-02-03 02:35:45 +0000 | [diff] [blame] | 556 | #ifdef _OPENSSL_SUPPORTS_SHA2 |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 557 | CONSTRUCTOR_METH_DEF(sha224), |
| 558 | CONSTRUCTOR_METH_DEF(sha256), |
| 559 | CONSTRUCTOR_METH_DEF(sha384), |
| 560 | CONSTRUCTOR_METH_DEF(sha512), |
Benjamin Peterson | 5e55b3e | 2010-02-03 02:35:45 +0000 | [diff] [blame] | 561 | #endif |
Alexander Belopolsky | f0f4514 | 2010-08-11 17:31:17 +0000 | [diff] [blame] | 562 | {NULL, NULL} /* Sentinel */ |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 563 | }; |
| 564 | |
| 565 | |
| 566 | /* Initialize this module. */ |
| 567 | |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 568 | |
| 569 | static struct PyModuleDef _hashlibmodule = { |
Antoine Pitrou | bcd5cbe | 2009-01-08 21:17:16 +0000 | [diff] [blame] | 570 | PyModuleDef_HEAD_INIT, |
| 571 | "_hashlib", |
| 572 | NULL, |
| 573 | -1, |
| 574 | EVP_functions, |
| 575 | NULL, |
| 576 | NULL, |
| 577 | NULL, |
| 578 | NULL |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 579 | }; |
| 580 | |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 581 | PyMODINIT_FUNC |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 582 | PyInit__hashlib(void) |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 583 | { |
| 584 | PyObject *m; |
| 585 | |
| 586 | OpenSSL_add_all_digests(); |
| 587 | |
| 588 | /* TODO build EVP_functions openssl_* entries dynamically based |
| 589 | * on what hashes are supported rather than listing many |
| 590 | * but having some be unsupported. Only init appropriate |
| 591 | * constants. */ |
| 592 | |
Christian Heimes | 90aa764 | 2007-12-19 02:45:37 +0000 | [diff] [blame] | 593 | Py_TYPE(&EVPtype) = &PyType_Type; |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 594 | if (PyType_Ready(&EVPtype) < 0) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 595 | return NULL; |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 596 | |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 597 | m = PyModule_Create(&_hashlibmodule); |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 598 | if (m == NULL) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 599 | return NULL; |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 600 | |
| 601 | #if HASH_OBJ_CONSTRUCTOR |
| 602 | Py_INCREF(&EVPtype); |
| 603 | PyModule_AddObject(m, "HASH", (PyObject *)&EVPtype); |
| 604 | #endif |
| 605 | |
| 606 | /* these constants are used by the convenience constructors */ |
| 607 | INIT_CONSTRUCTOR_CONSTANTS(md5); |
| 608 | INIT_CONSTRUCTOR_CONSTANTS(sha1); |
Benjamin Peterson | 5e55b3e | 2010-02-03 02:35:45 +0000 | [diff] [blame] | 609 | #ifdef _OPENSSL_SUPPORTS_SHA2 |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 610 | INIT_CONSTRUCTOR_CONSTANTS(sha224); |
| 611 | INIT_CONSTRUCTOR_CONSTANTS(sha256); |
| 612 | INIT_CONSTRUCTOR_CONSTANTS(sha384); |
| 613 | INIT_CONSTRUCTOR_CONSTANTS(sha512); |
Benjamin Peterson | 5e55b3e | 2010-02-03 02:35:45 +0000 | [diff] [blame] | 614 | #endif |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 615 | return m; |
Gregory P. Smith | f21a5f7 | 2005-08-21 18:45:59 +0000 | [diff] [blame] | 616 | } |