~ubuntu-branches/ubuntu/wily/python-crypto/wily-proposed

« back to all changes in this revision

Viewing changes to src/SHA256.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Rottmann
  • Date: 2009-03-20 20:16:38 UTC
  • Revision ID: james.westby@ubuntu.com-20090320201638-6so4qvp6rgi72d6c
Tags: 2.0.1+dfsg1-4
* Switched to quilt patches:
  - errata-2.0.1.patch: 
      Syncs the source tree to the actually released 2.0.1 tarball.
  - dfsg-adjust.patch:
      Adjusts the build system to the DFSGified source, to deal with 
      the removed files.
  - aes256-55bytes.patch:
      Fixes the AES256 padding bug (Bug#474177).
  - arc2-buffer-overflow.patch:
      Fixes the ARC2 buffer overflow (Bug#516660).
  - m68k-no-O3.patch: 
      Workaround GCC 4.0.1 ICE regarding -O3 on m68k. This patch is 
      deactived -- hopefully this is fixed in recent GCC.
* New patches:
  - run-tests.patch:
      Non-Debian part of the patch by Kees Cook <kees@debian.org> 
      to run test suite during build (closes: #518202).
  - no-usr-local.patch:
      Remove #!/usr/local/bin/python shebang line from Util/RFC1751.py.
* Run test suite during build.
* Added ${misc:Depends}.
* Added ${shlib:Depends} to python-crypto.
* Restored old changelog entries, which seem to got cut off between 2.
  0.1+dfsg1-2.1 and 2.0.1+dfsg1-2.3 (by Matthias?).
* Typo fix for python-crypto-dbg description: python -> Python.
* Use ${binary:Version} instead of ${Source-Version}.
* Added debian/watch.
* Bump Standards-Version to 3.8.1:
  - Added Homepage field to debian/control.
* Adjust copyright line in debian/copyright.
* Move python-crypto-dbg to section 'debug'.
* Add XB-Python-Version to python-crypto-dbg.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 * Tom St Denis -- http://tomstdenis.home.dhs.org
12
12
 * */
13
13
#include "Python.h"
14
 
#define MODULE_NAME SHA256
 
14
#define MODULE_NAME SHA256
15
15
#define DIGEST_SIZE 32
16
16
 
17
 
typedef unsigned char U8;
18
 
#ifdef __alpha__
19
 
typedef    unsigned int        U32;
20
 
#elif defined(__amd64__)
21
 
#include <inttypes.h>
22
 
typedef uint32_t U32;
23
 
#else
 
17
typedef unsigned char U8;
24
18
typedef unsigned int U32;
25
 
#endif
26
19
 
27
20
typedef struct {
28
 
    U32 state[8], length, curlen;
 
21
    unsigned long state[8], length, curlen;
29
22
    unsigned char buf[64];
30
23
}
31
24
hash_state;
32
25
 
33
26
/* the K array */
34
 
static const U32 K[64] = {
 
27
static const unsigned long K[64] = {
35
28
    0x428a2f98UL, 0x71374491UL, 0xb5c0fbcfUL, 0xe9b5dba5UL, 0x3956c25bUL,
36
29
    0x59f111f1UL, 0x923f82a4UL, 0xab1c5ed5UL, 0xd807aa98UL, 0x12835b01UL,
37
30
    0x243185beUL, 0x550c7dc3UL, 0x72be5d74UL, 0x80deb1feUL, 0x9bdc06a7UL,
60
53
/* compress 512-bits */
61
54
static void sha_compress(hash_state * md)
62
55
{
63
 
    U32 S[8], W[64], t0, t1;
 
56
    unsigned long S[8], W[64], t0, t1;
64
57
    int i;
65
58
 
66
59
    /* copy state into S */
69
62
 
70
63
    /* copy the state into 512-bits into W[0..15] */
71
64
    for (i = 0; i < 16; i++)
72
 
        W[i] = (((U32) md->buf[(4 * i) + 0]) << 24) |
73
 
            (((U32) md->buf[(4 * i) + 1]) << 16) |
74
 
            (((U32) md->buf[(4 * i) + 2]) << 8) |
75
 
            (((U32) md->buf[(4 * i) + 3]));
 
65
        W[i] = (((unsigned long) md->buf[(4 * i) + 0]) << 24) |
 
66
            (((unsigned long) md->buf[(4 * i) + 1]) << 16) |
 
67
            (((unsigned long) md->buf[(4 * i) + 2]) << 8) |
 
68
            (((unsigned long) md->buf[(4 * i) + 3]));
76
69
 
77
70
    /* fill W[16..63] */
78
71
    for (i = 16; i < 64; i++)
140
133
                               * then compress.  Then we can fall back to padding zeros and length
141
134
                               * encoding like normal.
142
135
                             */
143
 
    if (md->curlen > 56) {
 
136
    if (md->curlen >= 56) {
144
137
        for (; md->curlen < 64;)
145
138
            md->buf[md->curlen++] = 0;
146
139
        sha_compress(md);
179
172
}
180
173
 
181
174
// Done
182
 
static void
 
175
static void
183
176
hash_copy(hash_state *src, hash_state *dest)
184
177
{
185
178
        memcpy(dest,src,sizeof(hash_state));
186
179
}
187
180
 
188
181
// Done
189
 
static PyObject *
 
182
static PyObject *
190
183
hash_digest (const hash_state *self)
191
184
{
192
185
        unsigned char digest[32];