⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 optest.h

📁 PGP SDK 包括大范围的标准加密、数字签名和编解码技术
💻 H
字号:
/*____________________________________________________________________________
optest.h

Copyright (C) 2003,2004 PGP Corporation
All rights reserved.

FIPS 140-2 Operational Test

$Id: optest.h 48493 2006-10-12 21:19:56Z vinnie $
____________________________________________________________________________*/


/****************************************************************************
	Includes
****************************************************************************/

#if PGP_UNIX_AIX
#include <strings.h>
#endif

#ifndef MAX_PATH
#define MAX_PATH 256
#endif

#include "pgpErrors.h"
#include "pgpEncode.h"
#include "pgpFeatures.h"
#include "pgpOptionList.h"

/****************************************************************************
	Defines
****************************************************************************/

#ifndef MAX
#define MAX(a,b) (a >= b ? a : b)
#endif

 


#define kBobsKeyIDString	"0x8E10CFE6"
#define kAlicesKeyIDString	"0xEE481634" 
#define kAlicesOldSubKeyString "0xB00FE68B"
#define kEvesKeyIDString	"0x7A8FCA1C"

#define kOptestCAKeyIDString	"0x7EBC2CA6"
#define kOptestEOKeyIDString	"0xBAE21432"
#define kOptestSOKeyIDString	"0xA7FEB0D8"

#define kOptestTestKeyIDString	"0x1A52E54E"
#define kOptestTestKey2IDString	"0x18629903"
#define kRSATestKeyIDString		"0xB687D650"
#define kDSSTestKeyIDString		"0x14500175"

#define kBobsPassPhrase			"bobs passphrase" 
#define	kAlicesPassPhrase		"alices passphrase" 
#define kOptestCAKeyPassPhrase	"optest" 
#define kOptestSOKeyPassPhrase	"optest" 
#define kOptestEOKeyPassPhrase	"optest" 
#define	kOptestTestKeyPassPhrase "optest" 
#define	kOptestTestKey2PassPhrase "optest" 
#define	kOptestBundlePassPhrase "bundle" 

#define	kDSSTestKeyPassPhrase	"Unlocking passphrase" 
#define	kRSATestKeyPassPhrase	"Unlocking passphrase" 
#define kSymmetricPassPhrase	"si vis pacem, para bellum" 
 
 
/****************************************************************************
	Macros & Inlines
****************************************************************************/
 
#define pgpMemoryEqual(b1, b2, length)							\
(memcmp((void *)(b1), (void *)(b2), (length)) == 0)
 
#define COPY(b1, b2, len)							\
memcpy((void *)(b2), (void *)b1, (int)(len) )
  
#define ZERO(b1, len) \
memset((void *)(b1), 0, (int)(len) )

#ifndef IsNull
#define IsntNull( p )	( (PGPBoolean) ( (p) != NULL ) )
#define IsNull( p )		( (PGPBoolean) ( (p) == NULL ) )
#endif

#define ALLOC(_n) malloc(_n)
#define FREE(_p) free(_p)
#define REALLOC(_p,_n) realloc(_p, _n)
 

#define RETERR(x)	do { err = x; goto done; } while(0)
#define BKERR		if(IsPGPError(err)) break; 
#define MARK_ERR(_rv,_rv1)  if(IsPGPError(_rv1) && (_rv1 != kPGPError_EndOfIteration)) { \
 		_rv = _rv1;}

#define FAIL(_msg)  {\
		opTestTrace( __FILE__, __LINE__,__FUNCTION__, _msg); \
		err = kPGPError_SelfTestFailed; \
		goto done; }
 
#ifdef PGP_USE_TRACE_MACRO

#define PGP_NEED_TRACE_FUNC

	#define CKNULL(_p) if(IsNull(_p)) {\
		opTestTrace( __FILE__, __LINE__,__FUNCTION__,"Failed with Null value"); \
		err = kPGPError_OutOfMemory; \
		goto done; }

	#define CKERR  if(IsPGPError(err)) {\
	  	char _errstr[256];				\
		PGPGetErrorString( err, 256, _errstr); \
		opTestTrace( __FILE__, __LINE__,__FUNCTION__,"Failed with %d, %s", err, _errstr); \
		goto done; }


#else
 	
	#define CKNULL(_p) if(IsNull(_p)) {\
 		err = kPGPError_OutOfMemory; \
		goto done; }

	#define CKERR  if(IsPGPError(err)) {\
 		goto done; }

 
#endif

#if PGP_MOBILE
int OPTESTPrintF(const char *, ...);
int OPTESTVPrintF(const char *, va_list);
int OPTEST_IF_PrintF(const char *, ...);
 
#else
#define OPTESTPrintF printf
#define OPTEST_IF_PrintF if(gVerbose_flag) printf
#define OPTESTVPrintF vprintf
#endif

#if PGP_UNIX_DARWIN
#define STRICMP		strcasecmp
#else
#define STRICMP		stricmp
#endif


/****************************************************************************
	Globals
****************************************************************************/

extern PGPBoolean	gVerbose_flag;
extern PGPBoolean	gDebug_flag;
extern char*		gOutputDirectory;
extern char*		gTestVectorsDirectory;
extern char*		gTestKeysPath;
extern char*		gP11Module;
extern char*		gTokenSOPIN;
extern char*		gTokenUserPIN;
extern PGPUInt32	gTokNumber;
 

