Welcome to little lamb

Code » limb » commit f86ed18

chacha20_crypt: Support dst & msg overlap

author Olivier Brunel
2023-04-18 20:47:14 UTC
committer Olivier Brunel
2023-05-20 18:06:37 UTC
parent f5be997b5a44d606f8f4be4e426c75c889ae2dcb

chacha20_crypt: Support dst & msg overlap

src/liblimb/chacha20.h/chacha20_crypt.c +2 -2

diff --git a/src/liblimb/chacha20.h/chacha20_crypt.c b/src/liblimb/chacha20.h/chacha20_crypt.c
index 6ca4c2e..4f773dc 100644
--- a/src/liblimb/chacha20.h/chacha20_crypt.c
+++ b/src/liblimb/chacha20.h/chacha20_crypt.c
@@ -50,7 +50,7 @@ chacha20_crypt(void *dst_, const void *msg_, size_t mlen, void *ctx_)
         block(output, ctx->in);
 
         if (mlen <= l) {
-            memcpy(dst, msg, mlen);
+            memmove(dst, msg, mlen);
             memxor(dst, (u8 *) output + ctx->part, mlen);
             ctx->part = (ctx->part + mlen) % CHACHA_BLOCK_SIZE;
             if (!ctx->part)
@@ -58,7 +58,7 @@ chacha20_crypt(void *dst_, const void *msg_, size_t mlen, void *ctx_)
             return;
         }
 
-        memcpy(dst, msg, l);
+        memmove(dst, msg, l);
         memxor(dst, (u8 *) output + ctx->part, l);
         mlen -= l;
         dst += l;