c7fb1de8a32cfeb4be543d59e252f8a02c2eda86
[platform/framework/native/appfw.git] / inc / FSecKeaKeyParameters.h
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
15 //
16
17 /**
18  * @file                FSecKeaKeyParameters.h
19  * @brief               This is the header file for the %KeaKeyParameters class.
20  *
21  * This header file contains the declarations of the %KeaKeyParameters class.
22  */
23 #ifndef _FSEC_KEA_KEY_PARAMETERS_H_
24 #define _FSEC_KEA_KEY_PARAMETERS_H_
25
26 #include <FBaseString.h>
27 #include <FBaseByteBuffer.h>
28 #include <FSecISecretKey.h>
29 #include <FSecCryptoTypes.h>
30 #include <FSecIKeyParameters.h>
31
32
33 namespace Tizen { namespace Security
34 {
35
36 /**
37  *      @class          KeaKeyParameters
38  *      @brief          This class provides parameters for a Key Exchange mechanism using the KEA algorithm.
39  *
40  * @since               2.0
41  *
42  *      The %KeaKeyParameters class provides a subset of domain parameters for the KEA algorithm.
43  *  For example, a prime number and a generator value are used to exchange keys between the two parties. @n
44  *
45  * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/security/key_exchange_algorithm.htm">Key exchanging</a>.
46  *
47  *  @see        IKeyParameters
48  *
49  *  The following example demonstrates how to use the %KeaKeyParameters class.
50  *
51  *  @code
52  *      void GetParameterExample(void)
53  *      {
54  *              result r = E_SUCCESS;
55  *              KeyPairGenerator *pKeyPairGen = null;
56  *              IKeyParameters *pKeyParams = null;
57  *
58  *              int size = 1024;
59  *              int nResult = 0;
60  *              ByteBuffer* pResult = null;
61  *
62  *              // Generates the key.
63  *              pKeyPairGen = new KeyPairGenerator();
64  *              if (null == pKeyPairGen)
65  *              {
66  *                      goto CATCH;
67  *              }
68  *
69  *              r = pKeyPairGen->Construct(size, "KEA");
70  *              if (IsFailed(r))
71  *              {
72  *                      goto CATCH;
73  *              }
74  *
75  *              pKeyParams = pKeyPairGen->GenerateKeyParametersN();
76  *              if (null == pKeyParams)
77  *              {
78  *                      goto CATCH;
79  *              }
80  *
81  *              pResult = pKeyParams->GetParameterValueN(KEY_PARAMETER_KEA_P);
82  *              if (null == pResult)
83  *              {
84  *                      goto CATCH;
85  *              }
86  *
87  *              nResult  = pKeyParams->GetParameterSize(KEY_PARAMETER_KEA_PRIVATE_KEY_SIZE);
88  *
89  *      CATCH:
90  *              delete pKeyPairGen;
91  *              delete pResult;
92  *              delete pKeyParams;
93  *
94  *      }
95  * @endcode
96  */
97
98 class _OSP_EXPORT_ KeaKeyParameters
99         : public IKeyParameters
100         , public Tizen::Base::Object
101 {
102
103 public:
104         /**
105          * The object is not fully constructed after this constructor is called. For full construction, @n
106          * the Construct() method must be called right after calling this constructor.
107          *
108          *      @since      2.0
109          */
110         KeaKeyParameters(void);
111
112         /**
113          * This destructor overrides Tizen::Base::Object::~Object().
114          *
115          *      @since      2.0
116          */
117         virtual ~KeaKeyParameters(void);
118
119         /**
120          *      Constructs and initializes an instance of %KeaKeyParameters with the specified key parameters.
121          *
122          *      @since          2.0
123          *
124          *      @return         An error code
125          *      @param[in]      primeNumber                             The prime number to instantiate
126          *      @param[in]      generatorNumber                 The generator value to instantiate
127          *      @param[in]      privateKeySize                  The size of the private key to instantiate
128          *      @exception      E_SUCCESS                               The method is successful.
129          *      @exception      E_INVALID_ARG                   A specified input parameter is invalid.
130          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
131          *
132          */
133         result Construct(const Tizen::Base::ByteBuffer& primeNumber, const Tizen::Base::ByteBuffer& generatorNumber, int privateKeySize);
134
135         /**
136          *      Gets the Tizen::Base::ByteBuffer value of parameters for the specified key parameter type.
137          *
138          *      @since          2.0
139          *
140          *      @return         A pointer to the Tizen::Base::ByteBuffer class that contains the parameter values, @n
141          *                              else @c null if an error occurs
142          *      @param[in]      paramType                       The parameter type @n
143          *                                                                              For example, @c KEY_PARAMETER_KEA_P.
144          *      @exception      E_SUCCESS                       The method is successful.
145          *      @exception      E_OUT_OF_MEMORY         The memory is insufficient.
146          *      @exception      E_UNSUPPORTED_TYPE      The specified @c paramType is not supported.
147          *      @remarks        The specific error code can be accessed using the GetLastResult() method.
148          */
149         virtual Tizen::Base::ByteBuffer* GetParameterValueN(KeyParameterType paramType) const;
150
151         /**
152          *      Gets the size of the private key component.
153          *
154          *      @since          2.0
155          *
156          *      @return         The size of the private key component
157          *      @param[in]      paramType                       The parameter type @n
158          *                                                                      For example, @c KEY_PARAMETER_PRIVATE_KEY_SIZE.
159          *      @exception      E_SUCCESS                       The method is successful.
160          *      @exception      E_UNSUPPORTED_TYPE      The specified @c paramType is not supported.
161          *      @remarks        The specific error code can be accessed using the GetLastResult() method.
162          */
163         virtual int GetParameterSize(KeyParameterType paramType) const;
164
165 private:
166
167         //
168         // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
169         //
170         // @since 2.0
171         //
172         KeaKeyParameters(const KeaKeyParameters& rhs);
173
174         //
175         // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
176         //
177         // @since 2.0
178         //
179         KeaKeyParameters& operator =(const KeaKeyParameters& rhs);
180
181 private:
182         Tizen::Base::ByteBuffer __prime;
183         Tizen::Base::ByteBuffer __generator;
184         int __privateKeySize;
185
186         class _KeaKeyParametersImpl* __pKeaKeyParametersImpl;
187         friend class _KeaKeyParametersImpl;
188
189 }; //KeaKeyParameter
190
191 } } //Tizen::Security
192
193 #endif //_FSEC_KEA_KEY_EXCHANGE_PARAMS_H