annotate Modules/sha512module.c @ 80661:94de77bd0b4b 2.7

Issue #16194: document imp.load_dynamic problems when read several extension modules from the same binary object file.
author Andrew Svetlov <andrew.svetlov@gmail.com>
date Thu, 29 Nov 2012 19:51:28 +0200
parents b36cb4602e21
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
1 /* SHA512 module */
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
2
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
3 /* This module provides an interface to NIST's SHA-512 and SHA-384 Algorithms */
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
4
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
5 /* See below for information about the original code this module was
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
6 based upon. Additional work performed by:
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
7
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
8 Andrew Kuchling (amk@amk.ca)
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
9 Greg Stein (gstein@lyra.org)
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
10 Trevor Perrin (trevp@trevp.net)
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
11
43298
a11b4885b445 email address update
Gregory P. Smith <greg@mad-scientist.com>
parents: 42333
diff changeset
12 Copyright (C) 2005 Gregory P. Smith (greg@krypto.org)
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
13 Licensed to PSF under a Contributor Agreement.
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
14
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
15 */
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
16
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
17 /* SHA objects */
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
18
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
19 #include "Python.h"
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
20 #include "structmember.h"
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
21
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
22 #ifdef PY_LONG_LONG /* If no PY_LONG_LONG, don't compile anything! */
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
23
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
24 /* Endianness testing and definitions */
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
25 #define TestEndianness(variable) {int i=1; variable=PCT_BIG_ENDIAN;\
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
26 if (*((char*)&i)==1) variable=PCT_LITTLE_ENDIAN;}
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
27
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
28 #define PCT_LITTLE_ENDIAN 1
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
29 #define PCT_BIG_ENDIAN 0
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
30
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
31 /* Some useful types */
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
32
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
33 typedef unsigned char SHA_BYTE;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
34
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
35 #if SIZEOF_INT == 4
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
36 typedef unsigned int SHA_INT32; /* 32-bit integer */
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
37 typedef unsigned PY_LONG_LONG SHA_INT64; /* 64-bit integer */
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
38 #else
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
39 /* not defined. compilation will die. */
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
40 #endif
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
41
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
42 /* The SHA block size and message digest sizes, in bytes */
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
43
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
44 #define SHA_BLOCKSIZE 128
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
45 #define SHA_DIGESTSIZE 64
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
46
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
47 /* The structure for storing SHA info */
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
48
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
49 typedef struct {
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
50 PyObject_HEAD
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
51 SHA_INT64 digest[8]; /* Message digest */
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
52 SHA_INT32 count_lo, count_hi; /* 64-bit bit count */
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
53 SHA_BYTE data[SHA_BLOCKSIZE]; /* SHA data buffer */
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
54 int Endianness;
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
55 int local; /* unprocessed amount in data */
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
56 int digestsize;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
57 } SHAobject;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
58
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
59 /* When run on a little-endian CPU we need to perform byte reversal on an
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
60 array of longwords. */
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
61
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
62 static void longReverse(SHA_INT64 *buffer, int byteCount, int Endianness)
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
63 {
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
64 SHA_INT64 value;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
65
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
66 if ( Endianness == PCT_BIG_ENDIAN )
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
67 return;
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
68
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
69 byteCount /= sizeof(*buffer);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
70 while (byteCount--) {
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
71 value = *buffer;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
72
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
73 ((unsigned char*)buffer)[0] = (unsigned char)(value >> 56) & 0xff;
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
74 ((unsigned char*)buffer)[1] = (unsigned char)(value >> 48) & 0xff;
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
75 ((unsigned char*)buffer)[2] = (unsigned char)(value >> 40) & 0xff;
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
76 ((unsigned char*)buffer)[3] = (unsigned char)(value >> 32) & 0xff;
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
77 ((unsigned char*)buffer)[4] = (unsigned char)(value >> 24) & 0xff;
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
78 ((unsigned char*)buffer)[5] = (unsigned char)(value >> 16) & 0xff;
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
79 ((unsigned char*)buffer)[6] = (unsigned char)(value >> 8) & 0xff;
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
80 ((unsigned char*)buffer)[7] = (unsigned char)(value ) & 0xff;
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
81
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
82 buffer++;
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
83 }
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
84 }
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
85
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
86 static void SHAcopy(SHAobject *src, SHAobject *dest)
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
87 {
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
88 dest->Endianness = src->Endianness;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
89 dest->local = src->local;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
90 dest->digestsize = src->digestsize;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
91 dest->count_lo = src->count_lo;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
92 dest->count_hi = src->count_hi;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
93 memcpy(dest->digest, src->digest, sizeof(src->digest));
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
94 memcpy(dest->data, src->data, sizeof(src->data));
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
95 }
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
96
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
97
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
98 /* ------------------------------------------------------------------------
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
99 *
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
100 * This code for the SHA-512 algorithm was noted as public domain. The
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
101 * original headers are pasted below.
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
102 *
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
103 * Several changes have been made to make it more compatible with the
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
104 * Python environment and desired interface.
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
105 *
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
106 */
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
107
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
108 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
109 *
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
110 * LibTomCrypt is a library that provides various cryptographic
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
111 * algorithms in a highly modular and flexible manner.
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
112 *
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
113 * The library is free for all purposes without any express
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
114 * gurantee it works.
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
115 *
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
116 * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
117 */
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
118
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
119
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
120 /* SHA512 by Tom St Denis */
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
121
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
122 /* Various logical functions */
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
123 #define ROR64(x, y) \
38232
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
124 ( ((((x) & Py_ULL(0xFFFFFFFFFFFFFFFF))>>((unsigned PY_LONG_LONG)(y) & 63)) | \
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
125 ((x)<<((unsigned PY_LONG_LONG)(64-((y) & 63))))) & Py_ULL(0xFFFFFFFFFFFFFFFF))
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
126 #define Ch(x,y,z) (z ^ (x & (y ^ z)))
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
127 #define Maj(x,y,z) (((x | y) & z) | (x & y))
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
128 #define S(x, n) ROR64((x),(n))
38232
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
129 #define R(x, n) (((x) & Py_ULL(0xFFFFFFFFFFFFFFFF)) >> ((unsigned PY_LONG_LONG)n))
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
130 #define Sigma0(x) (S(x, 28) ^ S(x, 34) ^ S(x, 39))
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
131 #define Sigma1(x) (S(x, 14) ^ S(x, 18) ^ S(x, 41))
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
132 #define Gamma0(x) (S(x, 1) ^ S(x, 8) ^ R(x, 7))
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
133 #define Gamma1(x) (S(x, 19) ^ S(x, 61) ^ R(x, 6))
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
134
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
135
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
136 static void
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
137 sha512_transform(SHAobject *sha_info)
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
138 {
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
139 int i;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
140 SHA_INT64 S[8], W[80], t0, t1;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
141
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
142 memcpy(W, sha_info->data, sizeof(sha_info->data));
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
143 longReverse(W, (int)sizeof(sha_info->data), sha_info->Endianness);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
144
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
145 for (i = 16; i < 80; ++i) {
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
146 W[i] = Gamma1(W[i - 2]) + W[i - 7] + Gamma0(W[i - 15]) + W[i - 16];
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
147 }
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
148 for (i = 0; i < 8; ++i) {
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
149 S[i] = sha_info->digest[i];
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
150 }
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
151
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
152 /* Compress */
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
153 #define RND(a,b,c,d,e,f,g,h,i,ki) \
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
154 t0 = h + Sigma1(e) + Ch(e, f, g) + ki + W[i]; \
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
155 t1 = Sigma0(a) + Maj(a, b, c); \
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
156 d += t0; \
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
157 h = t0 + t1;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
158
38232
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
159 RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],0,Py_ULL(0x428a2f98d728ae22));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
160 RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],1,Py_ULL(0x7137449123ef65cd));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
161 RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],2,Py_ULL(0xb5c0fbcfec4d3b2f));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
162 RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],3,Py_ULL(0xe9b5dba58189dbbc));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
163 RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],4,Py_ULL(0x3956c25bf348b538));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
164 RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],5,Py_ULL(0x59f111f1b605d019));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
165 RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],6,Py_ULL(0x923f82a4af194f9b));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
166 RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],7,Py_ULL(0xab1c5ed5da6d8118));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
167 RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],8,Py_ULL(0xd807aa98a3030242));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
168 RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],9,Py_ULL(0x12835b0145706fbe));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
169 RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],10,Py_ULL(0x243185be4ee4b28c));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
170 RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],11,Py_ULL(0x550c7dc3d5ffb4e2));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
171 RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],12,Py_ULL(0x72be5d74f27b896f));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
172 RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],13,Py_ULL(0x80deb1fe3b1696b1));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
173 RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],14,Py_ULL(0x9bdc06a725c71235));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
174 RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],15,Py_ULL(0xc19bf174cf692694));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
175 RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],16,Py_ULL(0xe49b69c19ef14ad2));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
176 RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],17,Py_ULL(0xefbe4786384f25e3));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
177 RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],18,Py_ULL(0x0fc19dc68b8cd5b5));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
178 RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],19,Py_ULL(0x240ca1cc77ac9c65));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
179 RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],20,Py_ULL(0x2de92c6f592b0275));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
180 RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],21,Py_ULL(0x4a7484aa6ea6e483));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
181 RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],22,Py_ULL(0x5cb0a9dcbd41fbd4));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
182 RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],23,Py_ULL(0x76f988da831153b5));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
183 RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],24,Py_ULL(0x983e5152ee66dfab));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
184 RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],25,Py_ULL(0xa831c66d2db43210));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
185 RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],26,Py_ULL(0xb00327c898fb213f));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
186 RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],27,Py_ULL(0xbf597fc7beef0ee4));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
187 RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],28,Py_ULL(0xc6e00bf33da88fc2));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
188 RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],29,Py_ULL(0xd5a79147930aa725));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
189 RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],30,Py_ULL(0x06ca6351e003826f));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
190 RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],31,Py_ULL(0x142929670a0e6e70));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
191 RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],32,Py_ULL(0x27b70a8546d22ffc));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
192 RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],33,Py_ULL(0x2e1b21385c26c926));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
193 RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],34,Py_ULL(0x4d2c6dfc5ac42aed));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
194 RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],35,Py_ULL(0x53380d139d95b3df));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
195 RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],36,Py_ULL(0x650a73548baf63de));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
196 RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],37,Py_ULL(0x766a0abb3c77b2a8));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
197 RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],38,Py_ULL(0x81c2c92e47edaee6));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
198 RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],39,Py_ULL(0x92722c851482353b));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
199 RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],40,Py_ULL(0xa2bfe8a14cf10364));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
200 RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],41,Py_ULL(0xa81a664bbc423001));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
201 RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],42,Py_ULL(0xc24b8b70d0f89791));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
202 RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],43,Py_ULL(0xc76c51a30654be30));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
203 RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],44,Py_ULL(0xd192e819d6ef5218));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
204 RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],45,Py_ULL(0xd69906245565a910));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
205 RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],46,Py_ULL(0xf40e35855771202a));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
206 RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],47,Py_ULL(0x106aa07032bbd1b8));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
207 RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],48,Py_ULL(0x19a4c116b8d2d0c8));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
208 RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],49,Py_ULL(0x1e376c085141ab53));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
209 RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],50,Py_ULL(0x2748774cdf8eeb99));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
210 RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],51,Py_ULL(0x34b0bcb5e19b48a8));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
211 RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],52,Py_ULL(0x391c0cb3c5c95a63));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
212 RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],53,Py_ULL(0x4ed8aa4ae3418acb));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
213 RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],54,Py_ULL(0x5b9cca4f7763e373));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
214 RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],55,Py_ULL(0x682e6ff3d6b2b8a3));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
215 RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],56,Py_ULL(0x748f82ee5defb2fc));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
216 RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],57,Py_ULL(0x78a5636f43172f60));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
217 RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],58,Py_ULL(0x84c87814a1f0ab72));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
218 RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],59,Py_ULL(0x8cc702081a6439ec));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
219 RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],60,Py_ULL(0x90befffa23631e28));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
220 RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],61,Py_ULL(0xa4506cebde82bde9));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
221 RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],62,Py_ULL(0xbef9a3f7b2c67915));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
222 RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],63,Py_ULL(0xc67178f2e372532b));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
223 RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],64,Py_ULL(0xca273eceea26619c));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
224 RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],65,Py_ULL(0xd186b8c721c0c207));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
225 RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],66,Py_ULL(0xeada7dd6cde0eb1e));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
226 RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],67,Py_ULL(0xf57d4f7fee6ed178));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
227 RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],68,Py_ULL(0x06f067aa72176fba));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
228 RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],69,Py_ULL(0x0a637dc5a2c898a6));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
229 RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],70,Py_ULL(0x113f9804bef90dae));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
230 RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],71,Py_ULL(0x1b710b35131c471b));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
231 RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],72,Py_ULL(0x28db77f523047d84));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
232 RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],73,Py_ULL(0x32caab7b40c72493));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
233 RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],74,Py_ULL(0x3c9ebe0a15c9bebc));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
234 RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],75,Py_ULL(0x431d67c49c100d4c));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
235 RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],76,Py_ULL(0x4cc5d4becb3e42b6));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
236 RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],77,Py_ULL(0x597f299cfc657e2a));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
237 RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],78,Py_ULL(0x5fcb6fab3ad6faec));
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
238 RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],79,Py_ULL(0x6c44198c4a475817));
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
239
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
240 #undef RND
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
241
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
242 /* feedback */
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
243 for (i = 0; i < 8; i++) {
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
244 sha_info->digest[i] = sha_info->digest[i] + S[i];
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
245 }
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
246
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
247 }
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
248
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
249
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
250
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
251 /* initialize the SHA digest */
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
252
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
253 static void
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
254 sha512_init(SHAobject *sha_info)
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
255 {
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
256 TestEndianness(sha_info->Endianness)
38232
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
257 sha_info->digest[0] = Py_ULL(0x6a09e667f3bcc908);
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
258 sha_info->digest[1] = Py_ULL(0xbb67ae8584caa73b);
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
259 sha_info->digest[2] = Py_ULL(0x3c6ef372fe94f82b);
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
260 sha_info->digest[3] = Py_ULL(0xa54ff53a5f1d36f1);
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
261 sha_info->digest[4] = Py_ULL(0x510e527fade682d1);
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
262 sha_info->digest[5] = Py_ULL(0x9b05688c2b3e6c1f);
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
263 sha_info->digest[6] = Py_ULL(0x1f83d9abfb41bd6b);
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
264 sha_info->digest[7] = Py_ULL(0x5be0cd19137e2179);
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
265 sha_info->count_lo = 0L;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
266 sha_info->count_hi = 0L;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
267 sha_info->local = 0;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
268 sha_info->digestsize = 64;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
269 }
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
270
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
271 static void
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
272 sha384_init(SHAobject *sha_info)
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
273 {
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
274 TestEndianness(sha_info->Endianness)
38232
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
275 sha_info->digest[0] = Py_ULL(0xcbbb9d5dc1059ed8);
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
276 sha_info->digest[1] = Py_ULL(0x629a292a367cd507);
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
277 sha_info->digest[2] = Py_ULL(0x9159015a3070dd17);
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
278 sha_info->digest[3] = Py_ULL(0x152fecd8f70e5939);
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
279 sha_info->digest[4] = Py_ULL(0x67332667ffc00b31);
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
280 sha_info->digest[5] = Py_ULL(0x8eb44a8768581511);
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
281 sha_info->digest[6] = Py_ULL(0xdb0c2e0d64f98fa7);
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 36675
diff changeset
282 sha_info->digest[7] = Py_ULL(0x47b5481dbefa4fa4);
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
283 sha_info->count_lo = 0L;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
284 sha_info->count_hi = 0L;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
285 sha_info->local = 0;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
286 sha_info->digestsize = 48;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
287 }
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
288
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
289
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
290 /* update the SHA digest */
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
291
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
292 static void
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
293 sha512_update(SHAobject *sha_info, SHA_BYTE *buffer, int count)
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
294 {
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
295 int i;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
296 SHA_INT32 clo;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
297
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
298 clo = sha_info->count_lo + ((SHA_INT32) count << 3);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
299 if (clo < sha_info->count_lo) {
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
300 ++sha_info->count_hi;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
301 }
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
302 sha_info->count_lo = clo;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
303 sha_info->count_hi += (SHA_INT32) count >> 29;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
304 if (sha_info->local) {
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
305 i = SHA_BLOCKSIZE - sha_info->local;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
306 if (i > count) {
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
307 i = count;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
308 }
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
309 memcpy(((SHA_BYTE *) sha_info->data) + sha_info->local, buffer, i);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
310 count -= i;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
311 buffer += i;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
312 sha_info->local += i;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
313 if (sha_info->local == SHA_BLOCKSIZE) {
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
314 sha512_transform(sha_info);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
315 }
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
316 else {
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
317 return;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
318 }
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
319 }
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
320 while (count >= SHA_BLOCKSIZE) {
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
321 memcpy(sha_info->data, buffer, SHA_BLOCKSIZE);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
322 buffer += SHA_BLOCKSIZE;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
323 count -= SHA_BLOCKSIZE;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
324 sha512_transform(sha_info);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
325 }
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
326 memcpy(sha_info->data, buffer, count);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
327 sha_info->local = count;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
328 }
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
329
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
330 /* finish computing the SHA digest */
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
331
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
332 static void
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
333 sha512_final(unsigned char digest[SHA_DIGESTSIZE], SHAobject *sha_info)
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
334 {
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
335 int count;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
336 SHA_INT32 lo_bit_count, hi_bit_count;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
337
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
338 lo_bit_count = sha_info->count_lo;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
339 hi_bit_count = sha_info->count_hi;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
340 count = (int) ((lo_bit_count >> 3) & 0x7f);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
341 ((SHA_BYTE *) sha_info->data)[count++] = 0x80;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
342 if (count > SHA_BLOCKSIZE - 16) {
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
343 memset(((SHA_BYTE *) sha_info->data) + count, 0,
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
344 SHA_BLOCKSIZE - count);
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
345 sha512_transform(sha_info);
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
346 memset((SHA_BYTE *) sha_info->data, 0, SHA_BLOCKSIZE - 16);
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
347 }
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
348 else {
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
349 memset(((SHA_BYTE *) sha_info->data) + count, 0,
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
350 SHA_BLOCKSIZE - 16 - count);
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
351 }
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
352
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
353 /* GJS: note that we add the hi/lo in big-endian. sha512_transform will
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
354 swap these values into host-order. */
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
355 sha_info->data[112] = 0;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
356 sha_info->data[113] = 0;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
357 sha_info->data[114] = 0;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
358 sha_info->data[115] = 0;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
359 sha_info->data[116] = 0;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
360 sha_info->data[117] = 0;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
361 sha_info->data[118] = 0;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
362 sha_info->data[119] = 0;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
363 sha_info->data[120] = (hi_bit_count >> 24) & 0xff;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
364 sha_info->data[121] = (hi_bit_count >> 16) & 0xff;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
365 sha_info->data[122] = (hi_bit_count >> 8) & 0xff;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
366 sha_info->data[123] = (hi_bit_count >> 0) & 0xff;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
367 sha_info->data[124] = (lo_bit_count >> 24) & 0xff;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
368 sha_info->data[125] = (lo_bit_count >> 16) & 0xff;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
369 sha_info->data[126] = (lo_bit_count >> 8) & 0xff;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
370 sha_info->data[127] = (lo_bit_count >> 0) & 0xff;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
371 sha512_transform(sha_info);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
372 digest[ 0] = (unsigned char) ((sha_info->digest[0] >> 56) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
373 digest[ 1] = (unsigned char) ((sha_info->digest[0] >> 48) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
374 digest[ 2] = (unsigned char) ((sha_info->digest[0] >> 40) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
375 digest[ 3] = (unsigned char) ((sha_info->digest[0] >> 32) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
376 digest[ 4] = (unsigned char) ((sha_info->digest[0] >> 24) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
377 digest[ 5] = (unsigned char) ((sha_info->digest[0] >> 16) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
378 digest[ 6] = (unsigned char) ((sha_info->digest[0] >> 8) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
379 digest[ 7] = (unsigned char) ((sha_info->digest[0] ) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
380 digest[ 8] = (unsigned char) ((sha_info->digest[1] >> 56) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
381 digest[ 9] = (unsigned char) ((sha_info->digest[1] >> 48) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
382 digest[10] = (unsigned char) ((sha_info->digest[1] >> 40) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
383 digest[11] = (unsigned char) ((sha_info->digest[1] >> 32) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
384 digest[12] = (unsigned char) ((sha_info->digest[1] >> 24) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
385 digest[13] = (unsigned char) ((sha_info->digest[1] >> 16) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
386 digest[14] = (unsigned char) ((sha_info->digest[1] >> 8) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
387 digest[15] = (unsigned char) ((sha_info->digest[1] ) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
388 digest[16] = (unsigned char) ((sha_info->digest[2] >> 56) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
389 digest[17] = (unsigned char) ((sha_info->digest[2] >> 48) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
390 digest[18] = (unsigned char) ((sha_info->digest[2] >> 40) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
391 digest[19] = (unsigned char) ((sha_info->digest[2] >> 32) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
392 digest[20] = (unsigned char) ((sha_info->digest[2] >> 24) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
393 digest[21] = (unsigned char) ((sha_info->digest[2] >> 16) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
394 digest[22] = (unsigned char) ((sha_info->digest[2] >> 8) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
395 digest[23] = (unsigned char) ((sha_info->digest[2] ) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
396 digest[24] = (unsigned char) ((sha_info->digest[3] >> 56) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
397 digest[25] = (unsigned char) ((sha_info->digest[3] >> 48) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
398 digest[26] = (unsigned char) ((sha_info->digest[3] >> 40) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
399 digest[27] = (unsigned char) ((sha_info->digest[3] >> 32) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
400 digest[28] = (unsigned char) ((sha_info->digest[3] >> 24) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
401 digest[29] = (unsigned char) ((sha_info->digest[3] >> 16) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
402 digest[30] = (unsigned char) ((sha_info->digest[3] >> 8) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
403 digest[31] = (unsigned char) ((sha_info->digest[3] ) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
404 digest[32] = (unsigned char) ((sha_info->digest[4] >> 56) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
405 digest[33] = (unsigned char) ((sha_info->digest[4] >> 48) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
406 digest[34] = (unsigned char) ((sha_info->digest[4] >> 40) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
407 digest[35] = (unsigned char) ((sha_info->digest[4] >> 32) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
408 digest[36] = (unsigned char) ((sha_info->digest[4] >> 24) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
409 digest[37] = (unsigned char) ((sha_info->digest[4] >> 16) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
410 digest[38] = (unsigned char) ((sha_info->digest[4] >> 8) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
411 digest[39] = (unsigned char) ((sha_info->digest[4] ) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
412 digest[40] = (unsigned char) ((sha_info->digest[5] >> 56) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
413 digest[41] = (unsigned char) ((sha_info->digest[5] >> 48) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
414 digest[42] = (unsigned char) ((sha_info->digest[5] >> 40) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
415 digest[43] = (unsigned char) ((sha_info->digest[5] >> 32) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
416 digest[44] = (unsigned char) ((sha_info->digest[5] >> 24) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
417 digest[45] = (unsigned char) ((sha_info->digest[5] >> 16) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
418 digest[46] = (unsigned char) ((sha_info->digest[5] >> 8) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
419 digest[47] = (unsigned char) ((sha_info->digest[5] ) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
420 digest[48] = (unsigned char) ((sha_info->digest[6] >> 56) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
421 digest[49] = (unsigned char) ((sha_info->digest[6] >> 48) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
422 digest[50] = (unsigned char) ((sha_info->digest[6] >> 40) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
423 digest[51] = (unsigned char) ((sha_info->digest[6] >> 32) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
424 digest[52] = (unsigned char) ((sha_info->digest[6] >> 24) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
425 digest[53] = (unsigned char) ((sha_info->digest[6] >> 16) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
426 digest[54] = (unsigned char) ((sha_info->digest[6] >> 8) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
427 digest[55] = (unsigned char) ((sha_info->digest[6] ) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
428 digest[56] = (unsigned char) ((sha_info->digest[7] >> 56) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
429 digest[57] = (unsigned char) ((sha_info->digest[7] >> 48) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
430 digest[58] = (unsigned char) ((sha_info->digest[7] >> 40) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
431 digest[59] = (unsigned char) ((sha_info->digest[7] >> 32) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
432 digest[60] = (unsigned char) ((sha_info->digest[7] >> 24) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
433 digest[61] = (unsigned char) ((sha_info->digest[7] >> 16) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
434 digest[62] = (unsigned char) ((sha_info->digest[7] >> 8) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
435 digest[63] = (unsigned char) ((sha_info->digest[7] ) & 0xff);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
436 }
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
437
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
438 /*
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
439 * End of copied SHA code.
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
440 *
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
441 * ------------------------------------------------------------------------
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
442 */
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
443
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
444 static PyTypeObject SHA384type;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
445 static PyTypeObject SHA512type;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
446
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
447
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
448 static SHAobject *
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
449 newSHA384object(void)
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
450 {
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
451 return (SHAobject *)PyObject_New(SHAobject, &SHA384type);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
452 }
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
453
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
454 static SHAobject *
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
455 newSHA512object(void)
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
456 {
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
457 return (SHAobject *)PyObject_New(SHAobject, &SHA512type);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
458 }
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
459
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
460 /* Internal methods for a hash object */
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
461
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
462 static void
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
463 SHA512_dealloc(PyObject *ptr)
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
464 {
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
465 PyObject_Del(ptr);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
466 }
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
467
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
468
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
469 /* External methods for a hash object */
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
470
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
471 PyDoc_STRVAR(SHA512_copy__doc__, "Return a copy of the hash object.");
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
472
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
473 static PyObject *
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 38232
diff changeset
474 SHA512_copy(SHAobject *self, PyObject *unused)
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
475 {
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
476 SHAobject *newobj;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
477
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
478 if (((PyObject*)self)->ob_type == &SHA512type) {
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
479 if ( (newobj = newSHA512object())==NULL)
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
480 return NULL;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
481 } else {
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
482 if ( (newobj = newSHA384object())==NULL)
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
483 return NULL;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
484 }
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
485
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
486 SHAcopy(self, newobj);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
487 return (PyObject *)newobj;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
488 }
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
489
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
490 PyDoc_STRVAR(SHA512_digest__doc__,
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
491 "Return the digest value as a string of binary data.");
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
492
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
493 static PyObject *
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 38232
diff changeset
494 SHA512_digest(SHAobject *self, PyObject *unused)
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
495 {
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
496 unsigned char digest[SHA_DIGESTSIZE];
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
497 SHAobject temp;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
498
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
499 SHAcopy(self, &temp);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
500 sha512_final(digest, &temp);
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
501 return PyString_FromStringAndSize((const char *)digest, self->digestsize);
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
502 }
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
503
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
504 PyDoc_STRVAR(SHA512_hexdigest__doc__,
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
505 "Return the digest value as a string of hexadecimal digits.");
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
506
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
507 static PyObject *
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 38232
diff changeset
508 SHA512_hexdigest(SHAobject *self, PyObject *unused)
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
509 {
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
510 unsigned char digest[SHA_DIGESTSIZE];
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
511 SHAobject temp;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
512 PyObject *retval;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
513 char *hex_digest;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
514 int i, j;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
515
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
516 /* Get the raw (binary) digest value */
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
517 SHAcopy(self, &temp);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
518 sha512_final(digest, &temp);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
519
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
520 /* Create a new string */
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
521 retval = PyString_FromStringAndSize(NULL, self->digestsize * 2);
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
522 if (!retval)
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
523 return NULL;
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
524 hex_digest = PyString_AsString(retval);
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
525 if (!hex_digest) {
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
526 Py_DECREF(retval);
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
527 return NULL;
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
528 }
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
529
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
530 /* Make hex version of the digest */
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 38232
diff changeset
531 for (i=j=0; i<self->digestsize; i++) {
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
532 char c;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
533 c = (digest[i] >> 4) & 0xf;
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
534 c = (c>9) ? c+'a'-10 : c + '0';
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
535 hex_digest[j++] = c;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
536 c = (digest[i] & 0xf);
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
537 c = (c>9) ? c+'a'-10 : c + '0';
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
538 hex_digest[j++] = c;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
539 }
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
540 return retval;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
541 }
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
542
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
543 PyDoc_STRVAR(SHA512_update__doc__,
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
544 "Update this hash object's state with the provided string.");
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
545
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
546 static PyObject *
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
547 SHA512_update(SHAobject *self, PyObject *args)
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
548 {
51580
1e7ac14e4938 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents: 47527
diff changeset
549 Py_buffer buf;
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
550
58101
ff5bc2fa38d6 Issue #3745: Undo the requirement for new buffer API only objects to be passed
Gregory P. Smith <greg@mad-scientist.com>
parents: 51976
diff changeset
551 if (!PyArg_ParseTuple(args, "s*:update", &buf))
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
552 return NULL;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
553
51580
1e7ac14e4938 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents: 47527
diff changeset
554 sha512_update(self, buf.buf, buf.len);
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
555
51580
1e7ac14e4938 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents: 47527
diff changeset
556 PyBuffer_Release(&buf);
58101
ff5bc2fa38d6 Issue #3745: Undo the requirement for new buffer API only objects to be passed
Gregory P. Smith <greg@mad-scientist.com>
parents: 51976
diff changeset
557 Py_RETURN_NONE;
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
558 }
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
559
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
560 static PyMethodDef SHA_methods[] = {
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
561 {"copy", (PyCFunction)SHA512_copy, METH_NOARGS, SHA512_copy__doc__},
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
562 {"digest", (PyCFunction)SHA512_digest, METH_NOARGS, SHA512_digest__doc__},
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 38232
diff changeset
563 {"hexdigest", (PyCFunction)SHA512_hexdigest, METH_NOARGS, SHA512_hexdigest__doc__},
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
564 {"update", (PyCFunction)SHA512_update, METH_VARARGS, SHA512_update__doc__},
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
565 {NULL, NULL} /* sentinel */
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
566 };
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
567
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
568 static PyObject *
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
569 SHA512_get_block_size(PyObject *self, void *closure)
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
570 {
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
571 return PyInt_FromLong(SHA_BLOCKSIZE);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
572 }
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
573
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
574 static PyObject *
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
575 SHA512_get_name(PyObject *self, void *closure)
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
576 {
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
577 if (((SHAobject *)self)->digestsize == 64)
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
578 return PyString_FromStringAndSize("SHA512", 6);
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
579 else
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
580 return PyString_FromStringAndSize("SHA384", 6);
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
581 }
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
582
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
583 static PyGetSetDef SHA_getseters[] = {
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
584 {"block_size",
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
585 (getter)SHA512_get_block_size, NULL,
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
586 NULL,
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
587 NULL},
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
588 {"name",
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
589 (getter)SHA512_get_name, NULL,
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
590 NULL,
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
591 NULL},
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
592 {NULL} /* Sentinel */
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
593 };
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
594
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
595 static PyMemberDef SHA_members[] = {
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
596 {"digest_size", T_INT, offsetof(SHAobject, digestsize), READONLY, NULL},
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
597 /* the old md5 and sha modules support 'digest_size' as in PEP 247.
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
598 * the old sha module also supported 'digestsize'. ugh. */
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
599 {"digestsize", T_INT, offsetof(SHAobject, digestsize), READONLY, NULL},
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
600 {NULL} /* Sentinel */
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
601 };
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
602
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
603 static PyTypeObject SHA384type = {
42333
6620a510e9a9 PEP 3123: Provide forward compatibility with Python 3.0, while keeping
Martin v. Löwis <martin@v.loewis.de>
parents: 38489
diff changeset
604 PyVarObject_HEAD_INIT(NULL, 0)
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
605 "_sha512.sha384", /*tp_name*/
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
606 sizeof(SHAobject), /*tp_size*/
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
607 0, /*tp_itemsize*/
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
608 /* methods */
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
609 SHA512_dealloc, /*tp_dealloc*/
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
610 0, /*tp_print*/
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
611 0, /*tp_getattr*/
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
612 0, /*tp_setattr*/
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
613 0, /*tp_compare*/
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
614 0, /*tp_repr*/
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
615 0, /*tp_as_number*/
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
616 0, /*tp_as_sequence*/
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
617 0, /*tp_as_mapping*/
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
618 0, /*tp_hash*/
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
619 0, /*tp_call*/
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
620 0, /*tp_str*/
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
621 0, /*tp_getattro*/
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
622 0, /*tp_setattro*/
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
623 0, /*tp_as_buffer*/
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
624 Py_TPFLAGS_DEFAULT, /*tp_flags*/
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
625 0, /*tp_doc*/
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
626 0, /*tp_traverse*/
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
627 0, /*tp_clear*/
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
628 0, /*tp_richcompare*/
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
629 0, /*tp_weaklistoffset*/
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
630 0, /*tp_iter*/
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
631 0, /*tp_iternext*/
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
632 SHA_methods, /* tp_methods */
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
633 SHA_members, /* tp_members */
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
634 SHA_getseters, /* tp_getset */
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
635 };
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
636
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
637 static PyTypeObject SHA512type = {
42333
6620a510e9a9 PEP 3123: Provide forward compatibility with Python 3.0, while keeping
Martin v. Löwis <martin@v.loewis.de>
parents: 38489
diff changeset
638 PyVarObject_HEAD_INIT(NULL, 0)
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
639 "_sha512.sha512", /*tp_name*/
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
640 sizeof(SHAobject), /*tp_size*/
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
641 0, /*tp_itemsize*/
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
642 /* methods */
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
643 SHA512_dealloc, /*tp_dealloc*/
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
644 0, /*tp_print*/
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
645 0, /*tp_getattr*/
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
646 0, /*tp_setattr*/
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
647 0, /*tp_compare*/
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
648 0, /*tp_repr*/
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
649 0, /*tp_as_number*/
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
650 0, /*tp_as_sequence*/
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
651 0, /*tp_as_mapping*/
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
652 0, /*tp_hash*/
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
653 0, /*tp_call*/
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
654 0, /*tp_str*/
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
655 0, /*tp_getattro*/
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
656 0, /*tp_setattro*/
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
657 0, /*tp_as_buffer*/
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
658 Py_TPFLAGS_DEFAULT, /*tp_flags*/
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
659 0, /*tp_doc*/
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
660 0, /*tp_traverse*/
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
661 0, /*tp_clear*/
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
662 0, /*tp_richcompare*/
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
663 0, /*tp_weaklistoffset*/
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
664 0, /*tp_iter*/
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
665 0, /*tp_iternext*/
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
666 SHA_methods, /* tp_methods */
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
667 SHA_members, /* tp_members */
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
668 SHA_getseters, /* tp_getset */
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
669 };
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
670
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
671
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
672 /* The single module-level function: new() */
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
673
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
674 PyDoc_STRVAR(SHA512_new__doc__,
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
675 "Return a new SHA-512 hash object; optionally initialized with a string.");
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
676
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
677 static PyObject *
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
678 SHA512_new(PyObject *self, PyObject *args, PyObject *kwdict)
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
679 {
36675
dba6494735d0 Revert backwards-incompatible const changes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
680 static char *kwlist[] = {"string", NULL};
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
681 SHAobject *new;
58101
ff5bc2fa38d6 Issue #3745: Undo the requirement for new buffer API only objects to be passed
Gregory P. Smith <greg@mad-scientist.com>
parents: 51976
diff changeset
682 Py_buffer buf = { 0 };
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
683
58101
ff5bc2fa38d6 Issue #3745: Undo the requirement for new buffer API only objects to be passed
Gregory P. Smith <greg@mad-scientist.com>
parents: 51976
diff changeset
684 if (!PyArg_ParseTupleAndKeywords(args, kwdict, "|s*:new", kwlist,
ff5bc2fa38d6 Issue #3745: Undo the requirement for new buffer API only objects to be passed
Gregory P. Smith <greg@mad-scientist.com>
parents: 51976
diff changeset
685 &buf)) {
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
686 return NULL;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
687 }
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
688
51976
61d20e919a9e Fixed memory leak.
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents: 51580
diff changeset
689 if ((new = newSHA512object()) == NULL) {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 58101
diff changeset
690 PyBuffer_Release(&buf);
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
691 return NULL;
51976
61d20e919a9e Fixed memory leak.
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents: 51580
diff changeset
692 }
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
693
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
694 sha512_init(new);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
695
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
696 if (PyErr_Occurred()) {
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
697 Py_DECREF(new);
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 58101
diff changeset
698 PyBuffer_Release(&buf);
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
699 return NULL;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
700 }
58101
ff5bc2fa38d6 Issue #3745: Undo the requirement for new buffer API only objects to be passed
Gregory P. Smith <greg@mad-scientist.com>
parents: 51976
diff changeset
701 if (buf.len > 0) {
51580
1e7ac14e4938 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents: 47527
diff changeset
702 sha512_update(new, buf.buf, buf.len);
1e7ac14e4938 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents: 47527
diff changeset
703 }
58101
ff5bc2fa38d6 Issue #3745: Undo the requirement for new buffer API only objects to be passed
Gregory P. Smith <greg@mad-scientist.com>
parents: 51976
diff changeset
704 PyBuffer_Release(&buf);
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
705
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
706 return (PyObject *)new;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
707 }
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
708
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
709 PyDoc_STRVAR(SHA384_new__doc__,
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
710 "Return a new SHA-384 hash object; optionally initialized with a string.");
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
711
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
712 static PyObject *
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
713 SHA384_new(PyObject *self, PyObject *args, PyObject *kwdict)
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
714 {
36675
dba6494735d0 Revert backwards-incompatible const changes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
715 static char *kwlist[] = {"string", NULL};
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
716 SHAobject *new;
58101
ff5bc2fa38d6 Issue #3745: Undo the requirement for new buffer API only objects to be passed
Gregory P. Smith <greg@mad-scientist.com>
parents: 51976
diff changeset
717 Py_buffer buf = { 0 };
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
718
58101
ff5bc2fa38d6 Issue #3745: Undo the requirement for new buffer API only objects to be passed
Gregory P. Smith <greg@mad-scientist.com>
parents: 51976
diff changeset
719 if (!PyArg_ParseTupleAndKeywords(args, kwdict, "|s*:new", kwlist,
ff5bc2fa38d6 Issue #3745: Undo the requirement for new buffer API only objects to be passed
Gregory P. Smith <greg@mad-scientist.com>
parents: 51976
diff changeset
720 &buf)) {
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
721 return NULL;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
722 }
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
723
51976
61d20e919a9e Fixed memory leak.
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents: 51580
diff changeset
724 if ((new = newSHA384object()) == NULL) {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 58101
diff changeset
725 PyBuffer_Release(&buf);
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
726 return NULL;
51976
61d20e919a9e Fixed memory leak.
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents: 51580
diff changeset
727 }
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
728
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
729 sha384_init(new);
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
730
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
731 if (PyErr_Occurred()) {
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
732 Py_DECREF(new);
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 58101
diff changeset
733 PyBuffer_Release(&buf);
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
734 return NULL;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
735 }
58101
ff5bc2fa38d6 Issue #3745: Undo the requirement for new buffer API only objects to be passed
Gregory P. Smith <greg@mad-scientist.com>
parents: 51976
diff changeset
736 if (buf.len > 0) {
51580
1e7ac14e4938 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents: 47527
diff changeset
737 sha512_update(new, buf.buf, buf.len);
1e7ac14e4938 - Issue #3745: Fix hashlib to always reject unicode and non buffer-api
Gregory P. Smith <greg@mad-scientist.com>
parents: 47527
diff changeset
738 }
58101
ff5bc2fa38d6 Issue #3745: Undo the requirement for new buffer API only objects to be passed
Gregory P. Smith <greg@mad-scientist.com>
parents: 51976
diff changeset
739 PyBuffer_Release(&buf);
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
740
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
741 return (PyObject *)new;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
742 }
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
743
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
744
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
745 /* List of functions exported by this module */
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
746
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
747 static struct PyMethodDef SHA_functions[] = {
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
748 {"sha512", (PyCFunction)SHA512_new, METH_VARARGS|METH_KEYWORDS, SHA512_new__doc__},
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
749 {"sha384", (PyCFunction)SHA384_new, METH_VARARGS|METH_KEYWORDS, SHA384_new__doc__},
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
750 {NULL, NULL} /* Sentinel */
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
751 };
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
752
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
753
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
754 /* Initialize this module. */
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
755
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
756 #define insint(n,v) { PyModule_AddIntConstant(m,n,v); }
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
757
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
758 PyMODINIT_FUNC
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
759 init_sha512(void)
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
760 {
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
761 PyObject *m;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
762
44350
26384b8180c7 #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents: 43298
diff changeset
763 Py_TYPE(&SHA384type) = &PyType_Type;
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
764 if (PyType_Ready(&SHA384type) < 0)
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
765 return;
44350
26384b8180c7 #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents: 43298
diff changeset
766 Py_TYPE(&SHA512type) = &PyType_Type;
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
767 if (PyType_Ready(&SHA512type) < 0)
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
768 return;
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
769 m = Py_InitModule("_sha512", SHA_functions);
36324
1af7f719ed28 Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36024
diff changeset
770 if (m == NULL)
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
771 return;
35375
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
772 }
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
773
624918e1c1b2 [ sf.net patch # 1121611 ]
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
774 #endif