Skip to content

Commit

Permalink
Merge pull request #2577 from babarosaM33/master
Browse files Browse the repository at this point in the history
Remove unnecessary memmove
  • Loading branch information
madeye authored Jan 7, 2020
2 parents f6bc4cc + 7fe555c commit f1b185e
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/aead.c
Original file line number Diff line number Diff line change
Expand Up @@ -617,9 +617,6 @@ aead_chunk_decrypt(cipher_ctx_t *ctx, uint8_t *p, uint8_t *c, uint8_t *n,

sodium_increment(n, nlen);

if (*clen > chunk_len)
memmove(c, c + chunk_len, *clen - chunk_len);

*clen = *clen - chunk_len;

return CRYPTO_OK;
Expand Down Expand Up @@ -671,22 +668,27 @@ aead_decrypt(buffer_t *ciphertext, cipher_ctx_t *cipher_ctx, size_t capacity)
}

size_t plen = 0;
size_t cidx = 0;
while (cipher_ctx->chunk->len > 0) {
size_t chunk_clen = cipher_ctx->chunk->len;
size_t chunk_plen = 0;
err = aead_chunk_decrypt(cipher_ctx,
(uint8_t *)plaintext->data + plen,
(uint8_t *)cipher_ctx->chunk->data,
(uint8_t *)cipher_ctx->chunk->data + cidx,
cipher_ctx->nonce, &chunk_plen, &chunk_clen);
if (err == CRYPTO_ERROR) {
return err;
} else if (err == CRYPTO_NEED_MORE) {
if (plen == 0)
return err;
else
else{
memmove((uint8_t *)cipher_ctx->chunk->data,
(uint8_t *)cipher_ctx->chunk->data + cidx, chunk_clen);
break;
}
}
cipher_ctx->chunk->len = chunk_clen;
cidx += cipher_ctx->cipher->tag_len * 2 + CHUNK_SIZE_LEN + chunk_plen;
plen += chunk_plen;
}
plaintext->len = plen;
Expand Down

0 comments on commit f1b185e

Please sign in to comment.