]> git.ozlabs.org Git - ccan/commitdiff
Merge remote-tracking branch 'origin/pr/47'
authorRusty Russell <rusty@rustcorp.com.au>
Tue, 23 Aug 2016 03:39:44 +0000 (13:09 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Tue, 23 Aug 2016 03:39:44 +0000 (13:09 +0930)
Closes: 47
ccan/crypto/ripemd160/_info
ccan/crypto/ripemd160/ripemd160.c
ccan/crypto/ripemd160/ripemd160.h
ccan/crypto/sha256/benchmarks/double-sha-bench.c
ccan/crypto/sha256/sha256.c
ccan/crypto/sha256/sha256.h
ccan/str/hex/hex.c

index 4df7d4d28c8afd8bb5856600c7edc1756a1d3ee6..db37b681bc9aa49224df91a971b2f0eb4389285c 100644 (file)
@@ -40,6 +40,7 @@ int main(int argc, char *argv[])
                return 1;
 
        if (strcmp(argv[1], "depends") == 0) {
+               printf("ccan/compiler\n");
                printf("ccan/endian\n");
                return 0;
        }
index 46a6c950e04396352aedc667a4ade9ef09dfce26..cdd0266d7deba8f37849df7bbe1cf3cd662252d2 100644 (file)
@@ -8,6 +8,7 @@
  */
 #include <ccan/crypto/ripemd160/ripemd160.h>
 #include <ccan/endian/endian.h>
+#include <ccan/compiler/compiler.h>
 #include <stdbool.h>
 #include <assert.h>
 #include <string.h>
@@ -21,7 +22,7 @@ static void invalidate_ripemd160(struct ripemd160_ctx *ctx)
 #endif
 }
 
