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