2 // Open Service Platform
3 // Copyright (c) 2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FSecPkcsPkcs05Schemes.cpp
20 * @brief This is the implementation file for Pkcs05Schemes class.
22 * This header file contains the implementation of Pkcs05Schemes class.
26 #include <unique_ptr.h>
27 #include <FBaseSysLog.h>
28 #include <FBaseByteBuffer.h>
29 #include <FBaseResult.h>
30 #include <FSecPkcsPkcs05Schemes.h>
31 #include <FSecPkcsAlgorithmIdentifier.h>
32 #include <FSecPkcsPkcs05PbKdf2Parameters.h>
33 #include <FSecPkcsPkcs05PbEs2Parameters.h>
34 #include <FSecPkcsPkcs05PbMacParameters.h>
35 #include "FSecPkcs_Pkcs05SchemesImpl.h"
37 using namespace Tizen::Base;
39 namespace Tizen { namespace Security { namespace Pkcs
42 Pkcs05Schemes::Pkcs05Schemes(void)
43 : __pPkcs05SchemesImpl(null)
48 Pkcs05Schemes::~Pkcs05Schemes(void)
54 Pkcs05Schemes::Construct(const Tizen::Base::ByteBuffer& password, int derivedKeyLength)
58 SysAssertf(__pPkcs05SchemesImpl == null,
59 "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class");
61 __pPkcs05SchemesImpl = new (std::nothrow) _Pkcs05SchemesImpl();
62 SysTryReturnResult(NID_SEC_CRYPTO, __pPkcs05SchemesImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory in insufficient.");
64 r = __pPkcs05SchemesImpl->Construct(password, derivedKeyLength);
65 SysTryCatch(NID_SEC_CRYPTO, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r));
71 delete __pPkcs05SchemesImpl;
72 __pPkcs05SchemesImpl = null;
79 Pkcs05Schemes::GenerateKeyKdf2N(const Pkcs05PbKdf2Parameters& params)
85 SysAssertf(__pPkcs05SchemesImpl != null, "Not yet constructed. Reconstructor the object.");
86 std::unique_ptr< ByteBuffer > pOut(__pPkcs05SchemesImpl->GenerateKeyKdf2N(params));
87 SysTryReturn(NID_SEC_CRYPTO, pOut != null, null, GetLastResult(), "[%s] Propagated.", GetErrorMessage(r));
89 return pOut.release();
94 Pkcs05Schemes::EncryptionScheme2N(const Pkcs05PbEs2Parameters& params, const Tizen::Base::ByteBuffer& message)
100 SysAssertf(__pPkcs05SchemesImpl != null, "Not yet constructed. Reconstructor the object.");
101 std::unique_ptr< ByteBuffer > pOutBuffer(__pPkcs05SchemesImpl->EncryptionScheme2N(params, message));
102 SysTryReturn(NID_SEC_CRYPTO, pOutBuffer != null, null, GetLastResult(), "[%s] Propagated.", GetErrorMessage(r));
104 return pOutBuffer.release();
108 Pkcs05Schemes::DecryptionScheme2N(const Pkcs05PbEs2Parameters& params, const Tizen::Base::ByteBuffer& message)
110 result r = E_SUCCESS;
114 SysAssertf(__pPkcs05SchemesImpl != null, "Not yet constructed. Reconstructor the object.");
115 std::unique_ptr< ByteBuffer > pOutBuffer(__pPkcs05SchemesImpl->DecryptionScheme2N(params, message));
116 SysTryReturn(NID_SEC_CRYPTO, pOutBuffer != null, null, GetLastResult(), "[%s] Propagated.", GetErrorMessage(r));
118 return pOutBuffer.release();
122 Pkcs05Schemes::GetPbHMacN(const Pkcs05PbMacParameters& params, const Tizen::Base::ByteBuffer& message)
124 result r = E_SUCCESS;
128 SysAssertf(__pPkcs05SchemesImpl != null, "Not yet constructed. Reconstructor the object.");
129 std::unique_ptr< ByteBuffer > pOutput(__pPkcs05SchemesImpl->GetPbHMacN(params, message));
130 SysTryReturn(NID_SEC_CRYPTO, pOutput != null, null, GetLastResult(), "[%s] Propagated.", GetErrorMessage(r));
132 return pOutput.release();
137 Pkcs05Schemes::VerifyPbMac(const Pkcs05PbMacParameters& params, const Tizen::Base::ByteBuffer& message, const Tizen::Base::ByteBuffer& mac)
139 result r = E_SUCCESS;
141 SysAssertf(__pPkcs05SchemesImpl != null, "Not yet constructed. Reconstructor the object.");
142 r = __pPkcs05SchemesImpl->VerifyPbMac(params, message, mac);
143 SysTryReturn(NID_SEC_CRYPTO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r));
149 } } } // end of namespace Pkcs05