a53b3b4761bf3bf8974422e5b065e9551d1ddd64
[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 // During initialization, FIPS_MODE and the entropy source are set
42 // and system certificates are loaded to memory.
43 //    FIPS_MODE - ON, OFF(Default)
44 //    entropy source - /dev/random,/dev/urandom(Default)
45 int initialize();
46
47 void createKeyPairRSA(const int size,
48     KeyImpl &createdPrivateKey,
49     KeyImpl &createdPublicKey);
50
51 void createKeyPairDSA(const int size,
52     KeyImpl &createdPrivateKey,
53     KeyImpl &createdPublicKey);
54
55 void createKeyPairECDSA(ElipticCurve type1,
56     KeyImpl &createdPrivateKey,
57     KeyImpl &createdPublicKey);
58
59 RawBuffer sign(EVP_PKEY *pkey,
60     const CryptoAlgorithm &alg,
61     const RawBuffer &message);
62
63 int verify(EVP_PKEY *pkey,
64     const CryptoAlgorithm &alg,
65     const RawBuffer &message,
66     const RawBuffer &signature);
67
68 const EVP_MD *getMdAlgo(const HashAlgorithm hashAlgo);
69 int getRsaPadding(const RSAPaddingAlgorithm padAlgo);
70
71 RawBuffer signMessage(EVP_PKEY *privKey,
72     const RawBuffer &message,
73     const int rsa_padding);
74
75 RawBuffer digestSignMessage(EVP_PKEY *privKey,
76     const RawBuffer &message,
77     const EVP_MD *md_algo,
78     const int rsa_padding);
79
80 int verifyMessage(EVP_PKEY *pubKey,
81     const RawBuffer &message,
82     const RawBuffer &signature,
83     const int rsa_padding);
84
85 int digestVerifyMessage(EVP_PKEY *pubKey,
86     const RawBuffer &message,
87     const RawBuffer &signature,
88     const EVP_MD *md_algo,
89     const int rsa_padding);
90
91 } // namespace Internals
92 } // namespace SW
93 } // namespace Crypto
94 } // namespace CKM
95