]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/contrib/sha256.cc
- add --arch option for apt-ftparchive packages and contents commands
[apt.git] / apt-pkg / contrib / sha256.cc
index a4d258d263e8f637a80658037489db5098676ec2..e380c13aeda2c38a6e3fba5d449d349707da9781 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * Cryptographic API.
+ * Cryptographic API.                                                  {{{
  *
  * SHA-256, as specified in
  * http://csrc.nist.gov/cryptval/shs/sha256-384-512.pdf
  *
  * SHA-256, as specified in
  * http://csrc.nist.gov/cryptval/shs/sha256-384-512.pdf
  * Software Foundation; either version 2 of the License, or (at your option) 
  * any later version.
  *
  * Software Foundation; either version 2 of the License, or (at your option) 
  * any later version.
  *
- */
+ */                                                                    /*}}}*/
+
+#ifdef __GNUG__
+#pragma implementation "apt-pkg/sha256.h"
+#endif
+
+
 #define SHA256_DIGEST_SIZE      32
 #define SHA256_HMAC_BLOCK_SIZE  64
 
 #define SHA256_DIGEST_SIZE      32
 #define SHA256_HMAC_BLOCK_SIZE  64
 
@@ -59,17 +65,20 @@ static inline u32 Maj(u32 x, u32 y, u32 z)
 #define H6         0x1f83d9ab
 #define H7         0x5be0cd19
 
 #define H6         0x1f83d9ab
 #define H7         0x5be0cd19
 
-static inline void LOAD_OP(int I, u32 *W, const u8 *input)
+static inline void LOAD_OP(int I, u32 *W, const u8 *input)             /*{{{*/
 {
 {
-        W[I] = ntohl( ((u32*)(input))[I] );
+       W[I] = (  ((u32) input[I * 4 + 0] << 24)
+               | ((u32) input[I * 4 + 1] << 16)
+               | ((u32) input[I * 4 + 2] << 8)
+               | ((u32) input[I * 4 + 3]));
 }
 }
-
+                                                                       /*}}}*/
 static inline void BLEND_OP(int I, u32 *W)
 {
         W[I] = s1(W[I-2]) + W[I-7] + s0(W[I-15]) + W[I-16];
 }
 
 static inline void BLEND_OP(int I, u32 *W)
 {
         W[I] = s1(W[I-2]) + W[I-7] + s0(W[I-15]) + W[I-16];
 }
 
-static void sha256_transform(u32 *state, const u8 *input)
+static void sha256_transform(u32 *state, const u8 *input)              /*{{{*/
 {
         u32 a, b, c, d, e, f, g, h, t1, t2;
         u32 W[64];
 {
         u32 a, b, c, d, e, f, g, h, t1, t2;
         u32 W[64];
@@ -231,8 +240,8 @@ static void sha256_transform(u32 *state, const u8 *input)
         a = b = c = d = e = f = g = h = t1 = t2 = 0;
         memset(W, 0, 64 * sizeof(u32));
 }
         a = b = c = d = e = f = g = h = t1 = t2 = 0;
         memset(W, 0, 64 * sizeof(u32));
 }
-
-SHA256Summation::SHA256Summation()
+                                                                       /*}}}*/
+SHA256Summation::SHA256Summation()                                     /*{{{*/
 {
         Sum.state[0] = H0;
         Sum.state[1] = H1;
 {
         Sum.state[0] = H0;
         Sum.state[1] = H1;
@@ -246,8 +255,8 @@ SHA256Summation::SHA256Summation()
         memset(Sum.buf, 0, sizeof(Sum.buf));
         Done = false;
 }
         memset(Sum.buf, 0, sizeof(Sum.buf));
         Done = false;
 }
-
-bool SHA256Summation::Add(const u8 *data, unsigned long len)
+                                                                       /*}}}*/
+bool SHA256Summation::Add(const u8 *data, unsigned long len)           /*{{{*/
 {
         struct sha256_ctx *sctx = &Sum;
         unsigned int i, index, part_len;
 {
         struct sha256_ctx *sctx = &Sum;
         unsigned int i, index, part_len;
@@ -282,8 +291,8 @@ bool SHA256Summation::Add(const u8 *data, unsigned long len)
 
         return true;
 }
 
         return true;
 }
-
-SHA256SumValue SHA256Summation::Result()
+                                                                       /*}}}*/
+SHA256SumValue SHA256Summation::Result()                               /*{{{*/
 {
    struct sha256_ctx *sctx = &Sum;
    if (!Done) {
 {
    struct sha256_ctx *sctx = &Sum;
    if (!Done) {
@@ -331,7 +340,7 @@ SHA256SumValue SHA256Summation::Result()
 
    return res;
 }
 
    return res;
 }
-
+                                                                       /*}}}*/
 // SHA256SumValue::SHA256SumValue - Constructs the sum from a string   /*{{{*/
 // ---------------------------------------------------------------------
 /* The string form of a SHA256 is a 64 character hex number */
 // SHA256SumValue::SHA256SumValue - Constructs the sum from a string   /*{{{*/
 // ---------------------------------------------------------------------
 /* The string form of a SHA256 is a 64 character hex number */
@@ -340,7 +349,6 @@ SHA256SumValue::SHA256SumValue(string Str)
    memset(Sum,0,sizeof(Sum));
    Set(Str);
 }
    memset(Sum,0,sizeof(Sum));
    Set(Str);
 }
-
                                                                        /*}}}*/
 // SHA256SumValue::SHA256SumValue - Default constructor                /*{{{*/
 // ---------------------------------------------------------------------
                                                                        /*}}}*/
 // SHA256SumValue::SHA256SumValue - Default constructor                /*{{{*/
 // ---------------------------------------------------------------------
@@ -349,7 +357,6 @@ SHA256SumValue::SHA256SumValue()
 {
    memset(Sum,0,sizeof(Sum));
 }
 {
    memset(Sum,0,sizeof(Sum));
 }
-
                                                                        /*}}}*/
 // SHA256SumValue::Set - Set the sum from a string                     /*{{{*/
 // ---------------------------------------------------------------------
                                                                        /*}}}*/
 // SHA256SumValue::Set - Set the sum from a string                     /*{{{*/
 // ---------------------------------------------------------------------
@@ -382,9 +389,7 @@ string SHA256SumValue::Value() const
 
    return string(Result);
 }
 
    return string(Result);
 }
-
-
-
+                                                                       /*}}}*/
 // SHA256SumValue::operator == - Comparator                            /*{{{*/
 // ---------------------------------------------------------------------
 /* Call memcmp on the buffer */
 // SHA256SumValue::operator == - Comparator                            /*{{{*/
 // ---------------------------------------------------------------------
 /* Call memcmp on the buffer */
@@ -393,8 +398,6 @@ bool SHA256SumValue::operator == (const SHA256SumValue & rhs) const
    return memcmp(Sum,rhs.Sum,sizeof(Sum)) == 0;
 }
                                                                        /*}}}*/
    return memcmp(Sum,rhs.Sum,sizeof(Sum)) == 0;
 }
                                                                        /*}}}*/
-
-
 // SHA256Summation::AddFD - Add content of file into the checksum      /*{{{*/
 // ---------------------------------------------------------------------
 /* */
 // SHA256Summation::AddFD - Add content of file into the checksum      /*{{{*/
 // ---------------------------------------------------------------------
 /* */