digest-core.cpp revision 13493ab7596e827b8d0caab2c89e635dd65f78f9
/* $Id$ */
/** @file
* IPRT - Crypto - Cryptographic Hash / Message Digest API
*/
/*
* Copyright (C) 2006-2014 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/**
* Generic message digest instance.
*/
typedef struct RTCRDIGESTINT
{
/** Magic value (RTCRDIGESTINT_MAGIC). */
/** Reference counter. */
/** Pointer to the message digest descriptor. */
/** The offset into abState of the storage space . At
* least RTCRDIGESTDESC::cbHash bytes is available at that location. */
/** State. */
/** The number of bytes consumed. */
/** Opaque data specific to the message digest algorithm, size given by
* RTCRDIGESTDESC::cbState. This is followed by space for the final hash at
* offHash with size RTCRDIGESTDESC::cbHash. */
/** Pointer to a message digest instance. */
typedef RTCRDIGESTINT *PRTCRDIGESTINT;
/** Magic value for RTCRDIGESTINT::u32Magic (Ralph C. Merkle). */
/** @name RTCRDIGESTINT::uState values.
* @{ */
/** Ready for more data. */
/** The hash has been finalized and can be found at offHash. */
/** Busted state, can happen after re-init. */
/** @} */
{
int rc = VINF_SUCCESS;
PRTCRDIGESTINT pThis = (PRTCRDIGESTINT)RTMemAllocZ(RT_OFFSETOF(RTCRDIGESTINT, abState[offHash + pDesc->cbHash]));
if (pThis)
{
if (RT_SUCCESS(rc))
{
return VINF_SUCCESS;
}
}
else
rc = VERR_NO_MEMORY;
return rc;
}
{
int rc = VINF_SUCCESS;
PRTCRDIGESTINT pThis = (PRTCRDIGESTINT)RTMemAllocZ(RT_OFFSETOF(RTCRDIGESTINT, abState[offHash + hSrc->pDesc->cbHash]));
if (pThis)
{
else
if (RT_SUCCESS(rc))
{
return VINF_SUCCESS;
}
}
else
rc = VERR_NO_MEMORY;
return rc;
}
{
pThis->cbConsumed = 0;
int rc = VINF_SUCCESS;
{
if (RT_FAILURE(rc))
}
else
return rc;
}
{
return cRefs;
}
{
if (pThis == NIL_RTCRDIGEST)
return 0;
if (!cRefs)
{
}
return cRefs;
}
{
return VINF_SUCCESS;
}
{
AssertReturn(pThis->uState == RTCRDIGEST_STATE_READY || pThis->uState == RTCRDIGEST_STATE_FINAL, VERR_INVALID_STATE);
/*
* Make sure the hash calculation is final.
*/
{
}
else
/*
* Copy out the hash if requested.
*/
if (cbHash > 0)
{
{
return VINF_BUFFER_UNDERFLOW;
}
else
{
return VERR_BUFFER_OVERFLOW;
}
}
return VINF_SUCCESS;
}
{
AssertRCReturn(rc, false);
AssertPtrReturn(pvHash, false);
}
{
}
{
AssertPtrReturn(pThis, 0);
{
return cbHash;
}
}
{
AssertPtrReturn(pThis, 0);
return pThis->cbConsumed;
}
{
AssertPtrReturn(pThis, false);
}
{
return enmType;
}