s2k.cpp

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

CPP
58
字号
/* This file is in the public domain */#include <vector>#include <string>#include <cstdlib>#include <botan/lookup.h>#include <botan/filters.h>#include <botan/pgp_s2k.h>using namespace Botan;/* A weird little hack to fit S2K algorithms into the validation suite   You probably wouldn't ever want to actually use the S2K algorithms like   this, the raw S2K interface is much more convenient for actually using them*/class S2K_Filter : public Filter   {   public:      void write(const byte in[], u32bit len)         { passphrase += std::string((const char*)in, len); }      void end_msg()         {         SymmetricKey x = s2k->derive_key(passphrase, outlen);         send(x, x.length());         }      S2K_Filter(S2K* algo, const SymmetricKey& s, u32bit o)         {         s2k = algo;         outlen = o;         s2k->change_salt(s, s.length());         }      ~S2K_Filter() { delete s2k; }   private:      std::string passphrase;      S2K* s2k;      u32bit outlen;   };Filter* lookup_s2k(const std::string& algname, const std::string& salt)   {   std::vector<std::string> name = parse_algorithm_name(algname);   if(name.size() == 0)      return 0;   const std::string s2k_name = deref_alias(name[0]);   if(s2k_name == "OpenPGP-S2K")      {      if(name.size() != 4)         throw Invalid_Algorithm_Name(algname);      return new S2K_Filter(new OpenPGP_S2K(name[1], to_u32bit(name[3])),                            salt, to_u32bit(name[2]));      }   return 0;   }

⌨️ 快捷键说明

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