49ce47fb742d09a5f4df774787c9bf16d3ad474b
[platform/core/security/key-manager.git] / src / manager / crypto / sw-backend / internals.h
1 /*
2  *  Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
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  * @file       internals.h
18  * @author
19  * @version    1.0
20  */
21 #pragma once
22
23 #include <key-impl.h>
24 #include <certificate-impl.h>
25 #include <ckm/ckm-type.h>
26 #include <openssl/evp.h>
27
28 #define EVP_SUCCESS 1   // DO NOTCHANGE THIS VALUE
29 #define EVP_FAIL    0   // DO NOTCHANGE THIS VALUE
30
31 #define CKM_CRYPTO_INIT_SUCCESS 1
32 #define CKM_CRYPTO_CREATEKEY_SUCCESS 2
33 #define CKM_VERIFY_CHAIN_SUCCESS 5
34 #define NOT_DEFINED -1
35
36 namespace CKM {
37 namespace Crypto {
38 namespace SW {
39 namespace Internals {
40
41 int initialize();
42
43 void createKeyPairRSA(const int size,
44     KeyImpl &createdPrivateKey,
45     KeyImpl &createdPublicKey);
46
47 void createKeyPairDSA(const int size,
48     KeyImpl &createdPrivateKey,
49     KeyImpl &createdPublicKey);
50
51 void createKeyPairECDSA(ElipticCurve type1,
52     KeyImpl &createdPrivateKey,
53     KeyImpl &createdPublicKey);
54
55 RawBuffer sign(EVP_PKEY *pkey,
56     const CryptoAlgorithm &alg,
57     const RawBuffer &message);
58
59 int verify(EVP_PKEY *pkey,
60     const CryptoAlgorithm &alg,
61     const RawBuffer &message,
62     const RawBuffer &signature);
63
64 const EVP_MD *getMdAlgo(const HashAlgorithm hashAlgo);
65 int getRsaPadding(const RSAPaddingAlgorithm padAlgo);
66
67 RawBuffer signMessage(EVP_PKEY *privKey,
68     const RawBuffer &message,
69     const int rsa_padding);
70
71 RawBuffer digestSignMessage(EVP_PKEY *privKey,
72     const RawBuffer &message,
73     const EVP_MD *md_algo,
74     const int rsa_padding);
75
76 int verifyMessage(EVP_PKEY *pubKey,
77     const RawBuffer &message,
78     const RawBuffer &signature,
79     const int rsa_padding);
80
81 int digestVerifyMessage(EVP_PKEY *pubKey,
82     const RawBuffer &message,
83     const RawBuffer &signature,
84     const EVP_MD *md_algo,
85     const int rsa_padding);
86
87 } // namespace Internals
88 } // namespace SW
89 } // namespace Crypto
90 } // namespace CKM
91