dedup

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

commit dda406622a65ea3905118661977763385ff03d3b
parent 1feae458b96873f36e197e2eadcf34bde003b43e
Author: sin <sin@2f30.org>
Date:   Fri,  3 May 2019 12:24:28 +0100

Add some comments to bencrypt

Diffstat:
Mbencrypt.c | 14++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/bencrypt.c b/bencrypt.c @@ -47,15 +47,15 @@ static struct bops bops = { /* Encryption layer context */ struct ectx { - int type; /* encryption algorithm type for new blocks */ + int type; /* encryption algorithm type for new blocks */ unsigned char key[KEYSIZE]; /* secret key */ }; /* Encryption descriptor */ struct ed { - uint16_t type; /* encryption algorithm type */ - uint8_t reserved[6]; - uint64_t size; + uint16_t type; /* encryption algorithm type */ + uint8_t reserved[6]; /* should be set to 0 when writing */ + uint64_t size; /* size of encrypted block */ unsigned char nonce[crypto_aead_xchacha20poly1305_ietf_NPUBBYTES]; }; @@ -98,6 +98,7 @@ becreat(struct bctx *bctx, char *path, int mode, struct bparam *bpar) struct bops *bops; int type; + /* Determine algorithm type */ if (strcasecmp(bpar->ealgo, "none") == 0) type = EDNONETYPE; else if (strcasecmp(bpar->ealgo, "XChaCha20-Poly1305") == 0) @@ -105,12 +106,14 @@ becreat(struct bctx *bctx, char *path, int mode, struct bparam *bpar) else return -1; + /* Ensure that if caller requested encryption, a key was provided */ if (type != EDNONETYPE && bpar->key == NULL) return -1; if (sodium_init() < 0) return -1; + /* Allocate and initialize encryption context */ bctx->ectx = calloc(1, sizeof(struct ectx)); if (bctx->ectx == NULL) return -1; @@ -133,6 +136,7 @@ beopen(struct bctx *bctx, char *path, int flags, int mode, struct bparam *bpar) struct ectx *ectx; struct bops *bops; + /* Allocate and initialize encryption context */ bctx->ectx = calloc(1, sizeof(struct ectx)); if (bctx->ectx == NULL) return -1; @@ -146,6 +150,7 @@ beopen(struct bctx *bctx, char *path, int flags, int mode, struct bparam *bpar) return -1; } + /* Determine algorithm type */ if (strcasecmp(bpar->ealgo, "none") == 0) ectx->type = EDNONETYPE; else if (strcasecmp(bpar->ealgo, "XChaCha20-Poly1305") == 0) @@ -156,6 +161,7 @@ beopen(struct bctx *bctx, char *path, int flags, int mode, struct bparam *bpar) return -1; } + /* Ensure that if repo is encrypted, a key was provided */ if (ectx->type != EDNONETYPE && bpar->key == NULL) { bops->close(bctx); free(ectx);