1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
|
/** @file
* IPRT - Crypto - Cryptographic Hash / Message Digest.
*/
/*
* Copyright (C) 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;
* you can redistribute it and/or modify it under the terms of the GNU
* 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.
*/
#ifndef ___iprt_crypto_digest_h
#define ___iprt_crypto_digest_h
#include <iprt/asn1.h>
RT_C_DECLS_BEGIN
/** @defgroup grp_rt_crdigest RTCrDigest - Crypographic Hash / Message Digest API.
* @ingroup grp_rt
* @{
*/
/**
* Cryptographic hash / message digest provider descriptor.
*
* This gives the basic details and identifiers of the algorithm as well as
* function pointers to the implementation.
*/
typedef struct RTCRDIGESTDESC
{
/** The message digest provider name. */
const char *pszName;
/** The object ID string. */
const char *pszObjId;
/** Pointer to a NULL terminated table of alias object IDs (optional). */
const char * const *papszObjIdAliases;
/** The IPRT digest type. */
RTDIGESTTYPE enmType;
/** The max size of the final hash (binary). */
uint32_t cbHash;
/** The size of the state. */
uint32_t cbState;
/** Reserved. */
uint32_t uReserved;
/**
* Updates the digest with more data.
*
* @param pvState The opaque message digest state.
* @param pvData The data to add to the digest.
* @param cbData The amount of data to add to the digest.
*/
DECLCALLBACKMEMBER(void, pfnUpdate)(void *pvState, const void *pvData, size_t cbData);
/**
* Finalizes the digest calculation.
*
* @param pvState The opaque message digest state.
* @param pbHash Where to store the output digest. This buffer is at
* least RTCRDIGESTDESC::cbHash bytes large.
*/
DECLCALLBACKMEMBER(void, pfnFinal)(void *pvState, uint8_t *pbHash);
/**
* (Re-)Initializes the digest. Optional.
*
* Optional, RT_BZERO will be used if NULL.
*
* @returns IPRT status code.
* @param pvState The opaque message digest state.
* @param pvOpaque Opaque algortihm specific parameter.
* @param fReInit Set if this is a re-init call.
*/
DECLCALLBACKMEMBER(int, pfnInit)(void *pvState, void *pvOpaque, bool fReInit);
/**
* Deletes the message digest state.
*
* Optional, memset will be used if NULL.
*
* @param pvState The opaque message digest state.
*/
DECLCALLBACKMEMBER(void, pfnDelete)(void *pvState);
/**
* Clones the message digest state.
*
* Optional, memcpy will be used if NULL.
*
* @returns IPRT status code.
* @param pvState The opaque message digest state (destination).
* @param pvSrcState The opaque message digest state to clone (source).
*/
DECLCALLBACKMEMBER(int, pfnClone)(void *pvState, void const *pvSrcState);
/**
* Gets the hash size.
*
* Optional, if not provided RTCRDIGESTDESC::cbHash will be returned. If
* provided though, RTCRDIGESTDESC::cbHash must be set to the largest possible
* hash size.
*
* @returns The hash size.
* @param pvState The opaque message digest state.
*/
DECLCALLBACKMEMBER(uint32_t, pfnGetHashSize)(void *pvState);
/**
* Gets the digest type (when enmType is RTDIGESTTYPE_UNKNOWN).
*
* @returns The hash size.
* @param pvState The opaque message digest state.
*/
DECLCALLBACKMEMBER(RTDIGESTTYPE, pfnGetDigestType)(void *pvState);
} RTCRDIGESTDESC;
/** Pointer to const message digest details and vtable. */
typedef RTCRDIGESTDESC const *PCRTCRDIGESTDESC;
/**
* Finds a cryptographic hash / message digest descriptor by object identifier
* string.
*
* @returns Pointer to the message digest details & vtable if found. NULL if
* not found.
* @param pszObjId The dotted object identifier string of the message
* digest algorithm.
* @param ppvOpaque Where to return an opaque implementation specfici
* sub-type indicator that can be passed to
* RTCrDigestCreate. This is optional, fewer
* algortihms are available if not specified.
*/
RTDECL(PCRTCRDIGESTDESC) RTCrDigestFindByObjIdString(const char *pszObjId, void *ppvOpaque);
/**
* Finds a cryptographic hash / message digest descriptor by object identifier
* ASN.1 object.
*
* @returns Pointer to the message digest details & vtable if found. NULL if
* not found.
* @param pszObjId The ASN.1 object ID of the message digest algorithm.
* @param ppvOpaque Where to return an opaque implementation specfici
* sub-type indicator that can be passed to
* RTCrDigestCreate. This is optional, fewer
* algortihms are available if not specified.
*/
RTDECL(PCRTCRDIGESTDESC) RTCrDigestFindByObjId(PCRTASN1OBJID pObjId, void *ppvOpaque);
RTDECL(PCRTCRDIGESTDESC) RTCrDigestFindByType(RTDIGESTTYPE enmDigestType);
RTDECL(int) RTCrDigestCreateByObjIdString(PRTCRDIGEST phDigest, const char *pszObjId);
RTDECL(int) RTCrDigestCreateByObjId(PRTCRDIGEST phDigest, PCRTASN1OBJID pObjId);
RTDECL(int) RTCrDigestCreateByType(PRTCRDIGEST phDigest, RTDIGESTTYPE enmDigestType);
RTDECL(int) RTCrDigestCreate(PRTCRDIGEST phDigest, PCRTCRDIGESTDESC pDesc, void *pvOpaque);
RTDECL(int) RTCrDigestClone(PRTCRDIGEST phDigest, RTCRDIGEST hSrc);
RTDECL(int) RTCrDigestReset(RTCRDIGEST hDigest);
RTDECL(uint32_t) RTCrDigestRetain(RTCRDIGEST hDigest);
RTDECL(uint32_t) RTCrDigestRelease(RTCRDIGEST hDigest);
RTDECL(int) RTCrDigestUpdate(RTCRDIGEST hDigest, void const *pvData, size_t cbData);
RTDECL(int) RTCrDigestFinal(RTCRDIGEST hDigest, void *pvHash, size_t cbHash);
RTDECL(bool) RTCrDigestMatch(RTCRDIGEST hDigest, void const *pvHash, size_t cbHash);
RTDECL(uint8_t const *) RTCrDigestGetHash(RTCRDIGEST hDigest);
RTDECL(uint32_t) RTCrDigestGetHashSize(RTCRDIGEST hDigest);
RTDECL(uint64_t) RTCrDigestGetConsumedSize(RTCRDIGEST hDigest);
RTDECL(bool) RTCrDigestIsFinalized(RTCRDIGEST hDigest);
RTDECL(RTDIGESTTYPE) RTCrDigestGetType(RTCRDIGEST hDigest);
/** @} */
RT_C_DECLS_END
#endif
|