Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 4172
b: refs/heads/master
c: 4072518
h: refs/heads/master
v: v3
  • Loading branch information
Herbert Xu authored and David S. Miller committed Jul 6, 2005
1 parent d26f842 commit 08163f8
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 27 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: c774e93e2152d0be2612739418689e6e6400f4eb
refs/heads/master: 40725181b74be6b0e3bdc8c05bd1e0b9873ec5cc
38 changes: 18 additions & 20 deletions trunk/crypto/cipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@
#include "internal.h"
#include "scatterwalk.h"

struct cipher_desc {
struct crypto_tfm *tfm;
void (*crfn)(void *ctx, u8 *dst, const u8 *src);
unsigned int (*prfn)(const struct cipher_desc *desc, u8 *dst,
const u8 *src, unsigned int nbytes);
void *info;
};

static inline void xor_64(u8 *a, const u8 *b)
{
((u32 *)a)[0] ^= ((u32 *)b)[0];
Expand Down Expand Up @@ -224,10 +216,11 @@ static int ecb_encrypt(struct crypto_tfm *tfm,
struct scatterlist *src, unsigned int nbytes)
{
struct cipher_desc desc;
struct cipher_alg *cipher = &tfm->__crt_alg->cra_cipher;

desc.tfm = tfm;
desc.crfn = tfm->__crt_alg->cra_cipher.cia_encrypt;
desc.prfn = ecb_process;
desc.crfn = cipher->cia_encrypt;
desc.prfn = cipher->cia_encrypt_ecb ?: ecb_process;

return crypt(&desc, dst, src, nbytes);
}
Expand All @@ -238,10 +231,11 @@ static int ecb_decrypt(struct crypto_tfm *tfm,
unsigned int nbytes)
{
struct cipher_desc desc;
struct cipher_alg *cipher = &tfm->__crt_alg->cra_cipher;

desc.tfm = tfm;
desc.crfn = tfm->__crt_alg->cra_cipher.cia_decrypt;
desc.prfn = ecb_process;
desc.crfn = cipher->cia_decrypt;
desc.prfn = cipher->cia_decrypt_ecb ?: ecb_process;

return crypt(&desc, dst, src, nbytes);
}
Expand All @@ -252,10 +246,11 @@ static int cbc_encrypt(struct crypto_tfm *tfm,
unsigned int nbytes)
{
struct cipher_desc desc;
struct cipher_alg *cipher = &tfm->__crt_alg->cra_cipher;

desc.tfm = tfm;
desc.crfn = tfm->__crt_alg->cra_cipher.cia_encrypt;
desc.prfn = cbc_process_encrypt;
desc.crfn = cipher->cia_encrypt;
desc.prfn = cipher->cia_encrypt_cbc ?: cbc_process_encrypt;
desc.info = tfm->crt_cipher.cit_iv;

return crypt(&desc, dst, src, nbytes);
Expand All @@ -267,10 +262,11 @@ static int cbc_encrypt_iv(struct crypto_tfm *tfm,
unsigned int nbytes, u8 *iv)
{
struct cipher_desc desc;
struct cipher_alg *cipher = &tfm->__crt_alg->cra_cipher;

desc.tfm = tfm;
desc.crfn = tfm->__crt_alg->cra_cipher.cia_encrypt;
desc.prfn = cbc_process_encrypt;
desc.crfn = cipher->cia_encrypt;
desc.prfn = cipher->cia_encrypt_cbc ?: cbc_process_encrypt;
desc.info = iv;

return crypt(&desc, dst, src, nbytes);
Expand All @@ -282,10 +278,11 @@ static int cbc_decrypt(struct crypto_tfm *tfm,
unsigned int nbytes)
{
struct cipher_desc desc;
struct cipher_alg *cipher = &tfm->__crt_alg->cra_cipher;

desc.tfm = tfm;
desc.crfn = tfm->__crt_alg->cra_cipher.cia_decrypt;
desc.prfn = cbc_process_decrypt;
desc.crfn = cipher->cia_decrypt;
desc.prfn = cipher->cia_decrypt_cbc ?: cbc_process_decrypt;
desc.info = tfm->crt_cipher.cit_iv;

return crypt(&desc, dst, src, nbytes);
Expand All @@ -297,10 +294,11 @@ static int cbc_decrypt_iv(struct crypto_tfm *tfm,
unsigned int nbytes, u8 *iv)
{
struct cipher_desc desc;
struct cipher_alg *cipher = &tfm->__crt_alg->cra_cipher;

desc.tfm = tfm;
desc.crfn = tfm->__crt_alg->cra_cipher.cia_decrypt;
desc.prfn = cbc_process_decrypt;
desc.crfn = cipher->cia_decrypt;
desc.prfn = cipher->cia_decrypt_cbc ?: cbc_process_decrypt;
desc.info = iv;

return crypt(&desc, dst, src, nbytes);
Expand Down
5 changes: 0 additions & 5 deletions trunk/crypto/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ static inline void crypto_yield(struct crypto_tfm *tfm)
cond_resched();
}

static inline void *crypto_tfm_ctx(struct crypto_tfm *tfm)
{
return (void *)&tfm[1];
}

struct crypto_alg *crypto_alg_lookup(const char *name);

/* A far more intelligent version of this is planned. For now, just
Expand Down
28 changes: 27 additions & 1 deletion trunk/include/linux/crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@
#define CRYPTO_DIR_DECRYPT 0

struct scatterlist;
struct crypto_tfm;

struct cipher_desc {
struct crypto_tfm *tfm;
void (*crfn)(void *ctx, u8 *dst, const u8 *src);
unsigned int (*prfn)(const struct cipher_desc *desc, u8 *dst,
const u8 *src, unsigned int nbytes);
void *info;
};

/*
* Algorithms: modular crypto algorithm implementations, managed
Expand All @@ -73,6 +82,19 @@ struct cipher_alg {
unsigned int keylen, u32 *flags);
void (*cia_encrypt)(void *ctx, u8 *dst, const u8 *src);
void (*cia_decrypt)(void *ctx, u8 *dst, const u8 *src);

unsigned int (*cia_encrypt_ecb)(const struct cipher_desc *desc,
u8 *dst, const u8 *src,
unsigned int nbytes);
unsigned int (*cia_decrypt_ecb)(const struct cipher_desc *desc,
u8 *dst, const u8 *src,
unsigned int nbytes);
unsigned int (*cia_encrypt_cbc)(const struct cipher_desc *desc,
u8 *dst, const u8 *src,
unsigned int nbytes);
unsigned int (*cia_decrypt_cbc)(const struct cipher_desc *desc,
u8 *dst, const u8 *src,
unsigned int nbytes);
};

struct digest_alg {
Expand Down Expand Up @@ -136,7 +158,6 @@ static inline int crypto_alg_available(const char *name, u32 flags)
* and core processing logic. Managed via crypto_alloc_tfm() and
* crypto_free_tfm(), as well as the various helpers below.
*/
struct crypto_tfm;

struct cipher_tfm {
void *cit_iv;
Expand Down Expand Up @@ -266,6 +287,11 @@ static inline unsigned int crypto_tfm_alg_digestsize(struct crypto_tfm *tfm)
return tfm->__crt_alg->cra_digest.dia_digestsize;
}

static inline void *crypto_tfm_ctx(struct crypto_tfm *tfm)
{
return (void *)&tfm[1];
}

/*
* API wrappers.
*/
Expand Down

0 comments on commit 08163f8

Please sign in to comment.