]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
openssl: Add helper to determine EVP_MD from hash_algorithm_t
authorTobias Brunner <tobias@strongswan.org>
Sat, 23 Sep 2017 08:12:36 +0000 (10:12 +0200)
committerTobias Brunner <tobias@strongswan.org>
Wed, 8 Nov 2017 15:48:10 +0000 (16:48 +0100)
src/libstrongswan/plugins/openssl/openssl_hasher.c
src/libstrongswan/plugins/openssl/openssl_hasher.h

index 96ee230c9b25ce40c6195110f4ee0860d7319c28..eb6c505082129ceebe4e39f450c2c1f16bb66497 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Copyright (C) 2008 Tobias Brunner
- * Hochschule fuer Technik Rapperswil
+ * Copyright (C) 2008-2017 Tobias Brunner
+ * HSR Hochschule fuer Technik Rapperswil
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the
@@ -91,16 +91,24 @@ METHOD(hasher_t, destroy, void,
 /*
  * Described in header
  */
-openssl_hasher_t *openssl_hasher_create(hash_algorithm_t algo)
+const EVP_MD *openssl_get_md(hash_algorithm_t hash)
 {
-       private_openssl_hasher_t *this;
-       char* name;
+       char *name;
 
-       name = enum_to_name(hash_algorithm_short_names, algo);
+       name = enum_to_name(hash_algorithm_short_names, hash);
        if (!name)
        {
                return NULL;
        }
+       return EVP_get_digestbyname(name);
+}
+
+/*
+ * Described in header
+ */
+openssl_hasher_t *openssl_hasher_create(hash_algorithm_t algo)
+{
+       private_openssl_hasher_t *this;
 
        INIT(this,
                .public = {
@@ -114,7 +122,7 @@ openssl_hasher_t *openssl_hasher_create(hash_algorithm_t algo)
                },
        );
 
-       this->hasher = EVP_get_digestbyname(name);
+       this->hasher = openssl_get_md(algo);
        if (!this->hasher)
        {
                /* OpenSSL does not support the requested algo */
index b03f6891b551b0e23fb7d2918f9012554c27e7f4..66b9b505e409dceb083477b1c23416d02084f1af 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Copyright (C) 2008 Tobias Brunner
- * Hochschule fuer Technik Rapperswil
+ * Copyright (C) 2008-2017 Tobias Brunner
+ * HSR Hochschule fuer Technik Rapperswil
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the
@@ -25,6 +25,8 @@ typedef struct openssl_hasher_t openssl_hasher_t;
 
 #include <crypto/hashers/hasher.h>
 
+#include <openssl/evp.h>
+
 /**
  * Implementation of hashers using OpenSSL.
  */
@@ -36,6 +38,14 @@ struct openssl_hasher_t {
        hasher_t hasher;
 };
 
+/**
+ * Determine EVP_MD for the given hash algorithm
+ *
+ * @param hash                 hash algorithm
+ * @return                             EVP_MD or NULL if not found/supported
+ */
+const EVP_MD *openssl_get_md(hash_algorithm_t hash);
+
 /**
  * Constructor to create openssl_hasher_t.
  *