2024-05-12 21:02:16 +03:00
|
|
|
/* $NetBSD: params.h,v 1.15 2024/05/12 18:02:16 christos Exp $ */
|
2002-10-04 22:37:19 +04:00
|
|
|
|
|
|
|
/*-
|
2003-03-24 05:02:49 +03:00
|
|
|
* Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
|
2002-10-04 22:37:19 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Roland C. Dowdeswell.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2003-03-24 05:02:49 +03:00
|
|
|
#ifndef PARAMS_H
|
|
|
|
#define PARAMS_H
|
|
|
|
|
|
|
|
#include "utils.h"
|
|
|
|
|
|
|
|
struct keygen {
|
|
|
|
int kg_method;
|
2007-11-06 05:50:48 +03:00
|
|
|
size_t kg_iterations;
|
2021-11-22 17:34:35 +03:00
|
|
|
size_t kg_memory; /* only used for Argon2 */
|
|
|
|
size_t kg_parallelism; /* only used for Argon2 */
|
|
|
|
size_t kg_version; /* only used for Argon2 */
|
2003-03-24 05:02:49 +03:00
|
|
|
bits_t *kg_salt;
|
|
|
|
bits_t *kg_key;
|
2008-05-11 07:15:21 +04:00
|
|
|
string_t *kg_cmd;
|
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.
2022-08-12 13:49:17 +03:00
|
|
|
string_t *kg_sharedid;
|
|
|
|
int kg_sharedalg;
|
|
|
|
size_t kg_sharedlen;
|
|
|
|
bits_t *kg_sharedinfo;
|
2003-03-24 05:02:49 +03:00
|
|
|
struct keygen *next;
|
|
|
|
};
|
|
|
|
|
2002-10-04 22:37:19 +04:00
|
|
|
struct params {
|
2003-03-24 05:02:49 +03:00
|
|
|
string_t *algorithm;
|
|
|
|
string_t *ivmeth;
|
|
|
|
bits_t *key;
|
2007-11-06 05:50:48 +03:00
|
|
|
size_t keylen;
|
|
|
|
size_t bsize;
|
2002-10-13 01:02:18 +04:00
|
|
|
int verify_method;
|
2003-03-24 05:02:49 +03:00
|
|
|
struct keygen *dep_keygen;
|
|
|
|
struct keygen *keygen;
|
2002-10-04 22:37:19 +04:00
|
|
|
};
|
|
|
|
|
2002-10-13 01:02:18 +04:00
|
|
|
/* key generation methods */
|
|
|
|
|
2004-03-17 04:29:13 +03:00
|
|
|
#define KEYGEN_UNKNOWN 0x0
|
|
|
|
#define KEYGEN_RANDOMKEY 0x1
|
|
|
|
#define KEYGEN_PKCS5_PBKDF2_OLD 0x2
|
|
|
|
#define KEYGEN_STOREDKEY 0x3
|
2004-08-13 19:03:57 +04:00
|
|
|
#define KEYGEN_URANDOMKEY 0x4
|
2004-03-17 04:29:13 +03:00
|
|
|
#define KEYGEN_PKCS5_PBKDF2_SHA1 0x5
|
2008-05-11 07:15:21 +04:00
|
|
|
#define KEYGEN_SHELL_CMD 0x6
|
2021-11-22 17:34:35 +03:00
|
|
|
#define KEYGEN_ARGON2ID 0x7
|
2002-10-04 22:37:19 +04:00
|
|
|
|
2002-10-13 01:02:18 +04:00
|
|
|
/* verification methods */
|
|
|
|
|
|
|
|
#define VERIFY_UNKNOWN 0x0
|
|
|
|
#define VERIFY_NONE 0x1
|
|
|
|
#define VERIFY_DISKLABEL 0x2
|
2003-03-24 05:02:49 +03:00
|
|
|
#define VERIFY_FFS 0x3
|
2003-09-23 21:24:45 +04:00
|
|
|
#define VERIFY_REENTER 0x4
|
2014-12-14 15:31:39 +03:00
|
|
|
#define VERIFY_MBR 0x5
|
|
|
|
#define VERIFY_GPT 0x6
|
2024-05-12 21:02:16 +03:00
|
|
|
#define VERIFY_ZFS 0x7
|
2003-03-24 05:02:49 +03:00
|
|
|
|
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.
2022-08-12 13:49:17 +03:00
|
|
|
/* shared key derivation methods */
|
|
|
|
|
|
|
|
#define SHARED_ALG_UNKNOWN 0x0
|
|
|
|
#define SHARED_ALG_HKDF_HMAC_SHA256 0x1
|
|
|
|
|
2003-03-24 05:02:49 +03:00
|
|
|
__BEGIN_DECLS
|
|
|
|
struct params *params_new(void);
|
|
|
|
void params_free(struct params *);
|
|
|
|
|
|
|
|
int params_filldefaults(struct params *);
|
|
|
|
int params_verify(const struct params *);
|
2002-10-13 01:02:18 +04:00
|
|
|
|
2003-03-24 05:02:49 +03:00
|
|
|
struct params *params_combine(struct params *, struct params *);
|
|
|
|
struct params *params_algorithm(string_t *);
|
|
|
|
struct params *params_ivmeth(string_t *);
|
2007-11-06 05:50:48 +03:00
|
|
|
struct params *params_keylen(size_t);
|
|
|
|
struct params *params_bsize(size_t);
|
2003-03-24 05:02:49 +03:00
|
|
|
struct params *params_verify_method(string_t *);
|
|
|
|
struct params *params_keygen(struct keygen *);
|
|
|
|
struct params *params_dep_keygen(struct keygen *);
|
2002-10-04 22:37:19 +04:00
|
|
|
|
2003-03-24 05:02:49 +03:00
|
|
|
struct params *params_fget(FILE *);
|
|
|
|
struct params *params_cget(const char *);
|
|
|
|
int params_fput(struct params *, FILE *);
|
|
|
|
int params_cput(struct params *, const char *);
|
2002-10-04 22:37:19 +04:00
|
|
|
|
2003-03-24 05:02:49 +03:00
|
|
|
struct keygen *keygen_new(void);
|
|
|
|
void keygen_free(struct keygen *);
|
2002-10-04 22:37:19 +04:00
|
|
|
|
2007-11-06 05:50:48 +03:00
|
|
|
int keygen_filldefaults(struct keygen *, size_t);
|
2022-08-12 13:49:35 +03:00
|
|
|
void keygen_stripstored(struct keygen **);
|
|
|
|
int keygen_makeshared(struct keygen *);
|
|
|
|
int keygen_tweakshared(struct keygen *);
|
2003-03-24 05:02:49 +03:00
|
|
|
int keygen_verify(const struct keygen *);
|
|
|
|
void keygen_addlist(struct keygen **, struct keygen *);
|
2002-10-04 22:37:19 +04:00
|
|
|
|
2003-03-24 05:02:49 +03:00
|
|
|
struct keygen *keygen_combine(struct keygen *, struct keygen *);
|
|
|
|
struct keygen *keygen_generate(int);
|
|
|
|
struct keygen *keygen_method(string_t *);
|
|
|
|
struct keygen *keygen_set_method(struct keygen *, string_t *);
|
|
|
|
struct keygen *keygen_salt(bits_t *);
|
2007-11-06 05:50:48 +03:00
|
|
|
struct keygen *keygen_iterations(size_t);
|
2021-11-22 17:34:35 +03:00
|
|
|
struct keygen *keygen_memory(size_t);
|
|
|
|
struct keygen *keygen_parallelism(size_t);
|
|
|
|
struct keygen *keygen_version(size_t);
|
2003-03-24 05:02:49 +03:00
|
|
|
struct keygen *keygen_key(bits_t *);
|
2008-05-11 07:15:21 +04:00
|
|
|
struct keygen *keygen_cmd(string_t *);
|
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.
2022-08-12 13:49:17 +03:00
|
|
|
struct keygen *keygen_shared(string_t *, string_t *, bits_t *);
|
2002-10-04 22:37:19 +04:00
|
|
|
|
2003-03-24 05:02:49 +03:00
|
|
|
int keygen_fput(struct keygen *, int, FILE *);
|
|
|
|
__END_DECLS
|
2002-10-04 22:37:19 +04:00
|
|
|
|
2003-03-24 05:02:49 +03:00
|
|
|
#endif
|