-static void check_ripemd160(struct ripemd160_ctx *ctx)
+static void check_ripemd160(struct ripemd160_ctx *ctx UNUSED)
 {
 #ifdef CCAN_CRYPTO_RIPEMD160_USE_OPENSSL
        assert(ctx->c.num != -1U);
@@ -54,19 +55,9 @@ static uint32_t inline f3(uint32_t x, uint32_t y, uint32_t z) { return (x | ~y)
 static uint32_t inline f4(uint32_t x, uint32_t y, uint32_t z) { return (x & z) | (y & ~z); }
 static uint32_t inline f5(uint32_t x, uint32_t y, uint32_t z) { return x ^ (y | ~z); }
 
-/** Initialize RIPEMD-160 state. */
-static void inline Initialize(uint32_t* s)
-{
-    s[0] = 0x67452301ul;
-    s[1] = 0xEFCDAB89ul;
-    s[2] = 0x98BADCFEul;
-    s[3] = 0x10325476ul;
-    s[4] = 0xC3D2E1F0ul;
-}
-
 static uint32_t inline rol(uint32_t x, int i) { return (x << i) | (x >> (32 - i)); }
 
-static void inline Round(uint32_t *a, uint32_t b, uint32_t *c, uint32_t d, uint32_t e, uint32_t f, uint32_t x, uint32_t k, int r)
+static void inline Round(uint32_t *a, uint32_t b UNUSED, uint32_t *c, uint32_t d UNUSED, uint32_t e, uint32_t f, uint32_t x, uint32_t k, int r)
 {
     *a = rol(*a + f + x + k, r) + e;
     *c = rol(*c, 10);
@@ -93,6 +84,7 @@ static void Transform(uint32_t *s, const uint32_t *chunk)
     uint32_t w4 = le32_to_cpu(chunk[4]), w5 = le32_to_cpu(chunk[5]), w6 = le32_to_cpu(chunk[6]), w7 = le32_to_cpu(chunk[7]);
     uint32_t w8 = le32_to_cpu(chunk[8]), w9 = le32_to_cpu(chunk[9]), w10 = le32_to_cpu(chunk[10]), w11 = le32_to_cpu(chunk[11]);
     uint32_t w12 = le32_to_cpu(chunk[12]), w13 = le32_to_cpu(chunk[13]), w14 = le32_to_cpu(chunk[14]), w15 = le32_to_cpu(chunk[15]);
+    uint32_t t;
 
     R11(&a1, b1, &c1, d1, e1, w0, 11);
     R12(&a2, b2, &c2, d2, e2, w5, 8);
@@ -259,7 +251,7 @@ static void Transform(uint32_t *s, const uint32_t *chunk)
     R51(&b1, c1, &d1, e1, a1, w13, 6);
     R52(&b2, c2, &d2, e2, a2, w11, 11);
 
-    uint32_t t = s[0];
+    t = s[0];
     s[0] = s[1] + c1 + d2;
     s[1] = s[2] + d1 + e2;
     s[2] = s[3] + e1 + a2;
@@ -267,7 +259,7 @@ static void Transform(uint32_t *s, const uint32_t *chunk)
     s[4] = t + b1 + c2;
 }
 
-static bool alignment_ok(const void *p, size_t n)
+static bool alignment_ok(const void *p UNUSED, size_t n UNUSED)
 {
 #if HAVE_UNALIGNED_ACCESS
        return true;
@@ -282,7 +274,7 @@ static void add(struct ripemd160_ctx *ctx, const void *p, size_t len)
        size_t bufsize = ctx->bytes % 64;
 
        if (bufsize + len >= 64) {
-               // Fill the buffer, and process it.
+               /* Fill the buffer, and process it. */
                memcpy(ctx->buf.u8 + bufsize, data, 64 - bufsize);
                ctx->bytes += 64 - bufsize;
                data += 64 - bufsize;
@@ -292,7 +284,7 @@ static void add(struct ripemd160_ctx *ctx, const void *p, size_t len)
        }
 
        while (len >= 64) {
-               // Process full chunks directly from the source.
+               /* Process full chunks directly from the source. */
                if (alignment_ok(data, sizeof(uint32_t)))
                        Transform(ctx->s, (const uint32_t *)data);
                else {
@@ -305,7 +297,7 @@ static void add(struct ripemd160_ctx *ctx, const void *p, size_t len)
        }
            
        if (len) {
-               // Fill the buffer with what remains.
+               /* Fill the buffer with what remains. */
                memcpy(ctx->buf.u8 + bufsize, data, len);
                ctx->bytes += len;
        }
@@ -340,13 +332,13 @@ void ripemd160_done(struct ripemd160_ctx *ctx, struct ripemd160 *res)
 }
 #endif
 
-void ripemd160(struct ripemd160 *sha, const void *p, size_t size)
+void ripemd160(struct ripemd160 *ripemd, const void *p, size_t size)
 {
        struct ripemd160_ctx ctx;
 
        ripemd160_init(&ctx);
        ripemd160_update(&ctx, p, size);
-       ripemd160_done(&ctx, sha);
+       ripemd160_done(&ctx, ripemd);
 }
        
 void ripemd160_u8(struct ripemd160_ctx *ctx, uint8_t v)
index e29e42bb044b3ac63134205731dd3c9c51e5bab8..377a07df407fae01ef0b3ac0aaf8208aa62a8645 100644 (file)
@@ -6,7 +6,7 @@
 #include <stdlib.h>
 
 /* Uncomment this to use openssl's RIPEMD160 routines (and link with -lcrypto) */
-//#define CCAN_CRYPTO_RIPEMD160_USE_OPENSSL 1
+/*#define CCAN_CRYPTO_RIPEMD160_USE_OPENSSL 1*/
 
 #ifdef CCAN_CRYPTO_RIPEMD160_USE_OPENSSL
 #include <openssl/ripemd.h>
@@ -37,7 +37,7 @@ struct ripemd160 {
  * The bytes pointed to by @p is RIPEMD160 hashed into @ripemd160.  This is
  * equivalent to ripemd160_init(), ripemd160_update() then ripemd160_done().
  */
-void ripemd160(struct ripemd160 *sha, const void *p, size_t size);
+void ripemd160(struct ripemd160 *ripemd, const void *p, size_t size);
 
 /**
  * struct ripemd160_ctx - structure to store running context for ripemd160
index b66531b853bfdbf0268664ec2553707b06d42357..09a9900e41d9c9dc218b77d01f89aafaa5869bef 100644 (file)
@@ -37,7 +37,7 @@ int main(int argc, char *argv[])
        memset(&block, 0, sizeof(block));
        sha256(&block.h, &n, sizeof(n));
        block.u8[sizeof(block.h)] = 0x80;
-       // Size is 256 bits
+       /* Size is 256 bits */
        block.u8[sizeof(block)-2] = 1;
 
        start = time_now();
index 21d17c40dd9d97562f128c830ba6f46f34fb75a0..d42b47b0a587c3df97b0e67f785800715cc12da8 100644 (file)
@@ -182,7 +182,7 @@ static void add(struct sha256_ctx *ctx, const void *p, size_t len)
        size_t bufsize = ctx->bytes % 64;
 
        if (bufsize + len >= 64) {
-               // Fill the buffer, and process it.
+               /* Fill the buffer, and process it. */
                memcpy(ctx->buf.u8 + bufsize, data, 64 - bufsize);
                ctx->bytes += 64 - bufsize;
                data += 64 - bufsize;
@@ -192,7 +192,7 @@ static void add(struct sha256_ctx *ctx, const void *p, size_t len)
        }
 
        while (len >= 64) {
-               // Process full chunks directly from the source.
+               /* Process full chunks directly from the source. */
                if (alignment_ok(data, sizeof(uint32_t)))
                        Transform(ctx->s, (const uint32_t *)data);
                else {
@@ -205,7 +205,7 @@ static void add(struct sha256_ctx *ctx, const void *p, size_t len)
        }
            
        if (len) {
-               // Fill the buffer with what remains.
+               /* Fill the buffer with what remains. */
                memcpy(ctx->buf.u8 + bufsize, data, len);
                ctx->bytes += len;
        }
index fc5af21b8b9628065e6318e4ae09e32abccc53b7..9a310b9564c6be7bfcaca90a718d280788f303c7 100644 (file)
@@ -6,7 +6,7 @@
 #include <stdlib.h>
 
 /* Uncomment this to use openssl's SHA256 routines (and link with -lcrypto) */
-//#define CCAN_CRYPTO_SHA256_USE_OPENSSL 1
+/*#define CCAN_CRYPTO_SHA256_USE_OPENSSL 1*/
 
 #ifdef CCAN_CRYPTO_SHA256_USE_OPENSSL
 #include <openssl/sha.h>
@@ -80,7 +80,7 @@ void sha256_init(struct sha256_ctx *ctx);
 /**
  * SHA256_INIT - initializer for an SHA256 context.
  *
- * This can be used to staticly initialize an SHA256 context (instead
+ * This can be used to statically initialize an SHA256 context (instead
  * of sha256_init()).
  *
  * Example:
index fd4074f3d6a4f484e33674fa80b126b0fb1416db..6e031779fe87b325670040606fafefdef562c1f4 100644 (file)
@@ -50,21 +50,17 @@ static char hexchar(unsigned int val)
 
 bool hex_encode(const void *buf, size_t bufsize, char *dest, size_t destsize)
 {
-       size_t used = 0;
+       size_t i;
 
-       if (destsize < 1)
+       if (destsize < hex_str_size(bufsize))
                return false;
 
-       while (used < bufsize) {
-               unsigned int c = ((const unsigned char *)buf)[used];
-               if (destsize < 3)
-                       return false;
+       for (i = 0; i < bufsize; i++) {
+               unsigned int c = ((const unsigned char *)buf)[i];
                *(dest++) = hexchar(c >> 4);
                *(dest++) = hexchar(c & 0xF);
-               used++;
-               destsize -= 2;
        }
        *dest = '\0';
 
-       return used + 1;
+       return true;
 }