2 * Worldvisions Tunnel Vision Software:
3 * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
5 * MD5, SHA-1 and HMAC digest abstractions.
10 #include "wvencoder.h"
17 * Superclass for all message digests.
19 * All message digest encoders have the following semantics:
21 * - On encode() or flush(), data from the input buffer is
22 * consumed and a message digest function is applied to
23 * incrementally update the internal digest state.
24 * No output is ever generated.
25 * - On finish(), the message digest is finalized and its value
26 * is written to the output buffer. Afterwards, no new data
27 * can be processed unless reset() is called.
28 * - On reset(), the current digest state is discarded allowing
29 * a new stream of data to be processed.
32 class WvDigest
: public WvEncoder
35 /** Returns the number of bytes in the message digest. */
36 virtual size_t digestsize() const = 0;
42 * Base class for all digests constructed using the OpenSSL EVP API.
44 class WvEVPMDDigest
: public WvDigest
46 friend class WvHMACDigest
;
47 const env_md_st
*evpmd
;
48 env_md_ctx_st
*evpctx
;
52 virtual ~WvEVPMDDigest();
53 virtual size_t digestsize() const;
56 WvEVPMDDigest(const env_md_st
*_evpmd
);
57 virtual bool _encode(WvBuf
&inbuf
, WvBuf
&outbuf
,
58 bool flush
); // consumes input
59 virtual bool _finish(WvBuf
&outbuf
); // outputs digest
60 virtual bool _reset(); // supported: resets digest value
62 const env_md_st
*getevpmd()
72 * Has a digest length of 128 bits.
74 class WvMD5Digest
: public WvEVPMDDigest
77 /** Creates an MD5 digest encoder. */
79 virtual ~WvMD5Digest() { }
85 * Has a digest length of 160 bits.
87 class WvSHA1Digest
: public WvEVPMDDigest
90 /** Creates an SHA1 digest encoder. */
92 virtual ~WvSHA1Digest() { }
97 * HMAC Message Authentication Code.
98 * Has a digest length that equals that of its underlying
99 * message digest encoder.
101 class WvHMACDigest
: public WvDigest
103 WvEVPMDDigest
*digest
;
106 hmac_ctx_st
*hmacctx
;
111 * Creates an HMAC digest encoder.
113 * "digest" is the message digest encoder to use as a
115 * "key" is the authentication key
116 * "keysize" is the key size in bytes
118 WvHMACDigest(WvEVPMDDigest
*_digest
, const void *_key
,
120 virtual ~WvHMACDigest();
121 virtual size_t digestsize() const;
124 virtual bool _encode(WvBuf
&inbuf
, WvBuf
&outbuf
,
125 bool flush
); // consumes input
126 virtual bool _finish(WvBuf
&outbuf
); // outputs digest
127 virtual bool _reset(); // supported: resets digest value
136 * Digest length of 4 bytes.
138 class WvCrc32Digest
: public WvDigest
144 virtual ~WvCrc32Digest() { }
146 virtual size_t digestsize() const;
147 virtual bool _encode(WvBuf
&inbuf
, WvBuf
&outbuf
,
148 bool flush
); // consumes input
149 virtual bool _finish(WvBuf
&outbuf
); // outputs digest
150 virtual bool _reset(); // supported: resets digest value
156 * Digest length of 4 bytes.
158 class WvAdler32Digest
: public WvDigest
164 virtual ~WvAdler32Digest() { }
166 virtual size_t digestsize() const;
167 virtual bool _encode(WvBuf
&inbuf
, WvBuf
&outbuf
,
168 bool flush
); // consumes input
169 virtual bool _finish(WvBuf
&outbuf
); // outputs digest
170 virtual bool _reset(); // supported: resets digest value
173 #endif // __WVDIGEST_H