Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chacha20-Poly1305 encryption #14249

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ cstyle:
! -name 'zfs_config.*' ! -name '*.mod.c' \
! -name 'opt_global.h' ! -name '*_if*.h' \
! -name 'zstd_compat_wrapper.h' \
! -name 'monocypher.[ch]' \
! -path './module/zstd/lib/*' \
! -path './include/sys/lua/*' \
! -path './module/lua/l*.[ch]' \
Expand Down
1 change: 1 addition & 0 deletions include/os/freebsd/zfs/sys/freebsd_crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#define SUN_CKM_AES_CCM "CKM_AES_CCM"
#define SUN_CKM_AES_GCM "CKM_AES_GCM"
#define SUN_CKM_SHA512_HMAC "CKM_SHA512_HMAC"
#define SUN_CKM_CHACHA20_POLY1305 "CKM_CHACHA20_POLY1305"

#define CRYPTO_BITS2BYTES(n) ((n) == 0 ? 0 : (((n) - 1) >> 3) + 1)
#define CRYPTO_BYTES2BITS(n) ((n) << 3)
Expand Down
1 change: 1 addition & 0 deletions include/sys/crypto/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ typedef uint32_t crypto_keysize_unit_t;
#define SUN_CKM_SHA512_HMAC "CKM_SHA512_HMAC"
#define SUN_CKM_AES_CCM "CKM_AES_CCM"
#define SUN_CKM_AES_GCM "CKM_AES_GCM"
#define SUN_CKM_CHACHA20_POLY1305 "CKM_CHACHA20_POLY1305"

/* Data arguments of cryptographic operations */

Expand Down
3 changes: 3 additions & 0 deletions include/sys/crypto/icp.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
#ifndef _SYS_CRYPTO_ALGS_H
#define _SYS_CRYPTO_ALGS_H

int chapoly_mod_init(void);
int chapoly_mod_fini(void);

int aes_mod_init(void);
int aes_mod_fini(void);

Expand Down
1 change: 1 addition & 0 deletions include/sys/fs/zfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1906,6 +1906,7 @@ enum zio_encrypt {
ZIO_CRYPT_AES_128_GCM,
ZIO_CRYPT_AES_192_GCM,
ZIO_CRYPT_AES_256_GCM,
ZIO_CRYPT_CHACHA20_POLY1305,
ZIO_CRYPT_FUNCTIONS
};

Expand Down
5 changes: 3 additions & 2 deletions include/sys/zio_crypt.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ struct zbookmark_phys;
typedef enum zio_crypt_type {
ZC_TYPE_NONE = 0,
ZC_TYPE_CCM,
ZC_TYPE_GCM
ZC_TYPE_GCM,
ZC_TYPE_CHACHA20_POLY1305,
} zio_crypt_type_t;

