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
00057 class DSIG_EXPORT OpenSSLCryptoSymmetricKey : public XSECCryptoSymmetricKey {
00058
00059 public :
00060
00063
00070 OpenSSLCryptoSymmetricKey(XSECCryptoSymmetricKey::SymmetricKeyType type);
00071
00079 virtual ~OpenSSLCryptoSymmetricKey();
00080
00082
00085
00090 virtual const XMLCh * getProviderName();
00091
00100 virtual XSECCryptoKey * clone();
00101
00103
00106
00115 SymmetricKeyType getSymmetricKeyType(void);
00116
00128 void setKey(const unsigned char * key, unsigned int keyLen);
00129
00146 virtual bool decryptInit(bool doPad = true,
00147 SymmetricKeyMode mode = MODE_CBC,
00148 const unsigned char * iv = NULL);
00149
00174 virtual unsigned int decrypt(const unsigned char * inBuf,
00175 unsigned char * plainBuf,
00176 unsigned int inLength,
00177 unsigned int maxOutLength);
00178
00198 virtual unsigned int decryptFinish(unsigned char * plainBuf,
00199 unsigned int maxOutLength);
00200
00216 virtual bool encryptInit(bool doPad = true,
00217 SymmetricKeyMode mode = MODE_CBC,
00218 const unsigned char * iv = NULL);
00219
00240 virtual unsigned int encrypt(const unsigned char * inBuf,
00241 unsigned char * cipherBuf,
00242 unsigned int inLength,
00243 unsigned int maxOutLength);
00244
00266 virtual unsigned int encryptFinish(unsigned char * plainBuf,
00267 unsigned int maxOutLength);
00268
00270
00271 private:
00272
00273
00274
00275 OpenSSLCryptoSymmetricKey();
00276 OpenSSLCryptoSymmetricKey(const OpenSSLCryptoSymmetricKey &);
00277 OpenSSLCryptoSymmetricKey & operator= (const OpenSSLCryptoSymmetricKey &);
00278
00279
00280 int decryptCtxInit(const unsigned char * iv);
00281
00282
00283 SymmetricKeyType m_keyType;
00284 SymmetricKeyMode m_keyMode;
00285 EVP_CIPHER_CTX m_ctx;
00286 safeBuffer m_keyBuf;
00287 unsigned int m_keyLen;
00288 bool m_initialised;
00289 unsigned char m_lastBlock[MAX_BLOCK_SIZE];
00290 int m_blockSize;
00291 int m_ivSize;
00292 int m_bytesInLastBlock;
00293 bool m_ivSent;
00294 bool m_doPad;
00295 };
00296
00297 #endif
00298 #endif