head	1.6;
access;
symbols
	netbsd-11-0-RC5:1.5
	netbsd-11-0-RC4:1.5
	netbsd-11-0-RC3:1.5
	netbsd-11-0-RC2:1.5
	netbsd-11-0-RC1:1.5
	perseant-exfatfs-base-20250801:1.5
	netbsd-11:1.5.0.12
	netbsd-11-base:1.5
	netbsd-10-1-RELEASE:1.5
	perseant-exfatfs-base-20240630:1.5
	perseant-exfatfs:1.5.0.10
	perseant-exfatfs-base:1.5
	netbsd-8-3-RELEASE:1.3
	netbsd-9-4-RELEASE:1.4
	netbsd-10-0-RELEASE:1.5
	netbsd-10-0-RC6:1.5
	netbsd-10-0-RC5:1.5
	netbsd-10-0-RC4:1.5
	netbsd-10-0-RC3:1.5
	netbsd-10-0-RC2:1.5
	netbsd-10-0-RC1:1.5
	netbsd-10:1.5.0.8
	netbsd-10-base:1.5
	netbsd-9-3-RELEASE:1.4
	cjep_sun2x-base1:1.5
	cjep_sun2x:1.5.0.6
	cjep_sun2x-base:1.5
	cjep_staticlib_x-base1:1.5
	netbsd-9-2-RELEASE:1.4
	cjep_staticlib_x:1.5.0.4
	cjep_staticlib_x-base:1.5
	netbsd-9-1-RELEASE:1.4
	phil-wifi-20200421:1.5
	phil-wifi-20200411:1.5
	is-mlppp:1.5.0.2
	is-mlppp-base:1.5
	phil-wifi-20200406:1.5
	netbsd-8-2-RELEASE:1.3
	netbsd-9-0-RELEASE:1.4
	netbsd-9-0-RC2:1.4
	netbsd-9-0-RC1:1.4
	phil-wifi-20191119:1.4
	netbsd-9:1.4.0.8
	netbsd-9-base:1.4
	phil-wifi-20190609:1.4
	netbsd-8-1-RELEASE:1.3
	netbsd-8-1-RC1:1.3
	pgoyette-compat-merge-20190127:1.4
	pgoyette-compat-20190127:1.4
	pgoyette-compat-20190118:1.4
	pgoyette-compat-1226:1.4
	pgoyette-compat-1126:1.4
	pgoyette-compat-1020:1.4
	pgoyette-compat-0930:1.4
	pgoyette-compat-0906:1.4
	netbsd-7-2-RELEASE:1.2
	pgoyette-compat-0728:1.4
	netbsd-8-0-RELEASE:1.3
	phil-wifi:1.4.0.6
	phil-wifi-base:1.4
	pgoyette-compat-0625:1.4
	netbsd-8-0-RC2:1.3
	pgoyette-compat-0521:1.4
	pgoyette-compat-0502:1.4
	pgoyette-compat-0422:1.4
	netbsd-8-0-RC1:1.3
	pgoyette-compat-0415:1.4
	pgoyette-compat-0407:1.4
	pgoyette-compat-0330:1.4
	pgoyette-compat-0322:1.4
	pgoyette-compat-0315:1.4
	netbsd-7-1-2-RELEASE:1.2
	pgoyette-compat:1.4.0.4
	pgoyette-compat-base:1.4
	netbsd-7-1-1-RELEASE:1.2
	matt-nb8-mediatek:1.3.0.6
	matt-nb8-mediatek-base:1.3
	perseant-stdc-iso10646:1.4.0.2
	perseant-stdc-iso10646-base:1.4
	netbsd-8:1.3.0.4
	netbsd-8-base:1.3
	prg-localcount2-base3:1.3
	prg-localcount2-base2:1.3
	prg-localcount2-base1:1.3
	prg-localcount2:1.3.0.2
	prg-localcount2-base:1.3
	pgoyette-localcount-20170426:1.3
	bouyer-socketcan-base1:1.3
	pgoyette-localcount-20170320:1.2
	netbsd-7-1:1.2.0.18
	netbsd-7-1-RELEASE:1.2
	netbsd-7-1-RC2:1.2
	netbsd-7-nhusb-base-20170116:1.2
	bouyer-socketcan:1.2.0.16
	bouyer-socketcan-base:1.2
	pgoyette-localcount-20170107:1.2
	netbsd-7-1-RC1:1.2
	pgoyette-localcount-20161104:1.2
	netbsd-7-0-2-RELEASE:1.2
	localcount-20160914:1.2
	netbsd-7-nhusb:1.2.0.14
	netbsd-7-nhusb-base:1.2
	pgoyette-localcount-20160806:1.2
	pgoyette-localcount-20160726:1.2
	pgoyette-localcount:1.2.0.12
	pgoyette-localcount-base:1.2
	netbsd-7-0-1-RELEASE:1.2
	netbsd-7-0:1.2.0.10
	netbsd-7-0-RELEASE:1.2
	netbsd-7-0-RC3:1.2
	netbsd-7-0-RC2:1.2
	netbsd-7-0-RC1:1.2
	tls-maxphys-base:1.2
	tls-maxphys:1.2.0.8
	netbsd-7:1.2.0.6
	netbsd-7-base:1.2
	yamt-pagecache:1.2.0.4
	yamt-pagecache-base9:1.2
	tls-earlyentropy:1.2.0.2
	tls-earlyentropy-base:1.2
	riastradh-xf86-video-intel-2-7-1-pre-2-21-15:1.2
	riastradh-drm2-base3:1.2;
