summaryrefslogtreecommitdiffstats
path: root/Modules/md5module.c
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/md5module.c')
-rw-r--r--Modules/md5module.c31
1 files changed, 14 insertions, 17 deletions
diff --git a/Modules/md5module.c b/Modules/md5module.c
index 208930d..e2681a8 100644
--- a/Modules/md5module.c
+++ b/Modules/md5module.c
@@ -210,7 +210,8 @@ static void md5_compress(struct md5_state *md5, unsigned char *buf)
Initialize the hash state
@param sha1 The hash state you wish to initialize
*/
-void md5_init(struct md5_state *md5)
+static void
+md5_init(struct md5_state *md5)
{
assert(md5 != NULL);
md5->state[0] = 0x67452301UL;
@@ -227,8 +228,8 @@ void md5_init(struct md5_state *md5)
@param in The data to hash
@param inlen The length of the data (octets)
*/
-void md5_process(struct md5_state *md5,
- const unsigned char *in, Py_ssize_t inlen)
+static void
+md5_process(struct md5_state *md5, const unsigned char *in, Py_ssize_t inlen)
{
Py_ssize_t n;
@@ -243,7 +244,7 @@ void md5_process(struct md5_state *md5,
in += MD5_BLOCKSIZE;
inlen -= MD5_BLOCKSIZE;
} else {
- n = MIN(inlen, (MD5_BLOCKSIZE - md5->curlen));
+ n = MIN(inlen, (Py_ssize_t)(MD5_BLOCKSIZE - md5->curlen));
memcpy(md5->buf + md5->curlen, in, (size_t)n);
md5->curlen += n;
in += n;
@@ -262,7 +263,8 @@ void md5_process(struct md5_state *md5,
@param sha1 The hash state
@param out [out] The destination of the hash (16 bytes)
*/
-void md5_done(struct md5_state *md5, unsigned char *out)
+static void
+md5_done(struct md5_state *md5, unsigned char *out)
{
int i;
@@ -376,7 +378,7 @@ MD5_hexdigest(MD5object *self, PyObject *unused)
unsigned char digest[MD5_DIGESTSIZE];
struct md5_state temp;
PyObject *retval;
- Py_UNICODE *hex_digest;
+ Py_UCS1 *hex_digest;
int i, j;
/* Get the raw (binary) digest value */
@@ -384,25 +386,20 @@ MD5_hexdigest(MD5object *self, PyObject *unused)
md5_done(&temp, digest);
/* Create a new string */
- retval = PyUnicode_FromStringAndSize(NULL, MD5_DIGESTSIZE * 2);
+ retval = PyUnicode_New(MD5_DIGESTSIZE * 2, 127);
if (!retval)
return NULL;
- hex_digest = PyUnicode_AS_UNICODE(retval);
- if (!hex_digest) {
- Py_DECREF(retval);
- return NULL;
- }
+ hex_digest = PyUnicode_1BYTE_DATA(retval);
/* Make hex version of the digest */
for(i=j=0; i<MD5_DIGESTSIZE; i++) {
- char c;
+ unsigned char c;
c = (digest[i] >> 4) & 0xf;
- c = (c>9) ? c+'a'-10 : c + '0';
- hex_digest[j++] = c;
+ hex_digest[j++] = Py_hexdigits[c];
c = (digest[i] & 0xf);
- c = (c>9) ? c+'a'-10 : c + '0';
- hex_digest[j++] = c;
+ hex_digest[j++] = Py_hexdigits[c];
}
+ assert(_PyUnicode_CheckConsistency(retval, 1));
return retval;
}