md2.h
Go to the documentation of this file.
1 /**
2  * @file md2.h
3  * @brief MD2 (Message-Digest Algorithm)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2024 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 2.4.0
29  **/
30 
31 #ifndef _MD2_H
32 #define _MD2_H
33 
34 //Dependencies
35 #include "core/crypto.h"
36 
37 //MD2 block size
38 #define MD2_BLOCK_SIZE 16
39 //MD2 digest size
40 #define MD2_DIGEST_SIZE 16
41 //Minimum length of the padding string
42 #define MD2_MIN_PAD_SIZE 1
43 //Common interface for hash algorithms
44 #define MD2_HASH_ALGO (&md2HashAlgo)
45 
46 //C++ guard
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
51 
52 /**
53  * @brief MD2 algorithm context
54  **/
55 
56 typedef struct
57 {
58 
59  union
60  {
61  uint8_t x[48];
62  uint8_t digest[16];
63  };
64  uint8_t m[16];
65  uint8_t c[16];
66  size_t size;
67 } Md2Context;
68 
69 
70 //MD2 related constants
71 extern const uint8_t MD2_OID[8];
72 extern const HashAlgo md2HashAlgo;
73 
74 //MD2 related functions
75 error_t md2Compute(const void *data, size_t length, uint8_t *digest);
76 void md2Init(Md2Context *context);
77 void md2Update(Md2Context *context, const void *data, size_t length);
78 void md2Final(Md2Context *context, uint8_t *digest);
79 void md2ProcessBlock(const uint8_t *m, uint8_t *x, uint8_t *c);
80 
81 //C++ guard
82 #ifdef __cplusplus
83 }
84 #endif
85 
86 #endif
General definitions for cryptographic algorithms.
error_t
Error codes.
Definition: error.h:43
uint8_t data[]
Definition: ethernet.h:222
uint8_t x
Definition: lldp_ext_med.h:211
void md2Final(Md2Context *context, uint8_t *digest)
Finish the MD2 message digest.
Definition: md2.c:198
const uint8_t MD2_OID[8]
Definition: md2.c:68
const HashAlgo md2HashAlgo
Definition: md2.c:71
void md2Update(Md2Context *context, const void *data, size_t length)
Update the MD2 context with a portion of the message being hashed.
Definition: md2.c:160
void md2Init(Md2Context *context)
Initialize MD2 message digest context.
Definition: md2.c:142
error_t md2Compute(const void *data, size_t length, uint8_t *digest)
Digest a message using MD2.
Definition: md2.c:97
void md2ProcessBlock(const uint8_t *m, uint8_t *x, uint8_t *c)
Process message in 16-word blocks.
Definition: md2.c:230
uint8_t c
Definition: ndp.h:514
uint8_t m
Definition: ndp.h:304
Common interface for hash algorithms.
Definition: crypto.h:1014
MD2 algorithm context.
Definition: md2.h:57
size_t size
Definition: md2.h:66
uint8_t length
Definition: tcp.h:368