Botan
1.11.15
|
00001 /* 00002 * MDx Hash Function 00003 * (C) 1999-2008 Jack Lloyd 00004 * 00005 * Botan is released under the Simplified BSD License (see license.txt) 00006 */ 00007 00008 #ifndef BOTAN_MDX_BASE_H__ 00009 #define BOTAN_MDX_BASE_H__ 00010 00011 #include <botan/hash.h> 00012 00013 namespace Botan { 00014 00015 /** 00016 * MDx Hash Function Base Class 00017 */ 00018 class BOTAN_DLL MDx_HashFunction : public HashFunction 00019 { 00020 public: 00021 /** 00022 * @param block_length is the number of bytes per block 00023 * @param big_byte_endian specifies if the hash uses big-endian bytes 00024 * @param big_bit_endian specifies if the hash uses big-endian bits 00025 * @param counter_size specifies the size of the counter var in bytes 00026 */ 00027 MDx_HashFunction(size_t block_length, 00028 bool big_byte_endian, 00029 bool big_bit_endian, 00030 size_t counter_size = 8); 00031 00032 size_t hash_block_size() const { return buffer.size(); } 00033 protected: 00034 void add_data(const byte input[], size_t length); 00035 void final_result(byte output[]); 00036 00037 /** 00038 * Run the hash's compression function over a set of blocks 00039 * @param blocks the input 00040 * @param block_n the number of blocks 00041 */ 00042 virtual void compress_n(const byte blocks[], size_t block_n) = 0; 00043 00044 void clear(); 00045 00046 /** 00047 * Copy the output to the buffer 00048 * @param buffer to put the output into 00049 */ 00050 virtual void copy_out(byte buffer[]) = 0; 00051 00052 /** 00053 * Write the count, if used, to this spot 00054 * @param out where to write the counter to 00055 */ 00056 virtual void write_count(byte out[]); 00057 private: 00058 secure_vector<byte> buffer; 00059 u64bit count; 00060 size_t position; 00061 00062 const bool BIG_BYTE_ENDIAN, BIG_BIT_ENDIAN; 00063 const size_t COUNT_SIZE; 00064 }; 00065 00066 } 00067 00068 #endif