2 * Copyright (c) 2017 - 2019 Samsung Electronics Co., Ltd All Rights Reserved
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 * @author Krzysztof Dynowski (k.dynowski@samsung.com)
19 * @author Lukasz Kostyra (l.kostyra@samsung.com)
24 #include <ckm/ckm-type.h>
25 #include <data-type.h>
26 #include <tz-backend/obj.h>
27 #include <generic-backend/gstore.h>
34 using DataPair = std::pair<Data, Data>;
35 using BufferPair = std::pair<RawBuffer, RawBuffer>;
37 // encryption schema + buffer pair
38 using KeyIdPair = std::pair<int, RawBuffer>;
40 RawBuffer generateIV();
42 AlgoType generateAKey(const CryptoAlgorithm &alg,
43 const Password &pubPwd,
44 const Password &privPwd,
45 const RawBuffer &pubPwdIv,
46 const RawBuffer &privPwdIv,
49 const RawBuffer &hashPriv,
50 const RawBuffer &hashPub);
52 void generateSKey(const CryptoAlgorithm &alg,
56 const RawBuffer &hash);
58 void importData(const Data &key,
59 const EncryptionParams &encData,
61 const RawBuffer &pwdIV,
63 const RawBuffer &hash);
65 void importWrappedKey(const RawBuffer &wrappingKeyId,
66 const Pwd &wrappingKeyPwd,
67 const CryptoAlgorithm &alg,
68 const Data &encryptedKey,
69 const Password &encryptedKeyPassword,
70 const RawBuffer &encryptedKeyIV,
71 RawBuffer &encryptedKeyTag,
72 const RawBuffer &encryptedKeyId);
74 RawBuffer exportWrappedKey(const RawBuffer &wrappingKeyId,
75 const Pwd &wrappingKeyPwd,
76 const CryptoAlgorithm &alg,
77 const RawBuffer &keyToWrapId,
78 const Pwd &keyToWrapPwd);
80 RawBuffer getData(const RawBuffer &dataId,
83 void destroyData(const RawBuffer &dataId);
85 void destroyKey(const RawBuffer &keyId);
87 RawBuffer symmetricEncrypt(
88 const RawBuffer &keyId,
90 const CryptoAlgorithm &alg,
91 const RawBuffer &data);
93 RawBuffer symmetricDecrypt(
94 const RawBuffer &keyId,
96 const CryptoAlgorithm &alg,
97 const RawBuffer &cipher);
99 RawBuffer asymmetricEncrypt(
100 const RawBuffer &keyId,
102 const CryptoAlgorithm &alg,
103 const RawBuffer &data);
105 RawBuffer asymmetricDecrypt(
106 const RawBuffer &keyId,
108 const CryptoAlgorithm &alg,
109 const RawBuffer &cipher);
111 BufferPair encryptDataAesGcm(const RawBuffer &keyId,
115 const RawBuffer &data,
116 const RawBuffer &aad = RawBuffer());
118 RawBuffer decryptDataAesGcm(const RawBuffer &keyId,
121 const RawBuffer &tag,
122 const RawBuffer &data,
123 const RawBuffer &aad = RawBuffer());
125 uint32_t initCipher(const RawBuffer &keyId,
127 const CryptoAlgorithm &alg,
130 void addAAD(uint32_t opId,
131 const RawBuffer &aad);
133 RawBuffer updateCipher(uint32_t opId,
134 const RawBuffer &data);
136 RawBuffer finalizeCipher(uint32_t opId,
137 const RawBuffer &data);
139 RawBuffer sign(const RawBuffer &pkeyId,
141 const CryptoAlgorithm &alg,
142 const RawBuffer &message);
144 int verify(const RawBuffer &pkeyId,
146 const CryptoAlgorithm &alg,
147 const RawBuffer &message,
148 const RawBuffer &signature);
150 void deriveECDH(const RawBuffer &prvKeyId,
151 const Pwd &prvKeyPwd,
152 const RawBuffer &pubKey,
153 const Password &secretPwd,
154 const RawBuffer &secretPwdIV,
155 RawBuffer &secretTag,
156 const RawBuffer &secretHash);
158 void deriveKBKDF(const RawBuffer &secretId,
159 const CryptoAlgorithm &alg,
160 const Password &keyPwd,
161 const RawBuffer &keyPwdIV,
163 const RawBuffer &keyHash);
164 } // namespace Internals
166 } // namespace Crypto