~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to extra/yassl/taocrypt/include/hash.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   Copyright (C) 2000-2007 MySQL AB
 
3
 
 
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.
 
7
 
 
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.
 
12
 
 
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,
 
16
   MA  02110-1301  USA.
 
17
*/
 
18
 
 
19
/* hash.hpp provides a base for digest types
 
20
*/
 
21
 
 
22
 
 
23
#ifndef TAO_CRYPT_HASH_HPP
 
24
#define TAO_CRYPT_HASH_HPP
 
25
 
 
26
#include "misc.hpp"
 
27
 
 
28
namespace TaoCrypt {
 
29
 
 
30
 
 
31
// HASH
 
32
class HASH : public virtual_base {
 
33
public:
 
34
    virtual ~HASH() {}
 
35
 
 
36
    virtual void Update(const byte*, word32) = 0;
 
37
    virtual void Final(byte*)                = 0;
 
38
 
 
39
    virtual void Init() = 0;
 
40
 
 
41
    virtual word32 getBlockSize()  const = 0;
 
42
    virtual word32 getDigestSize() const = 0;
 
43
};
 
44
 
 
45
 
 
46
// HASH with Transform
 
47
class HASHwithTransform : public HASH {
 
48
public:
 
49
    HASHwithTransform(word32 digSz, word32 buffSz);
 
50
    virtual ~HASHwithTransform() {}
 
51
    virtual ByteOrder getByteOrder()  const = 0;
 
52
    virtual word32    getPadSize()    const = 0;
 
53
 
 
54
    virtual void Update(const byte*, word32);
 
55
    virtual void Final(byte*);
 
56
 
 
57
    word32  GetBitCountLo() const { return  loLen_ << 3; }
 
58
    word32  GetBitCountHi() const { return (loLen_ >> (8*sizeof(loLen_) - 3)) +
 
59
                                           (hiLen_ << 3); } 
 
60
    enum { MaxDigestSz = 8, MaxBufferSz = 64 };
 
61
protected:
 
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)];
 
68
 
 
69
    virtual void Transform() = 0;
 
70
 
 
71
    void AddLength(word32);
 
72
};
 
73
 
 
74
 
 
75
#ifdef WORD64_AVAILABLE
 
76
 
 
77
// 64-bit HASH with Transform
 
78
class HASH64withTransform : public HASH {
 
79
public:
 
80
    HASH64withTransform(word32 digSz, word32 buffSz);
 
81
    virtual ~HASH64withTransform() {}
 
82
    virtual ByteOrder getByteOrder()  const = 0;
 
83
    virtual word32    getPadSize()    const = 0;
 
84
 
 
85
    virtual void Update(const byte*, word32);
 
86
    virtual void Final(byte*);
 
87
 
 
88
    word32  GetBitCountLo() const { return  loLen_ << 3; }
 
89
    word32  GetBitCountHi() const { return (loLen_ >> (8*sizeof(loLen_) - 3)) +
 
90
                                           (hiLen_ << 3); } 
 
91
    enum { MaxDigestSz = 8, MaxBufferSz = 128 };
 
92
protected:
 
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)];
 
99
 
 
100
    virtual void Transform() = 0;
 
101
 
 
102
    void AddLength(word32);
 
103
};
 
104
 
 
105
#endif // WORD64_AVAILABLE
 
106
 
 
107
 
 
108
} // namespace
 
109
 
 
110
#endif // TAO_CRYPT_HASH_HPP