cryptlib.h
来自「提供了很多种加密算法和CA认证及相关服务如CMP、OCSP等的开发」· C头文件 代码 · 共 1,540 行 · 第 1/5 页
H
1,540 行
#ifndef _CRYPTLIB_DEFINED
#define _CRYPTLIB_DEFINED
/* Fixup for Windows support. We need to include windows.h for various types
and prototypes needed for DLL's. In addition wincrypt.h defines some
values with the same names as cryptlib ones, so we need to check for this
and issue a warning not to mix cryptlib with CryptoAPI (that's like taking
a bank vault and making one side out of papier mache) */
#if ( defined( _WINDOWS ) || defined( WIN32 ) || defined( _WIN32 ) || \
defined( __WIN32__ ) ) && !defined( _SCCTK )
#define WIN32_LEAN_AND_MEAN /* Skip RPC, OLE, Multimedia, etc */
#define NOCRYPT /* Disable include of wincrypt.h */
#include <windows.h>
#if defined( CRYPT_MODE_ECB )
#error "cryptlib.h and wincrypt.h can't both be used at the same time due to conflicting type names"
#endif /* Clash with wincrypt.h defines */
#endif /* Windows other than a cross-development environment */
/* Machine-dependant types to allow use in special library types such as
DLL's. Under Win32 we need to use the dllimport and dllexport directives
for the DLL version of the library, so we define the type used for
functions depending on whether we're being included via crypt.h or not */
#if ( defined( WIN32 ) || defined( _WIN32 ) || defined( __WIN32__ ) ) && \
!( defined( STATIC_LIB ) || defined( _SCCTK ) )
#define C_PTR * /* General pointer */
#if defined( __BORLANDC__ ) && ( __BORLANDC__ < 0x500 )
#ifdef _CRYPT_DEFINED
#define C_RET int _export _stdcall /* BC++ DLL export ret.val.*/
#else
#define C_RET int _import _stdcall /* BC++ DLL import ret.val.*/
#endif /* CRYPT_DEFINED */
#else
#ifdef _CRYPT_DEFINED
#define C_RET __declspec( dllexport ) int __stdcall /* DLL export ret.val.*/
#else
#define C_RET __declspec( dllimport ) int __stdcall /* DLL import ret.val.*/
#endif /* CRYPT_DEFINED */
#endif /* BC++ vs VC++ DLL functions */
#elif defined( _WINDOWS )
#define C_PTR FAR * /* DLL pointer */
#define C_RET int FAR PASCAL _export /* DLL return value */
#else
#define C_PTR * /* General pointer */
#define C_RET int /* General return value */
#endif /* Windows vs everything else function types */
/* Symbolic defines to make it clearer how the function parameters behave */
#define C_IN const /* Input-only */
#define C_OUT /* Output-only */
#define C_INOUT /* Modified in-place */
/* Alongside the externally visible types, cryptlib also has various internal
types which are extended forms of the external types which are invisible
to the user (eg SignedPublicKeyAndChallenge == certRequest). These can
only be used internally and are blocked by the security kernel, so they
can never be accessed from outside cryptlib (in fact for good measure
they're blocked before they even get to the kernel by preliminary range
checks in the API wrapper functions). The only reason they're defined
here is because it's not possible to extend an enum outside the point
where it's originally defined */
/****************************************************************************
* *
* Algorithm and Object Types *
* *
****************************************************************************/
/* Algorithm and mode types */
typedef enum { /* Algorithms */
/* No encryption */
CRYPT_ALGO_NONE, /* No encryption */
/* Conventional encryption */
CRYPT_ALGO_DES, /* DES */
CRYPT_ALGO_3DES, /* Triple DES */
CRYPT_ALGO_IDEA, /* IDEA */
CRYPT_ALGO_CAST, /* CAST-128 */
CRYPT_ALGO_RC2, /* RC2 */
CRYPT_ALGO_RC4, /* RC4 */
CRYPT_ALGO_RC5, /* RC5 */
CRYPT_ALGO_AES, /* AES */
CRYPT_ALGO_BLOWFISH, /* Blowfish */
CRYPT_ALGO_SKIPJACK, /* Skipjack */
/* Public-key encryption */
CRYPT_ALGO_DH = 100, /* Diffie-Hellman */
CRYPT_ALGO_RSA, /* RSA */
CRYPT_ALGO_DSA, /* DSA */
CRYPT_ALGO_ELGAMAL, /* ElGamal */
CRYPT_ALGO_KEA, /* KEA */
/* Hash algorithms */
CRYPT_ALGO_MD2 = 200, /* MD2 */
CRYPT_ALGO_MD4, /* MD4 */
CRYPT_ALGO_MD5, /* MD5 */
CRYPT_ALGO_SHA, /* SHA/SHA1 */
CRYPT_ALGO_RIPEMD160, /* RIPE-MD 160 */
/* CRYPT_ALGO_SHA2, /* SHA2 placeholder */
/* MAC's */
CRYPT_ALGO_HMAC_MD5 = 300, /* HMAC-MD5 */
CRYPT_ALGO_HMAC_SHA, /* HMAC-SHA */
CRYPT_ALGO_HMAC_RIPEMD160, /* HMAC-RIPEMD-160 */
/* Vendors may want to use their own algorithms which aren't part of the
general cryptlib suite. The following values are for vendor-defined
algorithms, and can be used just like the named algorithm types (it's
up to the vendor to keep track of what _VENDOR1 actually corresponds
to) */
#ifdef USE_VENDOR_ALGOS
CRYPT_ALGO_VENDOR1 = 10000, CRYPT_ALGO_VENDOR2, CRYPT_ALGO_VENDOR3,
#endif /* USE_VENDOR_ALGOS */
CRYPT_ALGO_LAST, /* Last possible crypt algo value */
/* In order that we can scan through a range of algorithms with
cryptQueryCapability(), we define the following boundary points for
each algorithm class */
CRYPT_ALGO_FIRST_CONVENTIONAL = CRYPT_ALGO_DES,
CRYPT_ALGO_LAST_CONVENTIONAL = CRYPT_ALGO_DH - 1,
CRYPT_ALGO_FIRST_PKC = CRYPT_ALGO_DH,
CRYPT_ALGO_LAST_PKC = CRYPT_ALGO_MD2 - 1,
CRYPT_ALGO_FIRST_HASH = CRYPT_ALGO_MD2,
CRYPT_ALGO_LAST_HASH = CRYPT_ALGO_HMAC_MD5 - 1,
CRYPT_ALGO_FIRST_MAC = CRYPT_ALGO_HMAC_MD5,
CRYPT_ALGO_LAST_MAC = CRYPT_ALGO_HMAC_MD5 + 99 /* End of mac algo.range */
} CRYPT_ALGO;
typedef enum { /* Block cipher modes */
CRYPT_MODE_NONE, /* No encryption mode */
CRYPT_MODE_ECB, /* ECB */
CRYPT_MODE_CBC, /* CBC */
CRYPT_MODE_CFB, /* CFB */
CRYPT_MODE_OFB, /* OFB */
CRYPT_MODE_LAST /* Last possible crypt mode value */
} CRYPT_MODE;
/* Keyset subtypes */
typedef enum { /* Keyset types */
CRYPT_KEYSET_NONE, /* No keyset type */
CRYPT_KEYSET_FILE, /* Generic flat file keyset */
CRYPT_KEYSET_HTTP, /* Web page containing cert/CRL */
CRYPT_KEYSET_LDAP, /* LDAP directory service */
CRYPT_KEYSET_ODBC, /* Generic ODBC interface */
CRYPT_KEYSET_MYSQL, /* MySQL RDBMS */
CRYPT_KEYSET_DATABASE, /* Generic database plugin */
CRYPT_KEYSET_ODBC_STORE, /* ODBC certificate store */
CRYPT_KEYSET_MYSQL_STORE, /* MySQL certificate store */
CRYPT_KEYSET_DATABASE_STORE, /* Database certificate store */
CRYPT_KEYSET_LAST /* Last possible keyset type */
#ifdef _CRYPT_DEFINED
/* Useful defines used internally for range checking */
, CRYPT_FIRST_RDBMS = CRYPT_KEYSET_ODBC,
CRYPT_LAST_RDBMS = CRYPT_KEYSET_LAST - 1
#endif /* _CRYPT_DEFINED */
} CRYPT_KEYSET_TYPE;
/* Device subtypes */
typedef enum { /* Crypto device types */
CRYPT_DEVICE_NONE, /* No crypto device */
CRYPT_DEVICE_FORTEZZA, /* Fortezza card */
CRYPT_DEVICE_PKCS11, /* PKCS #11 crypto token */
CRYPT_DEVICE_LAST /* Last possible crypto device type */
} CRYPT_DEVICE_TYPE;
/* Certificate subtypes */
typedef enum { /* Certificate object types */
CRYPT_CERTTYPE_NONE, /* No certificate type */
CRYPT_CERTTYPE_CERTIFICATE, /* Certificate */
CRYPT_CERTTYPE_ATTRIBUTE_CERT, /* Attribute certificate */
CRYPT_CERTTYPE_CERTCHAIN, /* PKCS #7 certificate chain */
CRYPT_CERTTYPE_CERTREQUEST, /* PKCS #10 certification request */
CRYPT_CERTTYPE_REQUEST_CERT, /* CRMF certification request */
CRYPT_CERTTYPE_REQUEST_REVOCATION, /* CRMF revocation request */
CRYPT_CERTTYPE_CRL, /* CRL */
CRYPT_CERTTYPE_CMS_ATTRIBUTES, /* CMS attributes */
CRYPT_CERTTYPE_OCSP_REQUEST, /* OCSP request */
CRYPT_CERTTYPE_OCSP_RESPONSE, /* OCSP response */
CRYPT_CERTTYPE_PKIUSER, /* PKI user information */
#ifdef _CRYPT_DEFINED
/* Alongside the usual types we can also wind up with various
certificate-bagging schemes such as cert chains and sequences which
can't be exported in this format and therefore aren't visible to the
user, but which need to be distinguished internally. The following
types are only visible internally */
CRYPT_CERTTYPE_CMS_CERTSET, /* CMS SET OF Certificate = cert chain */
CRYPT_CERTTYPE_SSL_CERTCHAIN, /* SSL certificate chain = cert chain */
#endif /* _CRYPT_DEFINED */
CRYPT_CERTTYPE_LAST /* Last possible cert.type */
#ifdef _CRYPT_DEFINED
, CRYPT_CERTTYPE_LAST_EXTERNAL = CRYPT_CERTTYPE_CMS_CERTSET
#endif /* _CRYPT_DEFINED */
} CRYPT_CERTTYPE_TYPE;
/* Envelope/data format subtypes */
typedef enum {
CRYPT_FORMAT_NONE, /* No format type */
CRYPT_FORMAT_AUTO, /* Deenv, auto-determine type */
CRYPT_FORMAT_CRYPTLIB, /* cryptlib native format */
CRYPT_FORMAT_CMS, /* PKCS #7 / CMS / S/MIME fmt.*/
CRYPT_FORMAT_PKCS7 = CRYPT_FORMAT_CMS,
CRYPT_FORMAT_SMIME, /* As CMS with MSG-style behaviour */
CRYPT_FORMAT_PGP, /* PGP format */
CRYPT_FORMAT_LAST /* Last possible format type */
} CRYPT_FORMAT_TYPE;
/* Session subtypes */
typedef enum {
CRYPT_SESSION_NONE, /* No session type */
CRYPT_SESSION_SSH, /* SSH */
CRYPT_SESSION_SSH_SERVER, /* SSH server */
CRYPT_SESSION_SSL, /* SSL/TLS */
CRYPT_SESSION_SSL_SERVER, /* SSL/TLS server */
CRYPT_SESSION_OCSP, /* OCSP */
CRYPT_SESSION_OCSP_SERVER, /* OCSP server */
CRYPT_SESSION_TSP, /* TSP */
CRYPT_SESSION_TSP_SERVER, /* TSP server */
CRYPT_SESSION_CMP, /* PKIX CMP */
CRYPT_SESSION_CMP_SERVER, /* PKIX CMP server */
CRYPT_SESSION_LAST /* Last possible session type */
} CRYPT_SESSION_TYPE;
/* User subtypes */
typedef enum {
CRYPT_USER_NONE, /* No user type */
CRYPT_USER_NORMAL, /* Normal user */
CRYPT_USER_SO, /* Security officer */
CRYPT_USER_CA, /* CA user */
CRYPT_USER_LAST /* Last possible user type */
} CRYPT_USER_TYPE;
/****************************************************************************
* *
* Attribute Types *
* *
****************************************************************************/
/* Attribute types. These are arranged in the following order:
PROPERTY - Object property
ATTRIBUTE - Generic attributes
OPTION - Global or object-specific config.option
CTXINFO - Context-specific attribute
CERTINFO - Certificate-specific attribute
KEYINFO - Keyset-specific attribute
DEVINFO - Device-specific attribute
ENVINFO - Envelope-specific attribute
SESSINFO - Session-specific attribute
USERINFO - User-specific attribute */
typedef enum {
CRYPT_ATTRIBUTE_NONE, /* Non-value */
/* Used internally */
CRYPT_PROPERTY_FIRST,
/*********************/
/* Object attributes */
/*********************/
/* Object properties */
CRYPT_PROPERTY_HIGHSECURITY, /* Owned+non-forwardable+locked */
CRYPT_PROPERTY_OWNER, /* Object owner */
CRYPT_PROPERTY_FORWARDABLE, /* No.of times object can be forwarded */
CRYPT_PROPERTY_LOCKED, /* Whether properties can be chged/read */
CRYPT_PROPERTY_USAGECOUNT, /* Usage count before object expires */
CRYPT_PROPERTY_NONEXPORTABLE, /* Whether key is nonexp.from context */
/* Used internally */
CRYPT_PROPERTY_LAST, CRYPT_GENERIC_FIRST,
/* Extended error information */
CRYPT_ATTRIBUTE_ERRORTYPE, /* Type of last error */
CRYPT_ATTRIBUTE_ERRORLOCUS, /* Locus of last error */
CRYPT_ATTRIBUTE_INT_ERRORCODE, /* Low-level software-specific */
CRYPT_ATTRIBUTE_INT_ERRORMESSAGE, /* error code and message */
/* Generic information */
CRYPT_ATTRIBUTE_BUFFERSIZE, /* Internal data buffer size */
/* User internally */
CRYPT_GENERIC_LAST, CRYPT_OPTION_FIRST = 100,
/****************************/
/* Configuration attributes */
/****************************/
/* cryptlib information (read-only) */
CRYPT_OPTION_INFO_DESCRIPTION, /* Text description */
CRYPT_OPTION_INFO_COPYRIGHT, /* Copyright notice */
CRYPT_OPTION_INFO_MAJORVERSION, /* Major release version */
CRYPT_OPTION_INFO_MINORVERSION, /* Minor release version */
CRYPT_OPTION_INFO_STEPPING, /* Release stepping */
/* Encryption options */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?