2 // Copyright (c) 2013 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file FSecPkcsPkcs05Schemes.cpp
19 * @brief This is the implementation file for Pkcs05Schemes class.
21 * This header file contains the implementation of Pkcs05Schemes class.
25 #include <unique_ptr.h>
26 #include <FBaseSysLog.h>
27 #include <FBaseByteBuffer.h>
28 #include <FBaseResult.h>
29 #include <FSecPkcsPkcs05Schemes.h>
30 #include <FSecPkcsAlgorithmIdentifier.h>
31 #include <FSecPkcsPkcs05PbKdf2Parameters.h>
32 #include <FSecPkcsPkcs05PbEs2Parameters.h>
33 #include <FSecPkcsPkcs05PbMacParameters.h>
34 #include "FSecPkcs_Pkcs05SchemesImpl.h"
36 using namespace Tizen::Base;
38 namespace Tizen { namespace Security { namespace Pkcs
41 Pkcs05Schemes::Pkcs05Schemes(void)
42 : __pPkcs05SchemesImpl(null)
47 Pkcs05Schemes::~Pkcs05Schemes(void)
49 delete __pPkcs05SchemesImpl;
53 Pkcs05Schemes::Construct(const Tizen::Base::ByteBuffer& password, int derivedKeyLength)
57 SysAssertf(__pPkcs05SchemesImpl == null,
58 "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class");
60 __pPkcs05SchemesImpl = new (std::nothrow) _Pkcs05SchemesImpl();
61 SysTryReturnResult(NID_SEC_CRYPTO, __pPkcs05SchemesImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory in insufficient.");
63 r = __pPkcs05SchemesImpl->Construct(password, derivedKeyLength);
64 SysTryCatch(NID_SEC_CRYPTO, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r));
70 delete __pPkcs05SchemesImpl;
71 __pPkcs05SchemesImpl = null;
78 Pkcs05Schemes::GenerateKeyKdf2N(const Pkcs05PbKdf2Parameters& params)
84 SysAssertf(__pPkcs05SchemesImpl != null, "Not yet constructed. Reconstructor the object.");
85 std::unique_ptr< ByteBuffer > pOut(__pPkcs05SchemesImpl->GenerateKeyKdf2N(params));
86 SysTryReturn(NID_SEC_CRYPTO, pOut != null, null, GetLastResult(), "[%s] Propagated.", GetErrorMessage(r));
88 return pOut.release();
93 Pkcs05Schemes::EncryptionScheme2N(const Pkcs05PbEs2Parameters& params, const Tizen::Base::ByteBuffer& message)
99 SysAssertf(__pPkcs05SchemesImpl != null, "Not yet constructed. Reconstructor the object.");
100 std::unique_ptr< ByteBuffer > pOutBuffer(__pPkcs05SchemesImpl->EncryptionScheme2N(params, message));
101 SysTryReturn(NID_SEC_CRYPTO, pOutBuffer != null, null, GetLastResult(), "[%s] Propagated.", GetErrorMessage(r));
103 return pOutBuffer.release();
107 Pkcs05Schemes::DecryptionScheme2N(const Pkcs05PbEs2Parameters& params, const Tizen::Base::ByteBuffer& message)
109 result r = E_SUCCESS;
113 SysAssertf(__pPkcs05SchemesImpl != null, "Not yet constructed. Reconstructor the object.");
114 std::unique_ptr< ByteBuffer > pOutBuffer(__pPkcs05SchemesImpl->DecryptionScheme2N(params, message));
115 SysTryReturn(NID_SEC_CRYPTO, pOutBuffer != null, null, GetLastResult(), "[%s] Propagated.", GetErrorMessage(r));
117 return pOutBuffer.release();
121 Pkcs05Schemes::GetPbHMacN(const Pkcs05PbMacParameters& params, const Tizen::Base::ByteBuffer& message)
123 result r = E_SUCCESS;
127 SysAssertf(__pPkcs05SchemesImpl != null, "Not yet constructed. Reconstructor the object.");
128 std::unique_ptr< ByteBuffer > pOutput(__pPkcs05SchemesImpl->GetPbHMacN(params, message));
129 SysTryReturn(NID_SEC_CRYPTO, pOutput != null, null, GetLastResult(), "[%s] Propagated.", GetErrorMessage(r));
131 return pOutput.release();
136 Pkcs05Schemes::VerifyPbMac(const Pkcs05PbMacParameters& params, const Tizen::Base::ByteBuffer& message, const Tizen::Base::ByteBuffer& mac)
138 result r = E_SUCCESS;
140 SysAssertf(__pPkcs05SchemesImpl != null, "Not yet constructed. Reconstructor the object.");
141 r = __pPkcs05SchemesImpl->VerifyPbMac(params, message, mac);
142 SysTryReturn(NID_SEC_CRYPTO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r));
148 } } } // end of namespace Pkcs05