diff options
author | Xiongfeng Wang <xiongfeng.wang@linaro.org> | 2019-01-18 00:58:13 -0500 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2019-01-25 05:41:52 -0500 |
commit | 56a00d9da159ad7a2e9cbd18a2db9165bf5c373b (patch) | |
tree | 2eca1327f931353625245f25d47de8560456c05d | |
parent | 0db1903539e9569391bff41e2e6b171f791e2ed9 (diff) |
crypto: gcm - use template array registering API to simplify the code
Use crypto template array registering API to simplify the code.
Signed-off-by: Xiongfeng Wang <xiongfeng.wang@linaro.org>
Reviewed-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r-- | crypto/gcm.c | 73 |
1 files changed, 23 insertions, 50 deletions
diff --git a/crypto/gcm.c b/crypto/gcm.c index bbce31f6199b..e1a11f529d25 100644 --- a/crypto/gcm.c +++ b/crypto/gcm.c | |||
@@ -727,12 +727,6 @@ static int crypto_gcm_create(struct crypto_template *tmpl, struct rtattr **tb) | |||
727 | ctr_name, "ghash"); | 727 | ctr_name, "ghash"); |
728 | } | 728 | } |
729 | 729 | ||
730 | static struct crypto_template crypto_gcm_tmpl = { | ||
731 | .name = "gcm", | ||
732 | .create = crypto_gcm_create, | ||
733 | .module = THIS_MODULE, | ||
734 | }; | ||
735 | |||
736 | static int crypto_gcm_base_create(struct crypto_template *tmpl, | 730 | static int crypto_gcm_base_create(struct crypto_template *tmpl, |
737 | struct rtattr **tb) | 731 | struct rtattr **tb) |
738 | { | 732 | { |
@@ -756,12 +750,6 @@ static int crypto_gcm_base_create(struct crypto_template *tmpl, | |||
756 | ctr_name, ghash_name); | 750 | ctr_name, ghash_name); |
757 | } | 751 | } |
758 | 752 | ||
759 | static struct crypto_template crypto_gcm_base_tmpl = { | ||
760 | .name = "gcm_base", | ||
761 | .create = crypto_gcm_base_create, | ||
762 | .module = THIS_MODULE, | ||
763 | }; | ||
764 | |||
765 | static int crypto_rfc4106_setkey(struct crypto_aead *parent, const u8 *key, | 753 | static int crypto_rfc4106_setkey(struct crypto_aead *parent, const u8 *key, |
766 | unsigned int keylen) | 754 | unsigned int keylen) |
767 | { | 755 | { |
@@ -989,12 +977,6 @@ out_free_inst: | |||
989 | goto out; | 977 | goto out; |
990 | } | 978 | } |
991 | 979 | ||
992 | static struct crypto_template crypto_rfc4106_tmpl = { | ||
993 | .name = "rfc4106", | ||
994 | .create = crypto_rfc4106_create, | ||
995 | .module = THIS_MODULE, | ||
996 | }; | ||
997 | |||
998 | static int crypto_rfc4543_setkey(struct crypto_aead *parent, const u8 *key, | 980 | static int crypto_rfc4543_setkey(struct crypto_aead *parent, const u8 *key, |
999 | unsigned int keylen) | 981 | unsigned int keylen) |
1000 | { | 982 | { |
@@ -1231,10 +1213,24 @@ out_free_inst: | |||
1231 | goto out; | 1213 | goto out; |
1232 | } | 1214 | } |
1233 | 1215 | ||
1234 | static struct crypto_template crypto_rfc4543_tmpl = { | 1216 | static struct crypto_template crypto_gcm_tmpls[] = { |
1235 | .name = "rfc4543", | 1217 | { |
1236 | .create = crypto_rfc4543_create, | 1218 | .name = "gcm_base", |
1237 | .module = THIS_MODULE, | 1219 | .create = crypto_gcm_base_create, |
1220 | .module = THIS_MODULE, | ||
1221 | }, { | ||
1222 | .name = "gcm", | ||
1223 | .create = crypto_gcm_create, | ||
1224 | .module = THIS_MODULE, | ||
1225 | }, { | ||
1226 | .name = "rfc4106", | ||
1227 | .create = crypto_rfc4106_create, | ||
1228 | .module = THIS_MODULE, | ||
1229 | }, { | ||
1230 | .name = "rfc4543", | ||
1231 | .create = crypto_rfc4543_create, | ||
1232 | .module = THIS_MODULE, | ||
1233 | }, | ||
1238 | }; | 1234 | }; |
1239 | 1235 | ||
1240 | static int __init crypto_gcm_module_init(void) | 1236 | static int __init crypto_gcm_module_init(void) |
@@ -1247,42 +1243,19 @@ static int __init crypto_gcm_module_init(void) | |||
1247 | 1243 | ||
1248 | sg_init_one(&gcm_zeroes->sg, gcm_zeroes->buf, sizeof(gcm_zeroes->buf)); | 1244 | sg_init_one(&gcm_zeroes->sg, gcm_zeroes->buf, sizeof(gcm_zeroes->buf)); |
1249 | 1245 | ||
1250 | err = crypto_register_template(&crypto_gcm_base_tmpl); | 1246 | err = crypto_register_templates(crypto_gcm_tmpls, |
1251 | if (err) | 1247 | ARRAY_SIZE(crypto_gcm_tmpls)); |
1252 | goto out; | ||
1253 | |||
1254 | err = crypto_register_template(&crypto_gcm_tmpl); | ||
1255 | if (err) | 1248 | if (err) |
1256 | goto out_undo_base; | 1249 | kfree(gcm_zeroes); |
1257 | 1250 | ||
1258 | err = crypto_register_template(&crypto_rfc4106_tmpl); | ||
1259 | if (err) | ||
1260 | goto out_undo_gcm; | ||
1261 | |||
1262 | err = crypto_register_template(&crypto_rfc4543_tmpl); | ||
1263 | if (err) | ||
1264 | goto out_undo_rfc4106; | ||
1265 | |||
1266 | return 0; | ||
1267 | |||
1268 | out_undo_rfc4106: | ||
1269 | crypto_unregister_template(&crypto_rfc4106_tmpl); | ||
1270 | out_undo_gcm: | ||
1271 | crypto_unregister_template(&crypto_gcm_tmpl); | ||
1272 | out_undo_base: | ||
1273 | crypto_unregister_template(&crypto_gcm_base_tmpl); | ||
1274 | out: | ||
1275 | kfree(gcm_zeroes); | ||
1276 | return err; | 1251 | return err; |
1277 | } | 1252 | } |
1278 | 1253 | ||
1279 | static void __exit crypto_gcm_module_exit(void) | 1254 | static void __exit crypto_gcm_module_exit(void) |
1280 | { | 1255 | { |
1281 | kfree(gcm_zeroes); | 1256 | kfree(gcm_zeroes); |
1282 | crypto_unregister_template(&crypto_rfc4543_tmpl); | 1257 | crypto_unregister_templates(crypto_gcm_tmpls, |
1283 | crypto_unregister_template(&crypto_rfc4106_tmpl); | 1258 | ARRAY_SIZE(crypto_gcm_tmpls)); |
1284 | crypto_unregister_template(&crypto_gcm_tmpl); | ||
1285 | crypto_unregister_template(&crypto_gcm_base_tmpl); | ||
1286 | } | 1259 | } |
1287 | 1260 | ||
1288 | module_init(crypto_gcm_module_init); | 1261 | module_init(crypto_gcm_module_init); |