summaryrefslogtreecommitdiff
path: root/services/tests/servicestests/src/com/android/server/locksettings/SP800DeriveTests.java
blob: fc2dcb9cc83b37dfd3a7f34a6c84e34117f36644 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.server.locksettings;

import android.test.AndroidTestCase;

import com.android.internal.util.HexDump;

public class SP800DeriveTests extends AndroidTestCase {
    public void testFixedInput() throws Exception {
        // CAVP: https://csrc.nist.gov/projects/cryptographic-algorithm-validation-program/key-derivation
        byte[] keyBytes = HexDump.hexStringToByteArray(
            "e204d6d466aad507ffaf6d6dab0a5b26"
            + "152c9e21e764370464e360c8fbc765c6");
        SP800Derive sk = new SP800Derive(keyBytes);
        byte[] fixedInput = HexDump.hexStringToByteArray(
            "7b03b98d9f94b899e591f3ef264b71b1"
            + "93fba7043c7e953cde23bc5384bc1a62"
            + "93580115fae3495fd845dadbd02bd645"
            + "5cf48d0f62b33e62364a3a80");
        byte[] res = sk.fixedInput(fixedInput);
        assertEquals((
                "770dfab6a6a4a4bee0257ff335213f78"
                + "d8287b4fd537d5c1fffa956910e7c779").toUpperCase(), HexDump.toHexString(res));
    }
}