📄 int_api.h
字号:
/****************************************************************************
* *
* cryptlib Internal API Header File *
* Copyright Peter Gutmann 1992-2007 *
* *
****************************************************************************/
#ifndef _INTAPI_DEFINED
#define _INTAPI_DEFINED
/* Internal forms of various external functions. These work with internal
resources that are marked as being inaccessible to the corresponding
external functions, and don't perform all the checking that their
external equivalents perform, since the parameters have already been
checked by cryptlib */
CHECK_RETVAL STDC_NONNULL_ARG( ( 3 ) ) \
int iCryptCreateSignature( OUT_BUFFER_OPT( signatureMaxLength, *signatureLength ) \
void *signature,
IN_LENGTH const int signatureMaxLength,
OUT_LENGTH_Z int *signatureLength,
IN_ENUM( CRYPT_FORMAT ) \
const CRYPT_FORMAT_TYPE formatType,
IN_HANDLE const CRYPT_CONTEXT iSignContext,
IN_HANDLE const CRYPT_CONTEXT iHashContext,
IN_HANDLE_OPT const CRYPT_CERTIFICATE iExtraData,
IN_HANDLE_OPT const CRYPT_SESSION iTspSession );
CHECK_RETVAL STDC_NONNULL_ARG( ( 1 ) ) \
int iCryptCheckSignature( IN_BUFFER( signatureLength ) const void *signature,
IN_LENGTH_SHORT const int signatureLength,
IN_ENUM( CRYPT_FORMAT ) \
const CRYPT_FORMAT_TYPE formatType,
IN_HANDLE const CRYPT_HANDLE iSigCheckKey,
IN_HANDLE const CRYPT_CONTEXT iHashContext,
IN_HANDLE const CRYPT_CONTEXT iHash2Context,
OUT_OPT_HANDLE_OPT CRYPT_HANDLE *extraData );
CHECK_RETVAL STDC_NONNULL_ARG( ( 1 ) ) \
int iCryptImportKey( IN_BUFFER( encryptedKeyLength ) const void *encryptedKey,
IN_LENGTH_SHORT const int encryptedKeyLength,
IN_ENUM( CRYPT_FORMAT ) \
const CRYPT_FORMAT_TYPE formatType,
IN_HANDLE const CRYPT_CONTEXT iImportKey,
IN_HANDLE_OPT const CRYPT_CONTEXT iSessionKeyContext,
OUT_OPT_HANDLE_OPT CRYPT_CONTEXT *iReturnedContext );
CHECK_RETVAL STDC_NONNULL_ARG( ( 3 ) ) \
int iCryptExportKey( OUT_BUFFER_OPT( encryptedKeyMaxLength, *encryptedKeyLength ) \
void *encryptedKey,
IN_LENGTH_Z const int encryptedKeyMaxLength,
OUT_LENGTH_Z int *encryptedKeyLength,
IN_ENUM( CRYPT_FORMAT ) \
const CRYPT_FORMAT_TYPE formatType,
IN_HANDLE_OPT const CRYPT_CONTEXT iSessionKeyContext,
IN_HANDLE const CRYPT_CONTEXT iExportKey );
/* Copy a string attribute to external storage, with various range checks
to follow the cryptlib external API semantics. There are two variants
of this function depending on whether the result parameters are passed
in as discrete values or packed into a MESSAGE_DATA struct */
CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 2 ) ) \
int attributeCopy( INOUT MESSAGE_DATA *msgData,
IN_BUFFER( attributeLength ) const void *attribute,
IN_LENGTH_SHORT_Z const int attributeLength );
CHECK_RETVAL STDC_NONNULL_ARG( ( 3, 4 ) ) \
int attributeCopyParams( OUT_BUFFER_OPT( destMaxLength, *destLength ) void *dest,
IN_LENGTH_SHORT_Z const int destMaxLength,
OUT_LENGTH_SHORT_Z int *destLength,
IN_BUFFER( sourceLength ) const void *source,
IN_LENGTH_SHORT_Z const int sourceLength );
/* Check whether a password is valid or not. Currently this just checks that
it contains at least one character, but stronger checking can be
substituted if required */
#ifdef UNICODE_CHARS
#define isBadPassword( password ) \
( !isReadPtr( password, sizeof( wchar_t ) ) || \
( wcslen( password ) < 1 ) )
#else
#define isBadPassword( password ) \
( !isReadPtr( password, 1 ) || \
( strlen( password ) < 1 ) )
#endif /* Unicode vs. ASCII environments */
/* Check whether a given algorithm is available for use. This is performed
frequently enough that we have a special krnlSendMessage() wrapper
function for it rather than having to explicitly query the system
object */
CHECK_RETVAL_BOOL \
BOOLEAN algoAvailable( IN_ALGO const CRYPT_ALGO_TYPE cryptAlgo );
/* For a given algorithm pair, check whether the first is stronger than the
second */
CHECK_RETVAL_BOOL \
BOOLEAN isStrongerHash( IN_ALGO const CRYPT_ALGO_TYPE algorithm1,
IN_ALGO const CRYPT_ALGO_TYPE algorithm2 );
/* Check that a string has at least a minimal amount of entropy. This is
used as a sanity-check on (supposedly) random keys before we load them */
CHECK_RETVAL STDC_NONNULL_ARG( ( 1 ) ) \
BOOLEAN checkEntropy( IN_BUFFER( dataLength ) const BYTE *data,
IN_LENGTH_SHORT_MIN( MIN_KEYSIZE ) const int dataLength );
/* Map one value to another, used to map values from one representation
(e.g. PGP algorithms or HMAC algorithms) to another (cryptlib algorithms
or the underlying hash used for the HMAC algorithm) */
typedef struct {
int source, destination;
} MAP_TABLE;
CHECK_RETVAL STDC_NONNULL_ARG( ( 2, 3 ) ) \
int mapValue( IN_INT_SHORT_Z const int srcValue,
OUT_INT_SHORT_Z int *destValue,
IN_ARRAY( mapTblSize ) const MAP_TABLE *mapTbl,
IN_LENGTH_SHORT const int mapTblSize );
/* Read a line of text from a stream. The caller passes in a character-read
function callback that returns the next character from a supplied input
stream, and readTextLine() uses it to fetch the next line of input up to
an EOL. The localError flag is set when the returned error code was
generated by readTextLine() itself, rather than being passed up from the
character-read function. This allows the caller to report the errors
differently, for example a data-formatting error vs. a network I/O error.
It would be nice if we could declare READCHARFUNCTION as taking a
STREAM * but this header gets included long before the stream header does
so the STREAM structure isn't visible at this point */
CHECK_RETVAL STDC_NONNULL_ARG( ( 1 ) ) \
typedef int ( *READCHARFUNCTION )( INOUT void *streamPtr );
CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 2, 3, 5 ) ) \
int readTextLine( READCHARFUNCTION readCharFunction,
INOUT void *streamPtr,
OUT_BUFFER( lineBufferMaxLen, lineBufferSize ) char *lineBuffer,
IN_LENGTH_SHORT_MIN( 10 ) const int lineBufferMaxLen,
OUT_LENGTH_SHORT_Z int *lineBufferSize,
OUT_OPT_BOOL BOOLEAN *localError );
/* Get OS-specific values */
#if defined( __WIN32__ ) || defined( __WINCE__ )
typedef enum {
SYSVAR_NONE, /* No system variable */
SYSVAR_OSVERSION, /* OS version number */
SYSVAR_ISWIN95, /* Whether code base is Win95 or WinNT */
SYSVAR_HWCAP, /* Hardware crypto capabilities */
SYSVAR_PAGESIZE, /* System page size */
SYSVAR_LAST /* Last valid system variable type */
} SYSVAR_TYPE;
#elif defined( __UNIX__ )
typedef enum {
SYSVAR_NONE, /* No system variable */
SYSVAR_HWCAP, /* Hardware crypto capabilities */
SYSVAR_PAGESIZE, /* System page size */
SYSVAR_LAST /* Last valid system variable type */
} SYSVAR_TYPE;
#else
typedef enum { SYSVAR_NONE, SYSVAR_LAST } SYSVAR_TYPE;
#endif /* OS-specific system variable types */
CHECK_RETVAL \
int initSysVars( void );
CHECK_RETVAL \
int getSysVar( const SYSVAR_TYPE type );
/* Flags for SYSVAR_HWCAP capabilities */
#define HWCAP_FLAG_NONE 0x00 /* No special HW capabilities */
#define HWCAP_FLAG_RDTSC 0x01 /* x86 RDTSC instruction support */
#define HWCAP_FLAG_XSTORE 0x02 /* VIA XSTORE instruction support */
#define HWCAP_FLAG_XCRYPT 0x04 /* VIA XCRYPT instruction support */
#define HWCAP_FLAG_XSHA 0x08 /* VIA XSHA instruction support */
#define HWCAP_FLAG_MONTMUL 0x10 /* VIA bignum instruction support */
#define HWCAP_FLAG_TRNG 0x20 /* Amd Geode LX TRNG MSR support */
/* Windows NT/2000/XP/Vista support ACL-based access control mechanisms for
system objects, so when we create objects such as files and threads we
give them an ACL that allows only the creator access. The following
functions return the security info needed when creating objects */
#ifdef __WINDOWS__
#ifdef __WIN32__
CHECK_RETVAL_PTR \
void *initACLInfo( const int access );
STDC_NONNULL_ARG( ( 1 ) ) \
void *getACLInfo( void *securityInfoPtr );
STDC_NONNULL_ARG( ( 1 ) ) \
void freeACLInfo( void *securityInfoPtr );
#else
#define initACLInfo( x ) NULL
#define getACLInfo( x ) NULL
#define freeACLInfo( x )
#endif /* __WIN32__ */
#endif /* __WINDOWS__ */
/****************************************************************************
* *
* String Functions *
* *
****************************************************************************/
/* Compare two strings in a case-insensitive manner for those systems that
don't have this function */
#if defined( __UNIX__ ) && !( defined( __CYGWIN__ ) )
#if defined( __TANDEM_NSK__ ) || defined( __TANDEM_OSS__ )
#include <strings.h>
#endif /* Tandem */
#define strnicmp strncasecmp
#define stricmp strcasecmp
#elif defined( __WINCE__ )
#define strnicmp _strnicmp
#define stricmp _stricmp
#elif defined( _MSC_VER ) && ( _MSC_VER >= 1300 )
/* VC++ 8 and up warn about these being deprecated Posix functions and
require the ANSI/ISO conformant _strXcmp */
#define strnicmp _strnicmp
#define stricmp _stricmp
#elif defined __PALMOS__
/* PalmOS has strcasecmp()/strncasecmp() but these aren't i18n-aware so we
have to use a system function instead */
#include <StringMgr.h>
#define strnicmp StrNCaselessCompare
#define stricmp StrCaselessCompare
#elif defined( __xxxOS___ )
int strnicmp( const char *src, const char *dest, const int length );
int stricmp( const char *src, const char *dest );
#endif /* OS-specific case-insensitive string compares */
/* Sanitise a string before passing it back to the user. This is used to
clear potential problem characters (for example control characters)
from strings passed back from untrusted sources. The function returns a
pointer to the string to allow it to be used in the form
printf( "..%s..", sanitiseString( string, strLen ) ). In addition it
formats the data to fit a fixed-length buffer. If the string is longer
than the indicated buffer size it appends a '[...]' at the end of the
buffer to indicate that further data was truncated */
STDC_NONNULL_ARG( ( 1 ) ) \
char *sanitiseString( INOUT_BUFFER_FIXED( strMaxLen ) BYTE *string,
IN_LENGTH_SHORT const int strMaxLen,
IN_LENGTH_SHORT const int strLen );
/* Perform various string-processing operations */
CHECK_RETVAL_STRINGOP( strLen ) STDC_NONNULL_ARG( ( 1 ) ) \
int strFindCh( IN_BUFFER( strLen ) const char *str,
IN_LENGTH_SHORT const int strLen,
IN_CHAR const int findCh );
CHECK_RETVAL_STRINGOP( strLen ) STDC_NONNULL_ARG( ( 1, 3 ) ) \
int strFindStr( IN_BUFFER( strLen ) const char *str,
IN_LENGTH_SHORT const int strLen,
IN_BUFFER( findStrLen ) const char *findStr,
IN_LENGTH_SHORT const int findStrLen );
CHECK_RETVAL_STRINGOP( strLen ) STDC_NONNULL_ARG( ( 1 ) ) \
int strSkipWhitespace( IN_BUFFER( strLen ) const char *str,
IN_LENGTH_SHORT const int strLen );
CHECK_RETVAL_STRINGOP( strLen ) STDC_NONNULL_ARG( ( 1 ) ) \
int strSkipNonWhitespace( IN_BUFFER( strLen ) const char *str,
IN_LENGTH_SHORT const int strLen );
CHECK_RETVAL_STRINGOP( strLen ) STDC_NONNULL_ARG( ( 1, 2 ) ) \
int strStripWhitespace( OUT_PTR char **newStringPtr,
IN_BUFFER( strLen ) const char *string,
IN_LENGTH_SHORT const int strLen );
CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 2 ) ) \
int strExtract( OUT_PTR char **newStringPtr,
IN_BUFFER( srcLen ) const char *string,
IN_LENGTH_SHORT const int startOffset,
IN_LENGTH_SHORT const int strLen );
CHECK_RETVAL STDC_NONNULL_ARG( ( 1 ) ) \
int strGetNumeric( IN_BUFFER( strLen ) const char *str,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -