md5.h
Go to the documentation of this file.
1 /**
2  * @file md5.h
3  * @brief MD5 (Message-Digest Algorithm)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2019 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneCrypto Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 1.9.6
29  **/
30 
31 #ifndef _MD5_H
32 #define _MD5_H
33 
34 //Dependencies
35 #include "core/crypto.h"
36 
37 //MD5 block size
38 #define MD5_BLOCK_SIZE 64
39 //MD5 digest size
40 #define MD5_DIGEST_SIZE 16
41 //Minimum length of the padding string
42 #define MD5_MIN_PAD_SIZE 9
43 //MD5 algorithm object identifier
44 #define MD5_OID md5Oid
45 //Common interface for hash algorithms
46 #define MD5_HASH_ALGO (&md5HashAlgo)
47 
48 //C++ guard
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52 
53 
54 /**
55  * @brief MD5 algorithm context
56  **/
57 
58 typedef struct
59 {
60  union
61  {
62  uint32_t h[4];
63  uint8_t digest[16];
64  };
65  union
66  {
67  uint32_t x[16];
68  uint8_t buffer[64];
69  };
70  size_t size;
71  uint64_t totalSize;
72 } Md5Context;
73 
74 
75 //MD5 related constants
76 extern const uint8_t md5Oid[8];
77 extern const HashAlgo md5HashAlgo;
78 
79 //MD5 related functions
80 error_t md5Compute(const void *data, size_t length, uint8_t *digest);
81 void md5Init(Md5Context *context);
82 void md5Update(Md5Context *context, const void *data, size_t length);
83 void md5Final(Md5Context *context, uint8_t *digest);
84 void md5FinalRaw(Md5Context *context, uint8_t *digest);
85 void md5ProcessBlock(Md5Context *context);
86 
87 //C++ guard
88 #ifdef __cplusplus
89 }
90 #endif
91 
92 #endif
error_t md5Compute(const void *data, size_t length, uint8_t *digest)
Digest a message using MD5.
Definition: md5.c:109
uint8_t length
Definition: dtls_misc.h:149
void md5ProcessBlock(Md5Context *context)
Process message in 16-word blocks.
Definition: md5.c:266
const uint8_t md5Oid[8]
Definition: md5.c:80
void md5Init(Md5Context *context)
Initialize MD5 message digest context.
Definition: md5.c:136
void md5Final(Md5Context *context, uint8_t *digest)
Finish the MD5 message digest.
Definition: md5.c:197
const HashAlgo md5HashAlgo
Definition: md5.c:83
uint8_t h
Definition: ndp.h:300
void md5FinalRaw(Md5Context *context, uint8_t *digest)
Finish the MD5 message digest (no padding is added)
Definition: md5.c:240
error_t
Error codes.
Definition: error.h:42
General definitions for cryptographic algorithms.
MD5 algorithm context.
Definition: md5.h:58
void md5Update(Md5Context *context, const void *data, size_t length)
Update the MD5 context with a portion of the message being hashed.
Definition: md5.c:158
uint64_t totalSize
Definition: md5.h:71
size_t size
Definition: md5.h:70
Common interface for hash algorithms.
Definition: crypto.h:1128
uint8_t data[]
Definition: dtls_misc.h:176