All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
md4.h
Go to the documentation of this file.
1 #ifndef _FR_MD4_H
2 #define _FR_MD4_H
3 /**
4  * $Id: 6c8f5faf40a7a485f8eb174f28f25bcf4cfa2bbb $
5  *
6  * @note license is LGPL, but largely derived from a public domain source.
7  *
8  * @file include/md4.h
9  * @brief Structures and prototypes for md4.
10  */
11 RCSIDH(md4_h, "$Id: 6c8f5faf40a7a485f8eb174f28f25bcf4cfa2bbb $")
12 
13 #ifdef HAVE_INTTYPES_H
14 # include <inttypes.h>
15 #endif
16 
17 #ifdef HAVE_SYS_TYPES_H
18 # include <sys/types.h>
19 #endif
20 
21 #ifdef HAVE_STDINT_H
22 # include <stdint.h>
23 #endif
24 
25 #include <string.h>
26 
27 #ifdef HAVE_OPENSSL_EVP_H
28 # include <openssl/evp.h>
29 #endif
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 #ifndef MD4_DIGEST_LENGTH
36 # define MD4_DIGEST_LENGTH 16
37 #endif
38 
39 #ifndef HAVE_OPENSSL_EVP_H
40 /*
41  * The MD5 code used here and in md4.c was originally retrieved from:
42  * http://www.openbsd.org/cgi-bin/cvsweb/src/include/md4.h?rev=1.12
43  *
44  * This code implements the MD4 message-digest algorithm.
45  * The algorithm is due to Ron Rivest. This code was
46  * written by Colin Plumb in 1993, no copyright is claimed.
47  * This code is in the public domain; do with it what you wish.
48  * Todd C. Miller modified the MD5 code to do MD4 based on RFC 1186.
49  *
50  * Equivalent code is available from RSA Data Security, Inc.
51  * This code has been tested against that, and is equivalent,
52  * except that you don't need to include two pages of legalese
53  * with every copy.
54  */
55 # define MD4_BLOCK_LENGTH 64
56 # define MD4_DIGEST_STRING_LENGTH (MD4_DIGEST_LENGTH * 2 + 1)
57 
58 typedef struct FR_MD4Context {
59  uint32_t state[4]; //!< State.
60  uint32_t count[2]; //!< Number of bits, mod 2^64.
61  uint8_t buffer[MD4_BLOCK_LENGTH]; //!< Input buffer.
62 } FR_MD4_CTX;
63 
64 void fr_md4_init(FR_MD4_CTX *ctx);
65 void fr_md4_update(FR_MD4_CTX *ctx, uint8_t const *in, size_t inlen)
66  CC_BOUNDED(__string__, 2, 3);
67 void fr_md4_final(uint8_t out[MD4_DIGEST_LENGTH], FR_MD4_CTX *ctx)
68  CC_BOUNDED(__minbytes__, 1, MD4_DIGEST_LENGTH);
69 void fr_md4_transform(uint32_t buf[4], uint8_t const inc[MD4_BLOCK_LENGTH])
70  CC_BOUNDED(__size__, 1, 4, 4)
71  CC_BOUNDED(__minbytes__, 2, MD4_BLOCK_LENGTH);
72 #else /* HAVE_OPENSSL_EVP_H */
74 # define FR_MD4_CTX EVP_MD_CTX
75 # define fr_md4_init(_ctx) do { \
76  EVP_MD_CTX_init(_ctx);\
77  EVP_DigestInit(_ctx, EVP_md4());\
78 } while (0)
79 # define fr_md4_update EVP_DigestUpdate
80 # define fr_md4_final(_out, _ctx) EVP_DigestFinal_ex(_ctx, _out, NULL)
81 #endif
82 
83 /* md4.c */
84 void fr_md4_calc(uint8_t out[MD4_DIGEST_LENGTH], uint8_t const *in, size_t inlen);
85 
86 #ifdef __cplusplus
87 }
88 #endif
89 #endif /* _FR_MD4_H */
#define RCSIDH(h, id)
Definition: build.h:136
uint32_t count[2]
Number of bits, mod 2^64.
Definition: md4.h:60
void fr_md4_calc(uint8_t out[MD4_DIGEST_LENGTH], uint8_t const *in, size_t inlen)
Calculate the MD4 hash of the contents of a buffer.
Definition: md4.c:24
void fr_md4_init(FR_MD4_CTX *ctx)
Initialise a new MD4 context.
Definition: md4.c:115
void fr_md4_transform(uint32_t buf[4], uint8_t const inc[MD4_BLOCK_LENGTH]) CC_BOUNDED(__minbytes__
void fr_md4_update(FR_MD4_CTX *ctx, uint8_t const *in, size_t inlen) CC_BOUNDED(__string__
void void fr_md4_final(uint8_t out[MD4_DIGEST_LENGTH], FR_MD4_CTX *ctx) CC_BOUNDED(__minbytes__
struct FR_MD4Context FR_MD4_CTX
#define CC_BOUNDED(...)
Definition: build.h:77
uint32_t state[4]
State.
Definition: md4.h:59
#define MD4_BLOCK_LENGTH
Definition: md4.h:55
#define MD4_DIGEST_LENGTH
Definition: md4.h:36
#define USES_APPLE_DEPRECATED_API
Definition: build.h:122
uint8_t buffer[MD4_BLOCK_LENGTH]
Input buffer.
Definition: md4.h:61