[1] | 1 | /** @file
|
---|
[8245] | 2 | * IPRT - Message-Digest algorithm 5.
|
---|
[1] | 3 | */
|
---|
| 4 |
|
---|
| 5 | /*
|
---|
[76553] | 6 | * Copyright (C) 2006-2019 Oracle Corporation
|
---|
[1] | 7 | *
|
---|
| 8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
| 9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
| 10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
[5999] | 11 | * General Public License (GPL) as published by the Free Software
|
---|
| 12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
| 13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
| 14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
| 15 | *
|
---|
| 16 | * The contents of this file may alternatively be used under the terms
|
---|
| 17 | * of the Common Development and Distribution License Version 1.0
|
---|
| 18 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
| 19 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
| 20 | * CDDL are applicable instead of those of the GPL.
|
---|
| 21 | *
|
---|
| 22 | * You may elect to license modified versions of this file under the
|
---|
| 23 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
[1] | 24 | */
|
---|
| 25 |
|
---|
[76557] | 26 | #ifndef IPRT_INCLUDED_md5_h
|
---|
| 27 | #define IPRT_INCLUDED_md5_h
|
---|
[76507] | 28 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
| 29 | # pragma once
|
---|
| 30 | #endif
|
---|
[1] | 31 |
|
---|
| 32 | #include <iprt/types.h>
|
---|
| 33 |
|
---|
| 34 | /** @defgroup grp_rt_md5 RTMd5 - Message-Digest algorithm 5
|
---|
| 35 | * @ingroup grp_rt
|
---|
| 36 | * @{
|
---|
| 37 | */
|
---|
| 38 |
|
---|
| 39 | /** Size of a MD5 hash. */
|
---|
[23507] | 40 | #define RTMD5_HASH_SIZE 16
|
---|
| 41 | /** @deprecated Use RTMD5_HASH_SIZE. */
|
---|
| 42 | #define RTMD5HASHSIZE RTMD5_HASH_SIZE
|
---|
[34449] | 43 | /** The length of a MD5 digest string. The terminator is not included. */
|
---|
| 44 | #define RTMD5_DIGEST_LEN 32
|
---|
| 45 | /** Size of a MD5 hash.
|
---|
| 46 | * @deprecated Use RTMD5_DIGEST_LEN */
|
---|
| 47 | #define RTMD5_STRING_LEN RTMD5_DIGEST_LEN
|
---|
[1] | 48 |
|
---|
| 49 | /**
|
---|
| 50 | * MD5 hash algorithm context.
|
---|
| 51 | */
|
---|
[51851] | 52 | typedef union RTMD5CONTEXT
|
---|
[1] | 53 | {
|
---|
[51851] | 54 | uint64_t u64BetterAlignment;
|
---|
| 55 | uint8_t abPadding[(4 + 6 + 16 + 1) * sizeof(uint32_t)];
|
---|
| 56 | /** Context used by md5-alt.cpp. */
|
---|
| 57 | struct
|
---|
| 58 | {
|
---|
| 59 | uint32_t in[16];
|
---|
| 60 | uint32_t buf[4];
|
---|
| 61 | uint32_t bits[2];
|
---|
| 62 | } AltPrivate;
|
---|
| 63 | #ifdef RT_MD5_OPENSSL_PRIVATE_CONTEXT
|
---|
| 64 | /** Context used by md5-openssl.cpp. */
|
---|
| 65 | MD5_CTX OsslPrivate;
|
---|
| 66 | #endif
|
---|
[1] | 67 | } RTMD5CONTEXT;
|
---|
| 68 | /** Pointer to MD5 hash algorithm context. */
|
---|
| 69 | typedef RTMD5CONTEXT *PRTMD5CONTEXT;
|
---|
| 70 |
|
---|
[20374] | 71 | RT_C_DECLS_BEGIN
|
---|
[1] | 72 |
|
---|
| 73 | /**
|
---|
[21918] | 74 | * Compute the MD5 hash of the data.
|
---|
| 75 | *
|
---|
| 76 | * @param pvBuf Pointer to data.
|
---|
| 77 | * @param cbBuf Length of data (in bytes).
|
---|
| 78 | * @param pabDigest Where to store the hash.
|
---|
| 79 | * (What's passed is a pointer to the caller's buffer.)
|
---|
| 80 | */
|
---|
| 81 | RTDECL(void) RTMd5(const void *pvBuf, size_t cbBuf, uint8_t pabDigest[RTMD5HASHSIZE]);
|
---|
| 82 |
|
---|
| 83 | /**
|
---|
[1] | 84 | * Initialize MD5 context.
|
---|
| 85 | *
|
---|
| 86 | * @param pCtx Pointer to the MD5 context to initialize.
|
---|
| 87 | */
|
---|
| 88 | RTDECL(void) RTMd5Init(PRTMD5CONTEXT pCtx);
|
---|
| 89 |
|
---|
| 90 | /**
|
---|
| 91 | * Feed data into the MD5 computation.
|
---|
| 92 | *
|
---|
| 93 | * @param pCtx Pointer to the MD5 context.
|
---|
| 94 | * @param pvBuf Pointer to data.
|
---|
| 95 | * @param cbBuf Length of data (in bytes).
|
---|
| 96 | */
|
---|
| 97 | RTDECL(void) RTMd5Update(PRTMD5CONTEXT pCtx, const void *pvBuf, size_t cbBuf);
|
---|
| 98 |
|
---|
| 99 | /**
|
---|
| 100 | * Compute the MD5 hash of the data.
|
---|
| 101 | *
|
---|
[21918] | 102 | * @param pabDigest Where to store the hash.
|
---|
| 103 | * (What's passed is a pointer to the caller's buffer.)
|
---|
| 104 | * @param pCtx Pointer to the MD5 context.
|
---|
[1] | 105 | */
|
---|
| 106 | RTDECL(void) RTMd5Final(uint8_t pabDigest[RTMD5HASHSIZE], PRTMD5CONTEXT pCtx);
|
---|
| 107 |
|
---|
[23507] | 108 | /**
|
---|
| 109 | * Converts a MD5 hash to a digest string.
|
---|
| 110 | *
|
---|
| 111 | * @returns IPRT status code.
|
---|
| 112 | *
|
---|
| 113 | * @param pabDigest The binary digest returned by RTMd5Final or RTMd5.
|
---|
| 114 | * @param pszDigest Where to return the stringified digest.
|
---|
| 115 | * @param cchDigest The size of the output buffer. Should be at least
|
---|
| 116 | * RTMD5_STRING_LEN + 1 bytes.
|
---|
| 117 | */
|
---|
| 118 | RTDECL(int) RTMd5ToString(uint8_t const pabDigest[RTMD5_HASH_SIZE], char *pszDigest, size_t cchDigest);
|
---|
| 119 |
|
---|
| 120 | /**
|
---|
| 121 | * Converts a MD5 hash to a digest string.
|
---|
| 122 | *
|
---|
| 123 | * @returns IPRT status code.
|
---|
| 124 | *
|
---|
[33540] | 125 | * @param pszDigest The stringified digest. Leading and trailing spaces are
|
---|
[23507] | 126 | * ignored.
|
---|
| 127 | * @param pabDigest Where to store the hash. (What is passed is a pointer to
|
---|
| 128 | * the caller's buffer.)
|
---|
| 129 | */
|
---|
| 130 | RTDECL(int) RTMd5FromString(char const *pszDigest, uint8_t pabDigest[RTMD5_HASH_SIZE]);
|
---|
| 131 |
|
---|
| 132 |
|
---|
[20374] | 133 | RT_C_DECLS_END
|
---|
[1] | 134 |
|
---|
| 135 | /** @} */
|
---|
| 136 |
|
---|
[76585] | 137 | #endif /* !IPRT_INCLUDED_md5_h */
|
---|
[21918] | 138 |
|
---|