blob: c5a7b91297b60d82150553d6e84e2c601af4bd52 [file] [log] [blame]
Shawn Willden0d560bf2014-12-15 17:44:02 -07001/*
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
22namespace keymaster {
23
Shawn Willdenf9239632015-05-12 06:57:37 -060024class HmacKeyFactory : public SymmetricKeyFactory {
25 public:
Shawn Willden8ba2a042015-05-18 08:35:28 -060026 HmacKeyFactory(const KeymasterContext* context) : SymmetricKeyFactory(context) {}
27
Shawn Willdenf9239632015-05-12 06:57:37 -060028 keymaster_algorithm_t registry_key() const override { return KM_ALGORITHM_HMAC; }
29
Shawn Willden8ba2a042015-05-18 08:35:28 -060030 keymaster_error_t LoadKey(const KeymasterKeyBlob& key_material,
31 const AuthorizationSet& hw_enforced,
32 const AuthorizationSet& sw_enforced, UniquePtr<Key>* key) override;
33
34 private:
35 bool key_size_supported(size_t key_size_bits) const override {
36 return key_size_bits > 0 && key_size_bits % 8 == 00 &&
37 key_size_bits <= 2048 /* Some RFC test cases require >1024-bit keys */;
38 }
Shawn Willdenf9239632015-05-12 06:57:37 -060039};
40
Shawn Willden0d560bf2014-12-15 17:44:02 -070041class HmacKey : public SymmetricKey {
42 public:
Shawn Willden8ba2a042015-05-18 08:35:28 -060043 HmacKey(const KeymasterKeyBlob& key_material, const AuthorizationSet& hw_enforced,
44 const AuthorizationSet& sw_enforced, keymaster_error_t* error)
45 : SymmetricKey(key_material, hw_enforced, sw_enforced, error) {}
Shawn Willden0d560bf2014-12-15 17:44:02 -070046};
47
48} // namespace keymaster
49
50#endif // SYSTEM_KEYMASTER_HMAC_KEY_H_