38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync/** @file
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * IPRT - Message-Digest algorithm 5.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync */
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync/*
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Copyright (C) 2006-2010 Oracle Corporation
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync *
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * available from http://www.virtualbox.org. This file is free software;
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * you can redistribute it and/or modify it under the terms of the GNU
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * General Public License (GPL) as published by the Free Software
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync *
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * The contents of this file may alternatively be used under the terms
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * of the Common Development and Distribution License Version 1.0
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * VirtualBox OSE distribution, in which case the provisions of the
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * CDDL are applicable instead of those of the GPL.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync *
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * You may elect to license modified versions of this file under the
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * terms and conditions of either the GPL or the CDDL or both.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync */
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync#ifndef ___iprt_md5_h
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync#define ___iprt_md5_h
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync#include <iprt/types.h>
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync/** @defgroup grp_rt_md5 RTMd5 - Message-Digest algorithm 5
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @ingroup grp_rt
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @{
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync */
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync/** Size of a MD5 hash. */
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync#define RTMD5_HASH_SIZE 16
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync/** @deprecated Use RTMD5_HASH_SIZE. */
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync#define RTMD5HASHSIZE RTMD5_HASH_SIZE
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync/** The length of a MD5 digest string. The terminator is not included. */
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync#define RTMD5_DIGEST_LEN 32
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync/** Size of a MD5 hash.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @deprecated Use RTMD5_DIGEST_LEN */
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync#define RTMD5_STRING_LEN RTMD5_DIGEST_LEN
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync/**
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * MD5 hash algorithm context.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync */
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsynctypedef union RTMD5CONTEXT
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync{
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync uint64_t u64BetterAlignment;
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync uint8_t abPadding[(4 + 6 + 16 + 1) * sizeof(uint32_t)];
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync /** Context used by md5-alt.cpp. */
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync struct
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync {
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync uint32_t in[16];
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync uint32_t buf[4];
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync uint32_t bits[2];
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync } AltPrivate;
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync#ifdef RT_MD5_OPENSSL_PRIVATE_CONTEXT
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync /** Context used by md5-openssl.cpp. */
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync MD5_CTX OsslPrivate;
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync#endif
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync} RTMD5CONTEXT;
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync/** Pointer to MD5 hash algorithm context. */
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsynctypedef RTMD5CONTEXT *PRTMD5CONTEXT;
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncRT_C_DECLS_BEGIN
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync/**
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Compute the MD5 hash of the data.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync *
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @param pvBuf Pointer to data.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @param cbBuf Length of data (in bytes).
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @param pabDigest Where to store the hash.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * (What's passed is a pointer to the caller's buffer.)
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync */
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncRTDECL(void) RTMd5(const void *pvBuf, size_t cbBuf, uint8_t pabDigest[RTMD5HASHSIZE]);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync/**
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Initialize MD5 context.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync *
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @param pCtx Pointer to the MD5 context to initialize.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync */
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncRTDECL(void) RTMd5Init(PRTMD5CONTEXT pCtx);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync/**
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Feed data into the MD5 computation.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync *
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @param pCtx Pointer to the MD5 context.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @param pvBuf Pointer to data.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @param cbBuf Length of data (in bytes).
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync */
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncRTDECL(void) RTMd5Update(PRTMD5CONTEXT pCtx, const void *pvBuf, size_t cbBuf);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync/**
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Compute the MD5 hash of the data.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync *
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @param pabDigest Where to store the hash.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * (What's passed is a pointer to the caller's buffer.)
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @param pCtx Pointer to the MD5 context.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync */
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncRTDECL(void) RTMd5Final(uint8_t pabDigest[RTMD5HASHSIZE], PRTMD5CONTEXT pCtx);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync/**
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Converts a MD5 hash to a digest string.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync *
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @returns IPRT status code.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync *
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @param pabDigest The binary digest returned by RTMd5Final or RTMd5.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @param pszDigest Where to return the stringified digest.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @param cchDigest The size of the output buffer. Should be at least
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * RTMD5_STRING_LEN + 1 bytes.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync */
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncRTDECL(int) RTMd5ToString(uint8_t const pabDigest[RTMD5_HASH_SIZE], char *pszDigest, size_t cchDigest);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync/**
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Converts a MD5 hash to a digest string.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync *
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @returns IPRT status code.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync *
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @param pszDigest The stringified digest. Leading and trailing spaces are
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * ignored.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @param pabDigest Where to store the hash. (What is passed is a pointer to
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * the caller's buffer.)
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync */
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncRTDECL(int) RTMd5FromString(char const *pszDigest, uint8_t pabDigest[RTMD5_HASH_SIZE]);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncRT_C_DECLS_END
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync/** @} */
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync#endif
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync