From 77094976e17f3c1151dc7210815f0d47029ea54b Mon Sep 17 00:00:00 2001 From: Franklin Wei Date: Fri, 22 Jun 2018 22:57:25 -0400 Subject: Finish implementing client and server Also makes a minor change to F_rs() IVP; the encryption pad ought to depend on the file version, not the counter. --- crypto.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'crypto.c') diff --git a/crypto.c b/crypto.c index f819fda..4125f7b 100644 --- a/crypto.c +++ b/crypto.c @@ -524,7 +524,7 @@ hash_t u64_to_hash(uint64_t n) /* simple XOR cipher, so encryption and decryption are symmetric */ hash_t crypt_secret(hash_t encrypted_secret, - uint64_t file_idx, uint64_t file_counter, + uint64_t file_idx, uint64_t file_version, const void *key, size_t keylen) { hash_t pad; /* key = encrypted_secret ^ pad */ @@ -535,7 +535,7 @@ hash_t crypt_secret(hash_t encrypted_secret, /* potential endianness issue */ HMAC_Update(ctx, (const unsigned char*)&file_idx, sizeof(file_idx)); - HMAC_Update(ctx, (const unsigned char*)&file_counter, sizeof(file_counter)); + HMAC_Update(ctx, (const unsigned char*)&file_version, sizeof(file_version)); HMAC_Final(ctx, pad.hash, NULL); HMAC_CTX_free(ctx); @@ -599,6 +599,19 @@ bool ack_verify(const struct tm_request *req, return hash_equals(hmac, correct); } +void write_to_fd(void *userdata, const void *data, size_t len) +{ + int *fdptr = userdata; + write(*fdptr, data, len); +} + + +int read_from_fd(void *userdata, void *buf, size_t len) +{ + int *fdptr = userdata; + return read(*fdptr, buf, len); +} + void crypto_test(void) { #if 1 -- cgit v1.1