public-key: Add helper to map signature schemes to ASN.1 OIDs
authorTobias Brunner <tobias@strongswan.org>
Mon, 23 Feb 2015 16:38:05 +0000 (17:38 +0100)
committerTobias Brunner <tobias@strongswan.org>
Wed, 4 Mar 2015 12:54:08 +0000 (13:54 +0100)
There is a similar function to map key_type_t and hasher_t to an OID,
but this maps schemes directly (and to use the other function we'd
have to have a function to map schemes to hash algorithms first).

src/libstrongswan/credentials/keys/public_key.c
src/libstrongswan/credentials/keys/public_key.h

index 54ab15b..b6e5216 100644 (file)
@@ -143,9 +143,52 @@ signature_scheme_t signature_scheme_from_oid(int oid)
                        return SIGN_BLISS_WITH_SHA256;
                case OID_BLISS_WITH_SHA384:
                        return SIGN_BLISS_WITH_SHA384;
-               default:
-                       return SIGN_UNKNOWN;
        }
+       return SIGN_UNKNOWN;
+}
+
+/*
+ * Defined in header.
+ */
+int signature_scheme_to_oid(signature_scheme_t scheme)
+{
+       switch (scheme)
+       {
+               case SIGN_UNKNOWN:
+               case SIGN_RSA_EMSA_PKCS1_NULL:
+               case SIGN_ECDSA_WITH_NULL:
+               case SIGN_ECDSA_256:
+               case SIGN_ECDSA_384:
+               case SIGN_ECDSA_521:
+                       break;
+               case SIGN_RSA_EMSA_PKCS1_MD5:
+                       return OID_MD5_WITH_RSA;
+               case SIGN_RSA_EMSA_PKCS1_SHA1:
+                       return OID_SHA1_WITH_RSA;
+               case SIGN_RSA_EMSA_PKCS1_SHA224:
+                       return OID_SHA224_WITH_RSA;
+               case SIGN_RSA_EMSA_PKCS1_SHA256:
+                       return OID_SHA256_WITH_RSA;
+               case SIGN_RSA_EMSA_PKCS1_SHA384:
+                       return OID_SHA384_WITH_RSA;
+               case SIGN_RSA_EMSA_PKCS1_SHA512:
+                       return OID_SHA512_WITH_RSA;
+               case SIGN_ECDSA_WITH_SHA1_DER:
+                       return OID_ECDSA_WITH_SHA1;
+               case SIGN_ECDSA_WITH_SHA256_DER:
+                       return OID_ECDSA_WITH_SHA256;
+               case SIGN_ECDSA_WITH_SHA384_DER:
+                       return OID_ECDSA_WITH_SHA384;
+               case SIGN_ECDSA_WITH_SHA512_DER:
+                       return OID_ECDSA_WITH_SHA512;
+               case SIGN_BLISS_WITH_SHA256:
+                       return OID_BLISS_WITH_SHA256;
+               case SIGN_BLISS_WITH_SHA384:
+                       return OID_BLISS_WITH_SHA384;
+               case SIGN_BLISS_WITH_SHA512:
+                       return OID_BLISS_WITH_SHA512;
+       }
+       return OID_UNKNOWN;
 }
 
 /*
index f4ec09b..a106663 100644 (file)
@@ -244,11 +244,19 @@ bool public_key_has_fingerprint(public_key_t *public, chunk_t fingerprint);
  * Conversion of ASN.1 signature or hash OID to signature scheme.
  *
  * @param oid                  ASN.1 OID
- * @return                             signature_scheme, SIGN_UNKNOWN if OID is unsupported
+ * @return                             signature scheme, SIGN_UNKNOWN if OID is unsupported
  */
 signature_scheme_t signature_scheme_from_oid(int oid);
 
 /**
+ * Conversion of signature scheme to ASN.1 signature OID.
+ *
+ * @param scheme               signature scheme
+ * @return                             ASN.1 OID, OID_UNKNOWN if not supported
+ */
+int signature_scheme_to_oid(signature_scheme_t scheme);
+
+/**
  * Determine the type of key associated with a given signature scheme.
  *
  * @param scheme               signature scheme