* {
* 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;
* }
*/
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;
}
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 {
}
if (len) {
- // Fill the buffer with what remains.
+ /* Fill the buffer with what remains. */
memcpy(ctx->buf.u8 + bufsize, data, len);
ctx->bytes += len;
}
#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>
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();
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;
}
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 {
}
if (len) {
- // Fill the buffer with what remains.
+ /* Fill the buffer with what remains. */
memcpy(ctx->buf.u8 + bufsize, data, len);
ctx->bytes += len;
}
#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>
/**
* 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:
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;
}