iAdd some comments to bencrypt - dedup - deduplicating backup program Err bitreich.org 70 hgit clone git://bitreich.org/dedup/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/dedup/ URL:git://bitreich.org/dedup/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/dedup/ bitreich.org 70 1Log /scm/dedup/log.gph bitreich.org 70 1Files /scm/dedup/files.gph bitreich.org 70 1Refs /scm/dedup/refs.gph bitreich.org 70 1Tags /scm/dedup/tag bitreich.org 70 1README /scm/dedup/file/README.gph bitreich.org 70 1LICENSE /scm/dedup/file/LICENSE.gph bitreich.org 70 i--- Err bitreich.org 70 1commit dda406622a65ea3905118661977763385ff03d3b /scm/dedup/commit/dda406622a65ea3905118661977763385ff03d3b.gph bitreich.org 70 1parent 1feae458b96873f36e197e2eadcf34bde003b43e /scm/dedup/commit/1feae458b96873f36e197e2eadcf34bde003b43e.gph bitreich.org 70 hAuthor: sin URL:mailto:sin@2f30.org bitreich.org 70 iDate: Fri, 3 May 2019 12:24:28 +0100 Err bitreich.org 70 i Err bitreich.org 70 iAdd some comments to bencrypt Err bitreich.org 70 i Err bitreich.org 70 iDiffstat: Err bitreich.org 70 i M bencrypt.c | 14 ++++++++++---- Err bitreich.org 70 i Err bitreich.org 70 i1 file changed, 10 insertions(+), 4 deletions(-) Err bitreich.org 70 i--- Err bitreich.org 70 1diff --git a/bencrypt.c b/bencrypt.c /scm/dedup/file/bencrypt.c.gph bitreich.org 70 i@@ -47,15 +47,15 @@ static struct bops bops = { Err bitreich.org 70 i Err bitreich.org 70 i /* Encryption layer context */ Err bitreich.org 70 i struct ectx { Err bitreich.org 70 i- int type; /* encryption algorithm type for new blocks */ Err bitreich.org 70 i+ int type; /* encryption algorithm type for new blocks */ Err bitreich.org 70 i unsigned char key[KEYSIZE]; /* secret key */ Err bitreich.org 70 i }; Err bitreich.org 70 i Err bitreich.org 70 i /* Encryption descriptor */ Err bitreich.org 70 i struct ed { Err bitreich.org 70 i- uint16_t type; /* encryption algorithm type */ Err bitreich.org 70 i- uint8_t reserved[6]; Err bitreich.org 70 i- uint64_t size; Err bitreich.org 70 i+ uint16_t type; /* encryption algorithm type */ Err bitreich.org 70 i+ uint8_t reserved[6]; /* should be set to 0 when writing */ Err bitreich.org 70 i+ uint64_t size; /* size of encrypted block */ Err bitreich.org 70 i unsigned char nonce[crypto_aead_xchacha20poly1305_ietf_NPUBBYTES]; Err bitreich.org 70 i }; Err bitreich.org 70 i Err bitreich.org 70 i@@ -98,6 +98,7 @@ becreat(struct bctx *bctx, char *path, int mode, struct bparam *bpar) Err bitreich.org 70 i struct bops *bops; Err bitreich.org 70 i int type; Err bitreich.org 70 i Err bitreich.org 70 i+ /* Determine algorithm type */ Err bitreich.org 70 i if (strcasecmp(bpar->ealgo, "none") == 0) Err bitreich.org 70 i type = EDNONETYPE; Err bitreich.org 70 i else if (strcasecmp(bpar->ealgo, "XChaCha20-Poly1305") == 0) Err bitreich.org 70 i@@ -105,12 +106,14 @@ becreat(struct bctx *bctx, char *path, int mode, struct bparam *bpar) Err bitreich.org 70 i else Err bitreich.org 70 i return -1; Err bitreich.org 70 i Err bitreich.org 70 i+ /* Ensure that if caller requested encryption, a key was provided */ Err bitreich.org 70 i if (type != EDNONETYPE && bpar->key == NULL) Err bitreich.org 70 i return -1; Err bitreich.org 70 i Err bitreich.org 70 i if (sodium_init() < 0) Err bitreich.org 70 i return -1; Err bitreich.org 70 i Err bitreich.org 70 i+ /* Allocate and initialize encryption context */ Err bitreich.org 70 i bctx->ectx = calloc(1, sizeof(struct ectx)); Err bitreich.org 70 i if (bctx->ectx == NULL) Err bitreich.org 70 i return -1; Err bitreich.org 70 i@@ -133,6 +136,7 @@ beopen(struct bctx *bctx, char *path, int flags, int mode, struct bparam *bpar) Err bitreich.org 70 i struct ectx *ectx; Err bitreich.org 70 i struct bops *bops; Err bitreich.org 70 i Err bitreich.org 70 i+ /* Allocate and initialize encryption context */ Err bitreich.org 70 i bctx->ectx = calloc(1, sizeof(struct ectx)); Err bitreich.org 70 i if (bctx->ectx == NULL) Err bitreich.org 70 i return -1; Err bitreich.org 70 i@@ -146,6 +150,7 @@ beopen(struct bctx *bctx, char *path, int flags, int mode, struct bparam *bpar) Err bitreich.org 70 i return -1; Err bitreich.org 70 i } Err bitreich.org 70 i Err bitreich.org 70 i+ /* Determine algorithm type */ Err bitreich.org 70 i if (strcasecmp(bpar->ealgo, "none") == 0) Err bitreich.org 70 i ectx->type = EDNONETYPE; Err bitreich.org 70 i else if (strcasecmp(bpar->ealgo, "XChaCha20-Poly1305") == 0) Err bitreich.org 70 i@@ -156,6 +161,7 @@ beopen(struct bctx *bctx, char *path, int flags, int mode, struct bparam *bpar) Err bitreich.org 70 i return -1; Err bitreich.org 70 i } Err bitreich.org 70 i Err bitreich.org 70 i+ /* Ensure that if repo is encrypted, a key was provided */ Err bitreich.org 70 i if (ectx->type != EDNONETYPE && bpar->key == NULL) { Err bitreich.org 70 i bops->close(bctx); Err bitreich.org 70 i free(ectx); Err bitreich.org 70 .