]> git.ozlabs.org Git - ccan/commitdiff
Merge remote-tracking branch 'origin/pr/46'
authorRusty Russell <rusty@rustcorp.com.au>
Tue, 23 Aug 2016 03:37:07 +0000 (13:07 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Tue, 23 Aug 2016 03:37:07 +0000 (13:07 +0930)
Closes: 46
ccan/cast/cast.h
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 1f3a7aac1e48640f37868c0564e3851e203113e6..cd384c4636d8e5a51fa2ba55f97ff162b5dff84a 100644 (file)
@@ -38,8 +38,8 @@
  *     {
  *             size_t i;
  *             for (i = 0; i < strlen(haystack); i++)
- *             if (memcmp("needle", haystack+i, strlen("needle")) == 0)
- *                     return cast_const(char *, haystack+i);
+ *                     if (memcmp("needle", haystack+i, strlen("needle")) == 0)
+ *                             return cast_const(char *, haystack+i);
  *             return NULL;
  *     }
  */
index 4fa58c068a0cf9f4164b54f1d5049743bf771139..cdd0266d7deba8f37849df7bbe1cf3cd662252d2 100644 (file)
@@ -274,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;
@@ -284,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 {
@@ -297,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;
        }
index 38d38156f36391a04c64ace7b735ca8cab92193b..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>
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 40da0b4bb670d488b9a051b4307f8c41b9e8c42a..95c700692ce50a0f2a57163a41706f9bb8980c79 100644 (file)
@@ -181,7 +181,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;
@@ -191,7 +191,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 {
@@ -204,7 +204,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 eedaa94ee77df0cfe3e875ec45597f364bbea55f..d8b683ecee3747a2081592a8e0b624e3c2b8d98e 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>
@@ -82,7 +82,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;
 }