~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/crypto/kpp.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-or-later
  2 /*
  3  * Key-agreement Protocol Primitives (KPP)
  4  *
  5  * Copyright (c) 2016, Intel Corporation
  6  * Authors: Salvatore Benedetto <salvatore.benedetto@intel.com>
  7  */
  8 
  9 #include <crypto/internal/kpp.h>
 10 #include <linux/cryptouser.h>
 11 #include <linux/errno.h>
 12 #include <linux/kernel.h>
 13 #include <linux/module.h>
 14 #include <linux/seq_file.h>
 15 #include <linux/string.h>
 16 #include <net/netlink.h>
 17 
 18 #include "internal.h"
 19 
 20 static int __maybe_unused crypto_kpp_report(
 21         struct sk_buff *skb, struct crypto_alg *alg)
 22 {
 23         struct crypto_report_kpp rkpp;
 24 
 25         memset(&rkpp, 0, sizeof(rkpp));
 26 
 27         strscpy(rkpp.type, "kpp", sizeof(rkpp.type));
 28 
 29         return nla_put(skb, CRYPTOCFGA_REPORT_KPP, sizeof(rkpp), &rkpp);
 30 }
 31 
 32 static void crypto_kpp_show(struct seq_file *m, struct crypto_alg *alg)
 33         __maybe_unused;
 34 
 35 static void crypto_kpp_show(struct seq_file *m, struct crypto_alg *alg)
 36 {
 37         seq_puts(m, "type         : kpp\n");
 38 }
 39 
 40 static void crypto_kpp_exit_tfm(struct crypto_tfm *tfm)
 41 {
 42         struct crypto_kpp *kpp = __crypto_kpp_tfm(tfm);
 43         struct kpp_alg *alg = crypto_kpp_alg(kpp);
 44 
 45         alg->exit(kpp);
 46 }
 47 
 48 static int crypto_kpp_init_tfm(struct crypto_tfm *tfm)
 49 {
 50         struct crypto_kpp *kpp = __crypto_kpp_tfm(tfm);
 51         struct kpp_alg *alg = crypto_kpp_alg(kpp);
 52 
 53         if (alg->exit)
 54                 kpp->base.exit = crypto_kpp_exit_tfm;
 55 
 56         if (alg->init)
 57                 return alg->init(kpp);
 58 
 59         return 0;
 60 }
 61 
 62 static void crypto_kpp_free_instance(struct crypto_instance *inst)
 63 {
 64         struct kpp_instance *kpp = kpp_instance(inst);
 65 
 66         kpp->free(kpp);
 67 }
 68 
 69 static const struct crypto_type crypto_kpp_type = {
 70         .extsize = crypto_alg_extsize,
 71         .init_tfm = crypto_kpp_init_tfm,
 72         .free = crypto_kpp_free_instance,
 73 #ifdef CONFIG_PROC_FS
 74         .show = crypto_kpp_show,
 75 #endif
 76 #if IS_ENABLED(CONFIG_CRYPTO_USER)
 77         .report = crypto_kpp_report,
 78 #endif
 79         .maskclear = ~CRYPTO_ALG_TYPE_MASK,
 80         .maskset = CRYPTO_ALG_TYPE_MASK,
 81         .type = CRYPTO_ALG_TYPE_KPP,
 82         .tfmsize = offsetof(struct crypto_kpp, base),
 83 };
 84 
 85 struct crypto_kpp *crypto_alloc_kpp(const char *alg_name, u32 type, u32 mask)
 86 {
 87         return crypto_alloc_tfm(alg_name, &crypto_kpp_type, type, mask);
 88 }
 89 EXPORT_SYMBOL_GPL(crypto_alloc_kpp);
 90 
 91 int crypto_grab_kpp(struct crypto_kpp_spawn *spawn,
 92                     struct crypto_instance *inst,
 93                     const char *name, u32 type, u32 mask)
 94 {
 95         spawn->base.frontend = &crypto_kpp_type;
 96         return crypto_grab_spawn(&spawn->base, inst, name, type, mask);
 97 }
 98 EXPORT_SYMBOL_GPL(crypto_grab_kpp);
 99 
100 int crypto_has_kpp(const char *alg_name, u32 type, u32 mask)
101 {
102         return crypto_type_has_alg(alg_name, &crypto_kpp_type, type, mask);
103 }
104 EXPORT_SYMBOL_GPL(crypto_has_kpp);
105 
106 static void kpp_prepare_alg(struct kpp_alg *alg)
107 {
108         struct crypto_alg *base = &alg->base;
109 
110         base->cra_type = &crypto_kpp_type;
111         base->cra_flags &= ~CRYPTO_ALG_TYPE_MASK;
112         base->cra_flags |= CRYPTO_ALG_TYPE_KPP;
113 }
114 
115 int crypto_register_kpp(struct kpp_alg *alg)
116 {
117         struct crypto_alg *base = &alg->base;
118 
119         kpp_prepare_alg(alg);
120         return crypto_register_alg(base);
121 }
122 EXPORT_SYMBOL_GPL(crypto_register_kpp);
123 
124 void crypto_unregister_kpp(struct kpp_alg *alg)
125 {
126         crypto_unregister_alg(&alg->base);
127 }
128 EXPORT_SYMBOL_GPL(crypto_unregister_kpp);
129 
130 int kpp_register_instance(struct crypto_template *tmpl,
131                           struct kpp_instance *inst)
132 {
133         if (WARN_ON(!inst->free))
134                 return -EINVAL;
135 
136         kpp_prepare_alg(&inst->alg);
137 
138         return crypto_register_instance(tmpl, kpp_crypto_instance(inst));
139 }
140 EXPORT_SYMBOL_GPL(kpp_register_instance);
141 
142 MODULE_LICENSE("GPL");
143 MODULE_DESCRIPTION("Key-agreement Protocol Primitives");
144 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php