1 /* 2 * Copyright (C) 2017 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 package com.android.server.locksettings; 18 19 import static org.junit.Assert.assertEquals; 20 21 import android.platform.test.annotations.Presubmit; 22 23 import androidx.test.filters.SmallTest; 24 import androidx.test.runner.AndroidJUnit4; 25 26 import com.android.internal.util.HexDump; 27 28 import org.junit.Test; 29 import org.junit.runner.RunWith; 30 31 @SmallTest 32 @Presubmit 33 @RunWith(AndroidJUnit4.class) 34 public class SP800DeriveTests { 35 @Test testFixedInput()36 public void testFixedInput() throws Exception { 37 // CAVP: https://csrc.nist.gov/projects/cryptographic-algorithm-validation-program/key-derivation 38 byte[] keyBytes = HexDump.hexStringToByteArray( 39 "e204d6d466aad507ffaf6d6dab0a5b26" 40 + "152c9e21e764370464e360c8fbc765c6"); 41 SP800Derive sk = new SP800Derive(keyBytes); 42 byte[] fixedInput = HexDump.hexStringToByteArray( 43 "7b03b98d9f94b899e591f3ef264b71b1" 44 + "93fba7043c7e953cde23bc5384bc1a62" 45 + "93580115fae3495fd845dadbd02bd645" 46 + "5cf48d0f62b33e62364a3a80"); 47 byte[] res = sk.fixedInput(fixedInput); 48 assertEquals(( 49 "770dfab6a6a4a4bee0257ff335213f78" 50 + "d8287b4fd537d5c1fffa956910e7c779").toUpperCase(), HexDump.toHexString(res)); 51 } 52 } 53