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
00270 private:
00271
00272
00273
00274 OpenSSLCryptoSymmetricKey();
00275 OpenSSLCryptoSymmetricKey(const OpenSSLCryptoSymmetricKey &);
00276 OpenSSLCryptoSymmetricKey & operator= (const OpenSSLCryptoSymmetricKey &);
00277
00278
00279 int decryptCtxInit(const unsigned char * iv);
00280
00281
00282 SymmetricKeyType m_keyType;
00283 SymmetricKeyMode m_keyMode;
00284 EVP_CIPHER_CTX m_ctx;
00285 safeBuffer m_keyBuf;
00286 unsigned int m_keyLen;
00287 bool m_initialised;
00288 unsigned char m_lastBlock[MAX_BLOCK_SIZE];
00289 int m_blockSize;
00290 int m_ivSize;
00291 int m_bytesInLastBlock;
00292 bool m_ivSent;
00293 bool m_doPad;
00294 };
00295
00296 #endif
00297 #endif