fnaaccumulator.h

来自「手机加密通话软件」· C头文件 代码 · 共 62 行

H
62
字号
/* Copyright 2001,2002,2003 NAH6 BV
 * All Rights Reserved
 *
 *  $Header: /var/lib/cvs/secphone/ui/rng/fortuna/fnaAccumulator.h,v 1.3 2003/11/21 12:39:24 itsme Exp $
 *
 *
 */


#ifndef __FNAACCUMULATOR_H__

#include "vectorutils.h"
#include "fnaPool.h"
#include "fnaGenerator.h"
#include "winMutex.h"

//--------------------------------------------------------------------------
//
// the Accumulator is also referred to as the 'PRNG' in practical cryptography
//
// todo: add flag that signals if we are seeded properly
class Accumulator {
public:
    typedef int sourcenumber_t;
    typedef int poolnumber_t;

    Accumulator();
    ~Accumulator();

    void Initialize();

    bool AddRandomEvent(sourcenumber_t source, poolnumber_t pool, const ByteVector& data);
    bool RandomData(int nBytesRequested, ByteVector& r);

    bool UpdateSeedFile();
    void DoReseed();
    bool WriteSeedFile();

    enum { NROFSOURCES= 256 };
    enum { NROFPOOLS= 32 };
    enum { MINIMUMPOOLSIZE= 64 };           // in bytes
    enum { MINIMUMRESEEDINTERVAL= 100 };    // in msec
    enum { SEEDFILESIZE= 64 };              // in bytes

private:
    Pool m_pools[NROFPOOLS];

    Mutex m_mutexUpdateSeed;

    Generator m_generator;
    DWORD m_reseedtime;
    DWORD m_reseedcount;
    bool m_properly_seeded;

    void AddSystemTimeToRandom(ByteVector& random);

};


#define __FNAACCUMULATOR_H__
#endif

⌨️ 快捷键说明

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