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

📄 globrand.h

📁 伯克利做的SFTP安全文件传输协议
💻 H
字号:
// globrand.h// defines a global random pool, such that all modules can both//   (1) get strong random values, and//   (2) add entropy with it is available// copyright SafeTP Development Group, Inc., 2000  Terms of use are as specified in license.txt#ifndef __GLOBRAND_H#define __GLOBRAND_H#include "randpool.h"      // RandomPool#include "datablok.h"      // DataBlock// random generator with added security because it hashes everything on// the way out; this was an idea I had originally, but decided to actually// implement it after reading "Cryptanalytic Attacks on Pseudorandom// Number Generators" by Kelsey, Schneier, Wagner, and Hall, available// at counterpane.comclass HashedRandomPool : public RandomNumberGenerator {private:     // data  // pool I'm improving  RandomPool basePool;                   // internal random pool  // output hashing state  enum { BUFSIZE = 20 };                 // should be equal to SHA::DIGESTSIZE  byte outBuffer[BUFSIZE];               // bytes ready to output  int outPtr;                            // next byte to output  // state, so we can warn on failure to seed  bool notSeeded;private:     // funcs  // set state so next GetByte() triggers a refill of output buffer  void forceRehash();public:      // funcs  HashedRandomPool();  // RandomNumberGenerator interface  byte GetByte();  // entropy-adding interface, similar to RandomPool's  void Put(byte const *bytes, int length);  // seed saving and loading (not guaranteed to save or  // restore the exact state, but guaranteed to retain  // entropy across save/load)  DataBlock getSeed();  void seed(DataBlock const &seed);};// the pool// sm: I'm commenting this out to hide the name externally, since// all access needs to be protected by the lock; all of the public// entry points below take responsibility for protecting accesses//extern HashedRandomPool globalRandomPool;// there places we want to access the pool directly; this class can be// instantiated in those places, and will automatically lock/unlock// the poolclass GlobalRandomPool {public:  GlobalRandomPool();           // lock  ~GlobalRandomPool();          // unlock  HashedRandomPool &pool();     // access the pool};// read seed from persistent statevoid readRandomSeed(bool complain = true);  // if complain is true, we will print a warning message if  // the random seed file is missing// simple existence checkbool isRandomSeedThere();// save seed to persistent statevoid saveRandomSeed();// add entropy based on time and other queryable statsvoid addEntropy();// add whatever entropy is available from some valuevoid addEntropy(long value);// occasionally-convenient interfaceDataBlock getRandomBytes(int bytes);#endif // __GLOBRAND_H

⌨️ 快捷键说明

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