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

📄 random.h

📁 BestCrypt开源加密原代码
💻 H
字号:
// $Id: random.h,v 1.2 2002/10/29 07:11:46 crypt Rel-1.6-5 $#ifndef __RANDOM_H__#define __RANDOM_H__#include <stddef.h>#include "sha1.h"typedef struct{	byte state [ SHA1_DIGEST_SIZE ];	/* Current state buffer */	byte data  [ SHA1_DIGEST_SIZE ];	/* Stored random data   */	unsigned int  residue;				/* Quantity of unused bytes */} sSHA1Random;#define RNGRESULT unsigned intenum  { 	RNG_OK = 0,	RNG_MALLOC_ERROR,	RNG_INIT_ERROR};/*************************************************************************************\** Function:  SHA1RandomAllocate*	sSHA1Random **sRandom				- pointer to sSHA1Random structure pointer;** Return value:*  If successfull return RNG_OK.*\*************************************************************************************/RNGRESULT SHA1RandomAllocate( sSHA1Random **sRandom );/*************************************************************************************\** Function:  SHA1RandomInit - zeroes random structure.*	sSHA1Random *sRandom				- pointer to sSHA1Random structure;*\*************************************************************************************/void SHA1RandomInit( sSHA1Random *sRandom );/*************************************************************************************\** Function:  SHA1RandomUpdate*	sSHA1Random *sRandom	- pointer to sSHA1Random structure;*	const byte *seedBuffer	- pointer to initialisation buffer;*	int seedBufferSize		- size of the initialization buffer;** Description:*  SHA1RandomInit initializes the sRandom struct by zero.*  Use this function to initialize current random state by seedBuffer.*  The seedBufferSize does not limited. State will always padded by SHA1 digest*  algorithm.*\*************************************************************************************/void SHA1RandomUpdate(	sSHA1Random *sRandom ,	const byte *seedBuffer ,	int seedBufferSize );/*************************************************************************************\** Function: SHA1RandomGenerateBytes (*	sSHA1Random *sRandom		- pointer to sSHA1Random structure;*	unsigned char *buffer	- pointer to buffer for new generated random data*	unsigned int bufferSize	- size in bytes of required random data** Description:*  sRandom structure must be initialized by SHA1RandomInit.*  SHA1RandomGenerate function can by called numerous times.\*************************************************************************************/void SHA1RandomGenerateBytes(	sSHA1Random *sRandom,	unsigned char *buffer ,	unsigned int bufferSize);/*************************************************************************************\** Function: SHA1RandomFinal - deallocate random structure.* Parameter:*	sSHA1Random **sRandom		- double pointer to sSHA1Random structure;** Description:*  secure zeroizes sRandom structure and deallocate it.\*************************************************************************************/void SHA1RandomFinal ( sSHA1Random **sRandom );/*************************************************************************************\*	Function : SHA1RandomGenerate*		High level function.*		Allocate and initialize SHA1 random generator;*		Set seed by seedBuffer;*		Generate random sequence of bytes to buffer;*		Free SHA1 random generator.*	Params:*		byte	*byteBuffer ,	- destination buffer for random generation.*		size_t	byteBufferSize,	- size of destnation buffer in bytes.*		byte	*seedBuffer ,	- seed byte stream to initaialize prime random generator.*		size_t	seedBufferSize	- size of seedBuffer in bytes.*  Return value :*		Return RNG_OK if successful.\*************************************************************************************/extern "C" RNGRESULT SHA1RandomGenerate(	byte *byteBuffer ,	size_t byteBufferSize ,	byte *seedBuffer ,	size_t seedBufferSize );////	Main difference in random generation is,//	SHA1RandomGenerateBytesEx does not use //		the SHA1RandomReGenerate ( the function simple increments sRandom->state ),//		SHA1RandomGenerateBytesEx processes current state first and //		then processes all seed again.extern "C" RNGRESULT SHA1RandomGenerateKey(	byte *byteBuffer ,	size_t byteBufferSize ,	byte *seedBuffer ,	size_t seedBufferSize );#endif /* __RANDOM_H__ */

⌨️ 快捷键说明

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