diff options
author | dimitri staessens <dimitri.staessens@ugent.be> | 2017-04-16 09:42:13 +0200 |
---|---|---|
committer | dimitri staessens <dimitri.staessens@ugent.be> | 2017-04-16 13:40:12 +0200 |
commit | bc651653d50145a8ca3a09b7b1146bf3089ccf47 (patch) | |
tree | b4c16263531b1b802fb867f3d26bf0fcb173fe28 /include | |
parent | ffc4468030398955ec56dac17934b43adfeab68b (diff) | |
download | ouroboros-bc651653d50145a8ca3a09b7b1146bf3089ccf47.tar.gz ouroboros-bc651653d50145a8ca3a09b7b1146bf3089ccf47.zip |
lib: Add implementation for MD5 hashes
Diffstat (limited to 'include')
-rw-r--r-- | include/ouroboros/hash.h | 5 | ||||
-rw-r--r-- | include/ouroboros/md5.h | 72 |
2 files changed, 75 insertions, 2 deletions
diff --git a/include/ouroboros/hash.h b/include/ouroboros/hash.h index 4779a9a6..a94b37ee 100644 --- a/include/ouroboros/hash.h +++ b/include/ouroboros/hash.h @@ -24,11 +24,12 @@ #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> #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, \ 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 */ |