| 1 | /* | ||
| 2 | * The Tiger algorithm was written by Eli Biham and Ross Anderson and | ||
| 3 | * is available on the official Tiger algorithm page <http://www.cs.technion.ac.il/~biham/Reports/Tiger/>. | ||
| 4 | * The below Tiger implementation is a C++ version of their original C code. | ||
| 5 | * Permission was granted by Eli Biham to use with the following conditions; | ||
| 6 | * a) This note must be retained. | ||
| 7 | * b) The algorithm must correctly compute Tiger. | ||
| 8 | * c) The algorithm's use must be legal. | ||
| 9 | * d) The algorithm may not be exported to countries banned by law. | ||
| 10 | * e) The authors of the C code are not responsible of this use of the code, | ||
| 11 | * the software or anything else. | ||
| 12 | */ | ||
| 13 | |||
| 14 | /* | ||
| 15 | * This program is free software; you can redistribute it and/or modify | ||
| 16 | * it under the terms of the GNU General Public License as published by | ||
| 17 | * the Free Software Foundation; either version 2 of the License, or | ||
| 18 | * (at your option) any later version. | ||
| 19 | * | ||
| 20 | * This program is distributed in the hope that it will be useful, | ||
| 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 23 | * GNU General Public License for more details. | ||
| 24 | * | ||
| 25 | * You should have received a copy of the GNU General Public License | ||
| 26 | * along with this program; if not, write to the Free Software | ||
| 27 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 28 | */ | ||
| 29 | |||
| 30 | #pragma once | ||
| 31 | |||
| 32 | #include <cstddef> | ||
| 33 | #include <cstdint> | ||
| 34 | |||
| 35 | namespace dcpp { | ||
| 36 | |||
| 37 | class TigerHash { | ||
| 38 | public: | ||
| 39 | /** Hash size in bytes */ | ||
| 40 | static const size_t BITS = 192; | ||
| 41 | static const size_t BYTES = BITS / 8; | ||
| 42 | |||
| 43 | 87 | TigerHash() : pos(0) { | |
| 44 | 87 | res[0]=_ULL(0x0123456789ABCDEF); | |
| 45 | 87 | res[1]=_ULL(0xFEDCBA9876543210); | |
| 46 | 87 | res[2]=_ULL(0xF096A5B4C3B2E187); | |
| 47 | 87 | } | |
| 48 | |||
| 49 | 87 | ~TigerHash() { | |
| 50 | 87 | } | |
| 51 | |||
| 52 | /** Calculates the Tiger hash of the data. */ | ||
| 53 | void update(const void* data, size_t len); | ||
| 54 | /** Call once all data has been processed. */ | ||
| 55 | uint8_t* finalize(); | ||
| 56 | |||
| 57 | 87 | uint8_t* getResult() { return (uint8_t*) res; } | |
| 58 | private: | ||
| 59 | enum { BLOCK_SIZE = 512/8 }; | ||
| 60 | /** 512 bit blocks for the compress function */ | ||
| 61 | uint8_t tmp[512/8]; | ||
| 62 | /** State / final hash value */ | ||
| 63 | uint64_t res[3]; | ||
| 64 | /** Total number of bytes compressed */ | ||
| 65 | uint64_t pos; | ||
| 66 | /** S boxes */ | ||
| 67 | static uint64_t table[]; | ||
| 68 | |||
| 69 | void tigerCompress(const uint64_t* data, uint64_t state[3]); | ||
| 70 | }; | ||
| 71 | |||
| 72 | } // namespace dcpp |