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 | #include "hmac_key.h" |
| 18 | |
| 19 | #include <openssl/err.h> |
| 20 | #include <openssl/rand.h> |
| 21 | |
| 22 | #include "hmac_operation.h" |
| 23 | |
| 24 | namespace keymaster { |
| 25 | |
Shawn Willden | 0629810 | 2015-05-25 23:12:48 -0600 | [diff] [blame^] | 26 | static HmacSignOperationFactory sign_factory; |
| 27 | static HmacVerifyOperationFactory verify_factory; |
| 28 | |
| 29 | OperationFactory* HmacKeyFactory::GetOperationFactory(keymaster_purpose_t purpose) const { |
| 30 | switch (purpose) { |
| 31 | case KM_PURPOSE_SIGN: |
| 32 | return &sign_factory; |
| 33 | case KM_PURPOSE_VERIFY: |
| 34 | return &verify_factory; |
| 35 | default: |
| 36 | return nullptr; |
| 37 | } |
| 38 | } |
| 39 | |
Shawn Willden | 0cb6942 | 2015-05-26 08:31:37 -0600 | [diff] [blame] | 40 | keymaster_error_t HmacKeyFactory::LoadKey(const KeymasterKeyBlob& key_material, |
| 41 | const AuthorizationSet& hw_enforced, |
| 42 | const AuthorizationSet& sw_enforced, |
Shawn Willden | 0629810 | 2015-05-25 23:12:48 -0600 | [diff] [blame^] | 43 | UniquePtr<Key>* key) const { |
Shawn Willden | 0cb6942 | 2015-05-26 08:31:37 -0600 | [diff] [blame] | 44 | if (!key) |
| 45 | return KM_ERROR_OUTPUT_PARAMETER_NULL; |
Shawn Willden | a278f61 | 2014-12-23 11:22:21 -0700 | [diff] [blame] | 46 | |
Shawn Willden | 0cb6942 | 2015-05-26 08:31:37 -0600 | [diff] [blame] | 47 | keymaster_error_t error; |
| 48 | key->reset(new HmacKey(key_material, hw_enforced, sw_enforced, &error)); |
| 49 | if (!key->get()) |
| 50 | error = KM_ERROR_MEMORY_ALLOCATION_FAILED; |
| 51 | return error; |
Shawn Willden | f923963 | 2015-05-12 06:57:37 -0600 | [diff] [blame] | 52 | } |
Shawn Willden | a278f61 | 2014-12-23 11:22:21 -0700 | [diff] [blame] | 53 | |
Shawn Willden | 0d560bf | 2014-12-15 17:44:02 -0700 | [diff] [blame] | 54 | } // namespace keymaster |