/* table of supported crypto algorithms, modes and keylengths. */
Expand All @@ -60,7 +61,7 @@ typedef struct zio_crypt_info {
#else
crypto_mech_name_t ci_mechname;
#endif
/* cipher mode type (GCM, CCM) */
/* cipher mode type (GCM, CCM, ChaCha20-Poly1305) */
zio_crypt_type_t ci_crypt_type;

/* length of the encryption key */
Expand Down
1 change: 1 addition & 0 deletions include/zfeature_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ typedef enum spa_feature {
SPA_FEATURE_REDACTION_LIST_SPILL,
SPA_FEATURE_RAIDZ_EXPANSION,
SPA_FEATURE_FAST_DEDUP,
SPA_FEATURE_CHACHA20_POLY1305,
SPA_FEATURES
} spa_feature_t;

Expand Down
2 changes: 2 additions & 0 deletions lib/libicp/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ nodist_libicp_la_SOURCES = \
module/icp/algs/skein/skein_block.c \
module/icp/algs/skein/skein_iv.c \
module/icp/illumos-crypto.c \
module/icp/monocypher.c \
module/icp/io/aes.c \
module/icp/io/sha2_mod.c \
module/icp/io/chapoly.c \
module/icp/core/kcf_sched.c \
module/icp/core/kcf_prov_lib.c \
module/icp/core/kcf_callprov.c \
Expand Down
11 changes: 6 additions & 5 deletions lib/libzfs/libzfs.abi
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@
<elf-symbol name='fletcher_4_superscalar_ops' size='128' type='object-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<elf-symbol name='libzfs_config_ops' size='16' type='object-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<elf-symbol name='sa_protocol_names' size='16' type='object-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<elf-symbol name='spa_feature_table' size='2352' type='object-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<elf-symbol name='spa_feature_table' size='2408' type='object-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<elf-symbol name='zfeature_checks_disable' size='4' type='object-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<elf-symbol name='zfs_deleg_perm_tab' size='512' type='object-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<elf-symbol name='zfs_history_event_names' size='328' type='object-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
Expand Down Expand Up @@ -6017,7 +6017,8 @@
<enumerator name='SPA_FEATURE_REDACTION_LIST_SPILL' value='39'/>
<enumerator name='SPA_FEATURE_RAIDZ_EXPANSION' value='40'/>
<enumerator name='SPA_FEATURE_FAST_DEDUP' value='41'/>
<enumerator name='SPA_FEATURES' value='42'/>
<enumerator name='SPA_FEATURE_CHACHA20_POLY1305' value='42'/>
<enumerator name='SPA_FEATURES' value='43'/>
</enum-decl>
<typedef-decl name='spa_feature_t' type-id='33ecb627' id='d6618c78'/>
<qualified-type-def type-id='80f4b756' const='yes' id='b99c00c9'/>
Expand Down Expand Up @@ -9181,8 +9182,8 @@
</function-decl>
</abi-instr>
<abi-instr address-size='64' path='module/zcommon/zfeature_common.c' language='LANG_C99'>
<array-type-def dimensions='1' type-id='83f29ca2' size-in-bits='18816' id='b937914f'>
<subrange length='42' type-id='7359adad' id='cb7c937f'/>
<array-type-def dimensions='1' type-id='83f29ca2' size-in-bits='19264' id='bd39d632'>
<subrange length='43' type-id='7359adad' id='8f7e73a2'/>
</array-type-def>
<enum-decl name='zfeature_flags' id='6db816a4'>
<underlying-type type-id='9cac1fee'/>
Expand Down Expand Up @@ -9259,7 +9260,7 @@
<pointer-type-def type-id='611586a1' size-in-bits='64' id='2e243169'/>
<qualified-type-def type-id='eaa32e2f' const='yes' id='83be723c'/>
<pointer-type-def type-id='83be723c' size-in-bits='64' id='7acd98a2'/>
<var-decl name='spa_feature_table' type-id='b937914f' mangled-name='spa_feature_table' visibility='default' elf-symbol-id='spa_feature_table'/>
<var-decl name='spa_feature_table' type-id='bd39d632' mangled-name='spa_feature_table' visibility='default' elf-symbol-id='spa_feature_table'/>
<var-decl name='zfeature_checks_disable' type-id='c19b74c3' mangled-name='zfeature_checks_disable' visibility='default' elf-symbol-id='zfeature_checks_disable'/>
<function-decl name='opendir' visibility='default' binding='global' size-in-bits='64'>
<parameter type-id='80f4b756'/>
Expand Down
11 changes: 9 additions & 2 deletions man/man7/zfsprops.7
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@
.\" Copyright 2019 Joyent, Inc.
.\" Copyright (c) 2019, Kjeld Schouten-Lebbing
.\" Copyright (c) 2022 Hewlett Packard Enterprise Development LP.
.\" Copyright (c) 2023, Rob Norris <[email protected]>
.\"
.Dd June 29, 2024
.Dd July 26, 2024
.Dt ZFSPROPS 7
.Os
.
Expand Down Expand Up @@ -1077,7 +1078,7 @@ This property can also be referred to by its shortened column name,
.It Xo
.Sy encryption Ns = Ns Sy off Ns | Ns Sy on Ns | Ns Sy aes-128-ccm Ns | Ns
.Sy aes-192-ccm Ns | Ns Sy aes-256-ccm Ns | Ns Sy aes-128-gcm Ns | Ns
.Sy aes-192-gcm Ns | Ns Sy aes-256-gcm
.Sy aes-192-gcm Ns | Ns Sy aes-256-gcm Ns | Ns Sy chacha20-poly1305
.Xc
Controls the encryption cipher suite (block cipher, key length, and mode) used
for this dataset.
Expand All @@ -1096,6 +1097,12 @@ selected, which is currently
In order to provide consistent data protection, encryption must be specified at
dataset creation time and it cannot be changed afterwards.
.Pp
On systems lacking hardware-accelerated AES (many non-x86 boards)
.Sy chacha20-poly1305
will usually offer better performance without compromising security.
On x86, or when datasets may be mounted on on older versions of ZFS, an AES
suite is the best choice.
.Pp
For more details and caveats about encryption see the
.Sx Encryption
section of
Expand Down
18 changes: 17 additions & 1 deletion man/man7/zpool-features.7
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
.\" Copyright (c) 2019, Allan Jude
.\" Copyright (c) 2021, Colm Buckley <[email protected]>
.\" Copyright (c) 2023, Klara Inc.
.\" Copyright (c) 2024, Rob Norris <[email protected]>
.\"
.Dd February 14, 2024
.Dd August 23, 2024
.Dt ZPOOL-FEATURES 7
.Os
.
Expand Down Expand Up @@ -411,6 +412,21 @@ returned to the
.Sy enabled
state when all bookmarks with these fields are destroyed.
.
.feature org.openzfs chacha20_poly1305 no encryption extensible_dataset
This feature enables the use of the ChaCha20-Poly1305 cipher suite for encrypted
datasets.
On systems lacking hardware-accelerated AES (many non-x86 boards), this suite
will usually offer better performance than AES suites without compromising
security.
.Pp
This feature becomes
.Sy active
when an encrypted dataset is created with
.Nm encryption Ns = Ns Sy chacha20-poly1305
and will be returned to the
.Sy enabled
state when all datasets that use this feature are destroyed.
.
.feature org.openzfs device_rebuild yes
This feature enables the ability for the
.Nm zpool Cm attach
Expand Down
2 changes: 2 additions & 0 deletions module/Kbuild.in
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,10 @@ ICP_OBJS := \
core/kcf_prov_tabs.o \
core/kcf_sched.o \
illumos-crypto.o \
monocypher.o \
io/aes.o \
io/sha2_mod.o \
io/chapoly.o \
spi/kcf_spi.o

ICP_OBJS_X86_64 := \
Expand Down
2 changes: 2 additions & 0 deletions module/icp/illumos-crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ icp_fini(void)
{
sha2_mod_fini();
aes_mod_fini();
chapoly_mod_fini();
kcf_sched_destroy();
kcf_prov_tab_destroy();
kcf_destroy_mech_tabs();
Expand All @@ -131,6 +132,7 @@ icp_init(void)
kcf_sched_init();

/* initialize algorithms */
chapoly_mod_init();
aes_mod_init();
sha2_mod_init();

Expand Down
95 changes: 95 additions & 0 deletions module/icp/include/monocypher.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Copyright (c) 2017-2019, Loup Vaillant
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT
* HOLDER 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.
*/

/*
* Monocypher 4.0.2 (Poly1305, Chacha20, and supporting utilities)
* adapted for OpenZFS by Rob Norris <[email protected]>
*/

/*
* Note: this follows the Monocypher style rather than the OpenZFS style to
* keep the diff to the bare minimum. This is important for making it easy to
* compare the two and confirm that they are in fact the same. The diff should
* be almost entirely in deleted lines.
*/

#ifndef MONOCYPHER_H
#define MONOCYPHER_H

#include <sys/types.h>


// Constant time comparisons
// -------------------------

// Return 0 if a and b are equal, -1 otherwise
int crypto_verify16(const uint8_t a[16], const uint8_t b[16]);

// Erase sensitive data
// --------------------
void crypto_wipe(void *secret, size_t size);


// Chacha20
// --------

// Unauthenticated stream cipher.
// Don't forget to add authentication.
uint32_t crypto_chacha20_ietf(uint8_t *cipher_text,
const uint8_t *plain_text,
size_t text_size,
const uint8_t key[32],
const uint8_t nonce[12],
uint32_t ctr);


// Poly 1305
// ---------

// This is a *one time* authenticator.
// Disclosing the mac reveals the key.

// Incremental interface
typedef struct {
// Do not rely on the size or contents of this type,
// for they may change without notice.
uint8_t c[16]; // chunk of the message
size_t c_idx; // How many bytes are there in the chunk.
uint32_t r [4]; // constant multiplier (from the secret key)
uint32_t pad[4]; // random number added at the end (from the secret key)
uint32_t h [5]; // accumulated hash
} crypto_poly1305_ctx;

void crypto_poly1305_init (crypto_poly1305_ctx *ctx, const uint8_t key[32]);
void crypto_poly1305_update(crypto_poly1305_ctx *ctx,
const uint8_t *message, size_t message_size);
void crypto_poly1305_final (crypto_poly1305_ctx *ctx, uint8_t mac[16]);

#endif /* MONOCYPHER_H */
Loading
Loading