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 &wrappingKey,
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 getData(const RawBuffer &dataId,
77 void destroyData(const RawBuffer &dataId);
79 void destroyKey(const RawBuffer &key);
81 RawBuffer symmetricEncrypt(
84 const CryptoAlgorithm &alg,
85 const RawBuffer &data);
87 RawBuffer symmetricDecrypt(
90 const CryptoAlgorithm &alg,
91 const RawBuffer &cipher);
93 RawBuffer asymmetricEncrypt(
96 const CryptoAlgorithm &alg,
97 const RawBuffer &data);
99 RawBuffer asymmetricDecrypt(
100 const RawBuffer &key,
102 const CryptoAlgorithm &alg,
103 const RawBuffer &cipher);
105 BufferPair encryptDataAesGcm(const RawBuffer &key,
109 const RawBuffer &data,
110 const RawBuffer &aad = RawBuffer());
112 RawBuffer decryptDataAesGcm(const RawBuffer &key,
115 const RawBuffer &tag,
116 const RawBuffer &data,
117 const RawBuffer &aad = RawBuffer());
119 RawBuffer sign(const RawBuffer &pkey,
121 const CryptoAlgorithm &alg,
122 const RawBuffer &message);
124 int verify(const RawBuffer &pkey,
126 const CryptoAlgorithm &alg,
127 const RawBuffer &message,
128 const RawBuffer &signature);
130 void deriveECDH(const RawBuffer &prvKey,
131 const Pwd &prvKeyPwd,
132 const RawBuffer &pubKey,
133 const Password &secretPwd,
134 const RawBuffer &secretPwdIV,
135 RawBuffer &secretTag,
136 const RawBuffer &secretHash);
138 void deriveKBKDF(const RawBuffer &secret,
139 const CryptoAlgorithm &alg,
140 const Password &keyPwd,
141 const RawBuffer &keyPwdIV,
143 const RawBuffer &keyHash);
144 } // namespace Internals
146 } // namespace Crypto