2
0
mirror of https://github.com/edk2-porting/linux-next.git synced 2024-11-18 23:54:26 +08:00

[CRYPTO] users: Use crypto_comp and crypto_has_*

This patch converts all users to use the new crypto_comp type and the
crypto_has_* functions.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
Herbert Xu 2006-08-26 18:12:40 +10:00
parent fce32d70ba
commit e4d5b79c66
8 changed files with 60 additions and 45 deletions

View File

@ -749,7 +749,7 @@ static void test_deflate(void)
{ {
unsigned int i; unsigned int i;
char result[COMP_BUF_SIZE]; char result[COMP_BUF_SIZE];
struct crypto_tfm *tfm; struct crypto_comp *tfm;
struct comp_testvec *tv; struct comp_testvec *tv;
unsigned int tsize; unsigned int tsize;
@ -821,7 +821,7 @@ static void test_deflate(void)
ilen, dlen); ilen, dlen);
} }
out: out:
crypto_free_tfm(tfm); crypto_free_comp(tfm);
} }
static void test_available(void) static void test_available(void)
@ -830,8 +830,8 @@ static void test_available(void)
while (*name) { while (*name) {
printk("alg %s ", *name); printk("alg %s ", *name);
printk((crypto_alg_available(*name, 0)) ? printk(crypto_has_alg(*name, 0, CRYPTO_ALG_ASYNC) ?
"found\n" : "not found\n"); "found\n" : "not found\n");
name++; name++;
} }
} }

View File

