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 #include "kdf.h" 18 #include <gtest/gtest.h> 19 20 namespace keymaster { 21 22 namespace test { 23 24 class ForTestAbstractKdf : public Kdf { 25 bool GenerateKey(const uint8_t* /* info */, size_t /* info_len */, uint8_t* /* output */, 26 size_t /* output_len */) { 27 return true; 28 } 29 }; 30 31 TEST(KdfTest, Kdf) { 32 ForTestAbstractKdf kdf; 33 uint8_t key[128]; 34 uint8_t salt[128]; 35 ASSERT_TRUE(kdf.Init(KM_DIGEST_SHA1, key, 128, salt, 128)); 36 ASSERT_TRUE(kdf.Init(KM_DIGEST_SHA_2_256, key, 128, salt, 128)); 37 ASSERT_TRUE(kdf.Init(KM_DIGEST_SHA1, key, 128, nullptr, 0)); 38 ASSERT_FALSE(kdf.Init(KM_DIGEST_MD5, key, 128, salt, 128)); 39 ASSERT_FALSE(kdf.Init(KM_DIGEST_SHA1, nullptr, 0, salt, 128)); 40 ASSERT_FALSE(kdf.Init(KM_DIGEST_SHA1, nullptr, 128, salt, 128)); 41 ASSERT_FALSE(kdf.Init(KM_DIGEST_SHA1, key, 0, salt, 128)); 42 } 43 44 } // namespace test 45 46 } // namespace keymaster 47