williamr@2: /* williamr@2: * Copyright (c) 2006-2006 Nokia Corporation and/or its subsidiary(-ies). williamr@2: * All rights reserved. williamr@2: * This component and the accompanying materials are made available williamr@4: * under the terms of "Eclipse Public License v1.0" williamr@2: * which accompanies this distribution, and is available williamr@4: * at the URL "http://www.eclipse.org/legal/epl-v10.html". williamr@2: * williamr@2: * Initial Contributors: williamr@2: * Nokia Corporation - initial contribution. williamr@2: * williamr@2: * Contributors: williamr@2: * williamr@2: * Description: Crypto graphy utils api declaration williamr@2: * williamr@2: */ williamr@2: williamr@2: #ifndef C_SEN_CRYPTO_UTILS_H williamr@2: #define C_SEN_CRYPTO_UTILS_H williamr@2: williamr@2: #include williamr@2: williamr@2: williamr@2: /** williamr@2: * Set of static convenience methods to help in cryptography williamr@2: */ williamr@2: class SenCryptoUtils williamr@2: { williamr@2: public: williamr@2: /** williamr@2: * Algorithm taken from of TLS specification RFC 2246 - 5.HMAC and the pseudorandom function williamr@2: * williamr@2: * P_hash(secret, seed) = HMAC_hash(secret, A(1) + seed) + williamr@2: * HMAC_hash(secret, A(2) + seed) + williamr@2: * HMAC_hash(secret, A(3) + seed) + ... williamr@2: * williamr@2: * Where + indicates concatenation. williamr@2: * williamr@2: * A() is defined as: williamr@2: * A(0) = seed williamr@2: * A(i) = HMAC_hash(secret, A(i-1)) williamr@2: * williamr@2: * P_hash can be iterated as many times as is necessary to produce the williamr@2: * required quantity of data. For example, if P_SHA-1 was being used to williamr@2: * create 64 bytes of data, it would have to be iterated 4 times williamr@2: * (through A(4)), creating 80 bytes of output data; the last 16 bytes williamr@2: * of the final iteration would then be discarded, leaving 64 bytes of williamr@2: * output data. williamr@2: * @param aSecret - secret williamr@2: * @param aSeed - seed williamr@2: * @param aLength - length of new secret williamr@2: * @since Series60 4.0 williamr@2: */ williamr@2: IMPORT_C static HBufC8* GetPSHA1HashL( const TDesC8& aSecret, williamr@2: const TDesC8& aSeed, williamr@2: const TInt aLength ); williamr@2: williamr@2: /* williamr@2: * Encode data into Base64 format williamr@2: * @param aData - source data williamr@2: * @return encoded data, if some problem occurs, NULL is returned williamr@2: * @since Series60 4.0 williamr@2: */ williamr@2: IMPORT_C static HBufC8* EncodeBase64L(const TDesC8& aData); williamr@2: williamr@2: /* williamr@2: * Decode data from Base64 format williamr@2: * @param aData - source data williamr@2: * @return decoded data, if some problem occurs, NULL is returned williamr@2: * @since Series60 4.0 williamr@2: */ williamr@2: IMPORT_C static HBufC8* DecodeBase64L(const TDesC8& aData); williamr@2: williamr@2: /* williamr@2: * Randomize some data and hash it using MD5 digest algorithm. williamr@2: * @return hashed randomized data (constant length of hash according to MD5 specification) williamr@2: * @since Series60 4.0 williamr@2: */ williamr@2: IMPORT_C static HBufC8* RandomAndHashMd5LC(); williamr@2: williamr@2: /* williamr@2: * Create tag from security token. williamr@2: * @param aSecret security context token. williamr@2: * @param aValueType Indicates what the security token is williamr@2: * @return tag with encoded (base64) token. williamr@2: */ williamr@2: IMPORT_C static HBufC8* CreateEncodedBinarySecretL( const TDesC8& aSecret, williamr@2: const TDesC8& aValueType ); williamr@2: williamr@2: /* williamr@2: * Timestamp as number of seconds since 1 january 1970 williamr@2: * Calculated for present phone time. williamr@2: * @return timestamp value williamr@2: * @since Series60 5.0 williamr@2: */ williamr@2: IMPORT_C static HBufC8* GetTimestampL(); williamr@2: williamr@2: williamr@2: /* williamr@2: * Timestamp as number of seconds since 1 january 1970. williamr@2: * Calculated for provided time. williamr@2: * @param aTime base for generated timestamp williamr@2: * @return timestamp value williamr@2: * @since Series60 5.0 williamr@2: */ williamr@2: IMPORT_C static HBufC8* GetTimestampL(TTime aTime); williamr@2: williamr@2: /* williamr@2: * Randomize some data (based on time) and hash it using MD5 digest algorithm, williamr@2: * convert each byte to hex nember representation williamr@2: * @return hashed randomized data (constant length of hash according to MD5 specification williamr@2: * doubled during hex conversion) williamr@2: * @since Series60 5.0 williamr@2: */ williamr@2: IMPORT_C static HBufC8* GetRandomNonceL(); williamr@2: williamr@2: private: williamr@2: /** williamr@2: * Hide default C++ constructor. williamr@2: */ williamr@2: SenCryptoUtils(); williamr@2: }; williamr@2: williamr@2: #endif // C_SEN_CRYPTO_UTILS_H williamr@2: