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 the functionality of 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. This way, the destructors of the derived classes @n
149 * are called when the destructor of this interface is called.
153 virtual ~ISignature(void) {}
156 * Sets an 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 an 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 A system error has occurred. @n
194 * The method has failed to operate with the openssl library, or
195 * the Tizen::Base::ByteBuffer operation has failed.
197 virtual Tizen::Base::ByteBuffer* SignN(const Tizen::Base::ByteBuffer& input) = 0;
200 * Verifies the data. @n
201 * The verification is done by comparing the @c signedData to the signature created by the @c data.
205 * @return @c true if the signed data is correct, @n
207 * @param[in] data An instance of Tizen::Base::ByteBuffer that contains the original data
208 * @param[in] signedData An instance of Tizen::Base::ByteBuffer that contains the signed data
209 * @exception E_SUCCESS The method is successful.
210 * @exception E_INVALID_ARG The input Tizen::Base::ByteBuffer is empty or contains invalid data.
211 * @exception E_OUT_OF_MEMORY The memory is insufficient.
212 * @exception E_KEY_NOT_FOUND The specified key is not found.
213 * @exception E_SYSTEM A system error has occurred. @n
214 * The method has failed to operate with the openssl library, or
215 * the Tizen::Base::ByteBuffer operation has failed.
217 virtual bool Verify(const Tizen::Base::ByteBuffer& data, const Tizen::Base::ByteBuffer& signedData) = 0;
221 // This method is for internal use only. Using this method can cause behavioral, security-related,
222 // and consistency-related issues in the application.
224 // This method is reserved and may change its name at any time without prior notice.
228 virtual void ISignature_Reserved1(void) {}
232 } } } //Tizen::Security::Crypto
234 #endif //_FSEC_CRYPTO_ISIGNATURE_H_