Home | History | Annotate | only in /src/sbin/cgdconfig
History log of /src/sbin/cgdconfig
RevisionDateAuthorComments
 1.23 12-May-2024  christos PR/58212: Malte Dehling: Add zfs verification method
 1.22 12-Aug-2022  riastradh branches: 1.22.2;
cgdconfig(8): Add support for shared keys.

New clause `shared <id> algorithm <alg> subkey <info>' in a keygen
block enables `cgdconfig -C' to reuse a key between different params
files, so you can, e.g., use a single password for multiple disks.
This is better than simply caching the password itself because:

- Hashing the password is expensive, so it should only be done once.

Suppose your budget is time t before you get bored, and you
calibrate password hash parameters to unlock n disks before you get
bored waiting for `cgdconfig -C'.

. With n password hashings the adversary's cost goes up only by a
factor of t/n.
. With one password hashing and n subkeys the adversary's cost goes
up by a factor of n.

And if you ever add a disk, rehashing it will make `cgdconfig -C'
go over budget, whereas another subkey adds negligible cost to you.

- Subkeys work for other types of keygen blocks, like shell_cmd,
which could be used to get a key from a hardware token that needs a
button press.

The <info> parameter must be different for each params file;
everything else in the keygen block must be the same. With this
clause, the keygen block determines a shared key used only to derive
keys; the actual key used by cgdconfig is derived from the shared key
by the specified algorithm.

The only supported algorithm is hkdf-hmac-sha256, which uses
HKDF-Expand of RFC 5869 instantiated with SHA-256.

Example:

algorithm aes-cbc;
iv-method encblkno1;
keylength 128;
verify_method none;
keygen pkcs5_pbkdf2/sha1 {
iterations 39361;
salt AAAAgMoHiYonye6KogdYJAobCHE=;
shared "pw" algorithm hkdf-hmac-sha256
subkey AAAAgFlw0BMQ5gY+haYkZ6JC+yY=;
};

The key used for this disk will be derived by

HKDF-HMAC-SHA256_k(WXDQExDmBj6FpiRnokL7Jg==),

where k is the outcome of PBKDF2-SHA1 with the given parameters.

Note that <info> encodes a four-byte prefix giving the big-endian
length in bits of the info argument to HKDF, just like all other bit
strings in cgdconfig parameters files.

If you have multiple disks configured using the same keygen block
except for the info parameter, `cgdconfig -C' will only prompt once
for your passphrase, generate a shared key k with PBKDF2 as usual,
and then reuse it for each of the disks.
 1.21 17-May-2022  christos Use the Makefile.inc from libargon2 (fixes the vax build that requires
a compiler hack).
 1.20 16-May-2022  christos make things behave just like before the libcrypt symbol renaming:
The normal cgdconfig binary is built with threads and the crunched one
in rescue without.
 1.19 16-May-2022  christos Re-enable threads; apparently we get different results depending if we are
threaded or not... This tastes like a bug.
 1.18 15-May-2022  christos Build argon2 inline so that crunched programs work. I also disabled threads
for now; we can put them back if needed.
 1.17 28-Nov-2021  christos -lpthread to LDADD (fixes lint build)
 1.16 22-Nov-2021  nia cgdconfig(8): Add an argon2id password-based key generation method

This provides an extra level of side-channel and cracking resistance
compared to the pre-existing pkcs5_pbkdf2/sha1 method used for
password-based disk encryption.

Several new keygen parameters are supported:

memory (integer, in kilobytes)
parallelism (integer, usually the number of CPU cores)
version (integer, usually 19...)

We do our best to calibrate these automatically when the paramsfile
is initially generated.

lgtm riastradh@
 1.15 01-Jul-2016  christos replace openssl HMAC(3) with our hmac(3).
 1.14 14-Dec-2010  pooka Convert from the oldstyle cgd_kops.op_open to the newstyle prog_open
and define RUMPPRG. Get rid of the Makefile.inc stuff, since it was
useful only for the oldstyle regime.
 1.13 19-Dec-2009  pooka Use RUMP_ACTION to avoid having to specify the same information
in the Makefiles of all the consumers.
 1.12 08-Sep-2009  pooka * allow specification of kernel operations vector
* make it possible to build cgdconfig as a library
 1.11 20-Apr-2009  drochner define YY_NO_INPUT where appropriate, from Kurt J. Lidl per PR misc/41160
 1.10 24-Jul-2008  dholland branches: 1.10.4;
Adjust this to not need -Wno-pointer-sign.
 1.9 21-Jul-2008  gmcgarry Add HAVE_PCC tests for -Wno-pointer-sign.
 1.8 16-Feb-2008  matt branches: 1.8.4; 1.8.8;
Change incorrect usage of CFLAGS to CPPFLAGS
 1.7 11-May-2006  mrg branches: 1.7.10; 1.7.12;
sprinkle some -fno-strict-aliasing and -Wno-pointer-sign with GCC4.
 1.6 25-Feb-2006  simonb We link against libl and liby, so depend on them too.
 1.5 09-Mar-2005  christos Add -lcrypt where -lcrypto is specified.
 1.4 17-Apr-2003  thorpej We need -I., too.
 1.3 17-Apr-2003  fvdl -I. -> -I${.CURDIR}
 1.2 24-Mar-2003  elric substantial rototill of the code.

o added new features:
o -G: generate a new paramsfile that produces the same
key as the old paramsfile,
o ffs verify_method,
o multiple keygen methods that are xor'ed together
(for n-factor authentication), and
o calibrating the iteration count of PKCS#5 PBKDF2 to
the current machine's speed.
o changed paramsfile format to allow for the new features.
o replaced open-coded parser with yacc grammar.
o lots of supporting changes.
o updated documentation to reflect new features and new
paramsfile format.
 1.1 04-Oct-2002  elric Initial checkin of cgdconfig(8), a program to configure a cgd.
 1.7.12.1 18-Feb-2008  mjf Sync with HEAD.
 1.7.10.1 23-Mar-2008  matt sync with HEAD
 1.8.8.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.8.4.1 28-Sep-2008  mjf Sync with HEAD.
 1.10.4.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.22.2.1 11-Oct-2024  martin Pull up following revision(s) (requested by riastradh in ticket #941):

sbin/cgdconfig/params.c: revision 1.35
sbin/cgdconfig/params.h: revision 1.15
sbin/cgdconfig/cgdconfig.c: revision 1.62
sbin/cgdconfig/cgdconfig.c: revision 1.63
sbin/cgdconfig/cgdconfig.8: revision 1.58
sbin/cgdconfig/cgdconfig.8: revision 1.59
sbin/cgdconfig/Makefile: revision 1.23

cgdconfig(8): KNF in cgdconfig.c.
No functional change intended.

PR/58212: Malte Dehling: Add zfs verification method

cgdconfig(8): Estimate verify methods' false accept probabilities.
An addendum following discussion around:
PR bin/58212: cgdconfig(8): Add zfs verification method
 1.4 14-Dec-2010  pooka Convert from the oldstyle cgd_kops.op_open to the newstyle prog_open
and define RUMPPRG. Get rid of the Makefile.inc stuff, since it was
useful only for the oldstyle regime.
 1.3 05-Dec-2010  pooka mirror change of -lrumpcrypto ==> -lrumpkern_crypto
 1.2 19-Dec-2009  pooka Use RUMP_ACTION to avoid having to specify the same information
in the Makefiles of all the consumers.
 1.1 08-Sep-2009  pooka * allow specification of kernel operations vector
* make it possible to build cgdconfig as a library
 1.1 22-Nov-2021  nia cgdconfig(8): Add an argon2id password-based key generation method

This provides an extra level of side-channel and cracking resistance
compared to the pre-existing pkcs5_pbkdf2/sha1 method used for
password-based disk encryption.

Several new keygen parameters are supported:

memory (integer, in kilobytes)
parallelism (integer, usually the number of CPU cores)
version (integer, usually 19...)

We do our best to calibrate these automatically when the paramsfile
is initially generated.

lgtm riastradh@
 1.1 22-Nov-2021  nia cgdconfig(8): Add an argon2id password-based key generation method

This provides an extra level of side-channel and cracking resistance
compared to the pre-existing pkcs5_pbkdf2/sha1 method used for
password-based disk encryption.

Several new keygen parameters are supported:

memory (integer, in kilobytes)
parallelism (integer, usually the number of CPU cores)
version (integer, usually 19...)

We do our best to calibrate these automatically when the paramsfile
is initially generated.

lgtm riastradh@
 1.3 14-Dec-2010  pooka Convert from the oldstyle cgd_kops.op_open to the newstyle prog_open
and define RUMPPRG. Get rid of the Makefile.inc stuff, since it was
useful only for the oldstyle regime.
 1.2 13-Oct-2009  pooka fix prototypes of function pointers to varargs syscalls
 1.1 08-Sep-2009  pooka * allow specification of kernel operations vector
* make it possible to build cgdconfig as a library
 1.4 14-Dec-2010  pooka Convert from the oldstyle cgd_kops.op_open to the newstyle prog_open
and define RUMPPRG. Get rid of the Makefile.inc stuff, since it was
useful only for the oldstyle regime.
 1.3 13-Oct-2009  pooka fix prototypes of function pointers to varargs syscalls
 1.2 10-Sep-2009  pooka fix LP64 builds. yay, C type system.

patch from Joachim Kuebart
 1.1 08-Sep-2009  pooka * allow specification of kernel operations vector
* make it possible to build cgdconfig as a library
 1.2 14-Dec-2010  pooka Convert from the oldstyle cgd_kops.op_open to the newstyle prog_open
and define RUMPPRG. Get rid of the Makefile.inc stuff, since it was
useful only for the oldstyle regime.
 1.1 19-Dec-2009  pooka Use RUMP_ACTION to avoid having to specify the same information
in the Makefiles of all the consumers.
 1.59 09-Oct-2024  riastradh cgdconfig(8): Estimate verify methods' false accept probabilities.

An addendum following discussion around:

PR bin/58212: cgdconfig(8): Add zfs verification method
 1.58 12-May-2024  christos branches: 1.58.2;
PR/58212: Malte Dehling: Add zfs verification method
 1.57 12-Aug-2022  riastradh branches: 1.57.2;
cgdconfig(8): Handle -P/-S for shared keys with -G too.

This way you can convert an existing parameters file to one that is
derived from a shared key, and derive other subkeys for other disks
from the same shared key.

cgdconfig -G -S -o /etc/cgd/wd0.shared /etc/cgd/wd0
cgdconfig -G -S -o /etc/cgd/wd1.shared \
-P /etc/cgd/wd0.shared /etc/cgd/wd1

This way, if you enter the same new password both times, wd0.shared
and wd1.shared generate the same keys as wd0 and wd1, but only need
one password entry with `cgdconfig -C'.
 1.56 12-Aug-2022  riastradh cgdconfig(8): Add support for generating shared-key parameters files.

