md2.h revision 19a85ab446120db0d823d5c8e5d01b999212724c
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/** @file
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * IPRT - Message-Digest Algorithm 2.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/*
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Copyright (C) 2006-2014 Oracle Corporation
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync *
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * available from http://www.virtualbox.org. This file is free software;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * you can redistribute it and/or modify it under the terms of the GNU
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * General Public License (GPL) as published by the Free Software
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync *
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * The contents of this file may alternatively be used under the terms
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * of the Common Development and Distribution License Version 1.0
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * VirtualBox OSE distribution, in which case the provisions of the
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * CDDL are applicable instead of those of the GPL.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync *
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * You may elect to license modified versions of this file under the
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * terms and conditions of either the GPL or the CDDL or both.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync#ifndef ___iprt_md2_h
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync#define ___iprt_md2_h
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync#include <iprt/types.h>
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRT_C_DECLS_BEGIN
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/** @defgroup grp_rt_md2 RTMd2 - Message-Digest algorithm 2
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @ingroup grp_rt
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @{
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/** Size of a MD2 hash. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync#define RTMD2_HASH_SIZE 16
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/** The length of a MD2 digest string. The terminator is not included. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync#define RTMD2_DIGEST_LEN 32
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/**
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * MD2 hash algorithm context.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsynctypedef union RTMD2CONTEXT
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync{
19a85ab446120db0d823d5c8e5d01b999212724cvboxsync uint64_t u64BetterAlignment;
19a85ab446120db0d823d5c8e5d01b999212724cvboxsync uint8_t abPadding[4 + 16 + 16*4 + 16*4];
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync#ifdef RT_MD2_PRIVATE_CONTEXT
19a85ab446120db0d823d5c8e5d01b999212724cvboxsync MD2_CTX Private;
19a85ab446120db0d823d5c8e5d01b999212724cvboxsync#endif
19a85ab446120db0d823d5c8e5d01b999212724cvboxsync#ifdef RT_MD2_PRIVATE_ALT_CONTEXT
19a85ab446120db0d823d5c8e5d01b999212724cvboxsync RTMD2ALTPRIVATECTX AltPrivate;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync#endif
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync} RTMD2CONTEXT;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/** Pointer to MD2 hash algorithm context. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsynctypedef RTMD2CONTEXT *PRTMD2CONTEXT;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/**
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Compute the MD2 hash of the data.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync *
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @param pvBuf Pointer to data.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @param cbBuf Length of data (in bytes).
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @param pabDigest Where to store the hash.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * (What's passed is a pointer to the caller's buffer.)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(void) RTMd2(const void *pvBuf, size_t cbBuf, uint8_t pabDigest[RTMD2_HASH_SIZE]);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/**
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Initialize MD2 context.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync *
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @param pCtx Pointer to the MD2 context to initialize.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(void) RTMd2Init(PRTMD2CONTEXT pCtx);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/**
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Feed data into the MD2 computation.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync *
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @param pCtx Pointer to the MD2 context.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @param pvBuf Pointer to data.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @param cbBuf Length of data (in bytes).
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(void) RTMd2Update(PRTMD2CONTEXT pCtx, const void *pvBuf, size_t cbBuf);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/**
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Compute the MD2 hash of the data.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync *
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @param pCtx Pointer to the MD2 context.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @param pabDigest Where to store the hash. (What's passed is a pointer to
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * the caller's buffer.)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(void) RTMd2Final(PRTMD2CONTEXT pCtx, uint8_t pabDigest[RTMD2_HASH_SIZE]);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/**
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Converts a MD2 hash to a digest string.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync *
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @returns IPRT status code.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync *
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @param pabDigest The binary digest returned by RTMd2Final or RTMd2.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @param pszDigest Where to return the stringified digest.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @param cchDigest The size of the output buffer. Should be at least
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * RTMD2_STRING_LEN + 1 bytes.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(int) RTMd2ToString(uint8_t const pabDigest[RTMD2_HASH_SIZE], char *pszDigest, size_t cchDigest);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/**
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Converts a MD2 hash to a digest string.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync *
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @returns IPRT status code.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync *
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @param pszDigest The stringified digest. Leading and trailing spaces are
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * ignored.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @param pabDigest Where to store the hash. (What is passed is a pointer to
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * the caller's buffer.)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(int) RTMd2FromString(char const *pszDigest, uint8_t pabDigest[RTMD2_HASH_SIZE]);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/** @} */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRT_C_DECLS_END
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync#endif
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync