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 FSecCryptoISignature.h
19 * @brief This is the header file for the %ISignature interface.
21 * This header file contains the declarations of the %ISignature interface.
23 #ifndef _FSEC_CRYPTO_ISIGNATURE_H_
24 #define _FSEC_CRYPTO_ISIGNATURE_H_
26 #include <FBaseString.h>
27 #include <FBaseByteBuffer.h>
30 namespace Tizen { namespace Security { namespace Crypto
34 * @interface ISignature
35 * @brief This interface provides methods for a digital signature algorithm.
39 * The %ISignature interface provides the functionality of a digital signature algorithm. @n
41 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/security/ciphers.htm">Ciphers</a>. @n
43 * The following example demonstrates how to use the %ISignature interface.
48 * MyClass::TestSignatureSample(void)
50 * result r = E_FAILURE;
51 * ISignature *pSignature = null;
52 * IKeyPairGenerator *pKeyPairGen = null;
53 * KeyPair *pKeyPair = null;
54 * IPrivateKey *pPriKey = null;
55 * IPublicKey *pPubKey = null;
57 * ByteBuffer *pOutput = null;
58 * ByteBuffer keyBytes;
60 * byte pArray[] = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P'};
64 * r = input.Construct(16);
65 * r = input.SetArray(pArray, 0, 16);
68 * pSignature = new RsaSignature();
69 * if (pSignature == null)
74 * // Generates the key.
75 * pKeyPairGen = new KeyPairGenerator();
76 * if (pKeyPairGen == null)
81 * r = pKeyPairGen->Construct(size);
87 * pKeyPair = pKeyPairGen->GenerateKeyPairN();
88 * if (pKeyPair == null)
93 * pPubKey = pKeyPair->GetPublicKey();
94 * if (pPubKey == null)
99 * pPriKey = pKeyPair->GetPrivateKey();
100 * if (pPriKey == null)
105 * r = pSignature->SetPrivateKey(*pPriKey);
111 * pOutput = pSignature->SignN(input);
112 * if (pOutput == null)
114 * r = GetLastResult();
118 * r = pSignature->SetPublicKey(*pPubKey);
124 * res = pSignature->Verify(input, *pOutput);
127 * r = GetLastResult();
136 * delete pKeyPairGen;
143 class _OSP_EXPORT_ ISignature
148 * This polymorphic destructor should be overridden if required. @n
149 * This way, the destructors of the derived classes are called when the destructor of this interface is called.
153 virtual ~ISignature(void) {}
156 * Sets the asymmetric private key for signature.
160 * @return An error code
161 * @param[in] key An instance of IKey
162 * @exception E_SUCCESS The method is successful.
163 * @exception E_INVALID_ARG The specified @c key is invalid.
164 * @exception E_OUT_OF_MEMORY The memory is insufficient.
166 virtual result SetPrivateKey(const Tizen::Security::IKey& key) = 0;
169 * Sets the asymmetric public key for verification.
173 * @return An error code
174 * @param[in] key An instance of IKey
175 * @exception E_SUCCESS The method is successful.
176 * @exception E_INVALID_ARG The specified @c key is invalid.
177 * @exception E_OUT_OF_MEMORY The memory is insufficient.
179 virtual result SetPublicKey(const Tizen::Security::IKey& key) = 0;
186 * @return A pointer to the Tizen::Base::ByteBuffer instance that contains the output, @n
187 * else @c null if an error occurs
188 * @param[in] input An instance of Tizen::Base::ByteBuffer
189 * @exception E_SUCCESS The method is successful.
190 * @exception E_INVALID_ARG The input Tizen::Base::ByteBuffer is empty or contains invalid data.
191 * @exception E_OUT_OF_MEMORY The memory is insufficient.
192 * @exception E_KEY_NOT_FOUND The specified key is not found.
193 * @exception E_SYSTEM Either of the following conditions has occurred:
194 * - A system error has occurred.
195 * - The method has failed to operate with the openssl library.
196 * - The Tizen::Base::ByteBuffer operation has failed.
198 virtual Tizen::Base::ByteBuffer* SignN(const Tizen::Base::ByteBuffer& input) = 0;
201 * Verifies the specified data. @n
202 * The verification is done by comparing the @c signedData to the signature created by the @c data.
206 * @return @c true if the signed data is correct, @n
208 * @param[in] data An instance of Tizen::Base::ByteBuffer that contains the original data
209 * @param[in] signedData An instance of Tizen::Base::ByteBuffer that contains the signed data
210 * @exception E_SUCCESS The method is successful.
211 * @exception E_INVALID_ARG The input Tizen::Base::ByteBuffer is empty or contains invalid data.
212 * @exception E_OUT_OF_MEMORY The memory is insufficient.
213 * @exception E_KEY_NOT_FOUND The specified key is not found.
214 * @exception E_SYSTEM Either of the following conditions has occurred:
215 * - A system error has occurred.
216 * - The method has failed to operate with the openssl library.
217 * - The Tizen::Base::ByteBuffer operation has failed.
219 virtual bool Verify(const Tizen::Base::ByteBuffer& data, const Tizen::Base::ByteBuffer& signedData) = 0;
223 // This method is for internal use only. Using this method can cause behavioral, security-related,
224 // and consistency-related issues in the application.
226 // This method is reserved and may change its name at any time without prior notice.
230 virtual void ISignature_Reserved1(void) {}
234 } } } //Tizen::Security::Crypto
236 #endif //_FSEC_CRYPTO_ISIGNATURE_H_