Usage model:

- Generate a parameters file that supports sharing its main key:

cgdconfig -g -S -o /etc/cgd/wd0e -V gpt adiantum

- Make another parameters file that uses the same shared main key but
derives an independent subkey from it:

cgdconfig -g -S -P /etc/cgd/wd0e -o /etc/cgd/ld1e \
-V disklabel aes-cbc 256
 1.55 12-Aug-2022  riastradh cgdconfig(8): Add support for shared keys.

New clause `shared <id> algorithm <alg> subkey <info>' in a keygen
block enables `cgdconfig -C' to reuse a key between different params
files, so you can, e.g., use a single password for multiple disks.
This is better than simply caching the password itself because:

- Hashing the password is expensive, so it should only be done once.

Suppose your budget is time t before you get bored, and you
calibrate password hash parameters to unlock n disks before you get
bored waiting for `cgdconfig -C'.

. With n password hashings the adversary's cost goes up only by a
factor of t/n.
. With one password hashing and n subkeys the adversary's cost goes
up by a factor of n.

And if you ever add a disk, rehashing it will make `cgdconfig -C'
go over budget, whereas another subkey adds negligible cost to you.

- Subkeys work for other types of keygen blocks, like shell_cmd,
which could be used to get a key from a hardware token that needs a
button press.

The <info> parameter must be different for each params file;
everything else in the keygen block must be the same. With this
clause, the keygen block determines a shared key used only to derive
keys; the actual key used by cgdconfig is derived from the shared key
by the specified algorithm.

The only supported algorithm is hkdf-hmac-sha256, which uses
HKDF-Expand of RFC 5869 instantiated with SHA-256.

Example:

algorithm aes-cbc;
iv-method encblkno1;
keylength 128;
verify_method none;
keygen pkcs5_pbkdf2/sha1 {
iterations 39361;
salt AAAAgMoHiYonye6KogdYJAobCHE=;
shared "pw" algorithm hkdf-hmac-sha256
subkey AAAAgFlw0BMQ5gY+haYkZ6JC+yY=;
};

The key used for this disk will be derived by

HKDF-HMAC-SHA256_k(WXDQExDmBj6FpiRnokL7Jg==),

where k is the outcome of PBKDF2-SHA1 with the given parameters.

Note that <info> encodes a four-byte prefix giving the big-endian
length in bits of the info argument to HKDF, just like all other bit
strings in cgdconfig parameters files.

If you have multiple disks configured using the same keygen block
except for the info parameter, `cgdconfig -C' will only prompt once
for your passphrase, generate a shared key k with PBKDF2 as usual,
and then reuse it for each of the disks.
 1.54 12-Aug-2022  riastradh cgdconfig(8): New -T operation prints all generated keys in cgd.conf.

For testing purposes.
 1.53 12-Aug-2022  riastradh cgdconfig(8): New -t operation just prints the derived key in base64.

For testing purposes.
 1.52 04-Dec-2021  nia cgdconfig.8: Use argon2id in examples
 1.51 22-Nov-2021  nia cgdconfig(8): Add an argon2id password-based key generation method

This provides an extra level of side-channel and cracking resistance
compared to the pre-existing pkcs5_pbkdf2/sha1 method used for
password-based disk encryption.

Several new keygen parameters are supported:

memory (integer, in kilobytes)
parallelism (integer, usually the number of CPU cores)
version (integer, usually 19...)

We do our best to calibrate these automatically when the paramsfile
is initially generated.

lgtm riastradh@
 1.50 30-Apr-2021  nia cgdconfig.8: use gpt in examples, it's more versatile for this use case
 1.49 18-Apr-2021  maya The -n flag is useless with -g, don't mention it.

From rudolf in PR misc/36243
 1.48 11-Dec-2020  riastradh Touch up cgdconfig(8) man page.

- Suggest adiantum first.
- Remove references to Blowfish.
- Clarify that ivmethod is relevant only for ancient compatibility.
 1.47 23-Jun-2020  wiz Use Nm.
 1.46 23-Jun-2020  nia cgdconfig.8: remove references to using cgd for swap

this is potentially misleading now that the kernel does swap encryption
 1.45 23-Jun-2020  nia cgdconfig.8: Reflect actual behaviour of /dev/(u)random
 1.44 29-Dec-2018  wiz Sort SEE ALSO.
 1.43 28-Dec-2018  alnsn s/Dec/December/.
 1.42 27-Dec-2018  alnsn Document that cgd.conf supports NAME=label and ROOT.<suffix> targets.

XXX Default paramsfile for NAME=label is /etc/cgd/dkNN (resolved wedge
partition) and /etc/cgd/ROOT.<suffix> for ROOT.<suffix>. This isn't yet
documented. IMO, it should be the other way around: /etc/cgd/label
for the former and /et/cgd/[root-device] for the latter.
 1.41 01-Sep-2018  prlw1 typo
 1.40 09-May-2018  kre branches: 1.40.2;

With the change to use getpass_r the 128 byte passphrase limit no
longer applies, so update the BUGS section here to reflect that change.
The limit now is 1023 whichever method is used to fetch the passphrase.
 1.39 09-May-2018  alnsn Add '-e' option (echo the passphrase) and wipe the passphrase after use.

XXX Using memset for wiping isn't a good idea because memset is likely
optimised away by gcc. This should be revisited.
 1.38 09-May-2018  wiz Add commas in enumeration.
 1.37 09-May-2018  kre Fix missing -p in usage message (noted by Christoph Badura, thanks),
and update -l usage as well.

While here fix man page synopses and a few other odds and ends.
 1.36 11-Sep-2016  sevan branches: 1.36.6; 1.36.12;
Spelling mistake.
Bump date.
 1.35 14-Dec-2014  wiz Bump date for previous. Fix typo.
 1.34 14-Dec-2014  mlelstv Add validation methods "mbr" and "gpt" for disks without a valid disklabel.
 1.33 05-Dec-2012  wiz Whitespace.
New sentence, new line.
 1.32 05-Dec-2012  christos add cgdconfig -l like vnconfig -l
 1.31 03-Jul-2011  dholland branches: 1.31.2; 1.31.8;
fix typo
 1.30 30-Mar-2010  joerg \\ -> \e
 1.29 19-Oct-2009  wiz Document -n, from Jukka Ruohonen in private mail.
Bump date.
 1.28 12-Sep-2008  christos PR/39525: Joachim Schueth, Frederik Sausmikat:
cgd inadvertently encrypts blkno eight times to generate IV
 1.27 13-May-2008  wiz Bump date for previous.
 1.26 11-May-2008  elric Add a new keygen method which will execute an external command and
take its output as the key. I've been meaning to do this for quite
a while...
 1.25 10-May-2008  elric Add -p flag to retrieve passphrases from stdin. This is mainly aimed
at programatic use where the caller wants to be able to use PKCS#5.

Disable looping on invalid verifications unless both a passphrase method
is in use and the -p flag is not specified.

Update man page to document -p flag.
 1.24 30-Apr-2008  martin branches: 1.24.2;
Convert TNF licenses to new 2 clause variant
 1.23 23-Feb-2007  rumble branches: 1.23.12; 1.23.14;
Add a DIAGNOSTICS section and explain that the error message "could not
calibrate pkcs5_pbkdf2" could have resulted due to dynamic changes in cpu
clock frequency.
 1.22 15-Oct-2004  salo Correct the omission in 're-enter' verification method addition in EXAMPLES.
 1.21 13-Aug-2004  wiz Bump date for previous, and re-add some flags that were removed in the
previous commit without a mention in the commit message, and which are
still in the usage.
 1.20 13-Aug-2004  tv Add "urandomkey" key generation method as described in PR kern/22766;
useful for configuring a throwaway key for cgd-on-swap at boot time.
 1.19 04-Jul-2004  elric Add options to SYNOPSIS.

Addresses PR misc/26065.
 1.18 17-Mar-2004  wiz branches: 1.18.2;
Drop trailing whitespace; new sentence, new line.
 1.17 17-Mar-2004  dan Fix a longstanding algorithmic flaw in PKCS#5 key generation.

The existing pkcs5_pbdkf2 keygen method is retained functionally
as-is, for compatibility with existing params files. The corrected
algorithm, which is now the default for new params file generation, is
called pkcs5_pbkdf2/sha1.

NB. The backwards compatibility for the miscreant keygen method will
be removed at the same time as support for the previous parameters
file syntax. Sometime between now and then, users should update their
params files using -G, which will create a new params file including
an xor value so that the resulting generated key is the same; they
should also

Problem discovery and 2-char algorithm fix by Charles Blundell, messy
compat goop by me, long complicated names by Roland Dowdeswell.

Update manpage accordingly and bump date.
 1.16 23-Sep-2003  wiz Add article.
 1.15 23-Sep-2003  cb add a new verification method that prompts for the pkcs#5 pbkdf2
passphrase again and checks the generated key against the original.
 1.14 27-Jun-2003  wiz Remove superfluous "".
 1.13 16-Apr-2003  wiz Bump date for last-but-one; remove superfluous .Pp.
 1.12 15-Apr-2003  elric Fix typo. params files are not stored in /dev/cgd/
 1.11 24-Mar-2003  elric substantial rototill of the code.

o added new features:
o -G: generate a new paramsfile that produces the same
key as the old paramsfile,
o ffs verify_method,
o multiple keygen methods that are xor'ed together
(for n-factor authentication), and
o calibrating the iteration count of PKCS#5 PBKDF2 to
the current machine's speed.
o changed paramsfile format to allow for the new features.
o replaced open-coded parser with yacc grammar.
o lots of supporting changes.
o updated documentation to reflect new features and new
paramsfile format.
 1.10 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.9 19-Jan-2003  atatat The next release will be 2.0, not 1.7.
 1.8 13-Oct-2002  elric At the suggestion of wiz@, we remove the lines that mention that the
lack of the feature added earlier today was a bug.
 1.7 12-Oct-2002  elric Add documentation for verification methods. Specify defaults for IV
method, keygen method and verification method.
 1.6 07-Oct-2002  wiz Begin new sentence in upper case.
 1.5 05-Oct-2002  grant cgdconfig first appeared in NetBSD 1.7 (for now).
 1.4 05-Oct-2002  grant New sentence, new line. Some mdoc cleanup, other minor nits.
 1.3 05-Oct-2002  dan note some other caveats and uses
 1.2 04-Oct-2002  dan channelling wiz
 1.1 04-Oct-2002  elric Initial checkin of cgdconfig(8), a program to configure a cgd.
 1.18.2.1 13-Aug-2004  tv Oy, sometimes CVS sticky tags hurt. Revert urandomkey; that should be on HEAD.
 1.23.14.1 18-May-2008  yamt sync with head.
 1.23.12.2 28-Sep-2008  mjf Sync with HEAD.
 1.23.12.1 02-Jun-2008  mjf Sync with HEAD.
 1.24.2.2 24-Sep-2008  wrstuden Merge in changes between wrstuden-revivesa-base-2 and
wrstuden-revivesa-base-3.
 1.24.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.31.8.1 25-Feb-2013  tls resync with head
 1.31.2.1 16-Jan-2013  yamt sync with (a bit old) head
 1.36.12.3 18-Jan-2019  pgoyette Synch with HEAD
 1.36.12.2 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.36.12.1 21-May-2018  pgoyette Sync with HEAD
 1.36.6.2 07-Aug-2018  martin Pull up following revision(s) (requested by alnsn in ticket #958):

sbin/cgdconfig/cgdconfig.c: revision 1.46
sbin/cgdconfig/cgdconfig.c: revision 1.47
sbin/cgdconfig/cgdconfig.c: revision 1.48
sbin/cgdconfig/cgdconfig.8: revision 1.39
sbin/cgdconfig/cgdconfig.8: revision 1.40

Add '-e' option (echo the passphrase) and wipe the passphrase after use.
XXX Using memset for wiping isn't a good idea because memset is likely
optimised away by gcc. This should be revisited.

Missed one change when doing a manual merge of my patch with kre's commit.

use explicit_memset(3)

With the change to use getpass_r the 128 byte passphrase limit no
longer applies, so update the BUGS section here to reflect that change.
The limit now is 1023 whichever method is used to fetch the passphrase.
 1.36.6.1 31-Jul-2018  martin Pull up following revision(s) (requested by kre in ticket #946):

sbin/cgdconfig/cgdconfig.c: revision 1.42
sbin/cgdconfig/cgdconfig.c: revision 1.43
sbin/cgdconfig/cgdconfig.c: revision 1.44
sbin/cgdconfig/cgdconfig.c: revision 1.45
sbin/cgdconfig/cgdconfig.8: revision 1.37
sbin/cgdconfig/cgdconfig.8: revision 1.38

Check whether the cgd device selected is available to be
configured,that is, not already in use, before requesting
passwords from the user (or elsewhere).

Fix usage for rump. Fixes test breakage caused by previous commit.
Check arg count in configure() at entry, rather than later.

This avoids the stupid null deref I added a couple of commits
ago (on bad usage) and also simplifies the rest of the routine
which no longer needs to check the arg count nearly as much.
Thanks to Alexander Nasonov for finding the null deref bug.

Fix missing -p in usage message (noted by Christoph Badura, thanks),
and update -l usage as well.
While here fix man page synopses and a few other odds and ends.
Add commas in enumeration.
 1.40.2.1 10-Jun-2019  christos Sync with HEAD
 1.57.2.1 11-Oct-2024  martin Pull up following revision(s) (requested by riastradh in ticket #941):

sbin/cgdconfig/params.c: revision 1.35
sbin/cgdconfig/params.h: revision 1.15
sbin/cgdconfig/cgdconfig.c: revision 1.62
sbin/cgdconfig/cgdconfig.c: revision 1.63
sbin/cgdconfig/cgdconfig.8: revision 1.58
sbin/cgdconfig/cgdconfig.8: revision 1.59
sbin/cgdconfig/Makefile: revision 1.23

cgdconfig(8): KNF in cgdconfig.c.
No functional change intended.

PR/58212: Malte Dehling: Add zfs verification method

cgdconfig(8): Estimate verify methods' false accept probabilities.
An addendum following discussion around:
PR bin/58212: cgdconfig(8): Add zfs verification method
 1.58.2.1 02-Aug-2025  perseant Sync with HEAD
 1.63 12-May-2024  christos PR/58212: Malte Dehling: Add zfs verification method
 1.62 29-Apr-2024  riastradh cgdconfig(8): KNF in cgdconfig.c.

No functional change intended.
 1.61 17-Nov-2022  chs branches: 1.61.2;
Restore backward compatibility of UFS2 with previous NetBSD releases by
disabling support in UFS2 for extended attributes (including ACLs).
Add a new variant of UFS2 called "UFS2ea" that does support extended attributes.
Add new fsck_ffs operations "-c ea" and "-c no-ea" to convert file systems
from UFS2 to UFS2ea and vice-versa (both of which delete all existing extended
attributes in the process).
 1.60 13-Sep-2022  riastradh cgdconfig(8): Restore loop for password re-entry for non-shared keys.

Fixes mistake in previous which changed the semantics in the case
where _no_ keys are shared.
 1.59 30-Aug-2022  riastradh cgdconfig(8): Gracefully handle failed verification with shared keys.

The first time each key is verified, if verification fails, we chuck
the failed key and try again with passphrase re-entry.

But if a key has already been verified, and verification fails,
assume something is wrong with the disk and fail.
 1.58 12-Aug-2022  riastradh cgdconfig(8): Handle -P/-S for shared keys with -G too.

This way you can convert an existing parameters file to one that is
derived from a shared key, and derive other subkeys for other disks
from the same shared key.

cgdconfig -G -S -o /etc/cgd/wd0.shared /etc/cgd/wd0
cgdconfig -G -S -o /etc/cgd/wd1.shared \
-P /etc/cgd/wd0.shared /etc/cgd/wd1

This way, if you enter the same new password both times, wd0.shared
and wd1.shared generate the same keys as wd0 and wd1, but only need
one password entry with `cgdconfig -C'.
 1.57 12-Aug-2022  riastradh cgdconfig(8): Add support for generating shared-key parameters files.

Usage model:

- Generate a parameters file that supports sharing its main key:

cgdconfig -g -S -o /etc/cgd/wd0e -V gpt adiantum

- Make another parameters file that uses the same shared main key but
derives an independent subkey from it:

cgdconfig -g -S -P /etc/cgd/wd0e -o /etc/cgd/ld1e \
-V disklabel aes-cbc 256
 1.56 12-Aug-2022  riastradh cgdconfig(8): Add support for shared keys.

New clause `shared <id> algorithm <alg> subkey <info>' in a keygen
block enables `cgdconfig -C' to reuse a key between different params
files, so you can, e.g., use a single password for multiple disks.
This is better than simply caching the password itself because:

- Hashing the password is expensive, so it should only be done once.

Suppose your budget is time t before you get bored, and you
calibrate password hash parameters to unlock n disks before you get
bored waiting for `cgdconfig -C'.

. With n password hashings the adversary's cost goes up only by a
factor of t/n.
. With one password hashing and n subkeys the adversary's cost goes
up by a factor of n.

And if you ever add a disk, rehashing it will make `cgdconfig -C'
go over budget, whereas another subkey adds negligible cost to you.

- Subkeys work for other types of keygen blocks, like shell_cmd,
which could be used to get a key from a hardware token that needs a
button press.

The <info> parameter must be different for each params file;
everything else in the keygen block must be the same. With this
clause, the keygen block determines a shared key used only to derive
keys; the actual key used by cgdconfig is derived from the shared key
by the specified algorithm.

The only supported algorithm is hkdf-hmac-sha256, which uses
HKDF-Expand of RFC 5869 instantiated with SHA-256.

Example:

algorithm aes-cbc;
iv-method encblkno1;
keylength 128;
verify_method none;
keygen pkcs5_pbkdf2/sha1 {
iterations 39361;
salt AAAAgMoHiYonye6KogdYJAobCHE=;
shared "pw" algorithm hkdf-hmac-sha256
subkey AAAAgFlw0BMQ5gY+haYkZ6JC+yY=;
};

The key used for this disk will be derived by

HKDF-HMAC-SHA256_k(WXDQExDmBj6FpiRnokL7Jg==),

where k is the outcome of PBKDF2-SHA1 with the given parameters.

Note that <info> encodes a four-byte prefix giving the big-endian
length in bits of the info argument to HKDF, just like all other bit
strings in cgdconfig parameters files.