locks; strict;
comment	@# @;


1.6
date	2026.04.25.00.37.29;	author christos;	state Exp;
branches;
next	1.5;
commitid	Y9jWsK7XhTdK4hDG;

1.5
date	2019.12.03.04.20.45;	author hikaru;	state Exp;
branches
	1.5.8.1
	1.5.12.1;
next	1.4;
commitid	ZM2reoYjIvXFmdNB;

1.4
date	2017.06.09.06.09.02;	author knakahara;	state Exp;
branches
	1.4.6.1;
next	1.3;
commitid	aCCEb98twlrr7FUz;

1.3
date	2017.04.17.03.59.37;	author knakahara;	state Exp;
branches;
next	1.2;
commitid	SBKEGOJ0379O6QNz;

1.2
date	2014.01.17.22.33.02;	author pgoyette;	state Exp;
branches
	1.2.4.1
	1.2.8.1
	1.2.12.1
	1.2.16.1;
next	1.1;
commitid	uF40A6LGIONfowlx;

1.1
date	2014.01.14.17.51.39;	author pgoyette;	state Exp;
branches;
next	;
commitid	oRH1A3BChCjoV6lx;

1.5.8.1
date	2026.06.27.15.25.56;	author martin;	state Exp;
branches;
next	;
commitid	kQjWoBo6mm57YrLG;

1.5.12.1
date	2026.06.27.15.23.23;	author martin;	state Exp;
branches;
next	;
commitid	YcbudnMnnbffXrLG;

1.4.6.1
date	2020.04.08.14.09.05;	author martin;	state Exp;
branches;
next	;
commitid	Qli2aW9E74UFuA3C;

1.2.4.1
date	2014.01.17.22.33.02;	author yamt;	state dead;
branches;
next	1.2.4.2;
commitid	30ZGlhv2KNB1MwBx;

1.2.4.2
date	2014.05.22.11.42.17;	author yamt;	state Exp;
branches;
next	;
commitid	30ZGlhv2KNB1MwBx;

1.2.8.1
date	2014.01.17.22.33.02;	author tls;	state dead;
branches;
next	1.2.8.2;
commitid	jTnpym9Qu0o4R1Nx;

