source: box/trunk/lib/crypto/CipherDescription.h @ 3098

Revision 3098, 2.0 KB checked in by chris, 4 weeks ago (diff)

Allow ciphers to identify themselves for debugging.

  • Property svn:eol-style set to native
Line 
1// --------------------------------------------------------------------------
2//
3// File
4//              Name:    CipherDescription.h
5//              Purpose: Pure virtual base class for describing ciphers
6//              Created: 1/12/03
7//
8// --------------------------------------------------------------------------
9
10#ifndef CIPHERDESCRIPTION__H
11#define CIPHERDESCRIPTION__H
12
13#ifndef BOX_LIB_CRYPTO_OPENSSL_HEADERS_INCLUDED_TRUE
14        #define BOX_LIB_CRYPTO_OPENSSL_HEADERS_INCLUDED_FALSE
15        class EVP_CIPHER;
16        class EVP_CIPHER_CTX;
17#endif
18
19// --------------------------------------------------------------------------
20//
21// Class
22//              Name:    CipherDescription
23//              Purpose: Describes a cipher
24//              Created: 1/12/03
25//
26// --------------------------------------------------------------------------
27class CipherDescription
28{
29public:
30        CipherDescription();
31        CipherDescription(const CipherDescription &rToCopy);
32        virtual ~CipherDescription();
33        CipherDescription &operator=(const CipherDescription &rToCopy);
34       
35        // Return OpenSSL cipher object
36        virtual const EVP_CIPHER *GetCipher() const = 0;
37
38        // Setup any other parameters
39        virtual void SetupParameters(EVP_CIPHER_CTX *pCipherContext) const = 0;
40       
41        // Mode parameter for cipher -- used in derived classes
42        typedef enum
43        {
44                Mode_ECB = 0,
45                Mode_CBC = 1,
46                Mode_CFB = 2,
47                Mode_OFB = 3
48        } CipherMode;
49
50        virtual std::string GetCipherName() const = 0;
51        virtual CipherMode GetCipherMode() const = 0;
52        virtual std::string GetFullName() const
53        {
54                std::ostringstream out;
55                out << GetCipherName() << "-";
56                switch (GetCipherMode())
57                {
58                case Mode_ECB: out << "ECB"; break;
59                case Mode_CBC: out << "CBC"; break;
60                case Mode_CFB: out << "CFB"; break;
61                case Mode_OFB: out << "OFB"; break;
62                default: out << "unknown";
63                }
64                return out.str();
65        }
66       
67#ifdef HAVE_OLD_SSL
68        // For the old version of OpenSSL, we need to be able to store cipher descriptions.
69        virtual CipherDescription *Clone() const = 0;
70        // And to be able to store new IVs
71        virtual void SetIV(const void *pIV) = 0;
72#endif
73};
74
75#endif // CIPHERDESCRIPTION__H
76
Note: See TracBrowser for help on using the repository browser.