diff options
author | Franklin Wei <me@fwei.tk> | 2018-06-22 22:57:25 -0400 |
---|---|---|
committer | Franklin Wei <me@fwei.tk> | 2018-06-22 22:57:25 -0400 |
commit | 77094976e17f3c1151dc7210815f0d47029ea54b (patch) | |
tree | 0c10179dacb7d6a696132c1cd63aba1559c8c437 /crypto.c | |
parent | 898454639359d49ddb8cb098634473e9207c6e49 (diff) | |
download | csaa-77094976e17f3c1151dc7210815f0d47029ea54b.zip csaa-77094976e17f3c1151dc7210815f0d47029ea54b.tar.gz csaa-77094976e17f3c1151dc7210815f0d47029ea54b.tar.bz2 csaa-77094976e17f3c1151dc7210815f0d47029ea54b.tar.xz |
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.
Diffstat (limited to 'crypto.c')
-rw-r--r-- | crypto.c | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -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 |