summaryrefslogtreecommitdiff
path: root/src/cipher.c
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anytun.org>2014-06-21 18:26:51 +0000
committerChristian Pointner <equinox@anytun.org>2014-06-21 18:26:51 +0000
commit01ef67da5564e1dcb380adead3e7f869fa3be2c8 (patch)
tree2d61c96e2aed44703955ce731ffa28a5f055fff7 /src/cipher.c
parentrefactored crypto lib selection (diff)
added defines for nettle as crypto lib
further improved selection of crypto lib
Diffstat (limited to 'src/cipher.c')
-rw-r--r--src/cipher.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/cipher.c b/src/cipher.c
index 03449a0..a2e7f5e 100644
--- a/src/cipher.c
+++ b/src/cipher.c
@@ -210,7 +210,12 @@ int cipher_aesctr_init(cipher_t* c)
if(!c->params_)
return -2;
-#ifdef USE_GCRYPT
+#if defined(USE_SSL_CRYPTO)
+ // nothing here
+#elif defined(USE_NETTLE)
+ // TODO: nettle
+
+#else // USE_GCRYPT is the default
int algo;
switch(c->key_length_) {
case 128: algo = GCRY_CIPHER_AES128; break;
@@ -239,7 +244,12 @@ void cipher_aesctr_close(cipher_t* c)
return;
if(c->params_) {
-#ifdef USE_GCRYPT
+#if defined(USE_SSL_CRYPTO)
+ // nothing here
+#elif defined(USE_NETTLE)
+ // TODO: nettle
+
+#else // USE_GCRYPT is the default
cipher_aesctr_param_t* params = c->params_;
gcry_cipher_close(params->handle_);
#endif
@@ -285,12 +295,15 @@ int32_t cipher_aesctr_crypt(cipher_t* c, key_derivation_t* kd, key_derivation_di
if(ret < 0)
return ret;
-#ifdef USE_SSL_CRYPTO
+#if defined(USE_SSL_CRYPTO)
ret = AES_set_encrypt_key(c->key_.buf_, c->key_length_, &params->aes_key_);
if(ret) {
log_printf(ERROR, "failed to set cipher key (code: %d)", ret);
return -1;
}
+#elif defined(USE_NETTLE)
+ // TODO: nettle
+
#else // USE_GCRYPT is the default
gcry_error_t err = gcry_cipher_setkey(params->handle_, c->key_.buf_, c->key_.length_);
if(err) {
@@ -305,7 +318,7 @@ int32_t cipher_aesctr_crypt(cipher_t* c, key_derivation_t* kd, key_derivation_di
return ret;
}
-#ifdef USE_SSL_CRYPTO
+#if defined(USE_SSL_CRYPTO)
if(C_AESCTR_CTR_LENGTH != AES_BLOCK_SIZE) {
log_printf(ERROR, "failed to set cipher CTR: size doesn't fit");
return -1;
@@ -313,6 +326,9 @@ int32_t cipher_aesctr_crypt(cipher_t* c, key_derivation_t* kd, key_derivation_di
u_int32_t num = 0;
memset(params->ecount_buf_, 0, AES_BLOCK_SIZE);
AES_ctr128_encrypt(in, out, (ilen < olen) ? ilen : olen, &params->aes_key_, params->ctr_.buf_, params->ecount_buf_, &num);
+#elif defined(USE_NETTLE)
+ // TODO: nettle
+
#else // USE_GCRYPT is the default
err = gcry_cipher_setctr(params->handle_, params->ctr_.buf_, C_AESCTR_CTR_LENGTH);
if(err) {