multimediacommscontroller/mmccrtpsourcesink/src/mmcccryptoadapter.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2006 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:    Implementation of the MCC Crypto Adapter
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // System includes
       
    22 #include <e32base.h>
       
    23 #include <srtpcryptocontext.h>
       
    24 #include <srtpmasterkey.h>
       
    25 #include <srtpmastersalt.h>
       
    26 #include <mmf/common/mmfcontrollerframework.h>
       
    27 
       
    28 // User include
       
    29 #include "mmcccryptoadapter.h"
       
    30 #include "mccrtpdefs.h"
       
    31 #include "mmcccryptocontext.h"
       
    32 
       
    33 
       
    34 // ======== MEMBER FUNCTIONS ========
       
    35 
       
    36 // ---------------------------------------------------------------------------
       
    37 // TMccCryptoAdapter::CreateCryptoContextL
       
    38 // 
       
    39 // ---------------------------------------------------------------------------
       
    40 //    
       
    41 CSRTPCryptoContext* TMccCryptoAdapter::CreateCryptoContextL( 
       
    42                                    const TMccCryptoContext& aContextParams )
       
    43     {
       
    44 	TRACE_RTP_CRYPTO_ADAPTER_PRINT( "TMccCryptoAdapter::CreateCryptoContextL IN" )
       
    45     
       
    46     const TMccSrtpMasterKey mccMasterkey( aContextParams.MasterKey() ); 
       
    47     const TMccSrtpMasterSalt mccMasterSalt( aContextParams.MasterSalt() );
       
    48     const TMccSrtpCryptoParams mccCryptoParams( aContextParams.CryptoParams() ); 
       
    49 
       
    50     // Creates Srtp master key
       
    51     CSRTPMasterKey* masterKey = CSRTPMasterKey::NewL( mccMasterkey.iMasterKey,
       
    52                                                       mccMasterkey.iMKI,
       
    53                                                       mccMasterkey.iEncKeyBitLength,
       
    54                                                       mccMasterkey.iAuthKeyBitLength );
       
    55     CleanupStack::PushL( masterKey );
       
    56     
       
    57     TRACE_RTP_CRYPTO_ADAPTER_PRINT2( "TMccCryptoAdapter::masterKey - iEncKeyBitLength: %d ", mccMasterkey.iEncKeyBitLength )
       
    58     TRACE_RTP_CRYPTO_ADAPTER_PRINT2( "TMccCryptoAdapter::masterKey - iAuthKeyBitLength: %d ", mccMasterkey.iAuthKeyBitLength  )    
       
    59 
       
    60     
       
    61     // Creates Srtp master salt                                   
       
    62     CSRTPMasterSalt* masterSalt = CSRTPMasterSalt::NewL( mccMasterSalt.iMasterSalt,
       
    63                                                          mccMasterSalt.iSaltKeyLength );
       
    64     CleanupStack::PushL( masterSalt );
       
    65     
       
    66     TRACE_RTP_CRYPTO_ADAPTER_PRINT2( "TMccCryptoAdapter::masterSalt - iSaltKeyLength: %d ", mccMasterSalt.iSaltKeyLength )    
       
    67 
       
    68     // Creates Srtp crypto params
       
    69     TSrtpCryptoParams cryptoParams;
       
    70     cryptoParams.iSrtpEncAlg = ( TSRTPEncAlg )mccCryptoParams.iSrtpEncAlg;
       
    71     cryptoParams.iSrtpAuthAlg = ( TSRTPAuthAlg )mccCryptoParams.iSrtpAuthAlg;
       
    72     cryptoParams.iSrtpAuthTagLen = mccCryptoParams.iSrtpAuthTagLen;
       
    73     cryptoParams.iPrefixLen = mccCryptoParams.iPrefixLen;
       
    74     cryptoParams.iSrtpReplayProtection = mccCryptoParams.iSrtpReplayProtection;
       
    75     cryptoParams.iSrtpKeyDervRate = mccCryptoParams.iSrtpKeyDervRate;
       
    76     
       
    77     // RTCP Crypto Params
       
    78     cryptoParams.iSrtcpEncAlg = ( TSRTPEncAlg )mccCryptoParams.iSrtcpEncAlg;
       
    79     cryptoParams.iSrtcpAuthAlg = ( TSRTPAuthAlg )mccCryptoParams.iSrtcpAuthAlg;
       
    80     cryptoParams.iSrtcpAuthTagLen = mccCryptoParams.iSrtcpAuthTagLen;
       
    81     cryptoParams.iSrtcpReplayProtection = mccCryptoParams.iSrtcpReplayProtection;
       
    82     cryptoParams.iSrtcpKeyDervRate = mccCryptoParams.iSrtcpKeyDervRate;
       
    83     
       
    84     cryptoParams.iROCTransRate = mccCryptoParams.iROCTransRate;
       
    85     cryptoParams.iMasterKeysLifeTime = mccCryptoParams.iMasterKeysLifeTime;
       
    86     cryptoParams.iReplayWindowSizeHint = mccCryptoParams.iReplayWindowSizeHint;
       
    87     cryptoParams.iIsRCCm3Sync = mccCryptoParams.iIsRCCm3Sync;
       
    88     
       
    89 
       
    90     TRACE_RTP_CRYPTO_ADAPTER_PRINT2( "TMccCryptoAdapter::cryptoParams - iSrtpEncAlg, [0=null, 1=AES_CM]: %d", ( TUint )cryptoParams.iSrtpEncAlg )
       
    91     TRACE_RTP_CRYPTO_ADAPTER_PRINT2( "TMccCryptoAdapter::cryptoParams - iSrtpAuthAlg [0=null, 1=HMAC_SHA1 2=RCCm1, 3=RCCm2, 4=RCCm3]: %d", ( TUint )cryptoParams.iSrtpAuthAlg )
       
    92     TRACE_RTP_CRYPTO_ADAPTER_PRINT2( "TMccCryptoAdapter::cryptoParams - iSrtpAuthTagLen: %d", cryptoParams.iSrtpAuthTagLen )
       
    93     TRACE_RTP_CRYPTO_ADAPTER_PRINT2( "TMccCryptoAdapter::cryptoParams - iPrefixLen: %d", cryptoParams.iPrefixLen )
       
    94     TRACE_RTP_CRYPTO_ADAPTER_PRINT2( "TMccCryptoAdapter::cryptoParams - iSrtpReplayProtection: %d", cryptoParams.iSrtpReplayProtection )
       
    95     TRACE_RTP_CRYPTO_ADAPTER_PRINT2( "TMccCryptoAdapter::cryptoParams - iSrtpKeyDervRate: %d", cryptoParams.iSrtpKeyDervRate )
       
    96     TRACE_RTP_CRYPTO_ADAPTER_PRINT( "" )  
       
    97     TRACE_RTP_CRYPTO_ADAPTER_PRINT2( "TMccCryptoAdapter::cryptoParams - iSrtcpEncAlg, [0=null, 1=AES_CM] : %d", ( TUint )cryptoParams.iSrtcpEncAlg )
       
    98     TRACE_RTP_CRYPTO_ADAPTER_PRINT2( "TMccCryptoAdapter::cryptoParams - iSrtcpAuthAlg [0=null, 1=HMAC_SHA1 2=RCCm1, 3=RCCm2, 4=RCCm3]: %d", ( TUint )cryptoParams.iSrtcpAuthAlg )   
       
    99     TRACE_RTP_CRYPTO_ADAPTER_PRINT2( "TMccCryptoAdapter::cryptoParams - iSrtcpAuthTagLen: %d", cryptoParams.iSrtcpAuthTagLen )
       
   100     TRACE_RTP_CRYPTO_ADAPTER_PRINT2( "TMccCryptoAdapter::cryptoParams - iSrtcpReplayProtection: %d", cryptoParams.iSrtcpReplayProtection )
       
   101     TRACE_RTP_CRYPTO_ADAPTER_PRINT2( "TMccCryptoAdapter::cryptoParams - iSrtcpKeyDervRate: %d", cryptoParams.iSrtcpKeyDervRate )
       
   102 
       
   103 
       
   104     TRACE_RTP_CRYPTO_ADAPTER_PRINT2( "TMccCryptoAdapter::cryptoParams - iROCTransRate: %d", cryptoParams.iROCTransRate)
       
   105     TRACE_RTP_CRYPTO_ADAPTER_PRINT2( "TMccCryptoAdapter::cryptoParams - iMasterKeysLifeTime: %d", cryptoParams.iMasterKeysLifeTime )
       
   106     TRACE_RTP_CRYPTO_ADAPTER_PRINT2( "TMccCryptoAdapter::cryptoParams - iReplayWindowSizeHint: %d", cryptoParams.iReplayWindowSizeHint )
       
   107     TRACE_RTP_CRYPTO_ADAPTER_PRINT2( "TMccCryptoAdapter::cryptoParams - iIsRCCm3Sync: %d", cryptoParams.iIsRCCm3Sync )     
       
   108 
       
   109     
       
   110     CleanupStack::Pop( masterSalt );
       
   111     CleanupStack::Pop( masterKey );
       
   112                                                                
       
   113     CSRTPCryptoContext* context = CSRTPCryptoContext::NewL( masterKey,
       
   114                                                             masterSalt, 
       
   115                                                             cryptoParams );
       
   116 
       
   117 	TRACE_RTP_CRYPTO_ADAPTER_PRINT( "TMccCryptoAdapter::CreateCryptoContextL OUT" );   
       
   118     return context;   
       
   119     };
       
   120  
       
   121 // ---------------------------------------------------------------------------
       
   122 // TMccCryptoAdapter::UpdateCryptoContextL()
       
   123 // 
       
   124 // ---------------------------------------------------------------------------
       
   125 //   
       
   126 void TMccCryptoAdapter::UpdateCryptoContextL( const TMccCryptoContext& aContextParams,
       
   127                                               CSRTPCryptoContext& aContext )
       
   128     {
       
   129     TRACE_RTP_CRYPTO_ADAPTER_PRINT( "TMccCryptoAdapter::UpdateCryptoContextL IN" )
       
   130     
       
   131     const TMccSrtpMasterKey mccMasterkey( aContextParams.MasterKey() ); 
       
   132     const TMccSrtpMasterSalt mccMasterSalt( aContextParams.MasterSalt() );
       
   133     const TMccSrtpCryptoParams mccCryptoParams( aContextParams.CryptoParams() );
       
   134        
       
   135     // Creates Srtp master key
       
   136     CSRTPMasterKey* masterKey = CSRTPMasterKey::NewL( mccMasterkey.iMasterKey,
       
   137                                                       mccMasterkey.iMKI,
       
   138                                                       mccMasterkey.iEncKeyBitLength,
       
   139                                                       mccMasterkey.iAuthKeyBitLength );
       
   140                                                       
       
   141     CleanupStack::PushL( masterKey );
       
   142                                                       
       
   143     CSRTPMasterSalt* masterSalt = CSRTPMasterSalt::NewL( mccMasterSalt.iMasterSalt,
       
   144                                                          mccMasterSalt.iSaltKeyLength );
       
   145     CleanupStack::PushL( masterSalt );
       
   146                                                
       
   147     if ( EFalse == masterKey->Valid() )
       
   148         {
       
   149         TRACE_RTP_CRYPTO_ADAPTER_PRINT( "TMccCryptoAdapter::UpdateCryptoContextL Masterkey isn't valid" )
       
   150 
       
   151         User::Leave( KErrArgument );
       
   152         }
       
   153         
       
   154     if ( EFalse == masterSalt->Valid() )
       
   155         {
       
   156         TRACE_RTP_CRYPTO_ADAPTER_PRINT( "TMccCryptoAdapter::UpdateCryptoContextL Mastersalt isn't valid" )
       
   157 
       
   158         User::Leave( KErrArgument );
       
   159         } 
       
   160          
       
   161     if ( ( aContext.MasterSalt().MasterSalt()).Compare( masterSalt->MasterSalt() ) != 0 )
       
   162         {               
       
   163         aContext.SetMasterSalt( masterSalt );
       
   164         CleanupStack::Pop( masterSalt );
       
   165         TRACE_RTP_CRYPTO_ADAPTER_PRINT( "TMccCryptoAdapter::UpdateCryptoContextL MasterSalt Is changed" )  
       
   166         }
       
   167     else
       
   168         {
       
   169         CleanupStack::PopAndDestroy( masterSalt );
       
   170         TRACE_RTP_CRYPTO_ADAPTER_PRINT( "TMccCryptoAdapter::UpdateCryptoContextL MasterSalt Isn't changed" )   
       
   171         }
       
   172 
       
   173     if ( ( aContext.MasterKey().MasterKey()).Compare( masterKey->MasterKey() ) != 0 ||
       
   174          ( aContext.MasterKey().MKI()).Compare( masterKey->MKI() ) != 0 )
       
   175         {               
       
   176         aContext.SetMasterKey( masterKey );
       
   177         CleanupStack::Pop( masterKey );
       
   178         TRACE_RTP_CRYPTO_ADAPTER_PRINT( "TMccCryptoAdapter::UpdateCryptoContextL MasterKey Is changed" ) 
       
   179         }
       
   180     else
       
   181         {
       
   182         CleanupStack::PopAndDestroy( masterKey );
       
   183         TRACE_RTP_CRYPTO_ADAPTER_PRINT( "TMccCryptoAdapter::UpdateCryptoContextL MasterKey Isn't changed" )  
       
   184         }
       
   185     
       
   186     TRACE_RTP_CRYPTO_ADAPTER_PRINT( "TMccCryptoAdapter::UpdateCryptoContextL OUT" )            
       
   187     }
       
   188 //  End of File