If you have multiple disks configured using the same keygen block
except for the info parameter, `cgdconfig -C' will only prompt once
for your passphrase, generate a shared key k with PBKDF2 as usual,
and then reuse it for each of the disks.
 1.55 12-Aug-2022  riastradh cgdconfig(8): New -T operation prints all generated keys in cgd.conf.

For testing purposes.
 1.54 12-Aug-2022  riastradh cgdconfig(8): New -t operation just prints the derived key in base64.

For testing purposes.
 1.53 22-Nov-2021  nia cgdconfig(8): Add an argon2id password-based key generation method

This provides an extra level of side-channel and cracking resistance
compared to the pre-existing pkcs5_pbkdf2/sha1 method used for
password-based disk encryption.

Several new keygen parameters are supported:

memory (integer, in kilobytes)
parallelism (integer, usually the number of CPU cores)
version (integer, usually 19...)

We do our best to calibrate these automatically when the paramsfile
is initially generated.

lgtm riastradh@
 1.52 16-Jun-2021  riastradh cgdconfig(8): Fail more gracefully than SIGSEGV if shell_cmd fails.
 1.51 18-Apr-2021  maya The -n flag is useless with -g, don't mention it.

From rudolf in PR misc/36243
 1.50 10-Apr-2019  kre KNF, 80 column police, a few other tidy ups (use if (ret == 0) rather
than if (!ret) when ret is not a boolean, and test fopen result against
NULL, for example).

NFCI.
 1.49 10-Apr-2019  kre PR bin/53999 from rudolf (eq.cz)

Fix cgdconfig to report verification failures with gpt and mbr
verification methods (and not treat them as silent hard errors).
This also causes the cgd to be unconfigured when one of those
verification methods fails.

Add ATF tests to check that bad verification is reported, and
does not leave the cgd configured.

Patches from the PR applied.
 1.48 09-May-2018  alnsn branches: 1.48.2;
use explicit_memset(3)
 1.47 09-May-2018  alnsn Missed one change when doing a manual merge of my patch with kre's commit.
 1.46 09-May-2018  alnsn Add '-e' option (echo the passphrase) and wipe the passphrase after use.

XXX Using memset for wiping isn't a good idea because memset is likely
optimised away by gcc. This should be revisited.
 1.45 09-May-2018  kre Fix missing -p in usage message (noted by Christoph Badura, thanks),
and update -l usage as well.

While here fix man page synopses and a few other odds and ends.
 1.44 09-May-2018  kre Check arg count in configure() at entry, rather than later.
This avoids the stupid null deref I added a couple of commits
ago (on bad usage) and also simplifies the rest of the routine
which no longer needs to check the arg count nearly as much.

Thanks to Alexander Nasonov for finding the null deref bug.
 1.43 06-May-2018  kre Fix usage for rump. Fixes test breakage caused by previous commit.
 1.42 05-May-2018  kre Check whether the cgd device selected is available to be
configured,that is, not already in use, before requesting
passwords from the user (or elsewhere).
 1.41 10-Jan-2017  christos branches: 1.41.6; 1.41.12;
Need <sys/stat.h> for S_IFBLK.
 1.40 22-Nov-2015  christos branches: 1.40.2;
Don't chdir to the config directory; just form the parameters file with a
path if needed.
 1.39 14-Dec-2014  christos fix possibly uninitialized variable.
 1.38 14-Dec-2014  christos avoid local variable shadowing devname.
 1.37 14-Dec-2014  mlelstv Add validation methods "mbr" and "gpt" for disks without a valid disklabel.
 1.36 14-Dec-2014  mlelstv support wedge names.

The default param file for a wedge is still named after the device (dkN)
which might be unpredictable. Use an explicit param file instead.
 1.35 09-Jun-2013  christos List all cgd's no matter if they are not contiguously allocated
 1.34 05-Dec-2012  christos add cgdconfig -l like vnconfig -l
 1.33 29-Aug-2011  joerg branches: 1.33.2; 1.33.8;
Use __dead
 1.32 14-Dec-2010  pooka Convert from the oldstyle cgd_kops.op_open to the newstyle prog_open
and define RUMPPRG. Get rid of the Makefile.inc stuff, since it was
useful only for the oldstyle regime.
 1.31 02-Dec-2010  elric Remove a line that was intended only for my personal testing and that
breaks things.
 1.30 02-Dec-2010  elric In -G, refuse to operate if KEYGEN_URANDOM is specified as we already do
for KEYGEN_RANDOMKEY.

Print a warning if such a refusal is made---this will help the user understand
why there is an error.

Patch provided by: Taylor R Campbell <campbell+netbsd@mumble.net>.
 1.29 27-Nov-2010  elric Remove trailing whitespace (patch provided by: Taylor R Campbell
<campbell+netbsd@mumble.net>)
 1.28 08-Sep-2009  pooka * allow specification of kernel operations vector
* make it possible to build cgdconfig as a library
 1.27 24-Jul-2008  christos PR/39525: Joachim Schueth, Frederik Sausmikat:
cgd inadvertently encrypts blkno eight times to generate IV

Add "encblkno1" IV type to encrypt only once, rename old "encblkno" to
"encblkno8" for clarity, and make "encblkno" an alias for "encblkno8"
for backward compatibility.
 1.26 24-Jul-2008  dholland bzero the passphrase before freeing it, to discourage chill attacks.
 1.25 24-Jul-2008  dholland Adjust this to not need -Wno-pointer-sign.
 1.24 20-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.23 11-May-2008  elric Add a new keygen method which will execute an external command and
take its output as the key. I've been meaning to do this for quite
a while...
 1.22 10-May-2008  elric Add -p flag to retrieve passphrases from stdin. This is mainly aimed
at programatic use where the caller wants to be able to use PKCS#5.

Disable looping on invalid verifications unless both a passphrase method
is in use and the -p flag is not specified.

Update man page to document -p flag.
 1.21 28-Apr-2008  martin branches: 1.21.2;
Remove clause 3 and 4 from TNF licenses
 1.20 06-Nov-2007  martin branches: 1.20.8; 1.20.10;
Do not use %d for size_t
 1.19 06-Nov-2007  christos 3 month roland feedback timeout:
- Pass lint
- knf
- convert ints to size_t's
 1.18 06-Feb-2007  cbiere branches: 1.18.4;
Fixed format string in opendisk_werror() which was wrong since my previous
commit.
 1.17 06-Feb-2007  cbiere * 1 -> EXIT_FAILURE.
* Replaced atoi() with parse_int().
* Use an enum for ACTION_* instead of #define.
* Use strdup() or asnprintf() instead of strlcpy() to avoid truncation.
* pread() returns ssize_t not int.
* Suppress "unused parameter" warnings.
* verify_disklabel(): Pass the correct size to disklabel_scan().
* verify_ffs():
* Don't indicate success if pread() fails.
* Check the amount of bytes read.
* Don't cast buf to (struct fs *), it's not aligned.
* eliminate_cores(): No need for a temporary variable.
 1.16 27-Jun-2005  christos - constify.
- don't dup extern declarations on each file because they end up being
inconsistent (yyerror).
 1.15 30-Mar-2005  elric setprogname(3) needs to come before calls to err(3).
 1.14 30-Mar-2005  elric Lock all memory.
 1.13 30-Mar-2005  elric Turn off core dumps.
 1.12 13-Aug-2004  tv Add "urandomkey" key generation method as described in PR kern/22766;
useful for configuring a throwaway key for cgd-on-swap at boot time.
 1.11 10-Aug-2004  rumble In getkey(), check the return values of the various keygen functions
and abort if necessary. Also, check for errors in its callers and
handle them gracefully.

OK'd by elric.
 1.10 17-Mar-2004  dan branches: 1.10.2;
Fix a longstanding algorithmic flaw in PKCS#5 key generation.

The existing pkcs5_pbdkf2 keygen method is retained functionally
as-is, for compatibility with existing params files. The corrected
algorithm, which is now the default for new params file generation, is
called pkcs5_pbkdf2/sha1.

NB. The backwards compatibility for the miscreant keygen method will
be removed at the same time as support for the previous parameters
file syntax. Sometime between now and then, users should update their
params files using -G, which will create a new params file including
an xor value so that the resulting generated key is the same; they
should also

Problem discovery and 2-char algorithm fix by Charles Blundell, messy
compat goop by me, long complicated names by Roland Dowdeswell.

Update manpage accordingly and bump date.
 1.9 23-Sep-2003  cb add a new verification method that prompts for the pkcs#5 pbkdf2
passphrase again and checks the generated key against the original.
 1.8 17-May-2003  itojun use strlcpy
 1.7 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.6 24-Mar-2003  elric Quick bugfix:
o need to do keygen_filldefaults() in generate_convert no
matter what, not only if there are no existing keygen
methods in the new parameters.
 1.5 24-Mar-2003  elric substantial rototill of the code.

o added new features:
o -G: generate a new paramsfile that produces the same
key as the old paramsfile,
o ffs verify_method,
o multiple keygen methods that are xor'ed together
(for n-factor authentication), and
o calibrating the iteration count of PKCS#5 PBKDF2 to
the current machine's speed.
o changed paramsfile format to allow for the new features.
o replaced open-coded parser with yacc grammar.
o lots of supporting changes.
o updated documentation to reflect new features and new
paramsfile format.
 1.4 28-Oct-2002  elric bugfix: was still pulling random bits from /dev/random when generating
a paramsfile of type randomkey which does not need them. Pointed out
by dan@netbsd.org.
 1.3 12-Oct-2002  elric Add the concept of a verification method which allows cgdconfig(8)
to reprompt for the passphrase if the key does not meet certain
criteria. The currently implemented methods are ``none'' and
``disklabel''. The first behaves in the original fashion, the
second will scan for a disklabel on the cgd after configuration
and if it does not find a disklabel then it will reprompt for the
password and reconfigure the disk.
 1.2 12-Oct-2002  elric Small usage enhancement: open the cgd before prompting for the passphrase
so that errors can be reported w/o asking for the passphrase unnec.
 1.1 04-Oct-2002  elric Initial checkin of cgdconfig(8), a program to configure a cgd.
 1.10.2.1 13-Aug-2004  tv Oy, sometimes CVS sticky tags hurt. Revert urandomkey; that should be on HEAD.
 1.18.4.4 23-Mar-2008  matt sync with HEAD
 1.18.4.3 08-Jan-2008  matt Pull in changes from HEAD to make compile
 1.18.4.2 08-Nov-2007  matt sync with HEAD
 1.18.4.1 06-Nov-2007  matt sync with HEAD
 1.20.10.1 18-May-2008  yamt sync with head.
 1.20.8.2 28-Sep-2008  mjf Sync with HEAD.
 1.20.8.1 02-Jun-2008  mjf Sync with HEAD.
 1.21.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.21.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.33.8.2 23-Jun-2013  tls resync from head
 1.33.8.1 25-Feb-2013  tls resync with head
 1.33.2.2 22-May-2014  yamt 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")
 1.33.2.1 16-Jan-2013  yamt sync with (a bit old) head
 1.40.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.41.12.1 21-May-2018  pgoyette Sync with HEAD
 1.41.6.2 07-Aug-2018  martin Pull up following revision(s) (requested by alnsn in ticket #958):

sbin/cgdconfig/cgdconfig.c: revision 1.46
sbin/cgdconfig/cgdconfig.c: revision 1.47
sbin/cgdconfig/cgdconfig.c: revision 1.48
sbin/cgdconfig/cgdconfig.8: revision 1.39
sbin/cgdconfig/cgdconfig.8: revision 1.40

Add '-e' option (echo the passphrase) and wipe the passphrase after use.
XXX Using memset for wiping isn't a good idea because memset is likely
optimised away by gcc. This should be revisited.

Missed one change when doing a manual merge of my patch with kre's commit.

use explicit_memset(3)

With the change to use getpass_r the 128 byte passphrase limit no
longer applies, so update the BUGS section here to reflect that change.
The limit now is 1023 whichever method is used to fetch the passphrase.
 1.41.6.1 31-Jul-2018  martin Pull up following revision(s) (requested by kre in ticket #946):

sbin/cgdconfig/cgdconfig.c: revision 1.42
sbin/cgdconfig/cgdconfig.c: revision 1.43
sbin/cgdconfig/cgdconfig.c: revision 1.44
sbin/cgdconfig/cgdconfig.c: revision 1.45
sbin/cgdconfig/cgdconfig.8: revision 1.37
sbin/cgdconfig/cgdconfig.8: revision 1.38

Check whether the cgd device selected is available to be
configured,that is, not already in use, before requesting
passwords from the user (or elsewhere).

Fix usage for rump. Fixes test breakage caused by previous commit.
Check arg count in configure() at entry, rather than later.

This avoids the stupid null deref I added a couple of commits
ago (on bad usage) and also simplifies the rest of the routine
which no longer needs to check the arg count nearly as much.
Thanks to Alexander Nasonov for finding the null deref bug.

Fix missing -p in usage message (noted by Christoph Badura, thanks),
and update -l usage as well.
While here fix man page synopses and a few other odds and ends.
Add commas in enumeration.
 1.48.2.1 10-Jun-2019  christos Sync with HEAD
 1.61.2.1 11-Oct-2024  martin Pull up following revision(s) (requested by riastradh in ticket #941):

sbin/cgdconfig/params.c: revision 1.35
sbin/cgdconfig/params.h: revision 1.15
sbin/cgdconfig/cgdconfig.c: revision 1.62
sbin/cgdconfig/cgdconfig.c: revision 1.63
sbin/cgdconfig/cgdconfig.8: revision 1.58
sbin/cgdconfig/cgdconfig.8: revision 1.59
sbin/cgdconfig/Makefile: revision 1.23

cgdconfig(8): KNF in cgdconfig.c.
No functional change intended.

PR/58212: Malte Dehling: Add zfs verification method

cgdconfig(8): Estimate verify methods' false accept probabilities.
An addendum following discussion around:
PR bin/58212: cgdconfig(8): Add zfs verification method
 1.2 22-Nov-2015  christos Don't chdir to the config directory; just form the parameters file with a
path if needed.
 1.1 08-Sep-2009  pooka Remember to add cgdconfig.h too.
 1.1 14-Dec-2010  pooka Convert from the oldstyle cgd_kops.op_open to the newstyle prog_open
and define RUMPPRG. Get rid of the Makefile.inc stuff, since it was
useful only for the oldstyle regime.
 1.1 14-Dec-2010  pooka Convert from the oldstyle cgd_kops.op_open to the newstyle prog_open
and define RUMPPRG. Get rid of the Makefile.inc stuff, since it was
useful only for the oldstyle regime.
 1.7 12-Aug-2022  riastradh cgdconfig(8): Add support for shared keys.

New clause `shared <id> algorithm <alg> subkey <info>' in a keygen
block enables `cgdconfig -C' to reuse a key between different params
files, so you can, e.g., use a single password for multiple disks.
This is better than simply caching the password itself because:

- Hashing the password is expensive, so it should only be done once.

Suppose your budget is time t before you get bored, and you
calibrate password hash parameters to unlock n disks before you get
bored waiting for `cgdconfig -C'.

