linux/fs/bcachefs/checksum.h

/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _BCACHEFS_CHECKSUM_H
#define _BCACHEFS_CHECKSUM_H

#include "bcachefs.h"
#include "extents_types.h"
#include "super-io.h"

#include <linux/crc64.h>
#include <crypto/chacha.h>

static inline bool bch2_checksum_mergeable(unsigned type)
{}

struct bch_csum bch2_checksum_merge(unsigned, struct bch_csum,
				    struct bch_csum, size_t);

#define BCH_NONCE_EXTENT
#define BCH_NONCE_BTREE
#define BCH_NONCE_JOURNAL
#define BCH_NONCE_PRIO
#define BCH_NONCE_POLY

struct bch_csum bch2_checksum(struct bch_fs *, unsigned, struct nonce,
			     const void *, size_t);

/*
 * This is used for various on disk data structures - bch_sb, prio_set, bset,
 * jset: The checksum is _always_ the first field of these structs
 */
#define csum_vstruct(_c, _type, _nonce, _i)

static inline void bch2_csum_to_text(struct printbuf *out,
				     enum bch_csum_type type,
				     struct bch_csum csum)
{}

static inline void bch2_csum_err_msg(struct printbuf *out,
				     enum bch_csum_type type,
				     struct bch_csum expected,
				     struct bch_csum got)
{}

int bch2_chacha_encrypt_key(struct bch_key *, struct nonce, void *, size_t);
int bch2_request_key(struct bch_sb *, struct bch_key *);
#ifndef __KERNEL__
int bch2_revoke_key(struct bch_sb *);
#endif

int bch2_encrypt(struct bch_fs *, unsigned, struct nonce,
		 void *data, size_t);

struct bch_csum bch2_checksum_bio(struct bch_fs *, unsigned,
				  struct nonce, struct bio *);

int bch2_rechecksum_bio(struct bch_fs *, struct bio *, struct bversion,
			struct bch_extent_crc_unpacked,
			struct bch_extent_crc_unpacked *,
			struct bch_extent_crc_unpacked *,
			unsigned, unsigned, unsigned);

int __bch2_encrypt_bio(struct bch_fs *, unsigned,
		       struct nonce, struct bio *);

static inline int bch2_encrypt_bio(struct bch_fs *c, unsigned type,
				   struct nonce nonce, struct bio *bio)
{}

extern const struct bch_sb_field_ops bch_sb_field_ops_crypt;

int bch2_decrypt_sb_key(struct bch_fs *, struct bch_sb_field_crypt *,
			struct bch_key *);

int bch2_disable_encryption(struct bch_fs *);
int bch2_enable_encryption(struct bch_fs *, bool);

void bch2_fs_encryption_exit(struct bch_fs *);
int bch2_fs_encryption_init(struct bch_fs *);

static inline enum bch_csum_type bch2_csum_opt_to_type(enum bch_csum_opts type,
						       bool data)
{}

static inline enum bch_csum_type bch2_data_checksum_type(struct bch_fs *c,
							 struct bch_io_opts opts)
{}

static inline enum bch_csum_type bch2_meta_checksum_type(struct bch_fs *c)
{}

static inline bool bch2_checksum_type_valid(const struct bch_fs *c,
					   unsigned type)
{}

/* returns true if not equal */
static inline bool bch2_crc_cmp(struct bch_csum l, struct bch_csum r)
{}

/* for skipping ahead and encrypting/decrypting at an offset: */
static inline struct nonce nonce_add(struct nonce nonce, unsigned offset)
{}

static inline struct nonce null_nonce(void)
{}

static inline struct nonce extent_nonce(struct bversion version,
					struct bch_extent_crc_unpacked crc)
{}

static inline bool bch2_key_is_encrypted(struct bch_encrypted_key *key)
{}

static inline struct nonce __bch2_sb_key_nonce(struct bch_sb *sb)
{}

static inline struct nonce bch2_sb_key_nonce(struct bch_fs *c)
{}

#endif /* _BCACHEFS_CHECKSUM_H */