Mercurial > cpython-lru_cache-weakref
annotate Modules/md5module.c @ 74135:9c19df6c8ea0 3.2
News entry for Issue12798
| author | Senthil Kumaran <senthil@uthcode.com> |
|---|---|
| date | Fri, 23 Dec 2011 11:11:21 +0800 |
| parents | 3bf4d9f1660a |
| children | 43fd627cc060 |
| rev | line source |
|---|---|
|
43294
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
1 /* MD5 module */ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
2 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
3 /* This module provides an interface to the MD5 algorithm */ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
4 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
5 /* See below for information about the original code this module was |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
6 based upon. Additional work performed by: |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
7 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
8 Andrew Kuchling (amk@amk.ca) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
9 Greg Stein (gstein@lyra.org) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
10 Trevor Perrin (trevp@trevp.net) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
11 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
12 Copyright (C) 2005-2007 Gregory P. Smith (greg@krypto.org) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
13 Licensed to PSF under a Contributor Agreement. |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
14 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
15 */ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
16 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
17 /* MD5 objects */ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
18 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
19 #include "Python.h" |
|
51574
ce29faed7f69
- Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
51271
diff
changeset
|
20 #include "hashlib.h" |
|
43294
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
21 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
22 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
23 /* Some useful types */ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
24 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
25 #if SIZEOF_INT == 4 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51969
diff
changeset
|
26 typedef unsigned int MD5_INT32; /* 32-bit integer */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51969
diff
changeset
|
27 typedef PY_LONG_LONG MD5_INT64; /* 64-bit integer */ |
|
43294
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
28 #else |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
29 /* not defined. compilation will die. */ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
30 #endif |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
31 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
32 /* The MD5 block size and message digest sizes, in bytes */ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
33 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
34 #define MD5_BLOCKSIZE 64 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
35 #define MD5_DIGESTSIZE 16 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
36 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
37 /* The structure for storing MD5 info */ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
38 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
39 struct md5_state { |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
40 MD5_INT64 length; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
41 MD5_INT32 state[4], curlen; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
42 unsigned char buf[MD5_BLOCKSIZE]; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
43 }; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
44 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
45 typedef struct { |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
46 PyObject_HEAD |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
47 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
48 struct md5_state hash_state; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
49 } MD5object; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
50 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
51 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
52 /* ------------------------------------------------------------------------ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
53 * |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
54 * This code for the MD5 algorithm was noted as public domain. The |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
55 * original headers are pasted below. |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
56 * |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
57 * Several changes have been made to make it more compatible with the |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
58 * Python environment and desired interface. |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
59 * |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
60 */ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
61 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
62 /* LibTomCrypt, modular cryptographic library -- Tom St Denis |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
63 * |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
64 * LibTomCrypt is a library that provides various cryptographic |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
65 * algorithms in a highly modular and flexible manner. |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
66 * |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
67 * The library is free for all purposes without any express |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
68 * guarantee it works. |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
69 * |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
70 * Tom St Denis, tomstdenis@gmail.com, http://libtom.org |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
71 */ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
72 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
73 /* rotate the hard way (platform optimizations could be done) */ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
74 #define ROLc(x, y) ( (((unsigned long)(x)<<(unsigned long)((y)&31)) | (((unsigned long)(x)&0xFFFFFFFFUL)>>(unsigned long)(32-((y)&31)))) & 0xFFFFFFFFUL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
75 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
76 /* Endian Neutral macros that work on all platforms */ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
77 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
78 #define STORE32L(x, y) \ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
79 { (y)[3] = (unsigned char)(((x)>>24)&255); (y)[2] = (unsigned char)(((x)>>16)&255); \ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
80 (y)[1] = (unsigned char)(((x)>>8)&255); (y)[0] = (unsigned char)((x)&255); } |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
81 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
82 #define LOAD32L(x, y) \ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
83 { x = ((unsigned long)((y)[3] & 255)<<24) | \ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
84 ((unsigned long)((y)[2] & 255)<<16) | \ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
85 ((unsigned long)((y)[1] & 255)<<8) | \ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
86 ((unsigned long)((y)[0] & 255)); } |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
87 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
88 #define STORE64L(x, y) \ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
89 { (y)[7] = (unsigned char)(((x)>>56)&255); (y)[6] = (unsigned char)(((x)>>48)&255); \ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
90 (y)[5] = (unsigned char)(((x)>>40)&255); (y)[4] = (unsigned char)(((x)>>32)&255); \ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
91 (y)[3] = (unsigned char)(((x)>>24)&255); (y)[2] = (unsigned char)(((x)>>16)&255); \ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
92 (y)[1] = (unsigned char)(((x)>>8)&255); (y)[0] = (unsigned char)((x)&255); } |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
93 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
94 #ifndef MIN |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
95 #define MIN(x, y) ( ((x)<(y))?(x):(y) ) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
96 #endif |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
97 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
98 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
99 /* MD5 macros */ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
100 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
101 #define F(x,y,z) (z ^ (x & (y ^ z))) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
102 #define G(x,y,z) (y ^ (z & (y ^ x))) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
103 #define H(x,y,z) (x^y^z) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
104 #define I(x,y,z) (y^(x|(~z))) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
105 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
106 #define FF(a,b,c,d,M,s,t) \ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
107 a = (a + F(b,c,d) + M + t); a = ROLc(a, s) + b; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
108 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
109 #define GG(a,b,c,d,M,s,t) \ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
110 a = (a + G(b,c,d) + M + t); a = ROLc(a, s) + b; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
111 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
112 #define HH(a,b,c,d,M,s,t) \ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
113 a = (a + H(b,c,d) + M + t); a = ROLc(a, s) + b; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
114 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
115 #define II(a,b,c,d,M,s,t) \ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
116 a = (a + I(b,c,d) + M + t); a = ROLc(a, s) + b; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
117 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
118 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
119 static void md5_compress(struct md5_state *md5, unsigned char *buf) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
120 { |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
121 MD5_INT32 i, W[16], a, b, c, d; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
122 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
123 assert(md5 != NULL); |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
124 assert(buf != NULL); |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
125 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
126 /* copy the state into 512-bits into W[0..15] */ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
127 for (i = 0; i < 16; i++) { |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
128 LOAD32L(W[i], buf + (4*i)); |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
129 } |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51969
diff
changeset
|
130 |
|
43294
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
131 /* copy state */ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
132 a = md5->state[0]; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
133 b = md5->state[1]; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
134 c = md5->state[2]; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
135 d = md5->state[3]; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
136 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
137 FF(a,b,c,d,W[0],7,0xd76aa478UL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
138 FF(d,a,b,c,W[1],12,0xe8c7b756UL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
139 FF(c,d,a,b,W[2],17,0x242070dbUL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
140 FF(b,c,d,a,W[3],22,0xc1bdceeeUL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
141 FF(a,b,c,d,W[4],7,0xf57c0fafUL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
142 FF(d,a,b,c,W[5],12,0x4787c62aUL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
143 FF(c,d,a,b,W[6],17,0xa8304613UL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
144 FF(b,c,d,a,W[7],22,0xfd469501UL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
145 FF(a,b,c,d,W[8],7,0x698098d8UL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
146 FF(d,a,b,c,W[9],12,0x8b44f7afUL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
147 FF(c,d,a,b,W[10],17,0xffff5bb1UL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
148 FF(b,c,d,a,W[11],22,0x895cd7beUL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
149 FF(a,b,c,d,W[12],7,0x6b901122UL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
150 FF(d,a,b,c,W[13],12,0xfd987193UL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
151 FF(c,d,a,b,W[14],17,0xa679438eUL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
152 FF(b,c,d,a,W[15],22,0x49b40821UL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
153 GG(a,b,c,d,W[1],5,0xf61e2562UL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
154 GG(d,a,b,c,W[6],9,0xc040b340UL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
155 GG(c,d,a,b,W[11],14,0x265e5a51UL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
156 GG(b,c,d,a,W[0],20,0xe9b6c7aaUL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
157 GG(a,b,c,d,W[5],5,0xd62f105dUL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
158 GG(d,a,b,c,W[10],9,0x02441453UL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
159 GG(c,d,a,b,W[15],14,0xd8a1e681UL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
160 GG(b,c,d,a,W[4],20,0xe7d3fbc8UL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
161 GG(a,b,c,d,W[9],5,0x21e1cde6UL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
162 GG(d,a,b,c,W[14],9,0xc33707d6UL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
163 GG(c,d,a,b,W[3],14,0xf4d50d87UL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
164 GG(b,c,d,a,W[8],20,0x455a14edUL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
165 GG(a,b,c,d,W[13],5,0xa9e3e905UL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
166 GG(d,a,b,c,W[2],9,0xfcefa3f8UL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
167 GG(c,d,a,b,W[7],14,0x676f02d9UL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
168 GG(b,c,d,a,W[12],20,0x8d2a4c8aUL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
169 HH(a,b,c,d,W[5],4,0xfffa3942UL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
170 HH(d,a,b,c,W[8],11,0x8771f681UL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
171 HH(c,d,a,b,W[11],16,0x6d9d6122UL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
172 HH(b,c,d,a,W[14],23,0xfde5380cUL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
173 HH(a,b,c,d,W[1],4,0xa4beea44UL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
174 HH(d,a,b,c,W[4],11,0x4bdecfa9UL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
175 HH(c,d,a,b,W[7],16,0xf6bb4b60UL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
176 HH(b,c,d,a,W[10],23,0xbebfbc70UL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
177 HH(a,b,c,d,W[13],4,0x289b7ec6UL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
178 HH(d,a,b,c,W[0],11,0xeaa127faUL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
179 HH(c,d,a,b,W[3],16,0xd4ef3085UL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
180 HH(b,c,d,a,W[6],23,0x04881d05UL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
181 HH(a,b,c,d,W[9],4,0xd9d4d039UL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
182 HH(d,a,b,c,W[12],11,0xe6db99e5UL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
183 HH(c,d,a,b,W[15],16,0x1fa27cf8UL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
184 HH(b,c,d,a,W[2],23,0xc4ac5665UL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
185 II(a,b,c,d,W[0],6,0xf4292244UL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
186 II(d,a,b,c,W[7],10,0x432aff97UL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
187 II(c,d,a,b,W[14],15,0xab9423a7UL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
188 II(b,c,d,a,W[5],21,0xfc93a039UL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
189 II(a,b,c,d,W[12],6,0x655b59c3UL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
190 II(d,a,b,c,W[3],10,0x8f0ccc92UL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
191 II(c,d,a,b,W[10],15,0xffeff47dUL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
192 II(b,c,d,a,W[1],21,0x85845dd1UL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
193 II(a,b,c,d,W[8],6,0x6fa87e4fUL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
194 II(d,a,b,c,W[15],10,0xfe2ce6e0UL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
195 II(c,d,a,b,W[6],15,0xa3014314UL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
196 II(b,c,d,a,W[13],21,0x4e0811a1UL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
197 II(a,b,c,d,W[4],6,0xf7537e82UL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
198 II(d,a,b,c,W[11],10,0xbd3af235UL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
199 II(c,d,a,b,W[2],15,0x2ad7d2bbUL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
200 II(b,c,d,a,W[9],21,0xeb86d391UL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
201 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
202 md5->state[0] = md5->state[0] + a; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
203 md5->state[1] = md5->state[1] + b; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
204 md5->state[2] = md5->state[2] + c; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
205 md5->state[3] = md5->state[3] + d; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
206 } |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
207 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
208 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
209 /** |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
210 Initialize the hash state |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
211 @param sha1 The hash state you wish to initialize |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
212 */ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
213 void md5_init(struct md5_state *md5) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
214 { |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
215 assert(md5 != NULL); |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
216 md5->state[0] = 0x67452301UL; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
217 md5->state[1] = 0xefcdab89UL; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
218 md5->state[2] = 0x98badcfeUL; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
219 md5->state[3] = 0x10325476UL; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
220 md5->curlen = 0; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
221 md5->length = 0; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
222 } |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
223 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
224 /** |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
225 Process a block of memory though the hash |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
226 @param sha1 The hash state |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
227 @param in The data to hash |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
228 @param inlen The length of the data (octets) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
229 */ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
230 void md5_process(struct md5_state *md5, |
|
67347
3bf4d9f1660a
Issue #9566: use Py_ssize_t instead of int
Victor Stinner <victor.stinner@haypocalc.com>
parents:
61466
diff
changeset
|
231 const unsigned char *in, Py_ssize_t inlen) |
|
43294
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
232 { |
|
67347
3bf4d9f1660a
Issue #9566: use Py_ssize_t instead of int
Victor Stinner <victor.stinner@haypocalc.com>
parents:
61466
diff
changeset
|
233 Py_ssize_t n; |
|
43294
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
234 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
235 assert(md5 != NULL); |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
236 assert(in != NULL); |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
237 assert(md5->curlen <= sizeof(md5->buf)); |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
238 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
239 while (inlen > 0) { |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
240 if (md5->curlen == 0 && inlen >= MD5_BLOCKSIZE) { |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
241 md5_compress(md5, (unsigned char *)in); |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
242 md5->length += MD5_BLOCKSIZE * 8; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
243 in += MD5_BLOCKSIZE; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
244 inlen -= MD5_BLOCKSIZE; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
245 } else { |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
246 n = MIN(inlen, (MD5_BLOCKSIZE - md5->curlen)); |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
247 memcpy(md5->buf + md5->curlen, in, (size_t)n); |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
248 md5->curlen += n; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
249 in += n; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
250 inlen -= n; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
251 if (md5->curlen == MD5_BLOCKSIZE) { |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
252 md5_compress(md5, md5->buf); |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
253 md5->length += 8*MD5_BLOCKSIZE; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
254 md5->curlen = 0; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
255 } |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
256 } |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
257 } |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
258 } |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
259 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
260 /** |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
261 Terminate the hash to get the digest |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
262 @param sha1 The hash state |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
263 @param out [out] The destination of the hash (16 bytes) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
264 */ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
265 void md5_done(struct md5_state *md5, unsigned char *out) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
266 { |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
267 int i; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
268 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
269 assert(md5 != NULL); |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
270 assert(out != NULL); |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
271 assert(md5->curlen < sizeof(md5->buf)); |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
272 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
273 /* increase the length of the message */ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
274 md5->length += md5->curlen * 8; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
275 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
276 /* append the '1' bit */ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
277 md5->buf[md5->curlen++] = (unsigned char)0x80; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
278 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
279 /* if the length is currently above 56 bytes we append zeros |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
280 * then compress. Then we can fall back to padding zeros and length |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
281 * encoding like normal. |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
282 */ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
283 if (md5->curlen > 56) { |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
284 while (md5->curlen < 64) { |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
285 md5->buf[md5->curlen++] = (unsigned char)0; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
286 } |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
287 md5_compress(md5, md5->buf); |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
288 md5->curlen = 0; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
289 } |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
290 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
291 /* pad upto 56 bytes of zeroes */ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
292 while (md5->curlen < 56) { |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
293 md5->buf[md5->curlen++] = (unsigned char)0; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
294 } |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
295 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
296 /* store length */ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
297 STORE64L(md5->length, md5->buf+56); |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
298 md5_compress(md5, md5->buf); |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
299 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
300 /* copy output */ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
301 for (i = 0; i < 4; i++) { |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
302 STORE32L(md5->state[i], out+(4*i)); |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
303 } |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
304 } |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
305 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
306 /* .Source: /cvs/libtom/libtomcrypt/src/hashes/md5.c,v $ */ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
307 /* .Revision: 1.10 $ */ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
308 /* .Date: 2007/05/12 14:25:28 $ */ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
309 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
310 /* |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
311 * End of copied MD5 code. |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
312 * |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
313 * ------------------------------------------------------------------------ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
314 */ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
315 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
316 static PyTypeObject MD5type; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
317 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
318 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
319 static MD5object * |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
320 newMD5object(void) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
321 { |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
322 return (MD5object *)PyObject_New(MD5object, &MD5type); |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
323 } |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
324 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
325 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
326 /* Internal methods for a hash object */ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
327 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
328 static void |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
329 MD5_dealloc(PyObject *ptr) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
330 { |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
331 PyObject_Del(ptr); |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
332 } |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
333 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
334 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
335 /* External methods for a hash object */ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
336 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
337 PyDoc_STRVAR(MD5_copy__doc__, "Return a copy of the hash object."); |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
338 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
339 static PyObject * |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
340 MD5_copy(MD5object *self, PyObject *unused) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
341 { |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
342 MD5object *newobj; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
343 |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
344 if (Py_TYPE(self) == &MD5type) { |
|
43294
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
345 if ( (newobj = newMD5object())==NULL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
346 return NULL; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
347 } else { |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
348 if ( (newobj = newMD5object())==NULL) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
349 return NULL; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
350 } |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
351 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
352 newobj->hash_state = self->hash_state; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
353 return (PyObject *)newobj; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
354 } |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
355 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
356 PyDoc_STRVAR(MD5_digest__doc__, |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
357 "Return the digest value as a string of binary data."); |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
358 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
359 static PyObject * |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
360 MD5_digest(MD5object *self, PyObject *unused) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
361 { |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
362 unsigned char digest[MD5_DIGESTSIZE]; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
363 struct md5_state temp; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
364 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
365 temp = self->hash_state; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
366 md5_done(&temp, digest); |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
367 return PyBytes_FromStringAndSize((const char *)digest, MD5_DIGESTSIZE); |
|
43294
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
368 } |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
369 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
370 PyDoc_STRVAR(MD5_hexdigest__doc__, |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
371 "Return the digest value as a string of hexadecimal digits."); |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
372 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
373 static PyObject * |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
374 MD5_hexdigest(MD5object *self, PyObject *unused) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
375 { |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
376 unsigned char digest[MD5_DIGESTSIZE]; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
377 struct md5_state temp; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
378 PyObject *retval; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
379 Py_UNICODE *hex_digest; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
380 int i, j; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
381 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
382 /* Get the raw (binary) digest value */ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
383 temp = self->hash_state; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
384 md5_done(&temp, digest); |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
385 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
386 /* Create a new string */ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
387 retval = PyUnicode_FromStringAndSize(NULL, MD5_DIGESTSIZE * 2); |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
388 if (!retval) |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51969
diff
changeset
|
389 return NULL; |
|
43294
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
390 hex_digest = PyUnicode_AS_UNICODE(retval); |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
391 if (!hex_digest) { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51969
diff
changeset
|
392 Py_DECREF(retval); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51969
diff
changeset
|
393 return NULL; |
|
43294
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
394 } |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
395 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
396 /* Make hex version of the digest */ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
397 for(i=j=0; i<MD5_DIGESTSIZE; i++) { |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
398 char c; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
399 c = (digest[i] >> 4) & 0xf; |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51969
diff
changeset
|
400 c = (c>9) ? c+'a'-10 : c + '0'; |
|
43294
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
401 hex_digest[j++] = c; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
402 c = (digest[i] & 0xf); |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51969
diff
changeset
|
403 c = (c>9) ? c+'a'-10 : c + '0'; |
|
43294
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
404 hex_digest[j++] = c; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
405 } |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
406 return retval; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
407 } |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
408 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
409 PyDoc_STRVAR(MD5_update__doc__, |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
410 "Update this hash object's state with the provided string."); |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
411 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
412 static PyObject * |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
413 MD5_update(MD5object *self, PyObject *args) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
414 { |
|
51574
ce29faed7f69
- Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
51271
diff
changeset
|
415 PyObject *obj; |
|
48691
ade33e13ec69
Use s* to receive data. Fixes #3552.
Martin v. Löwis <martin@v.loewis.de>
parents:
47581
diff
changeset
|
416 Py_buffer buf; |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51969
diff
changeset
|
417 |
|
51574
ce29faed7f69
- Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
51271
diff
changeset
|
418 if (!PyArg_ParseTuple(args, "O:update", &obj)) |
|
43294
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
419 return NULL; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
420 |
|
51574
ce29faed7f69
- Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
51271
diff
changeset
|
421 GET_BUFFER_VIEW_OR_ERROUT(obj, &buf); |
|
ce29faed7f69
- Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
51271
diff
changeset
|
422 |
|
48691
ade33e13ec69
Use s* to receive data. Fixes #3552.
Martin v. Löwis <martin@v.loewis.de>
parents:
47581
diff
changeset
|
423 md5_process(&self->hash_state, buf.buf, buf.len); |
|
43294
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
424 |
|
48691
ade33e13ec69
Use s* to receive data. Fixes #3552.
Martin v. Löwis <martin@v.loewis.de>
parents:
47581
diff
changeset
|
425 PyBuffer_Release(&buf); |
|
43294
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
426 Py_INCREF(Py_None); |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
427 return Py_None; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
428 } |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
429 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
430 static PyMethodDef MD5_methods[] = { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51969
diff
changeset
|
431 {"copy", (PyCFunction)MD5_copy, METH_NOARGS, MD5_copy__doc__}, |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51969
diff
changeset
|
432 {"digest", (PyCFunction)MD5_digest, METH_NOARGS, MD5_digest__doc__}, |
|
43294
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
433 {"hexdigest", (PyCFunction)MD5_hexdigest, METH_NOARGS, MD5_hexdigest__doc__}, |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51969
diff
changeset
|
434 {"update", (PyCFunction)MD5_update, METH_VARARGS, MD5_update__doc__}, |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51969
diff
changeset
|
435 {NULL, NULL} /* sentinel */ |
|
43294
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
436 }; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
437 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
438 static PyObject * |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
439 MD5_get_block_size(PyObject *self, void *closure) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
440 { |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
441 return PyLong_FromLong(MD5_BLOCKSIZE); |
|
43294
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
442 } |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
443 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
444 static PyObject * |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
445 MD5_get_name(PyObject *self, void *closure) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
446 { |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
447 return PyUnicode_FromStringAndSize("MD5", 3); |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
448 } |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
449 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
450 static PyObject * |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
451 md5_get_digest_size(PyObject *self, void *closure) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
452 { |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
453 return PyLong_FromLong(MD5_DIGESTSIZE); |
|
43294
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
454 } |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
455 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
456 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
457 static PyGetSetDef MD5_getseters[] = { |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
458 {"block_size", |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
459 (getter)MD5_get_block_size, NULL, |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
460 NULL, |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
461 NULL}, |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
462 {"name", |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
463 (getter)MD5_get_name, NULL, |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
464 NULL, |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
465 NULL}, |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
466 {"digest_size", |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
467 (getter)md5_get_digest_size, NULL, |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
468 NULL, |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
469 NULL}, |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
470 {NULL} /* Sentinel */ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
471 }; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
472 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
473 static PyTypeObject MD5type = { |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
474 PyVarObject_HEAD_INIT(NULL, 0) |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51969
diff
changeset
|
475 "_md5.md5", /*tp_name*/ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51969
diff
changeset
|
476 sizeof(MD5object), /*tp_size*/ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51969
diff
changeset
|
477 0, /*tp_itemsize*/ |
|
43294
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
478 /* methods */ |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51969
diff
changeset
|
479 MD5_dealloc, /*tp_dealloc*/ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51969
diff
changeset
|
480 0, /*tp_print*/ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51969
diff
changeset
|
481 0, /*tp_getattr*/ |
|
43294
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
482 0, /*tp_setattr*/ |
|
51271
87fbbf22adf3
Merged revisions 69214 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
48691
diff
changeset
|
483 0, /*tp_reserved*/ |
|
43294
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
484 0, /*tp_repr*/ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
485 0, /*tp_as_number*/ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
486 0, /*tp_as_sequence*/ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
487 0, /*tp_as_mapping*/ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
488 0, /*tp_hash*/ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
489 0, /*tp_call*/ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
490 0, /*tp_str*/ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
491 0, /*tp_getattro*/ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
492 0, /*tp_setattro*/ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
493 0, /*tp_as_buffer*/ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
494 Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
495 0, /*tp_doc*/ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
496 0, /*tp_traverse*/ |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51969
diff
changeset
|
497 0, /*tp_clear*/ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51969
diff
changeset
|
498 0, /*tp_richcompare*/ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51969
diff
changeset
|
499 0, /*tp_weaklistoffset*/ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51969
diff
changeset
|
500 0, /*tp_iter*/ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51969
diff
changeset
|
501 0, /*tp_iternext*/ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51969
diff
changeset
|
502 MD5_methods, /* tp_methods */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51969
diff
changeset
|
503 NULL, /* tp_members */ |
|
43294
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
504 MD5_getseters, /* tp_getset */ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
505 }; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
506 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
507 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
508 /* The single module-level function: new() */ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
509 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
510 PyDoc_STRVAR(MD5_new__doc__, |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
511 "Return a new MD5 hash object; optionally initialized with a string."); |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
512 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
513 static PyObject * |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
514 MD5_new(PyObject *self, PyObject *args, PyObject *kwdict) |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
515 { |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
516 static char *kwlist[] = {"string", NULL}; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
517 MD5object *new; |
|
51574
ce29faed7f69
- Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
51271
diff
changeset
|
518 PyObject *data_obj = NULL; |
|
48691
ade33e13ec69
Use s* to receive data. Fixes #3552.
Martin v. Löwis <martin@v.loewis.de>
parents:
47581
diff
changeset
|
519 Py_buffer buf; |
|
43294
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
520 |
|
51574
ce29faed7f69
- Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
51271
diff
changeset
|
521 if (!PyArg_ParseTupleAndKeywords(args, kwdict, "|O:new", kwlist, |
|
ce29faed7f69
- Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
51271
diff
changeset
|
522 &data_obj)) { |
|
43294
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
523 return NULL; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
524 } |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
525 |
|
51574
ce29faed7f69
- Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
51271
diff
changeset
|
526 if (data_obj) |
|
ce29faed7f69
- Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
51271
diff
changeset
|
527 GET_BUFFER_VIEW_OR_ERROUT(data_obj, &buf); |
|
ce29faed7f69
- Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
51271
diff
changeset
|
528 |
|
51969
e8af4e24f08f
Fixed memory leak on failure. This is related to issue5403 but won't crash on py3k.
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents:
51574
diff
changeset
|
529 if ((new = newMD5object()) == NULL) { |
|
e8af4e24f08f
Fixed memory leak on failure. This is related to issue5403 but won't crash on py3k.
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents:
51574
diff
changeset
|
530 if (data_obj) |
|
e8af4e24f08f
Fixed memory leak on failure. This is related to issue5403 but won't crash on py3k.
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents:
51574
diff
changeset
|
531 PyBuffer_Release(&buf); |
|
43294
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
532 return NULL; |
|
51969
e8af4e24f08f
Fixed memory leak on failure. This is related to issue5403 but won't crash on py3k.
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents:
51574
diff
changeset
|
533 } |
|
43294
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
534 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
535 md5_init(&new->hash_state); |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
536 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
537 if (PyErr_Occurred()) { |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
538 Py_DECREF(new); |
|
51969
e8af4e24f08f
Fixed memory leak on failure. This is related to issue5403 but won't crash on py3k.
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents:
51574
diff
changeset
|
539 if (data_obj) |
|
e8af4e24f08f
Fixed memory leak on failure. This is related to issue5403 but won't crash on py3k.
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents:
51574
diff
changeset
|
540 PyBuffer_Release(&buf); |
|
43294
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
541 return NULL; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
542 } |
|
51574
ce29faed7f69
- Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents:
51271
diff
changeset
|
543 if (data_obj) { |
|
48691
ade33e13ec69
Use s* to receive data. Fixes #3552.
Martin v. Löwis <martin@v.loewis.de>
parents:
47581
diff
changeset
|
544 md5_process(&new->hash_state, buf.buf, buf.len); |
|
51969
e8af4e24f08f
Fixed memory leak on failure. This is related to issue5403 but won't crash on py3k.
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents:
51574
diff
changeset
|
545 PyBuffer_Release(&buf); |
|
48691
ade33e13ec69
Use s* to receive data. Fixes #3552.
Martin v. Löwis <martin@v.loewis.de>
parents:
47581
diff
changeset
|
546 } |
|
43294
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
547 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
548 return (PyObject *)new; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
549 } |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
550 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
551 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
552 /* List of functions exported by this module */ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
553 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
554 static struct PyMethodDef MD5_functions[] = { |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
555 {"md5", (PyCFunction)MD5_new, METH_VARARGS|METH_KEYWORDS, MD5_new__doc__}, |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51969
diff
changeset
|
556 {NULL, NULL} /* Sentinel */ |
|
43294
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
557 }; |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
558 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
559 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
560 /* Initialize this module. */ |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
561 |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
562 #define insint(n,v) { PyModule_AddIntConstant(m,n,v); } |
|
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
563 |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
564 |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
565 static struct PyModuleDef _md5module = { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51969
diff
changeset
|
566 PyModuleDef_HEAD_INIT, |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51969
diff
changeset
|
567 "_md5", |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51969
diff
changeset
|
568 NULL, |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51969
diff
changeset
|
569 -1, |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51969
diff
changeset
|
570 MD5_functions, |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51969
diff
changeset
|
571 NULL, |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51969
diff
changeset
|
572 NULL, |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51969
diff
changeset
|
573 NULL, |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51969
diff
changeset
|
574 NULL |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
575 }; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
576 |
|
43294
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
577 PyMODINIT_FUNC |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
578 PyInit__md5(void) |
|
43294
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
579 { |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
580 Py_TYPE(&MD5type) = &PyType_Type; |
|
43294
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
581 if (PyType_Ready(&MD5type) < 0) |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
582 return NULL; |
|
47581
2511431519a2
Fix module initialization glitches.
Martin v. Löwis <martin@v.loewis.de>
parents:
47580
diff
changeset
|
583 return PyModule_Create(&_md5module); |
|
43294
78f1c329c983
Adds stand alone _md5 and _sha1 modules for use by hashlib on systems
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
584 } |
