Shawn Willden | 0d560bf | 2014-12-15 17:44:02 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 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_HMAC_KEY_H_ |
| 18 | #define SYSTEM_KEYMASTER_HMAC_KEY_H_ |
| 19 | |
| 20 | #include "symmetric_key.h" |
| 21 | |
| 22 | namespace keymaster { |
| 23 | |
Shawn Willden | 33ab038 | 2015-07-08 08:47:25 -0600 | [diff] [blame] | 24 | const size_t kMinHmacLengthBits = 64; |
| 25 | |
Shawn Willden | f923963 | 2015-05-12 06:57:37 -0600 | [diff] [blame] | 26 | class HmacKeyFactory : public SymmetricKeyFactory { |
| 27 | public: |
Shawn Willden | 0cb6942 | 2015-05-26 08:31:37 -0600 | [diff] [blame] | 28 | HmacKeyFactory(const KeymasterContext* context) : SymmetricKeyFactory(context) {} |
| 29 | |
Shawn Willden | 0cb6942 | 2015-05-26 08:31:37 -0600 | [diff] [blame] | 30 | keymaster_error_t LoadKey(const KeymasterKeyBlob& key_material, |
Shawn Willden | 2612fb5 | 2015-07-27 16:58:30 -0600 | [diff] [blame] | 31 | const AuthorizationSet& additional_params, |
Shawn Willden | 0cb6942 | 2015-05-26 08:31:37 -0600 | [diff] [blame] | 32 | const AuthorizationSet& hw_enforced, |
Shawn Willden | 0629810 | 2015-05-25 23:12:48 -0600 | [diff] [blame] | 33 | const AuthorizationSet& sw_enforced, |
| 34 | UniquePtr<Key>* key) const override; |
| 35 | |
| 36 | OperationFactory* GetOperationFactory(keymaster_purpose_t purpose) const override; |
Shawn Willden | 0cb6942 | 2015-05-26 08:31:37 -0600 | [diff] [blame] | 37 | |
| 38 | private: |
| 39 | bool key_size_supported(size_t key_size_bits) const override { |
| 40 | return key_size_bits > 0 && key_size_bits % 8 == 00 && |
| 41 | key_size_bits <= 2048 /* Some RFC test cases require >1024-bit keys */; |
| 42 | } |
Shawn Willden | 33ab038 | 2015-07-08 08:47:25 -0600 | [diff] [blame] | 43 | keymaster_error_t validate_algorithm_specific_new_key_params( |
| 44 | const AuthorizationSet& key_description) const override; |
Shawn Willden | f923963 | 2015-05-12 06:57:37 -0600 | [diff] [blame] | 45 | }; |
| 46 | |
Shawn Willden | 0d560bf | 2014-12-15 17:44:02 -0700 | [diff] [blame] | 47 | class HmacKey : public SymmetricKey { |
| 48 | public: |
Shawn Willden | 0cb6942 | 2015-05-26 08:31:37 -0600 | [diff] [blame] | 49 | HmacKey(const KeymasterKeyBlob& key_material, const AuthorizationSet& hw_enforced, |
| 50 | const AuthorizationSet& sw_enforced, keymaster_error_t* error) |
| 51 | : SymmetricKey(key_material, hw_enforced, sw_enforced, error) {} |
Shawn Willden | 0d560bf | 2014-12-15 17:44:02 -0700 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | } // namespace keymaster |
| 55 | |
| 56 | #endif // SYSTEM_KEYMASTER_HMAC_KEY_H_ |