1.2.8.2
date	2014.08.20.00.04.46;	author tls;	state Exp;
branches;
next	;
commitid	jTnpym9Qu0o4R1Nx;

1.2.12.1
date	2017.04.26.02.53.32;	author pgoyette;	state Exp;
branches;
next	;
commitid	ojV02aOSdzvBqZOz;

1.2.16.1
date	2017.04.21.16.54.09;	author bouyer;	state Exp;
branches;
next	;
commitid	dUG7nkTKALCadqOz;


desc
@@


1.6
log
@Add a threaded test to test for races in cryptodev.
@
text
@# $NetBSD: Makefile,v 1.5 2019/12/03 04:20:45 hikaru Exp $

.include <bsd.own.mk>

TESTSDIR=	${TESTSBASE}/crypto/opencrypto

TESTS_SH+=	t_opencrypto

BINDIR=		${TESTSDIR}
MKMAN=		no

PROGS+=		h_aescbc
PROGS+=		h_aesctr1
PROGS+=		h_aesctr2
PROGS+=		h_arc4
PROGS+=		h_camellia
PROGS+=		h_cbcdes
PROGS+=		h_cbc3des
PROGS+=		h_comp
PROGS+=		h_comp_zlib
PROGS+=		h_comp_zlib_rnd
PROGS+=		h_gcm
PROGS+=		h_md5
PROGS+=		h_md5hmac
PROGS+=		h_null
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 <bsd.test.mk>
@


1.5
log
@Add HMAC-SHA-{256,384,512} test cases.
@
text
@d1 1
a1 1
# $NetBSD: Makefile,v 1.4 2017/06/09 06:09:02 knakahara Exp $
d30 1
d33 1
d35 3
@


