rng.cpp

来自「含有多种公开密钥算法、多种块加密、多种数据流加密、多种HASH函数、多种Chec」· C++ 代码 · 共 46 行

CPP
46
字号
/* This file is in the public domain */#include <string>#include <cstdlib>#include <ctime>#include <botan/filters.h>#include <botan/randpool.h>#include <botan/x917_rng.h>using namespace Botan;/* Not too useful generally; just dumps random bits for benchmarking */class RNG_Filter : public Filter   {   public:      void write(const byte[], u32bit);      RNG_Filter(RandomNumberGenerator* r) : rng(r), buffer(1024)         { position = 0; }      ~RNG_Filter() { delete rng; }   private:      RandomNumberGenerator* rng;      SecureVector<byte> buffer;      u32bit position;   };void RNG_Filter::write(const byte[], u32bit length)   {   while(length)      {      u32bit gen = std::min(buffer.size() - position, length);      rng->randomize(buffer, buffer.size());      length -= gen;      }   }Filter* lookup_rng(const std::string& algname)   {   if(algname == "X9.17(Rijndael)")      return new RNG_Filter(new ANSI_X917_RNG);   if(algname == "Randpool")      return new RNG_Filter(new Randpool);   return 0;   }

⌨️ 快捷键说明

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