1 | /** @file
|
---|
2 | * IPRT - Message-Digest Algorithm 2.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox base platform packages, as
|
---|
9 | * available from https://www.virtualbox.org.
|
---|
10 | *
|
---|
11 | * This program is free software; you can redistribute it and/or
|
---|
12 | * modify it under the terms of the GNU General Public License
|
---|
13 | * as published by the Free Software Foundation, in version 3 of the
|
---|
14 | * License.
|
---|
15 | *
|
---|
16 | * This program is distributed in the hope that it will be useful, but
|
---|
17 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
19 | * General Public License for more details.
|
---|
20 | *
|
---|
21 | * You should have received a copy of the GNU General Public License
|
---|
22 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
23 | *
|
---|
24 | * The contents of this file may alternatively be used under the terms
|
---|
25 | * of the Common Development and Distribution License Version 1.0
|
---|
26 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
27 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
28 | * CDDL are applicable instead of those of the GPL.
|
---|
29 | *
|
---|
30 | * You may elect to license modified versions of this file under the
|
---|
31 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
32 | *
|
---|
33 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
34 | */
|
---|
35 |
|
---|
36 | #ifndef IPRT_INCLUDED_md2_h
|
---|
37 | #define IPRT_INCLUDED_md2_h
|
---|
38 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
39 | # pragma once
|
---|
40 | #endif
|
---|
41 |
|
---|
42 | #include <iprt/types.h>
|
---|
43 |
|
---|
44 | RT_C_DECLS_BEGIN
|
---|
45 |
|
---|
46 | /** @defgroup grp_rt_md2 RTMd2 - Message-Digest algorithm 2
|
---|
47 | * @ingroup grp_rt
|
---|
48 | * @{
|
---|
49 | */
|
---|
50 |
|
---|
51 | /** Size of a MD2 hash. */
|
---|
52 | #define RTMD2_HASH_SIZE 16
|
---|
53 | /** The length of a MD2 digest string. The terminator is not included. */
|
---|
54 | #define RTMD2_DIGEST_LEN 32
|
---|
55 |
|
---|
56 | /**
|
---|
57 | * MD2 hash algorithm context.
|
---|
58 | */
|
---|
59 | typedef union RTMD2CONTEXT
|
---|
60 | {
|
---|
61 | uint64_t u64BetterAlignment;
|
---|
62 | uint8_t abPadding[4 + 16 + 16*4 + 16*4];
|
---|
63 | #ifdef RT_MD2_PRIVATE_CONTEXT
|
---|
64 | MD2_CTX Private;
|
---|
65 | #endif
|
---|
66 | #ifdef RT_MD2_PRIVATE_ALT_CONTEXT
|
---|
67 | RTMD2ALTPRIVATECTX AltPrivate;
|
---|
68 | #endif
|
---|
69 | } RTMD2CONTEXT;
|
---|
70 |
|
---|
71 | /** Pointer to MD2 hash algorithm context. */
|
---|
72 | typedef RTMD2CONTEXT *PRTMD2CONTEXT;
|
---|
73 |
|
---|
74 |
|
---|
75 | /**
|
---|
76 | * Compute the MD2 hash of the data.
|
---|
77 | *
|
---|
78 | * @param pvBuf Pointer to data.
|
---|
79 | * @param cbBuf Length of data (in bytes).
|
---|
80 | * @param pabDigest Where to store the hash.
|
---|
81 | * (What's passed is a pointer to the caller's buffer.)
|
---|
82 | */
|
---|
83 | RTDECL(void) RTMd2(const void *pvBuf, size_t cbBuf, uint8_t pabDigest[RTMD2_HASH_SIZE]);
|
---|
84 |
|
---|
85 | /**
|
---|
86 | * Initialize MD2 context.
|
---|
87 | *
|
---|
88 | * @param pCtx Pointer to the MD2 context to initialize.
|
---|
89 | */
|
---|
90 | RTDECL(void) RTMd2Init(PRTMD2CONTEXT pCtx);
|
---|
91 |
|
---|
92 | /**
|
---|
93 | * Feed data into the MD2 computation.
|
---|
94 | *
|
---|
95 | * @param pCtx Pointer to the MD2 context.
|
---|
96 | * @param pvBuf Pointer to data.
|
---|
97 | * @param cbBuf Length of data (in bytes).
|
---|
98 | */
|
---|
99 | RTDECL(void) RTMd2Update(PRTMD2CONTEXT pCtx, const void *pvBuf, size_t cbBuf);
|
---|
100 |
|
---|
101 | /**
|
---|
102 | * Compute the MD2 hash of the data.
|
---|
103 | *
|
---|
104 | * @param pCtx Pointer to the MD2 context.
|
---|
105 | * @param pabDigest Where to store the hash. (What's passed is a pointer to
|
---|
106 | * the caller's buffer.)
|
---|
107 | */
|
---|
108 | RTDECL(void) RTMd2Final(PRTMD2CONTEXT pCtx, uint8_t pabDigest[RTMD2_HASH_SIZE]);
|
---|
109 |
|
---|
110 | /**
|
---|
111 | * Converts a MD2 hash to a digest string.
|
---|
112 | *
|
---|
113 | * @returns IPRT status code.
|
---|
114 | *
|
---|
115 | * @param pabDigest The binary digest returned by RTMd2Final or RTMd2.
|
---|
116 | * @param pszDigest Where to return the stringified digest.
|
---|
117 | * @param cchDigest The size of the output buffer. Should be at least
|
---|
118 | * RTMD2_STRING_LEN + 1 bytes.
|
---|
119 | */
|
---|
120 | RTDECL(int) RTMd2ToString(uint8_t const pabDigest[RTMD2_HASH_SIZE], char *pszDigest, size_t cchDigest);
|
---|
121 |
|
---|
122 | /**
|
---|
123 | * Converts a MD2 hash to a digest string.
|
---|
124 | *
|
---|
125 | * @returns IPRT status code.
|
---|
126 | *
|
---|
127 | * @param pszDigest The stringified digest. Leading and trailing spaces are
|
---|
128 | * ignored.
|
---|
129 | * @param pabDigest Where to store the hash. (What is passed is a pointer to
|
---|
130 | * the caller's buffer.)
|
---|
131 | */
|
---|
132 | RTDECL(int) RTMd2FromString(char const *pszDigest, uint8_t pabDigest[RTMD2_HASH_SIZE]);
|
---|
133 |
|
---|
134 | /** @} */
|
---|
135 |
|
---|
136 | RT_C_DECLS_END
|
---|
137 |
|
---|
138 | #endif /* !IPRT_INCLUDED_md2_h */
|
---|
139 |
|
---|