Created framework for BLISS post-quantum signature algorithm
[strongswan.git] / src / libstrongswan / credentials / keys / public_key.c
1 /*
2 * Copyright (C) 2007 Martin Willi
3 * Copyright (C) 2014 Andreas Steffen
4 * HSR Hochschule fuer Technik Rapperswil
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 */
16
17 #include <asn1/oid.h>
18
19 #include "public_key.h"
20
21 ENUM(key_type_names, KEY_ANY, KEY_BLISS,
22 "ANY",
23 "RSA",
24 "ECDSA",
25 "DSA",
26 "BLISS"
27 );
28
29 ENUM(signature_scheme_names, SIGN_UNKNOWN, SIGN_BLISS_IV_SHA384,
30 "UNKNOWN",
31 "RSA_EMSA_PKCS1_NULL",
32 "RSA_EMSA_PKCS1_MD5",
33 "RSA_EMSA_PKCS1_SHA1",
34 "RSA_EMSA_PKCS1_SHA224",
35 "RSA_EMSA_PKCS1_SHA256",
36 "RSA_EMSA_PKCS1_SHA384",
37 "RSA_EMSA_PKCS1_SHA512",
38 "ECDSA_WITH_SHA1_DER",
39 "ECDSA_WITH_SHA256_DER",
40 "ECDSA_WITH_SHA384_DER",
41 "ECDSA_WITH_SHA512_DER",
42 "ECDSA_WITH_NULL",
43 "ECDSA-256",
44 "ECDSA-384",
45 "ECDSA-521",
46 "BLISS-I_SHA256",
47 "BLISS-IV_SHA384",
48 );
49
50 ENUM(encryption_scheme_names, ENCRYPT_UNKNOWN, ENCRYPT_RSA_OAEP_SHA512,
51 "ENCRYPT_UNKNOWN",
52 "ENCRYPT_RSA_PKCS1",
53 "ENCRYPT_RSA_OAEP_SHA1",
54 "ENCRYPT_RSA_OAEP_SHA224",
55 "ENCRYPT_RSA_OAEP_SHA256",
56 "ENCRYPT_RSA_OAEP_SHA384",
57 "ENCRYPT_RSA_OAEP_SHA512",
58 );
59
60 /**
61 * See header.
62 */
63 bool public_key_equals(public_key_t *this, public_key_t *other)
64 {
65 cred_encoding_type_t type;
66 chunk_t a, b;
67
68 if (this == other)
69 {
70 return TRUE;
71 }
72
73 for (type = 0; type < CRED_ENCODING_MAX; type++)
74 {
75 if (this->get_fingerprint(this, type, &a) &&
76 other->get_fingerprint(other, type, &b))
77 {
78 return chunk_equals(a, b);
79 }
80 }
81 return FALSE;
82 }
83
84 /**
85 * See header.
86 */
87 bool public_key_has_fingerprint(public_key_t *public, chunk_t fingerprint)
88 {
89 cred_encoding_type_t type;
90 chunk_t current;
91
92 for (type = 0; type < KEYID_MAX; type++)
93 {
94 if (public->get_fingerprint(public, type, &current) &&
95 chunk_equals(current, fingerprint))
96 {
97 return TRUE;
98 }
99 }
100 return FALSE;
101 }
102
103 /*
104 * Defined in header.
105 */
106 signature_scheme_t signature_scheme_from_oid(int oid)
107 {
108 switch (oid)
109 {
110 case OID_MD5_WITH_RSA:
111 case OID_MD5:
112 return SIGN_RSA_EMSA_PKCS1_MD5;
113 case OID_SHA1_WITH_RSA:
114 case OID_SHA1:
115 return SIGN_RSA_EMSA_PKCS1_SHA1;
116 case OID_SHA224_WITH_RSA:
117 case OID_SHA224:
118 return SIGN_RSA_EMSA_PKCS1_SHA224;
119 case OID_SHA256_WITH_RSA:
120 case OID_SHA256:
121 return SIGN_RSA_EMSA_PKCS1_SHA256;
122 case OID_SHA384_WITH_RSA:
123 case OID_SHA384:
124 return SIGN_RSA_EMSA_PKCS1_SHA384;
125 case OID_SHA512_WITH_RSA:
126 case OID_SHA512:
127 return SIGN_RSA_EMSA_PKCS1_SHA512;
128 case OID_ECDSA_WITH_SHA1:
129 case OID_EC_PUBLICKEY:
130 return SIGN_ECDSA_WITH_SHA1_DER;
131 case OID_ECDSA_WITH_SHA256:
132 return SIGN_ECDSA_WITH_SHA256_DER;
133 case OID_ECDSA_WITH_SHA384:
134 return SIGN_ECDSA_WITH_SHA384_DER;
135 case OID_ECDSA_WITH_SHA512:
136 return SIGN_ECDSA_WITH_SHA512_DER;
137 default:
138 return SIGN_UNKNOWN;
139 }
140 }
141