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 FSecDhKeyParameters.cpp
20 * @brief This header file contains the declaration of Tizen::Security::Crypto::DhKeyParameters.
23 #include <unique_ptr.h>
24 #include <FBaseResult.h>
25 #include <FBaseErrors.h>
26 #include <FSecISecretKey.h>
27 #include <FSecSecretKey.h>
28 #include <FSecDhKeyParameters.h>
29 #include <FSecCryptoDhKeyExchange.h>
30 #include <FBaseSysLog.h>
32 using namespace Tizen::Base;
35 namespace Tizen { namespace Security
38 DhKeyParameters::DhKeyParameters(void)
40 , __pDhKeyParametersImpl(null)
45 DhKeyParameters::~DhKeyParameters(void)
51 DhKeyParameters::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 DhKeyParameters::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_DH_P:
82 r = pOutput->Construct(__prime);
83 SysTryReturn(NID_SEC, !IsFailed(r), null, r, "[%s] Dh prime number should be valid.", GetErrorMessage(r));
86 case KEY_PARAMETER_DH_G:
87 r = pOutput->Construct(__generator);
88 SysTryReturn(NID_SEC, !IsFailed(r), null, r, "[%s] Dh 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");
97 return pOutput.release();
101 DhKeyParameters::GetParameterSize(KeyParameterType paramType) const
103 SysTryReturn(NID_SEC, paramType == KEY_PARAMETER_DH_PRIVATE_KEY_SIZE, 0, E_UNSUPPORTED_TYPE, "[E_UNSUPPORTED_TYPE] The input request is not supported.");
104 return __privateKeySize;
107 } } //Tizen::Security