summaryrefslogtreecommitdiff
path: root/src/lib/hash.c
diff options
context:
space:
mode:
authorSander Vrijders <sander.vrijders@ugent.be>2017-08-17 16:56:00 +0200
committerSander Vrijders <sander.vrijders@ugent.be>2017-08-17 18:02:30 +0200
commit4d9c4025222e19dac9a90cabe8bd886e47959ad6 (patch)
tree3959a7206bfa3b5de2881d4404a2746a75aaefda /src/lib/hash.c
parentc7cb10810c447579cb20a8bc99049baeeb8e2065 (diff)
downloadouroboros-4d9c4025222e19dac9a90cabe8bd886e47959ad6.tar.gz
ouroboros-4d9c4025222e19dac9a90cabe8bd886e47959ad6.zip
lib: Add basic FRCT mechanisms
This adds the basic FRCT mechanisms to the library. Upon flow alloc or accept an FRCT instance is now created and used when reading or writing to the flow. The timerwheel has been refactored to allow recharging timers and removing them and is now part of the library. The first SDU sent over the connection has the DRF set and this initializes the connection. Sender and receiver inactivity timers are added.
Diffstat (limited to 'src/lib/hash.c')
-rw-r--r--src/lib/hash.c40
1 files changed, 24 insertions, 16 deletions
diff --git a/src/lib/hash.c b/src/lib/hash.c
index d8cabfd3..e062a0ad 100644
--- a/src/lib/hash.c
+++ b/src/lib/hash.c
@@ -64,45 +64,46 @@ uint16_t hash_len(enum hash_algo algo)
#endif
}
-void str_hash(enum hash_algo algo,
- void * buf,
- const char * str)
+void mem_hash(enum hash_algo algo,
+ void * dst,
+ const uint8_t * buf,
+ size_t len)
{
#ifdef HAVE_LIBGCRYPT
- gcry_md_hash_buffer(algo, buf, str, strlen(str));
+ gcry_md_hash_buffer(algo, dst, buf, len);
#else
struct sha3_ctx sha3_ctx;
struct md5_ctx md5_ctx;
switch (algo) {
case HASH_CRC32:
- memset(buf, 0, CRC32_HASH_LEN);
- crc32((uint32_t *) buf, str, strlen(str));
+ memset(dst, 0, CRC32_HASH_LEN);
+ crc32((uint32_t *) dst, buf, len);
break;
case HASH_MD5:
rhash_md5_init(&md5_ctx);
- rhash_md5_update(&md5_ctx, str, strlen(str));
- rhash_md5_final(&md5_ctx, (uint8_t *) buf);
+ rhash_md5_update(&md5_ctx, buf, len);
+ rhash_md5_final(&md5_ctx, (uint8_t *) dst);
break;
case HASH_SHA3_224:
rhash_sha3_224_init(&sha3_ctx);
- rhash_sha3_update(&sha3_ctx, str, strlen(str));
- rhash_sha3_final(&sha3_ctx, (uint8_t *) buf);
+ rhash_sha3_update(&sha3_ctx, buf, len);
+ rhash_sha3_final(&sha3_ctx, (uint8_t *) dst);
break;
case HASH_SHA3_256:
rhash_sha3_256_init(&sha3_ctx);
- rhash_sha3_update(&sha3_ctx, str, strlen(str));
- rhash_sha3_final(&sha3_ctx, (uint8_t *) buf);
+ rhash_sha3_update(&sha3_ctx, buf, len);
+ rhash_sha3_final(&sha3_ctx, (uint8_t *) dst);
break;
case HASH_SHA3_384:
rhash_sha3_384_init(&sha3_ctx);
- rhash_sha3_update(&sha3_ctx, str, strlen(str));
- rhash_sha3_final(&sha3_ctx, (uint8_t *) buf);
+ rhash_sha3_update(&sha3_ctx, buf, len);
+ rhash_sha3_final(&sha3_ctx, (uint8_t *) dst);
break;
case HASH_SHA3_512:
rhash_sha3_512_init(&sha3_ctx);
- rhash_sha3_update(&sha3_ctx, str, strlen(str));
- rhash_sha3_final(&sha3_ctx, (uint8_t *) buf);
+ rhash_sha3_update(&sha3_ctx, buf, len);
+ rhash_sha3_final(&sha3_ctx, (uint8_t *) dst);
break;
default:
assert(false);
@@ -110,3 +111,10 @@ void str_hash(enum hash_algo algo,
}
#endif
}
+
+void str_hash(enum hash_algo algo,
+ void * dst,
+ const char * str)
+{
+ return mem_hash(algo, dst, (const uint8_t *) str, strlen(str));
+}