. With n password hashings the adversary's cost goes up only by a
factor of t/n.
. With one password hashing and n subkeys the adversary's cost goes
up by a factor of n.

And if you ever add a disk, rehashing it will make `cgdconfig -C'
go over budget, whereas another subkey adds negligible cost to you.

- Subkeys work for other types of keygen blocks, like shell_cmd,
which could be used to get a key from a hardware token that needs a
button press.

The <info> parameter must be different for each params file;
everything else in the keygen block must be the same. With this
clause, the keygen block determines a shared key used only to derive
keys; the actual key used by cgdconfig is derived from the shared key
by the specified algorithm.

The only supported algorithm is hkdf-hmac-sha256, which uses
HKDF-Expand of RFC 5869 instantiated with SHA-256.

Example:

algorithm aes-cbc;
iv-method encblkno1;
keylength 128;
verify_method none;
keygen pkcs5_pbkdf2/sha1 {
iterations 39361;
salt AAAAgMoHiYonye6KogdYJAobCHE=;
shared "pw" algorithm hkdf-hmac-sha256
subkey AAAAgFlw0BMQ5gY+haYkZ6JC+yY=;
};

The key used for this disk will be derived by

HKDF-HMAC-SHA256_k(WXDQExDmBj6FpiRnokL7Jg==),

where k is the outcome of PBKDF2-SHA1 with the given parameters.

Note that <info> encodes a four-byte prefix giving the big-endian
length in bits of the info argument to HKDF, just like all other bit
strings in cgdconfig parameters files.

If you have multiple disks configured using the same keygen block
except for the info parameter, `cgdconfig -C' will only prompt once
for your passphrase, generate a shared key k with PBKDF2 as usual,
and then reuse it for each of the disks.
 1.6 22-Nov-2021  nia cgdconfig(8): Add an argon2id password-based key generation method

This provides an extra level of side-channel and cracking resistance
compared to the pre-existing pkcs5_pbkdf2/sha1 method used for
password-based disk encryption.

Several new keygen parameters are supported:

memory (integer, in kilobytes)
parallelism (integer, usually the number of CPU cores)
version (integer, usually 19...)

We do our best to calibrate these automatically when the paramsfile
is initially generated.

lgtm riastradh@
 1.5 29-Oct-2009  christos use %option instead of #define YY_NO_...
 1.4 28-Oct-2009  christos no unput
 1.3 11-May-2008  elric Add a new keygen method which will execute an external command and
take its output as the key. I've been meaning to do this for quite
a while...
 1.2 28-Apr-2008  martin branches: 1.2.2;
Remove clause 3 and 4 from TNF licenses
 1.1 24-Mar-2003  elric branches: 1.1.32; 1.1.34;
substantial rototill of the code.

o added new features:
o -G: generate a new paramsfile that produces the same
key as the old paramsfile,
o ffs verify_method,
o multiple keygen methods that are xor'ed together
(for n-factor authentication), and
o calibrating the iteration count of PKCS#5 PBKDF2 to
the current machine's speed.
o changed paramsfile format to allow for the new features.
o replaced open-coded parser with yacc grammar.
o lots of supporting changes.
o updated documentation to reflect new features and new
paramsfile format.
 1.1.34.1 18-May-2008  yamt sync with head.
 1.1.32.1 02-Jun-2008  mjf Sync with HEAD.
 1.2.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.7 12-Aug-2022  riastradh cgdconfig(8): Add support for shared keys.

New clause `shared <id> algorithm <alg> subkey <info>' in a keygen
block enables `cgdconfig -C' to reuse a key between different params
files, so you can, e.g., use a single password for multiple disks.
This is better than simply caching the password itself because:

- Hashing the password is expensive, so it should only be done once.

Suppose your budget is time t before you get bored, and you
calibrate password hash parameters to unlock n disks before you get
bored waiting for `cgdconfig -C'.

. With n password hashings the adversary's cost goes up only by a
factor of t/n.
. With one password hashing and n subkeys the adversary's cost goes
up by a factor of n.

And if you ever add a disk, rehashing it will make `cgdconfig -C'
go over budget, whereas another subkey adds negligible cost to you.

- Subkeys work for other types of keygen blocks, like shell_cmd,
which could be used to get a key from a hardware token that needs a
button press.

The <info> parameter must be different for each params file;
everything else in the keygen block must be the same. With this
clause, the keygen block determines a shared key used only to derive
keys; the actual key used by cgdconfig is derived from the shared key
by the specified algorithm.

The only supported algorithm is hkdf-hmac-sha256, which uses
HKDF-Expand of RFC 5869 instantiated with SHA-256.

Example:

algorithm aes-cbc;
iv-method encblkno1;
keylength 128;
verify_method none;
keygen pkcs5_pbkdf2/sha1 {
iterations 39361;
salt AAAAgMoHiYonye6KogdYJAobCHE=;
shared "pw" algorithm hkdf-hmac-sha256
subkey AAAAgFlw0BMQ5gY+haYkZ6JC+yY=;
};

The key used for this disk will be derived by

HKDF-HMAC-SHA256_k(WXDQExDmBj6FpiRnokL7Jg==),

where k is the outcome of PBKDF2-SHA1 with the given parameters.

Note that <info> encodes a four-byte prefix giving the big-endian
length in bits of the info argument to HKDF, just like all other bit
strings in cgdconfig parameters files.

If you have multiple disks configured using the same keygen block
except for the info parameter, `cgdconfig -C' will only prompt once
for your passphrase, generate a shared key k with PBKDF2 as usual,
and then reuse it for each of the disks.
 1.6 22-Nov-2021  nia cgdconfig(8): Add an argon2id password-based key generation method

This provides an extra level of side-channel and cracking resistance
compared to the pre-existing pkcs5_pbkdf2/sha1 method used for
password-based disk encryption.

Several new keygen parameters are supported:

memory (integer, in kilobytes)
parallelism (integer, usually the number of CPU cores)
version (integer, usually 19...)

We do our best to calibrate these automatically when the paramsfile
is initially generated.

lgtm riastradh@
 1.5 17-Jul-2008  drochner include <stdlib.h> explicitely, for exit(), getprogname() etc.
(it happens to be pulled in by the yacc skeleton, but we shouldn't
rely on this)
 1.4 11-May-2008  elric Add a new keygen method which will execute an external command and
take its output as the key. I've been meaning to do this for quite
a while...
 1.3 28-Apr-2008  martin branches: 1.3.2;
Remove clause 3 and 4 from TNF licenses
 1.2 27-Jun-2005  christos branches: 1.2.20; 1.2.22;
- constify.
- don't dup extern declarations on each file because they end up being
inconsistent (yyerror).
 1.1 24-Mar-2003  elric substantial rototill of the code.

o added new features:
o -G: generate a new paramsfile that produces the same
key as the old paramsfile,
o ffs verify_method,
o multiple keygen methods that are xor'ed together
(for n-factor authentication), and
o calibrating the iteration count of PKCS#5 PBKDF2 to
the current machine's speed.
o changed paramsfile format to allow for the new features.
o replaced open-coded parser with yacc grammar.
o lots of supporting changes.
o updated documentation to reflect new features and new
paramsfile format.
 1.2.22.1 18-May-2008  yamt sync with head.
 1.2.20.2 28-Sep-2008  mjf Sync with HEAD.
 1.2.20.1 02-Jun-2008  mjf Sync with HEAD.
 1.3.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.3.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.2 16-Feb-2008  matt yyerror returns void, not int
 1.1 27-Jun-2005  christos branches: 1.1.10; 1.1.12;
- constify.
- don't dup extern declarations on each file because they end up being
inconsistent (yyerror).
 1.1.12.1 18-Feb-2008  mjf Sync with HEAD.
 1.1.10.1 23-Mar-2008  matt sync with HEAD
 1.1 12-Aug-2022  riastradh cgdconfig(8): Add support for shared keys.

New clause `shared <id> algorithm <alg> subkey <info>' in a keygen
block enables `cgdconfig -C' to reuse a key between different params
files, so you can, e.g., use a single password for multiple disks.
This is better than simply caching the password itself because:

- Hashing the password is expensive, so it should only be done once.

Suppose your budget is time t before you get bored, and you
calibrate password hash parameters to unlock n disks before you get
bored waiting for `cgdconfig -C'.

. With n password hashings the adversary's cost goes up only by a
factor of t/n.
. With one password hashing and n subkeys the adversary's cost goes
up by a factor of n.

