epoc32/include/mw/sencryptoutils.h
author William Roberts <williamr@symbian.org>
Tue, 16 Mar 2010 16:12:26 +0000
branchSymbian2
changeset 2 2fe1408b6811
child 4 837f303aceeb
permissions -rw-r--r--
Final list of Symbian^2 public API header files
williamr@2
     1
/*
williamr@2
     2
* Copyright (c) 2006-2006 Nokia Corporation and/or its subsidiary(-ies). 
williamr@2
     3
* All rights reserved.
williamr@2
     4
* This component and the accompanying materials are made available
williamr@2
     5
* 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
williamr@2
     6
* which accompanies this distribution, and is available
williamr@2
     7
* at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
williamr@2
     8
*
williamr@2
     9
* Initial Contributors:
williamr@2
    10
* Nokia Corporation - initial contribution.
williamr@2
    11
*
williamr@2
    12
* Contributors:
williamr@2
    13
*
williamr@2
    14
* Description: Crypto graphy utils api declaration
williamr@2
    15
*
williamr@2
    16
*/
williamr@2
    17
williamr@2
    18
#ifndef C_SEN_CRYPTO_UTILS_H
williamr@2
    19
#define C_SEN_CRYPTO_UTILS_H
williamr@2
    20
williamr@2
    21
#include <hash.h>
williamr@2
    22
williamr@2
    23
williamr@2
    24
/**
williamr@2
    25
 * Set of static convenience methods to help in cryptography
williamr@2
    26
 */
williamr@2
    27
class SenCryptoUtils
williamr@2
    28
    {
williamr@2
    29
    public:
williamr@2
    30
        /**
williamr@2
    31
        * Algorithm taken from of TLS specification RFC 2246 - 5.HMAC and the pseudorandom function  
williamr@2
    32
        *           
williamr@2
    33
        *           P_hash(secret, seed) = HMAC_hash(secret, A(1) + seed) +
williamr@2
    34
        *                              HMAC_hash(secret, A(2) + seed) +
williamr@2
    35
        *                              HMAC_hash(secret, A(3) + seed) + ...
williamr@2
    36
        *
williamr@2
    37
        *               Where + indicates concatenation.
williamr@2
    38
        *
williamr@2
    39
        *               A() is defined as:
williamr@2
    40
        *                   A(0) = seed
williamr@2
    41
        *                   A(i) = HMAC_hash(secret, A(i-1))
williamr@2
    42
        *
williamr@2
    43
        *       P_hash can be iterated as many times as is necessary to produce the
williamr@2
    44
        *       required quantity of data. For example, if P_SHA-1 was being used to
williamr@2
    45
        *       create 64 bytes of data, it would have to be iterated 4 times
williamr@2
    46
        *       (through A(4)), creating 80 bytes of output data; the last 16 bytes
williamr@2
    47
        *       of the final iteration would then be discarded, leaving 64 bytes of
williamr@2
    48
        *       output data.
williamr@2
    49
        * @param aSecret - secret
williamr@2
    50
        * @param aSeed - seed
williamr@2
    51
        * @param aLength - length of new secret
williamr@2
    52
        * @since Series60 4.0
williamr@2
    53
        */
williamr@2
    54
        IMPORT_C static HBufC8* GetPSHA1HashL( const TDesC8& aSecret, 
williamr@2
    55
                                               const TDesC8& aSeed, 
williamr@2
    56
                                               const TInt aLength );
williamr@2
    57
    
williamr@2
    58
        /*
williamr@2
    59
        * Encode data into Base64 format
williamr@2
    60
        * @param aData - source data
williamr@2
    61
        * @return encoded data, if some problem occurs, NULL is returned
williamr@2
    62
        * @since Series60 4.0
williamr@2
    63
        */
williamr@2
    64
        IMPORT_C static HBufC8* EncodeBase64L(const TDesC8& aData);
williamr@2
    65
    
williamr@2
    66
        /*
williamr@2
    67
        * Decode data from Base64 format
williamr@2
    68
        * @param aData - source data
williamr@2
    69
        * @return decoded data, if some problem occurs, NULL is returned
williamr@2
    70
        * @since Series60 4.0
williamr@2
    71
        */
williamr@2
    72
        IMPORT_C static HBufC8* DecodeBase64L(const TDesC8& aData);
williamr@2
    73
    
williamr@2
    74
        /*
williamr@2
    75
        * Randomize some data and hash it using MD5 digest algorithm.
williamr@2
    76
        * @return hashed randomized data (constant length of hash according to MD5 specification)
williamr@2
    77
        * @since Series60 4.0
williamr@2
    78
        */
williamr@2
    79
        IMPORT_C static HBufC8* RandomAndHashMd5LC();
williamr@2
    80
        
williamr@2
    81
        /*
williamr@2
    82
        * Create <BinarySecret> tag from security token.
williamr@2
    83
        * @param aSecret security context token.
williamr@2
    84
        * @param aValueType Indicates what the security token is
williamr@2
    85
        * @return <BinarySecret> tag with encoded (base64) token.
williamr@2
    86
        */
williamr@2
    87
        IMPORT_C static HBufC8* CreateEncodedBinarySecretL( const TDesC8& aSecret, 
williamr@2
    88
                                                            const TDesC8& aValueType );
williamr@2
    89
        
williamr@2
    90
        /*
williamr@2
    91
        * Timestamp as number of seconds since 1 january 1970 
williamr@2
    92
        *   Calculated for present phone time.
williamr@2
    93
        * @return timestamp value
williamr@2
    94
        * @since Series60 5.0
williamr@2
    95
        */
williamr@2
    96
        IMPORT_C static HBufC8* GetTimestampL();
williamr@2
    97
williamr@2
    98
williamr@2
    99
        /*
williamr@2
   100
        * Timestamp as number of seconds since 1 january 1970.
williamr@2
   101
        *   Calculated for provided time.
williamr@2
   102
        * @param aTime base for generated timestamp
williamr@2
   103
        * @return timestamp value
williamr@2
   104
        * @since Series60 5.0
williamr@2
   105
        */
williamr@2
   106
        IMPORT_C static HBufC8* GetTimestampL(TTime aTime);
williamr@2
   107
        
williamr@2
   108
        /*
williamr@2
   109
        * Randomize some data (based on time) and hash it using MD5 digest algorithm, 
williamr@2
   110
        * convert each byte to hex nember representation
williamr@2
   111
        * @return hashed randomized data (constant length of hash according to MD5 specification
williamr@2
   112
        * doubled during hex conversion)
williamr@2
   113
        * @since Series60 5.0
williamr@2
   114
        */
williamr@2
   115
        IMPORT_C static HBufC8* GetRandomNonceL();
williamr@2
   116
        
williamr@2
   117
    private:
williamr@2
   118
        /**
williamr@2
   119
        * Hide default C++ constructor.
williamr@2
   120
        */
williamr@2
   121
        SenCryptoUtils();
williamr@2
   122
    };
williamr@2
   123
williamr@2
   124
#endif // C_SEN_CRYPTO_UTILS_H
williamr@2
   125