src/stream/ZStream_SHA1.h

00001 /*  @(#) $Id: ZStream_SHA1.h,v 1.7 2006/04/10 20:44:21 agreen Exp $ */
00002 
00003 /* ------------------------------------------------------------
00004 Copyright (c) 2002 Andrew Green and Learning in Motion, Inc.
00005 http://www.zoolib.org
00006 
00007 Permission is hereby granted, free of charge, to any person obtaining a copy
00008 of this software and associated documentation files (the "Software"), to deal
00009 in the Software without restriction, including without limitation the rights
00010 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00011 copies of the Software, and to permit persons to whom the Software is
00012 furnished to do so, subject to the following conditions:
00013 
00014 The above copyright notice and this permission notice shall be included in
00015 all copies or substantial portions of the Software.
00016 
00017 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00018 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00020 COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00021 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00022 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00023 ------------------------------------------------------------ */
00024 
00025 #ifndef __ZStream_SHA1__
00026 #define __ZStream_SHA1__ 1
00027 #include "zconfig.h"
00028 #include "ZCONFIG_SPI.h"
00029 
00030 #ifndef ZCONFIG_StreamSHA1_UseOpenSSL
00031 #       define ZCONFIG_StreamSHA1_UseOpenSSL ZCONFIG_SPI_Enabled(openssl)
00032 #endif
00033 
00034 #include "ZStream.h"
00035 
00036 // =================================================================================================
00037 #pragma mark -
00038 #pragma mark * ZStream_SHA1
00039 
00040 #if ZCONFIG_StreamSHA1_UseOpenSSL
00041 #       include <openssl/sha.h>
00042 #endif
00043 
00044 namespace ZStream_SHA1 {
00045 
00046 #if ZCONFIG_StreamSHA1_UseOpenSSL
00047 
00048 typedef SHA_CTX Context;
00049 
00050 #else // ZCONFIG_StreamSHA1_UseOpenSSL
00051 
00052 struct Context
00053         {
00054         uint32 fState[5];
00055         size_t fSpaceUsed;
00056         size_t fBuffersSent;
00057         union
00058                 {
00059                 uint32 fBuffer32[16];
00060                 uint8 fBuffer8[64];
00061                 };
00062         };
00063 
00064 #endif // ZCONFIG_StreamSHA1_UseOpenSSL
00065 
00066 void sInit(Context& oContext);
00067 void sUpdate(Context& ioContext, const void* iData, size_t iCount);
00068 void sFinal(Context& ioContext, uint8 oDigest[20]);
00069 
00070 void sTest();
00071 
00072 } // namespace ZStream_SHA1
00073 
00074 // =================================================================================================
00075 #pragma mark -
00076 #pragma mark * ZStreamR_SHA1
00077 
00079 
00080 class ZStreamR_SHA1 : public ZStreamR
00081         {
00082 public:
00083         ZStreamR_SHA1(const ZStreamR& iStreamSource);
00084         ZStreamR_SHA1(uint8 oDigest[20], const ZStreamR& iStreamSource);
00085         ~ZStreamR_SHA1();
00086 
00087 // From ZStreamR
00088         virtual void Imp_Read(void* iDest, size_t iCount, size_t* oCountRead);
00089         virtual size_t Imp_CountReadable();
00090 
00091 // Our protocol
00092         void GetDigest(uint8 oDigest[20]);
00093 
00094 protected:
00095         const ZStreamR& fStreamSource;
00096         ZStream_SHA1::Context fContext;
00097         uint8* fDigest;
00098         };
00099 
00100 // =================================================================================================
00101 #pragma mark -
00102 #pragma mark * ZStreamW_SHA1
00103 
00105 
00106 class ZStreamW_SHA1 : public ZStreamW
00107         {
00108 public:
00109         ZStreamW_SHA1(const ZStreamW& iStreamSink);
00110         ZStreamW_SHA1(uint8 oDigest[20], const ZStreamW& iStreamSink);
00111         ~ZStreamW_SHA1();
00112 
00113 // From ZStreamW
00114         virtual void Imp_Write(const void* iSource, size_t iCount, size_t* oCountWritten);
00115         virtual void Imp_Flush();
00116 
00117 // Our protocol
00118         void GetDigest(uint8 oDigest[20]);
00119 
00120 protected:
00121         const ZStreamW& fStreamSink;
00122         ZStream_SHA1::Context fContext;
00123         uint8* fDigest;
00124         };
00125 
00126 // =================================================================================================
00127 
00128 #endif // __ZStream_SHA1__

Generated on Thu Jul 26 11:21:53 2007 for ZooLib by  doxygen 1.4.7