And if you ever add a disk, rehashing it will make `cgdconfig -C'
go over budget, whereas another subkey adds negligible cost to you.

- Subkeys work for other types of keygen blocks, like shell_cmd,
which could be used to get a key from a hardware token that needs a
button press.

The <info> parameter must be different for each params file;
everything else in the keygen block must be the same. With this
clause, the keygen block determines a shared key used only to derive
keys; the actual key used by cgdconfig is derived from the shared key
by the specified algorithm.

The only supported algorithm is hkdf-hmac-sha256, which uses
HKDF-Expand of RFC 5869 instantiated with SHA-256.

Example:

algorithm aes-cbc;
iv-method encblkno1;
keylength 128;
verify_method none;
keygen pkcs5_pbkdf2/sha1 {
iterations 39361;
salt AAAAgMoHiYonye6KogdYJAobCHE=;
shared "pw" algorithm hkdf-hmac-sha256
subkey AAAAgFlw0BMQ5gY+haYkZ6JC+yY=;
};

The key used for this disk will be derived by

HKDF-HMAC-SHA256_k(WXDQExDmBj6FpiRnokL7Jg==),

where k is the outcome of PBKDF2-SHA1 with the given parameters.

Note that <info> encodes a four-byte prefix giving the big-endian
length in bits of the info argument to HKDF, just like all other bit
strings in cgdconfig parameters files.

If you have multiple disks configured using the same keygen block
except for the info parameter, `cgdconfig -C' will only prompt once
for your passphrase, generate a shared key k with PBKDF2 as usual,
and then reuse it for each of the disks.
 1.1 12-Aug-2022  riastradh cgdconfig(8): Add support for shared keys.

New clause `shared <id> algorithm <alg> subkey <info>' in a keygen
block enables `cgdconfig -C' to reuse a key between different params
files, so you can, e.g., use a single password for multiple disks.
This is better than simply caching the password itself because:

- Hashing the password is expensive, so it should only be done once.

Suppose your budget is time t before you get bored, and you
calibrate password hash parameters to unlock n disks before you get
bored waiting for `cgdconfig -C'.

. With n password hashings the adversary's cost goes up only by a
factor of t/n.
. With one password hashing and n subkeys the adversary's cost goes
up by a factor of n.

And if you ever add a disk, rehashing it will make `cgdconfig -C'
go over budget, whereas another subkey adds negligible cost to you.

- Subkeys work for other types of keygen blocks, like shell_cmd,
which could be used to get a key from a hardware token that needs a
button press.

The <info> parameter must be different for each params file;
everything else in the keygen block must be the same. With this
clause, the keygen block determines a shared key used only to derive
keys; the actual key used by cgdconfig is derived from the shared key
by the specified algorithm.

The only supported algorithm is hkdf-hmac-sha256, which uses
HKDF-Expand of RFC 5869 instantiated with SHA-256.

Example:

algorithm aes-cbc;
iv-method encblkno1;
keylength 128;
verify_method none;
keygen pkcs5_pbkdf2/sha1 {
iterations 39361;
salt AAAAgMoHiYonye6KogdYJAobCHE=;
shared "pw" algorithm hkdf-hmac-sha256
subkey AAAAgFlw0BMQ5gY+haYkZ6JC+yY=;
};

The key used for this disk will be derived by

HKDF-HMAC-SHA256_k(WXDQExDmBj6FpiRnokL7Jg==),

where k is the outcome of PBKDF2-SHA1 with the given parameters.

Note that <info> encodes a four-byte prefix giving the big-endian
length in bits of the info argument to HKDF, just like all other bit
strings in cgdconfig parameters files.

If you have multiple disks configured using the same keygen block
except for the info parameter, `cgdconfig -C' will only prompt once
for your passphrase, generate a shared key k with PBKDF2 as usual,
and then reuse it for each of the disks.
 1.35 12-May-2024  christos PR/58212: Malte Dehling: Add zfs verification method
 1.34 12-Aug-2022  riastradh branches: 1.34.2;
cgdconfig(8): Add support for generating shared-key parameters files.

Usage model:

- Generate a parameters file that supports sharing its main key:

cgdconfig -g -S -o /etc/cgd/wd0e -V gpt adiantum

- Make another parameters file that uses the same shared main key but
derives an independent subkey from it:

cgdconfig -g -S -P /etc/cgd/wd0e -o /etc/cgd/ld1e \
-V disklabel aes-cbc 256
 1.33 12-Aug-2022  riastradh cgdconfig(8): Add support for shared keys.

New clause `shared <id> algorithm <alg> subkey <info>' in a keygen
block enables `cgdconfig -C' to reuse a key between different params
files, so you can, e.g., use a single password for multiple disks.
This is better than simply caching the password itself because:

- Hashing the password is expensive, so it should only be done once.

Suppose your budget is time t before you get bored, and you
calibrate password hash parameters to unlock n disks before you get
bored waiting for `cgdconfig -C'.

. With n password hashings the adversary's cost goes up only by a
factor of t/n.
. With one password hashing and n subkeys the adversary's cost goes
up by a factor of n.

And if you ever add a disk, rehashing it will make `cgdconfig -C'
go over budget, whereas another subkey adds negligible cost to you.

- Subkeys work for other types of keygen blocks, like shell_cmd,
which could be used to get a key from a hardware token that needs a
button press.

The <info> parameter must be different for each params file;
everything else in the keygen block must be the same. With this
clause, the keygen block determines a shared key used only to derive
keys; the actual key used by cgdconfig is derived from the shared key
by the specified algorithm.

The only supported algorithm is hkdf-hmac-sha256, which uses
HKDF-Expand of RFC 5869 instantiated with SHA-256.

Example:

algorithm aes-cbc;
iv-method encblkno1;
keylength 128;
verify_method none;
keygen pkcs5_pbkdf2/sha1 {
iterations 39361;
salt AAAAgMoHiYonye6KogdYJAobCHE=;
shared "pw" algorithm hkdf-hmac-sha256
subkey AAAAgFlw0BMQ5gY+haYkZ6JC+yY=;
};

The key used for this disk will be derived by

HKDF-HMAC-SHA256_k(WXDQExDmBj6FpiRnokL7Jg==),

where k is the outcome of PBKDF2-SHA1 with the given parameters.

Note that <info> encodes a four-byte prefix giving the big-endian
length in bits of the info argument to HKDF, just like all other bit
strings in cgdconfig parameters files.

If you have multiple disks configured using the same keygen block
except for the info parameter, `cgdconfig -C' will only prompt once
for your passphrase, generate a shared key k with PBKDF2 as usual,
and then reuse it for each of the disks.
 1.32 22-Nov-2021  nia cgdconfig(8): Add an argon2id password-based key generation method

This provides an extra level of side-channel and cracking resistance
compared to the pre-existing pkcs5_pbkdf2/sha1 method used for
password-based disk encryption.

Several new keygen parameters are supported:

memory (integer, in kilobytes)
parallelism (integer, usually the number of CPU cores)
version (integer, usually 19...)

We do our best to calibrate these automatically when the paramsfile
is initially generated.

lgtm riastradh@
 1.31 03-Jun-2021  prlw1 Make adiantum a first class citizen
 1.30 30-Dec-2018  mlelstv branches: 1.30.8;
Avoid crash when no algorithm is specified in parameter file.
 1.29 11-Dec-2016  alnsn branches: 1.29.12; 1.29.14;
Add aes-xts to cgdconfig(8).
 1.28 24-Nov-2015  christos branches: 1.28.2;
CID 1340063: fix TOCTOU
 1.27 22-Nov-2015  christos Don't chdir to the config directory; just form the parameters file with a
path if needed.
 1.26 16-Jun-2015  christos fix error messages containing \n
 1.25 14-Dec-2014  mlelstv Add validation methods "mbr" and "gpt" for disks without a valid disklabel.
 1.24 12-Sep-2008  christos PR/39525: Joachim Schueth, Frederik Sausmikat:
cgd inadvertently encrypts blkno eight times to generate IV
 1.23 11-May-2008  elric Add a new keygen method which will execute an external command and
take its output as the key. I've been meaning to do this for quite
a while...
 1.22 28-Apr-2008  martin branches: 1.22.2;
Remove clause 3 and 4 from TNF licenses
 1.21 11-Nov-2007  christos branches: 1.21.8; 1.21.10;
simplify and fix the combination code. Hi pooka.
 1.20 06-Nov-2007  christos 3 month roland feedback timeout:
- Pass lint
- knf
- convert ints to size_t's
 1.19 06-Feb-2007  cbiere branches: 1.19.4;
Use warn() and warnx().
 1.18 06-Feb-2007  cbiere crypt_defaults_lookup():
* Avoid comparison of int with unsigned.
* Simplified.
 1.17 17-Jan-2007  hubertf Remove more duplicate #includes,
from Slava Semushin <slava.semushin@gmail.com>
 1.16 26-Aug-2006  christos Programs that use efun.
 1.15 17-Mar-2006  elad Proper bounds check, found by Coverity, CID 1468.
 1.14 27-Jun-2005  christos - constify.
- don't dup extern declarations on each file because they end up being
inconsistent (yyerror).
 1.13 30-Mar-2005  christos Centralize error checking for malloc,calloc,strdup.
 1.12 04-Jan-2005  elric Fix comment. We're using microseconds not milliseconds.
 1.11 04-Jan-2005  elric Fix bits vs. bytes problem in call to calibration routine.
 1.10 13-Aug-2004  tv Add "urandomkey" key generation method as described in PR kern/22766;
useful for configuring a throwaway key for cgd-on-swap at boot time.
 1.9 17-Mar-2004  dan branches: 1.9.2;
Fix a longstanding algorithmic flaw in PKCS#5 key generation.

The existing pkcs5_pbdkf2 keygen method is retained functionally
as-is, for compatibility with existing params files. The corrected
algorithm, which is now the default for new params file generation, is
called pkcs5_pbkdf2/sha1.

NB. The backwards compatibility for the miscreant keygen method will
be removed at the same time as support for the previous parameters
file syntax. Sometime between now and then, users should update their
params files using -G, which will create a new params file including
an xor value so that the resulting generated key is the same; they
should also

Problem discovery and 2-char algorithm fix by Charles Blundell, messy
compat goop by me, long complicated names by Roland Dowdeswell.

Update manpage accordingly and bump date.
 1.8 23-Sep-2003  cb add a new verification method that prompts for the pkcs#5 pbkdf2
passphrase again and checks the generated key against the original.
 1.7 13-Jul-2003  itojun die if asprintf fails to malloc
 1.6 10-Apr-2003  elric If reading an old style parameters file then default a missing
keygen_iteration to 128. This will not default the iteration count
on a new style parameter file as it is an error in the new style
to fail to specify the iteration count.

