VirtualBox

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

Last change on this file since 61776 was 56291, checked in by vboxsync, 9 years ago

include: Updated (C) year.

  • 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-2015 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_md5_h
27#define ___iprt_md5_h
28
29#include <iprt/types.h>
30
31/** @defgroup grp_rt_md5 RTMd5 - Message-Digest algorithm 5
32 * @ingroup grp_rt
33 * @{
34 */
35
36/** Size of a MD5 hash. */
37#define RTMD5_HASH_SIZE 16
38/** @deprecated Use RTMD5_HASH_SIZE. */
39#define RTMD5HASHSIZE RTMD5_HASH_SIZE
40/** The length of a MD5 digest string. The terminator is not included. */
41#define RTMD5_DIGEST_LEN 32
42/** Size of a MD5 hash.
43 * @deprecated Use RTMD5_DIGEST_LEN */
44#define RTMD5_STRING_LEN RTMD5_DIGEST_LEN
45
46/**
47 * MD5 hash algorithm context.
48 */
49typedef union RTMD5CONTEXT
50{
51 uint64_t u64BetterAlignment;
52 uint8_t abPadding[(4 + 6 + 16 + 1) * sizeof(uint32_t)];
53 /** Context used by md5-alt.cpp. */
54 struct
55 {
56 uint32_t in[16];
57 uint32_t buf[4];
58 uint32_t bits[2];
59 } AltPrivate;
60#ifdef RT_MD5_OPENSSL_PRIVATE_CONTEXT
61 /** Context used by md5-openssl.cpp. */
62 MD5_CTX OsslPrivate;
63#endif
64} RTMD5CONTEXT;
65/** Pointer to MD5 hash algorithm context. */
66typedef RTMD5CONTEXT *PRTMD5CONTEXT;
67
68RT_C_DECLS_BEGIN
69
70/**
71 * Compute the MD5 hash of the data.
72 *
73 * @param pvBuf Pointer to data.
74 * @param cbBuf Length of data (in bytes).
75 * @param pabDigest Where to store the hash.
76 * (What's passed is a pointer to the caller's buffer.)
77 */
78RTDECL(void) RTMd5(const void *pvBuf, size_t cbBuf, uint8_t pabDigest[RTMD5HASHSIZE]);
79
80/**
81 * Initialize MD5 context.
82 *
83 * @param pCtx Pointer to the MD5 context to initialize.
84 */
85RTDECL(void) RTMd5Init(PRTMD5CONTEXT pCtx);
86
87/**
88 * Feed data into the MD5 computation.
89 *
90 * @param pCtx Pointer to the MD5 context.
91 * @param pvBuf Pointer to data.
92 * @param cbBuf Length of data (in bytes).
93 */
94RTDECL(void) RTMd5Update(PRTMD5CONTEXT pCtx, const void *pvBuf, size_t cbBuf);
95
96/**
97 * Compute the MD5 hash of the data.
98 *
99 * @param pabDigest Where to store the hash.
100 * (What's passed is a pointer to the caller's buffer.)
101 * @param pCtx Pointer to the MD5 context.
102 */
103RTDECL(void) RTMd5Final(uint8_t pabDigest[RTMD5HASHSIZE], PRTMD5CONTEXT pCtx);
104
105/**
106 * Converts a MD5 hash to a digest string.
107 *
108 * @returns IPRT status code.
109 *
110 * @param pabDigest The binary digest returned by RTMd5Final or RTMd5.
111 * @param pszDigest Where to return the stringified digest.
112 * @param cchDigest The size of the output buffer. Should be at least
113 * RTMD5_STRING_LEN + 1 bytes.
114 */
115RTDECL(int) RTMd5ToString(uint8_t const pabDigest[RTMD5_HASH_SIZE], char *pszDigest, size_t cchDigest);
116
117/**
118 * Converts a MD5 hash to a digest string.
119 *
120 * @returns IPRT status code.
121 *
122 * @param pszDigest The stringified digest. Leading and trailing spaces are
123 * ignored.
124 * @param pabDigest Where to store the hash. (What is passed is a pointer to
125 * the caller's buffer.)
126 */
127RTDECL(int) RTMd5FromString(char const *pszDigest, uint8_t pabDigest[RTMD5_HASH_SIZE]);
128
129
130RT_C_DECLS_END
131
132/** @} */
133
134#endif
135
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