Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 34229
b: refs/heads/master
c: 6d7d684
h: refs/heads/master
i:
  34227: f839a34
v: v3
  • Loading branch information
Herbert Xu committed Sep 21, 2006
1 parent 31d2d89 commit 3478b3f
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 12 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: 65b75c36f4e8422602826c75c803136e0da94122
refs/heads/master: 6d7d684d635ac5a345f075015f2c84169c111c6a
60 changes: 60 additions & 0 deletions trunk/crypto/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,66 @@ struct crypto_tfm *crypto_alloc_tfm(const char *name, u32 flags)
return tfm;
}

/*
* crypto_alloc_base - Locate algorithm and allocate transform
* @alg_name: Name of algorithm
* @type: Type of algorithm
* @mask: Mask for type comparison
*
* crypto_alloc_base() will first attempt to locate an already loaded
* algorithm. If that fails and the kernel supports dynamically loadable
* modules, it will then attempt to load a module of the same name or
* alias. If that fails it will send a query to any loaded crypto manager
* to construct an algorithm on the fly. A refcount is grabbed on the
* algorithm which is then associated with the new transform.
*
* The returned transform is of a non-determinate type. Most people
* should use one of the more specific allocation functions such as
* crypto_alloc_blkcipher.
*
* In case of error the return value is an error pointer.
*/
struct crypto_tfm *crypto_alloc_base(const char *alg_name, u32 type, u32 mask)
{
struct crypto_tfm *tfm;
int err;

for (;;) {
struct crypto_alg *alg;

alg = crypto_alg_mod_lookup(alg_name, type, mask);
err = PTR_ERR(alg);
tfm = ERR_PTR(err);
if (IS_ERR(alg))
goto err;

tfm = __crypto_alloc_tfm(alg, 0);
if (!IS_ERR(tfm))
break;

crypto_mod_put(alg);
err = PTR_ERR(tfm);

err:
if (err != -EAGAIN)
break;
if (signal_pending(current)) {
err = -EINTR;
break;
}
};

return tfm;
}
EXPORT_SYMBOL_GPL(crypto_alloc_base);

/*
* crypto_free_tfm - Free crypto transform
* @tfm: Transform to free
*
* crypto_free_tfm() frees up the transform and any associated resources,
* then drops the refcount on the associated algorithm.
*/
void crypto_free_tfm(struct crypto_tfm *tfm)
{
struct crypto_alg *alg;
Expand Down
14 changes: 3 additions & 11 deletions trunk/include/linux/crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ static inline int crypto_alg_available(const char *name, u32 flags)

/*
* Transforms: user-instantiated objects which encapsulate algorithms
* and core processing logic. Managed via crypto_alloc_tfm() and
* crypto_free_tfm(), as well as the various helpers below.
* and core processing logic. Managed via crypto_alloc_*() and
* crypto_free_*(), as well as the various helpers below.
*/

struct cipher_tfm {
Expand Down Expand Up @@ -278,16 +278,8 @@ struct crypto_attr_alg {
* Transform user interface.
*/

/*
* crypto_alloc_tfm() will first attempt to locate an already loaded algorithm.
* If that fails and the kernel supports dynamically loadable modules, it
* will then attempt to load a module of the same name or alias. A refcount
* is grabbed on the algorithm which is then associated with the new transform.
*
* crypto_free_tfm() frees up the transform and any associated resources,
* then drops the refcount on the associated algorithm.
*/
struct crypto_tfm *crypto_alloc_tfm(const char *alg_name, u32 tfm_flags);
struct crypto_tfm *crypto_alloc_base(const char *alg_name, u32 type, u32 mask);
void crypto_free_tfm(struct crypto_tfm *tfm);

/*
Expand Down

0 comments on commit 3478b3f

Please sign in to comment.