Addresses PR: bin/21056
 1.5 24-Mar-2003  elric substantial rototill of the code.

o added new features:
o -G: generate a new paramsfile that produces the same
key as the old paramsfile,
o ffs verify_method,
o multiple keygen methods that are xor'ed together
(for n-factor authentication), and
o calibrating the iteration count of PKCS#5 PBKDF2 to
the current machine's speed.
o changed paramsfile format to allow for the new features.
o replaced open-coded parser with yacc grammar.
o lots of supporting changes.
o updated documentation to reflect new features and new
paramsfile format.
 1.4 04-Dec-2002  elric Make iteration count for PKCS#5 settable in the parameters files.
 1.3 30-Nov-2002  lukem tweaks for fparseln(3) move from libutil to libc:
- remove #include <util.h> if nothing else needed it
- remove LDFLAGS+=-lutil if nothing else needed it
 1.2 12-Oct-2002  elric Add the concept of a verification method which allows cgdconfig(8)
to reprompt for the passphrase if the key does not meet certain
criteria. The currently implemented methods are ``none'' and
``disklabel''. The first behaves in the original fashion, the
second will scan for a disklabel on the cgd after configuration
and if it does not find a disklabel then it will reprompt for the
password and reconfigure the disk.
 1.1 04-Oct-2002  elric Initial checkin of cgdconfig(8), a program to configure a cgd.
 1.9.2.1 13-Aug-2004  tv Oy, sometimes CVS sticky tags hurt. Revert urandomkey; that should be on HEAD.
 1.19.4.2 09-Jan-2008  matt sync with HEAD
 1.19.4.1 06-Nov-2007  matt sync with HEAD
 1.21.10.1 18-May-2008  yamt sync with head.
 1.21.8.2 28-Sep-2008  mjf Sync with HEAD.
 1.21.8.1 02-Jun-2008  mjf Sync with HEAD.
 1.22.2.2 24-Sep-2008  wrstuden Merge in changes between wrstuden-revivesa-base-2 and
