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 #ifndef NSSCRYPTOSYMMETRICKEY_INCLUDE
00028 #define NSSCRYPTOSYMMETRICKEY_INCLUDE
00029
00030 #include <xsec/framework/XSECDefs.hpp>
00031 #include <xsec/enc/XSECCryptoSymmetricKey.hpp>
00032
00033 #if defined (HAVE_NSS)
00034
00035 #include "nss/pk11func.h"
00036 #include "nss/nss.h"
00037
00038 #define NSS_MAX_BLOCK_SIZE 32
00039
00052 class DSIG_EXPORT NSSCryptoSymmetricKey : public XSECCryptoSymmetricKey {
00053
00054 public :
00055
00058
00067 NSSCryptoSymmetricKey(XSECCryptoSymmetricKey::SymmetricKeyType type);
00068
00076 virtual ~NSSCryptoSymmetricKey();
00077
00079
00082
00087 virtual const XMLCh * getProviderName();
00088
00097 virtual XSECCryptoKey * clone();
00098
00100
00103
00112 SymmetricKeyType getSymmetricKeyType(void);
00113
00125 void setKey(const unsigned char * key, unsigned int keyLen);
00126
00143 virtual bool decryptInit(bool doPad = true,
00144 SymmetricKeyMode mode = MODE_CBC,
00145 const unsigned char * iv = NULL);
00146
00171 virtual unsigned int decrypt(const unsigned char * inBuf,
00172 unsigned char * plainBuf,
00173 unsigned int inLength,
00174 unsigned int maxOutLength);
00175
00195 virtual unsigned int decryptFinish(unsigned char * plainBuf,
00196 unsigned int maxOutLength);
00197
00213 virtual bool encryptInit(bool doPad = true,
00214 SymmetricKeyMode mode = MODE_CBC,
00215 const unsigned char * iv = NULL);
00216
00237 virtual unsigned int encrypt(const unsigned char * inBuf,
00238 unsigned char * cipherBuf,
00239 unsigned int inLength,
00240 unsigned int maxOutLength);
00241
00263 virtual unsigned int encryptFinish(unsigned char * plainBuf,
00264 unsigned int maxOutLength);
00265
00267
00268 private:
00269
00270
00271
00272 NSSCryptoSymmetricKey();
00273 NSSCryptoSymmetricKey(const NSSCryptoSymmetricKey &);
00274 NSSCryptoSymmetricKey & operator= (const NSSCryptoSymmetricKey &);
00275
00276 int decryptCtxInit(const unsigned char * iv);
00277
00278 SymmetricKeyType m_keyType;
00279 SymmetricKeyMode m_keyMode;
00280 bool m_initialised;
00281 bool m_doPad;
00282
00283 unsigned char m_lastBlock[NSS_MAX_BLOCK_SIZE];
00284 unsigned int m_blockSize;
00285 bool m_ivSent;
00286 unsigned int m_ivSize;
00287
00288 PK11Context * mp_ctx;
00289 PK11SymKey * mp_k;
00290
00291 };
00292
00293 #endif
00294 #endif