Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 17423
b: refs/heads/master
c: 5cb1454
h: refs/heads/master
i:
  17421: 7d4c0d6
  17419: 7353e34
  17415: 1a18f9e
  17407: bd354ad
v: v3
  • Loading branch information
Herbert Xu authored and David S. Miller committed Jan 9, 2006
1 parent 340299f commit d6d87ae
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 10 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 06ace7a9bafeb9047352707eb79e8eaa0dfdf5f2
refs/heads/master: 5cb1454b862ab3040b78364d58330262fea1ddba
52 changes: 46 additions & 6 deletions trunk/crypto/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*
* Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
* Copyright (c) 2002 David S. Miller (davem@redhat.com)
* Copyright (c) 2005 Herbert Xu <herbert@gondor.apana.org.au>
*
* Portions derived from Cryptoapi, by Alexander Kjeldaas <astor@fast.no>
* and Nettle, by Niels Möller.
Expand All @@ -18,9 +19,11 @@
#include <linux/init.h>
#include <linux/crypto.h>
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/kmod.h>
#include <linux/rwsem.h>
#include <linux/slab.h>
#include <linux/string.h>
#include "internal.h"

LIST_HEAD(crypto_alg_list);
Expand All @@ -39,18 +42,31 @@ static inline void crypto_alg_put(struct crypto_alg *alg)
static struct crypto_alg *crypto_alg_lookup(const char *name)
{
struct crypto_alg *q, *alg = NULL;
int best = -1;

if (!name)
return NULL;

down_read(&crypto_alg_sem);

list_for_each_entry(q, &crypto_alg_list, cra_list) {
if (!(strcmp(q->cra_name, name))) {
if (crypto_alg_get(q))
alg = q;
int exact, fuzzy;

exact = !strcmp(q->cra_driver_name, name);
fuzzy = !strcmp(q->cra_name, name);
if (!exact && !(fuzzy && q->cra_priority > best))
continue;

if (unlikely(!crypto_alg_get(q)))
continue;

best = q->cra_priority;
if (alg)
crypto_alg_put(alg);
alg = q;

if (exact)
break;
}
}

up_read(&crypto_alg_sem);
Expand Down Expand Up @@ -207,9 +223,26 @@ void crypto_free_tfm(struct crypto_tfm *tfm)
kfree(tfm);
}

static inline int crypto_set_driver_name(struct crypto_alg *alg)
{
static const char suffix[] = "-generic";
char *driver_name = (char *)alg->cra_driver_name;
int len;

if (*driver_name)
return 0;

len = strlcpy(driver_name, alg->cra_name, CRYPTO_MAX_ALG_NAME);
if (len + sizeof(suffix) > CRYPTO_MAX_ALG_NAME)
return -ENAMETOOLONG;

memcpy(driver_name + len, suffix, sizeof(suffix));
return 0;
}

int crypto_register_alg(struct crypto_alg *alg)
{
int ret = 0;
int ret;
struct crypto_alg *q;

if (alg->cra_alignmask & (alg->cra_alignmask + 1))
Expand All @@ -220,11 +253,18 @@ int crypto_register_alg(struct crypto_alg *alg)

if (alg->cra_blocksize > PAGE_SIZE)
return -EINVAL;

if (alg->cra_priority < 0)
return -EINVAL;

ret = crypto_set_driver_name(alg);
if (unlikely(ret))
return ret;

down_write(&crypto_alg_sem);

list_for_each_entry(q, &crypto_alg_list, cra_list) {
if (!(strcmp(q->cra_name, alg->cra_name))) {
if (!strcmp(q->cra_driver_name, alg->cra_driver_name)) {
ret = -EEXIST;
goto out;
}
Expand Down
6 changes: 6 additions & 0 deletions trunk/crypto/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Cryptographic API.
*
* Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
* Copyright (c) 2005 Herbert Xu <herbert@gondor.apana.org.au>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
Expand All @@ -16,10 +17,15 @@
#include <linux/highmem.h>
#include <linux/interrupt.h>
#include <linux/init.h>
#include <linux/list.h>
#include <linux/kernel.h>
#include <linux/rwsem.h>
#include <linux/slab.h>
#include <asm/kmap_types.h>

extern struct list_head crypto_alg_list;
extern struct rw_semaphore crypto_alg_sem;

extern enum km_type crypto_km_types[];

static inline enum km_type crypto_kmap_type(int out)
Expand Down
6 changes: 3 additions & 3 deletions trunk/crypto/proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Procfs information.
*
* Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
* Copyright (c) 2005 Herbert Xu <herbert@gondor.apana.org.au>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
Expand All @@ -18,9 +19,6 @@
#include <linux/seq_file.h>
#include "internal.h"

extern struct list_head crypto_alg_list;
extern struct rw_semaphore crypto_alg_sem;

static void *c_start(struct seq_file *m, loff_t *pos)
{
struct list_head *v;
Expand Down Expand Up @@ -53,7 +51,9 @@ static int c_show(struct seq_file *m, void *p)
struct crypto_alg *alg = (struct crypto_alg *)p;

seq_printf(m, "name : %s\n", alg->cra_name);
seq_printf(m, "driver : %s\n", alg->cra_driver_name);
seq_printf(m, "module : %s\n", module_name(alg->cra_module));
seq_printf(m, "priority : %d\n", alg->cra_priority);

switch (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) {
case CRYPTO_ALG_TYPE_CIPHER:
Expand Down
5 changes: 5 additions & 0 deletions trunk/include/linux/crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*
* Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
* Copyright (c) 2002 David S. Miller (davem@redhat.com)
* Copyright (c) 2005 Herbert Xu <herbert@gondor.apana.org.au>
*
* Portions derived from Cryptoapi, by Alexander Kjeldaas <astor@fast.no>
* and Nettle, by Niels Möller.
Expand Down Expand Up @@ -126,7 +127,11 @@ struct crypto_alg {
unsigned int cra_blocksize;
unsigned int cra_ctxsize;
unsigned int cra_alignmask;

int cra_priority;

const char cra_name[CRYPTO_MAX_ALG_NAME];
const char cra_driver_name[CRYPTO_MAX_ALG_NAME];

union {
struct cipher_alg cipher;
Expand Down

0 comments on commit d6d87ae

Please sign in to comment.