VirtualBox

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

Last change on this file since 25477 was 23507, checked in by vboxsync, 15 years ago

IPRT: Added APIs for convering digests to/from strings.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.8 KB
Line 
1/** @file
2 * IPRT - Message-Digest algorithm 5.
3 */
4
5/*
6 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
26 * Clara, CA 95054 USA or visit http://www.sun.com if you need
27 * additional information or have any questions.
28 */
29
30#ifndef ___iprt_md5_h
31#define ___iprt_md5_h
32
33#include <iprt/types.h>
34
35/** @defgroup grp_rt_md5 RTMd5 - Message-Digest algorithm 5
36 * @ingroup grp_rt
37 * @{
38 */
39
40/** Size of a MD5 hash. */
41#define RTMD5_HASH_SIZE 16
42/** @deprecated Use RTMD5_HASH_SIZE. */
43#define RTMD5HASHSIZE RTMD5_HASH_SIZE
44/** Size of a MD5 hash. */
45#define RTMD5_STRING_LEN 32
46
47/**
48 * MD5 hash algorithm context.
49 */
50typedef struct RTMD5CONTEXT
51{
52 uint32_t in[16];
53 uint32_t buf[4];
54 uint32_t bits[2];
55} RTMD5CONTEXT;
56
57/** Pointer to MD5 hash algorithm context. */
58typedef RTMD5CONTEXT *PRTMD5CONTEXT;
59
60RT_C_DECLS_BEGIN
61
62/**
63 * Compute the MD5 hash of the data.
64 *
65 * @param pvBuf Pointer to data.
66 * @param cbBuf Length of data (in bytes).
67 * @param pabDigest Where to store the hash.
68 * (What's passed is a pointer to the caller's buffer.)
69 */
70RTDECL(void) RTMd5(const void *pvBuf, size_t cbBuf, uint8_t pabDigest[RTMD5HASHSIZE]);
71
72/**
73 * Initialize MD5 context.
74 *
75 * @param pCtx Pointer to the MD5 context to initialize.
76 */
77RTDECL(void) RTMd5Init(PRTMD5CONTEXT pCtx);
78
79/**
80 * Feed data into the MD5 computation.
81 *
82 * @param pCtx Pointer to the MD5 context.
83 * @param pvBuf Pointer to data.
84 * @param cbBuf Length of data (in bytes).
85 */
86RTDECL(void) RTMd5Update(PRTMD5CONTEXT pCtx, const void *pvBuf, size_t cbBuf);
87
88/**
89 * Compute the MD5 hash of the data.
90 *
91 * @param pabDigest Where to store the hash.
92 * (What's passed is a pointer to the caller's buffer.)
93 * @param pCtx Pointer to the MD5 context.
94 */
95RTDECL(void) RTMd5Final(uint8_t pabDigest[RTMD5HASHSIZE], PRTMD5CONTEXT pCtx);
96
97/**
98 * Converts a MD5 hash to a digest string.
99 *
100 * @returns IPRT status code.
101 *
102 * @param pabDigest The binary digest returned by RTMd5Final or RTMd5.
103 * @param pszDigest Where to return the stringified digest.
104 * @param cchDigest The size of the output buffer. Should be at least
105 * RTMD5_STRING_LEN + 1 bytes.
106 */
107RTDECL(int) RTMd5ToString(uint8_t const pabDigest[RTMD5_HASH_SIZE], char *pszDigest, size_t cchDigest);
108
109/**
110 * Converts a MD5 hash to a digest string.
111 *
112 * @returns IPRT status code.
113 *
114 * @param pszDigest The strigified digest. Leading and trailing spaces are
115 * ignored.
116 * @param pabDigest Where to store the hash. (What is passed is a pointer to
117 * the caller's buffer.)
118 */
119RTDECL(int) RTMd5FromString(char const *pszDigest, uint8_t pabDigest[RTMD5_HASH_SIZE]);
120
121
122RT_C_DECLS_END
123
124/** @} */
125
126#endif
127
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