X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=bluesky%2Fcrypto.c;h=6981f45be9b0c8f197e5b1e03aa2132f530f7e56;hb=a8339d9810e470f59dffb3e186dd693b751ae04a;hp=c40c15c6aa6b756a0d1742b8fb88a9f95e5115be;hpb=afdaf6a249027cccc296b8923dd95fd38736b70d;p=bluesky.git diff --git a/bluesky/crypto.c b/bluesky/crypto.c index c40c15c..6981f45 100644 --- a/bluesky/crypto.c +++ b/bluesky/crypto.c @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -15,8 +16,6 @@ #include "bluesky-private.h" -static int DISABLE_CRYPTO = 1; - /* Cryptographic operations. The rest of the BlueSky code merely calls into * the functions in this file, so this is the only point where we interface * with an external cryptographic library. */ @@ -43,14 +42,25 @@ void bluesky_crypt_random_bytes(guchar *buf, gint len) gcry_randomize(buf, len, GCRY_STRONG_RANDOM); } +/* Hash a string down to an encryption key. */ +void bluesky_crypt_hash_key(const char *keystr, uint8_t *out) +{ + guint8 raw_csum[32]; + gsize csum_len = sizeof(raw_csum); + + assert(CRYPTO_KEY_SIZE == 16); + + GChecksum *csum = g_checksum_new(G_CHECKSUM_SHA256); + g_checksum_update(csum, keystr, strlen(keystr)); + g_checksum_get_digest(csum, raw_csum, &csum_len); + g_checksum_free(csum); + + memcpy(out, raw_csum, CRYPTO_KEY_SIZE); +} + /* Encrypt a data block. */ BlueSkyRCStr *bluesky_crypt_encrypt(BlueSkyRCStr *in, const uint8_t *key) { - if (DISABLE_CRYPTO) { - bluesky_string_ref(in); - return in; - } - gcry_error_t status; gcry_cipher_hd_t handle; @@ -91,11 +101,6 @@ BlueSkyRCStr *bluesky_crypt_encrypt(BlueSkyRCStr *in, const uint8_t *key) /* Decrypt a data block. */ BlueSkyRCStr *bluesky_crypt_decrypt(BlueSkyRCStr *in, const uint8_t *key) { - if (DISABLE_CRYPTO) { - bluesky_string_ref(in); - return in; - } - gcry_error_t status; gcry_cipher_hd_t handle;