The introduced SHA1_NOFINAL hasher was not sufficient for EAP-AKA,
[strongswan.git] / src / charon / plugins / unit_tester / tests / test_fips_prf.c
1 /*
2 * Copyright (C) 2007 Martin Willi
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 #include <utils/linked_list.h>
17 #include <daemon.h>
18
19 /*******************************************************************************
20 * fips prf known value test
21 ******************************************************************************/
22 bool fips_prf_test()
23 {
24 prf_t *prf;
25 u_int8_t key_buf[] = {
26 0xbd, 0x02, 0x9b, 0xbe, 0x7f, 0x51, 0x96, 0x0b,
27 0xcf, 0x9e, 0xdb, 0x2b, 0x61, 0xf0, 0x6f, 0x0f,
28 0xeb, 0x5a, 0x38, 0xb6
29 };
30 u_int8_t seed_buf[] = {
31 0x00
32 };
33 u_int8_t result_buf[] = {
34 0x20, 0x70, 0xb3, 0x22, 0x3d, 0xba, 0x37, 0x2f,
35 0xde, 0x1c, 0x0f, 0xfc, 0x7b, 0x2e, 0x3b, 0x49,
36 0x8b, 0x26, 0x06, 0x14, 0x3c, 0x6c, 0x18, 0xba,
37 0xcb, 0x0f, 0x6c, 0x55, 0xba, 0xbb, 0x13, 0x78,
38 0x8e, 0x20, 0xd7, 0x37, 0xa3, 0x27, 0x51, 0x16
39 };
40 chunk_t key = chunk_from_buf(key_buf);
41 chunk_t seed = chunk_from_buf(seed_buf);
42 chunk_t expected = chunk_from_buf(result_buf);
43 chunk_t result;
44
45 prf = lib->crypto->create_prf(lib->crypto, PRF_FIPS_SHA1_160);
46 if (prf == NULL)
47 {
48 DBG1(DBG_CFG, "FIPS PRF implementation not found");
49 return FALSE;
50 }
51 prf->set_key(prf, key);
52 prf->allocate_bytes(prf, seed, &result);
53 prf->destroy(prf);
54 if (!chunk_equals(result, expected))
55 {
56 DBG1(DBG_CFG, "FIPS PRF result invalid:\nexpected: %Bresult: %B",
57 &expected, &result);
58 chunk_free(&result);
59 return FALSE;
60 }
61 chunk_free(&result);
62 return TRUE;
63 }
64