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

📄 yarrow.h

📁 Vovida 社区开源的 SIP 协议源码
💻 H
字号:
/* -*- Mode: C; c-file-style: "bsd" -*- */#ifndef YARROW_H#define YARROW_H#if defined( YARROW_DETECT_FORK )#include <unistd.h>#endif#include "ytypes.h"#include "yhash.h"#include "ycipher.h"/* These error codes are returned by the functions below. */#define YARROW_OK                1  /* All is well */#define YARROW_FAIL              0  /* generic failure */#define YARROW_NOT_INIT         -1  /* YarrowInit hasn't been called */#define YARROW_ALREADY_INIT     -2  /* YarrowInit has already been called */#define YARROW_NO_DRIVER        -3  /* driver doesn't exist */#define YARROW_CANT_OPEN        -4  /* can't open driver */#define YARROW_BAD_SOURCE       -5  /* invalid source id */#define YARROW_TOO_MANY_SOURCES -6  /* can't create any more source ids */#define YARROW_BAD_ARG          -7  /* invalid argument */#define YARROW_ACCESS           -8  /* insufficient privileges */#define YARROW_NOMEM            -9  /* out of memory */#define YARROW_NORSRC          -10  /* a resource is exhausted */#define YARROW_NOT_SEEDED      -11  /* not enough entropy to generate output */#define YARROW_LOCKING         -12  /* locking error */#define YARROW_NO_STATE        -13  /* there is no state to load */#define YARROW_STATE_ERROR     -14  /* error with state load or save */#define YARROW_NOT_IMPL        -15  /* not implemented */#ifdef __cplusplusextern "C" {#endif/* Yarrow implementation and configuration parameters *//* pool identification */#define YARROW_FAST_POOL 0#define YARROW_SLOW_POOL 1#define YARROW_MAX_SOURCES 20#define YARROW_ENTROPY_MULTIPLIER 0.5#define YARROW_POOL_SIZE (HASH_DIGEST_SIZE*8)#define YARROW_OUTPUTS_PER_GATE 10   /* Pg */#define YARROW_FAST_PT 10#define YARROW_SLOW_PT 100/* thresholds to use once seeded */#define YARROW_FAST_THRESH 100#define YARROW_SLOW_THRESH 160#define YARROW_K_OF_N_THRESH 2/* The Yarrow paper does not specify when the initial seed should be   considered complete. Use the same conditions as a slow reseed */#define YARROW_FAST_INIT_THRESH YARROW_FAST_THRESH#define YARROW_SLOW_INIT_THRESH YARROW_SLOW_THRESH#define YARROW_K_OF_N_INIT_THRESH YARROW_K_OF_N_THRESH/* sanity checks */#if YARROW_FAST_THRESH > YARROW_POOL_SIZE#undef YARROW_FAST_THRESH#define YARROW_FAST_THRESH YARROW_POOL_SIZE#endif#if YARROW_SLOW_THRESH > YARROW_POOL_SIZE#undef YARROW_SLOW_THRESH#define YARROW_SLOW_THRESH YARROW_POOL_SIZE#endif#if YARROW_FAST_INIT_THRESH > YARROW_POOL_SIZE#undef YARROW_FAST_INIT_THRESH#define YARROW_FAST_INIT_THRESH YARROW_POOL_SIZE#endif#if YARROW_SLOW_INIT_THRESH > YARROW_POOL_SIZE#undef YARROW_SLOW_INIT_THRESH#define YARROW_SLOW_INIT_THRESH YARROW_POOL_SIZE#endiftypedef size_t estimator_fn(const void* sample, size_t size);typedef struct{    int pool;    int entropy[2];    int reached_slow_thresh;    estimator_fn* estimator;} Source;typedef struct{    /* state */    int seeded;    int saved;#if defined( YARROW_DETECT_FORK )    int pid;#endif    Source source[YARROW_MAX_SOURCES];    unsigned num_sources;    HASH_CTX pool[2];    byte out[CIPHER_BLOCK_SIZE];    unsigned out_left;    COUNTER out_count;    COUNTER gate_count;    COUNTER gates_limit;    byte C[CIPHER_BLOCK_SIZE];    CIPHER_CTX cipher;    byte K[CIPHER_KEY_SIZE];    const char *entropyfile;    /* parameters */    COUNTER Pt[2];    COUNTER Pg;    int slow_k_of_n;    /* current thresholds */    int slow_thresh;    int fast_thresh;    int slow_k_of_n_thresh;} Yarrow_CTX;#if defined(WIN32)#   if defined(YARROW_IMPL)#       define YARROW_DLL __declspec(dllexport) #   else#       define YARROW_DLL __declspec(dllimport) #   endif#else#   define YARROW_DLL#endifYARROW_DLLint Yarrow_Init( Yarrow_CTX* y, const char *filename );YARROW_DLLint Yarrow_Poll( Yarrow_CTX *y, unsigned source_id );YARROW_DLLint Yarrow_Input( Yarrow_CTX* y, unsigned source_id,		  const void* sample, 		  size_t size, size_t entropy_bits );YARROW_DLLint Yarrow_Status( Yarrow_CTX* y, int *num_sources, unsigned *source_id,		   size_t *entropy_bits, size_t *entropy_max );YARROW_DLLint Yarrow_Output( Yarrow_CTX* y, void* out, size_t size );YARROW_DLLint Yarrow_New_Source( Yarrow_CTX* y, unsigned* source_id );YARROW_DLLint Yarrow_Register_Source_Estimator( Yarrow_CTX* y, unsigned source_id, 				      estimator_fn* fptr );YARROW_DLLint Yarrow_Stretch( const byte* m, size_t size, byte* out, size_t out_size );YARROW_DLLint Yarrow_Reseed( Yarrow_CTX* y, int pool );YARROW_DLLint Yarrow_Gate( Yarrow_CTX* y );YARROW_DLLint Yarrow_Final( Yarrow_CTX* y );YARROW_DLLconst char* Yarrow_Str_Error( int );/* portability stuff */#if defined(macintosh) && YARROW_DRIVER && TARGET_CPU_PPC#   define mem_zero(p, n)       BlockZero((p), (n))#   define mem_copy(d, s, n)    BlockMoveData((s), (d), (n))#else#   define mem_zero(p, n)       memset((p), 0, (n))#   define mem_copy(d, s, n)    memcpy((d), (s), (n))#endif#if !defined(WIN32)#   define min(x, y) ((x) < (y) ? (x) : (y))#   define max(x, y) ((x) > (y) ? (x) : (y))#endif/* end portability stuff */#ifdef __cplusplus}#endif#endif /* YARROW_H */

⌨️ 快捷键说明

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