root / branches / tbeta / ccv_ofx_0061 / Windows / libs / poco / include / Poco / SHA1Engine.h @ 214

View | Annotate | Download (2.9 KB)

1 214 jimbo
//
2 214 jimbo
// SHA1Engine.h
3 214 jimbo
//
4 214 jimbo
// $Id: //poco/1.3/Foundation/include/Poco/SHA1Engine.h#2 $
5 214 jimbo
//
6 214 jimbo
// Library: Foundation
7 214 jimbo
// Package: Crypt
8 214 jimbo
// Module:  SHA1Engine
9 214 jimbo
//
10 214 jimbo
// Definition of class SHA1Engine.
11 214 jimbo
//
12 214 jimbo
// Secure Hash Standard SHA-1 algorithm
13 214 jimbo
// (FIPS 180-1, see http://www.itl.nist.gov/fipspubs/fip180-1.htm)
14 214 jimbo
//
15 214 jimbo
// Based on the public domain implementation by Peter C. Gutmann
16 214 jimbo
// on 2 Sep 1992, modified by Carl Ellison to be SHA-1.
17 214 jimbo
//
18 214 jimbo
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
19 214 jimbo
// and Contributors.
20 214 jimbo
//
21 214 jimbo
// Permission is hereby granted, free of charge, to any person or organization
22 214 jimbo
// obtaining a copy of the software and accompanying documentation covered by
23 214 jimbo
// this license (the "Software") to use, reproduce, display, distribute,
24 214 jimbo
// execute, and transmit the Software, and to prepare derivative works of the
25 214 jimbo
// Software, and to permit third-parties to whom the Software is furnished to
26 214 jimbo
// do so, all subject to the following:
27 214 jimbo
//
28 214 jimbo
// The copyright notices in the Software and this entire statement, including
29 214 jimbo
// the above license grant, this restriction and the following disclaimer,
30 214 jimbo
// must be included in all copies of the Software, in whole or in part, and
31 214 jimbo
// all derivative works of the Software, unless such copies or derivative
32 214 jimbo
// works are solely in the form of machine-executable object code generated by
33 214 jimbo
// a source language processor.
34 214 jimbo
//
35 214 jimbo
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
36 214 jimbo
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
37 214 jimbo
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
38 214 jimbo
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
39 214 jimbo
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
40 214 jimbo
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
41 214 jimbo
// DEALINGS IN THE SOFTWARE.
42 214 jimbo
//
43 214 jimbo
44 214 jimbo
45 214 jimbo
#ifndef Foundation_SHA1Engine_INCLUDED
46 214 jimbo
#define Foundation_SHA1Engine_INCLUDED
47 214 jimbo
48 214 jimbo
49 214 jimbo
#include "Poco/Foundation.h"
50 214 jimbo
#include "Poco/DigestEngine.h"
51 214 jimbo
52 214 jimbo
53 214 jimbo
namespace Poco {
54 214 jimbo
55 214 jimbo
56 214 jimbo
class Foundation_API SHA1Engine: public DigestEngine
57 214 jimbo
        /// This class implementes the SHA-1 message digest algorithm.
58 214 jimbo
        /// (FIPS 180-1, see http://www.itl.nist.gov/fipspubs/fip180-1.htm)
59 214 jimbo
{
60 214 jimbo
public:
61 214 jimbo
        enum
62 214 jimbo
        {
63 214 jimbo
                BLOCK_SIZE  = 64,
64 214 jimbo
                DIGEST_SIZE = 20
65 214 jimbo
        };
66 214 jimbo
67 214 jimbo
        SHA1Engine();
68 214 jimbo
        ~SHA1Engine();
69 214 jimbo
70 214 jimbo
        unsigned digestLength() const;
71 214 jimbo
        void reset();
72 214 jimbo
        const DigestEngine::Digest& digest();
73 214 jimbo
74 214 jimbo
protected:
75 214 jimbo
        void updateImpl(const void* data, unsigned length);
76 214 jimbo
77 214 jimbo
private:
78 214 jimbo
        void transform();
79 214 jimbo
        static void byteReverse(UInt32* buffer, int byteCount);
80 214 jimbo
81 214 jimbo
        typedef UInt8 BYTE;
82 214 jimbo
83 214 jimbo
        struct Context
84 214 jimbo
        {
85 214 jimbo
                UInt32 digest[5]; // Message digest
86 214 jimbo
                UInt32 countLo;   // 64-bit bit count
87 214 jimbo
                UInt32 countHi;
88 214 jimbo
                UInt32 data[16];  // SHA data buffer
89 214 jimbo
                UInt32 slop;      // # of bytes saved in data[]
90 214 jimbo
        };
91 214 jimbo
92 214 jimbo
        Context _context;
93 214 jimbo
        DigestEngine::Digest _digest;
94 214 jimbo
95 214 jimbo
        SHA1Engine(const SHA1Engine&);
96 214 jimbo
        SHA1Engine& operator = (const SHA1Engine&);
97 214 jimbo
};
98 214 jimbo
99 214 jimbo
100 214 jimbo
} // namespace Poco
101 214 jimbo
102 214 jimbo
103 214 jimbo
#endif // Foundation_SHA1Engine_INCLUDED