crypto: sun4i-ss - linearize buffers content must be kept
authorCorentin Labbe <clabbe@baylibre.com>
Mon, 14 Dec 2020 20:02:25 +0000 (20:02 +0000)
committerHerbert Xu <herbert@gondor.apana.org.au>
Sat, 2 Jan 2021 21:41:35 +0000 (08:41 +1100)
When running the non-optimized cipher function, SS produce partial random
output.
This is due to linearize buffers being reseted after each loop.

For preserving stack, instead of moving them back to start of function,
I move them in sun4i_ss_ctx.

Fixes: 8d3bcb9900ca ("crypto: sun4i-ss - reduce stack usage")
Signed-off-by: Corentin Labbe <clabbe@baylibre.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h

index b72de8939497b98f99703cb8ea766af8ead15758..19f1aa577ed4d6c2ee5e401482ce38c57742fd71 100644 (file)
@@ -233,8 +233,6 @@ static int sun4i_ss_cipher_poll(struct skcipher_request *areq)
 
        while (oleft) {
                if (ileft) {
-                       char buf[4 * SS_RX_MAX];/* buffer for linearize SG src */
-
                        /*
                         * todo is the number of consecutive 4byte word that we
                         * can read from current SG
@@ -256,12 +254,12 @@ static int sun4i_ss_cipher_poll(struct skcipher_request *areq)
                                 */
                                todo = min(rx_cnt * 4 - ob, ileft);
                                todo = min_t(size_t, todo, mi.length - oi);
-                               memcpy(buf + ob, mi.addr + oi, todo);
+                               memcpy(ss->buf + ob, mi.addr + oi, todo);
                                ileft -= todo;
                                oi += todo;
                                ob += todo;
                                if (!(ob % 4)) {
-                                       writesl(ss->base + SS_RXFIFO, buf,
+                                       writesl(ss->base + SS_RXFIFO, ss->buf,
                                                ob / 4);
                                        ob = 0;
                                }
@@ -295,13 +293,11 @@ static int sun4i_ss_cipher_poll(struct skcipher_request *areq)
                                oo = 0;
                        }
                } else {
-                       char bufo[4 * SS_TX_MAX]; /* buffer for linearize SG dst */
-
                        /*
                         * read obl bytes in bufo, we read at maximum for
                         * emptying the device
                         */
-                       readsl(ss->base + SS_TXFIFO, bufo, tx_cnt);
+                       readsl(ss->base + SS_TXFIFO, ss->bufo, tx_cnt);
                        obl = tx_cnt * 4;
                        obo = 0;
                        do {
@@ -313,7 +309,7 @@ static int sun4i_ss_cipher_poll(struct skcipher_request *areq)
                                 */
                                todo = min_t(size_t,
                                             mo.length - oo, obl - obo);
-                               memcpy(mo.addr + oo, bufo + obo, todo);
+                               memcpy(mo.addr + oo, ss->bufo + obo, todo);
                                oleft -= todo;
                                obo += todo;
                                oo += todo;
index 5c291e4a6857b6c4edc9357dd968a6a548c127a7..c242fccb2ab67fa3d9bd52ced07a4131ae41a5c9 100644 (file)
@@ -148,6 +148,8 @@ struct sun4i_ss_ctx {
        struct reset_control *reset;
        struct device *dev;
        struct resource *res;
+       char buf[4 * SS_RX_MAX];/* buffer for linearize SG src */
+       char bufo[4 * SS_TX_MAX]; /* buffer for linearize SG dst */
        spinlock_t slock; /* control the use of the device */
 #ifdef CONFIG_CRYPTO_DEV_SUN4I_SS_PRNG
        u32 seed[SS_SEED_LEN / BITS_PER_LONG];