#ifdef PASSWORD_CRYPTO_GNUTLS
#define BUFSIZE 128
+/* Since we can't count on having GnuTLS new enough to have
+ * gnutls_cipher_get_iv_size(), we hardcode the IV length for now. */
+#define IVLEN 16
+
gchar *password_encrypt_gnutls(const gchar *password,
const gchar *encryption_passphrase)
{
gnutls_digest_algorithm_t digest = GNUTLS_DIG_SHA512;
gnutls_cipher_hd_t handle;
gnutls_datum_t key, iv;
- int ivlen, keylen, digestlen, blocklen, ret, i;
+ int keylen, digestlen, blocklen, ret, i;
unsigned char hashbuf[BUFSIZE], *buf, *encbuf, *base, *output;
#if defined G_OS_UNIX
int rnd;
g_return_val_if_fail(password != NULL, NULL);
g_return_val_if_fail(encryption_passphrase != NULL, NULL);
- ivlen = gnutls_cipher_get_iv_size(algo);
+/* ivlen = gnutls_cipher_get_iv_size(algo);*/
keylen = gnutls_cipher_get_key_size(algo);
blocklen = gnutls_cipher_get_block_size(algo);
digestlen = gnutls_hash_get_len(digest);
}
/* Prepare random IV for cipher */
- iv.data = malloc(ivlen);
- iv.size = ivlen;
+ iv.data = malloc(IVLEN);
+ iv.size = IVLEN;
#if defined G_OS_UNIX
- ret = read(rnd, iv.data, ivlen);
- if (ret != ivlen) {
+ ret = read(rnd, iv.data, IVLEN);
+ if (ret != IVLEN) {
perror("read into iv");
close(rnd);
#elif defined G_OS_WIN32
- if (!CryptGenRandom(rnd, ivlen, iv.data)) {
+ if (!CryptGenRandom(rnd, IVLEN, iv.data)) {
debug_print("Could not read random data for IV\n");
CryptReleaseContext(rnd, 0);
#endif
gnutls_digest_algorithm_t digest = GNUTLS_DIG_UNKNOWN;
gnutls_cipher_hd_t handle;
gnutls_datum_t key, iv;
- int ivlen, keylen, digestlen, blocklen, ret, i;
+ int keylen, digestlen, blocklen, ret, i;
gsize len;
unsigned char hashbuf[BUFSIZE], *buf;
#if defined G_OS_UNIX
return NULL;
}
- ivlen = gnutls_cipher_get_iv_size(algo);
+/* ivlen = gnutls_cipher_get_iv_size(algo); */
keylen = gnutls_cipher_get_key_size(algo);
blocklen = gnutls_cipher_get_block_size(algo);
digestlen = gnutls_hash_get_len(digest);
}
/* Prepare random IV for cipher */
- iv.data = malloc(ivlen);
- iv.size = ivlen;
+ iv.data = malloc(IVLEN);
+ iv.size = IVLEN;
#if defined G_OS_UNIX
- ret = read(rnd, iv.data, ivlen);
- if (ret != ivlen) {
+ ret = read(rnd, iv.data, IVLEN);
+ if (ret != IVLEN) {
perror("read into iv");
close(rnd);
#elif defined G_OS_WIN32
- if (!CryptGenRandom(rnd, ivlen, iv.data)) {
+ if (!CryptGenRandom(rnd, IVLEN, iv.data)) {
debug_print("Could not read random data for IV\n");
CryptReleaseContext(rnd, 0);
#endif