summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/ouroboros/crc32.h2
-rw-r--r--include/ouroboros/endian.h2
-rw-r--r--include/ouroboros/hash.h22
-rw-r--r--include/ouroboros/ipcp.h4
-rw-r--r--include/ouroboros/md5.h72
-rw-r--r--include/ouroboros/sha3.h6
6 files changed, 98 insertions, 10 deletions
diff --git a/include/ouroboros/crc32.h b/include/ouroboros/crc32.h
index dccdf7cb..800d6c4f 100644
--- a/include/ouroboros/crc32.h
+++ b/include/ouroboros/crc32.h
@@ -27,6 +27,8 @@
#include <stdint.h>
#include <stddef.h>
+#define CRC32_HASH_LEN 4
+
void crc32(uint32_t * crc,
const void * buf,
size_t len);
diff --git a/include/ouroboros/endian.h b/include/ouroboros/endian.h
index 691e3f8b..4738159e 100644
--- a/include/ouroboros/endian.h
+++ b/include/ouroboros/endian.h
@@ -83,7 +83,7 @@
#define hton64(x) htobe64(x)
#define hton32(x) htobe32(x)
#define ntoh64(x) betoh64(x)
-#define noth32(x) betoh32(x)
+#define ntoh32(x) betoh32(x)
#define hton16(x) htobe16(x)
#define ntoh16(x) betoh16(x)
diff --git a/include/ouroboros/hash.h b/include/ouroboros/hash.h
index 4779a9a6..60bfbe30 100644
--- a/include/ouroboros/hash.h
+++ b/include/ouroboros/hash.h
@@ -24,18 +24,30 @@
#ifndef OUROBOROS_LIB_HASH_H
#define OUROBOROS_LIB_HASH_H
-#include <ouroboros/sha3.h>
#include <ouroboros/crc32.h>
+#include <ouroboros/md5.h>
+#include <ouroboros/sha3.h>
+
+enum hash_algo {
+ HASH_CRC32 = 0,
+ HASH_MD5,
+ HASH_SHA3_224,
+ HASH_SHA3_256,
+ HASH_SHA3_384,
+ HASH_SHA3_512
+};
#define HASH_FMT "%02x%02x%02x%02x"
-#define HASH_VAL(hash) \
+#define HASH_VAL(hash) \
((*(unsigned int *) hash) & 0xFF000000) >> 24, \
((*(unsigned int *) hash) & 0x00FF0000) >> 16, \
((*(unsigned int *) hash) & 0x0000FF00) >> 8, \
((*(unsigned int *) hash) & 0x000000FF)
-/* FIXME: Implement specifying algorithm */
-void get_hash(uint8_t buf[],
- const char * name);
+uint16_t hash_len(enum hash_algo algo);
+
+void str_hash(enum hash_algo algo,
+ void * buf,
+ const char * str);
#endif /* OUROBOROS_LIB_HASH_H */
diff --git a/include/ouroboros/ipcp.h b/include/ouroboros/ipcp.h
index f439f29b..4c815b83 100644
--- a/include/ouroboros/ipcp.h
+++ b/include/ouroboros/ipcp.h
@@ -24,6 +24,8 @@
#ifndef OUROBOROS_IPCP_H
#define OUROBOROS_IPCP_H
+#include <ouroboros/hash.h>
+
#include <stdint.h>
#include <unistd.h>
#include <stdbool.h>
@@ -51,7 +53,7 @@ enum pol_gam {
struct ipcp_config {
char * dif_name;
enum ipcp_type type;
- uint16_t dir_hash_len;
+ enum hash_algo dir_hash_algo;
/* Normal DIF */
uint8_t addr_size;
diff --git a/include/ouroboros/md5.h b/include/ouroboros/md5.h
new file mode 100644
index 00000000..a628e6cb
--- /dev/null
+++ b/include/ouroboros/md5.h
@@ -0,0 +1,72 @@
+/*
+ * Ouroboros - Copyright (C) 2016 - 2017
+ *
+ * MD5 algorithm
+ *
+ * Dimitri Staessens <dimitri.staessens@ugent.be>
+ * Sander Vrijders <sander.vrijders@ugent.be>
+ *
+ * This implementation is adapted and redistributed from the RHASH
+ * project implementation of the MD5 algorithm
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ * -- original license
+ *
+ * md5.c - an implementation of the MD5 algorithm, based on RFC 1321.
+ *
+ * Copyright: 2007-2012 Aleksey Kravchenko <rhash.admin@gmail.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. Use this program at your own risk!
+ */
+
+#ifndef OUROBOROS_LIB_MD5_H
+#define OUROBOROS_LIB_MD5_H
+
+#include "unistd.h"
+#include <stdint.h>
+
+#define MD5_BLOCK_SIZE 64
+#define MD5_HASH_LEN 16
+
+struct md5_ctx
+{
+ /* 512-bit buffer for leftovers */
+ uint32_t message[MD5_BLOCK_SIZE / 4];
+ /* number of processed bytes */
+ uint64_t length;
+ /* 128-bit algorithm internal hashing state */
+ uint32_t hash[4];
+};
+
+void rhash_md5_init(struct md5_ctx *ctx);
+
+void rhash_md5_update(struct md5_ctx * ctx,
+ const void * msg,
+ size_t size);
+
+void rhash_md5_final(struct md5_ctx * ctx,
+ uint8_t * result);
+
+#endif /* OUROBOROS_LIB_MD5_H */
diff --git a/include/ouroboros/sha3.h b/include/ouroboros/sha3.h
index 17888870..2357b4aa 100644
--- a/include/ouroboros/sha3.h
+++ b/include/ouroboros/sha3.h
@@ -44,8 +44,8 @@
* or FITNESS FOR A PARTICULAR PURPOSE. Use this program at your own risk!
*/
-#ifndef OUROBOROS_SHA3_H
-#define OUROBOROS_SHA3_H
+#ifndef OUROBOROS_LIB_SHA3_H
+#define OUROBOROS_LIB_SHA3_H
#include <unistd.h>
#include <stdint.h>
@@ -83,4 +83,4 @@ void rhash_sha3_update(struct sha3_ctx * ctx,
void rhash_sha3_final(struct sha3_ctx * ctx,
uint8_t * res);
-#endif /* OUROBOROS_SHA3_H */
+#endif /* OUROBOROS_LIB_SHA3_H */