gmp: Support of SHA-3 RSA signatures
[strongswan.git] / src / libstrongswan / plugins / gmp / gmp_plugin.c
1 /*
2 * Copyright (C) 2008-2009 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 "gmp_plugin.h"
17
18 #include <library.h>
19 #include "gmp_diffie_hellman.h"
20 #include "gmp_rsa_private_key.h"
21 #include "gmp_rsa_public_key.h"
22
23 typedef struct private_gmp_plugin_t private_gmp_plugin_t;
24
25 /**
26 * private data of gmp_plugin
27 */
28 struct private_gmp_plugin_t {
29
30 /**
31 * public functions
32 */
33 gmp_plugin_t public;
34 };
35
36 METHOD(plugin_t, get_name, char*,
37 private_gmp_plugin_t *this)
38 {
39 return "gmp";
40 }
41
42 METHOD(plugin_t, get_features, int,
43 private_gmp_plugin_t *this, plugin_feature_t *features[])
44 {
45 static plugin_feature_t f[] = {
46 /* DH groups */
47 PLUGIN_REGISTER(DH, gmp_diffie_hellman_create),
48 PLUGIN_PROVIDE(DH, MODP_3072_BIT),
49 PLUGIN_DEPENDS(RNG, RNG_STRONG),
50 PLUGIN_PROVIDE(DH, MODP_4096_BIT),
51 PLUGIN_DEPENDS(RNG, RNG_STRONG),
52 PLUGIN_PROVIDE(DH, MODP_6144_BIT),
53 PLUGIN_DEPENDS(RNG, RNG_STRONG),
54 PLUGIN_PROVIDE(DH, MODP_8192_BIT),
55 PLUGIN_DEPENDS(RNG, RNG_STRONG),
56 PLUGIN_PROVIDE(DH, MODP_2048_BIT),
57 PLUGIN_DEPENDS(RNG, RNG_STRONG),
58 PLUGIN_PROVIDE(DH, MODP_2048_224),
59 PLUGIN_DEPENDS(RNG, RNG_STRONG),
60 PLUGIN_PROVIDE(DH, MODP_2048_256),
61 PLUGIN_DEPENDS(RNG, RNG_STRONG),
62 PLUGIN_PROVIDE(DH, MODP_1536_BIT),
63 PLUGIN_DEPENDS(RNG, RNG_STRONG),
64 PLUGIN_PROVIDE(DH, MODP_1024_BIT),
65 PLUGIN_DEPENDS(RNG, RNG_STRONG),
66 PLUGIN_PROVIDE(DH, MODP_1024_160),
67 PLUGIN_DEPENDS(RNG, RNG_STRONG),
68 PLUGIN_PROVIDE(DH, MODP_768_BIT),
69 PLUGIN_DEPENDS(RNG, RNG_STRONG),
70 PLUGIN_REGISTER(DH, gmp_diffie_hellman_create_custom),
71 PLUGIN_PROVIDE(DH, MODP_CUSTOM),
72 PLUGIN_DEPENDS(RNG, RNG_STRONG),
73 /* private/public keys */
74 PLUGIN_REGISTER(PRIVKEY, gmp_rsa_private_key_load, TRUE),
75 PLUGIN_PROVIDE(PRIVKEY, KEY_RSA),
76 PLUGIN_REGISTER(PRIVKEY_GEN, gmp_rsa_private_key_gen, FALSE),
77 PLUGIN_PROVIDE(PRIVKEY_GEN, KEY_RSA),
78 PLUGIN_DEPENDS(RNG, RNG_TRUE),
79 PLUGIN_REGISTER(PUBKEY, gmp_rsa_public_key_load, TRUE),
80 PLUGIN_PROVIDE(PUBKEY, KEY_RSA),
81 /* signature schemes, private */
82 PLUGIN_PROVIDE(PRIVKEY_SIGN, SIGN_RSA_EMSA_PKCS1_NULL),
83 PLUGIN_PROVIDE(PRIVKEY_SIGN, SIGN_RSA_EMSA_PKCS1_SHA2_224),
84 PLUGIN_DEPENDS(HASHER, HASH_SHA224),
85 PLUGIN_PROVIDE(PRIVKEY_SIGN, SIGN_RSA_EMSA_PKCS1_SHA2_256),
86 PLUGIN_DEPENDS(HASHER, HASH_SHA256),
87 PLUGIN_PROVIDE(PRIVKEY_SIGN, SIGN_RSA_EMSA_PKCS1_SHA2_384),
88 PLUGIN_DEPENDS(HASHER, HASH_SHA384),
89 PLUGIN_PROVIDE(PRIVKEY_SIGN, SIGN_RSA_EMSA_PKCS1_SHA2_512),
90 PLUGIN_DEPENDS(HASHER, HASH_SHA512),
91 PLUGIN_PROVIDE(PRIVKEY_SIGN, SIGN_RSA_EMSA_PKCS1_SHA3_224),
92 PLUGIN_DEPENDS(HASHER, HASH_SHA3_224),
93 PLUGIN_PROVIDE(PRIVKEY_SIGN, SIGN_RSA_EMSA_PKCS1_SHA3_256),
94 PLUGIN_DEPENDS(HASHER, HASH_SHA3_256),
95 PLUGIN_PROVIDE(PRIVKEY_SIGN, SIGN_RSA_EMSA_PKCS1_SHA3_384),
96 PLUGIN_DEPENDS(HASHER, HASH_SHA3_384),
97 PLUGIN_PROVIDE(PRIVKEY_SIGN, SIGN_RSA_EMSA_PKCS1_SHA3_512),
98 PLUGIN_DEPENDS(HASHER, HASH_SHA3_512),
99 PLUGIN_PROVIDE(PRIVKEY_SIGN, SIGN_RSA_EMSA_PKCS1_SHA1),
100 PLUGIN_DEPENDS(HASHER, HASH_SHA1),
101 PLUGIN_PROVIDE(PRIVKEY_SIGN, SIGN_RSA_EMSA_PKCS1_MD5),
102 PLUGIN_DEPENDS(HASHER, HASH_MD5),
103 /* signature verification schemes */
104 PLUGIN_PROVIDE(PUBKEY_VERIFY, SIGN_RSA_EMSA_PKCS1_NULL),
105 PLUGIN_PROVIDE(PUBKEY_VERIFY, SIGN_RSA_EMSA_PKCS1_SHA2_224),
106 PLUGIN_DEPENDS(HASHER, HASH_SHA224),
107 PLUGIN_PROVIDE(PUBKEY_VERIFY, SIGN_RSA_EMSA_PKCS1_SHA2_256),
108 PLUGIN_DEPENDS(HASHER, HASH_SHA256),
109 PLUGIN_PROVIDE(PUBKEY_VERIFY, SIGN_RSA_EMSA_PKCS1_SHA2_384),
110 PLUGIN_DEPENDS(HASHER, HASH_SHA384),
111 PLUGIN_PROVIDE(PUBKEY_VERIFY, SIGN_RSA_EMSA_PKCS1_SHA2_512),
112 PLUGIN_DEPENDS(HASHER, HASH_SHA512),
113 PLUGIN_PROVIDE(PUBKEY_VERIFY, SIGN_RSA_EMSA_PKCS1_SHA3_224),
114 PLUGIN_DEPENDS(HASHER, HASH_SHA3_224),
115 PLUGIN_PROVIDE(PUBKEY_VERIFY, SIGN_RSA_EMSA_PKCS1_SHA3_256),
116 PLUGIN_DEPENDS(HASHER, HASH_SHA3_256),
117 PLUGIN_PROVIDE(PUBKEY_VERIFY, SIGN_RSA_EMSA_PKCS1_SHA3_384),
118 PLUGIN_DEPENDS(HASHER, HASH_SHA3_384),
119 PLUGIN_PROVIDE(PUBKEY_VERIFY, SIGN_RSA_EMSA_PKCS1_SHA3_512),
120 PLUGIN_DEPENDS(HASHER, HASH_SHA3_512),
121 PLUGIN_PROVIDE(PUBKEY_VERIFY, SIGN_RSA_EMSA_PKCS1_SHA1),
122 PLUGIN_DEPENDS(HASHER, HASH_SHA1),
123 PLUGIN_PROVIDE(PUBKEY_VERIFY, SIGN_RSA_EMSA_PKCS1_MD5),
124 PLUGIN_DEPENDS(HASHER, HASH_MD5),
125 /* en-/decryption schemes */
126 PLUGIN_PROVIDE(PRIVKEY_DECRYPT, ENCRYPT_RSA_PKCS1),
127 PLUGIN_PROVIDE(PUBKEY_ENCRYPT, ENCRYPT_RSA_PKCS1),
128 PLUGIN_DEPENDS(RNG, RNG_WEAK),
129 };
130 *features = f;
131 return countof(f);
132 }
133
134 METHOD(plugin_t, destroy, void,
135 private_gmp_plugin_t *this)
136 {
137 free(this);
138 }
139
140 /*
141 * see header file
142 */
143 plugin_t *gmp_plugin_create()
144 {
145 private_gmp_plugin_t *this;
146
147 INIT(this,
148 .public = {
149 .plugin = {
150 .get_name = _get_name,
151 .get_features = _get_features,
152 .destroy = _destroy,
153 },
154 },
155 );
156
157 return &this->public.plugin;
158 }
159