akcipher.c (addde1f2c966833f210e9318b17050293086b8c6) | akcipher.c (6cb8815f41a966b217c0d9826c592254d72dcc31) |
---|---|
1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * Public Key Encryption 4 * 5 * Copyright (c) 2015, Intel Corporation 6 * Authors: Tadeusz Struk <tadeusz.struk@intel.com> 7 */ 8#include <crypto/internal/akcipher.h> --- 4 unchanged lines hidden (view full) --- 13#include <linux/scatterlist.h> 14#include <linux/seq_file.h> 15#include <linux/slab.h> 16#include <linux/string.h> 17#include <net/netlink.h> 18 19#include "internal.h" 20 | 1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * Public Key Encryption 4 * 5 * Copyright (c) 2015, Intel Corporation 6 * Authors: Tadeusz Struk <tadeusz.struk@intel.com> 7 */ 8#include <crypto/internal/akcipher.h> --- 4 unchanged lines hidden (view full) --- 13#include <linux/scatterlist.h> 14#include <linux/seq_file.h> 15#include <linux/slab.h> 16#include <linux/string.h> 17#include <net/netlink.h> 18 19#include "internal.h" 20 |
21struct crypto_akcipher_sync_data { 22 struct crypto_akcipher *tfm; 23 const void *src; 24 void *dst; 25 unsigned int slen; 26 unsigned int dlen; | 21#define CRYPTO_ALG_TYPE_AHASH_MASK 0x0000000e |
27 | 22 |
28 struct akcipher_request *req; 29 struct crypto_wait cwait; 30 struct scatterlist sg; 31 u8 *buf; 32}; 33 | |
34static int __maybe_unused crypto_akcipher_report( 35 struct sk_buff *skb, struct crypto_alg *alg) 36{ 37 struct crypto_report_akcipher rakcipher; 38 39 memset(&rakcipher, 0, sizeof(rakcipher)); 40 41 strscpy(rakcipher.type, "akcipher", sizeof(rakcipher.type)); --- 72 unchanged lines hidden (view full) --- 114#endif 115#if IS_ENABLED(CONFIG_CRYPTO_USER) 116 .report = crypto_akcipher_report, 117#endif 118#ifdef CONFIG_CRYPTO_STATS 119 .report_stat = crypto_akcipher_report_stat, 120#endif 121 .maskclear = ~CRYPTO_ALG_TYPE_MASK, | 23static int __maybe_unused crypto_akcipher_report( 24 struct sk_buff *skb, struct crypto_alg *alg) 25{ 26 struct crypto_report_akcipher rakcipher; 27 28 memset(&rakcipher, 0, sizeof(rakcipher)); 29 30 strscpy(rakcipher.type, "akcipher", sizeof(rakcipher.type)); --- 72 unchanged lines hidden (view full) --- 103#endif 104#if IS_ENABLED(CONFIG_CRYPTO_USER) 105 .report = crypto_akcipher_report, 106#endif 107#ifdef CONFIG_CRYPTO_STATS 108 .report_stat = crypto_akcipher_report_stat, 109#endif 110 .maskclear = ~CRYPTO_ALG_TYPE_MASK, |
122 .maskset = CRYPTO_ALG_TYPE_MASK, | 111 .maskset = CRYPTO_ALG_TYPE_AHASH_MASK, |
123 .type = CRYPTO_ALG_TYPE_AKCIPHER, 124 .tfmsize = offsetof(struct crypto_akcipher, base), 125}; 126 127int crypto_grab_akcipher(struct crypto_akcipher_spawn *spawn, 128 struct crypto_instance *inst, 129 const char *name, u32 type, u32 mask) 130{ --- 64 unchanged lines hidden (view full) --- 195{ 196 if (WARN_ON(!inst->free)) 197 return -EINVAL; 198 akcipher_prepare_alg(&inst->alg); 199 return crypto_register_instance(tmpl, akcipher_crypto_instance(inst)); 200} 201EXPORT_SYMBOL_GPL(akcipher_register_instance); 202 | 112 .type = CRYPTO_ALG_TYPE_AKCIPHER, 113 .tfmsize = offsetof(struct crypto_akcipher, base), 114}; 115 116int crypto_grab_akcipher(struct crypto_akcipher_spawn *spawn, 117 struct crypto_instance *inst, 118 const char *name, u32 type, u32 mask) 119{ --- 64 unchanged lines hidden (view full) --- 184{ 185 if (WARN_ON(!inst->free)) 186 return -EINVAL; 187 akcipher_prepare_alg(&inst->alg); 188 return crypto_register_instance(tmpl, akcipher_crypto_instance(inst)); 189} 190EXPORT_SYMBOL_GPL(akcipher_register_instance); 191 |
203static int crypto_akcipher_sync_prep(struct crypto_akcipher_sync_data *data) | 192int crypto_akcipher_sync_prep(struct crypto_akcipher_sync_data *data) |
204{ 205 unsigned int reqsize = crypto_akcipher_reqsize(data->tfm); 206 unsigned int mlen = max(data->slen, data->dlen); 207 struct akcipher_request *req; 208 struct scatterlist *sg; 209 unsigned int len; 210 u8 *buf; 211 --- 6 unchanged lines hidden (view full) --- 218 return -ENOMEM; 219 220 data->req = req; 221 222 buf = (u8 *)(req + 1) + reqsize; 223 data->buf = buf; 224 memcpy(buf, data->src, data->slen); 225 | 193{ 194 unsigned int reqsize = crypto_akcipher_reqsize(data->tfm); 195 unsigned int mlen = max(data->slen, data->dlen); 196 struct akcipher_request *req; 197 struct scatterlist *sg; 198 unsigned int len; 199 u8 *buf; 200 --- 6 unchanged lines hidden (view full) --- 207 return -ENOMEM; 208 209 data->req = req; 210 211 buf = (u8 *)(req + 1) + reqsize; 212 data->buf = buf; 213 memcpy(buf, data->src, data->slen); 214 |
226 sg = &data->sg; | 215 sg = data->sg; |
227 sg_init_one(sg, buf, mlen); 228 akcipher_request_set_crypt(req, sg, sg, data->slen, data->dlen); 229 230 crypto_init_wait(&data->cwait); 231 akcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_SLEEP, 232 crypto_req_done, &data->cwait); 233 234 return 0; 235} | 216 sg_init_one(sg, buf, mlen); 217 akcipher_request_set_crypt(req, sg, sg, data->slen, data->dlen); 218 219 crypto_init_wait(&data->cwait); 220 akcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_SLEEP, 221 crypto_req_done, &data->cwait); 222 223 return 0; 224} |
225EXPORT_SYMBOL_GPL(crypto_akcipher_sync_prep); |
|
236 | 226 |
237static int crypto_akcipher_sync_post(struct crypto_akcipher_sync_data *data, 238 int err) | 227int crypto_akcipher_sync_post(struct crypto_akcipher_sync_data *data, int err) |
239{ 240 err = crypto_wait_req(err, &data->cwait); 241 memcpy(data->dst, data->buf, data->dlen); 242 data->dlen = data->req->dst_len; 243 kfree_sensitive(data->req); 244 return err; 245} | 228{ 229 err = crypto_wait_req(err, &data->cwait); 230 memcpy(data->dst, data->buf, data->dlen); 231 data->dlen = data->req->dst_len; 232 kfree_sensitive(data->req); 233 return err; 234} |
235EXPORT_SYMBOL_GPL(crypto_akcipher_sync_post); |
|
246 247int crypto_akcipher_sync_encrypt(struct crypto_akcipher *tfm, 248 const void *src, unsigned int slen, 249 void *dst, unsigned int dlen) 250{ 251 struct crypto_akcipher_sync_data data = { 252 .tfm = tfm, 253 .src = src, --- 22 unchanged lines hidden (view full) --- 276 277 return crypto_akcipher_sync_prep(&data) ?: 278 crypto_akcipher_sync_post(&data, 279 crypto_akcipher_decrypt(data.req)) ?: 280 data.dlen; 281} 282EXPORT_SYMBOL_GPL(crypto_akcipher_sync_decrypt); 283 | 236 237int crypto_akcipher_sync_encrypt(struct crypto_akcipher *tfm, 238 const void *src, unsigned int slen, 239 void *dst, unsigned int dlen) 240{ 241 struct crypto_akcipher_sync_data data = { 242 .tfm = tfm, 243 .src = src, --- 22 unchanged lines hidden (view full) --- 266 267 return crypto_akcipher_sync_prep(&data) ?: 268 crypto_akcipher_sync_post(&data, 269 crypto_akcipher_decrypt(data.req)) ?: 270 data.dlen; 271} 272EXPORT_SYMBOL_GPL(crypto_akcipher_sync_decrypt); 273 |
274static void crypto_exit_akcipher_ops_sig(struct crypto_tfm *tfm) 275{ 276 struct crypto_akcipher **ctx = crypto_tfm_ctx(tfm); 277 278 crypto_free_akcipher(*ctx); 279} 280 281int crypto_init_akcipher_ops_sig(struct crypto_tfm *tfm) 282{ 283 struct crypto_akcipher **ctx = crypto_tfm_ctx(tfm); 284 struct crypto_alg *calg = tfm->__crt_alg; 285 struct crypto_akcipher *akcipher; 286 287 if (!crypto_mod_get(calg)) 288 return -EAGAIN; 289 290 akcipher = crypto_create_tfm(calg, &crypto_akcipher_type); 291 if (IS_ERR(akcipher)) { 292 crypto_mod_put(calg); 293 return PTR_ERR(akcipher); 294 } 295 296 *ctx = akcipher; 297 tfm->exit = crypto_exit_akcipher_ops_sig; 298 299 return 0; 300} 301EXPORT_SYMBOL_GPL(crypto_init_akcipher_ops_sig); 302 |
|
284MODULE_LICENSE("GPL"); 285MODULE_DESCRIPTION("Generic public key cipher type"); | 303MODULE_LICENSE("GPL"); 304MODULE_DESCRIPTION("Generic public key cipher type"); |