1.5.8.1
log
@Pull up following revision(s) (requested by riastradh in ticket #1278):

	sys/opencrypto/cryptodev.c: revision 1.130
	sys/opencrypto/cryptodev.c: revision 1.131
	sys/opencrypto/cryptodev.c: revision 1.132
	sys/opencrypto/cryptodev.c: revision 1.133
	tests/crypto/opencrypto/Makefile: revision 1.6
	sys/opencrypto/cryptosoft.c: revision 1.67
	sys/opencrypto/ocryptodev.c: revision 1.19
	tests/crypto/opencrypto/h_thread.c: revision 1.1
	sys/rump/dev/lib/libopencrypto/OPENCRYPTO.ioconf: revision 1.2
	tests/crypto/opencrypto/h_thread.c: revision 1.2
	sys/rump/dev/lib/libopencrypto/opencrypto_component.c: revision 1.7
	tests/crypto/opencrypto/t_opencrypto.sh: revision 1.12
	tests/crypto/opencrypto/t_opencrypto.sh: revision 1.13
	sys/opencrypto/cryptodev_internal.h: revision 1.5
	tests/crypto/opencrypto/t_opencrypto.sh: revision 1.14
	sys/opencrypto/cryptodev.c: revision 1.129
	distrib/sets/lists/debug/mi: revision 1.512
	distrib/sets/lists/tests/mi: revision 1.1417

Add a threaded test to test for races in cryptodev.
new thread cryptodev test


crypto(4): Make test more reliable, and test more.
1. New thread to concurrently create and destroy sessions.
   (There should really be multiple threads to concurrently compete
   with each other to create and destroy sessions, but this is
   already surfacing more crashes, as I expected.)
2. Handle EBUSY in CIOCFSESSION in case there is a concurrent
   CIOCCRYPT, as we are trying to test.
3. Handle CIOCCRYPT failure if a concurrent CIOCFSESSION beat us to
   it, as we are trying to test
4. Dump core if the threads get stuck for too long.
5. Provide stack traces from the test program or rump server if they
   dump core.
PR kern/60281: crypto(4): bugs in reference counting and test


crypto(4): Take reference _before_ releasing the lock.

Otherwise nothing ensures the object will still exist by the time we
try to take the reference.

Also guard against too many references, since this is only a 32-bit
reference count.
PR kern/60281: crypto(4): bugs in reference counting and test


crypto(4): Fix missing membars on reference count release.

If two threads A and B both hold references, we need to ensure that
memory ops in thread A happen before memory free in thread B in:
thread A                thread B                notes
--------                --------                -----
memory ops
atomic_dec(&refcnt)                             goes from 2 to 1
                        atomic_dec(&refcnt)     goes from 1 to 0
                        memory free

This requires a membar_release in thread A before the atomic_dec (or
atomic_dec with memory_order_release), and a membar_acquire in thread
B after the atomic_dec is found to have brought the reference count
down to zero (or atomic_dec wiht memory_order_acquire).
kern/60281: crypto(4): bugs in reference counting and test


crypto(4): Disentangle initialization and attachment goo.
Lotta unnecessary boilerplate deleted here!

Disable module unloading: can't be done safely.  Explain precisely
why it can't be done safely.

This also fixes annoying `crypto: unable to register devsw, error 17'
messages in rump dmesg by having exactly one path to devsw_attach.
PR kern/60281: crypto(4): bugs in reference counting and test


crypto(4): Omit needless locking in fcrypt_dtor.

We must have exclusive access to the object for this function to work
at all, so if removing the locks appeared to cause issues, it would
necessarily happen only because there is a bug somewhere else.
PR kern/60281: crypto(4): bugs in reference counting and test
crypto(4): Nix spurious mutex_exit; add missing bounds checks.

Consistently use `foo = kmem_alloc(n * sizeof(*foo), ...)' instead of
`sizeof(struct whatever_foo_is)'.  Makes it easier for a reader to
notice a discrepancy this way.

Move CRYPTODEV_OPS_MAX to cryptodev_internal.h so it can be used by
the compat ocryptodev.c shims too.  I think this is waaaaaaaaaaaaay
too high, by the way.  For example, it looks like qat(4) puts a limit
of 16384 on the number of sessions.  Other devices like hifn(4) look
like they're limited to numbers of sessions ranging from 2 to around
256.
PR kern/60281: crypto(4): bugs in reference counting and test
@
text
@d1 1
a1 1
# $NetBSD: Makefile,v 1.5 2019/12/03 04:20:45 hikaru Exp $
a29 1
PROGS+=		h_thread
a31 1
DPADD.h_comp_zlib+=	${LIBZ}
a32 3
DPADD.h_comp_zlib_rnd+=	${LIBZ}
LDADD.h_thread+=	-lpthread
DPADD.h_thread+=	${LIBPTHREAD}
@


1.5.12.1
log
@Pull up following revision(s) (requested by riastradh in ticket #330):

	sys/opencrypto/cryptodev.c: revision 1.130
	sys/opencrypto/cryptodev.c: revision 1.131
	sys/opencrypto/cryptodev.c: revision 1.132
	sys/opencrypto/cryptodev.c: revision 1.133
	tests/crypto/opencrypto/Makefile: revision 1.6
	sys/opencrypto/cryptosoft.c: revision 1.67
	sys/opencrypto/ocryptodev.c: revision 1.19
	tests/crypto/opencrypto/h_thread.c: revision 1.1
	sys/rump/dev/lib/libopencrypto/OPENCRYPTO.ioconf: revision 1.2
	tests/crypto/opencrypto/h_thread.c: revision 1.2
	sys/rump/dev/lib/libopencrypto/opencrypto_component.c: revision 1.7
	tests/crypto/opencrypto/t_opencrypto.sh: revision 1.12
	tests/crypto/opencrypto/t_opencrypto.sh: revision 1.13
	sys/opencrypto/cryptodev_internal.h: revision 1.5
	tests/crypto/opencrypto/t_opencrypto.sh: revision 1.14
	sys/opencrypto/cryptodev.c: revision 1.129
	distrib/sets/lists/debug/mi: revision 1.512
	distrib/sets/lists/tests/mi: revision 1.1417

Add a threaded test to test for races in cryptodev.
new thread cryptodev test


crypto(4): Make test more reliable, and test more.
1. New thread to concurrently create and destroy sessions.
   (There should really be multiple threads to concurrently compete
   with each other to create and destroy sessions, but this is
   already surfacing more crashes, as I expected.)
2. Handle EBUSY in CIOCFSESSION in case there is a concurrent
   CIOCCRYPT, as we are trying to test.
3. Handle CIOCCRYPT failure if a concurrent CIOCFSESSION beat us to
   it, as we are trying to test
4. Dump core if the threads get stuck for too long.
5. Provide stack traces from the test program or rump server if they
   dump core.
PR kern/60281: crypto(4): bugs in reference counting and test


crypto(4): Take reference _before_ releasing the lock.

Otherwise nothing ensures the object will still exist by the time we
try to take the reference.

Also guard against too many references, since this is only a 32-bit
reference count.
PR kern/60281: crypto(4): bugs in reference counting and test


crypto(4): Fix missing membars on reference count release.

If two threads A and B both hold references, we need to ensure that
memory ops in thread A happen before memory free in thread B in:
thread A                thread B                notes
--------                --------                -----
memory ops
atomic_dec(&refcnt)                             goes from 2 to 1
                        atomic_dec(&refcnt)     goes from 1 to 0
                        memory free

This requires a membar_release in thread A before the atomic_dec (or
atomic_dec with memory_order_release), and a membar_acquire in thread
B after the atomic_dec is found to have brought the reference count
down to zero (or atomic_dec wiht memory_order_acquire).
kern/60281: crypto(4): bugs in reference counting and test


crypto(4): Disentangle initialization and attachment goo.
Lotta unnecessary boilerplate deleted here!

Disable module unloading: can't be done safely.  Explain precisely
why it can't be done safely.

This also fixes annoying `crypto: unable to register devsw, error 17'
messages in rump dmesg by having exactly one path to devsw_attach.
PR kern/60281: crypto(4): bugs in reference counting and test


crypto(4): Omit needless locking in fcrypt_dtor.

We must have exclusive access to the object for this function to work
at all, so if removing the locks appeared to cause issues, it would
necessarily happen only because there is a bug somewhere else.
PR kern/60281: crypto(4): bugs in reference counting and test
crypto(4): Nix spurious mutex_exit; add missing bounds checks.

Consistently use `foo = kmem_alloc(n * sizeof(*foo), ...)' instead of
`sizeof(struct whatever_foo_is)'.  Makes it easier for a reader to
notice a discrepancy this way.

Move CRYPTODEV_OPS_MAX to cryptodev_internal.h so it can be used by
the compat ocryptodev.c shims too.  I think this is waaaaaaaaaaaaay
too high, by the way.  For example, it looks like qat(4) puts a limit
of 16384 on the number of sessions.  Other devices like hifn(4) look
like they're limited to numbers of sessions ranging from 2 to around
256.
PR kern/60281: crypto(4): bugs in reference counting and test
@
text
@d1 1
a1 1
# $NetBSD: Makefile,v 1.5 2019/12/03 04:20:45 hikaru Exp $
a29 1
PROGS+=		h_thread
a31 1
DPADD.h_comp_zlib+=	${LIBZ}
a32 3
DPADD.h_comp_zlib_rnd+=	${LIBZ}
LDADD.h_thread+=	-lpthread
DPADD.h_thread+=	${LIBPTHREAD}
@


1.4
log
@add tests of ioctl for /dev/crypto
@
text
@d1 1
a1 1
# $NetBSD: Makefile,v 1.3 2017/04/17 03:59:37 knakahara Exp $
d27 1
@


1.4.6.1
log
@Merge changes from current as of 20200406
@
text
@d1 1
a1 1
# $NetBSD$
a26 1
PROGS+=		h_sha2hmac
@


1.3
log
@add opencrypto atf for CRYPTO_3DES_CBC and CRYPTO_AES_CBC(=CRYPTO_RIJNDAEL128_CBC).
@
text
@d1 1
a1 1
# $NetBSD: Makefile,v 1.2 2014/01/17 22:33:02 pgoyette Exp $
d28 1
a33 1

@


1.2
log
@Additional tests for SHA1_HMAC (with test cases from RFC2202)
@
text
@d1 1
a1 1
# $NetBSD: Makefile,v 1.1 2014/01/14 17:51:39 pgoyette Exp $
d12 1
d18 1
@


1.2.12.1
log
@Sync with HEAD
@
text
@d1 1
a1 1
# $NetBSD: Makefile,v 1.3 2017/04/17 03:59:37 knakahara Exp $
a11 1
PROGS+=		h_aescbc
a16 1
PROGS+=		h_cbc3des
@


1.2.16.1
log
@Sync with HEAD
@
text
@d1 1
a1 1
# $NetBSD: Makefile,v 1.3 2017/04/17 03:59:37 knakahara Exp $
a11 1
PROGS+=		h_aescbc
a16 1
PROGS+=		h_cbc3des
@


1.2.8.1
log
@file Makefile was added on branch tls-maxphys on 2014-08-20 00:04:46 +0000
@
text
@d1 31
@


1.2.8.2
log
@Rebase to HEAD as of a few days ago.
@
text
@a0 31
# $NetBSD$

.include <bsd.own.mk>

TESTSDIR=	${TESTSBASE}/crypto/opencrypto

TESTS_SH+=	t_opencrypto

BINDIR=		${TESTSDIR}
MKMAN=		no

PROGS+=		h_aesctr1
PROGS+=		h_aesctr2
PROGS+=		h_arc4
PROGS+=		h_camellia
PROGS+=		h_cbcdes
PROGS+=		h_comp
PROGS+=		h_comp_zlib
PROGS+=		h_comp_zlib_rnd
PROGS+=		h_gcm
PROGS+=		h_md5
PROGS+=		h_md5hmac
PROGS+=		h_null
PROGS+=		h_sha1hmac
PROGS+=		h_xcbcmac

LDADD.h_comp_zlib+=	-lz
LDADD.h_comp_zlib_rnd+=	-lz

.include <bsd.test.mk>

@


1.2.4.1
log
@file Makefile was added on branch yamt-pagecache on 2014-05-22 11:42:17 +0000
@
text
@d1 31
@


1.2.4.2
log
@sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs.  ("Protocol error: too many arguments")
@
text
@a0 31
# $NetBSD$

.include <bsd.own.mk>

TESTSDIR=	${TESTSBASE}/crypto/opencrypto

TESTS_SH+=	t_opencrypto

BINDIR=		${TESTSDIR}
MKMAN=		no

PROGS+=		h_aesctr1
PROGS+=		h_aesctr2
PROGS+=		h_arc4
PROGS+=		h_camellia
PROGS+=		h_cbcdes
PROGS+=		h_comp
PROGS+=		h_comp_zlib
PROGS+=		h_comp_zlib_rnd
PROGS+=		h_gcm
PROGS+=		h_md5
PROGS+=		h_md5hmac
PROGS+=		h_null
PROGS+=		h_sha1hmac
PROGS+=		h_xcbcmac

LDADD.h_comp_zlib+=	-lz
LDADD.h_comp_zlib_rnd+=	-lz

.include <bsd.test.mk>

@


1.1
log
@Add some trivial tests for the in-kernel opencrypto framework, and link
them into the build.  (Thanks to Matthias Drochner for the test programs!)

XXX The arc4 and null tests currently fail - under investigation.
@
text
@d1 1
a1 1
# $NetBSD: Makefile,v 1.9 2012/07/14 04:06:17 christos Exp $
d24 1
@

