diff options
author | Kent Overstreet <kent.overstreet@linux.dev> | 2025-06-09 17:34:47 -0400 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2025-06-09 17:39:57 -0400 |
commit | 802903c8cf90f84248b31dd7776ecce148bb7b9c (patch) | |
tree | 0ec0d1e7ee7ea11ee9571c897dfa5f5562aa2bf7 /include | |
parent | 7e570195d49389fd7119b72d5de8fb458fc82f1a (diff) |
Update bcachefs sources to a8d89eb264e0 bcachefs: Allow CONFIG_UNICODE=m
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'include')
-rw-r--r-- | include/crypto/chacha.h | 57 | ||||
-rw-r--r-- | include/linux/poison.h | 4 | ||||
-rw-r--r-- | include/linux/sort.h | 10 |
3 files changed, 49 insertions, 22 deletions
diff --git a/include/crypto/chacha.h b/include/crypto/chacha.h index 424dd818..c9d23ab3 100644 --- a/include/crypto/chacha.h +++ b/include/crypto/chacha.h @@ -12,7 +12,13 @@ #define CHACHA_IV_SIZE 16 #define CHACHA_KEY_SIZE 32 #define CHACHA_BLOCK_SIZE 64 -#define CHACHA_STATE_WORDS (CHACHA_BLOCK_SIZE / sizeof(u32)) + +#define CHACHA_KEY_WORDS 8 +#define CHACHA_STATE_WORDS 16 + +struct chacha_state { + u32 x[CHACHA_STATE_WORDS]; +}; enum chacha_constants { /* expand 32-byte k */ CHACHA_CONSTANT_EXPA = 0x61707865U, @@ -21,38 +27,40 @@ enum chacha_constants { /* expand 32-byte k */ CHACHA_CONSTANT_TE_K = 0x6b206574U }; -static inline void chacha_init_consts(u32 *state) +static inline void chacha_init_consts(struct chacha_state *state) { - state[0] = CHACHA_CONSTANT_EXPA; - state[1] = CHACHA_CONSTANT_ND_3; - state[2] = CHACHA_CONSTANT_2_BY; - state[3] = CHACHA_CONSTANT_TE_K; + state->x[0] = CHACHA_CONSTANT_EXPA; + state->x[1] = CHACHA_CONSTANT_ND_3; + state->x[2] = CHACHA_CONSTANT_2_BY; + state->x[3] = CHACHA_CONSTANT_TE_K; } -static inline void chacha_init(u32 *state, const u32 *key, const u8 *iv) +static inline void chacha_init(struct chacha_state *state, + const u32 key[CHACHA_KEY_WORDS], + const u8 iv[CHACHA_IV_SIZE]) { chacha_init_consts(state); - state[4] = key[0]; - state[5] = key[1]; - state[6] = key[2]; - state[7] = key[3]; - state[8] = key[4]; - state[9] = key[5]; - state[10] = key[6]; - state[11] = key[7]; - state[12] = get_unaligned_le32(iv + 0); - state[13] = get_unaligned_le32(iv + 4); - state[14] = get_unaligned_le32(iv + 8); - state[15] = get_unaligned_le32(iv + 12); + state->x[4] = key[0]; + state->x[5] = key[1]; + state->x[6] = key[2]; + state->x[7] = key[3]; + state->x[8] = key[4]; + state->x[9] = key[5]; + state->x[10] = key[6]; + state->x[11] = key[7]; + state->x[12] = get_unaligned_le32(iv + 0); + state->x[13] = get_unaligned_le32(iv + 4); + state->x[14] = get_unaligned_le32(iv + 8); + state->x[15] = get_unaligned_le32(iv + 12); } #include <sodium/crypto_stream_chacha20.h> -static inline void chacha20_crypt(u32 *state, u8 *dst, const u8 *src, +static inline void chacha20_crypt(struct chacha_state *state, u8 *dst, const u8 *src, unsigned int bytes) { - u32 *key = state + 4; - u32 *iv = state + 12; + u32 *key = state->x + 4; + u32 *iv = state->x + 12; int ret = crypto_stream_chacha20_xor_ic(dst, src, bytes, (void *) &iv[2], iv[0] | ((u64) iv[1] << 32), @@ -60,4 +68,9 @@ static inline void chacha20_crypt(u32 *state, u8 *dst, const u8 *src, BUG_ON(ret); } +static inline void chacha_zeroize_state(struct chacha_state *state) +{ + memzero_explicit(state, sizeof(*state)); +} + #endif diff --git a/include/linux/poison.h b/include/linux/poison.h index 331a9a99..8ca2235f 100644 --- a/include/linux/poison.h +++ b/include/linux/poison.h @@ -70,6 +70,10 @@ #define KEY_DESTROY 0xbd /********** net/core/page_pool.c **********/ +/* + * page_pool uses additional free bits within this value to store data, see the + * definition of PP_DMA_INDEX_MASK in mm.h + */ #define PP_SIGNATURE (0x40 + POISON_POINTER_DELTA) /********** net/core/skbuff.c **********/ diff --git a/include/linux/sort.h b/include/linux/sort.h index 09519a90..d8a86590 100644 --- a/include/linux/sort.h +++ b/include/linux/sort.h @@ -4,6 +4,16 @@ #include <stdlib.h> #include <linux/types.h> +/** + * cmp_int - perform a three-way comparison of the arguments + * @l: the left argument + * @r: the right argument + * + * Return: 1 if the left argument is greater than the right one; 0 if the + * arguments are equal; -1 if the left argument is less than the right one. + */ +#define cmp_int(l, r) (((l) > (r)) - ((l) < (r))) + void sort_r(void *base, size_t num, size_t size, cmp_r_func_t cmp_func, swap_r_func_t swap_func, |