Thai Duong | fabacaf | 2015-03-25 20:14:57 -0700 | [diff] [blame] | 1 | /* |
| 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 Nguyen | f7538e0 | 2015-05-21 00:49:11 -0700 | [diff] [blame] | 20 | #include <hardware/keymaster_defs.h> |
| 21 | #include <keymaster/android_keymaster_utils.h> |
Thai Duong | fabacaf | 2015-03-25 20:14:57 -0700 | [diff] [blame] | 22 | #include <keymaster/serializable.h> |
| 23 | |
Quan Nguyen | f7538e0 | 2015-05-21 00:49:11 -0700 | [diff] [blame] | 24 | #include <UniquePtr.h> |
| 25 | |
Thai Duong | fabacaf | 2015-03-25 20:14:57 -0700 | [diff] [blame] | 26 | namespace keymaster { |
| 27 | |
Quan Nguyen | f7538e0 | 2015-05-21 00:49:11 -0700 | [diff] [blame] | 28 | /** |
| 29 | * A base class for wrapping different key derivation functions. |
| 30 | */ |
Thai Duong | fabacaf | 2015-03-25 20:14:57 -0700 | [diff] [blame] | 31 | class Kdf { |
| 32 | public: |
Quan Nguyen | f7538e0 | 2015-05-21 00:49:11 -0700 | [diff] [blame] | 33 | 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 Duong | fabacaf | 2015-03-25 20:14:57 -0700 | [diff] [blame] | 39 | |
Quan Nguyen | f7538e0 | 2015-05-21 00:49:11 -0700 | [diff] [blame] | 40 | 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 Duong | fabacaf | 2015-03-25 20:14:57 -0700 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | } // namespace keymaster |
| 52 | |
| 53 | #endif // SYSTEM_KEYMASTER_KDF_H_ |