|
1 /* |
|
2 * Copyright (c) 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: Header declaration |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #ifndef C_SEN_CRYPTO_UTILS_H |
|
22 #define C_SEN_CRYPTO_UTILS_H |
|
23 |
|
24 #include <hash.h> |
|
25 |
|
26 |
|
27 /** |
|
28 * Set of static convenience methods to help in cryptography |
|
29 */ |
|
30 class SenCryptoUtils |
|
31 { |
|
32 public: |
|
33 /** |
|
34 * Algorithm taken from of TLS specification RFC 2246 - 5.HMAC and the pseudorandom function |
|
35 * |
|
36 * P_hash(secret, seed) = HMAC_hash(secret, A(1) + seed) + |
|
37 * HMAC_hash(secret, A(2) + seed) + |
|
38 * HMAC_hash(secret, A(3) + seed) + ... |
|
39 * |
|
40 * Where + indicates concatenation. |
|
41 * |
|
42 * A() is defined as: |
|
43 * A(0) = seed |
|
44 * A(i) = HMAC_hash(secret, A(i-1)) |
|
45 * |
|
46 * P_hash can be iterated as many times as is necessary to produce the |
|
47 * required quantity of data. For example, if P_SHA-1 was being used to |
|
48 * create 64 bytes of data, it would have to be iterated 4 times |
|
49 * (through A(4)), creating 80 bytes of output data; the last 16 bytes |
|
50 * of the final iteration would then be discarded, leaving 64 bytes of |
|
51 * output data. |
|
52 * @param aSecret - secret |
|
53 * @param aSeed - seed |
|
54 * @param aLength - length of new secret |
|
55 * @since Series60 3.2.3 |
|
56 */ |
|
57 IMPORT_C static HBufC8* GetPSHA1HashL( const TDesC8& aSecret, |
|
58 const TDesC8& aSeed, |
|
59 const TInt aLength ); |
|
60 |
|
61 /* |
|
62 * Encode data into Base64 format |
|
63 * @param aData - source data |
|
64 * @return encoded data, if some problem occurs, NULL is returned |
|
65 * @since Series60 3.2.3 |
|
66 */ |
|
67 IMPORT_C static HBufC8* EncodeBase64L(const TDesC8& aData); |
|
68 |
|
69 /* |
|
70 * Decode data from Base64 format |
|
71 * @param aData - source data |
|
72 * @return decoded data, if some problem occurs, NULL is returned |
|
73 * @since Series60 3.2.3 |
|
74 */ |
|
75 IMPORT_C static HBufC8* DecodeBase64L(const TDesC8& aData); |
|
76 |
|
77 /* |
|
78 * Randomize some data and hash it using MD5 digest algorithm. |
|
79 * @return hashed randomized data (constant length of hash according to MD5 specification) |
|
80 * @since Series60 3.2.3 |
|
81 */ |
|
82 IMPORT_C static HBufC8* RandomAndHashMd5LC(); |
|
83 |
|
84 /* |
|
85 * Create <BinarySecret> tag from security token. |
|
86 * @param aSecret security context token. |
|
87 * @param aValueType Indicates what the security token is |
|
88 * @return <BinarySecret> tag with encoded (base64) token. |
|
89 */ |
|
90 IMPORT_C static HBufC8* CreateEncodedBinarySecretL( const TDesC8& aSecret, |
|
91 const TDesC8& aValueType ); |
|
92 |
|
93 /* |
|
94 * Timestamp as number of seconds since 1 january 1970. |
|
95 * Calculated for present phone time. |
|
96 * @return timestamp value |
|
97 * @since Series60 3.2.3 |
|
98 */ |
|
99 IMPORT_C static HBufC8* GetTimestampL(); |
|
100 |
|
101 |
|
102 /* |
|
103 * Timestamp as number of seconds since 1 january 1970. |
|
104 * Calculated for provided time. |
|
105 * @param aTime base for generated timestamp |
|
106 * @return timestamp value |
|
107 * @since Series60 5.0 |
|
108 */ |
|
109 IMPORT_C static HBufC8* GetTimestampL(TTime aTime); |
|
110 |
|
111 |
|
112 /* |
|
113 * Randomize some data (based on time) and hash it using MD5 digest algorithm, |
|
114 * convert each byte to hex nember representation |
|
115 * @return hashed randomized data (constant length of hash according to MD5 specification |
|
116 * doubled during hex conversion) |
|
117 * @since Series60 3.2.3 |
|
118 */ |
|
119 IMPORT_C static HBufC8* GetRandomNonceL(); |
|
120 |
|
121 private: |
|
122 /** |
|
123 * Hide default C++ constructor. |
|
124 */ |
|
125 SenCryptoUtils(); |
|
126 }; |
|
127 |
|
128 #endif // C_SEN_CRYPTO_UTILS_H |
|
129 |