Content-Type: multipart/mixed; boundary="===============8579681217712565984==" MIME-Version: 1.0 From: Andrew Zaborowski Subject: [PATCH 12/17] unit: Add TLS 1.2 PRF tests. Date: Fri, 24 Jul 2015 05:27:47 +0200 Message-ID: <1437708472-28124-3-git-send-email-andrew.zaborowski@intel.com> In-Reply-To: <1437708472-28124-1-git-send-email-andrew.zaborowski@intel.com> List-Id: To: ell@lists.01.org --===============8579681217712565984== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable --- .gitignore | 1 + Makefile.am | 5 +- unit/test-tls.c | 182 ++++++++++++++++++++++++++++++++++++++++++++++++++++= ++++ 3 files changed, 187 insertions(+), 1 deletion(-) create mode 100644 unit/test-tls.c diff --git a/.gitignore b/.gitignore index b122511..c50d7e7 100644 --- a/.gitignore +++ b/.gitignore @@ -46,6 +46,7 @@ unit/test-cipher unit/test-random unit/test-util unit/test-uintset +unit/test-tls unit/test-cert unit/*.log unit/*.trs diff --git a/Makefile.am b/Makefile.am index da1f4f1..29bf54e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -129,7 +129,8 @@ unit_tests =3D unit/test-unit \ unit/test-random \ unit/test-util \ unit/test-uintset \ - unit/test-cert + unit/test-cert \ + unit/test-tls = if MAINTAINER_MODE noinst_PROGRAMS +=3D $(unit_tests) @@ -193,6 +194,8 @@ unit_test_uintset_LDADD =3D ell/libell-private.la = unit_test_cert_LDADD =3D ell/libell-private.la = +unit_test_tls_LDADD =3D ell/libell-private.la + if MAINTAINER_MODE noinst_LTLIBRARIES +=3D unit/example-plugin.la endif diff --git a/unit/test-tls.c b/unit/test-tls.c new file mode 100644 index 0000000..49d754f --- /dev/null +++ b/unit/test-tls.c @@ -0,0 +1,182 @@ +/* + * + * Embedded Linux library + * + * Copyright (C) 2011-2014 Intel Corporation. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 = USA + * + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include + +#include "ell/cipher.h" +#include "ell/checksum.h" +#include "ell/tls-private.h" + +/* https://www.ietf.org/mail-archive/web/tls/current/msg03416.html */ +static struct tls12_prf_test { + enum l_checksum_type hash; + size_t hash_len; + const uint8_t *secret; + size_t secret_len; + const char *label; + const uint8_t *seed; + size_t seed_len; + const uint8_t *expected; + size_t out_len; +} tls12_prf_sha256_0 =3D { + .hash =3D L_CHECKSUM_SHA256, + .hash_len =3D 32, + .secret_len =3D 16, + .secret =3D (const uint8_t []) { + 0x9b, 0xbe, 0x43, 0x6b, 0xa9, 0x40, 0xf0, 0x17, + 0xb1, 0x76, 0x52, 0x84, 0x9a, 0x71, 0xdb, 0x35, + }, + .seed_len =3D 16, + .seed =3D (const uint8_t []) { + 0xa0, 0xba, 0x9f, 0x93, 0x6c, 0xda, 0x31, 0x18, + 0x27, 0xa6, 0xf7, 0x96, 0xff, 0xd5, 0x19, 0x8c, + }, + .label =3D "test label", + .out_len =3D 100, + .expected =3D (const uint8_t []) { + 0xe3, 0xf2, 0x29, 0xba, 0x72, 0x7b, 0xe1, 0x7b, + 0x8d, 0x12, 0x26, 0x20, 0x55, 0x7c, 0xd4, 0x53, + 0xc2, 0xaa, 0xb2, 0x1d, 0x07, 0xc3, 0xd4, 0x95, + 0x32, 0x9b, 0x52, 0xd4, 0xe6, 0x1e, 0xdb, 0x5a, + 0x6b, 0x30, 0x17, 0x91, 0xe9, 0x0d, 0x35, 0xc9, + 0xc9, 0xa4, 0x6b, 0x4e, 0x14, 0xba, 0xf9, 0xaf, + 0x0f, 0xa0, 0x22, 0xf7, 0x07, 0x7d, 0xef, 0x17, + 0xab, 0xfd, 0x37, 0x97, 0xc0, 0x56, 0x4b, 0xab, + 0x4f, 0xbc, 0x91, 0x66, 0x6e, 0x9d, 0xef, 0x9b, + 0x97, 0xfc, 0xe3, 0x4f, 0x79, 0x67, 0x89, 0xba, + 0xa4, 0x80, 0x82, 0xd1, 0x22, 0xee, 0x42, 0xc5, + 0xa7, 0x2e, 0x5a, 0x51, 0x10, 0xff, 0xf7, 0x01, + 0x87, 0x34, 0x7b, 0x66, + }, +}, tls12_prf_sha384_0 =3D { + .hash =3D L_CHECKSUM_SHA384, + .hash_len =3D 48, + .secret_len =3D 16, + .secret =3D (const uint8_t []) { + 0xb8, 0x0b, 0x73, 0x3d, 0x6c, 0xee, 0xfc, 0xdc, + 0x71, 0x56, 0x6e, 0xa4, 0x8e, 0x55, 0x67, 0xdf, + }, + .seed_len =3D 16, + .seed =3D (const uint8_t []) { + 0xcd, 0x66, 0x5c, 0xf6, 0xa8, 0x44, 0x7d, 0xd6, + 0xff, 0x8b, 0x27, 0x55, 0x5e, 0xdb, 0x74, 0x65, + }, + .label =3D "test label", + .out_len =3D 148, + .expected =3D (const uint8_t []) { + 0x7b, 0x0c, 0x18, 0xe9, 0xce, 0xd4, 0x10, 0xed, + 0x18, 0x04, 0xf2, 0xcf, 0xa3, 0x4a, 0x33, 0x6a, + 0x1c, 0x14, 0xdf, 0xfb, 0x49, 0x00, 0xbb, 0x5f, + 0xd7, 0x94, 0x21, 0x07, 0xe8, 0x1c, 0x83, 0xcd, + 0xe9, 0xca, 0x0f, 0xaa, 0x60, 0xbe, 0x9f, 0xe3, + 0x4f, 0x82, 0xb1, 0x23, 0x3c, 0x91, 0x46, 0xa0, + 0xe5, 0x34, 0xcb, 0x40, 0x0f, 0xed, 0x27, 0x00, + 0x88, 0x4f, 0x9d, 0xc2, 0x36, 0xf8, 0x0e, 0xdd, + 0x8b, 0xfa, 0x96, 0x11, 0x44, 0xc9, 0xe8, 0xd7, + 0x92, 0xec, 0xa7, 0x22, 0xa7, 0xb3, 0x2f, 0xc3, + 0xd4, 0x16, 0xd4, 0x73, 0xeb, 0xc2, 0xc5, 0xfd, + 0x4a, 0xbf, 0xda, 0xd0, 0x5d, 0x91, 0x84, 0x25, + 0x9b, 0x5b, 0xf8, 0xcd, 0x4d, 0x90, 0xfa, 0x0d, + 0x31, 0xe2, 0xde, 0xc4, 0x79, 0xe4, 0xf1, 0xa2, + 0x60, 0x66, 0xf2, 0xee, 0xa9, 0xa6, 0x92, 0x36, + 0xa3, 0xe5, 0x26, 0x55, 0xc9, 0xe9, 0xae, 0xe6, + 0x91, 0xc8, 0xf3, 0xa2, 0x68, 0x54, 0x30, 0x8d, + 0x5e, 0xaa, 0x3b, 0xe8, 0x5e, 0x09, 0x90, 0x70, + 0x3d, 0x73, 0xe5, 0x6f, + }, +}, tls12_prf_sha512_0 =3D { + .hash =3D L_CHECKSUM_SHA512, + .hash_len =3D 64, + .secret_len =3D 16, + .secret =3D (const uint8_t []) { + 0xb0, 0x32, 0x35, 0x23, 0xc1, 0x85, 0x35, 0x99, + 0x58, 0x4d, 0x88, 0x56, 0x8b, 0xbb, 0x05, 0xeb, + }, + .seed_len =3D 16, + .seed =3D (const uint8_t []) { + 0xd4, 0x64, 0x0e, 0x12, 0xe4, 0xbc, 0xdb, 0xfb, + 0x43, 0x7f, 0x03, 0xe6, 0xae, 0x41, 0x8e, 0xe5, + }, + .label =3D "test label", + .out_len =3D 196, + .expected =3D (const uint8_t []) { + 0x12, 0x61, 0xf5, 0x88, 0xc7, 0x98, 0xc5, 0xc2, + 0x01, 0xff, 0x03, 0x6e, 0x7a, 0x9c, 0xb5, 0xed, + 0xcd, 0x7f, 0xe3, 0xf9, 0x4c, 0x66, 0x9a, 0x12, + 0x2a, 0x46, 0x38, 0xd7, 0xd5, 0x08, 0xb2, 0x83, + 0x04, 0x2d, 0xf6, 0x78, 0x98, 0x75, 0xc7, 0x14, + 0x7e, 0x90, 0x6d, 0x86, 0x8b, 0xc7, 0x5c, 0x45, + 0xe2, 0x0e, 0xb4, 0x0c, 0x1c, 0xf4, 0xa1, 0x71, + 0x3b, 0x27, 0x37, 0x1f, 0x68, 0x43, 0x25, 0x92, + 0xf7, 0xdc, 0x8e, 0xa8, 0xef, 0x22, 0x3e, 0x12, + 0xea, 0x85, 0x07, 0x84, 0x13, 0x11, 0xbf, 0x68, + 0x65, 0x3d, 0x0c, 0xfc, 0x40, 0x56, 0xd8, 0x11, + 0xf0, 0x25, 0xc4, 0x5d, 0xdf, 0xa6, 0xe6, 0xfe, + 0xc7, 0x02, 0xf0, 0x54, 0xb4, 0x09, 0xd6, 0xf2, + 0x8d, 0xd0, 0xa3, 0x23, 0x3e, 0x49, 0x8d, 0xa4, + 0x1a, 0x3e, 0x75, 0xc5, 0x63, 0x0e, 0xed, 0xbe, + 0x22, 0xfe, 0x25, 0x4e, 0x33, 0xa1, 0xb0, 0xe9, + 0xf6, 0xb9, 0x82, 0x66, 0x75, 0xbe, 0xc7, 0xd0, + 0x1a, 0x84, 0x56, 0x58, 0xdc, 0x9c, 0x39, 0x75, + 0x45, 0x40, 0x1d, 0x40, 0xb9, 0xf4, 0x6c, 0x7a, + 0x40, 0x0e, 0xe1, 0xb8, 0xf8, 0x1c, 0xa0, 0xa6, + 0x0d, 0x1a, 0x39, 0x7a, 0x10, 0x28, 0xbf, 0xf5, + 0xd2, 0xef, 0x50, 0x66, 0x12, 0x68, 0x42, 0xfb, + 0x8d, 0xa4, 0x19, 0x76, 0x32, 0xbd, 0xb5, 0x4f, + 0xf6, 0x63, 0x3f, 0x86, 0xbb, 0xc8, 0x36, 0xe6, + 0x40, 0xd4, 0xd8, 0x98, + }, +}; + +static void test_tls12_prf(const void *data) +{ + const struct tls12_prf_test *test =3D data; + uint8_t out_buf[test->out_len]; + + tls12_prf(test->hash, test->hash_len, test->secret, test->secret_len, + test->label, test->seed, test->seed_len, + out_buf, test->out_len); + + assert(!memcmp(out_buf, test->expected, test->out_len)); +} + +int main(int argc, char *argv[]) +{ + l_test_init(&argc, &argv); + + l_test_add("TLS 1.2 PRF with SHA256", test_tls12_prf, + &tls12_prf_sha256_0); + + l_test_add("TLS 1.2 PRF with SHA384", test_tls12_prf, + &tls12_prf_sha384_0); + + l_test_add("TLS 1.2 PRF with SHA512", test_tls12_prf, + &tls12_prf_sha512_0); + + return l_test_run(); +} -- = 2.1.4 --===============8579681217712565984==--