rtp/srtpstack/src/srtpauthentication_rcc.cpp
branchRCL_3
changeset 9 1e1cc61f56c3
parent 0 307788aac0a8
--- a/rtp/srtpstack/src/srtpauthentication_rcc.cpp	Fri Feb 19 23:10:33 2010 +0200
+++ b/rtp/srtpstack/src/srtpauthentication_rcc.cpp	Fri Mar 12 15:44:11 2010 +0200
@@ -77,11 +77,11 @@
 	
     CleanupStack::PushL(result);
 
-    CSHA1* sha1 = CSHA1::NewL(); 
-    CleanupStack::PushL(sha1);
-    
-    CHMAC *hmac = CHMAC::NewL(aKey, sha1);        
-    CleanupStack::Pop(sha1);
+    if ( !iHmac || !iKey || (*iKey != aKey) )
+        {
+        CreateHmacL(aKey);
+        }
+   
     CleanupStack::Pop(result);
     SRTP_DEBUG_TINT_VALUE( "HMAC INPUT and INPUT Length is ", aAuthPortion.Length());
     SRTP_DEBUG_TINT_VALUE( "HMAC INPUT and INPUT Size is ", aAuthPortion.Size());     
@@ -89,17 +89,16 @@
               
     if(aRoc.Length())
     	{
-  		hmac->Update(DES_AS_8_BIT(aAuthPortion));
-    	buf.Copy(hmac->Final(DES_AS_8_BIT(aRoc))); 	
+  		iHmac->Update(DES_AS_8_BIT(aAuthPortion));
+    	buf.Copy(iHmac->Final(DES_AS_8_BIT(aRoc))); 	
     	}
     else
     	{
-    	buf.Copy(hmac->Final(DES_AS_8_BIT(aAuthPortion)));
+    	buf.Copy(iHmac->Final(DES_AS_8_BIT(aAuthPortion)));
     	}
     *result = buf;    
     ptrOutputBuff.SetLength(aBitLength/8);
     
-    delete hmac;
    	SRTP_DEBUG_DETAIL( "HMAC caculated Authentication tag" );
    	SRTP_DEBUG_PACKET( *result );    
     
@@ -124,6 +123,8 @@
 //
 CSrtpAuthentication_RCC::~CSrtpAuthentication_RCC()
     {    
+    delete iHmac;
+    delete iKey;
     }
 
 // ---------------------------------------------------------------------------
@@ -135,3 +136,20 @@
         
     }
 
+// ---------------------------------------------------------------------------
+// CSrtpAuthentication_RCC::CreateHmacL
+// ---------------------------------------------------------------------------
+//
+void CSrtpAuthentication_RCC::CreateHmacL(const TDesC8& aKey)
+    {
+    delete iHmac;
+    iHmac = 0;
+    delete iKey;
+    iKey = 0;
+    iKey = aKey.AllocL();
+    CSHA1* sha1 = CSHA1::NewL(); 
+    CleanupStack::PushL(sha1);
+    iHmac = CHMAC::NewL(*iKey, sha1);        
+    CleanupStack::Pop(sha1);
+    }
+