emsa1.cpp

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

CPP
69
字号
/************************************************** EMSA1 Source File                              ** (C) 1999-2002 The Botan Project                **************************************************/#include <botan/emsa1.h>#include <botan/lookup.h>namespace Botan {/************************************************** EMSA1 Update Operation                         **************************************************/void EMSA1::update(const byte input[], u32bit length)   {   hash->update(input, length);   }/************************************************** Return the raw (unencoded) data                **************************************************/SecureVector<byte> EMSA1::raw_data()   {   return hash->final();   }/************************************************** EMSA1 Encode Operation                         **************************************************/SecureVector<byte> EMSA1::encoding_of(const SecureVector<byte>& msg,                                      u32bit output_bits)   {   if(msg.size() != hash->OUTPUT_LENGTH)      throw Invalid_Argument("EMSA1::encoding_of: Invalid size for input");   if(8*msg.size() <= output_bits)      return SecureVector<byte>(msg, msg.size());   u32bit shift = 8*msg.size() - output_bits;   u32bit byte_shift = shift / 8, bit_shift = shift % 8;   SecureVector<byte> digest(msg.size() - byte_shift);   for(u32bit j = 0; j != msg.size() - byte_shift; j++)      digest[j] = msg[j];   if(bit_shift)      {      byte carry = 0;      for(u32bit j = 0; j != digest.size(); j++)         {         byte temp = digest[j];         digest[j] = (temp >> bit_shift) | carry;         carry = (temp << (8 - bit_shift));         }      }   return digest;   }/************************************************** EMSA1 Constructor                              **************************************************/EMSA1::EMSA1(const std::string& hash_name) :   hash(get_hash(hash_name))   {   }}

⌨️ 快捷键说明

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