vpnengine/ikev1lib/inc/ikev1crypto.h
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: 
       
    15 * Cryptographic Intermediate Layer to use and change any crypto library easily.
       
    16 *
       
    17 */
       
    18 
       
    19 #ifndef IKEV1CRYPTO_H
       
    20 #define IKEV1CRYPTO_H
       
    21 
       
    22 #include <e32base.h>
       
    23 #include "ikev1isakmpct.h"
       
    24 
       
    25 
       
    26 class CUtlDiffieHellman;
       
    27 
       
    28 NONSHARABLE_CLASS(CIkeKeys) : public CBase
       
    29 {
       
    30 public:
       
    31     static CIkeKeys* NewL(const TDesC8& aN,const TDesC8& aG);   
       
    32     HBufC8 *GetPubKey();
       
    33     void XValueL(); 
       
    34     const HBufC8* KValueL(const TDesC8& aY) const;
       
    35 	inline TInt ModulusLength() {return iModuluslength;}
       
    36 
       
    37     ~CIkeKeys();
       
    38 private:
       
    39     CUtlDiffieHellman* iDHKey;
       
    40     const HBufC8*      iPubKey;
       
    41 	TInt               iModuluslength;
       
    42 };
       
    43 
       
    44 
       
    45 // SSL function implementation using Symbian apis
       
    46 //  - des_ede3_cbc_encrypt
       
    47 #define DES_ENCRYPT 1
       
    48 #define DES_DECRYPT 0
       
    49 
       
    50 #define HMAC_MD5_SIZE   128
       
    51 #define HMAC_SHA1_SIZE  160
       
    52 
       
    53 #define DESCBC_KEY_LEN  8
       
    54 #define DESCBC_IV_LEN   8
       
    55 
       
    56 #define AESCBC_DEF_KEY_LEN 16
       
    57 #define AESCBC_IV_LEN   16
       
    58 
       
    59 #define DEFAULT_NONCE_SIZE   128/8   //128 bits = 16 bytes
       
    60 
       
    61 #define PAD_SIZE	64 + 2 * DEFAULT_NONCE_SIZE + 1000
       
    62 
       
    63 //DH functions
       
    64 CIkeKeys* GeneratePubPrivKeysL(TUint aGroupDesc);
       
    65 HBufC8* ComputeAgreedKeyL(TUint aGroupDesc, const TDesC8 &aPeerPublicKey, CIkeKeys *aOwnKeys);
       
    66 
       
    67 //
       
    68 //Symmetric encryption/decryption functions
       
    69 //
       
    70 void DecryptL(const TUint8* aInputPayload, TUint8* aOutputPayload, TUint32 aLength, TDes8 &aIV, TDesC8& aKey, TUint16 aEncrAlg);
       
    71 TBool EncryptL(TDes8& aInputPayload, TDes8& aOutputPayload,TDes8 &aIV, TDesC8& aKey , TUint16 aEncrAlg);
       
    72 void Cipher3DesL(TUint8 *aInData, TInt aInDataLen, const TDesC8 &aPrfKey, TDes8 &aIV, TDes8 &aPrfOutput);
       
    73 
       
    74 //
       
    75 //Message Digest Algorithms
       
    76 //
       
    77 void MD5HashL(const TDesC8 &aInData, TDes8& aOutData);
       
    78 void SHA1HashL(const TDesC8 &aInData, TDes8& aOutData);
       
    79 
       
    80 void MD5HmacL(const TDesC8 &aInData, TDes8& aOutData, const TDesC8& aKeyData);
       
    81 void SHA1HmacL(const TDesC8 &aInData, TDes8& aOutData, const TDesC8& aKeyData);
       
    82 
       
    83 //The length of aInData must be less than PAD_SIZE. The caller of this function
       
    84 //has to take care of handling the size of this parameter.
       
    85 void Hmac3DesCbcL(const TDesC8 &aInData, TDes8& aOutData, const TDesC8& aKeyData);
       
    86 
       
    87 TInt SymmetricCipherL(TUint8 *aInput,  TUint8 *aOutput, TInt aLength,
       
    88 					  TUint8 *aKey,    TUint8 *aIV, TBool aEncr, TInt aEncAlg = DES_CBC);
       
    89 
       
    90 #endif