|
1 /* |
|
2 * Copyright (c) 2008 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: Implementation of STSCipher |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "stscipher.h" |
|
21 #include "logger.h" |
|
22 |
|
23 namespace java |
|
24 { |
|
25 namespace satsa |
|
26 { |
|
27 |
|
28 |
|
29 STSCipher::STSCipher():mTransformation(0), mIV(0), miv_length(0), mKey(0), |
|
30 mKey_length(0) |
|
31 { |
|
32 |
|
33 } |
|
34 |
|
35 |
|
36 STSCipher::~STSCipher() |
|
37 { |
|
38 delete mTransformation; |
|
39 mTransformation = 0; |
|
40 delete mIV; |
|
41 mIV = 0; |
|
42 delete mKey; |
|
43 mKey = 0; |
|
44 } |
|
45 |
|
46 // Sets the transformation for this cipher object. |
|
47 void STSCipher::SetTransformation(STSTransformation* aTransformation) |
|
48 { |
|
49 LOG(ESATSA, EInfo, "STSCipher::SetTransformation+"); |
|
50 // Delete existing transformation object. |
|
51 delete mTransformation; |
|
52 |
|
53 // Take the ownership. |
|
54 mTransformation = aTransformation; |
|
55 LOG(ESATSA, EInfo, "STSCipher::SetTransformation--"); |
|
56 } |
|
57 |
|
58 // Initializes the cipher. |
|
59 jint STSCipher::Init(JNIEnv* aJni, const TCipherMode aMode, |
|
60 const jstring aKeyAlgorithm, const jstring aKeyFormat, |
|
61 const jbyteArray aKeyEncoded) |
|
62 { |
|
63 LOG(ESATSA, EInfo, "STSCipher::Init+"); |
|
64 // Function return value |
|
65 jint retVal = 0; |
|
66 |
|
67 // Call the ciphers specific initialize function. |
|
68 retVal = DoInit(aJni, aMode, aKeyAlgorithm, aKeyFormat, aKeyEncoded, NULL); |
|
69 |
|
70 if (retVal == 0) |
|
71 { |
|
72 // Set the mode of the initialized cipher |
|
73 mMode = aMode; |
|
74 } // end if |
|
75 |
|
76 // return the return value |
|
77 LOG(ESATSA, EInfo, "STSCipher::Init--"); |
|
78 return retVal; |
|
79 } |
|
80 |
|
81 //Initialize the cipher |
|
82 jint STSCipher::Init(JNIEnv* aJni, const TCipherMode aMode, |
|
83 const jstring aKeyAlgorithm, const jstring aKeyFormat, |
|
84 const jbyteArray aKeyEncoded, const jbyteArray aParams) |
|
85 { |
|
86 LOG(ESATSA, EInfo, "STSCipher::Init with Params+"); |
|
87 // Function return value |
|
88 jint retVal = 0; |
|
89 |
|
90 // Call the ciphers specific initialize function. |
|
91 retVal = DoInit(aJni, aMode, aKeyAlgorithm, aKeyFormat, aKeyEncoded, |
|
92 aParams); |
|
93 |
|
94 if (retVal == 0) |
|
95 { |
|
96 // Set the mode of the initialized cipher |
|
97 mMode = aMode; |
|
98 } // end if |
|
99 |
|
100 // return the return value |
|
101 LOG(ESATSA, EInfo, "STSCipher::Init with Params--"); |
|
102 return retVal; |
|
103 } |
|
104 |
|
105 // Function to retreive the IV of the cipher. |
|
106 const unsigned char* STSCipher::IV(int* length) const |
|
107 { |
|
108 LOG(ESATSA, EInfo, "STSCipher::IV+"); |
|
109 // return IV if it is set or generated, otherwise return NULL. |
|
110 if (length) |
|
111 { |
|
112 *length = miv_length; |
|
113 } |
|
114 LOG(ESATSA, EInfo, "STSCipher::IV--"); |
|
115 return mIV; |
|
116 |
|
117 } |
|
118 } // namespace satsa |
|
119 } // namespace java |
|
120 |