Skip to content

Commit

Permalink
chapoly: add chacha20_poly1305 feature
Browse files Browse the repository at this point in the history
Signed-off-by: Rob Norris <[email protected]>
  • Loading branch information
robn committed May 21, 2023
1 parent a1a2000 commit aa3c336
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 6 deletions.
1 change: 1 addition & 0 deletions include/zfeature_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ typedef enum spa_feature {
SPA_FEATURE_BLAKE3,
SPA_FEATURE_BLOCK_CLONING,
SPA_FEATURE_AVZ_V2,
SPA_FEATURE_CHACHA20_POLY1305,
SPA_FEATURES
} spa_feature_t;

Expand Down
9 changes: 5 additions & 4 deletions lib/libzfs/libzfs.abi
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,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='2184' type='object-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<elf-symbol name='spa_feature_table' size='2240' 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 @@ -5809,7 +5809,8 @@
<enumerator name='SPA_FEATURE_BLAKE3' value='36'/>
<enumerator name='SPA_FEATURE_BLOCK_CLONING' value='37'/>
<enumerator name='SPA_FEATURE_AVZ_V2' value='38'/>
<enumerator name='SPA_FEATURES' value='39'/>
<enumerator name='SPA_FEATURE_CHACHA20_POLY1305' value='39'/>
<enumerator name='SPA_FEATURES' value='40'/>
</enum-decl>
<typedef-decl name='spa_feature_t' type-id='33ecb627' id='d6618c78'/>
<qualified-type-def type-id='22cce67b' const='yes' id='d2816df0'/>
Expand Down Expand Up @@ -8706,8 +8707,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='17472' id='dd432c71'>
<subrange length='39' type-id='7359adad' id='ae4a9561'/>
<array-type-def dimensions='1' type-id='83f29ca2' size-in-bits='17920' id='dd432c71'>
<subrange length='40' type-id='7359adad' id='ae4a9561'/>
</array-type-def>
<enum-decl name='zfeature_flags' id='6db816a4'>
<underlying-type type-id='9cac1fee'/>
Expand Down
17 changes: 16 additions & 1 deletion man/man7/zpool-features.7
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
.\" Copyright (c) 2019, Allan Jude
.\" Copyright (c) 2021, Colm Buckley <[email protected]>
.\"
.Dd June 23, 2022
.Dd May 21, 2023
.Dt ZPOOL-FEATURES 7
.Os
.
Expand Down Expand Up @@ -396,6 +396,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 lackng 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
13 changes: 13 additions & 0 deletions module/zcommon/zfeature_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,19 @@ zpool_feature_init(void)
ZFEATURE_FLAG_MOS, ZFEATURE_TYPE_BOOLEAN, NULL,
sfeatures);

{
static const spa_feature_t chapoly_deps[] = {
SPA_FEATURE_EXTENSIBLE_DATASET,
SPA_FEATURE_ENCRYPTION,
SPA_FEATURE_NONE
};
zfeature_register(SPA_FEATURE_CHACHA20_POLY1305,
"org.openzfs:chacha20_poly1305", "chacha20_poly1305",
"Chacha20-Poly1305 encryption suite.",
ZFEATURE_FLAG_PER_DATASET, ZFEATURE_TYPE_BOOLEAN,
chapoly_deps, sfeatures);
}

zfs_mod_list_supported_free(sfeatures);
}

Expand Down
21 changes: 21 additions & 0 deletions module/zfs/dsl_crypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1819,6 +1819,12 @@ dmu_objset_create_crypt_check(dsl_dir_t *parentdd, dsl_crypto_params_t *dcp,
return (SET_ERROR(EOPNOTSUPP));
}

if (crypt == ZIO_CRYPT_CHACHA20_POLY1305 && parentdd != NULL &&
!spa_feature_is_enabled(parentdd->dd_pool->dp_spa,
SPA_FEATURE_CHACHA20_POLY1305)) {
return (SET_ERROR(EOPNOTSUPP));
}

/* handle inheritance */
if (dcp->cp_wkey == NULL) {
ASSERT3P(parentdd, !=, NULL);
Expand Down Expand Up @@ -1937,6 +1943,9 @@ dsl_dataset_create_crypt_sync(uint64_t dsobj, dsl_dir_t *dd,
tx));
dsl_dataset_activate_feature(dsobj, SPA_FEATURE_ENCRYPTION,
(void *)B_TRUE, tx);
if (crypt == ZIO_CRYPT_CHACHA20_POLY1305)
dsl_dataset_activate_feature(dsobj,
SPA_FEATURE_CHACHA20_POLY1305, (void *)B_TRUE, tx);

/*
* If we inherited the wrapping key we release our reference now.
Expand Down Expand Up @@ -2157,6 +2166,11 @@ dsl_crypto_recv_raw_key_check(dsl_dataset_t *ds, nvlist_t *nvl, dmu_tx_t *tx)
if (intval >= ZIO_CRYPT_FUNCTIONS)
return (SET_ERROR(ZFS_ERR_CRYPTO_NOTSUP));

if (intval == ZIO_CRYPT_CHACHA20_POLY1305 &&
!spa_feature_is_enabled(ds->ds_dir->dd_pool->dp_spa,
SPA_FEATURE_CHACHA20_POLY1305))
return (SET_ERROR(EOPNOTSUPP));

ret = nvlist_lookup_uint64(nvl, DSL_CRYPTO_KEY_GUID, &intval);
if (ret != 0)
return (SET_ERROR(EINVAL));
Expand Down Expand Up @@ -2276,6 +2290,13 @@ dsl_crypto_recv_raw_key_sync(dsl_dataset_t *ds, nvlist_t *nvl, dmu_tx_t *tx)
SPA_FEATURE_ENCRYPTION, (void *)B_TRUE, tx);
ds->ds_feature[SPA_FEATURE_ENCRYPTION] = (void *)B_TRUE;

if (crypt == ZIO_CRYPT_CHACHA20_POLY1305) {
dsl_dataset_activate_feature(ds->ds_object,
SPA_FEATURE_CHACHA20_POLY1305, (void *)B_TRUE, tx);
ds->ds_feature[SPA_FEATURE_CHACHA20_POLY1305] =
(void *)B_TRUE;
}

/* save the dd_crypto_obj on disk */
VERIFY0(zap_add(mos, dd->dd_object, DD_FIELD_CRYPTO_KEY_OBJ,
sizeof (uint64_t), 1, &dd->dd_crypto_obj, tx));
Expand Down
6 changes: 5 additions & 1 deletion module/zfs/dsl_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,12 @@ dsl_pool_create(spa_t *spa, nvlist_t *zplprops __attribute__((unused)),
spa_feature_create_zap_objects(spa, tx);

if (dcp != NULL && dcp->cp_crypt != ZIO_CRYPT_OFF &&
dcp->cp_crypt != ZIO_CRYPT_INHERIT)
dcp->cp_crypt != ZIO_CRYPT_INHERIT) {
spa_feature_enable(spa, SPA_FEATURE_ENCRYPTION, tx);
if (dcp->cp_crypt == ZIO_CRYPT_CHACHA20_POLY1305)
spa_feature_enable(spa,
SPA_FEATURE_CHACHA20_POLY1305, tx);
}

/* create the root dataset */
obj = dsl_dataset_create_sync_dd(dp->dp_root_dir, NULL, dcp, 0, tx);
Expand Down

0 comments on commit aa3c336

Please sign in to comment.