From owner-svn-src-projects@freebsd.org Sat Jan 14 07:16:16 2017 Return-Path: Delivered-To: svn-src-projects@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B3A47CAF533 for ; Sat, 14 Jan 2017 07:16:16 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 908C11A35; Sat, 14 Jan 2017 07:16:16 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v0E7GFbk020810; Sat, 14 Jan 2017 07:16:15 GMT (envelope-from ngie@FreeBSD.org) Received: (from ngie@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v0E7GFOm020809; Sat, 14 Jan 2017 07:16:15 GMT (envelope-from ngie@FreeBSD.org) Message-Id: <201701140716.v0E7GFOm020809@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ngie set sender to ngie@FreeBSD.org using -f From: Ngie Cooper Date: Sat, 14 Jan 2017 07:16:15 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r312130 - projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/hash X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 14 Jan 2017 07:16:16 -0000 Author: ngie Date: Sat Jan 14 07:16:15 2017 New Revision: 312130 URL: https://svnweb.freebsd.org/changeset/base/312130 Log: Copy ^/vendor/NetBSD/tests/dist/lib/libc/hash/t_hmac.c to contrib/netbsd-tests/lib/libc/hash/t_hmac.c This was missed in r303980 Added: projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/hash/t_hmac.c - copied unchanged from r312129, vendor/NetBSD/tests/dist/lib/libc/hash/t_hmac.c Copied: projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/hash/t_hmac.c (from r312129, vendor/NetBSD/tests/dist/lib/libc/hash/t_hmac.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/hash/t_hmac.c Sat Jan 14 07:16:15 2017 (r312130, copy of r312129, vendor/NetBSD/tests/dist/lib/libc/hash/t_hmac.c) @@ -0,0 +1,127 @@ +/* $NetBSD: t_hmac.c,v 1.1 2016/07/02 14:52:09 christos Exp $ */ + +/*- + * Copyright (c) 2016 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#include +__RCSID("$NetBSD: t_hmac.c,v 1.1 2016/07/02 14:52:09 christos Exp $"); + +#include +#include +#include +#include +#include + +static void +test(void) +{ + uint8_t tmp1[EVP_MAX_MD_SIZE]; + uint8_t tmp2[EVP_MAX_MD_SIZE]; + uint8_t key[256]; + uint8_t data[4096]; + unsigned int tmp1len; + size_t tmp2len; + int stop; + void *e1; + const void *evps[] = { + EVP_md2(), + EVP_md4(), + EVP_md5(), + EVP_ripemd160(), + EVP_sha1(), + EVP_sha224(), + EVP_sha256(), + EVP_sha384(), + EVP_sha512(), + }; + const char *names[] = { + "md2", + "md4", + "md5", + "rmd160", + "sha1", + "sha224", + "sha256", + "sha384", + "sha512", + }; + + for (size_t k = 0; k < sizeof(key); k++) + key[k] = k; + for (size_t d = 0; d < sizeof(data); d++) + data[d] = d % 256; + + for (size_t t = 0; t < __arraycount(names); t++) + for (size_t i = 1; i < sizeof(key); i += 9) + for (size_t j = 3; j < sizeof(data); j += 111) { + stop = 0; +#ifdef DEBUG + printf("%s: keysize = %zu datasize = %zu\n", names[t], + i, j); +#endif + memset(tmp1, 0, sizeof(tmp1)); + memset(tmp2, 0, sizeof(tmp2)); + e1 = HMAC(evps[t], key, i, data, j, tmp1, &tmp1len); + ATF_REQUIRE(e1 != NULL); + tmp2len = hmac(names[t], key, i, data, j, tmp2, + sizeof(tmp2)); + ATF_REQUIRE_MSG(tmp1len == tmp2len, "hash %s len %u " + "!= %zu", names[t], tmp1len, tmp2len); + for (size_t k = 0; k < tmp2len; k++) + if (tmp1[k] != tmp2[k]) { +#ifdef DEBUG + printf("%zu %.2x %.2x\n", + k, tmp1[k], tmp2[k]); +#endif + stop = 1; + break; + } + ATF_REQUIRE_MSG(!stop, "hash %s failed for " + "keylen=%zu, datalen=%zu", names[t], i, j); + } +} + +ATF_TC(t_hmac); + +ATF_TC_HEAD(t_hmac, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Test hmac functions for consistent results"); +} + +ATF_TC_BODY(t_hmac, tc) +{ + test(); +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, t_hmac); + return atf_no_error(); +} +