KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
md5.h
Go to the documentation of this file.
1/* KallistiOS ##version##
2
3 kos/md5.h
4 Copyright (C) 2010 Lawrence Sebald
5*/
6
7#ifndef __KOS_MD5_H
8#define __KOS_MD5_H
9
10/** \file kos/md5.h
11 \brief Message Digest 5 (MD5) hashing support.
12
13 This file provides the functionality to compute MD5 hashes over any data
14 buffer. While MD5 isn't considered a safe cryptographic hash any more, it
15 still has its uses.
16
17 \author Lawrence Sebald
18*/
19
20#include <sys/cdefs.h>
21__BEGIN_DECLS
22
23#include <arch/types.h>
24
25/** \brief MD5 context.
26
27 This structure contains the variables needed to maintain the internal state
28 of the MD5 code. You should not manipulate these variables manually, but
29 rather use the kos_md5_* functions to do everything you need.
30
31 \headerfile kos/md5.h
32*/
33typedef struct kos_md5_cxt {
34 uint64 size; /**< \brief Size of the data in buf. */
35 uint32 hash[4]; /**< \brief Intermediate hash value. */
36 uint8 buf[64]; /**< \brief Temporary storage of values to be hashed. */
38
39/** \brief Initialize a MD5 context.
40
41 This function initializes the context passed in to the initial state needed
42 for computing a MD5 hash. You must call this function to initialize the
43 state variables before attempting to hash any blocks of data.
44
45 \param cxt The MD5 context to initialize.
46*/
48
49/** \brief Hash a block of data with MD5.
50
51 This function is used to hash the block of data input into the function with
52 MD5, updating the state context as appropriate. If the data does not fill an
53 entire block of 64-bytes (or there is left-over data), it will be stored in
54 the context for hashing with a future block. Thus, do not attempt to read
55 the intermediate hash value, as it will not be complete.
56
57 \param cxt The MD5 context to use.
58 \param input The block of data to hash.
59 \param size The number of bytes of input data passed in.
60*/
61void kos_md5_hash_block(kos_md5_cxt_t *cxt, const uint8 *input, uint32 size);
62
63/** \brief Complete a MD5 hash.
64
65 This function computes the final MD5 hash of the context passed in,
66 returning the completed digest in the output parameter.
67
68 \param cxt The MD5 context to finalize.
69 \param output Where to store the final digest.
70*/
71void kos_md5_finish(kos_md5_cxt_t *cxt, uint8 output[16]);
72
73/** \brief Compute the hash of a block of data with MD5.
74
75 This function is used to hash a full block of data without messing around
76 with any contexts or anything else of the sort. This is appropriate if you
77 have all the data you want to hash readily available. It takes care of all
78 of the context setup and teardown for you.
79
80 \param input The data to hash.
81 \param size The number of bytes of input data passed in.
82 \param output Where to store the final message digest.
83*/
84void kos_md5(const uint8 *input, uint32 size, uint8 output[16]);
85
86__END_DECLS
87
88#endif /* !__KOS_MD5_H */
unsigned long long uint64
64-bit unsigned integer
Definition types.h:32
unsigned long uint32
32-bit unsigned integer
Definition types.h:33
unsigned char uint8
8-bit unsigned integer
Definition types.h:35
void kos_md5_start(kos_md5_cxt_t *cxt)
Initialize a MD5 context.
void kos_md5_hash_block(kos_md5_cxt_t *cxt, const uint8 *input, uint32 size)
Hash a block of data with MD5.
void kos_md5_finish(kos_md5_cxt_t *cxt, uint8 output[16])
Complete a MD5 hash.
void kos_md5(const uint8 *input, uint32 size, uint8 output[16])
Compute the hash of a block of data with MD5.
MD5 context.
Definition md5.h:33
uint64 size
Size of the data in buf.
Definition md5.h:34
Common integer types.