2 // Open Service Platform
3 // Copyright (c) 2012 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 FSecKeaKeyParameters.cpp
20 * @brief This header file contains the declaration of Tizen::Security::Crypto::KeaKeyParameters.
23 #include <unique_ptr.h>
24 #include <FBaseResult.h>
25 #include <FBaseErrors.h>
26 #include <FSecISecretKey.h>
27 #include <FSecSecretKey.h>
28 #include <FSecCryptoKeaKeyExchange.h>
29 #include <FSecKeaKeyParameters.h>
30 #include <FBaseSysLog.h>
32 using namespace Tizen::Base;
35 namespace Tizen { namespace Security
38 KeaKeyParameters::KeaKeyParameters(void)
40 , __pKeaKeyParametersImpl(null)
45 KeaKeyParameters::~KeaKeyParameters(void)
51 KeaKeyParameters::Construct(const Tizen::Base::ByteBuffer& primeNumber, const Tizen::Base::ByteBuffer& generatorNumber, int privateKeySize)
55 SysAssertf(__prime.GetPointer() == null && __prime.GetRemaining() == 0 && __generator.GetPointer() == null && __generator.GetRemaining() == 0,
56 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class");
58 r = __prime.Construct(primeNumber);
59 SysTryReturn(NID_SEC, !IsFailed(r), r, r, "[%s] Input prime number is not valid.", GetErrorMessage(r));
61 r = __generator.Construct(generatorNumber);
62 SysTryReturn(NID_SEC, !IsFailed(r), r, r, "[%s] Input generator number is not valid.", GetErrorMessage(r));
64 __privateKeySize = privateKeySize;
69 Tizen::Base::ByteBuffer*
70 KeaKeyParameters::GetParameterValueN(KeyParameterType paramType) const
76 std::unique_ptr<ByteBuffer> pOutput(new (std::nothrow) ByteBuffer());
77 SysTryReturn(NID_SEC, pOutput != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory.");
81 case KEY_PARAMETER_KEA_P:
82 r = pOutput->Construct(__prime);
83 SysTryReturn(NID_SEC, !IsFailed(r), null, r, "[%s] Kea prime number should be valid.", GetErrorMessage(r));
86 case KEY_PARAMETER_KEA_G:
87 r = pOutput->Construct(__generator);
88 SysTryReturn(NID_SEC, !IsFailed(r), null, r, "[%s] Kea generator number should be valid.", GetErrorMessage(r));
92 SysTryReturn(NID_SEC, false, null, E_UNSUPPORTED_TYPE, "[E_UNSUPPORTED_TYPE] The requested type is not supported");
98 return pOutput.release();
102 KeaKeyParameters::GetParameterSize(KeyParameterType paramType) const
104 SysTryReturn(NID_SEC, paramType == KEY_PARAMETER_KEA_PRIVATE_KEY_SIZE, 0, E_UNSUPPORTED_TYPE, "[E_UNSUPPORTED_TYPE] The input request is not supported.");
105 return __privateKeySize;
108 } } //Tizen::Security