00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef OPENSSLCRYPTOSYMMETRICKEY_INCLUDE
00032 #define OPENSSLCRYPTOSYMMETRICKEY_INCLUDE
00033
00034 #include <xsec/framework/XSECDefs.hpp>
00035 #include <xsec/enc/XSECCryptoSymmetricKey.hpp>
00036
00037 #if defined (HAVE_OPENSSL)
00038
00039
00040
00041 #include <openssl/evp.h>
00042
00043 #define MAX_BLOCK_SIZE 32
00044
00056 class DSIG_EXPORT OpenSSLCryptoSymmetricKey : public XSECCryptoSymmetricKey {
00057
00058 public :
00059
00062
00069 OpenSSLCryptoSymmetricKey(XSECCryptoSymmetricKey::SymmetricKeyType type);
00070
00078 virtual ~OpenSSLCryptoSymmetricKey();
00079
00081
00084
00089 virtual const XMLCh * getProviderName();
00090
00099 virtual XSECCryptoKey * clone();
00100
00102
00105
00114 SymmetricKeyType getSymmetricKeyType(void);
00115
00127 void setKey(const unsigned char * key, unsigned int keyLen);
00128
00145 virtual bool decryptInit(bool doPad = true,
00146 SymmetricKeyMode mode = MODE_CBC,
00147 const unsigned char * iv = NULL);
00148
00173 virtual unsigned int decrypt(const unsigned char * inBuf,
00174 unsigned char * plainBuf,
00175 unsigned int inLength,
00176 unsigned int maxOutLength);
00177
00197 virtual unsigned int decryptFinish(unsigned char * plainBuf,
00198 unsigned int maxOutLength);
00199
00215 virtual bool encryptInit(bool doPad = true,
00216 SymmetricKeyMode mode = MODE_CBC,
00217 const unsigned char * iv = NULL);
00218
00239 virtual unsigned int encrypt(const unsigned char * inBuf,
00240 unsigned char * cipherBuf,
00241 unsigned int inLength,
00242 unsigned int maxOutLength);
00243
00265 virtual unsigned int encryptFinish(unsigned char * plainBuf,
00266 unsigned int maxOutLength);
00267
00269
00272
00277 EVP_CIPHER_CTX * getOpenSSLEVP_CIPHER_CTX(void) {return &m_ctx;}
00278
00280
00281 private:
00282
00283
00284
00285 OpenSSLCryptoSymmetricKey();
00286 OpenSSLCryptoSymmetricKey(const OpenSSLCryptoSymmetricKey &);
00287 OpenSSLCryptoSymmetricKey & operator= (const OpenSSLCryptoSymmetricKey &);
00288
00289
00290 int decryptCtxInit(const unsigned char * iv);
00291
00292
00293 SymmetricKeyType m_keyType;
00294 SymmetricKeyMode m_keyMode;
00295 EVP_CIPHER_CTX m_ctx;
00296 safeBuffer m_keyBuf;
00297 unsigned int m_keyLen;
00298 bool m_initialised;
00299 unsigned char m_lastBlock[MAX_BLOCK_SIZE];
00300 int m_blockSize;
00301 int m_ivSize;
00302 int m_bytesInLastBlock;
00303 bool m_ivSent;
00304 bool m_doPad;
00305 };
00306
00307 #endif
00308 #endif