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 24 const size_t kMinHmacLengthBits = 64; 25 const size_t kMinHmacKeyLengthBits = 64; 26 const size_t kMaxHmacKeyLengthBits = 2048; // Some RFC test cases require >1024-bit keys 27 28 class HmacKeyFactory : public SymmetricKeyFactory { 29 public: HmacKeyFactory(const KeymasterContext * context)30 explicit HmacKeyFactory(const KeymasterContext* context) : SymmetricKeyFactory(context) {} 31 32 keymaster_error_t LoadKey(const KeymasterKeyBlob& key_material, 33 const AuthorizationSet& additional_params, 34 const AuthorizationSet& hw_enforced, 35 const AuthorizationSet& sw_enforced, 36 UniquePtr<Key>* key) const override; 37 38 OperationFactory* GetOperationFactory(keymaster_purpose_t purpose) const override; 39 40 private: key_size_supported(size_t key_size_bits)41 bool key_size_supported(size_t key_size_bits) const override { 42 return key_size_bits > 0 && key_size_bits % 8 == 00 && 43 key_size_bits >= kMinHmacKeyLengthBits && key_size_bits <= kMaxHmacKeyLengthBits; 44 } 45 keymaster_error_t validate_algorithm_specific_new_key_params( 46 const AuthorizationSet& key_description) const override; 47 }; 48 49 class HmacKey : public SymmetricKey { 50 public: HmacKey(const KeymasterKeyBlob & key_material,const AuthorizationSet & hw_enforced,const AuthorizationSet & sw_enforced,keymaster_error_t * error)51 HmacKey(const KeymasterKeyBlob& key_material, const AuthorizationSet& hw_enforced, 52 const AuthorizationSet& sw_enforced, keymaster_error_t* error) 53 : SymmetricKey(key_material, hw_enforced, sw_enforced, error) {} 54 }; 55 56 } // namespace keymaster 57 58 #endif // SYSTEM_KEYMASTER_HMAC_KEY_H_ 59