modules/libmar/verify/cryptox.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #ifndef CRYPTOX_H
michael@0 6 #define CRYPTOX_H
michael@0 7
michael@0 8 #define XP_MIN_SIGNATURE_LEN_IN_BYTES 256
michael@0 9
michael@0 10 #define CryptoX_Result int
michael@0 11 #define CryptoX_Success 0
michael@0 12 #define CryptoX_Error (-1)
michael@0 13 #define CryptoX_Succeeded(X) ((X) == CryptoX_Success)
michael@0 14 #define CryptoX_Failed(X) ((X) != CryptoX_Success)
michael@0 15
michael@0 16 #if defined(MAR_NSS)
michael@0 17
michael@0 18 #include "nss_secutil.h"
michael@0 19
michael@0 20 #define CryptoX_InvalidHandleValue NULL
michael@0 21 #define CryptoX_ProviderHandle void*
michael@0 22 #define CryptoX_SignatureHandle VFYContext *
michael@0 23 #define CryptoX_PublicKey SECKEYPublicKey *
michael@0 24 #define CryptoX_Certificate CERTCertificate *
michael@0 25
michael@0 26 #ifdef __cplusplus
michael@0 27 extern "C" {
michael@0 28 #endif
michael@0 29 CryptoX_Result NSS_LoadPublicKey(const char *certNickname,
michael@0 30 SECKEYPublicKey **publicKey,
michael@0 31 CERTCertificate **cert);
michael@0 32 CryptoX_Result NSS_VerifyBegin(VFYContext **ctx,
michael@0 33 SECKEYPublicKey * const *publicKey);
michael@0 34 CryptoX_Result NSS_VerifySignature(VFYContext * const *ctx ,
michael@0 35 const unsigned char *signature,
michael@0 36 unsigned int signatureLen);
michael@0 37 #ifdef __cplusplus
michael@0 38 } // extern "C"
michael@0 39 #endif
michael@0 40
michael@0 41 #define CryptoX_InitCryptoProvider(CryptoHandle) \
michael@0 42 CryptoX_Success
michael@0 43 #define CryptoX_VerifyBegin(CryptoHandle, SignatureHandle, PublicKey) \
michael@0 44 NSS_VerifyBegin(SignatureHandle, PublicKey)
michael@0 45 #define CryptoX_FreeSignatureHandle(SignatureHandle) \
michael@0 46 VFY_DestroyContext(*SignatureHandle, PR_TRUE)
michael@0 47 #define CryptoX_VerifyUpdate(SignatureHandle, buf, len) \
michael@0 48 VFY_Update(*SignatureHandle, (const unsigned char*)(buf), len)
michael@0 49 #define CryptoX_LoadPublicKey(CryptoHandle, certData, dataSize, \
michael@0 50 publicKey, certName, cert) \
michael@0 51 NSS_LoadPublicKey(certName, publicKey, cert)
michael@0 52 #define CryptoX_VerifySignature(hash, publicKey, signedData, len) \
michael@0 53 NSS_VerifySignature(hash, (const unsigned char *)(signedData), len)
michael@0 54 #define CryptoX_FreePublicKey(key) \
michael@0 55 SECKEY_DestroyPublicKey(*key)
michael@0 56 #define CryptoX_FreeCertificate(cert) \
michael@0 57 CERT_DestroyCertificate(*cert)
michael@0 58
michael@0 59 #elif XP_MACOSX
michael@0 60
michael@0 61 #define CryptoX_InvalidHandleValue NULL
michael@0 62 #define CryptoX_ProviderHandle void*
michael@0 63 #define CryptoX_SignatureHandle void*
michael@0 64 #define CryptoX_PublicKey void*
michael@0 65 #define CryptoX_Certificate void*
michael@0 66
michael@0 67 // Forward-declare Objective-C functions implemented in MacVerifyCrypto.mm.
michael@0 68 #ifdef __cplusplus
michael@0 69 extern "C" {
michael@0 70 #endif
michael@0 71 CryptoX_Result CryptoMac_InitCryptoProvider();
michael@0 72 CryptoX_Result CryptoMac_VerifyBegin(CryptoX_SignatureHandle* aInputData);
michael@0 73 CryptoX_Result CryptoMac_VerifyUpdate(CryptoX_SignatureHandle* aInputData,
michael@0 74 void* aBuf, unsigned int aLen);
michael@0 75 CryptoX_Result CryptoMac_LoadPublicKey(const unsigned char* aCertData,
michael@0 76 CryptoX_PublicKey* aPublicKey);
michael@0 77 CryptoX_Result CryptoMac_VerifySignature(CryptoX_SignatureHandle* aInputData,
michael@0 78 CryptoX_PublicKey* aPublicKey,
michael@0 79 const unsigned char* aSignature,
michael@0 80 unsigned int aSignatureLen);
michael@0 81 void CryptoMac_FreeSignatureHandle(CryptoX_SignatureHandle* aInputData);
michael@0 82 void CryptoMac_FreePublicKey(CryptoX_PublicKey* aPublicKey);
michael@0 83 #ifdef __cplusplus
michael@0 84 } // extern "C"
michael@0 85 #endif
michael@0 86
michael@0 87 #define CryptoX_InitCryptoProvider(aProviderHandle) \
michael@0 88 CryptoMac_InitCryptoProvider()
michael@0 89 #define CryptoX_VerifyBegin(aCryptoHandle, aInputData, aPublicKey) \
michael@0 90 CryptoMac_VerifyBegin(aInputData)
michael@0 91 #define CryptoX_VerifyUpdate(aInputData, aBuf, aLen) \
michael@0 92 CryptoMac_VerifyUpdate(aInputData, aBuf, aLen)
michael@0 93 #define CryptoX_LoadPublicKey(aProviderHandle, aCertData, aDataSize, \
michael@0 94 aPublicKey, aCertName, aCert) \
michael@0 95 CryptoMac_LoadPublicKey(aCertData, aPublicKey)
michael@0 96 #define CryptoX_VerifySignature(aInputData, aPublicKey, aSignature, \
michael@0 97 aSignatureLen) \
michael@0 98 CryptoMac_VerifySignature(aInputData, aPublicKey, aSignature, aSignatureLen)
michael@0 99 #define CryptoX_FreeSignatureHandle(aInputData) \
michael@0 100 CryptoMac_FreeSignatureHandle(aInputData)
michael@0 101 #define CryptoX_FreePublicKey(aPublicKey) \
michael@0 102 CryptoMac_FreePublicKey(aPublicKey)
michael@0 103 #define CryptoX_FreeCertificate(aCertificate)
michael@0 104
michael@0 105 #elif defined(XP_WIN)
michael@0 106
michael@0 107 #include <windows.h>
michael@0 108 #include <wincrypt.h>
michael@0 109
michael@0 110 CryptoX_Result CryptoAPI_InitCryptoContext(HCRYPTPROV *provider);
michael@0 111 CryptoX_Result CryptoAPI_LoadPublicKey(HCRYPTPROV hProv,
michael@0 112 BYTE *certData,
michael@0 113 DWORD sizeOfCertData,
michael@0 114 HCRYPTKEY *publicKey,
michael@0 115 HCERTSTORE *cert);
michael@0 116 CryptoX_Result CryptoAPI_VerifyBegin(HCRYPTPROV provider, HCRYPTHASH* hash);
michael@0 117 CryptoX_Result CryptoAPI_VerifyUpdate(HCRYPTHASH* hash,
michael@0 118 BYTE *buf, DWORD len);
michael@0 119 CryptoX_Result CyprtoAPI_VerifySignature(HCRYPTHASH *hash,
michael@0 120 HCRYPTKEY *pubKey,
michael@0 121 const BYTE *signature,
michael@0 122 DWORD signatureLen);
michael@0 123
michael@0 124 #define CryptoX_InvalidHandleValue ((ULONG_PTR)NULL)
michael@0 125 #define CryptoX_ProviderHandle HCRYPTPROV
michael@0 126 #define CryptoX_SignatureHandle HCRYPTHASH
michael@0 127 #define CryptoX_PublicKey HCRYPTKEY
michael@0 128 #define CryptoX_Certificate HCERTSTORE
michael@0 129 #define CryptoX_InitCryptoProvider(CryptoHandle) \
michael@0 130 CryptoAPI_InitCryptoContext(CryptoHandle)
michael@0 131 #define CryptoX_VerifyBegin(CryptoHandle, SignatureHandle, PublicKey) \
michael@0 132 CryptoAPI_VerifyBegin(CryptoHandle, SignatureHandle)
michael@0 133 #define CryptoX_FreeSignatureHandle(SignatureHandle)
michael@0 134 #define CryptoX_VerifyUpdate(SignatureHandle, buf, len) \
michael@0 135 CryptoAPI_VerifyUpdate(SignatureHandle, (BYTE *)(buf), len)
michael@0 136 #define CryptoX_LoadPublicKey(CryptoHandle, certData, dataSize, \
michael@0 137 publicKey, certName, cert) \
michael@0 138 CryptoAPI_LoadPublicKey(CryptoHandle, (BYTE*)(certData), \
michael@0 139 dataSize, publicKey, cert)
michael@0 140 #define CryptoX_VerifySignature(hash, publicKey, signedData, len) \
michael@0 141 CyprtoAPI_VerifySignature(hash, publicKey, signedData, len)
michael@0 142 #define CryptoX_FreePublicKey(key) \
michael@0 143 CryptDestroyKey(*(key))
michael@0 144 #define CryptoX_FreeCertificate(cert) \
michael@0 145 CertCloseStore(*(cert), CERT_CLOSE_STORE_FORCE_FLAG);
michael@0 146
michael@0 147 #else
michael@0 148
michael@0 149 /* This default implementation is necessary because we don't want to
michael@0 150 * link to NSS from updater code on non Windows platforms. On Windows
michael@0 151 * we use CyrptoAPI instead of NSS. We don't call any function as they
michael@0 152 * would just fail, but this simplifies linking.
michael@0 153 */
michael@0 154
michael@0 155 #define CryptoX_InvalidHandleValue NULL
michael@0 156 #define CryptoX_ProviderHandle void*
michael@0 157 #define CryptoX_SignatureHandle void*
michael@0 158 #define CryptoX_PublicKey void*
michael@0 159 #define CryptoX_Certificate void*
michael@0 160 #define CryptoX_InitCryptoProvider(CryptoHandle) \
michael@0 161 CryptoX_Error
michael@0 162 #define CryptoX_VerifyBegin(CryptoHandle, SignatureHandle, PublicKey) \
michael@0 163 CryptoX_Error
michael@0 164 #define CryptoX_FreeSignatureHandle(SignatureHandle)
michael@0 165 #define CryptoX_VerifyUpdate(SignatureHandle, buf, len) CryptoX_Error
michael@0 166 #define CryptoX_LoadPublicKey(CryptoHandle, certData, dataSize, \
michael@0 167 publicKey, certName, cert) \
michael@0 168 CryptoX_Error
michael@0 169 #define CryptoX_VerifySignature(hash, publicKey, signedData, len) CryptoX_Error
michael@0 170 #define CryptoX_FreePublicKey(key) CryptoX_Error
michael@0 171
michael@0 172 #endif
michael@0 173
michael@0 174 #endif

mercurial