~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/sha1.c

Removed dead variable, sorted authors file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
     - More comments
49
49
*/
50
50
 
51
 
#include <mystrings/m_string.h>
 
51
#include "my_global.h"
 
52
#include "m_string.h"
52
53
#include "sha1.h"
53
54
 
54
55
/*
80
81
*/
81
82
 
82
83
 
83
 
const uint32_t sha_const_key[5]=
 
84
const uint32 sha_const_key[5]=
84
85
{
85
86
  0x67452301,
86
87
  0xEFCDAB89,
92
93
 
93
94
int mysql_sha1_reset(SHA1_CONTEXT *context)
94
95
{
 
96
#ifndef DBUG_OFF
 
97
  if (!context)
 
98
    return SHA_NULL;
 
99
#endif
 
100
 
95
101
  context->Length                 = 0;
96
102
  context->Message_Block_Index    = 0;
97
103
 
126
132
*/
127
133
 
128
134
int mysql_sha1_result(SHA1_CONTEXT *context,
129
 
                      uint8_t Message_Digest[SHA1_HASH_SIZE])
 
135
                      uint8 Message_Digest[SHA1_HASH_SIZE])
130
136
{
131
137
  int i;
132
138
 
 
139
#ifndef DBUG_OFF
 
140
  if (!context || !Message_Digest)
 
141
    return SHA_NULL;
 
142
 
 
143
  if (context->Corrupted)
 
144
    return context->Corrupted;
 
145
#endif
 
146
 
133
147
  if (!context->Computed)
134
148
  {
135
149
    SHA1PadMessage(context);
136
150
     /* message may be sensitive, clear it out */
137
 
    memset(context->Message_Block, 0, 64);
 
151
    bzero((char*) context->Message_Block,64);
138
152
    context->Length   = 0;    /* and clear length  */
139
153
    context->Computed = 1;
140
154
  }
141
155
 
142
156
  for (i = 0; i < SHA1_HASH_SIZE; i++)
143
 
    Message_Digest[i] = (int8_t)((context->Intermediate_Hash[i>>2] >> 8
 
157
    Message_Digest[i] = (int8)((context->Intermediate_Hash[i>>2] >> 8
144
158
                         * ( 3 - ( i & 0x03 ) )));
145
159
  return SHA_SUCCESS;
146
160
}
161
175
   != SHA_SUCCESS       sha Error Code.
162
176
*/
163
177
 
164
 
int mysql_sha1_input(SHA1_CONTEXT *context, const uint8_t *message_array,
 
178
int mysql_sha1_input(SHA1_CONTEXT *context, const uint8 *message_array,
165
179
                     unsigned length)
166
180
{
167
181
  if (!length)
168
182
    return SHA_SUCCESS;
169
183
 
 
184
#ifndef DBUG_OFF
 
185
  /* We assume client konows what it is doing in non-debug mode */
 
186
  if (!context || !message_array)
 
187
    return SHA_NULL;
 
188
  if (context->Computed)
 
189
    return (context->Corrupted= SHA_STATE_ERROR);
 
190
  if (context->Corrupted)
 
191
    return context->Corrupted;
 
192
#endif
 
193
 
170
194
  while (length--)
171
195
  {
172
196
    context->Message_Block[context->Message_Block_Index++]=
173
197
      (*message_array & 0xFF);
174
198
    context->Length  += 8;  /* Length is in bits */
175
199
 
 
200
#ifndef DBUG_OFF
 
201
    /*
 
202
      Then we're not debugging we assume we never will get message longer
 
203
      2^64 bits.
 
204
    */
 
205
    if (context->Length == 0)
 
206
      return (context->Corrupted= 1);      /* Message is too long */
 
207
#endif
 
208
 
176
209
    if (context->Message_Block_Index == 64)
177
210
    {
178
211
      SHA1ProcessMessageBlock(context);
196
229
*/
197
230
 
198
231
/* Constants defined in SHA-1   */
199
 
static const uint32_t  K[]=
 
232
static const uint32  K[]=
200
233
{
201
234
  0x5A827999,
202
235
  0x6ED9EBA1,
208
241
static void SHA1ProcessMessageBlock(SHA1_CONTEXT *context)
209
242
{
210
243
  int           t;                 /* Loop counter                */
211
 
  uint32_t      temp;              /* Temporary word value        */
212
 
  uint32_t      W[80];             /* Word sequence               */
213
 
  uint32_t      A, B, C, D, E;     /* Word buffers                */
 
244
  uint32        temp;              /* Temporary word value        */
 
245
  uint32        W[80];             /* Word sequence               */
 
246
  uint32        A, B, C, D, E;     /* Word buffers                */
214
247
  int idx;
215
248
 
216
249
  /*
322
355
  if (i > 55)
323
356
  {
324
357
    context->Message_Block[i++] = 0x80;
325
 
    memset(&context->Message_Block[i], 0,
326
 
           sizeof(context->Message_Block[0])*(64-i));
 
358
    bzero((char*) &context->Message_Block[i],
 
359
          sizeof(context->Message_Block[0])*(64-i));
327
360
    context->Message_Block_Index=64;
328
361
 
329
362
    /* This function sets context->Message_Block_Index to zero  */
330
363
    SHA1ProcessMessageBlock(context);
331
364
 
332
 
    memset(&context->Message_Block[0], 0,
333
 
           sizeof(context->Message_Block[0])*56);
 
365
    bzero((char*) &context->Message_Block[0],
 
366
          sizeof(context->Message_Block[0])*56);
334
367
    context->Message_Block_Index=56;
335
368
  }
336
369
  else
337
370
  {
338
371
    context->Message_Block[i++] = 0x80;
339
 
    memset(&context->Message_Block[i], 0,
340
 
           sizeof(context->Message_Block[0])*(56-i));
 
372
    bzero((char*) &context->Message_Block[i],
 
373
          sizeof(context->Message_Block[0])*(56-i));
341
374
    context->Message_Block_Index=56;
342
375
  }
343
376
 
345
378
    Store the message length as the last 8 octets
346
379
  */
347
380
 
348
 
  context->Message_Block[56] = (int8_t) (context->Length >> 56);
349
 
  context->Message_Block[57] = (int8_t) (context->Length >> 48);
350
 
  context->Message_Block[58] = (int8_t) (context->Length >> 40);
351
 
  context->Message_Block[59] = (int8_t) (context->Length >> 32);
352
 
  context->Message_Block[60] = (int8_t) (context->Length >> 24);
353
 
  context->Message_Block[61] = (int8_t) (context->Length >> 16);
354
 
  context->Message_Block[62] = (int8_t) (context->Length >> 8);
355
 
  context->Message_Block[63] = (int8_t) (context->Length);
 
381
  context->Message_Block[56] = (int8) (context->Length >> 56);
 
382
  context->Message_Block[57] = (int8) (context->Length >> 48);
 
383
  context->Message_Block[58] = (int8) (context->Length >> 40);
 
384
  context->Message_Block[59] = (int8) (context->Length >> 32);
 
385
  context->Message_Block[60] = (int8) (context->Length >> 24);
 
386
  context->Message_Block[61] = (int8) (context->Length >> 16);
 
387
  context->Message_Block[62] = (int8) (context->Length >> 8);
 
388
  context->Message_Block[63] = (int8) (context->Length);
356
389
 
357
390
  SHA1ProcessMessageBlock(context);
358
391
}