digest-builtin.cpp revision fc659761c3e27dad0ce26752ed131bd4b7763b3b
/* $Id$ */
/** @file
* IPRT - Crypto - Cryptographic Hash / Message Digest API, Built-in providers.
*/
/*
* 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 *
*******************************************************************************/
#ifdef IPRT_WITH_OPENSSL
# include "internal/iprt-openssl.h"
#endif
/*
* MD2
*/
/** @impl_interface_method{RTCRDIGESTDESC::pfnUpdate} */
{
}
/** @impl_interface_method{RTCRDIGESTDESC::pfnFinal} */
{
}
/** @impl_interface_method{RTCRDIGESTDESC::pfnInit} */
{
return VINF_SUCCESS;
}
/** MD2 alias ODIs. */
static const char * const g_apszMd2Aliases[] =
{
"1.3.14.3.2.24" /* OIW md2WithRSASignature */,
};
/** MD2 descriptor. */
static RTCRDIGESTDESC const g_rtCrDigestMd2Desc =
{
"md2",
"1.2.840.113549.2.2",
sizeof(RTMD2CONTEXT),
0,
NULL,
NULL,
NULL,
NULL,
};
/*
* MD5
*/
/** @impl_interface_method{RTCRDIGESTDESC::pfnUpdate} */
{
}
/** @impl_interface_method{RTCRDIGESTDESC::pfnFinal} */
{
}
/** @impl_interface_method{RTCRDIGESTDESC::pfnInit} */
{
return VINF_SUCCESS;
}
/** MD5 alias ODIs. */
static const char * const g_apszMd5Aliases[] =
{
"1.3.14.3.2.25" /* OIW md5WithRSASignature */,
};
/** MD5 descriptor. */
static RTCRDIGESTDESC const g_rtCrDigestMd5Desc =
{
"md5",
"1.2.840.113549.2.5",
sizeof(RTMD5CONTEXT),
0,
NULL,
NULL,
NULL,
NULL,
};
/*
* SHA-1
*/
/** @impl_interface_method{RTCRDIGESTDESC::pfnUpdate} */
{
}
/** @impl_interface_method{RTCRDIGESTDESC::pfnFinal} */
{
}
/** @impl_interface_method{RTCRDIGESTDESC::pfnInit} */
{
return VINF_SUCCESS;
}
/** SHA-1 alias ODIs. */
static const char * const g_apszSha1Aliases[] =
{
"1.3.14.3.2.29" /* OIW sha1WithRSASignature */,
};
/** SHA-1 descriptor. */
static RTCRDIGESTDESC const g_rtCrDigestSha1Desc =
{
"sha-1",
"1.3.14.3.2.26",
sizeof(RTSHA1CONTEXT),
0,
NULL,
NULL,
NULL,
NULL,
};
/*
* SHA-256
*/
/** @impl_interface_method{RTCRDIGESTDESC::pfnUpdate} */
{
}
/** @impl_interface_method{RTCRDIGESTDESC::pfnFinal} */
{
}
/** @impl_interface_method{RTCRDIGESTDESC::pfnInit} */
{
return VINF_SUCCESS;
}
/** SHA-256 alias ODIs. */
static const char * const g_apszSha256Aliases[] =
{
};
/** SHA-256 descriptor. */
static RTCRDIGESTDESC const g_rtCrDigestSha256Desc =
{
"sha-256",
"2.16.840.1.101.3.4.2.1",
sizeof(RTSHA256CONTEXT),
0,
NULL,
NULL,
NULL,
NULL,
};
/*
* SHA-512
*/
/** @impl_interface_method{RTCRDIGESTDESC::pfnUpdate} */
{
}
/** @impl_interface_method{RTCRDIGESTDESC::pfnFinal} */
{
}
/** @impl_interface_method{RTCRDIGESTDESC::pfnInit} */
{
return VINF_SUCCESS;
}
/** SHA-512 alias ODIs. */
static const char * const g_apszSha512Aliases[] =
{
};
/** SHA-512 descriptor. */
static RTCRDIGESTDESC const g_rtCrDigestSha512Desc =
{
"sha-512",
"2.16.840.1.101.3.4.2.3",
sizeof(RTSHA512CONTEXT),
0,
NULL,
NULL,
NULL,
NULL,
};
/*
* SHA-224
*/
/** @impl_interface_method{RTCRDIGESTDESC::pfnUpdate} */
{
}
/** @impl_interface_method{RTCRDIGESTDESC::pfnFinal} */
{
}
/** @impl_interface_method{RTCRDIGESTDESC::pfnInit} */
{
return VINF_SUCCESS;
}
/** SHA-224 alias ODIs. */
static const char * const g_apszSha224Aliases[] =
{
};
/** SHA-224 descriptor. */
static RTCRDIGESTDESC const g_rtCrDigestSha224Desc =
{
"sha-224",
"2.16.840.1.101.3.4.2.4",
sizeof(RTSHA224CONTEXT),
0,
NULL,
NULL,
NULL,
NULL,
};
/*
* SHA-384
*/
/** @impl_interface_method{RTCRDIGESTDESC::pfnUpdate} */
{
}
/** @impl_interface_method{RTCRDIGESTDESC::pfnFinal} */
{
}
/** @impl_interface_method{RTCRDIGESTDESC::pfnInit} */
{
return VINF_SUCCESS;
}
/** SHA-384 alias ODIs. */
static const char * const g_apszSha384Aliases[] =
{
};
/** SHA-384 descriptor. */
static RTCRDIGESTDESC const g_rtCrDigestSha384Desc =
{
"sha-384",
"2.16.840.1.101.3.4.2.2",
sizeof(RTSHA384CONTEXT),
0,
NULL,
NULL,
NULL,
NULL,
};
#ifndef IPRT_WITHOUT_SHA512T224
/*
* SHA-512/224
*/
/** @impl_interface_method{RTCRDIGESTDESC::pfnUpdate} */
static DECLCALLBACK(void) rtCrDigestSha512t224_Update(void *pvState, const void *pvData, size_t cbData)
{
}
/** @impl_interface_method{RTCRDIGESTDESC::pfnFinal} */
{
}
/** @impl_interface_method{RTCRDIGESTDESC::pfnInit} */
{
return VINF_SUCCESS;
}
/** SHA-512/224 alias ODIs. */
static const char * const g_apszSha512t224Aliases[] =
{
};
/** SHA-512/224 descriptor. */
static RTCRDIGESTDESC const g_rtCrDigestSha512t224Desc =
{
"sha-512/224",
"2.16.840.1.101.3.4.2.5",
sizeof(RTSHA512T224CONTEXT),
0,
NULL,
NULL,
NULL,
NULL,
};
#endif /* !IPRT_WITHOUT_SHA512T224 */
#ifndef IPRT_WITHOUT_SHA512T256
/*
* SHA-512/256
*/
/** @impl_interface_method{RTCRDIGESTDESC::pfnUpdate} */
static DECLCALLBACK(void) rtCrDigestSha512t256_Update(void *pvState, const void *pvData, size_t cbData)
{
}
/** @impl_interface_method{RTCRDIGESTDESC::pfnFinal} */
{
}
/** @impl_interface_method{RTCRDIGESTDESC::pfnInit} */
{
return VINF_SUCCESS;
}
/** SHA-512/256 alias ODIs. */
static const char * const g_apszSha512t256Aliases[] =
{
};
/** SHA-512/256 descriptor. */
static RTCRDIGESTDESC const g_rtCrDigestSha512t256Desc =
{
"sha-512/256",
"2.16.840.1.101.3.4.2.6",
sizeof(RTSHA512T256CONTEXT),
0,
NULL,
NULL,
NULL,
NULL,
};
#endif /* !IPRT_WITHOUT_SHA512T256 */
/**
* Array of built in message digest vtables.
*/
static PCRTCRDIGESTDESC const g_apDigestOps[] =
{
#ifndef IPRT_WITHOUT_SHA512T224
#endif
#ifndef IPRT_WITHOUT_SHA512T256
#endif
};
#ifdef IPRT_WITH_OPENSSL
/*
* OpenSSL EVP.
*/
/** @impl_interface_method{RTCRDIGESTDESC::pfnUpdate} */
static DECLCALLBACK(void) rtCrDigestOsslEvp_Update(void *pvState, const void *pvData, size_t cbData)
{
}
/** @impl_interface_method{RTCRDIGESTDESC::pfnFinal} */
{
unsigned int cbHash = EVP_MAX_MD_SIZE;
}
/** @impl_interface_method{RTCRDIGESTDESC::pfnInit} */
{
if (fReInit)
{
}
return VINF_SUCCESS;
}
/** @impl_interface_method{RTCRDIGESTDESC::pfn} */
{
}
/** @impl_interface_method{RTCRDIGESTDESC::pfnClone} */
{
return VINF_SUCCESS;
}
/** @impl_interface_method{RTCRDIGESTDESC::pfnGetHashSize} */
{
}
/** @impl_interface_method{RTCRDIGESTDESC::pfnGetHashSize} */
{
/** @todo figure which digest algorithm it is! */
return RTDIGESTTYPE_UNKNOWN;
}
/** Descriptor for the OpenSSL EVP base message digest provider. */
static RTCRDIGESTDESC const g_rtCrDigestOpenSslDesc =
{
"OpenSSL EVP",
NULL,
NULL,
sizeof(EVP_MD_CTX),
0,
};
#endif /* IPRT_WITH_OPENSSL */
{
if (ppvOpaque)
/*
* Primary OIDs.
*/
while (i-- > 0)
return g_apDigestOps[i];
/*
* Alias OIDs.
*/
i = RT_ELEMENTS(g_apDigestOps);
while (i-- > 0)
{
if (ppszAliases)
for (; *ppszAliases; ppszAliases++)
return g_apDigestOps[i];
}
#ifdef IPRT_WITH_OPENSSL
/*
* Try EVP and see if it knows the algorithm.
*/
if (ppvOpaque)
{
{
if (pEvpMdType)
{
/*
* Return the OpenSSL provider descriptor and the EVP_MD address.
*/
*ppvOpaque = (void *)pEvpMdType;
return &g_rtCrDigestOpenSslDesc;
}
}
}
#endif
return NULL;
}
{
}
{
void *pvOpaque;
if (pDesc)
return VERR_NOT_FOUND;
}
{
void *pvOpaque;
if (pDesc)
return VERR_NOT_FOUND;
}
{
while (i-- > 0)
return g_apDigestOps[i];
return NULL;
}
{
if (pDesc)
return VERR_NOT_FOUND;
}