[51770] | 1 | /** @file
|
---|
[73705] | 2 | * IPRT - Message-Digest Algorithm 4.
|
---|
[51770] | 3 | */
|
---|
| 4 |
|
---|
| 5 | /*
|
---|
[98103] | 6 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
[51770] | 7 | *
|
---|
[96407] | 8 | * This file is part of VirtualBox base platform packages, as
|
---|
| 9 | * available from https://www.virtualbox.org.
|
---|
[51770] | 10 | *
|
---|
[96407] | 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 | *
|
---|
[51770] | 24 | * The contents of this file may alternatively be used under the terms
|
---|
| 25 | * of the Common Development and Distribution License Version 1.0
|
---|
[96407] | 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
|
---|
[51770] | 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.
|
---|
[96407] | 32 | *
|
---|
| 33 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
[51770] | 34 | */
|
---|
| 35 |
|
---|
[76557] | 36 | #ifndef IPRT_INCLUDED_md4_h
|
---|
| 37 | #define IPRT_INCLUDED_md4_h
|
---|
[76507] | 38 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
| 39 | # pragma once
|
---|
| 40 | #endif
|
---|
[51770] | 41 |
|
---|
| 42 | #include <iprt/types.h>
|
---|
| 43 |
|
---|
| 44 | RT_C_DECLS_BEGIN
|
---|
| 45 |
|
---|
[73705] | 46 | /** @defgroup grp_rt_md4 RTMd4 - Message-Digest algorithm 4
|
---|
[51770] | 47 | * @ingroup grp_rt
|
---|
[73705] | 48 | *
|
---|
| 49 | * @note This is just for backwards compatibility and completeness.
|
---|
| 50 | *
|
---|
[51770] | 51 | * @{
|
---|
| 52 | */
|
---|
| 53 |
|
---|
[73705] | 54 | /** Size of a MD4 hash. */
|
---|
| 55 | #define RTMD4_HASH_SIZE 16
|
---|
| 56 | /** The length of a MD4 digest string. The terminator is not included. */
|
---|
| 57 | #define RTMD4_DIGEST_LEN 32
|
---|
[51770] | 58 |
|
---|
| 59 | /**
|
---|
[73705] | 60 | * MD4 hash algorithm context.
|
---|
[51770] | 61 | */
|
---|
[73705] | 62 | typedef union RTMD4CONTEXT
|
---|
[51770] | 63 | {
|
---|
[51822] | 64 | uint64_t u64BetterAlignment;
|
---|
[73705] | 65 | uint8_t abPadding[22*4 + 64 + 8];
|
---|
| 66 | #ifdef RT_MD4_PRIVATE_CONTEXT
|
---|
| 67 | MD4_CTX Private;
|
---|
[51770] | 68 | #endif
|
---|
[73705] | 69 | #ifdef RT_MD4_PRIVATE_ALT_CONTEXT
|
---|
| 70 | RTMD4ALTPRIVATECTX AltPrivate;
|
---|
[51822] | 71 | #endif
|
---|
[73705] | 72 | } RTMD4CONTEXT;
|
---|
[51770] | 73 |
|
---|
[73705] | 74 | /** Pointer to MD4 hash algorithm context. */
|
---|
| 75 | typedef RTMD4CONTEXT *PRTMD4CONTEXT;
|
---|
[51770] | 76 |
|
---|
| 77 |
|
---|
| 78 | /**
|
---|
[73705] | 79 | * Compute the MD4 hash of the data.
|
---|
[51770] | 80 | *
|
---|
| 81 | * @param pvBuf Pointer to data.
|
---|
| 82 | * @param cbBuf Length of data (in bytes).
|
---|
| 83 | * @param pabDigest Where to store the hash.
|
---|
| 84 | * (What's passed is a pointer to the caller's buffer.)
|
---|
| 85 | */
|
---|
[73705] | 86 | RTDECL(void) RTMd4(const void *pvBuf, size_t cbBuf, uint8_t pabDigest[RTMD4_HASH_SIZE]);
|
---|
[51770] | 87 |
|
---|
| 88 | /**
|
---|
[73705] | 89 | * Initialize MD4 context.
|
---|
[51770] | 90 | *
|
---|
[73705] | 91 | * @param pCtx Pointer to the MD4 context to initialize.
|
---|
[51770] | 92 | */
|
---|
[73705] | 93 | RTDECL(void) RTMd4Init(PRTMD4CONTEXT pCtx);
|
---|
[51770] | 94 |
|
---|
| 95 | /**
|
---|
[73705] | 96 | * Feed data into the MD4 computation.
|
---|
[51770] | 97 | *
|
---|
[73705] | 98 | * @param pCtx Pointer to the MD4 context.
|
---|
[51770] | 99 | * @param pvBuf Pointer to data.
|
---|
| 100 | * @param cbBuf Length of data (in bytes).
|
---|
| 101 | */
|
---|
[73705] | 102 | RTDECL(void) RTMd4Update(PRTMD4CONTEXT pCtx, const void *pvBuf, size_t cbBuf);
|
---|
[51770] | 103 |
|
---|
| 104 | /**
|
---|
[73705] | 105 | * Compute the MD4 hash of the data.
|
---|
[51770] | 106 | *
|
---|
[73705] | 107 | * @param pCtx Pointer to the MD4 context.
|
---|
[51770] | 108 | * @param pabDigest Where to store the hash. (What's passed is a pointer to
|
---|
| 109 | * the caller's buffer.)
|
---|
| 110 | */
|
---|
[73705] | 111 | RTDECL(void) RTMd4Final(PRTMD4CONTEXT pCtx, uint8_t pabDigest[RTMD4_HASH_SIZE]);
|
---|
[51770] | 112 |
|
---|
| 113 | /**
|
---|
[73705] | 114 | * Converts a MD4 hash to a digest string.
|
---|
[51770] | 115 | *
|
---|
| 116 | * @returns IPRT status code.
|
---|
| 117 | *
|
---|
[73705] | 118 | * @param pabDigest The binary digest returned by RTMd4Final or RTMd4.
|
---|
[51770] | 119 | * @param pszDigest Where to return the stringified digest.
|
---|
| 120 | * @param cchDigest The size of the output buffer. Should be at least
|
---|
[73705] | 121 | * RTMD4_STRING_LEN + 1 bytes.
|
---|
[51770] | 122 | */
|
---|
[73705] | 123 | RTDECL(int) RTMd4ToString(uint8_t const pabDigest[RTMD4_HASH_SIZE], char *pszDigest, size_t cchDigest);
|
---|
[51770] | 124 |
|
---|
| 125 | /**
|
---|
[73705] | 126 | * Converts a MD4 hash to a digest string.
|
---|
[51770] | 127 | *
|
---|
| 128 | * @returns IPRT status code.
|
---|
| 129 | *
|
---|
| 130 | * @param pszDigest The stringified digest. Leading and trailing spaces are
|
---|
| 131 | * ignored.
|
---|
| 132 | * @param pabDigest Where to store the hash. (What is passed is a pointer to
|
---|
| 133 | * the caller's buffer.)
|
---|
| 134 | */
|
---|
[73705] | 135 | RTDECL(int) RTMd4FromString(char const *pszDigest, uint8_t pabDigest[RTMD4_HASH_SIZE]);
|
---|
[51770] | 136 |
|
---|
| 137 | /** @} */
|
---|
| 138 |
|
---|
| 139 | RT_C_DECLS_END
|
---|
| 140 |
|
---|
[76585] | 141 | #endif /* !IPRT_INCLUDED_md4_h */
|
---|
[51770] | 142 |
|
---|