vpnengine/utlcrypto/src/utlcryptonew.cpp
changeset 0 33413c0669b9
equal deleted inserted replaced
-1:000000000000 0:33413c0669b9
       
     1 /*
       
     2 * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   New Symbian crypto API
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #define DummyForLeaveScanL(a)
       
    21 
       
    22 #include "msymmetriccipher.h"
       
    23 #include <bufferedtransformation.h>
       
    24 #include <cbcmode.h>
       
    25 #include <des.h>
       
    26 #include <3des.h>
       
    27 #include <rijndael.h>
       
    28 #include <padding.h>
       
    29 #include <hash.h>
       
    30 
       
    31 #include <asymmetrickeys.h>
       
    32 #include <asymmetric.h>
       
    33 #include <bigint.h>
       
    34 #include <random.h>
       
    35 #include <cryptostrength.h>
       
    36 #include <x509keys.h>
       
    37 #include <x509cert.h>
       
    38 
       
    39 #include "utlcrypto.h"
       
    40 
       
    41 
       
    42 
       
    43 EXPORT_C CUtlSymmetricCipher::~CUtlSymmetricCipher()
       
    44 /**
       
    45 * Destructor.
       
    46 */
       
    47     {
       
    48     delete iSymmetricCipher;
       
    49     }
       
    50     
       
    51 EXPORT_C void CUtlSymmetricCipher::Process(const TDesC8& aInput, TDes8& aOutput)
       
    52 /**
       
    53 * Runs the underlying transformation on aInput and appends the result to
       
    54 * aOutput.
       
    55 * @param aInput The input data to be processed.
       
    56 * @param aOutput The resulting processed data appended to aOutput.  aOutput must
       
    57 * have MaxOutputLength() empty bytes remaining in its length.
       
    58 */
       
    59     {
       
    60     iSymmetricCipher->Process(aInput, aOutput);
       
    61     }
       
    62     
       
    63 EXPORT_C void CUtlSymmetricCipher::ProcessFinalL(const TDesC8& aInput, TDes8& aOutput)
       
    64 /**
       
    65 * Pads aInput to be block aligned using the underlying padding system, if any,
       
    66 * and then runs the underlying transformation on aInput, and appends the result
       
    67 * to aOutput.  
       
    68 * @param aInput The input data to be processed.
       
    69 * @param aOutput The resulting, possibly padded, processed data appended to
       
    70 * aOutput.  aOutput must have MaxFinalOutputLength() empty bytes remaining in
       
    71 * its length.
       
    72 */
       
    73     {
       
    74     //Do dot call ProcessFinalL, but Process, because CPaddingNone is used.
       
    75     //ProcessFinalL causes panic in this case.
       
    76     DummyForLeaveScanL(1);
       
    77     iSymmetricCipher->Process(aInput, aOutput);
       
    78     }
       
    79     
       
    80 EXPORT_C TInt CUtlSymmetricCipher::MaxOutputLength(TInt aInputTextLength) const
       
    81 /** 
       
    82 * Gets a tight upper bound on the number of bytes that would be returned by a
       
    83 * call to Process() with aInputLength bytes of data.
       
    84 * @param aInputLength The length of data to be supplied to Process() in bytes.
       
    85 * @return The length of data which would result from a call to Process() with
       
    86 * an aInputLength number of bytes.
       
    87 */
       
    88     {
       
    89     return iSymmetricCipher->MaxOutputLength(aInputTextLength);
       
    90     }
       
    91 
       
    92 EXPORT_C TInt CUtlSymmetricCipher::MaxFinalOutputLength(TInt aInputTextLength) const
       
    93 /** 
       
    94 * Gets as tight an upper bound as possible on the number of bytes that would
       
    95 * be returned by a call to ProcessFinalL() with aInputLength bytes of data.
       
    96 * @param aInputLength The length of data to be supplied to Process() in bytes.
       
    97 * @return An upper bound on the length of data which would result from a call to
       
    98 * ProcessFinalL() with an aInputLength number of bytes.
       
    99 */
       
   100     {
       
   101     return iSymmetricCipher->MaxFinalOutputLength(aInputTextLength);
       
   102     }
       
   103 
       
   104 EXPORT_C void CUtlSymmetricCipher::Reset()
       
   105 /**
       
   106 * Resets the cipher back to its original state. Clears all its buffers.
       
   107 */
       
   108     {
       
   109     iSymmetricCipher->Reset();
       
   110     }
       
   111     
       
   112 EXPORT_C TInt CUtlSymmetricCipher::BlockSize() const
       
   113 /**
       
   114 * Gets the block size in bytes (1 for stream ciphers).
       
   115 * @return Block size of underlying cipher in bytes.
       
   116 */
       
   117     {
       
   118     return iSymmetricCipher->BlockSize();
       
   119     }
       
   120     
       
   121 EXPORT_C TInt CUtlSymmetricCipher::KeySize() const
       
   122 /**
       
   123 * Gets the key size in bits.    
       
   124 * @return Key size in bits.
       
   125 */
       
   126     {
       
   127     return iSymmetricCipher->KeySize();
       
   128     }
       
   129     
       
   130 CUtlSymmetricCipher::CUtlSymmetricCipher()
       
   131     {
       
   132     ;
       
   133     }
       
   134 
       
   135 //--------------------------------------------------------
       
   136     
       
   137 EXPORT_C CUtlMessageDigest::~CUtlMessageDigest()
       
   138 /**
       
   139 * Destructor.
       
   140 */
       
   141     {
       
   142     delete iMessageDigest;
       
   143     }
       
   144 
       
   145 EXPORT_C CMessageDigest* CUtlMessageDigest::ReplicateL(void)
       
   146 /** 
       
   147 * Creates a brand new reset CMessageDigest object containing no state
       
   148 * information from the current object.  To make a copy of a message
       
   149 * digest with its internal state intact, see CopyL().
       
   150 */
       
   151     {
       
   152     return iMessageDigest->ReplicateL();
       
   153     }
       
   154     
       
   155 EXPORT_C void CUtlMessageDigest::Update(const TDesC8& aMessage)
       
   156 /** 
       
   157 * Adds data to the internal representation of messages to be hashed
       
   158 * @param aMessage Data to be included in the hash.
       
   159 */
       
   160     {
       
   161     iMessageDigest->Update(aMessage);
       
   162     }
       
   163 
       
   164 EXPORT_C TPtrC8 CUtlMessageDigest::Final(const TDesC8& aMessage)
       
   165 /**
       
   166 * Adds aMessage to the internal representation of data to be hashed,
       
   167 * returns a TPtrC8 of the finalised hash of all the previously
       
   168 * appended messages, and calls Reset().
       
   169 * 
       
   170 * @param aMessage Data to be included in the hash 
       
   171 *
       
   172 * @return TPtrC8 A descriptor pointer to the buffer containing the
       
   173 * resulting hash.
       
   174 */
       
   175     {
       
   176     return iMessageDigest->Final(aMessage);
       
   177     }
       
   178 
       
   179 EXPORT_C TPtrC8 CUtlMessageDigest::Final(void)
       
   180 /**
       
   181 * Returns a TPtrC8 of the finalised hash of all the previously
       
   182 * appended messages and then calls Reset().
       
   183 * 
       
   184 * @return TPtrC8 A descriptor pointer to the buffer containing the
       
   185 * resulting hash.
       
   186 */
       
   187     {
       
   188     return iMessageDigest->Final();
       
   189     }
       
   190 
       
   191 EXPORT_C CMessageDigest* CUtlMessageDigest::CopyL(void)
       
   192 /**
       
   193 * Creates a new CMessageDigest object with the exact same state as
       
   194 * the current object.  This function copies all internal state of the
       
   195 * message digest.  To create a new CMessageDigest object without the
       
   196 * state of the current object, see ReplicateL().
       
   197 */
       
   198     {
       
   199     return iMessageDigest->CopyL();
       
   200     }
       
   201 
       
   202 EXPORT_C TInt CUtlMessageDigest::BlockSize(void) const
       
   203 /** 
       
   204 * Returns the internal block size of the message digest.
       
   205 * @return TInt internal block size of message digest in bytes.
       
   206 */
       
   207     {
       
   208     return iMessageDigest->BlockSize();
       
   209     }
       
   210 
       
   211 EXPORT_C TInt CUtlMessageDigest::HashSize(void) const
       
   212 /** 
       
   213 * Returns the size of the message digest output.
       
   214 * @return TInt output size of the message digest in bytes.
       
   215 */
       
   216     {
       
   217     return iMessageDigest->HashSize();
       
   218     }
       
   219 
       
   220 EXPORT_C void CUtlMessageDigest::Reset(void)
       
   221 /**
       
   222 * Resets the internal state of the message digest.  A reset hash
       
   223 * object loses all internal state representing the hashed data.  A
       
   224 * reset message digest is suitable to begin a new, distinct hash of
       
   225 * different data.  Any previously returned TPtrC8 from a call to
       
   226 * Final() remains valid until any subsequent call to Update() or
       
   227 * Final().
       
   228 */
       
   229     {
       
   230     iMessageDigest->Reset();
       
   231     }
       
   232 
       
   233     
       
   234 CUtlMessageDigest::CUtlMessageDigest()
       
   235     {
       
   236     ;
       
   237     }
       
   238 
       
   239 //--------------------------------------------------------
       
   240     
       
   241 EXPORT_C CUtlDiffieHellman::~CUtlDiffieHellman()
       
   242 /**
       
   243 * Destructor.
       
   244 */
       
   245     {
       
   246     delete iDhKeyPair;
       
   247     delete iDhKeyAgreement;
       
   248     //delete iKBuf;
       
   249     }
       
   250 
       
   251 EXPORT_C const HBufC8* CUtlDiffieHellman::GenerateXL(void)
       
   252 /** 
       
   253 * Generates a new Diffie-Hellman key exchange.
       
   254 * @return HBufC8* X.
       
   255 */
       
   256     {
       
   257     const CDHPublicKey* dhPublicKey = &iDhKeyPair->PublicKey();
       
   258     const TInteger* x = &dhPublicKey->X();
       
   259     HBufC8* resultBuf = NULL;
       
   260     HBufC8* xBuf = x->BufferLC();                   
       
   261     
       
   262     TInt padLength = iModulusLength - xBuf->Length(); 
       
   263     if ( padLength > 0 )
       
   264         {
       
   265         // Fill prepending zero bits to DH public value.        
       
   266         resultBuf = HBufC8::NewL(iModulusLength);
       
   267         TChar zero(0);   
       
   268         resultBuf->Des().AppendFill(zero, padLength);
       
   269         resultBuf->Des().Append(*xBuf);
       
   270         CleanupStack::PopAndDestroy(xBuf);
       
   271         }
       
   272     else
       
   273         {
       
   274         CleanupStack::Pop(xBuf);
       
   275         resultBuf = xBuf;
       
   276         }    
       
   277     
       
   278     return resultBuf;
       
   279     }
       
   280     
       
   281 EXPORT_C const HBufC8* CUtlDiffieHellman::CompleteKL(const TDesC8& aY)
       
   282 /** 
       
   283 * Completes a Diffie-Hellman key exchange.
       
   284 * @param aY Y.
       
   285 * @return HBufC8* K.
       
   286 */
       
   287     {
       
   288     const CDHPrivateKey* privateKey = &iDhKeyPair->PrivateKey();
       
   289     
       
   290     RInteger n = RInteger::NewL(privateKey->N());
       
   291     CleanupClosePushL(n);
       
   292     RInteger g = RInteger::NewL(privateKey->G());
       
   293     CleanupClosePushL(g);
       
   294     RInteger Y = RInteger::NewL(aY);
       
   295     CleanupClosePushL(Y);
       
   296     
       
   297     CDHPublicKey* dhPublicKeyY = CDHPublicKey::NewL(n, g, Y);
       
   298     CleanupStack::Pop(3); // Y, g, n
       
   299     CleanupStack::PushL(dhPublicKeyY);
       
   300 
       
   301     const HBufC8* kBuf = iDhKeyAgreement->AgreeL(*dhPublicKeyY);
       
   302     
       
   303     CleanupStack::PopAndDestroy(); // dhPublicKeyY
       
   304     
       
   305     //delete iKBuf;
       
   306     //iKBuf = const_cast<HBufC8*>(kBuf);
       
   307     //return iKBuf;
       
   308     return kBuf;
       
   309     }
       
   310     
       
   311 CUtlDiffieHellman::CUtlDiffieHellman()
       
   312     {
       
   313     ;
       
   314     }
       
   315 
       
   316 //--------------------------------------------------------  
       
   317     
       
   318 EXPORT_C CUtlSymmetricCipher*
       
   319 TUtlCrypto::MakeSymmetricEncryptorL(TUtlSymmetricCipherId aCipherId,
       
   320                                     const TDesC8& aKey,
       
   321                                     const TDesC8& aIv)
       
   322 /** 
       
   323 * Makes symmetric block encryptor without padding.
       
   324 * @param aCipherId Cipher id.
       
   325 * @param aKey Key.
       
   326 * @param aIv Initialization vector.
       
   327 * @return CUtlSymmetricCipher* Pointer to symmetric cipher.
       
   328 */
       
   329     {
       
   330     CSymmetricCipher* cipher = 0;
       
   331     CBlockTransformation* block = 0;
       
   332     
       
   333     switch (aCipherId)
       
   334         {
       
   335         case EUtlSymmetricCipherDesCbc:
       
   336             block = CDESEncryptor::NewLC(aKey);
       
   337             block = CModeCBCEncryptor::NewL(block, aIv);
       
   338             CleanupStack::Pop(); //1st block owned by 2nd
       
   339             CleanupStack::PushL(block);//2nd block
       
   340             break;
       
   341         case EUtlSymmetricCipher3DesCbc:
       
   342             block = C3DESEncryptor::NewLC(aKey);
       
   343             block = CModeCBCEncryptor::NewL(block, aIv);
       
   344             CleanupStack::Pop(); //1st block owned by 2nd
       
   345             CleanupStack::PushL(block);//2nd block
       
   346             break;
       
   347         case EUtlSymmetricCipherAesCbc:
       
   348             block = CAESEncryptor::NewLC(aKey);
       
   349             block = CModeCBCEncryptor::NewL(block, aIv);
       
   350             CleanupStack::Pop(); //1st block owned by 2nd
       
   351             CleanupStack::PushL(block);//2nd block
       
   352             break;
       
   353         default:
       
   354             User::Leave(KErrGeneral);
       
   355             break;
       
   356         }
       
   357 
       
   358     if (cipher == 0) // it's a block cipher -> make a buffered version
       
   359         {
       
   360         CPadding* padding = CPaddingNone::NewLC();
       
   361         cipher = CBufferedEncryptor::NewL(block, padding);
       
   362         CleanupStack::Pop(); //padding - owned by cipher
       
   363         CleanupStack::Pop(); //block - owned by cipher
       
   364         }
       
   365     else
       
   366         {
       
   367         //-- it's a stream cipher -> everything is already made
       
   368         }
       
   369 
       
   370     CleanupStack::PushL(cipher);
       
   371     CUtlSymmetricCipher* utlCipher = new (ELeave) CUtlSymmetricCipher();
       
   372     utlCipher->iSymmetricCipher = cipher;   
       
   373     CleanupStack::Pop(); //cipher - owned by utlCipher
       
   374 
       
   375     return utlCipher;
       
   376     }
       
   377 
       
   378     
       
   379 EXPORT_C CUtlSymmetricCipher*
       
   380 TUtlCrypto::MakeSymmetricDecryptorL(TUtlSymmetricCipherId aCipherId,
       
   381                                     const TDesC8& aKey,
       
   382                                     const TDesC8& aIv)
       
   383 /** 
       
   384 * Makes symmetric block decryptor without padding.
       
   385 * @param aCipherId Cipher id.
       
   386 * @param aKey Key.
       
   387 * @param aIv Initialization vector.
       
   388 * @return CUtlSymmetricCipher* Pointer to symmetric cipher.
       
   389 */
       
   390     {
       
   391     if (aKey.Length() < 1)
       
   392     {
       
   393         User::Leave(KErrArgument);
       
   394     }
       
   395     CSymmetricCipher* cipher = 0;
       
   396     CBlockTransformation* block = 0;
       
   397     
       
   398     switch (aCipherId)
       
   399         {
       
   400         case EUtlSymmetricCipherDesCbc:
       
   401             block = CDESDecryptor::NewLC(aKey);
       
   402             block = CModeCBCDecryptor::NewL(block, aIv);
       
   403             CleanupStack::Pop(); //1st block owned by 2nd
       
   404             CleanupStack::PushL(block);//2nd block
       
   405             break;
       
   406         case EUtlSymmetricCipher3DesCbc:
       
   407             block = C3DESDecryptor::NewLC(aKey);
       
   408             block = CModeCBCDecryptor::NewL(block, aIv);
       
   409             CleanupStack::Pop(); //1st block owned by 2nd
       
   410             CleanupStack::PushL(block);//2nd block
       
   411             break;
       
   412         case EUtlSymmetricCipherAesCbc:
       
   413             block = CAESDecryptor::NewLC(aKey);
       
   414             block = CModeCBCDecryptor::NewL(block, aIv);
       
   415             CleanupStack::Pop(); //1st block owned by 2nd
       
   416             CleanupStack::PushL(block);//2nd block
       
   417             break;
       
   418         default:
       
   419             User::Leave(KErrGeneral);
       
   420             break;
       
   421         }
       
   422 
       
   423     if (cipher == 0) // it's a block cipher -> make a buffered version
       
   424         {
       
   425         CPadding* padding = CPaddingNone::NewLC();
       
   426         cipher = CBufferedDecryptor::NewL(block, padding);
       
   427         CleanupStack::Pop(); //padding - owned by cipher
       
   428         CleanupStack::Pop(); //block - owned by cipher
       
   429         }
       
   430     else
       
   431         {
       
   432         //-- it's a stream cipher -> everything is already made
       
   433         }
       
   434 
       
   435     CleanupStack::PushL(cipher);
       
   436     CUtlSymmetricCipher* utlCipher = new (ELeave) CUtlSymmetricCipher();
       
   437     utlCipher->iSymmetricCipher = cipher;   
       
   438     CleanupStack::Pop(); //cipher - owned by utlCipher
       
   439 
       
   440     return utlCipher;
       
   441     }
       
   442 
       
   443 EXPORT_C CUtlMessageDigest*
       
   444 TUtlCrypto::MakeMessageDigesterL(TUtlMessageDigestId aDigestId,
       
   445                                  const TDesC8&       aHmacKey)
       
   446 /** 
       
   447 * Makes message digester.
       
   448 * @param aDigestId Digest id.
       
   449 * @param aHmacKey HMAC key, if HMAC.
       
   450 * @return CUtlMessageDigest* Pointer to message digester.
       
   451 */
       
   452     {
       
   453     CMessageDigest* digest = 0;
       
   454     
       
   455     switch (aDigestId)
       
   456         {
       
   457         case EUtlMessageDigestMd5:
       
   458             digest = CMD5::NewL();
       
   459             break;
       
   460         case EUtlMessageDigestSha1:
       
   461             digest = CSHA1::NewL();
       
   462             break;
       
   463         default:
       
   464             User::Leave(KErrGeneral);
       
   465             break;
       
   466         }
       
   467     CleanupStack::PushL(digest);
       
   468 
       
   469     if (aHmacKey.Length() > 0)
       
   470         {
       
   471         digest = CHMAC::NewL(aHmacKey, digest);
       
   472         CleanupStack::Pop(); //original digest - owned by CHMAC
       
   473         CleanupStack::PushL(digest);
       
   474         }
       
   475     
       
   476     CUtlMessageDigest* utlMessageDigest = new (ELeave) CUtlMessageDigest();
       
   477     utlMessageDigest->iMessageDigest = digest;
       
   478     CleanupStack::Pop(); //digest - owned by utlMessageDigest
       
   479 
       
   480     return utlMessageDigest;
       
   481     }
       
   482 
       
   483 EXPORT_C CUtlDiffieHellman*
       
   484 TUtlCrypto::MakeDiffieHellmanL(const TDesC8& aN, const TDesC8& aG)
       
   485 /** 
       
   486 * Makes Diffie-Hellman key exchange object.
       
   487 * @param aN N.
       
   488 * @param aG G.
       
   489 * @return CUtlDiffieHellman* Pointer to Diffie-Hellman key exchange object.
       
   490 */
       
   491     {
       
   492     RInteger n = RInteger::NewL(aN);
       
   493     CleanupClosePushL(n);
       
   494     RInteger g = RInteger::NewL(aG);
       
   495     CleanupClosePushL(g);
       
   496 
       
   497     CDHKeyPair* dhKeyPair = CDHKeyPair::NewL(n, g);
       
   498     CleanupStack::PushL(dhKeyPair);
       
   499     
       
   500     CDH* dhKeyAgreement = CDH::NewLC(dhKeyPair->PrivateKey());
       
   501     
       
   502     CUtlDiffieHellman* utlDiffieHellman = new (ELeave) CUtlDiffieHellman();
       
   503     utlDiffieHellman->iDhKeyAgreement = dhKeyAgreement;
       
   504     utlDiffieHellman->iDhKeyPair = dhKeyPair;
       
   505     utlDiffieHellman->iModulusLength = aN.Length();
       
   506     CleanupStack::Pop(2); //dhKeyAgreement, dhKeyPair
       
   507     CleanupStack::Pop(2); // g, n    
       
   508 
       
   509     return utlDiffieHellman;
       
   510     }
       
   511     
       
   512 EXPORT_C void TUtlCrypto::RsaPublicKeyEncryptL(const TDesC8&    aPublicKeyData,
       
   513                                                const TDesC8&    aPlaintext,
       
   514                                                HBufC8*&         aCiphertext)
       
   515 /** 
       
   516 * RSA encrypts the plain text with the public key.
       
   517 * @param aPublicKeyData Public key.
       
   518 * @param aPlaintext Plain text.
       
   519 * @param aCiphertext Cipher text.
       
   520 */
       
   521     {
       
   522     CX509RSAPublicKey* publicKey = CX509RSAPublicKey::NewLC(aPublicKeyData);
       
   523     CRSAPKCS1v15Encryptor* rsaEncryptor = CRSAPKCS1v15Encryptor::NewLC(*publicKey);
       
   524     
       
   525     TInt publicKeySize = 2048; //publicKey->Size()
       
   526     TInt encrLth = publicKeySize / 8;
       
   527     HBufC8* ciphertext = HBufC8::NewLC(encrLth);
       
   528     TPtr8 ciphertextDesc(ciphertext->Des());
       
   529 
       
   530     rsaEncryptor->EncryptL(aPlaintext, ciphertextDesc);
       
   531 
       
   532     CleanupStack::Pop();            //ciphertext
       
   533     CleanupStack::PopAndDestroy(2); //rsaEncryptor, publicKey
       
   534     aCiphertext = ciphertext;
       
   535     }
       
   536 
       
   537 EXPORT_C void TUtlCrypto::RsaPublicKeyDecryptL(const TDesC8&    aPublicKeyData,
       
   538                                                const TDesC8&    aCiphertext,
       
   539                                                HBufC8*&         aPlaintext)
       
   540 /** 
       
   541 * RSA decrypts the cipher text with the public key.
       
   542 * @param aPublicKeyData Public key.
       
   543 * @param aCiphertext Cipher text.
       
   544 * @param aPlaintext Plain text.
       
   545 */
       
   546     {
       
   547     CX509RSAPublicKey* publicKey = CX509RSAPublicKey::NewLC(aPublicKeyData);
       
   548     CRSAPKCS1v15Verifier* verifier = CRSAPKCS1v15Verifier::NewLC(*publicKey);
       
   549 
       
   550     RInteger S = RInteger::NewL(aCiphertext);
       
   551     CleanupClosePushL(S);
       
   552     CRSASignature* signature = CRSASignature::NewL(S);
       
   553     CleanupStack::Pop(); //S
       
   554     CleanupStack::PushL(signature);
       
   555     
       
   556     aPlaintext = verifier->InverseSignLC(*signature);
       
   557     
       
   558     CleanupStack::Pop();            //aPlaintext
       
   559     CleanupStack::PopAndDestroy(3); //signature, verifier, publicKey
       
   560     }
       
   561     
       
   562 EXPORT_C TBool TUtlCrypto::DsaVerifySignatureL(const TDesC8&       aPublicKeyData,
       
   563                                                const TDesC8&       aDsaParams,
       
   564                                                const TDesC8&       aDsaSignatureR,
       
   565                                                const TDesC8&       aDsaSignatureS,
       
   566                                                const TDesC8&       aHashData)
       
   567 /** 
       
   568 * Verifies DSA signature.
       
   569 * @param aPublicKeyData Public key.
       
   570 * @param aDsaParams DSA parameters.
       
   571 * @param aDsaSignatureR R.
       
   572 * @param aDsaSignatureS S.
       
   573 * @param aHashData Hash data.
       
   574 * @return TBool Verify signature status: ETrue, if OK.
       
   575 */
       
   576     {
       
   577     TBool ret;
       
   578     TX509KeyFactory keyFactory;
       
   579     CDSAParameters* params = keyFactory.DSAParametersL(aDsaParams);
       
   580     CleanupStack::PushL(params);
       
   581     CDSAPublicKey* key = keyFactory.DSAPublicKeyL(*params, aPublicKeyData);
       
   582     CleanupStack::PushL(key);
       
   583     
       
   584     RInteger R = RInteger::NewL(aDsaSignatureR);
       
   585     CleanupClosePushL(R);
       
   586     RInteger S = RInteger::NewL(aDsaSignatureS);
       
   587     CleanupClosePushL(S);
       
   588     CDSASignature* signature = CDSASignature::NewL(R, S);
       
   589     CleanupStack::Pop(2); //S, R
       
   590     CleanupStack::PushL(signature);
       
   591     
       
   592     CDSAVerifier* verifier = CDSAVerifier::NewLC(*key);
       
   593     ret = verifier->VerifyL(aHashData, *signature);
       
   594     
       
   595     CleanupStack::PopAndDestroy(4); //verifier, signature, key, params
       
   596     return ret;
       
   597     }
       
   598     
       
   599 EXPORT_C TBool TUtlCrypto::IsWeakCryptoLibrary(void)
       
   600 /** 
       
   601 * Tests the strength of the crypto libary.
       
   602 * @return TBool ETrue, if weak crypto library.
       
   603 */
       
   604     {
       
   605     TCrypto::TStrength strength = TCrypto::Strength();
       
   606     if (strength == TCrypto::EWeak)
       
   607         return ETrue;
       
   608     else
       
   609         return EFalse;
       
   610     }
       
   611 
       
   612 EXPORT_C TUtlCrypto::TUtlCryptoVersion TUtlCrypto::CryptoVersion(void)
       
   613 /** 
       
   614 * Returns the version of the crypto libary.
       
   615 * @return TUtlCryptoVersion, crypto version
       
   616 */
       
   617     {
       
   618     return EUtlCryptoVersionSymbian1;
       
   619     }
       
   620