Skip to contentSkip to conversation

crypto: chacha - constify ctx and iv arguments

PATCH In review Eric Biggers 3 participants 3 messages Jun 3, 2019 – Jun 13, 2019

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: chacha - constify ctx and iv arguments

From: Eric Biggers <[email protected]>

Constify the ctx and iv arguments to crypto_chacha_init() and the various chacha*_stream_xor() functions. This makes it clear that they are not modified.

---
 arch/arm/crypto/chacha-neon-glue.c   | 2 +-
 arch/arm64/crypto/chacha-neon-glue.c | 2 +-
 arch/x86/crypto/chacha_glue.c        | 2 +-
 crypto/chacha_generic.c              | 4 ++--
 include/crypto/chacha.h              | 2 +-
 5 files changed, 6 insertions(+), 6 deletions(-)
arch/arm/crypto/chacha-neon-glue.c +1 -1
index 48a89537b8283..a8e9b534c8da5 100644
@@ -63,7 +63,7 @@ static void chacha_doneon(u32 *state, u8 *dst, const u8 *src,
 }
 
 static int chacha_neon_stream_xor(struct skcipher_request *req,
-				  struct chacha_ctx *ctx, u8 *iv)
+				  const struct chacha_ctx *ctx, const u8 *iv)
 {
 	struct skcipher_walk walk;
 	u32 state[16];
arch/arm64/crypto/chacha-neon-glue.c +1 -1
index 82029cda2e77a..1495d2b18518d 100644
@@ -60,7 +60,7 @@ static void chacha_doneon(u32 *state, u8 *dst, const u8 *src,
 }
 
 static int chacha_neon_stream_xor(struct skcipher_request *req,
-				  struct chacha_ctx *ctx, u8 *iv)
+				  const struct chacha_ctx *ctx, const u8 *iv)
 {
 	struct skcipher_walk walk;
 	u32 state[16];
arch/x86/crypto/chacha_glue.c +1 -1
index 4967ad620775b..7276b7ef14ec4 100644
@@ -128,7 +128,7 @@ static void chacha_dosimd(u32 *state, u8 *dst, const u8 *src,
 }
 
 static int chacha_simd_stream_xor(struct skcipher_walk *walk,
-				  struct chacha_ctx *ctx, u8 *iv)
+				  const struct chacha_ctx *ctx, const u8 *iv)
 {
 	u32 *state, state_buf[16 + 2] __aligned(8);
 	int next_yield = 4096; /* bytes until next FPU yield */
crypto/chacha_generic.c +2 -2
index d2ec04997832e..d283bd3bdb607 100644
@@ -36,7 +36,7 @@ static void chacha_docrypt(u32 *state, u8 *dst, const u8 *src,
 }
 
 static int chacha_stream_xor(struct skcipher_request *req,
-			     struct chacha_ctx *ctx, u8 *iv)
+			     const struct chacha_ctx *ctx, const u8 *iv)
 {
 	struct skcipher_walk walk;
 	u32 state[16];
@@ -60,7 +60,7 @@ static int chacha_stream_xor(struct skcipher_request *req,
 	return err;
 }
 
-void crypto_chacha_init(u32 *state, struct chacha_ctx *ctx, u8 *iv)
+void crypto_chacha_init(u32 *state, const struct chacha_ctx *ctx, const u8 *iv)
 {
 	state[0]  = 0x61707865; /* "expa" */
 	state[1]  = 0x3320646e; /* "nd 3" */
include/crypto/chacha.h +1 -1
index 1fc70a69d5508..d1e723c6a37dd 100644
@@ -41,7 +41,7 @@ static inline void chacha20_block(u32 *state, u8 *stream)
 }
 void hchacha_block(const u32 *in, u32 *out, int nrounds);
 
-void crypto_chacha_init(u32 *state, struct chacha_ctx *ctx, u8 *iv);
+void crypto_chacha_init(u32 *state, const struct chacha_ctx *ctx, const u8 *iv);
 
 int crypto_chacha20_setkey(struct crypto_skcipher *tfm, const u8 *key,
 			   unsigned int keysize);
Signature · 1 line
2.21.0
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Eric Biggers

From: Eric Biggers <[email protected]>

Constify the ctx and iv arguments to crypto_chacha_init() and the various chacha*_stream_xor() functions. This makes it clear that they are not modified.

Quoted 85 lines
---
 arch/arm/crypto/chacha-neon-glue.c   | 2 +-
 arch/arm64/crypto/chacha-neon-glue.c | 2 +-
 arch/x86/crypto/chacha_glue.c        | 2 +-
 crypto/chacha_generic.c              | 4 ++--
 include/crypto/chacha.h              | 2 +-
 5 files changed, 6 insertions(+), 6 deletions(-)
arch/arm/crypto/chacha-neon-glue.c +1 -1
index 48a89537b8283..a8e9b534c8da5 100644
@@ -63,7 +63,7 @@ static void chacha_doneon(u32 *state, u8 *dst, const u8 *src,
 }
 
 static int chacha_neon_stream_xor(struct skcipher_request *req,
-                                 struct chacha_ctx *ctx, u8 *iv)
+                                 const struct chacha_ctx *ctx, const u8 *iv)
 {
        struct skcipher_walk walk;
        u32 state[16];
arch/arm64/crypto/chacha-neon-glue.c +1 -1
index 82029cda2e77a..1495d2b18518d 100644
@@ -60,7 +60,7 @@ static void chacha_doneon(u32 *state, u8 *dst, const u8 *src,
 }
 
 static int chacha_neon_stream_xor(struct skcipher_request *req,
-                                 struct chacha_ctx *ctx, u8 *iv)
+                                 const struct chacha_ctx *ctx, const u8 *iv)
 {
        struct skcipher_walk walk;
        u32 state[16];
arch/x86/crypto/chacha_glue.c +1 -1
index 4967ad620775b..7276b7ef14ec4 100644
@@ -128,7 +128,7 @@ static void chacha_dosimd(u32 *state, u8 *dst, const u8 *src,
 }
 
 static int chacha_simd_stream_xor(struct skcipher_walk *walk,
-                                 struct chacha_ctx *ctx, u8 *iv)
+                                 const struct chacha_ctx *ctx, const u8 *iv)
 {
        u32 *state, state_buf[16 + 2] __aligned(8);
        int next_yield = 4096; /* bytes until next FPU yield */
crypto/chacha_generic.c +2 -2
index d2ec04997832e..d283bd3bdb607 100644
@@ -36,7 +36,7 @@ static void chacha_docrypt(u32 *state, u8 *dst, const u8 *src,
 }
 
 static int chacha_stream_xor(struct skcipher_request *req,
-                            struct chacha_ctx *ctx, u8 *iv)
+                            const struct chacha_ctx *ctx, const u8 *iv)
 {
        struct skcipher_walk walk;
        u32 state[16];
@@ -60,7 +60,7 @@ static int chacha_stream_xor(struct skcipher_request *req,
        return err;
 }
 
-void crypto_chacha_init(u32 *state, struct chacha_ctx *ctx, u8 *iv)
+void crypto_chacha_init(u32 *state, const struct chacha_ctx *ctx, const u8 *iv)
 {
        state[0]  = 0x61707865; /* "expa" */
        state[1]  = 0x3320646e; /* "nd 3" */
include/crypto/chacha.h +1 -2
index 1fc70a69d5508..d1e723c6a37dd 100644
@@ -41,7 +41,7 @@ static inline void chacha20_block(u32 *state, u8 *stream)
 }
 void hchacha_block(const u32 *in, u32 *out, int nrounds);
 
-void crypto_chacha_init(u32 *state, struct chacha_ctx *ctx, u8 *iv);
+void crypto_chacha_init(u32 *state, const struct chacha_ctx *ctx, const u8 *iv);
 
 int crypto_chacha20_setkey(struct crypto_skcipher *tfm, const u8 *key,
                           unsigned int keysize);
--

2.21.0

maintainer
#2 lore raw
In reply to Eric Biggers
Quoted 6 lines · Eric Biggers

From: Eric Biggers <[email protected]>

Constify the ctx and iv arguments to crypto_chacha_init() and the various chacha*_stream_xor() functions. This makes it clear that they are not modified.

Quoted 8 lines

---

arch/arm/crypto/chacha-neon-glue.c   | 2 +-
arch/arm64/crypto/chacha-neon-glue.c | 2 +-
arch/x86/crypto/chacha_glue.c        | 2 +-
crypto/chacha_generic.c              | 4 ++--
include/crypto/chacha.h              | 2 +-
5 files changed, 6 insertions(+), 6 deletions(-)

Patch applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt