Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

wvdigest.h

Go to the documentation of this file.
00001 /* -*- Mode: C++ -*- 00002 * Worldvisions Tunnel Vision Software: 00003 * Copyright (C) 1997-2002 Net Integration Technologies, Inc. 00004 * 00005 * MD5, SHA-1 and HMAC digest abstractions. 00006 */ 00007 #ifndef __WVDIGEST_H 00008 #define __WVDIGEST_H 00009 00010 #include "wvencoder.h" 00011 00012 struct env_md_st; 00013 struct env_md_ctx_st; 00014 struct hmac_ctx_st; 00015 00016 /** 00017 * Superclass for all message digests. 00018 * 00019 * All message digest encoders have the following semantics: 00020 * 00021 * - On encode() or flush(), data from the input buffer is 00022 * consumed and a message digest function is applied to 00023 * incrementally update the internal digest state. 00024 * No output is ever generated. 00025 * - On finish(), the message digest is finalized and its value 00026 * is written to the output buffer. Afterwards, no new data 00027 * can be processed unless reset() is called. 00028 * - On reset(), the current digest state is discarded allowing 00029 * a new stream of data to be processed. 00030 * 00031 */ 00032 class WvDigest : public WvEncoder 00033 { 00034 public: 00035 /** Returns the number of bytes in the message digest. */ 00036 virtual size_t digestsize() const = 0; 00037 }; 00038 00039 00040 /** 00041 * @internal 00042 * Base class for all digests constructed using the OpenSSL EVP API. 00043 */ 00044 class WvEVPMDDigest : public WvDigest 00045 { 00046 friend class WvHMACDigest; 00047 const env_md_st *evpmd; 00048 env_md_ctx_st *evpctx; 00049 bool active; 00050 00051 public: 00052 virtual ~WvEVPMDDigest(); 00053 virtual size_t digestsize() const; 00054 00055 protected: 00056 WvEVPMDDigest(const env_md_st *_evpmd); 00057 virtual bool _encode(WvBuf &inbuf, WvBuf &outbuf, 00058 bool flush); // consumes input 00059 virtual bool _finish(WvBuf &outbuf); // outputs digest 00060 virtual bool _reset(); // supported: resets digest value 00061 00062 const env_md_st *getevpmd() 00063 { return evpmd; } 00064 00065 private: 00066 void cleanup(); 00067 }; 00068 00069 00070 /** 00071 * MD5 Digest. 00072 * Has a digest length of 128 bits. 00073 */ 00074 class WvMD5Digest : public WvEVPMDDigest 00075 { 00076 public: 00077 /** Creates an MD5 digest encoder. */ 00078 WvMD5Digest(); 00079 virtual ~WvMD5Digest() { } 00080 }; 00081 00082 00083 /** 00084 * SHA-1 Digest. 00085 * Has a digest length of 160 bits. 00086 */ 00087 class WvSHA1Digest : public WvEVPMDDigest 00088 { 00089 public: 00090 /** Creates an SHA1 digest encoder. */ 00091 WvSHA1Digest(); 00092 virtual ~WvSHA1Digest() { } 00093 }; 00094 00095 00096 /** 00097 * HMAC Message Authentication Code. 00098 * Has a digest length that equals that of its underlying 00099 * message digest encoder. 00100 */ 00101 class WvHMACDigest : public WvDigest 00102 { 00103 WvEVPMDDigest *digest; 00104 unsigned char *key; 00105 size_t keysize; 00106 hmac_ctx_st *hmacctx; 00107 bool active; 00108 00109 public: 00110 /** 00111 * Creates an HMAC digest encoder. 00112 * 00113 * "digest" is the message digest encoder to use as a 00114 * hash function 00115 * "key" is the authentication key 00116 * "keysize" is the key size in bytes 00117 */ 00118 WvHMACDigest(WvEVPMDDigest *_digest, const void *_key, 00119 size_t _keysize); 00120 virtual ~WvHMACDigest(); 00121 virtual size_t digestsize() const; 00122 00123 protected: 00124 virtual bool _encode(WvBuf &inbuf, WvBuf &outbuf, 00125 bool flush); // consumes input 00126 virtual bool _finish(WvBuf &outbuf); // outputs digest 00127 virtual bool _reset(); // supported: resets digest value 00128 00129 private: 00130 void cleanup(); 00131 }; 00132 00133 #endif // __WVDIGEST_H

Generated on Tue Oct 5 01:09:20 2004 for WvStreams by doxygen 1.3.7