|
1 /* |
|
2 * Copyright (c) 2004 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: Provides a class for AES CM 128 key derivation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include "srtpkeyderivation_aescm128.h" |
|
22 #include "srtpaesctrcrypto.h" |
|
23 #include "srtpdef.h" |
|
24 #include "srtputils.h" |
|
25 |
|
26 // --------------------------------------------------------------------------- |
|
27 // CSRTPEncryptionAESCM128::NewL |
|
28 // --------------------------------------------------------------------------- |
|
29 // |
|
30 CSRTPKeyDerivation_AESCM128* CSRTPKeyDerivation_AESCM128::NewL() |
|
31 { |
|
32 CSRTPKeyDerivation_AESCM128* self = CSRTPKeyDerivation_AESCM128::NewLC(); |
|
33 CleanupStack::Pop(self); |
|
34 return self; |
|
35 } |
|
36 |
|
37 // --------------------------------------------------------------------------- |
|
38 // CSRTPKeyDerivation_AESCM128::NewLC |
|
39 // --------------------------------------------------------------------------- |
|
40 // |
|
41 CSRTPKeyDerivation_AESCM128* CSRTPKeyDerivation_AESCM128::NewLC() |
|
42 { |
|
43 CSRTPKeyDerivation_AESCM128* self = new( ELeave ) CSRTPKeyDerivation_AESCM128(); |
|
44 CleanupStack::PushL( self ); |
|
45 self->ConstructL(); |
|
46 return self; |
|
47 } |
|
48 |
|
49 |
|
50 // --------------------------------------------------------------------------- |
|
51 // CSRTPKeyDerivation_AESCM128::PRF_128BitL |
|
52 // --------------------------------------------------------------------------- |
|
53 // |
|
54 HBufC8* CSRTPKeyDerivation_AESCM128::PRF_128BitL(TUint aBitLength, |
|
55 const TDesC8& aKey, |
|
56 const TDesC8& aIV) |
|
57 { |
|
58 HBufC8* paddedIV = NULL; |
|
59 HBufC8* keystream = NULL; |
|
60 TBuf8<1> padChar; |
|
61 |
|
62 // if the IV value is shorter than the AES block size (128 bits, 16 octets), |
|
63 // --> do the padding |
|
64 if (aIV.Length() < KAESCM128BlockSizeInBytes) |
|
65 { |
|
66 paddedIV = HBufC8::NewMaxL(KAESCM128BlockSizeInBytes); |
|
67 CleanupStack::PushL(paddedIV); |
|
68 TUint8* ptr = const_cast<TUint8*>(paddedIV->Des().Ptr()); |
|
69 |
|
70 Mem::FillZ( ptr, KAESCM128BlockSizeInBytes); |
|
71 Mem::Copy( ptr, aIV.Ptr(), aIV.Length() ); |
|
72 } |
|
73 |
|
74 if (!paddedIV) |
|
75 { |
|
76 // get the AES keystream with the original IV value |
|
77 keystream = iEncryptor->KeystreamL(aBitLength, aKey, aIV); |
|
78 } |
|
79 else |
|
80 { |
|
81 // get the AES keystream with the padded IV value |
|
82 keystream = iEncryptor->KeystreamL(aBitLength, aKey, *paddedIV); |
|
83 } |
|
84 |
|
85 if (paddedIV) |
|
86 { |
|
87 CleanupStack::Pop(paddedIV); |
|
88 delete paddedIV; paddedIV=NULL; |
|
89 } |
|
90 |
|
91 return keystream; |
|
92 } |
|
93 |
|
94 |
|
95 // --------------------------------------------------------------------------- |
|
96 // CSRTPKeyDerivation_AESCM128::ConstructL |
|
97 // --------------------------------------------------------------------------- |
|
98 // |
|
99 void CSRTPKeyDerivation_AESCM128::ConstructL() |
|
100 { |
|
101 // Create AES-CTR Wrapper |
|
102 iEncryptor = CSrtpAESCTRCrypto::NewL(); |
|
103 |
|
104 } |
|
105 |
|
106 // --------------------------------------------------------------------------- |
|
107 // CSRTPKeyDerivation_AESCM128::~CSRTPKeyDerivation_AESCM128 |
|
108 // --------------------------------------------------------------------------- |
|
109 // |
|
110 CSRTPKeyDerivation_AESCM128::~CSRTPKeyDerivation_AESCM128() |
|
111 { |
|
112 // delete AES-CTR Wrapper |
|
113 delete iEncryptor; |
|
114 |
|
115 } |
|
116 |
|
117 // --------------------------------------------------------------------------- |
|
118 // CSRTPKeyDerivation_AESCM128::CSRTPKeyDerivation_AESCM128 |
|
119 // --------------------------------------------------------------------------- |
|
120 // |
|
121 CSRTPKeyDerivation_AESCM128::CSRTPKeyDerivation_AESCM128() |
|
122 { |
|
123 |
|
124 } |