summaryrefslogtreecommitdiff
path: root/src/auth_algo.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/auth_algo.c
parentrefactored crypto lib selection (diff)
added defines for nettle as crypto lib
further improved selection of crypto lib
Diffstat (limited to 'src/auth_algo.c')
-rw-r--r--src/auth_algo.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/auth_algo.c b/src/auth_algo.c
index 8ee3f49..87ea472 100644
--- a/src/auth_algo.c
+++ b/src/auth_algo.c
@@ -154,9 +154,12 @@ int auth_algo_sha1_init(auth_algo_t* aa)
auth_algo_sha1_param_t* params = aa->params_;
-#ifdef USE_SSL_CRYPTO
+#if defined(USE_SSL_CRYPTO)
HMAC_CTX_init(&params->ctx_);
HMAC_Init_ex(&params->ctx_, NULL, 0, EVP_sha1(), NULL);
+#elif defined(USE_NETTLE)
+ // TODO: nettle
+
#else // USE_GCRYPT is the default
gcry_error_t err = gcry_md_open(&params->handle_, GCRY_MD_SHA1, GCRY_MD_FLAG_HMAC);
if(err) {
@@ -176,8 +179,11 @@ void auth_algo_sha1_close(auth_algo_t* aa)
if(aa->params_) {
auth_algo_sha1_param_t* params = aa->params_;
-#ifdef USE_SSL_CRYPTO
+#if defined(USE_SSL_CRYPTO)
HMAC_CTX_cleanup(&params->ctx_);
+#elif defined(USE_NETTLE)
+ // TODO: nettle
+
#else // USE_GCRYPT is the default
if(params->handle_)
gcry_md_close(params->handle_);
@@ -207,12 +213,16 @@ void auth_algo_sha1_generate(auth_algo_t* aa, key_derivation_t* kd, key_derivati
if(ret < 0)
return;
-#ifdef USE_SSL_CRYPTO
+#if defined(USE_SSL_CRYPTO)
HMAC_Init_ex(&params->ctx_, aa->key_.buf_, aa->key_.length_, EVP_sha1(), NULL);
u_int8_t hmac[SHA1_LENGTH];
HMAC_Update(&params->ctx_, encrypted_packet_get_auth_portion(packet), encrypted_packet_get_auth_portion_length(packet));
HMAC_Final(&params->ctx_, hmac, NULL);
+#elif defined(USE_NETTLE)
+ // TODO: nettle
+ u_int8_t hmac[SHA1_LENGTH];
+
#else // USE_GCRYPT is the default
gcry_error_t err = gcry_md_setkey(params->handle_, aa->key_.buf_, aa->key_.length_);
if(err) {
@@ -255,12 +265,16 @@ int auth_algo_sha1_check_tag(auth_algo_t* aa, key_derivation_t* kd, key_derivati
if(ret < 0)
return 0;
-#ifdef USE_SSL_CRYPTO
+#if defined(USE_SSL_CRYPTO)
HMAC_Init_ex(&params->ctx_, aa->key_.buf_, aa->key_.length_, EVP_sha1(), NULL);
u_int8_t hmac[SHA1_LENGTH];
HMAC_Update(&params->ctx_, encrypted_packet_get_auth_portion(packet), encrypted_packet_get_auth_portion_length(packet));
HMAC_Final(&params->ctx_, hmac, NULL);
+#elif defined(USE_NETTLE)
+ // TODO: nettle
+ u_int8_t hmac[SHA1_LENGTH];
+
#else // USE_GCRYPT is the default
gcry_error_t err = gcry_md_setkey(params->handle_, aa->key_.buf_, aa->key_.length_);
if(err) {