summaryrefslogtreecommitdiff
path: root/include/ouroboros/md5.h
blob: 9da88d7ada38808bd38ab4af1295222ecd8ae9a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
 * Ouroboros - Copyright (C) 2016 - 2020
 *
 * 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., http://www.fsf.org/about/contact/.
 *
 *    -- 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 */