4abaf4010c37d15ee4eb012451776318bbd9df3b
[strongswan.git] / src / libstrongswan / credentials / keys / public_key.c
1 /*
2 * Copyright (C) 2007 Martin Willi
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 #include <asn1/oid.h>
17
18 #include "public_key.h"
19
20 ENUM(key_type_names, KEY_RSA, KEY_DSA,
21 "RSA",
22 "ECDSA",
23 "DSA"
24 );
25
26 ENUM(signature_scheme_names, SIGN_UNKNOWN, SIGN_ECDSA_521,
27 "UNKNOWN",
28 "RSA_EMSA_PKCS1_NULL",
29 "RSA_EMSA_PKCS1_MD5",
30 "RSA_EMSA_PKCS1_SHA1",
31 "RSA_EMSA_PKCS1_SHA224",
32 "RSA_EMSA_PKCS1_SHA256",
33 "RSA_EMSA_PKCS1_SHA384",
34 "RSA_EMSA_PKCS1_SHA512",
35 "ECDSA_WITH_NULL",
36 "ECDSA_WITH_SHA1",
37 "ECDSA-256",
38 "ECDSA-384",
39 "ECDSA-521",
40 );
41
42 /**
43 * See header.
44 */
45 bool public_key_equals(public_key_t *this, public_key_t *other)
46 {
47 key_encoding_type_t type;
48 chunk_t a, b;
49
50 if (this == other)
51 {
52 return TRUE;
53 }
54
55 for (type = 0; type < KEY_ENCODING_MAX; type++)
56 {
57 if (this->get_fingerprint(this, type, &a) &&
58 other->get_fingerprint(other, type, &b))
59 {
60 return chunk_equals(a, b);
61 }
62 }
63 return FALSE;
64 }
65
66 /*
67 * Defined in header.
68 */
69 signature_scheme_t signature_scheme_from_oid(int oid)
70 {
71 switch (oid)
72 {
73 case OID_MD5_WITH_RSA:
74 case OID_MD5:
75 return SIGN_RSA_EMSA_PKCS1_MD5;
76 case OID_SHA1_WITH_RSA:
77 case OID_SHA1:
78 return SIGN_RSA_EMSA_PKCS1_SHA1;
79 case OID_SHA224_WITH_RSA:
80 case OID_SHA224:
81 return SIGN_RSA_EMSA_PKCS1_SHA224;
82 case OID_SHA256_WITH_RSA:
83 case OID_SHA256:
84 return SIGN_RSA_EMSA_PKCS1_SHA256;
85 case OID_SHA384_WITH_RSA:
86 case OID_SHA384:
87 return SIGN_RSA_EMSA_PKCS1_SHA384;
88 case OID_SHA512_WITH_RSA:
89 case OID_SHA512:
90 return SIGN_RSA_EMSA_PKCS1_SHA512;
91 case OID_ECDSA_WITH_SHA1:
92 case OID_EC_PUBLICKEY:
93 return SIGN_ECDSA_WITH_SHA1;
94 case OID_ECDSA_WITH_SHA256:
95 return SIGN_ECDSA_256;
96 case OID_ECDSA_WITH_SHA384:
97 return SIGN_ECDSA_384;
98 case OID_ECDSA_WITH_SHA512:
99 return SIGN_ECDSA_521;
100 default:
101 return SIGN_UNKNOWN;
102 }
103 }
104