-/* $OpenBSD: blocks.c,v 1.21 2021/11/03 14:42:12 deraadt Exp $ */
+/* $OpenBSD: blocks.c,v 1.22 2024/02/27 11:28:30 claudio Exp $ */
/*
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
*
blk->len, blk->idx);
tok = -(blk->idx + 1);
+ hash_file_buf(&st->ctx, st->map + last, sz + blk->len);
+
/*
* Write the data we have, then follow it with
* the tag of the block that matches.
st->total += blk->len;
st->offs += blk->len;
st->hint = blk->idx + 1;
+
return;
}
st->curlen = st->curpos + sz;
st->curtok = 0;
st->curst = sz ? BLKSTAT_DATA : BLKSTAT_TOK;
+
+ hash_file_buf(&st->ctx, st->map + st->curpos, sz);
} else {
st->curpos = 0;
st->curlen = st->mapsz;
st->curst = st->mapsz ? BLKSTAT_DATA : BLKSTAT_TOK;
st->dirty = st->total = st->mapsz;
+ hash_file_buf(&st->ctx, st->map, st->mapsz);
+
LOG4("%s: flushing whole file %zu B",
path, st->mapsz);
}
-/* $OpenBSD: extern.h,v 1.47 2023/11/27 11:30:49 claudio Exp $ */
+/* $OpenBSD: extern.h,v 1.48 2024/02/27 11:28:30 claudio Exp $ */
/*
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
*
#ifndef EXTERN_H
#define EXTERN_H
+#include <openssl/md4.h>
+
/*
* This is the rsync protocol version that we support.
*/
struct blktab *blktab; /* hashtable of blocks */
uint32_t s1; /* partial sum for computing fast hash */
uint32_t s2; /* partial sum for computing fast hash */
+ MD4_CTX ctx; /* context for hash_file */
};
/*
uint32_t hash_fast(const void *, size_t);
void hash_slow(const void *, size_t, unsigned char *,
const struct sess *);
-void hash_file(const void *, size_t, unsigned char *,
- const struct sess *);
+
+void hash_file_start(MD4_CTX *, const struct sess *);
+void hash_file_buf(MD4_CTX *, const void *, size_t);
+void hash_file_final(MD4_CTX *, unsigned char *);
void copy_file(int, const char *, const struct flist *);
-/* $OpenBSD: hash.c,v 1.4 2021/06/30 13:10:04 claudio Exp $ */
+/* $OpenBSD: hash.c,v 1.5 2024/02/27 11:28:30 claudio Exp $ */
/*
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
*
* of the sequence, not the beginning.
*/
void
-hash_file(const void *buf, size_t len,
- unsigned char *md, const struct sess *sess)
+hash_file_start(MD4_CTX *ctx, const struct sess *sess)
{
- MD4_CTX ctx;
int32_t seed = htole32(sess->seed);
- MD4_Init(&ctx);
- MD4_Update(&ctx, (unsigned char *)&seed, sizeof(int32_t));
- MD4_Update(&ctx, buf, len);
- MD4_Final(md, &ctx);
+ MD4_Init(ctx);
+ MD4_Update(ctx, (unsigned char *)&seed, sizeof(int32_t));
+}
+
+void
+hash_file_buf(MD4_CTX *ctx, const void *buf, size_t len)
+{
+ MD4_Update(ctx, buf, len);
+}
+void
+hash_file_final(MD4_CTX *ctx, unsigned char *md)
+{
+ MD4_Final(md, ctx);
}
-/* $OpenBSD: sender.c,v 1.31 2024/02/19 16:39:18 claudio Exp $ */
+/* $OpenBSD: sender.c,v 1.32 2024/02/27 11:28:30 claudio Exp $ */
/*
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
*
* finished with the file.
*/
- hash_file(up->stat.map, up->stat.mapsz, fmd, sess);
+ hash_file_final(&up->stat.ctx, fmd);
if (!io_lowbuffer_alloc(sess, wb, wbsz, wbmax, dsz)) {
ERRX1("io_lowbuffer_alloc");
return 0;
/* Hash our blocks. */
+ hash_file_start(&up.stat.ctx, sess);
blkhash_set(up.stat.blktab, up.cur->blks);
/*