aboutsummaryrefslogtreecommitdiff
path: root/crypto.c
diff options
context:
space:
mode:
authorFranklin Wei <me@fwei.tk>2018-06-30 20:01:43 -0400
committerFranklin Wei <me@fwei.tk>2018-06-30 20:01:43 -0400
commitf0519032a59aff4ca9edcb2916e094db93e08942 (patch)
tree2888deb8615fb03f30bab36773a9605a0546160d /crypto.c
parent03a354b8d0f2a8820db9571c639804648d804ac4 (diff)
downloadcsaa-f0519032a59aff4ca9edcb2916e094db93e08942.zip
csaa-f0519032a59aff4ca9edcb2916e094db93e08942.tar.gz
csaa-f0519032a59aff4ca9edcb2916e094db93e08942.tar.bz2
csaa-f0519032a59aff4ca9edcb2916e094db93e08942.tar.xz
Add dummy client/server for comparison; fix bugs and polish database code
Diffstat (limited to 'crypto.c')
-rw-r--r--crypto.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/crypto.c b/crypto.c
index 6fb1ead..0b626ba 100644
--- a/crypto.c
+++ b/crypto.c
@@ -1,3 +1,5 @@
+/* crypto and other generally useful stuff, shared by all code */
+
#include "crypto.h"
#include "iomt.h"
#include "trusted_module.h"
@@ -350,10 +352,14 @@ hash_t derive_key(const char *passphrase, hash_t nonce)
hash_t calc_kf(hash_t encryption_key, uint64_t file_idx)
{
- if(is_zero(encryption_key))
- return hash_null;
- return hmac_sha256(&encryption_key, sizeof(encryption_key),
- &file_idx, sizeof(file_idx));
+ hash_t kf = hash_null;
+ if(!is_zero(encryption_key))
+ kf = hmac_sha256(&encryption_key, sizeof(encryption_key),
+ &file_idx, sizeof(file_idx));
+ printf("calc_kf: encryption key = %s, file_idx = %lu, kf = %s\n",
+ hash_format(encryption_key, 4).str, file_idx,
+ hash_format(kf, 4).str);
+ return kf;
}
void memxor(unsigned char *dest, const unsigned char *b, size_t len)
@@ -453,6 +459,17 @@ void dump_versioninfo(const struct version_info *verinfo)
hash_format(verinfo->lambda, 4).str);
}
+void warn(const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+
+ char buf[256];
+ vsnprintf(buf, sizeof(buf), fmt, ap);
+
+ fprintf(stderr, "\033[31;1mWARNING\033[0m: %s\n", buf);
+}
+
void crypto_test(void)
{
#if 1