Commit bdc2a556 authored by Eric Biggers's avatar Eric Biggers Committed by Herbert Xu
Browse files

crypto: lib/chacha - add array bounds to function prototypes



Add explicit array bounds to the function prototypes for the parameters
that didn't already get handled by the conversion to use chacha_state:

- chacha_block_*():
  Change 'u8 *out' or 'u8 *stream' to u8 out[CHACHA_BLOCK_SIZE].

- hchacha_block_*():
  Change 'u32 *out' or 'u32 *stream' to u32 out[HCHACHA_OUT_WORDS].

- chacha_init():
  Change 'const u32 *key' to 'const u32 key[CHACHA_KEY_WORDS]'.
  Change 'const u8 *iv' to 'const u8 iv[CHACHA_IV_SIZE]'.

No functional changes.  This just makes it clear when fixed-size arrays
are expected.

Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 607c9214
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -23,9 +23,9 @@ asmlinkage void chacha_4block_xor_neon(const struct chacha_state *state,
				       u8 *dst, const u8 *src,
				       int nrounds, unsigned int nbytes);
asmlinkage void hchacha_block_arm(const struct chacha_state *state,
				  u32 *out, int nrounds);
				  u32 out[HCHACHA_OUT_WORDS], int nrounds);
asmlinkage void hchacha_block_neon(const struct chacha_state *state,
				   u32 *out, int nrounds);
				   u32 out[HCHACHA_OUT_WORDS], int nrounds);

asmlinkage void chacha_doarm(u8 *dst, const u8 *src, unsigned int bytes,
			     const struct chacha_state *state, int nrounds);
@@ -64,14 +64,14 @@ static void chacha_doneon(struct chacha_state *state, u8 *dst, const u8 *src,
	}
}

void hchacha_block_arch(const struct chacha_state *state, u32 *stream,
			int nrounds)
void hchacha_block_arch(const struct chacha_state *state,
			u32 out[HCHACHA_OUT_WORDS], int nrounds)
{
	if (!IS_ENABLED(CONFIG_KERNEL_MODE_NEON) || !neon_usable()) {
		hchacha_block_arm(state, stream, nrounds);
		hchacha_block_arm(state, out, nrounds);
	} else {
		kernel_neon_begin();
		hchacha_block_neon(state, stream, nrounds);
		hchacha_block_neon(state, out, nrounds);
		kernel_neon_end();
	}
}
+1 −1
Original line number Diff line number Diff line
@@ -408,7 +408,7 @@ ENDPROC(chacha_doarm)

/*
 * void hchacha_block_arm(const struct chacha_state *state,
 *			  u32 out[8], int nrounds);
 *			  u32 out[HCHACHA_OUT_WORDS], int nrounds);
 */
ENTRY(hchacha_block_arm)
	push		{r1,r4-r11,lr}
+5 −5
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ asmlinkage void chacha_4block_xor_neon(const struct chacha_state *state,
				       u8 *dst, const u8 *src,
				       int nrounds, int bytes);
asmlinkage void hchacha_block_neon(const struct chacha_state *state,
				   u32 *out, int nrounds);
				   u32 out[HCHACHA_OUT_WORDS], int nrounds);

static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_neon);

@@ -61,14 +61,14 @@ static void chacha_doneon(struct chacha_state *state, u8 *dst, const u8 *src,
	}
}

void hchacha_block_arch(const struct chacha_state *state, u32 *stream,
			int nrounds)
void hchacha_block_arch(const struct chacha_state *state,
			u32 out[HCHACHA_OUT_WORDS], int nrounds)
{
	if (!static_branch_likely(&have_neon) || !crypto_simd_usable()) {
		hchacha_block_generic(state, stream, nrounds);
		hchacha_block_generic(state, out, nrounds);
	} else {
		kernel_neon_begin();
		hchacha_block_neon(state, stream, nrounds);
		hchacha_block_neon(state, out, nrounds);
		kernel_neon_end();
	}
}
+1 −1
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@ asmlinkage void chacha_crypt_arch(struct chacha_state *state,
EXPORT_SYMBOL(chacha_crypt_arch);

asmlinkage void hchacha_block_arch(const struct chacha_state *state,
				   u32 *stream, int nrounds);
				   u32 out[HCHACHA_OUT_WORDS], int nrounds);
EXPORT_SYMBOL(hchacha_block_arch);

bool chacha_is_arch_optimized(void)
+2 −2
Original line number Diff line number Diff line
@@ -49,9 +49,9 @@ static void chacha_p10_do_8x(struct chacha_state *state, u8 *dst, const u8 *src,
}

void hchacha_block_arch(const struct chacha_state *state,
			u32 *stream, int nrounds)
			u32 out[HCHACHA_OUT_WORDS], int nrounds)
{
	hchacha_block_generic(state, stream, nrounds);
	hchacha_block_generic(state, out, nrounds);
}
EXPORT_SYMBOL(hchacha_block_arch);

Loading