? Atffile ? o Index: Makefile =================================================================== RCS file: /cvsroot/src/tests/crypto/opencrypto/Makefile,v retrieving revision 1.5 diff -u -p -u -r1.5 Makefile --- Makefile 3 Dec 2019 04:20:45 -0000 1.5 +++ Makefile 23 Apr 2026 23:44:37 -0000 @@ -27,8 +27,13 @@ PROGS+= h_sha1hmac PROGS+= h_sha2hmac PROGS+= h_xcbcmac PROGS+= h_ioctl +PROGS+= h_thread LDADD.h_comp_zlib+= -lz +DPADD.h_comp_zlib+= ${LIBZ} LDADD.h_comp_zlib_rnd+= -lz +DPADD.h_comp_zlib_rnd+= ${LIBZ} +LDADD.h_thread+= -lpthread +DPADD.h_thread+= ${LIBPTHREAD} .include Index: h_thread.c =================================================================== RCS file: h_thread.c diff -N h_thread.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ h_thread.c 23 Apr 2026 23:44:37 -0000 @@ -0,0 +1,143 @@ +/* $NetBSD: h_md5.c,v 1.5 2014/01/18 20:10:34 pgoyette Exp $ */ + +/*- + * Copyright (c) 2014 The NetBSD Foundation, Inc. + * All rights reserved. + * + * 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 +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +/* Test vectors from RFC1321 */ + +const struct { + size_t len; + unsigned char plaintx[80]; + unsigned char digest[16]; +} tests[] = { + { 0, "", + { 0xd4, 0x1d, 0x8c, 0xd9, 0x8f, 0x00, 0xb2, 0x04, + 0xe9, 0x80, 0x09, 0x98, 0xec, 0xf8, 0x42, 0x7e } }, + { 1, "a", + { 0x0c, 0xc1, 0x75, 0xb9, 0xc0, 0xf1, 0xb6, 0xa8, + 0x31, 0xc3, 0x99, 0xe2, 0x69, 0x77, 0x26, 0x61 } }, + { 3, "abc", + { 0x90, 0x01, 0x50, 0x98, 0x3c, 0xd2, 0x4f, 0xb0, + 0xd6, 0x96, 0x3f, 0x7d, 0x28, 0xe1, 0x7f, 0x72 } }, + { 14, "message digest", + { 0xf9, 0x6b, 0x69, 0x7d, 0x7c, 0xb7, 0x93, 0x8d, + 0x52, 0x5a, 0x2f, 0x31, 0xaa, 0xf1, 0x61, 0xd0 } }, + { 26, "abcdefghijklmnopqrstuvwxyz", + { 0xc3, 0xfc, 0xd3, 0xd7, 0x61, 0x92, 0xe4, 0x00, + 0x7d, 0xfb, 0x49, 0x6c, 0xca, 0x67, 0xe1, 0x3b } }, + { 62, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", + { 0xd1, 0x74, 0xab, 0x98, 0xd2, 0x77, 0xd9, 0xf5, + 0xa5, 0x61, 0x1c, 0x2c, 0x9f, 0x41, 0x9d, 0x9f } }, + { 80, "123456789012345678901234567890123456789012345678901234567890" + "12345678901234567890", + { 0x57, 0xed, 0xf4, 0xa2, 0x2b, 0xe3, 0xc9, 0x55, + 0xac, 0x49, 0xda, 0x2e, 0x21, 0x07, 0xb6, 0x7a } }, +}; + +struct arg { + int fd; + uint32_t ses; + char msg; +}; + +static void * +t_encrypt(void *v) +{ + struct crypt_op co; + unsigned char buf[16]; + struct arg *a = v; + int res; + + for (;;) { + for (size_t i = 0; i < __arraycount(tests); i++) { + memset(&co, 0, sizeof(co)); + memset(&buf, 0, sizeof(buf)); + co.ses = a->ses; + co.op = COP_ENCRYPT; + co.len = tests[i].len; + co.src = __UNCONST(&tests[i].plaintx); + co.mac = buf; + res = ioctl(a->fd, CIOCCRYPT, &co); + if (res < 0) + warn("CIOCCRYPT"); + if (memcmp(co.mac, tests[i].digest, sizeof(tests[i].digest))) + errx(1, "verification failed test %zu", i); + fprintf(stderr, "%c", a->msg); + } + } +} + + +int +main(void) +{ + int res; + size_t i; + struct session_op cs; + pthread_t t; + struct arg a, b; + + a.fd = open("/dev/crypto", O_RDWR, 0); + if (a.fd < 0) + err(1, "open"); + memset(&cs, 0, sizeof(cs)); + cs.mac = CRYPTO_MD5; + res = ioctl(a.fd, CIOCGSESSION, &cs); + if (res < 0) + err(1, "CIOCGSESSION"); + a.ses = cs.ses; + + a.msg = '-'; + pthread_create(&t, NULL, t_encrypt, &a); + b = a; + b.msg = '+'; + pthread_create(&t, NULL, t_encrypt, &b); + sleep(1); + res = ioctl(a.fd, CIOCFSESSION, &cs.ses); + if (res == -1) { + warn("CIOCFSESSION"); + return EXIT_FAILURE; + } + res = ioctl(a.fd, CIOCFSESSION, &cs.ses); + if (res != -1) { + warnx("double free success"); + return EXIT_FAILURE; + } + return EXIT_SUCCESS; +} Index: t_opencrypto.sh =================================================================== RCS file: /cvsroot/src/tests/crypto/opencrypto/t_opencrypto.sh,v retrieving revision 1.11 diff -u -p -u -r1.11 t_opencrypto.sh --- t_opencrypto.sh 18 Apr 2025 23:35:31 -0000 1.11 +++ t_opencrypto.sh 23 Apr 2026 23:44:37 -0000 @@ -295,6 +295,19 @@ xcbcmac_cleanup() { common_cleanup } +atf_test_case thread cleanup +thread_head() { + common_head "Test threaded crypto" +} + +thread_body() { + common_body h_thread +} + +thread_cleanup() { + common_cleanup +} + atf_test_case ioctl cleanup ioctl_head() { common_head "Test ioctl for /dev/crypto" @@ -333,5 +346,6 @@ atf_init_test_cases() { atf_add_test_case sha1_hmac atf_add_test_case sha2_hmac atf_add_test_case xcbcmac + atf_add_test_case thread atf_add_test_case ioctl }