~ubuntu-branches/debian/experimental/apt/experimental

« back to all changes in this revision

Viewing changes to apt-pkg/contrib/sha256.cc

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2010-02-18 22:07:23 UTC
  • mfrom: (9.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20100218220723-zb7zdh6fmsmp30tr
Tags: 0.7.26~exp2
fix crash when LANGUAGE is not set

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Cryptographic API.
 
2
 * Cryptographic API.                                                   {{{
3
3
 *
4
4
 * SHA-256, as specified in
5
5
 * http://csrc.nist.gov/cryptval/shs/sha256-384-512.pdf
17
17
 * Software Foundation; either version 2 of the License, or (at your option) 
18
18
 * any later version.
19
19
 *
20
 
 */
 
20
 */                                                                     /*}}}*/
21
21
 
22
22
#ifdef __GNUG__
23
23
#pragma implementation "apt-pkg/sha256.h"
29
29
 
30
30
#define ror32(value,bits) (((value) >> (bits)) | ((value) << (32 - (bits))))
31
31
 
32
 
#include <apt-pkg/contrib/sha256.h>
33
 
#include <apt-pkg/contrib/strutl.h>
 
32
#include <apt-pkg/sha256.h>
 
33
#include <apt-pkg/strutl.h>
34
34
#include <string.h>
35
35
#include <unistd.h>
36
36
#include <stdint.h>
65
65
#define H6         0x1f83d9ab
66
66
#define H7         0x5be0cd19
67
67
 
68
 
static inline void LOAD_OP(int I, u32 *W, const u8 *input)
 
68
static inline void LOAD_OP(int I, u32 *W, const u8 *input)              /*{{{*/
69
69
{
70
70
        W[I] = (  ((u32) input[I * 4 + 0] << 24)
71
71
                | ((u32) input[I * 4 + 1] << 16)
72
72
                | ((u32) input[I * 4 + 2] << 8)
73
73
                | ((u32) input[I * 4 + 3]));
74
74
}
75
 
 
 
75
                                                                        /*}}}*/
76
76
static inline void BLEND_OP(int I, u32 *W)
77
77
{
78
78
        W[I] = s1(W[I-2]) + W[I-7] + s0(W[I-15]) + W[I-16];
79
79
}
80
80
 
81
 
static void sha256_transform(u32 *state, const u8 *input)
 
81
static void sha256_transform(u32 *state, const u8 *input)               /*{{{*/
82
82
{
83
83
        u32 a, b, c, d, e, f, g, h, t1, t2;
84
84
        u32 W[64];
240
240
        a = b = c = d = e = f = g = h = t1 = t2 = 0;
241
241
        memset(W, 0, 64 * sizeof(u32));
242
242
}
243
 
 
244
 
SHA256Summation::SHA256Summation()
 
243
                                                                        /*}}}*/
 
244
SHA256Summation::SHA256Summation()                                      /*{{{*/
245
245
{
246
246
        Sum.state[0] = H0;
247
247
        Sum.state[1] = H1;
255
255
        memset(Sum.buf, 0, sizeof(Sum.buf));
256
256
        Done = false;
257
257
}
258
 
 
259
 
bool SHA256Summation::Add(const u8 *data, unsigned long len)
 
258
                                                                        /*}}}*/
 
259
bool SHA256Summation::Add(const u8 *data, unsigned long len)            /*{{{*/
260
260
{
261
261
        struct sha256_ctx *sctx = &Sum;
262
262
        unsigned int i, index, part_len;
291
291
 
292
292
        return true;
293
293
}
294
 
 
295
 
SHA256SumValue SHA256Summation::Result()
 
294
                                                                        /*}}}*/
 
295
SHA256SumValue SHA256Summation::Result()                                /*{{{*/
296
296
{
297
297
   struct sha256_ctx *sctx = &Sum;
298
298
   if (!Done) {
340
340
 
341
341
   return res;
342
342
}
343
 
 
 
343
                                                                        /*}}}*/
344
344
// SHA256SumValue::SHA256SumValue - Constructs the sum from a string   /*{{{*/
345
345
// ---------------------------------------------------------------------
346
346
/* The string form of a SHA256 is a 64 character hex number */
349
349
   memset(Sum,0,sizeof(Sum));
350
350
   Set(Str);
351
351
}
352
 
 
353
352
                                                                       /*}}}*/
354
353
// SHA256SumValue::SHA256SumValue - Default constructor                /*{{{*/
355
354
// ---------------------------------------------------------------------
358
357
{
359
358
   memset(Sum,0,sizeof(Sum));
360
359
}
361
 
 
362
360
                                                                       /*}}}*/
363
361
// SHA256SumValue::Set - Set the sum from a string                     /*{{{*/
364
362
// ---------------------------------------------------------------------
391
389
 
392
390
   return string(Result);
393
391
}
394
 
 
395
 
 
396
 
 
 
392
                                                                        /*}}}*/
397
393
// SHA256SumValue::operator == - Comparator                            /*{{{*/
398
394
// ---------------------------------------------------------------------
399
395
/* Call memcmp on the buffer */
402
398
   return memcmp(Sum,rhs.Sum,sizeof(Sum)) == 0;
403
399
}
404
400
                                                                       /*}}}*/
405
 
 
406
 
 
407
401
// SHA256Summation::AddFD - Add content of file into the checksum      /*{{{*/
408
402
// ---------------------------------------------------------------------
409
403
/* */