dedup

deduplicating backup program
git clone git://git.2f30.org/dedup
Log | Files | Refs | README | LICENSE

commit d0213e5514ecb4a49986054e94943ff3016c5766
parent 606b9b2b5560acf057d87bacb67d18512c3c1653
Author: sin <sin@2f30.org>
Date:   Thu,  2 May 2019 16:37:38 +0100

Add some comments to bencrypt.c

Diffstat:
Mbencrypt.c | 8++++++++
1 file changed, 8 insertions(+), 0 deletions(-)

diff --git a/bencrypt.c b/bencrypt.c @@ -174,6 +174,7 @@ beput(struct bctx *bctx, void *buf, size_t n, unsigned char *md) char *ebuf; size_t en; + /* Calculate size of encrypted block */ ectx = bctx->ectx; if (ectx->type == EDNONETYPE) en = n; @@ -182,12 +183,15 @@ beput(struct bctx *bctx, void *buf, size_t n, unsigned char *md) else return -1; + /* Allocate encrypted block */ ebuf = malloc(EDSIZE + en); if (ebuf == NULL) return -1; + /* Prepend the encryption descriptor */ ed.type = ectx->type; ed.size = en; + /* Fill nonce buffer */ if (ectx->type == EDNONETYPE) { memset(ed.nonce, 0, sizeof(ed.nonce)); } else if (ectx->type == EDCHACHATYPE) { @@ -198,6 +202,7 @@ beput(struct bctx *bctx, void *buf, size_t n, unsigned char *md) } packed(ebuf, &ed); + /* Encrypt block */ if (ectx->type == EDNONETYPE) { memcpy(&ebuf[EDSIZE], buf, en); } else if (ectx->type == EDCHACHATYPE) { @@ -230,17 +235,20 @@ beget(struct bctx *bctx, unsigned char *md, void *buf, size_t *n) char *ebuf; size_t dn, size; + /* Calculate maximum size of encrypted block */ size = EDSIZE + *n + crypto_aead_xchacha20poly1305_ietf_ABYTES; ebuf = malloc(size); if (ebuf == NULL) return -1; + /* Read encrypted block */ bops = bstorageops(); if (bops->get(bctx, md, ebuf, &size) < 0) { free(ebuf); return -1; } + /* Decrypt block */ unpacked(ebuf, &ed); if (ed.type == EDNONETYPE) { dn = ed.size;