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: Encryption/Decryption support functions |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <e32std.h> |
|
21 #include <e32base.h> |
|
22 #include <e32math.h> |
|
23 #include <s32buf.h> |
|
24 #include <s32crypt.h> |
|
25 |
|
26 #include "LMSecurity.h" |
|
27 #include "LMSecurityEncrypt.h" |
|
28 |
|
29 // ============================ MEMBER FUNCTIONS =============================== |
|
30 |
|
31 // ----------------------------------------------------------------------------- |
|
32 // CLMSecurityEncrypt::CLMSecurityEncrypt |
|
33 // Initialize the random key stream from a constant |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 CLMSecurityEncrypt::CLMSecurityEncrypt( |
|
37 const TDesC8& init) |
|
38 { |
|
39 TPckg<TUint> p(0); |
|
40 |
|
41 p.Copy(init); |
|
42 iKey = p(); |
|
43 Math::Rand(iKey); |
|
44 } |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // CLMSecurityEncrypt::EncryptL |
|
48 // Encrypt using the key stream |
|
49 // ----------------------------------------------------------------------------- |
|
50 // |
|
51 TInt CLMSecurityEncrypt::EncryptL( |
|
52 TDes8& aOutput, |
|
53 const TDesC8& aInput) |
|
54 { |
|
55 TInt i; |
|
56 TUint8* ptr; |
|
57 |
|
58 ptr = const_cast<TUint8*>(aOutput.Ptr()); |
|
59 for (i = 0; i < aInput.Size(); i++) |
|
60 { |
|
61 ptr[i] = static_cast<TUint8>(aInput[i] ^ Math::Rand(iKey)); |
|
62 } |
|
63 aOutput.SetLength(aInput.Size()); |
|
64 return aInput.Size(); |
|
65 } |
|
66 |
|
67 // ----------------------------------------------------------------------------- |
|
68 // CLMSecurityEncrypt::CompleteL |
|
69 // Final encryption |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 TInt CLMSecurityEncrypt::CompleteL( |
|
73 TDes8& aOutput, |
|
74 const TDesC8& aInput) |
|
75 { |
|
76 return EncryptL(aOutput, aInput); |
|
77 } |
|