@ -26,13 +26,13 @@ static int __init padlock_init(void)
{ {
int success = 0; int success = 0;
if (crypto_alg_available("aes-padlock", 0)) if (crypto_has_cipher("aes-padlock", 0, 0))
success++; success++;
if (crypto_alg_available("sha1-padlock", 0)) if (crypto_has_hash("sha1-padlock", 0, 0))
success++; success++;
if (crypto_alg_available("sha256-padlock", 0)) if (crypto_has_hash("sha256-padlock", 0, 0))
success++; success++;
if (!success) { if (!success) {

View File

@ -710,8 +710,8 @@ static struct compressor ppp_mppe = {
static int __init ppp_mppe_init(void) static int __init ppp_mppe_init(void)
{ {
int answer; int answer;
if (!(crypto_alg_available("ecb(arc4)", 0) && if (!(crypto_has_blkcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC) &&
crypto_alg_available("sha1", 0))) crypto_has_hash("sha1", 0, CRYPTO_ALG_ASYNC)))
return -ENODEV; return -ENODEV;
sha_pad = kmalloc(sizeof(struct sha_pad), GFP_KERNEL); sha_pad = kmalloc(sizeof(struct sha_pad), GFP_KERNEL);

View File

@ -928,6 +928,11 @@ static inline int crypto_has_comp(const char *alg_name, u32 type, u32 mask)
return crypto_has_alg(alg_name, type, mask); return crypto_has_alg(alg_name, type, mask);
} }
static inline const char *crypto_comp_name(struct crypto_comp *tfm)
{
return crypto_tfm_alg_name(crypto_comp_tfm(tfm));
}
static inline struct compress_tfm *crypto_comp_crt(struct crypto_comp *tfm) static inline struct compress_tfm *crypto_comp_crt(struct crypto_comp *tfm)
{ {
return &crypto_comp_tfm(tfm)->crt_compress; return &crypto_comp_tfm(tfm)->crt_compress;

View File

@ -1,15 +1,14 @@
#ifndef _NET_IPCOMP_H #ifndef _NET_IPCOMP_H
#define _NET_IPCOMP_H #define _NET_IPCOMP_H
#include <linux/crypto.h>
#include <linux/types.h> #include <linux/types.h>
#define IPCOMP_SCRATCH_SIZE 65400 #define IPCOMP_SCRATCH_SIZE 65400
struct crypto_tfm;
struct ipcomp_data { struct ipcomp_data {
u16 threshold; u16 threshold;
struct crypto_tfm **tfms; struct crypto_comp **tfms;
}; };
#endif #endif

View File

@ -32,7 +32,7 @@
struct ipcomp_tfms { struct ipcomp_tfms {
struct list_head list; struct list_head list;
struct crypto_tfm **tfms; struct crypto_comp **tfms;
int users; int users;
}; };
@ -46,7 +46,7 @@ static int ipcomp_decompress(struct xfrm_state *x, struct sk_buff *skb)
int err, plen, dlen; int err, plen, dlen;
struct ipcomp_data *ipcd = x->data; struct ipcomp_data *ipcd = x->data;
u8 *start, *scratch; u8 *start, *scratch;
struct crypto_tfm *tfm; struct crypto_comp *tfm;
int cpu; int cpu;
plen = skb->len; plen = skb->len;
@ -107,7 +107,7 @@ static int ipcomp_compress(struct xfrm_state *x, struct sk_buff *skb)
struct iphdr *iph = skb->nh.iph; struct iphdr *iph = skb->nh.iph;
struct ipcomp_data *ipcd = x->data; struct ipcomp_data *ipcd = x->data;
u8 *start, *scratch; u8 *start, *scratch;
struct crypto_tfm *tfm; struct crypto_comp *tfm;
int cpu; int cpu;
ihlen = iph->ihl * 4; ihlen = iph->ihl * 4;
@ -302,7 +302,7 @@ static void **ipcomp_alloc_scratches(void)
return scratches; return scratches;
} }
static void ipcomp_free_tfms(struct crypto_tfm **tfms) static void ipcomp_free_tfms(struct crypto_comp **tfms)
{ {
struct ipcomp_tfms *pos; struct ipcomp_tfms *pos;
int cpu; int cpu;
@ -324,28 +324,28 @@ static void ipcomp_free_tfms(struct crypto_tfm **tfms)
return; return;
for_each_possible_cpu(cpu) { for_each_possible_cpu(cpu) {
struct crypto_tfm *tfm = *per_cpu_ptr(tfms, cpu); struct crypto_comp *tfm = *per_cpu_ptr(tfms, cpu);
crypto_free_tfm(tfm); crypto_free_comp(tfm);
} }
free_percpu(tfms); free_percpu(tfms);
} }
static struct crypto_tfm **ipcomp_alloc_tfms(const char *alg_name) static struct crypto_comp **ipcomp_alloc_tfms(const char *alg_name)
{ {
struct ipcomp_tfms *pos; struct ipcomp_tfms *pos;
struct crypto_tfm **tfms; struct crypto_comp **tfms;
int cpu; int cpu;
/* This can be any valid CPU ID so we don't need locking. */ /* This can be any valid CPU ID so we don't need locking. */
cpu = raw_smp_processor_id(); cpu = raw_smp_processor_id();
list_for_each_entry(pos, &ipcomp_tfms_list, list) { list_for_each_entry(pos, &ipcomp_tfms_list, list) {
struct crypto_tfm *tfm; struct crypto_comp *tfm;
tfms = pos->tfms; tfms = pos->tfms;
tfm = *per_cpu_ptr(tfms, cpu); tfm = *per_cpu_ptr(tfms, cpu);
if (!strcmp(crypto_tfm_alg_name(tfm), alg_name)) { if (!strcmp(crypto_comp_name(tfm), alg_name)) {
pos->users++; pos->users++;
return tfms; return tfms;
} }
@ -359,12 +359,13 @@ static struct crypto_tfm **ipcomp_alloc_tfms(const char *alg_name)
INIT_LIST_HEAD(&pos->list); INIT_LIST_HEAD(&pos->list);
list_add(&pos->list, &ipcomp_tfms_list); list_add(&pos->list, &ipcomp_tfms_list);
pos->tfms = tfms = alloc_percpu(struct crypto_tfm *); pos->tfms = tfms = alloc_percpu(struct crypto_comp *);
if (!tfms) if (!tfms)
goto error; goto error;
for_each_possible_cpu(cpu) { for_each_possible_cpu(cpu) {
struct crypto_tfm *tfm = crypto_alloc_tfm(alg_name, 0); struct crypto_comp *tfm = crypto_alloc_comp(alg_name, 0,
CRYPTO_ALG_ASYNC);
if (!tfm) if (!tfm)
goto error; goto error;
*per_cpu_ptr(tfms, cpu) = tfm; *per_cpu_ptr(tfms, cpu) = tfm;

View File

@ -53,7 +53,7 @@
struct ipcomp6_tfms { struct ipcomp6_tfms {
struct list_head list; struct list_head list;
struct crypto_tfm **tfms; struct crypto_comp **tfms;
int users; int users;
}; };
@ -70,7 +70,7 @@ static int ipcomp6_input(struct xfrm_state *x, struct sk_buff *skb)
int plen, dlen; int plen, dlen;
struct ipcomp_data *ipcd = x->data; struct ipcomp_data *ipcd = x->data;
u8 *start, *scratch; u8 *start, *scratch;
struct crypto_tfm *tfm; struct crypto_comp *tfm;
int cpu; int cpu;
if (skb_linearize_cow(skb)) if (skb_linearize_cow(skb))
@ -129,7 +129,7 @@ static int ipcomp6_output(struct xfrm_state *x, struct sk_buff *skb)
struct ipcomp_data *ipcd = x->data; struct ipcomp_data *ipcd = x->data;
int plen, dlen; int plen, dlen;
u8 *start, *scratch; u8 *start, *scratch;
struct crypto_tfm *tfm; struct crypto_comp *tfm;
int cpu; int cpu;
hdr_len = skb->h.raw - skb->data; hdr_len = skb->h.raw - skb->data;
@ -301,7 +301,7 @@ static void **ipcomp6_alloc_scratches(void)
return scratches; return scratches;
} }
static void ipcomp6_free_tfms(struct crypto_tfm **tfms) static void ipcomp6_free_tfms(struct crypto_comp **tfms)
{ {
struct ipcomp6_tfms *pos; struct ipcomp6_tfms *pos;
int cpu; int cpu;
@ -323,28 +323,28 @@ static void ipcomp6_free_tfms(struct crypto_tfm **tfms)
return; return;
for_each_possible_cpu(cpu) { for_each_possible_cpu(cpu) {
struct crypto_tfm *tfm = *per_cpu_ptr(tfms, cpu); struct crypto_comp *tfm = *per_cpu_ptr(tfms, cpu);
crypto_free_tfm(tfm); crypto_free_comp(tfm);
} }
free_percpu(tfms); free_percpu(tfms);
} }
static struct crypto_tfm **ipcomp6_alloc_tfms(const char *alg_name) static struct crypto_comp **ipcomp6_alloc_tfms(const char *alg_name)
{ {
struct ipcomp6_tfms *pos; struct ipcomp6_tfms *pos;
struct crypto_tfm **tfms; struct crypto_comp **tfms;
int cpu; int cpu;
/* This can be any valid CPU ID so we don't need locking. */ /* This can be any valid CPU ID so we don't need locking. */
cpu = raw_smp_processor_id(); cpu = raw_smp_processor_id();
list_for_each_entry(pos, &ipcomp6_tfms_list, list) { list_for_each_entry(pos, &ipcomp6_tfms_list, list) {
struct crypto_tfm *tfm; struct crypto_comp *tfm;
tfms = pos->tfms; tfms = pos->tfms;
tfm = *per_cpu_ptr(tfms, cpu); tfm = *per_cpu_ptr(tfms, cpu);
if (!strcmp(crypto_tfm_alg_name(tfm), alg_name)) { if (!strcmp(crypto_comp_name(tfm), alg_name)) {
pos->users++; pos->users++;
return tfms; return tfms;
} }
@ -358,12 +358,13 @@ static struct crypto_tfm **ipcomp6_alloc_tfms(const char *alg_name)
INIT_LIST_HEAD(&pos->list); INIT_LIST_HEAD(&pos->list);
list_add(&pos->list, &ipcomp6_tfms_list); list_add(&pos->list, &ipcomp6_tfms_list);
pos->tfms = tfms = alloc_percpu(struct crypto_tfm *); pos->tfms = tfms = alloc_percpu(struct crypto_comp *);
if (!tfms) if (!tfms)
goto error; goto error;
for_each_possible_cpu(cpu) { for_each_possible_cpu(cpu) {
struct crypto_tfm *tfm = crypto_alloc_tfm(alg_name, 0); struct crypto_comp *tfm = crypto_alloc_comp(alg_name, 0,
CRYPTO_ALG_ASYNC);
if (!tfm) if (!tfm)
goto error; goto error;
*per_cpu_ptr(tfms, cpu) = tfm; *per_cpu_ptr(tfms, cpu) = tfm;

View File

@ -363,8 +363,8 @@ struct xfrm_algo_desc *xfrm_calg_get_byid(int alg_id)
EXPORT_SYMBOL_GPL(xfrm_calg_get_byid); EXPORT_SYMBOL_GPL(xfrm_calg_get_byid);
static struct xfrm_algo_desc *xfrm_get_byname(struct xfrm_algo_desc *list, static struct xfrm_algo_desc *xfrm_get_byname(struct xfrm_algo_desc *list,
int entries, char *name, int entries, u32 type, u32 mask,
int probe) char *name, int probe)
{ {
int i, status; int i, status;
@ -382,7 +382,7 @@ static struct xfrm_algo_desc *xfrm_get_byname(struct xfrm_algo_desc *list,
if (!probe) if (!probe)
break; break;
status = crypto_alg_available(name, 0); status = crypto_has_alg(name, type, mask | CRYPTO_ALG_ASYNC);
if (!status) if (!status)
break; break;
@ -394,19 +394,25 @@ static struct xfrm_algo_desc *xfrm_get_byname(struct xfrm_algo_desc *list,
struct xfrm_algo_desc *xfrm_aalg_get_byname(char *name, int probe) struct xfrm_algo_desc *xfrm_aalg_get_byname(char *name, int probe)
{ {
return xfrm_get_byname(aalg_list, aalg_entries(), name, probe); return xfrm_get_byname(aalg_list, aalg_entries(),
CRYPTO_ALG_TYPE_HASH, CRYPTO_ALG_TYPE_HASH_MASK,
name, probe);
} }
EXPORT_SYMBOL_GPL(xfrm_aalg_get_byname); EXPORT_SYMBOL_GPL(xfrm_aalg_get_byname);
struct xfrm_algo_desc *xfrm_ealg_get_byname(char *name, int probe) struct xfrm_algo_desc *xfrm_ealg_get_byname(char *name, int probe)
{ {
return xfrm_get_byname(ealg_list, ealg_entries(), name, probe); return xfrm_get_byname(ealg_list, ealg_entries(),
CRYPTO_ALG_TYPE_BLKCIPHER, CRYPTO_ALG_TYPE_MASK,
name, probe);
} }
EXPORT_SYMBOL_GPL(xfrm_ealg_get_byname); EXPORT_SYMBOL_GPL(xfrm_ealg_get_byname);
struct xfrm_algo_desc *xfrm_calg_get_byname(char *name, int probe) struct xfrm_algo_desc *xfrm_calg_get_byname(char *name, int probe)
{ {
return xfrm_get_byname(calg_list, calg_entries(), name, probe); return xfrm_get_byname(calg_list, calg_entries(),
CRYPTO_ALG_TYPE_COMPRESS, CRYPTO_ALG_TYPE_MASK,
name, probe);
} }
EXPORT_SYMBOL_GPL(xfrm_calg_get_byname); EXPORT_SYMBOL_GPL(xfrm_calg_get_byname);
@ -441,19 +447,22 @@ void xfrm_probe_algs(void)
BUG_ON(in_softirq()); BUG_ON(in_softirq());
for (i = 0; i < aalg_entries(); i++) { for (i = 0; i < aalg_entries(); i++) {
status = crypto_alg_available(aalg_list[i].name, 0); status = crypto_has_hash(aalg_list[i].name, 0,
CRYPTO_ALG_ASYNC);
if (aalg_list[i].available != status) if (aalg_list[i].available != status)
aalg_list[i].available = status; aalg_list[i].available = status;
} }
for (i = 0; i < ealg_entries(); i++) { for (i = 0; i < ealg_entries(); i++) {
status = crypto_alg_available(ealg_list[i].name, 0); status = crypto_has_blkcipher(ealg_list[i].name, 0,
CRYPTO_ALG_ASYNC);
if (ealg_list[i].available != status) if (ealg_list[i].available != status)
ealg_list[i].available = status; ealg_list[i].available = status;
} }
for (i = 0; i < calg_entries(); i++) { for (i = 0; i < calg_entries(); i++) {
status = crypto_alg_available(calg_list[i].name, 0); status = crypto_has_comp(calg_list[i].name, 0,
CRYPTO_ALG_ASYNC);
if (calg_list[i].available != status) if (calg_list[i].available != status)
calg_list[i].available = status; calg_list[i].available = status;
} }