wrstuden-revivesa-base-3.
 1.22.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.28.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.29.14.1 10-Jun-2019  christos Sync with HEAD
 1.29.12.1 18-Jan-2019  pgoyette Synch with HEAD
 1.30.8.1 06-Jun-2021  cjep sync with head
 1.34.2.1 11-Oct-2024  martin Pull up following revision(s) (requested by riastradh in ticket #941):

sbin/cgdconfig/params.c: revision 1.35
sbin/cgdconfig/params.h: revision 1.15
sbin/cgdconfig/cgdconfig.c: revision 1.62
sbin/cgdconfig/cgdconfig.c: revision 1.63
sbin/cgdconfig/cgdconfig.8: revision 1.58
sbin/cgdconfig/cgdconfig.8: revision 1.59
sbin/cgdconfig/Makefile: revision 1.23

cgdconfig(8): KNF in cgdconfig.c.
No functional change intended.

PR/58212: Malte Dehling: Add zfs verification method

cgdconfig(8): Estimate verify methods' false accept probabilities.
An addendum following discussion around:
PR bin/58212: cgdconfig(8): Add zfs verification method
 1.15 12-May-2024  christos PR/58212: Malte Dehling: Add zfs verification method
 1.14 12-Aug-2022  riastradh branches: 1.14.2;
cgdconfig(8): Add support for generating shared-key parameters files.

Usage model:

- Generate a parameters file that supports sharing its main key:

cgdconfig -g -S -o /etc/cgd/wd0e -V gpt adiantum

- Make another parameters file that uses the same shared main key but
derives an independent subkey from it:

cgdconfig -g -S -P /etc/cgd/wd0e -o /etc/cgd/ld1e \
-V disklabel aes-cbc 256
 1.13 12-Aug-2022  riastradh cgdconfig(8): Add support for shared keys.

New clause `shared <id> algorithm <alg> subkey <info>' in a keygen
block enables `cgdconfig -C' to reuse a key between different params
files, so you can, e.g., use a single password for multiple disks.
This is better than simply caching the password itself because:

- Hashing the password is expensive, so it should only be done once.

Suppose your budget is time t before you get bored, and you
calibrate password hash parameters to unlock n disks before you get
bored waiting for `cgdconfig -C'.

. With n password hashings the adversary's cost goes up only by a
factor of t/n.
. With one password hashing and n subkeys the adversary's cost goes
up by a factor of n.

And if you ever add a disk, rehashing it will make `cgdconfig -C'
go over budget, whereas another subkey adds negligible cost to you.

- Subkeys work for other types of keygen blocks, like shell_cmd,
which could be used to get a key from a hardware token that needs a
button press.

The <info> parameter must be different for each params file;
everything else in the keygen block must be the same. With this
clause, the keygen block determines a shared key used only to derive
keys; the actual key used by cgdconfig is derived from the shared key
by the specified algorithm.

The only supported algorithm is hkdf-hmac-sha256, which uses
HKDF-Expand of RFC 5869 instantiated with SHA-256.

Example:

algorithm aes-cbc;
iv-method encblkno1;
keylength 128;
verify_method none;
keygen pkcs5_pbkdf2/sha1 {
iterations 39361;
salt AAAAgMoHiYonye6KogdYJAobCHE=;
shared "pw" algorithm hkdf-hmac-sha256
subkey AAAAgFlw0BMQ5gY+haYkZ6JC+yY=;
};

The key used for this disk will be derived by

HKDF-HMAC-SHA256_k(WXDQExDmBj6FpiRnokL7Jg==),

where k is the outcome of PBKDF2-SHA1 with the given parameters.

Note that <info> encodes a four-byte prefix giving the big-endian
length in bits of the info argument to HKDF, just like all other bit
strings in cgdconfig parameters files.

If you have multiple disks configured using the same keygen block
except for the info parameter, `cgdconfig -C' will only prompt once
for your passphrase, generate a shared key k with PBKDF2 as usual,
and then reuse it for each of the disks.
 1.12 22-Nov-2021  nia cgdconfig(8): Add an argon2id password-based key generation method

This provides an extra level of side-channel and cracking resistance
compared to the pre-existing pkcs5_pbkdf2/sha1 method used for
password-based disk encryption.

Several new keygen parameters are supported:

memory (integer, in kilobytes)
parallelism (integer, usually the number of CPU cores)
version (integer, usually 19...)

We do our best to calibrate these automatically when the paramsfile
is initially generated.

lgtm riastradh@
 1.11 14-Dec-2014  mlelstv Add validation methods "mbr" and "gpt" for disks without a valid disklabel.
 1.10 11-May-2008  elric Add a new keygen method which will execute an external command and
take its output as the key. I've been meaning to do this for quite
a while...
 1.9 28-Apr-2008  martin branches: 1.9.2;
Remove clause 3 and 4 from TNF licenses
 1.8 06-Nov-2007  christos branches: 1.8.8; 1.8.10;
3 month roland feedback timeout:
- Pass lint
- knf
- convert ints to size_t's
 1.7 13-Aug-2004  tv branches: 1.7.16;
Add "urandomkey" key generation method as described in PR kern/22766;
useful for configuring a throwaway key for cgd-on-swap at boot time.
 1.6 17-Mar-2004  dan branches: 1.6.2;
Fix a longstanding algorithmic flaw in PKCS#5 key generation.

The existing pkcs5_pbdkf2 keygen method is retained functionally
as-is, for compatibility with existing params files. The corrected
algorithm, which is now the default for new params file generation, is
called pkcs5_pbkdf2/sha1.

NB. The backwards compatibility for the miscreant keygen method will
be removed at the same time as support for the previous parameters
file syntax. Sometime between now and then, users should update their
params files using -G, which will create a new params file including
an xor value so that the resulting generated key is the same; they
should also

Problem discovery and 2-char algorithm fix by Charles Blundell, messy
compat goop by me, long complicated names by Roland Dowdeswell.

Update manpage accordingly and bump date.
 1.5 23-Sep-2003  cb add a new verification method that prompts for the pkcs#5 pbkdf2
passphrase again and checks the generated key against the original.
 1.4 24-Mar-2003  elric substantial rototill of the code.

o added new features:
o -G: generate a new paramsfile that produces the same
key as the old paramsfile,
o ffs verify_method,
o multiple keygen methods that are xor'ed together
(for n-factor authentication), and
o calibrating the iteration count of PKCS#5 PBKDF2 to
the current machine's speed.
o changed paramsfile format to allow for the new features.
o replaced open-coded parser with yacc grammar.
o lots of supporting changes.
o updated documentation to reflect new features and new
paramsfile format.
 1.3 04-Dec-2002  elric Make iteration count for PKCS#5 settable in the parameters files.
 1.2 12-Oct-2002  elric Add the concept of a verification method which allows cgdconfig(8)
to reprompt for the passphrase if the key does not meet certain
criteria. The currently implemented methods are ``none'' and
``disklabel''. The first behaves in the original fashion, the
second will scan for a disklabel on the cgd after configuration
and if it does not find a disklabel then it will reprompt for the
password and reconfigure the disk.
 1.1 04-Oct-2002  elric Initial checkin of cgdconfig(8), a program to configure a cgd.
 1.6.2.1 13-Aug-2004  tv Oy, sometimes CVS sticky tags hurt. Revert urandomkey; that should be on HEAD.
 1.7.16.1 06-Nov-2007  matt sync with HEAD
 1.8.10.1 18-May-2008  yamt sync with head.
 1.8.8.1 02-Jun-2008  mjf Sync with HEAD.
 1.9.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.14.2.1 11-Oct-2024  martin Pull up following revision(s) (requested by riastradh in ticket #941):

sbin/cgdconfig/params.c: revision 1.35
sbin/cgdconfig/params.h: revision 1.15
sbin/cgdconfig/cgdconfig.c: revision 1.62
sbin/cgdconfig/cgdconfig.c: revision 1.63
sbin/cgdconfig/cgdconfig.8: revision 1.58
sbin/cgdconfig/cgdconfig.8: revision 1.59
sbin/cgdconfig/Makefile: revision 1.23

cgdconfig(8): KNF in cgdconfig.c.
No functional change intended.

PR/58212: Malte Dehling: Add zfs verification method

cgdconfig(8): Estimate verify methods' false accept probabilities.
An addendum following discussion around:
PR bin/58212: cgdconfig(8): Add zfs verification method
 1.17 22-Nov-2021  nia cgdconfig(8): add some console feedback when calculating the number
of pkcs5_pbkdf2 iterations
 1.16 01-Jul-2016  christos replace openssl HMAC(3) with our hmac(3).
 1.15 27-Nov-2010  elric Remove trailing whitespace (patch provided by: Taylor R Campbell
<campbell+netbsd@mumble.net>)
 1.14 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.13 21-Apr-2008  christos PR/28627: Andreas Gustafsson: Try 5 times to calibrate before failing. Should
fix issues with CPU's that don't produce consistent timing output due to code
morphing or power-savings.
 1.12 06-Nov-2007  martin branches: 1.12.8; 1.12.10;
size_t != unsigned int - so don't pass the address of the former when a
pointer to the latter is expected.
 1.11 06-Nov-2007  christos 3 month roland feedback timeout:
- Pass lint
- knf
- convert ints to size_t's
 1.10 27-Jan-2007  cbiere branches: 1.10.4;
Replaced int_encode() with be32enc().
 1.9 26-Aug-2006  christos Programs that use efun.
 1.8 11-May-2006  mrg HMAC() wants unsigned int pointer for the final argument; make it so.
 1.7 30-Mar-2005  christos Centralize error checking for malloc,calloc,strdup.
 1.6 04-Jan-2005  elric s/milliseconds/microseconds/ in comments and a variable because it is
misleading to say one when we've been meaning the other.
 1.5 17-Mar-2004  dan Fix a longstanding algorithmic flaw in PKCS#5 key generation.

The existing pkcs5_pbdkf2 keygen method is retained functionally
as-is, for compatibility with existing params files. The corrected
algorithm, which is now the default for new params file generation, is
called pkcs5_pbkdf2/sha1.

NB. The backwards compatibility for the miscreant keygen method will
be removed at the same time as support for the previous parameters
file syntax. Sometime between now and then, users should update their
params files using -G, which will create a new params file including
an xor value so that the resulting generated key is the same; they
should also

Problem discovery and 2-char algorithm fix by Charles Blundell, messy
compat goop by me, long complicated names by Roland Dowdeswell.

Update manpage accordingly and bump date.
 1.4 25-Sep-2003  cb back out revision 1.3. this should not have been committed yet,
since it breaks backward compatibility.

noticed by recht@
 1.3 23-Sep-2003  cb add a new verification method that prompts for the pkcs#5 pbkdf2
passphrase again and checks the generated key against the original.
 1.2 24-Mar-2003  elric substantial rototill of the code.

o added new features:
o -G: generate a new paramsfile that produces the same
key as the old paramsfile,
o ffs verify_method,
o multiple keygen methods that are xor'ed together
(for n-factor authentication), and
o calibrating the iteration count of PKCS#5 PBKDF2 to
the current machine's speed.
o changed paramsfile format to allow for the new features.
o replaced open-coded parser with yacc grammar.
o lots of supporting changes.
o updated documentation to reflect new features and new
paramsfile format.
 1.1 04-Oct-2002  elric Initial checkin of cgdconfig(8), a program to configure a cgd.
 1.10.4.2 08-Nov-2007  matt sync with HEAD
 1.10.4.1 06-Nov-2007  matt sync with HEAD
 1.12.10.1 18-May-2008  yamt sync with head.
 1.12.8.1 02-Jun-2008  mjf Sync with HEAD.
 1.5 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.4 06-Nov-2007  christos branches: 1.4.8; 1.4.10;
3 month roland feedback timeout:
- Pass lint
- knf
- convert ints to size_t's
 1.3 17-Mar-2004  dan branches: 1.3.22;
Fix a longstanding algorithmic flaw in PKCS#5 key generation.

The existing pkcs5_pbdkf2 keygen method is retained functionally
as-is, for compatibility with existing params files. The corrected
algorithm, which is now the default for new params file generation, is
called pkcs5_pbkdf2/sha1.

NB. The backwards compatibility for the miscreant keygen method will
be removed at the same time as support for the previous parameters
file syntax. Sometime between now and then, users should update their
params files using -G, which will create a new params file including
an xor value so that the resulting generated key is the same; they
should also

Problem discovery and 2-char algorithm fix by Charles Blundell, messy
compat goop by me, long complicated names by Roland Dowdeswell.

Update manpage accordingly and bump date.
 1.2 24-Mar-2003  elric substantial rototill of the code.

o added new features:
o -G: generate a new paramsfile that produces the same
key as the old paramsfile,
o ffs verify_method,
o multiple keygen methods that are xor'ed together
(for n-factor authentication), and
o calibrating the iteration count of PKCS#5 PBKDF2 to
the current machine's speed.
o changed paramsfile format to allow for the new features.
o replaced open-coded parser with yacc grammar.
o lots of supporting changes.
o updated documentation to reflect new features and new
paramsfile format.
 1.1 04-Oct-2002  elric Initial checkin of cgdconfig(8), a program to configure a cgd.
 1.3.22.1 06-Nov-2007  matt sync with HEAD
 1.4.10.1 18-May-2008  yamt sync with head.
 1.4.8.1 02-Jun-2008  mjf Sync with HEAD.
 1.1 14-Dec-2010  pooka Convert from the oldstyle cgd_kops.op_open to the newstyle prog_open
and define RUMPPRG. Get rid of the Makefile.inc stuff, since it was
useful only for the oldstyle regime.
 1.21 20-Mar-2012  matt Convert to C89 function definitions
 1.20 11-Apr-2009  lukem branches: 1.20.6;
fix sign-compare issues
 1.19 11-May-2008  elric branches: 1.19.4;
Add a new keygen method which will execute an external command and
take its output as the key. I've been meaning to do this for quite
a while...
 1.18 28-Apr-2008  martin branches: 1.18.2;
Remove clause 3 and 4 from TNF licenses
 1.17 06-Nov-2007  christos branches: 1.17.8; 1.17.10;
3 month roland feedback timeout:
- Pass lint
- knf
- convert ints to size_t's
 1.16 06-Feb-2007  cbiere branches: 1.16.4;
memxor(): Fixed size_t/int mismatch.
 1.15 26-Aug-2006  christos Programs that use efun.
 1.14 11-May-2006  mrg __b64_pton() wants unsigned char *.
 1.13 22-Mar-2006  christos Coverity CID 2753: Free the correct variable.
 1.12 22-Mar-2006  christos fix compile problem.
 1.11 22-Mar-2006  christos Coverity CID 1593: Plug memory leak
 1.10 20-Mar-2006  christos Coverity CID 1203: Check return code of b64_ntop().
 1.9 27-Jun-2005  christos - constify.
- don't dup extern declarations on each file because they end up being
inconsistent (yyerror).
 1.8 02-Jun-2005  lukem Avoid dereferencing/free()ing invalid pointers if the random device
cannot be opened.
Detected with gcc -Wuninitialized.
(The bug was fixed in rev 1.4 by rumble but reintroduced in rev 1.5 by tv !)
 1.7 30-Mar-2005  elric one more malloc -> emalloc.
 1.6 30-Mar-2005  christos Centralize error checking for malloc,calloc,strdup.
 1.5 13-Aug-2004  tv branches: 1.5.2;
Add "urandomkey" key generation method as described in PR kern/22766;
useful for configuring a throwaway key for cgd-on-swap at boot time.
 1.4 10-Aug-2004  rumble Avoid dereferencing/free()ing invalid pointers if the random device
cannot be opened.

OK'd by elric.
 1.3 23-Sep-2003  cb branches: 1.3.2;
add a new verification method that prompts for the pkcs#5 pbkdf2
passphrase again and checks the generated key against the original.
 1.2 24-Mar-2003  elric substantial rototill of the code.

o added new features:
o -G: generate a new paramsfile that produces the same
key as the old paramsfile,
o ffs verify_method,
o multiple keygen methods that are xor'ed together
(for n-factor authentication), and
o calibrating the iteration count of PKCS#5 PBKDF2 to
the current machine's speed.
o changed paramsfile format to allow for the new features.
o replaced open-coded parser with yacc grammar.
o lots of supporting changes.
o updated documentation to reflect new features and new
paramsfile format.
 1.1 04-Oct-2002  elric Initial checkin of cgdconfig(8), a program to configure a cgd.
 1.3.2.1 13-Aug-2004  tv Oy, sometimes CVS sticky tags hurt. Revert urandomkey; that should be on HEAD.
 1.5.2.1 14-Jun-2005  tron Pull up revision 1.8 (requested by lukem in ticket #404):
Avoid dereferencing/free()ing invalid pointers if the random device
cannot be opened.
Detected with gcc -Wuninitialized.
(The bug was fixed in rev 1.4 by rumble but reintroduced in rev 1.5 by tv !)
 1.16.4.1 06-Nov-2007  matt sync with HEAD
 1.17.10.1 18-May-2008  yamt sync with head.
 1.17.8.1 02-Jun-2008  mjf Sync with HEAD.
 1.18.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.19.4.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.20.6.1 17-Apr-2012  yamt sync with head
 1.9 11-May-2008  elric Add a new keygen method which will execute an external command and
take its output as the key. I've been meaning to do this for quite
a while...
 1.8 28-Apr-2008  martin branches: 1.8.2;
Remove clause 3 and 4 from TNF licenses
 1.7 06-Nov-2007  christos branches: 1.7.8; 1.7.10;
3 month roland feedback timeout:
- Pass lint
- knf
- convert ints to size_t's
 1.6 26-Aug-2006  christos branches: 1.6.8;
Programs that use efun.
 1.5 30-Mar-2005  christos Centralize error checking for malloc,calloc,strdup.
 1.4 13-Aug-2004  tv Add "urandomkey" key generation method as described in PR kern/22766;
useful for configuring a throwaway key for cgd-on-swap at boot time.
 1.3 23-Sep-2003  cb branches: 1.3.2;
add a new verification method that prompts for the pkcs#5 pbkdf2
passphrase again and checks the generated key against the original.
 1.2 24-Mar-2003  elric substantial rototill of the code.

o added new features:
o -G: generate a new paramsfile that produces the same
key as the old paramsfile,
o ffs verify_method,
o multiple keygen methods that are xor'ed together
(for n-factor authentication), and
o calibrating the iteration count of PKCS#5 PBKDF2 to
the current machine's speed.
o changed paramsfile format to allow for the new features.
o replaced open-coded parser with yacc grammar.
o lots of supporting changes.
o updated documentation to reflect new features and new
paramsfile format.
 1.1 04-Oct-2002  elric Initial checkin of cgdconfig(8), a program to configure a cgd.
 1.3.2.1 13-Aug-2004  tv Oy, sometimes CVS sticky tags hurt. Revert urandomkey; that should be on HEAD.
 1.6.8.1 06-Nov-2007  matt sync with HEAD
 1.7.10.1 18-May-2008  yamt sync with head.
 1.7.8.1 02-Jun-2008  mjf Sync with HEAD.
 1.8.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.

RSS XML Feed