Lines Matching +full:s +full:- +full:merged

1 // SPDX-License-Identifier: GPL-2.0
7 #include "super-io.h"
16 #include <keys/user-type.h>
22 * for hash-like algorithms, a state needs to be stored
35 switch (state->type) { in bch2_checksum_init()
39 state->seed = 0; in bch2_checksum_init()
42 state->seed = U32_MAX; in bch2_checksum_init()
45 state->seed = U64_MAX; in bch2_checksum_init()
48 xxh64_reset(&state->h64state, 0); in bch2_checksum_init()
57 switch (state->type) { in bch2_checksum_final()
61 return state->seed; in bch2_checksum_final()
63 return state->seed ^ U32_MAX; in bch2_checksum_final()
65 return state->seed ^ U64_MAX; in bch2_checksum_final()
67 return xxh64_digest(&state->h64state); in bch2_checksum_final()
75 switch (state->type) { in bch2_checksum_update()
80 state->seed = crc32c(state->seed, data, len); in bch2_checksum_update()
84 state->seed = crc64_be(state->seed, data, len); in bch2_checksum_update()
87 xxh64_update(&state->h64state, data, len); in bch2_checksum_update()
126 bch2_chacha20(&c->chacha20_key, nonce, key, sizeof(key)); in bch2_poly1305_init()
174 if (bch2_fs_inconsistent_on(!c->chacha20_key_set, in bch2_encrypt()
178 bch2_chacha20(&c->chacha20_key, nonce, data, len); in bch2_encrypt()
250 struct bvec_iter iter = bio->bi_iter; in bch2_checksum_bio()
263 if (bch2_fs_inconsistent_on(!c->chacha20_key_set, in __bch2_encrypt_bio()
267 bch2_chacha20_init(&chacha_state, &c->chacha20_key, nonce); in __bch2_encrypt_bio()
274 * CHACHA_BLOCK_SIZE on any non-final call. in __bch2_encrypt_bio()
278 ret = -EIO; in __bch2_encrypt_bio()
306 b_len -= page_len; in bch2_checksum_merge()
322 struct bvec_iter iter = bio->bi_iter; in bch2_rechecksum_bio()
324 struct bch_csum merged = { 0 }; in bch2_rechecksum_bio() local
333 { NULL, bio_sectors(bio) - len_a - len_b, new_csum_type, { 0 } }, in bch2_rechecksum_bio()
346 iter.bi_size = i->len << 9; in bch2_rechecksum_bio()
347 if (mergeable || i->crc) in bch2_rechecksum_bio()
348 i->csum = __bch2_checksum_bio(c, i->csum_type, in bch2_rechecksum_bio()
351 bio_advance_iter(bio, &iter, i->len << 9); in bch2_rechecksum_bio()
352 nonce = nonce_add(nonce, i->len << 9); in bch2_rechecksum_bio()
357 merged = bch2_checksum_merge(new_csum_type, merged, in bch2_rechecksum_bio()
358 i->csum, i->len << 9); in bch2_rechecksum_bio()
360 merged = bch2_checksum_bio(c, crc_old.csum_type, in bch2_rechecksum_bio()
363 if (bch2_crc_cmp(merged, crc_old.csum) && !c->opts.no_data_io) { in bch2_rechecksum_bio()
365 prt_printf(&buf, "checksum error in %s() (memory corruption or bug?)\n" in bch2_rechecksum_bio()
370 merged.hi, in bch2_rechecksum_bio()
371 merged.lo); in bch2_rechecksum_bio()
376 WARN_RATELIMIT(1, "%s", buf.buf); in bch2_rechecksum_bio()
382 if (i->crc) in bch2_rechecksum_bio()
383 *i->crc = (struct bch_extent_crc_unpacked) { in bch2_rechecksum_bio()
384 .csum_type = i->csum_type, in bch2_rechecksum_bio()
386 .compressed_size = i->len, in bch2_rechecksum_bio()
387 .uncompressed_size = i->len, in bch2_rechecksum_bio()
389 .live_size = i->len, in bch2_rechecksum_bio()
391 .csum = i->csum, in bch2_rechecksum_bio()
395 crc_nonce += i->len; in bch2_rechecksum_bio()
408 if (vstruct_bytes(&crypt->field) < sizeof(*crypt)) { in bch2_sb_crypt_validate()
410 vstruct_bytes(&crypt->field), sizeof(*crypt)); in bch2_sb_crypt_validate()
411 return -BCH_ERR_invalid_sb_crypt; in bch2_sb_crypt_validate()
416 return -BCH_ERR_invalid_sb_crypt; in bch2_sb_crypt_validate()
449 down_read(&keyring_key->sem); in __bch2_request_key()
451 if (ukp->datalen == sizeof(*key)) { in __bch2_request_key()
452 memcpy(key, ukp->data, ukp->datalen); in __bch2_request_key()
455 ret = -EINVAL; in __bch2_request_key()
457 up_read(&keyring_key->sem); in __bch2_request_key()
484 return -errno; in __bch2_request_key()
488 return -1; in __bch2_request_key()
502 pr_uuid(&key_description, sb->user_uuid.b); in bch2_request_key()
530 pr_uuid(&key_description, sb->user_uuid.b); in bch2_revoke_key()
547 struct bch_encrypted_key sb_key = crypt->key; in bch2_decrypt_sb_key()
555 ret = bch2_request_key(c->disk_sb.sb, &user_key); in bch2_decrypt_sb_key()
557 bch_err(c, "error requesting encryption key: %s", bch2_err_str(ret)); in bch2_decrypt_sb_key()
566 ret = -EINVAL; in bch2_decrypt_sb_key()
581 * bcachefs-tools, but we might want to switch userspace to use this - and
589 int ret = -EINVAL;
591 mutex_lock(&c->sb_lock);
593 crypt = bch2_sb_field_get(c->disk_sb.sb, crypt);
599 if (bch2_key_is_encrypted(&crypt->key))
606 crypt->key.magic = cpu_to_le64(BCH_KEY_MAGIC);
607 crypt->key.key = key;
609 SET_BCH_SB_ENCRYPTION_TYPE(c->disk_sb.sb, 0);
612 mutex_unlock(&c->sb_lock);
626 int ret = -EINVAL;
628 mutex_lock(&c->sb_lock);
631 if (bch2_sb_field_get(c->disk_sb.sb, crypt))
642 ret = bch2_request_key(c->disk_sb.sb, &user_key);
644 bch_err(c, "error requesting encryption key: %s", bch2_err_str(ret));
654 ret = crypto_skcipher_setkey(&c->chacha20->base,
659 crypt = bch2_sb_field_resize(&c->disk_sb, crypt,
666 crypt->key = key;
669 SET_BCH_SB_ENCRYPTION_TYPE(c->disk_sb.sb, 1);
672 mutex_unlock(&c->sb_lock);
681 memzero_explicit(&c->chacha20_key, sizeof(c->chacha20_key)); in bch2_fs_encryption_exit()
689 crypt = bch2_sb_field_get(c->disk_sb.sb, crypt); in bch2_fs_encryption_init()
693 ret = bch2_decrypt_sb_key(c, crypt, &c->chacha20_key); in bch2_fs_encryption_init()
696 c->chacha20_key_set = true; in bch2_fs_encryption_init()