]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
prf: Add helper function to convert OIDs to algorithm identifiers
authorTobias Brunner <tobias@strongswan.org>
Mon, 5 Mar 2018 08:43:07 +0000 (09:43 +0100)
committerTobias Brunner <tobias@strongswan.org>
Wed, 7 Mar 2018 14:23:03 +0000 (15:23 +0100)
src/libstrongswan/crypto/prfs/prf.c
src/libstrongswan/crypto/prfs/prf.h

index 12e13ef579f0e30c58919fb390a714b38d3ae397..eee09535dcf026393b76ac7feb22d691e68d2878 100644 (file)
@@ -1,7 +1,8 @@
 /*
+ * Copyright (C) 2018 Tobias Brunner
  * Copyright (C) 2005-2006 Martin Willi
  * Copyright (C) 2005 Jan Hutter
- * Hochschule fuer Technik Rapperswil
+ * 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
@@ -16,6 +17,8 @@
 
 #include "prf.h"
 
+#include <asn1/oid.h>
+
 ENUM_BEGIN(pseudo_random_function_names, PRF_UNDEFINED, PRF_CAMELLIA128_XCBC,
        "PRF_UNDEFINED",
        "PRF_FIPS_SHA1_160",
@@ -33,3 +36,25 @@ ENUM_NEXT(pseudo_random_function_names, PRF_HMAC_MD5, PRF_AES128_CMAC, PRF_CAMEL
        "PRF_AES128_CMAC");
 ENUM_END(pseudo_random_function_names, PRF_AES128_CMAC);
 
+/*
+ * Described in header.
+ */
+pseudo_random_function_t pseudo_random_function_from_oid(int oid)
+{
+       switch (oid)
+       {
+               case OID_HMAC_SHA1:
+                       return PRF_HMAC_SHA1;
+               case OID_HMAC_SHA256:
+                       return PRF_HMAC_SHA2_256;
+               case OID_HMAC_SHA384:
+                       return PRF_HMAC_SHA2_384;
+               case OID_HMAC_SHA512:
+                       return PRF_HMAC_SHA2_512;
+               case OID_HMAC_SHA224:
+               case OID_HMAC_SHA512_224:
+               case OID_HMAC_SHA512_256:
+               default:
+                       return PRF_UNDEFINED;
+       }
+}
index fe9ffc2dde5608ff970a4814faaa9641263379d5..a91de1ddc5b14f1b66dee044a524dd81da6d012d 100644 (file)
@@ -1,7 +1,8 @@
 /*
+ * Copyright (C) 2018 Tobias Brunner
  * Copyright (C) 2005-2006 Martin Willi
  * Copyright (C) 2005 Jan Hutter
- * Hochschule fuer Technik Rapperswil
+ * 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
@@ -125,4 +126,12 @@ struct prf_t {
        void (*destroy)(prf_t *this);
 };
 
+/**
+ * Conversion of ASN.1 OID to PRF algorithm.
+ *
+ * @param oid                  ASN.1 OID
+ * @return                             encryption algorithm, PRF_UNDEFINED if OID unsupported
+ */
+pseudo_random_function_t pseudo_random_function_from_oid(int oid);
+
 #endif /** PRF_H_ @}*/