2 // Copyright (c) 2012 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 FSecKeaKeyParameters.cpp
19 * @brief This header file contains the declaration of Tizen::Security::Crypto::KeaKeyParameters.
22 #include <unique_ptr.h>
23 #include <FBaseResult.h>
24 #include <FBaseErrors.h>
25 #include <FSecISecretKey.h>
26 #include <FSecSecretKey.h>
27 #include <FSecCryptoKeaKeyExchange.h>
28 #include <FSecKeaKeyParameters.h>
29 #include <FBaseSysLog.h>
31 using namespace Tizen::Base;
34 namespace Tizen { namespace Security
37 KeaKeyParameters::KeaKeyParameters(void)
39 , __pKeaKeyParametersImpl(null)
44 KeaKeyParameters::~KeaKeyParameters(void)
50 KeaKeyParameters::Construct(const Tizen::Base::ByteBuffer& primeNumber, const Tizen::Base::ByteBuffer& generatorNumber, int privateKeySize)
54 SysAssertf(__prime.GetPointer() == null && __prime.GetRemaining() == 0 && __generator.GetPointer() == null && __generator.GetRemaining() == 0,
55 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class");
57 r = __prime.Construct(primeNumber);
58 SysTryReturn(NID_SEC, !IsFailed(r), r, r, "[%s] Input prime number is not valid.", GetErrorMessage(r));
60 r = __generator.Construct(generatorNumber);
61 SysTryReturn(NID_SEC, !IsFailed(r), r, r, "[%s] Input generator number is not valid.", GetErrorMessage(r));
63 __privateKeySize = privateKeySize;
68 Tizen::Base::ByteBuffer*
69 KeaKeyParameters::GetParameterValueN(KeyParameterType paramType) const
75 std::unique_ptr<ByteBuffer> pOutput(new (std::nothrow) ByteBuffer());
76 SysTryReturn(NID_SEC, pOutput != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory.");
80 case KEY_PARAMETER_KEA_P:
81 r = pOutput->Construct(__prime);
82 SysTryReturn(NID_SEC, !IsFailed(r), null, r, "[%s] Kea prime number should be valid.", GetErrorMessage(r));
85 case KEY_PARAMETER_KEA_G:
86 r = pOutput->Construct(__generator);
87 SysTryReturn(NID_SEC, !IsFailed(r), null, r, "[%s] Kea generator number should be valid.", GetErrorMessage(r));
91 SysTryReturn(NID_SEC, false, null, E_UNSUPPORTED_TYPE, "[E_UNSUPPORTED_TYPE] The requested type is not supported");
97 return pOutput.release();
101 KeaKeyParameters::GetParameterSize(KeyParameterType paramType) const
103 SysTryReturn(NID_SEC, paramType == KEY_PARAMETER_KEA_PRIVATE_KEY_SIZE, 0, E_UNSUPPORTED_TYPE, "[E_UNSUPPORTED_TYPE] The input request is not supported.");
104 return __privateKeySize;
107 } } //Tizen::Security