~ubuntu-branches/ubuntu/vivid/unrar-nonfree/vivid

« back to all changes in this revision

Viewing changes to sha1.cpp

  • Committer: Package Import Robot
  • Author(s): Martin Meredith
  • Date: 2015-02-03 12:58:01 UTC
  • mfrom: (1.1.18) (5.1.18 sid)
  • Revision ID: package-import@ubuntu.com-20150203125801-od6ev8cqy1er51vz
Tags: 1:5.2.5-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
 
60
60
/* Hash a single 512-bit block. This is the core of the algorithm. */
61
61
 
62
 
void SHA1Transform(uint32 state[5], unsigned char workspace[64], unsigned char buffer[64], bool handsoff)
 
62
void SHA1Transform(uint32 state[5], unsigned char workspace[64], const byte buffer[64], bool handsoff)
63
63
{
64
64
#ifndef SFX_MODULE
65
65
  uint32 a, b, c, d, e;
155
155
 
156
156
/* Initialize new context */
157
157
 
158
 
void hash_initial(hash_context* context)
 
158
void sha1_init(sha1_context* context)
159
159
{
160
160
    /* SHA1 initialization constants */
161
161
    context->state[0] = 0x67452301;
168
168
 
169
169
 
170
170
/* Run your data through this. */
171
 
void hash_process( hash_context * context, unsigned char * data, size_t len,
 
171
void sha1_process( sha1_context * context, const unsigned char * data, size_t len,
172
172
                   bool handsoff )
173
173
{
174
174
unsigned int i, j;
181
181
        memcpy(&context->buffer[j], data, (i = 64-j));
182
182
        SHA1Transform(context->state, context->workspace, context->buffer, handsoff);
183
183
        for ( ; i + 63 < len; i += 64) {
184
 
#ifdef ALLOW_NOT_ALIGNED_INT
 
184
#ifdef ALLOW_MISALIGNED
185
185
            SHA1Transform(context->state, context->workspace, &data[i], handsoff);
186
186
#else
187
 
            unsigned char buffer[64];
 
187
            uint buffer[16];
188
188
            memcpy(buffer,data+i,sizeof(buffer));
189
 
            SHA1Transform(context->state, context->workspace, buffer, handsoff);
190
 
            memcpy(data+i,buffer,sizeof(buffer));
 
189
            SHA1Transform(context->state, context->workspace, (byte*)buffer, handsoff);
 
190
            if (!handsoff)
 
191
              memcpy((byte *)(data+i),buffer,sizeof(buffer));
191
192
#endif
192
193
#ifdef BIG_ENDIAN
193
194
            if (!handsoff)
194
195
            {
195
 
              unsigned char *d=data+i;
 
196
              unsigned char *d=(unsigned char *)(data+i);
196
197
              for (int k=0;k<64;k+=4)
197
198
              {
198
199
                byte b0=d[k],b1=d[k+1];
214
215
 
215
216
/* Add padding and return the message digest. */
216
217
 
217
 
void hash_final( hash_context* context, uint32 digest[5], bool handsoff)
 
218
void sha1_done( sha1_context* context, uint32 digest[5], bool handsoff)
218
219
{
219
220
uint i, j;
220
221
unsigned char finalcount[8];
224
225
         >> ((3-(i & 3)) * 8) ) & 255);  /* Endian independent */
225
226
    }
226
227
    unsigned char ch=(unsigned char)'\200';
227
 
    hash_process(context, &ch, 1, handsoff);
 
228
    sha1_process(context, &ch, 1, handsoff);
228
229
    while ((context->count[0] & 504) != 448) {
229
230
        ch=0;
230
 
        hash_process(context, &ch, 1, handsoff);
 
231
        sha1_process(context, &ch, 1, handsoff);
231
232
    }
232
 
    hash_process(context, finalcount, 8, handsoff);  /* Should cause a SHA1Transform() */
 
233
    sha1_process(context, finalcount, 8, handsoff);  /* Should cause a SHA1Transform() */
233
234
    for (i = 0; i < 5; i++) {
234
235
        digest[i] = context->state[i] & 0xffffffff;
235
236
    }