VirtualBox

source: vbox/trunk/include/iprt/md5.h@ 78286

Last change on this file since 78286 was 76585, checked in by vboxsync, 6 years ago

*: scm --fix-header-guard-endif

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.1 KB
Line 
1/** @file
2 * IPRT - Message-Digest algorithm 5.
3 */
4
5/*
6 * Copyright (C) 2006-2019 Oracle Corporation
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
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.
24 */
25
26#ifndef IPRT_INCLUDED_md5_h
27#define IPRT_INCLUDED_md5_h
28#ifndef RT_WITHOUT_PRAGMA_ONCE
29# pragma once
30#endif
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. */
40#define RTMD5_HASH_SIZE 16
41/** @deprecated Use RTMD5_HASH_SIZE. */
42#define RTMD5HASHSIZE RTMD5_HASH_SIZE
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
48
49/**
50 * MD5 hash algorithm context.
51 */
52typedef union RTMD5CONTEXT
53{
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
67} RTMD5CONTEXT;
68/** Pointer to MD5 hash algorithm context. */
69typedef RTMD5CONTEXT *PRTMD5CONTEXT;
70
71RT_C_DECLS_BEGIN
72
73/**
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 */
81RTDECL(void) RTMd5(const void *pvBuf, size_t cbBuf, uint8_t pabDigest[RTMD5HASHSIZE]);
82
83/**
84 * Initialize MD5 context.
85 *
86 * @param pCtx Pointer to the MD5 context to initialize.
87 */
88RTDECL(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 */
97RTDECL(void) RTMd5Update(PRTMD5CONTEXT pCtx, const void *pvBuf, size_t cbBuf);
98
99/**
100 * Compute the MD5 hash of the data.
101 *
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.
105 */
106RTDECL(void) RTMd5Final(uint8_t pabDigest[RTMD5HASHSIZE], PRTMD5CONTEXT pCtx);
107
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 */
118RTDECL(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 *
125 * @param pszDigest The stringified digest. Leading and trailing spaces are
126 * ignored.
127 * @param pabDigest Where to store the hash. (What is passed is a pointer to
128 * the caller's buffer.)
129 */
130RTDECL(int) RTMd5FromString(char const *pszDigest, uint8_t pabDigest[RTMD5_HASH_SIZE]);
131
132
133RT_C_DECLS_END
134
135/** @} */
136
137#endif /* !IPRT_INCLUDED_md5_h */
138
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette