2
Copyright (C) 2000-2007 MySQL AB
4
This program is free software; you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation; version 2 of the License.
8
This program is distributed in the hope that it will be useful,
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
GNU General Public License for more details.
13
You should have received a copy of the GNU General Public License
14
along with this program; see the file COPYING. If not, write to the
15
Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
19
/* hash.hpp provides a base for digest types
23
#ifndef TAO_CRYPT_HASH_HPP
24
#define TAO_CRYPT_HASH_HPP
32
class HASH : public virtual_base {
36
virtual void Update(const byte*, word32) = 0;
37
virtual void Final(byte*) = 0;
39
virtual void Init() = 0;
41
virtual word32 getBlockSize() const = 0;
42
virtual word32 getDigestSize() const = 0;
46
// HASH with Transform
47
class HASHwithTransform : public HASH {
49
HASHwithTransform(word32 digSz, word32 buffSz);
50
virtual ~HASHwithTransform() {}
51
virtual ByteOrder getByteOrder() const = 0;
52
virtual word32 getPadSize() const = 0;
54
virtual void Update(const byte*, word32);
55
virtual void Final(byte*);
57
word32 GetBitCountLo() const { return loLen_ << 3; }
58
word32 GetBitCountHi() const { return (loLen_ >> (8*sizeof(loLen_) - 3)) +
60
enum { MaxDigestSz = 8, MaxBufferSz = 64 };
62
typedef word32 HashLengthType;
63
word32 buffLen_; // in bytes
64
HashLengthType loLen_; // length in bytes
65
HashLengthType hiLen_; // length in bytes
66
word32 digest_[MaxDigestSz];
67
word32 buffer_[MaxBufferSz / sizeof(word32)];
69
virtual void Transform() = 0;
71
void AddLength(word32);
75
#ifdef WORD64_AVAILABLE
77
// 64-bit HASH with Transform
78
class HASH64withTransform : public HASH {
80
HASH64withTransform(word32 digSz, word32 buffSz);
81
virtual ~HASH64withTransform() {}
82
virtual ByteOrder getByteOrder() const = 0;
83
virtual word32 getPadSize() const = 0;
85
virtual void Update(const byte*, word32);
86
virtual void Final(byte*);
88
word32 GetBitCountLo() const { return loLen_ << 3; }
89
word32 GetBitCountHi() const { return (loLen_ >> (8*sizeof(loLen_) - 3)) +
91
enum { MaxDigestSz = 8, MaxBufferSz = 128 };
93
typedef word32 HashLengthType;
94
word32 buffLen_; // in bytes
95
HashLengthType loLen_; // length in bytes
96
HashLengthType hiLen_; // length in bytes
97
word64 digest_[MaxDigestSz];
98
word64 buffer_[MaxBufferSz / sizeof(word64)];
100
virtual void Transform() = 0;
102
void AddLength(word32);
105
#endif // WORD64_AVAILABLE
110
#endif // TAO_CRYPT_HASH_HPP