|
| 1 | +/* Copyright (c) Fortanix, Inc. |
| 2 | + * |
| 3 | + * Licensed under the GNU General Public License, version 2 <LICENSE-GPL or |
| 4 | + * https://www.gnu.org/licenses/gpl-2.0.html> or the Apache License, Version |
| 5 | + * 2.0 <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0>, at your |
| 6 | + * option. This file may not be copied, modified, or distributed except |
| 7 | + * according to those terms. */ |
| 8 | + |
| 9 | +use mbedtls::hash::Md; |
| 10 | +use mbedtls::hash::Type as MdType; |
| 11 | + |
| 12 | +#[test] |
| 13 | +fn test_hkdf_sha256() { |
| 14 | + let ikm = [ |
| 15 | + 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, |
| 16 | + 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, |
| 17 | + ]; |
| 18 | + |
| 19 | + let salt = [ |
| 20 | + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, |
| 21 | + ]; |
| 22 | + let info = [0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9]; |
| 23 | + let mut output = [0u8; 42]; |
| 24 | + Md::hkdf(MdType::Sha256, &salt, &ikm, &info, &mut output).unwrap(); |
| 25 | + |
| 26 | + assert_eq!( |
| 27 | + output, |
| 28 | + [ |
| 29 | + 0x3c, 0xb2, 0x5f, 0x25, 0xfa, 0xac, 0xd5, 0x7a, 0x90, 0x43, 0x4f, 0x64, 0xd0, 0x36, |
| 30 | + 0x2f, 0x2a, 0x2d, 0x2d, 0x0a, 0x90, 0xcf, 0x1a, 0x5a, 0x4c, 0x5d, 0xb0, 0x2d, 0x56, |
| 31 | + 0xec, 0xc4, 0xc5, 0xbf, 0x34, 0x00, 0x72, 0x08, 0xd5, 0xb8, 0x87, 0x18, 0x58, 0x65 |
| 32 | + ] |
| 33 | + ); |
| 34 | +} |
0 commit comments