blob: b90d2bc9a7e9e5c0b53d815e9fce2430a7fe2027 [file] [log] [blame]
Thai Duongfabacaf2015-03-25 20:14:57 -07001/*
2 * Copyright 2015 The Android Open Source Project
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#ifndef SYSTEM_KEYMASTER_KDF_H_
18#define SYSTEM_KEYMASTER_KDF_H_
19
Quan Nguyenf7538e02015-05-21 00:49:11 -070020#include <hardware/keymaster_defs.h>
21#include <keymaster/android_keymaster_utils.h>
Thai Duongfabacaf2015-03-25 20:14:57 -070022#include <keymaster/serializable.h>
23
Quan Nguyenf7538e02015-05-21 00:49:11 -070024#include <UniquePtr.h>
25
Thai Duongfabacaf2015-03-25 20:14:57 -070026namespace keymaster {
27
Quan Nguyenf7538e02015-05-21 00:49:11 -070028/**
29 * A base class for wrapping different key derivation functions.
30 */
Thai Duongfabacaf2015-03-25 20:14:57 -070031class Kdf {
32 public:
Quan Nguyenf7538e02015-05-21 00:49:11 -070033 virtual ~Kdf() { memset_s(secret_key_.get(), 0, secret_key_len_); };
34 Kdf();
35 bool Init(keymaster_digest_t digest_type, const uint8_t* secret, size_t secret_len,
36 const uint8_t* salt, size_t salt_len);
37 virtual bool GenerateKey(const uint8_t* info, size_t info_len, uint8_t* output,
38 size_t output_len) = 0;
Thai Duongfabacaf2015-03-25 20:14:57 -070039
Quan Nguyenf7538e02015-05-21 00:49:11 -070040 protected:
41 bool Uint32ToBigEndianByteArray(uint32_t number, uint8_t* output);
42 UniquePtr<uint8_t[]> secret_key_;
43 size_t secret_key_len_;
44 UniquePtr<uint8_t[]> salt_;
45 size_t salt_len_;
46 bool is_initialized_;
47 keymaster_digest_t digest_type_;
48 size_t digest_size_;
Thai Duongfabacaf2015-03-25 20:14:57 -070049};
50
51} // namespace keymaster
52
53#endif // SYSTEM_KEYMASTER_KDF_H_