summaryrefslogtreecommitdiff
path: root/src/auth_algo.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/auth_algo.c')
-rw-r--r--src/auth_algo.c42
1 files changed, 21 insertions, 21 deletions
diff --git a/src/auth_algo.c b/src/auth_algo.c
index e9b6d0f..8ee3f49 100644
--- a/src/auth_algo.c
+++ b/src/auth_algo.c
@@ -154,15 +154,15 @@ int auth_algo_sha1_init(auth_algo_t* aa)
auth_algo_sha1_param_t* params = aa->params_;
-#ifndef USE_SSL_CRYPTO
+#ifdef USE_SSL_CRYPTO
+ HMAC_CTX_init(&params->ctx_);
+ HMAC_Init_ex(&params->ctx_, NULL, 0, EVP_sha1(), NULL);
+#else // USE_GCRYPT is the default
gcry_error_t err = gcry_md_open(&params->handle_, GCRY_MD_SHA1, GCRY_MD_FLAG_HMAC);
if(err) {
log_printf(ERROR, "failed to open message digest algo: %s", gcry_strerror(err));
return -1;
}
-#else
- HMAC_CTX_init(&params->ctx_);
- HMAC_Init_ex(&params->ctx_, NULL, 0, EVP_sha1(), NULL);
#endif
return 0;
@@ -176,11 +176,11 @@ void auth_algo_sha1_close(auth_algo_t* aa)
if(aa->params_) {
auth_algo_sha1_param_t* params = aa->params_;
-#ifndef USE_SSL_CRYPTO
+#ifdef USE_SSL_CRYPTO
+ HMAC_CTX_cleanup(&params->ctx_);
+#else // USE_GCRYPT is the default
if(params->handle_)
gcry_md_close(params->handle_);
-#else
- HMAC_CTX_cleanup(&params->ctx_);
#endif
free(aa->params_);
@@ -207,7 +207,13 @@ void auth_algo_sha1_generate(auth_algo_t* aa, key_derivation_t* kd, key_derivati
if(ret < 0)
return;
-#ifndef USE_SSL_CRYPTO
+#ifdef 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);
+#else // USE_GCRYPT is the default
gcry_error_t err = gcry_md_setkey(params->handle_, aa->key_.buf_, aa->key_.length_);
if(err) {
log_printf(ERROR, "failed to set hmac key: %s", gcry_strerror(err));
@@ -218,12 +224,6 @@ void auth_algo_sha1_generate(auth_algo_t* aa, key_derivation_t* kd, key_derivati
gcry_md_write(params->handle_, encrypted_packet_get_auth_portion(packet), encrypted_packet_get_auth_portion_length(packet));
gcry_md_final(params->handle_);
u_int8_t* hmac = gcry_md_read(params->handle_, 0);
-#else
- 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);
#endif
u_int8_t* tag = encrypted_packet_get_auth_tag(packet);
@@ -255,7 +255,13 @@ int auth_algo_sha1_check_tag(auth_algo_t* aa, key_derivation_t* kd, key_derivati
if(ret < 0)
return 0;
-#ifndef USE_SSL_CRYPTO
+#ifdef 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);
+#else // USE_GCRYPT is the default
gcry_error_t err = gcry_md_setkey(params->handle_, aa->key_.buf_, aa->key_.length_);
if(err) {
log_printf(ERROR, "failed to set hmac key: %s", gcry_strerror(err));
@@ -266,12 +272,6 @@ int auth_algo_sha1_check_tag(auth_algo_t* aa, key_derivation_t* kd, key_derivati
gcry_md_write(params->handle_, encrypted_packet_get_auth_portion(packet), encrypted_packet_get_auth_portion_length(packet));
gcry_md_final(params->handle_);
u_int8_t* hmac = gcry_md_read(params->handle_, 0);
-#else
- 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);
#endif
u_int8_t* tag = encrypted_packet_get_auth_tag(packet);