Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 75966
b: refs/heads/master
c: 378f4f5
h: refs/heads/master
v: v3
  • Loading branch information
Herbert Xu committed Jan 10, 2008
1 parent f7dad30 commit 15a6d7d
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 17 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: 84c911523020a2e39b307a2da26ee1886b7214fe
refs/heads/master: 378f4f51f9fdd8df80ea875320e2bf1d7c6e6e77
25 changes: 23 additions & 2 deletions trunk/crypto/ablkcipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@
*
*/

#include <crypto/algapi.h>
#include <linux/errno.h>
#include <crypto/internal/skcipher.h>
#include <linux/err.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/seq_file.h>

#include "internal.h"

static int setkey_unaligned(struct crypto_ablkcipher *tfm, const u8 *key,
unsigned int keylen)
{
Expand Down Expand Up @@ -105,5 +107,24 @@ const struct crypto_type crypto_ablkcipher_type = {
};
EXPORT_SYMBOL_GPL(crypto_ablkcipher_type);

int crypto_grab_skcipher(struct crypto_skcipher_spawn *spawn, const char *name,
u32 type, u32 mask)
{
struct crypto_alg *alg;
int err;

type = crypto_skcipher_type(type);
mask = crypto_skcipher_mask(mask);

alg = crypto_alg_mod_lookup(name, type, mask);
if (IS_ERR(alg))
return PTR_ERR(alg);

err = crypto_init_spawn(&spawn->base, alg, spawn->base.inst, mask);
crypto_mod_put(alg);
return err;
}
EXPORT_SYMBOL_GPL(crypto_grab_skcipher);

MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Asynchronous block chaining cipher type");
22 changes: 18 additions & 4 deletions trunk/include/crypto/algapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ void crypto_drop_spawn(struct crypto_spawn *spawn);
struct crypto_tfm *crypto_spawn_tfm(struct crypto_spawn *spawn, u32 type,
u32 mask);

static inline void crypto_set_spawn(struct crypto_spawn *spawn,
struct crypto_instance *inst)
{
spawn->inst = inst;
}

struct crypto_attr_type *crypto_get_attr_type(struct rtattr **tb);
int crypto_check_attr_type(struct rtattr **tb, u32 type);
const char *crypto_attr_alg_name(struct rtattr *rta);
Expand Down Expand Up @@ -195,10 +201,9 @@ static inline struct crypto_instance *crypto_aead_alg_instance(
static inline struct crypto_ablkcipher *crypto_spawn_ablkcipher(
struct crypto_spawn *spawn)
{
u32 type = CRYPTO_ALG_TYPE_BLKCIPHER;
u32 mask = CRYPTO_ALG_TYPE_BLKCIPHER_MASK;

return __crypto_ablkcipher_cast(crypto_spawn_tfm(spawn, type, mask));
return __crypto_ablkcipher_cast(
crypto_spawn_tfm(spawn, crypto_skcipher_type(0),
crypto_skcipher_mask(0)));
}

static inline struct crypto_blkcipher *crypto_spawn_blkcipher(
Expand Down Expand Up @@ -308,5 +313,14 @@ static inline struct crypto_alg *crypto_get_attr_alg(struct rtattr **tb,
return crypto_attr_alg(tb[1], type, mask);
}

/*
* Returns CRYPTO_ALG_ASYNC if type/mask requires the use of sync algorithms.
* Otherwise returns zero.
*/
static inline int crypto_requires_sync(u32 type, u32 mask)
{
return (type ^ CRYPTO_ALG_ASYNC) & mask & CRYPTO_ALG_ASYNC;
}

#endif /* _CRYPTO_ALGAPI_H */

51 changes: 51 additions & 0 deletions trunk/include/crypto/internal/skcipher.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Symmetric key ciphers.
*
* Copyright (c) 2007 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
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
*/

#ifndef _CRYPTO_INTERNAL_SKCIPHER_H
#define _CRYPTO_INTERNAL_SKCIPHER_H

#include <crypto/algapi.h>

struct crypto_skcipher_spawn {
struct crypto_spawn base;
};

static inline void crypto_set_skcipher_spawn(
struct crypto_skcipher_spawn *spawn, struct crypto_instance *inst)
{
crypto_set_spawn(&spawn->base, inst);
}

int crypto_grab_skcipher(struct crypto_skcipher_spawn *spawn, const char *name,
u32 type, u32 mask);

static inline void crypto_drop_skcipher(struct crypto_skcipher_spawn *spawn)
{
crypto_drop_spawn(&spawn->base);
}

static inline struct crypto_alg *crypto_skcipher_spawn_alg(
struct crypto_skcipher_spawn *spawn)
{
return spawn->base.alg;
}

static inline struct crypto_ablkcipher *crypto_spawn_skcipher(
struct crypto_skcipher_spawn *spawn)
{
return __crypto_ablkcipher_cast(
crypto_spawn_tfm(&spawn->base, crypto_skcipher_type(0),
crypto_skcipher_mask(0)));
}

#endif /* _CRYPTO_INTERNAL_SKCIPHER_H */

26 changes: 16 additions & 10 deletions trunk/include/linux/crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -528,16 +528,26 @@ static inline struct crypto_ablkcipher *__crypto_ablkcipher_cast(
return (struct crypto_ablkcipher *)tfm;
}

static inline struct crypto_ablkcipher *crypto_alloc_ablkcipher(
const char *alg_name, u32 type, u32 mask)
static inline u32 crypto_skcipher_type(u32 type)
{
type &= ~CRYPTO_ALG_TYPE_MASK;
mask &= ~CRYPTO_ALG_TYPE_MASK;
type |= CRYPTO_ALG_TYPE_BLKCIPHER;
return type;
}

static inline u32 crypto_skcipher_mask(u32 mask)
{
mask &= ~CRYPTO_ALG_TYPE_MASK;
mask |= CRYPTO_ALG_TYPE_BLKCIPHER_MASK;
return mask;
}

static inline struct crypto_ablkcipher *crypto_alloc_ablkcipher(
const char *alg_name, u32 type, u32 mask)
{
return __crypto_ablkcipher_cast(
crypto_alloc_base(alg_name, type, mask));
crypto_alloc_base(alg_name, crypto_skcipher_type(type),
crypto_skcipher_mask(mask)));
}

static inline struct crypto_tfm *crypto_ablkcipher_tfm(
Expand All @@ -554,12 +564,8 @@ static inline void crypto_free_ablkcipher(struct crypto_ablkcipher *tfm)
static inline int crypto_has_ablkcipher(const char *alg_name, u32 type,
u32 mask)
{
type &= ~CRYPTO_ALG_TYPE_MASK;
mask &= ~CRYPTO_ALG_TYPE_MASK;
type |= CRYPTO_ALG_TYPE_BLKCIPHER;
mask |= CRYPTO_ALG_TYPE_BLKCIPHER_MASK;

return crypto_has_alg(alg_name, type, mask);
return crypto_has_alg(alg_name, crypto_skcipher_type(type),
crypto_skcipher_mask(mask));
}

static inline struct ablkcipher_tfm *crypto_ablkcipher_crt(
Expand Down

0 comments on commit 15a6d7d

Please sign in to comment.