/****************************************************************************
	Typedefs & Structures
****************************************************************************/
/* decode Event options */
typedef enum   
{
	kDecode_NoOption	= 0,
	kDecode_DumpTar,
	kDecode_UnpackTar,
	kDecode_MakeTarCache,
	kDecode_AllocOutput,
	kDecode_FileOutput,
	kDecode_Ignore_Output,
   	PGP_ENUM_FORCE( EventHandlerOptions )
 } EventHandlerOptions;
 
 
typedef struct 
{
	EventHandlerOptions option;
  	PGPByte				*sessionKey;
	PGPSize				sessionKeySize;
	PGPFileSpecRef		outFile;
	PGPByte				*outBuf;
	PGPSize				outBufSize;
	PGPByte				*outDir;
	
	int					keyCount;
	PGPKeyIterRef		keyIter;
 	struct {
		PGPKeyID		keyID;
		const   char    *passPhrase;
	} key[8];
	
 } DecodeInfo;

typedef  enum	 
{
	kTokenTestFlags_KeyTest			= (1UL << 0 ),
	kTokenTestFlags_Format			= (1UL << 1 ),
	kTokenTestFlags_Generate		= (1UL << 2 ),
	kTokenTestFlags_Export			= (1UL << 3 ),
	kTokenTestFlags_Delete			= (1UL << 4 ),
	kTokenTestFlags_Wipe			= (1UL << 5 ),
 } TokenTestFlags;
 
  
 //#define PGP_USE_TRACE_MACRO 1

/****************************************************************************
	functions
****************************************************************************/

/* Optest test functions */

PGPError TestSHA 	(PGPContextRef context );
PGPError TestHMAC 	(PGPContextRef context );
PGPError TestCiphers(PGPContextRef context );
PGPError TestKeys   (PGPContextRef context );

PGPError TestRNG	(PGPContextRef context);
PGPError TestX9_31	(PGPContextRef context);
PGPError TestKeyGen (PGPContextRef context );
PGPError TestKeyMgmt(PGPContextRef context);
PGPError TestSecretSharing	(PGPContextRef context);
PGPError TestEncodeDecode	(PGPContextRef context);
PGPError TestExpiredKey 	(PGPContextRef context );
PGPError TestKeyUsage		(PGPContextRef context);
PGPError TestTarEncode		(PGPContextRef context);
PGPError TestTokens			(PGPContextRef context, TokenTestFlags flags );
PGPError TestKeyServer		(PGPContextRef context );
PGPError TestX509			(PGPContextRef context );
PGPError TestRecon			(PGPContextRef context );

PGPError ConsoleAcquireEntropy(PGPContextRef context, PGPUInt32 entropyNeeded,
								PGPUInt32 * pEntropyAcquired, PGPBoolean bOutputProgress);

PGPError TestKeyCertificate (   PGPContextRef   context,
								PGPKeyDBObjRef  theKey,
								const PGPByte * pass,
								const PGPByte * encodeData,
								const PGPSize   encodeDataLen,
								const PGPByte * signData,
								const PGPSize   signDataLen,
								const PGPByte * katSigData,
								const PGPSize   katSigDataLen );
 
/* support functions */
PGPBoolean canKeySignMessages( PGPKeyDBObjRef key);
PGPBoolean canKeySignUserIDs( PGPKeyDBObjRef key);

PGPBoolean canKeyVerify( PGPKeyDBObjRef key);
PGPBoolean canKeyEncrypt( PGPKeyDBObjRef key);
PGPBoolean canKeyDecrypt( PGPKeyDBObjRef key);

PGPChar *	key_algor_table(int keytype);
PGPChar *	hash_algor_table(int algor);
PGPChar *	cipher_algor_table(int algor);
PGPChar *	compression_algor_table(int algor);
PGPChar *	email_encoding_table(int encoding);
PGPError	getCipherInfo(PGPCipherAlgorithm algor, PGPAlgorithmInfo* info);

PGPError	OptestEventHandler(PGPContextRef context, PGPEvent *event, PGPUserValue userValue);
void		CleanUpDecodeInfo( DecodeInfo* info);
void		InitDecodeInfo( DecodeInfo* info);
PGPError	importKeys (PGPContextRef context,  const PGPChar8 *path, PGPInputFormat format, PGPKeyDBRef *keyDB );
PGPError	GetAllocatedKeyInfoString(PGPKeyDBObjRef theKey, char *header,PGPBoolean biometric, void **buffer, PGPSize *dataSize);
void		printTruncated(char* data, int len, int max);
void		printKeyName( char *header, PGPKeyDBObjRef theKey);
PGPError	printKeyInfo( char *header, PGPKeyDBObjRef theKey);
PGPError	printSigInfo( char *header, PGPKeyDBObjRef	sig);
 PGPError	printKeyDetails( char *header, PGPBoolean biometric, PGPKeyDBObjRef theKey);
void		FormatFingerprintString(char *p, PGPByte *inBuffp, PGPSize len );
void		dumpHex( PGPByte* buffer, int length, int offset);
void		dumpLong( PGPByte* buffer, int length);
void		dumpTAR( PGPByte* buffer, int length, PGPBoolean detail);
PGPError	dumpTarCacheContent(PGPContextRef context, char* filename, PGPByte * sessionKey, char detail);
void		opTestTrace(const char *file, int line, const char *proc, const char *fmt, ...);  
int			makeDirectory(char *dirname);
int			makeFile(char *dirname);
PGPError	getPassphrase( PGPSize	 passphraseSize, PGPChar8 *passphrase);
PGPSize		addAV( PGPAVAttribute attribute, const char *value, PGPAttributeValue *av);
void		getPlatformInfo(char* osName, char* hwName);
 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -