epoc32/include/mw/sencryptoutils.h
branchSymbian2
changeset 2 2fe1408b6811
child 4 837f303aceeb
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/epoc32/include/mw/sencryptoutils.h	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -0,0 +1,125 @@
     1.4 +/*
     1.5 +* Copyright (c) 2006-2006 Nokia Corporation and/or its subsidiary(-ies). 
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: Crypto graphy utils api declaration
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +#ifndef C_SEN_CRYPTO_UTILS_H
    1.22 +#define C_SEN_CRYPTO_UTILS_H
    1.23 +
    1.24 +#include <hash.h>
    1.25 +
    1.26 +
    1.27 +/**
    1.28 + * Set of static convenience methods to help in cryptography
    1.29 + */
    1.30 +class SenCryptoUtils
    1.31 +    {
    1.32 +    public:
    1.33 +        /**
    1.34 +        * Algorithm taken from of TLS specification RFC 2246 - 5.HMAC and the pseudorandom function  
    1.35 +        *           
    1.36 +        *           P_hash(secret, seed) = HMAC_hash(secret, A(1) + seed) +
    1.37 +        *                              HMAC_hash(secret, A(2) + seed) +
    1.38 +        *                              HMAC_hash(secret, A(3) + seed) + ...
    1.39 +        *
    1.40 +        *               Where + indicates concatenation.
    1.41 +        *
    1.42 +        *               A() is defined as:
    1.43 +        *                   A(0) = seed
    1.44 +        *                   A(i) = HMAC_hash(secret, A(i-1))
    1.45 +        *
    1.46 +        *       P_hash can be iterated as many times as is necessary to produce the
    1.47 +        *       required quantity of data. For example, if P_SHA-1 was being used to
    1.48 +        *       create 64 bytes of data, it would have to be iterated 4 times
    1.49 +        *       (through A(4)), creating 80 bytes of output data; the last 16 bytes
    1.50 +        *       of the final iteration would then be discarded, leaving 64 bytes of
    1.51 +        *       output data.
    1.52 +        * @param aSecret - secret
    1.53 +        * @param aSeed - seed
    1.54 +        * @param aLength - length of new secret
    1.55 +        * @since Series60 4.0
    1.56 +        */
    1.57 +        IMPORT_C static HBufC8* GetPSHA1HashL( const TDesC8& aSecret, 
    1.58 +                                               const TDesC8& aSeed, 
    1.59 +                                               const TInt aLength );
    1.60 +    
    1.61 +        /*
    1.62 +        * Encode data into Base64 format
    1.63 +        * @param aData - source data
    1.64 +        * @return encoded data, if some problem occurs, NULL is returned
    1.65 +        * @since Series60 4.0
    1.66 +        */
    1.67 +        IMPORT_C static HBufC8* EncodeBase64L(const TDesC8& aData);
    1.68 +    
    1.69 +        /*
    1.70 +        * Decode data from Base64 format
    1.71 +        * @param aData - source data
    1.72 +        * @return decoded data, if some problem occurs, NULL is returned
    1.73 +        * @since Series60 4.0
    1.74 +        */
    1.75 +        IMPORT_C static HBufC8* DecodeBase64L(const TDesC8& aData);
    1.76 +    
    1.77 +        /*
    1.78 +        * Randomize some data and hash it using MD5 digest algorithm.
    1.79 +        * @return hashed randomized data (constant length of hash according to MD5 specification)
    1.80 +        * @since Series60 4.0
    1.81 +        */
    1.82 +        IMPORT_C static HBufC8* RandomAndHashMd5LC();
    1.83 +        
    1.84 +        /*
    1.85 +        * Create <BinarySecret> tag from security token.
    1.86 +        * @param aSecret security context token.
    1.87 +        * @param aValueType Indicates what the security token is
    1.88 +        * @return <BinarySecret> tag with encoded (base64) token.
    1.89 +        */
    1.90 +        IMPORT_C static HBufC8* CreateEncodedBinarySecretL( const TDesC8& aSecret, 
    1.91 +                                                            const TDesC8& aValueType );
    1.92 +        
    1.93 +        /*
    1.94 +        * Timestamp as number of seconds since 1 january 1970 
    1.95 +        *   Calculated for present phone time.
    1.96 +        * @return timestamp value
    1.97 +        * @since Series60 5.0
    1.98 +        */
    1.99 +        IMPORT_C static HBufC8* GetTimestampL();
   1.100 +
   1.101 +
   1.102 +        /*
   1.103 +        * Timestamp as number of seconds since 1 january 1970.
   1.104 +        *   Calculated for provided time.
   1.105 +        * @param aTime base for generated timestamp
   1.106 +        * @return timestamp value
   1.107 +        * @since Series60 5.0
   1.108 +        */
   1.109 +        IMPORT_C static HBufC8* GetTimestampL(TTime aTime);
   1.110 +        
   1.111 +        /*
   1.112 +        * Randomize some data (based on time) and hash it using MD5 digest algorithm, 
   1.113 +        * convert each byte to hex nember representation
   1.114 +        * @return hashed randomized data (constant length of hash according to MD5 specification
   1.115 +        * doubled during hex conversion)
   1.116 +        * @since Series60 5.0
   1.117 +        */
   1.118 +        IMPORT_C static HBufC8* GetRandomNonceL();
   1.119 +        
   1.120 +    private:
   1.121 +        /**
   1.122 +        * Hide default C++ constructor.
   1.123 +        */
   1.124 +        SenCryptoUtils();
   1.125 +    };
   1.126 +
   1.127 +#endif // C_SEN_CRYPTO_UTILS_H
   1.128 +