Commit b56bc16a authored by James Morris's avatar James Morris Committed by David S. Miller

[CRYPTO]: Cleanups based upon suggestions by Jeff Garzik.

- Changed unsigned to unsigned int in algos.
- Consistent use of u32 for flags throughout api.
- Use of unsigned int rather than int for counting things which must
be positive, also replaced size_ts to keep code simpler and lessen
bloat on some archs.
- got rid of some unneeded returns.
- const correctness.
parent e3f4fb0b
...@@ -34,7 +34,7 @@ static inline void crypto_alg_put(struct crypto_alg *alg) ...@@ -34,7 +34,7 @@ static inline void crypto_alg_put(struct crypto_alg *alg)
__MOD_DEC_USE_COUNT(alg->cra_module); __MOD_DEC_USE_COUNT(alg->cra_module);
} }
struct crypto_alg *crypto_alg_lookup(char *name) struct crypto_alg *crypto_alg_lookup(const char *name)
{ {
struct crypto_alg *q, *alg = NULL; struct crypto_alg *q, *alg = NULL;
...@@ -68,7 +68,6 @@ static int crypto_init_flags(struct crypto_tfm *tfm, u32 flags) ...@@ -68,7 +68,6 @@ static int crypto_init_flags(struct crypto_tfm *tfm, u32 flags)
default: default:
BUG(); BUG();
} }
return -EINVAL; return -EINVAL;
...@@ -95,7 +94,7 @@ static void crypto_init_ops(struct crypto_tfm *tfm) ...@@ -95,7 +94,7 @@ static void crypto_init_ops(struct crypto_tfm *tfm)
} }
} }
struct crypto_tfm *crypto_alloc_tfm(char *name, u32 flags) struct crypto_tfm *crypto_alloc_tfm(const char *name, u32 flags)
{ {
struct crypto_tfm *tfm = NULL; struct crypto_tfm *tfm = NULL;
struct crypto_alg *alg; struct crypto_alg *alg;
...@@ -176,8 +175,8 @@ int crypto_register_alg(struct crypto_alg *alg) ...@@ -176,8 +175,8 @@ int crypto_register_alg(struct crypto_alg *alg)
} }
if (crypto_alg_blocksize_check(alg)) { if (crypto_alg_blocksize_check(alg)) {
printk(KERN_WARNING "%s: blocksize %Zd exceeds max. " printk(KERN_WARNING "%s: blocksize %u exceeds max. "
"size %d\n", __FUNCTION__, alg->cra_blocksize, "size %u\n", __FUNCTION__, alg->cra_blocksize,
CRYPTO_MAX_CIPHER_BLOCK_SIZE); CRYPTO_MAX_CIPHER_BLOCK_SIZE);
ret = -EINVAL; ret = -EINVAL;
} }
...@@ -242,16 +241,16 @@ static int c_show(struct seq_file *m, void *p) ...@@ -242,16 +241,16 @@ static int c_show(struct seq_file *m, void *p)
seq_printf(m, "name : %s\n", alg->cra_name); seq_printf(m, "name : %s\n", alg->cra_name);
seq_printf(m, "module : %s\n", alg->cra_module ? seq_printf(m, "module : %s\n", alg->cra_module ?
alg->cra_module->name : "[static]"); alg->cra_module->name : "[static]");
seq_printf(m, "blocksize : %Zd\n", alg->cra_blocksize); seq_printf(m, "blocksize : %u\n", alg->cra_blocksize);
switch (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) { switch (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) {
case CRYPTO_ALG_TYPE_CIPHER: case CRYPTO_ALG_TYPE_CIPHER:
seq_printf(m, "keysize : %Zd\n", alg->cra_cipher.cia_keysize); seq_printf(m, "keysize : %u\n", alg->cra_cipher.cia_keysize);
seq_printf(m, "ivsize : %Zd\n", alg->cra_cipher.cia_ivsize); seq_printf(m, "ivsize : %u\n", alg->cra_cipher.cia_ivsize);
break; break;
case CRYPTO_ALG_TYPE_DIGEST: case CRYPTO_ALG_TYPE_DIGEST:
seq_printf(m, "digestsize : %Zd\n", seq_printf(m, "digestsize : %u\n",
alg->cra_digest.dia_digestsize); alg->cra_digest.dia_digestsize);
break; break;
} }
......
...@@ -21,8 +21,7 @@ ...@@ -21,8 +21,7 @@
* A far more intelligent version of this is planned. For now, just * A far more intelligent version of this is planned. For now, just
* try an exact match on the name of the algorithm. * try an exact match on the name of the algorithm.
*/ */
void crypto_alg_autoload(char *name) void crypto_alg_autoload(const char *name)
{ {
request_module(name); request_module(name);
return;
} }
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
#include <asm/scatterlist.h> #include <asm/scatterlist.h>
#include "internal.h" #include "internal.h"
typedef void (cryptfn_t)(void *, u8 *, u8 *); typedef void (cryptfn_t)(void *, u8 *, const u8 *);
typedef void (procfn_t)(struct crypto_tfm *, u8 *, cryptfn_t, int enc); typedef void (procfn_t)(struct crypto_tfm *, u8 *, cryptfn_t, int enc);
static inline void xor_64(u8 *a, const u8 *b) static inline void xor_64(u8 *a, const u8 *b)
...@@ -29,10 +29,9 @@ static inline void xor_64(u8 *a, const u8 *b) ...@@ -29,10 +29,9 @@ static inline void xor_64(u8 *a, const u8 *b)
((u32 *)a)[1] ^= ((u32 *)b)[1]; ((u32 *)a)[1] ^= ((u32 *)b)[1];
} }
static inline size_t sglen(struct scatterlist *sg, size_t nsg) static inline unsigned int sglen(struct scatterlist *sg, unsigned int nsg)
{ {
int i; unsigned int i, n;
size_t n;
for (i = 0, n = 0; i < nsg; i++) for (i = 0, n = 0; i < nsg; i++)
n += sg[i].length; n += sg[i].length;
...@@ -44,21 +43,21 @@ static inline size_t sglen(struct scatterlist *sg, size_t nsg) ...@@ -44,21 +43,21 @@ static inline size_t sglen(struct scatterlist *sg, size_t nsg)
* Do not call this unless the total length of all of the fragments * Do not call this unless the total length of all of the fragments
* has been verified as multiple of the block size. * has been verified as multiple of the block size.
*/ */
static int copy_chunks(struct crypto_tfm *tfm, u8 *buf, static unsigned int copy_chunks(struct crypto_tfm *tfm, u8 *buf,
struct scatterlist *sg, int sgidx, struct scatterlist *sg, unsigned int sgidx,
int rlen, int *last, int in) unsigned int rlen, unsigned int *last, int in)
{ {
int i, copied, coff, j, aligned; unsigned int i, copied, coff, j, aligned;
size_t bsize = crypto_tfm_alg_blocksize(tfm); unsigned int bsize = crypto_tfm_alg_blocksize(tfm);
for (i = sgidx, j = copied = 0, aligned = 0 ; copied < bsize; i++) { for (i = sgidx, j = copied = 0, aligned = 0 ; copied < bsize; i++) {
int len = sg[i].length; unsigned int len = sg[i].length;
int clen; unsigned int clen;
char *p; char *p;
if (copied) { if (copied) {
coff = 0; coff = 0;
clen = min_t(int, len, bsize - copied); clen = min(len, bsize - copied);
if (len == bsize - copied) if (len == bsize - copied)
aligned = 1; /* last + right aligned */ aligned = 1; /* last + right aligned */
...@@ -83,16 +82,18 @@ static int copy_chunks(struct crypto_tfm *tfm, u8 *buf, ...@@ -83,16 +82,18 @@ static int copy_chunks(struct crypto_tfm *tfm, u8 *buf,
return i - sgidx - 2 + aligned; return i - sgidx - 2 + aligned;
} }
static inline int gather_chunks(struct crypto_tfm *tfm, u8 *buf, static inline unsigned int gather_chunks(struct crypto_tfm *tfm, u8 *buf,
struct scatterlist *sg, struct scatterlist *sg,
int sgidx, int rlen, int *last) unsigned int sgidx, unsigned int rlen,
unsigned int *last)
{ {
return copy_chunks(tfm, buf, sg, sgidx, rlen, last, 1); return copy_chunks(tfm, buf, sg, sgidx, rlen, last, 1);
} }
static inline int scatter_chunks(struct crypto_tfm *tfm, u8 *buf, static inline unsigned int scatter_chunks(struct crypto_tfm *tfm, u8 *buf,
struct scatterlist *sg, struct scatterlist *sg,
int sgidx, int rlen, int *last) unsigned int sgidx, unsigned int rlen,
unsigned int *last)
{ {
return copy_chunks(tfm, buf, sg, sgidx, rlen, last, 0); return copy_chunks(tfm, buf, sg, sgidx, rlen, last, 0);
} }
...@@ -111,10 +112,10 @@ static inline int scatter_chunks(struct crypto_tfm *tfm, u8 *buf, ...@@ -111,10 +112,10 @@ static inline int scatter_chunks(struct crypto_tfm *tfm, u8 *buf,
* and the block offset (boff). * and the block offset (boff).
*/ */
static int crypt(struct crypto_tfm *tfm, struct scatterlist *sg, static int crypt(struct crypto_tfm *tfm, struct scatterlist *sg,
size_t nsg, cryptfn_t crfn, procfn_t prfn, int enc) unsigned int nsg, cryptfn_t crfn, procfn_t prfn, int enc)
{ {
int i, coff; unsigned int i, coff;
size_t bsize = crypto_tfm_alg_blocksize(tfm); unsigned int bsize = crypto_tfm_alg_blocksize(tfm);
u8 tmp[CRYPTO_MAX_CIPHER_BLOCK_SIZE]; u8 tmp[CRYPTO_MAX_CIPHER_BLOCK_SIZE];
if (sglen(sg, nsg) % bsize) { if (sglen(sg, nsg) % bsize) {
...@@ -123,8 +124,8 @@ static int crypt(struct crypto_tfm *tfm, struct scatterlist *sg, ...@@ -123,8 +124,8 @@ static int crypt(struct crypto_tfm *tfm, struct scatterlist *sg,
} }
for (i = 0, coff = 0; i < nsg; i++) { for (i = 0, coff = 0; i < nsg; i++) {
int n = 0, boff = 0; unsigned int n = 0, boff = 0;
int len = sg[i].length - coff; unsigned int len = sg[i].length - coff;
char *p = crypto_kmap(sg[i].page) + sg[i].offset + coff; char *p = crypto_kmap(sg[i].page) + sg[i].offset + coff;
while (len) { while (len) {
...@@ -185,41 +186,42 @@ static void ecb_process(struct crypto_tfm *tfm, u8 *block, ...@@ -185,41 +186,42 @@ static void ecb_process(struct crypto_tfm *tfm, u8 *block,
fn(tfm->crt_ctx, block, block); fn(tfm->crt_ctx, block, block);
} }
static int setkey(struct crypto_tfm *tfm, const u8 *key, size_t keylen) static int setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen)
{ {
return tfm->__crt_alg->cra_cipher.cia_setkey(tfm->crt_ctx, key, return tfm->__crt_alg->cra_cipher.cia_setkey(tfm->crt_ctx, key,
keylen, &tfm->crt_flags); keylen, &tfm->crt_flags);
} }
static int ecb_encrypt(struct crypto_tfm *tfm, static int ecb_encrypt(struct crypto_tfm *tfm,
struct scatterlist *sg, size_t nsg) struct scatterlist *sg, unsigned int nsg)
{ {
return crypt(tfm, sg, nsg, return crypt(tfm, sg, nsg,
tfm->__crt_alg->cra_cipher.cia_encrypt, ecb_process, 1); tfm->__crt_alg->cra_cipher.cia_encrypt, ecb_process, 1);
} }
static int ecb_decrypt(struct crypto_tfm *tfm, static int ecb_decrypt(struct crypto_tfm *tfm,
struct scatterlist *sg, size_t nsg) struct scatterlist *sg, unsigned int nsg)
{ {
return crypt(tfm, sg, nsg, return crypt(tfm, sg, nsg,
tfm->__crt_alg->cra_cipher.cia_decrypt, ecb_process, 1); tfm->__crt_alg->cra_cipher.cia_decrypt, ecb_process, 1);
} }
static int cbc_encrypt(struct crypto_tfm *tfm, static int cbc_encrypt(struct crypto_tfm *tfm,
struct scatterlist *sg, size_t nsg) struct scatterlist *sg, unsigned int nsg)
{ {
return crypt(tfm, sg, nsg, return crypt(tfm, sg, nsg,
tfm->__crt_alg->cra_cipher.cia_encrypt, cbc_process, 1); tfm->__crt_alg->cra_cipher.cia_encrypt, cbc_process, 1);
} }
static int cbc_decrypt(struct crypto_tfm *tfm, static int cbc_decrypt(struct crypto_tfm *tfm,
struct scatterlist *sg, size_t nsg) struct scatterlist *sg, unsigned int nsg)
{ {
return crypt(tfm, sg, nsg, return crypt(tfm, sg, nsg,
tfm->__crt_alg->cra_cipher.cia_decrypt, cbc_process, 0); tfm->__crt_alg->cra_cipher.cia_decrypt, cbc_process, 0);
} }
static int nocrypt(struct crypto_tfm *tfm, struct scatterlist *sg, size_t nsg) static int nocrypt(struct crypto_tfm *tfm,
struct scatterlist *sg, unsigned int nsg)
{ {
return -ENOSYS; return -ENOSYS;
} }
......
...@@ -23,14 +23,10 @@ ...@@ -23,14 +23,10 @@
* lossless Quadruple ROT13 compression. * lossless Quadruple ROT13 compression.
*/ */
static void crypto_compress(struct crypto_tfm *tfm) static void crypto_compress(struct crypto_tfm *tfm)
{ { }
return;
}
static void crypto_decompress(struct crypto_tfm *tfm) static void crypto_decompress(struct crypto_tfm *tfm)
{ { }
return;
}
int crypto_init_compress_flags(struct crypto_tfm *tfm, u32 flags) int crypto_init_compress_flags(struct crypto_tfm *tfm, u32 flags)
{ {
......
...@@ -278,7 +278,7 @@ const static u8 parity[] = { ...@@ -278,7 +278,7 @@ const static u8 parity[] = {
}; };
static void des_small_fips_encrypt(u32 *expkey, u8 *dst, u8 *src) static void des_small_fips_encrypt(u32 *expkey, u8 *dst, const u8 *src)
{ {
u32 x, y, z; u32 x, y, z;
...@@ -648,10 +648,9 @@ static void des_small_fips_encrypt(u32 *expkey, u8 *dst, u8 *src) ...@@ -648,10 +648,9 @@ static void des_small_fips_encrypt(u32 *expkey, u8 *dst, u8 *src)
dst[6] = y; dst[6] = y;
y >>= 8; y >>= 8;
dst[7] = y; dst[7] = y;
return;
} }
static void des_small_fips_decrypt(u32 *expkey, u8 *dst, u8 *src) static void des_small_fips_decrypt(u32 *expkey, u8 *dst, const u8 *src)
{ {
u32 x, y, z; u32 x, y, z;
...@@ -1021,14 +1020,13 @@ static void des_small_fips_decrypt(u32 *expkey, u8 *dst, u8 *src) ...@@ -1021,14 +1020,13 @@ static void des_small_fips_decrypt(u32 *expkey, u8 *dst, u8 *src)
dst[6] = y; dst[6] = y;
y >>= 8; y >>= 8;
dst[7] = y; dst[7] = y;
return;
} }
/* /*
* RFC2451: Weak key checks SHOULD be performed. * RFC2451: Weak key checks SHOULD be performed.
*/ */
static int setkey(u32 *expkey, const u8 *key, size_t keylen, int *flags) static int setkey(u32 *expkey, const u8 *key, unsigned int keylen, u32 *flags)
{ {
const u8 *k; const u8 *k;
u8 *b0, *b1; u8 *b0, *b1;
...@@ -1177,17 +1175,17 @@ static int setkey(u32 *expkey, const u8 *key, size_t keylen, int *flags) ...@@ -1177,17 +1175,17 @@ static int setkey(u32 *expkey, const u8 *key, size_t keylen, int *flags)
return 0; return 0;
} }
static int des_setkey(void *ctx, const u8 *key, size_t keylen, int *flags) static int des_setkey(void *ctx, const u8 *key, unsigned int keylen, u32 *flags)
{ {
return setkey(((struct des_ctx *)ctx)->expkey, key, keylen, flags); return setkey(((struct des_ctx *)ctx)->expkey, key, keylen, flags);
} }
static void des_encrypt(void *ctx, u8 *dst, u8 *src) static void des_encrypt(void *ctx, u8 *dst, const u8 *src)
{ {
des_small_fips_encrypt(((struct des_ctx *)ctx)->expkey, dst, src); des_small_fips_encrypt(((struct des_ctx *)ctx)->expkey, dst, src);
} }
static void des_decrypt(void *ctx, u8 *dst, u8 *src) static void des_decrypt(void *ctx, u8 *dst, const u8 *src)
{ {
des_small_fips_decrypt(((struct des_ctx *)ctx)->expkey, dst, src); des_small_fips_decrypt(((struct des_ctx *)ctx)->expkey, dst, src);
} }
...@@ -1205,9 +1203,10 @@ static void des_decrypt(void *ctx, u8 *dst, u8 *src) ...@@ -1205,9 +1203,10 @@ static void des_decrypt(void *ctx, u8 *dst, u8 *src)
* property. * property.
* *
*/ */
static int des3_ede_setkey(void *ctx, const u8 *key, size_t keylen, int *flags) static int des3_ede_setkey(void *ctx, const u8 *key,
unsigned int keylen, u32 *flags)
{ {
int i, off; unsigned int i, off;
struct des3_ede_ctx *dctx = ctx; struct des3_ede_ctx *dctx = ctx;
if (keylen != DES3_EDE_KEY_SIZE) { if (keylen != DES3_EDE_KEY_SIZE) {
...@@ -1232,26 +1231,22 @@ static int des3_ede_setkey(void *ctx, const u8 *key, size_t keylen, int *flags) ...@@ -1232,26 +1231,22 @@ static int des3_ede_setkey(void *ctx, const u8 *key, size_t keylen, int *flags)
return 0; return 0;
} }
static void des3_ede_encrypt(void *ctx, u8 *dst, u8 *src) static void des3_ede_encrypt(void *ctx, u8 *dst, const u8 *src)
{ {
struct des3_ede_ctx *dctx = ctx; struct des3_ede_ctx *dctx = ctx;
des_small_fips_encrypt(dctx->expkey, dst, src); des_small_fips_encrypt(dctx->expkey, dst, src);
des_small_fips_decrypt(&dctx->expkey[DES_EXPKEY_WORDS], dst, dst); des_small_fips_decrypt(&dctx->expkey[DES_EXPKEY_WORDS], dst, dst);
des_small_fips_encrypt(&dctx->expkey[DES_EXPKEY_WORDS * 2], dst, dst); des_small_fips_encrypt(&dctx->expkey[DES_EXPKEY_WORDS * 2], dst, dst);
return;
} }
static void des3_ede_decrypt(void *ctx, u8 *dst, u8 *src) static void des3_ede_decrypt(void *ctx, u8 *dst, const u8 *src)
{ {
struct des3_ede_ctx *dctx = ctx; struct des3_ede_ctx *dctx = ctx;
des_small_fips_decrypt(&dctx->expkey[DES_EXPKEY_WORDS * 2], dst, src); des_small_fips_decrypt(&dctx->expkey[DES_EXPKEY_WORDS * 2], dst, src);
des_small_fips_encrypt(&dctx->expkey[DES_EXPKEY_WORDS], dst, dst); des_small_fips_encrypt(&dctx->expkey[DES_EXPKEY_WORDS], dst, dst);
des_small_fips_decrypt(dctx->expkey, dst, dst); des_small_fips_decrypt(dctx->expkey, dst, dst);
return;
} }
static struct crypto_alg des_alg = { static struct crypto_alg des_alg = {
......
...@@ -23,12 +23,12 @@ ...@@ -23,12 +23,12 @@
static void init(struct crypto_tfm *tfm) static void init(struct crypto_tfm *tfm)
{ {
tfm->__crt_alg->cra_digest.dia_init(tfm->crt_ctx); tfm->__crt_alg->cra_digest.dia_init(tfm->crt_ctx);
return;
} }
static void update(struct crypto_tfm *tfm, struct scatterlist *sg, size_t nsg) static void update(struct crypto_tfm *tfm,
struct scatterlist *sg, unsigned int nsg)
{ {
int i; unsigned int i;
for (i = 0; i < nsg; i++) { for (i = 0; i < nsg; i++) {
char *p = crypto_kmap(sg[i].page) + sg[i].offset; char *p = crypto_kmap(sg[i].page) + sg[i].offset;
...@@ -37,19 +37,17 @@ static void update(struct crypto_tfm *tfm, struct scatterlist *sg, size_t nsg) ...@@ -37,19 +37,17 @@ static void update(struct crypto_tfm *tfm, struct scatterlist *sg, size_t nsg)
crypto_kunmap(p); crypto_kunmap(p);
crypto_yield(tfm); crypto_yield(tfm);
} }
return;
} }
static void final(struct crypto_tfm *tfm, u8 *out) static void final(struct crypto_tfm *tfm, u8 *out)
{ {
tfm->__crt_alg->cra_digest.dia_final(tfm->crt_ctx, out); tfm->__crt_alg->cra_digest.dia_final(tfm->crt_ctx, out);
return;
} }
static void digest(struct crypto_tfm *tfm, static void digest(struct crypto_tfm *tfm,
struct scatterlist *sg, size_t nsg, u8 *out) struct scatterlist *sg, unsigned int nsg, u8 *out)
{ {
int i; unsigned int i;
tfm->crt_digest.dit_init(tfm); tfm->crt_digest.dit_init(tfm);
...@@ -61,13 +59,12 @@ static void digest(struct crypto_tfm *tfm, ...@@ -61,13 +59,12 @@ static void digest(struct crypto_tfm *tfm,
crypto_yield(tfm); crypto_yield(tfm);
} }
crypto_digest_final(tfm, out); crypto_digest_final(tfm, out);
return;
} }
static void hmac(struct crypto_tfm *tfm, u8 *key, size_t keylen, static void hmac(struct crypto_tfm *tfm, u8 *key, unsigned int keylen,
struct scatterlist *sg, size_t nsg, u8 *out) struct scatterlist *sg, unsigned int nsg, u8 *out)
{ {
int i; unsigned int i;
struct scatterlist tmp; struct scatterlist tmp;
char ipad[crypto_tfm_alg_blocksize(tfm) + 1]; char ipad[crypto_tfm_alg_blocksize(tfm) + 1];
char opad[crypto_tfm_alg_blocksize(tfm) + 1]; char opad[crypto_tfm_alg_blocksize(tfm) + 1];
...@@ -112,7 +109,6 @@ static void hmac(struct crypto_tfm *tfm, u8 *key, size_t keylen, ...@@ -112,7 +109,6 @@ static void hmac(struct crypto_tfm *tfm, u8 *key, size_t keylen,
crypto_digest_update(tfm, &tmp, 1); crypto_digest_update(tfm, &tmp, 1);
crypto_digest_final(tfm, out); crypto_digest_final(tfm, out);
return;
} }
int crypto_init_digest_flags(struct crypto_tfm *tfm, u32 flags) int crypto_init_digest_flags(struct crypto_tfm *tfm, u32 flags)
......
...@@ -41,7 +41,7 @@ static inline int crypto_cipher_flags(u32 flags) ...@@ -41,7 +41,7 @@ static inline int crypto_cipher_flags(u32 flags)
} }
#ifdef CONFIG_KMOD #ifdef CONFIG_KMOD
void crypto_alg_autoload(char *name); void crypto_alg_autoload(const char *name);
#endif #endif
int crypto_init_digest_flags(struct crypto_tfm *tfm, u32 flags); int crypto_init_digest_flags(struct crypto_tfm *tfm, u32 flags);
......
...@@ -37,7 +37,7 @@ struct md4_ctx { ...@@ -37,7 +37,7 @@ struct md4_ctx {
u64 byte_count; u64 byte_count;
}; };
static u32 lshift(u32 x, int s) static u32 lshift(u32 x, unsigned int s)
{ {
x &= 0xFFFFFFFF; x &= 0xFFFFFFFF;
return ((x << s) & 0xFFFFFFFF) | (x >> (32 - s)); return ((x << s) & 0xFFFFFFFF) | (x >> (32 - s));
...@@ -63,7 +63,7 @@ static inline u32 H(u32 x, u32 y, u32 z) ...@@ -63,7 +63,7 @@ static inline u32 H(u32 x, u32 y, u32 z)
#define ROUND3(a,b,c,d,k,s) (a = lshift(a + H(b,c,d) + k + (u32)0x6ED9EBA1,s)) #define ROUND3(a,b,c,d,k,s) (a = lshift(a + H(b,c,d) + k + (u32)0x6ED9EBA1,s))
/* XXX: this stuff can be optimized */ /* XXX: this stuff can be optimized */
static inline void le32_to_cpu_array(u32 *buf, unsigned words) static inline void le32_to_cpu_array(u32 *buf, unsigned int words)
{ {
while (words--) { while (words--) {
__le32_to_cpus(buf); __le32_to_cpus(buf);
...@@ -71,7 +71,7 @@ static inline void le32_to_cpu_array(u32 *buf, unsigned words) ...@@ -71,7 +71,7 @@ static inline void le32_to_cpu_array(u32 *buf, unsigned words)
} }
} }
static inline void cpu_to_le32_array(u32 *buf, unsigned words) static inline void cpu_to_le32_array(u32 *buf, unsigned int words)
{ {
while (words--) { while (words--) {
__cpu_to_le32s(buf); __cpu_to_le32s(buf);
...@@ -162,7 +162,7 @@ static void md4_init(void *ctx) ...@@ -162,7 +162,7 @@ static void md4_init(void *ctx)
mctx->byte_count = 0; mctx->byte_count = 0;
} }
static void md4_update(void *ctx, const u8 *data, size_t len) static void md4_update(void *ctx, const u8 *data, unsigned int len)
{ {
struct md4_ctx *mctx = ctx; struct md4_ctx *mctx = ctx;
const u32 avail = sizeof(mctx->block) - (mctx->byte_count & 0x3f); const u32 avail = sizeof(mctx->block) - (mctx->byte_count & 0x3f);
...@@ -195,7 +195,7 @@ static void md4_update(void *ctx, const u8 *data, size_t len) ...@@ -195,7 +195,7 @@ static void md4_update(void *ctx, const u8 *data, size_t len)
static void md4_final(void *ctx, u8 *out) static void md4_final(void *ctx, u8 *out)
{ {
struct md4_ctx *mctx = ctx; struct md4_ctx *mctx = ctx;
const int offset = mctx->byte_count & 0x3f; const unsigned int offset = mctx->byte_count & 0x3f;
char *p = (char *)mctx->block + offset; char *p = (char *)mctx->block + offset;
int padding = 56 - (offset + 1); int padding = 56 - (offset + 1);
......
...@@ -124,7 +124,7 @@ static inline void md5_transform(u32 *hash, u32 const *in) ...@@ -124,7 +124,7 @@ static inline void md5_transform(u32 *hash, u32 const *in)
} }
/* XXX: this stuff can be optimized */ /* XXX: this stuff can be optimized */
static inline void le32_to_cpu_array(u32 *buf, unsigned words) static inline void le32_to_cpu_array(u32 *buf, unsigned int words)
{ {
while (words--) { while (words--) {
__le32_to_cpus(buf); __le32_to_cpus(buf);
...@@ -132,7 +132,7 @@ static inline void le32_to_cpu_array(u32 *buf, unsigned words) ...@@ -132,7 +132,7 @@ static inline void le32_to_cpu_array(u32 *buf, unsigned words)
} }
} }
static inline void cpu_to_le32_array(u32 *buf, unsigned words) static inline void cpu_to_le32_array(u32 *buf, unsigned int words)
{ {
while (words--) { while (words--) {
__cpu_to_le32s(buf); __cpu_to_le32s(buf);
...@@ -157,7 +157,7 @@ static void md5_init(void *ctx) ...@@ -157,7 +157,7 @@ static void md5_init(void *ctx)
mctx->byte_count = 0; mctx->byte_count = 0;
} }
static void md5_update(void *ctx, const u8 *data, size_t len) static void md5_update(void *ctx, const u8 *data, unsigned int len)
{ {
struct md5_ctx *mctx = ctx; struct md5_ctx *mctx = ctx;
const u32 avail = sizeof(mctx->block) - (mctx->byte_count & 0x3f); const u32 avail = sizeof(mctx->block) - (mctx->byte_count & 0x3f);
...@@ -190,7 +190,7 @@ static void md5_update(void *ctx, const u8 *data, size_t len) ...@@ -190,7 +190,7 @@ static void md5_update(void *ctx, const u8 *data, size_t len)
static void md5_final(void *ctx, u8 *out) static void md5_final(void *ctx, u8 *out)
{ {
struct md5_ctx *mctx = ctx; struct md5_ctx *mctx = ctx;
const int offset = mctx->byte_count & 0x3f; const unsigned int offset = mctx->byte_count & 0x3f;
char *p = (char *)mctx->block + offset; char *p = (char *)mctx->block + offset;
int padding = 56 - (offset + 1); int padding = 56 - (offset + 1);
......
...@@ -116,10 +116,10 @@ static void sha1_init(void *ctx) ...@@ -116,10 +116,10 @@ static void sha1_init(void *ctx)
*sctx = initstate; *sctx = initstate;
} }
static void sha1_update(void *ctx, const u8 *data, size_t len) static void sha1_update(void *ctx, const u8 *data, unsigned int len)
{ {
struct sha1_ctx *sctx = ctx; struct sha1_ctx *sctx = ctx;
unsigned i, j; unsigned int i, j;
j = (sctx->count >> 3) & 0x3f; j = (sctx->count >> 3) & 0x3f;
sctx->count += len << 3; sctx->count += len << 3;
......
...@@ -47,7 +47,7 @@ static char *xbuf; ...@@ -47,7 +47,7 @@ static char *xbuf;
static char *tvmem; static char *tvmem;
static void static void
hexdump(unsigned char *buf, size_t len) hexdump(unsigned char *buf, unsigned int len)
{ {
while (len--) while (len--)
printk("%02x", *buf++); printk("%02x", *buf++);
...@@ -59,19 +59,19 @@ static void ...@@ -59,19 +59,19 @@ static void
test_md5(void) test_md5(void)
{ {
char *p; char *p;
int i; unsigned int i;
struct scatterlist sg[2]; struct scatterlist sg[2];
char result[128]; char result[128];
struct crypto_tfm *tfm; struct crypto_tfm *tfm;
struct md5_testvec *md5_tv; struct md5_testvec *md5_tv;
struct hmac_md5_testvec *hmac_md5_tv; struct hmac_md5_testvec *hmac_md5_tv;
size_t tsize; unsigned int tsize;
printk("\ntesting md5\n"); printk("\ntesting md5\n");
tsize = sizeof (md5_tv_template); tsize = sizeof (md5_tv_template);
if (tsize > TVMEMSIZE) { if (tsize > TVMEMSIZE) {
printk("template (%Zd) too big for tvmem (%d)\n", tsize, printk("template (%u) too big for tvmem (%u)\n", tsize,
TVMEMSIZE); TVMEMSIZE);
return; return;
} }
...@@ -86,7 +86,7 @@ test_md5(void) ...@@ -86,7 +86,7 @@ test_md5(void)
} }
for (i = 0; i < MD5_TEST_VECTORS; i++) { for (i = 0; i < MD5_TEST_VECTORS; i++) {
printk("test %d:\n", i + 1); printk("test %u:\n", i + 1);
memset(result, 0, sizeof (result)); memset(result, 0, sizeof (result));
p = md5_tv[i].plaintext; p = md5_tv[i].plaintext;
...@@ -134,7 +134,7 @@ test_md5(void) ...@@ -134,7 +134,7 @@ test_md5(void)
tsize = sizeof (hmac_md5_tv_template); tsize = sizeof (hmac_md5_tv_template);
if (tsize > TVMEMSIZE) { if (tsize > TVMEMSIZE) {
printk("template (%Zd) too big for tvmem (%d)\n", tsize, printk("template (%u) too big for tvmem (%u)\n", tsize,
TVMEMSIZE); TVMEMSIZE);
return; return;
} }
...@@ -143,7 +143,7 @@ test_md5(void) ...@@ -143,7 +143,7 @@ test_md5(void)
hmac_md5_tv = (void *) tvmem; hmac_md5_tv = (void *) tvmem;
for (i = 0; i < HMAC_MD5_TEST_VECTORS; i++) { for (i = 0; i < HMAC_MD5_TEST_VECTORS; i++) {
printk("test %d:\n", i + 1); printk("test %u:\n", i + 1);
memset(result, 0, sizeof (result)); memset(result, 0, sizeof (result));
p = hmac_md5_tv[i].plaintext; p = hmac_md5_tv[i].plaintext;
...@@ -194,18 +194,18 @@ static void ...@@ -194,18 +194,18 @@ static void
test_md4(void) test_md4(void)
{ {
char *p; char *p;
int i; unsigned int i;
struct scatterlist sg[1]; struct scatterlist sg[1];
char result[128]; char result[128];
struct crypto_tfm *tfm; struct crypto_tfm *tfm;
struct md4_testvec *md4_tv; struct md4_testvec *md4_tv;
size_t tsize; unsigned int tsize;
printk("\ntesting md4\n"); printk("\ntesting md4\n");
tsize = sizeof (md4_tv_template); tsize = sizeof (md4_tv_template);
if (tsize > TVMEMSIZE) { if (tsize > TVMEMSIZE) {
printk("template (%Zd) too big for tvmem (%d)\n", tsize, printk("template (%u) too big for tvmem (%u)\n", tsize,
TVMEMSIZE); TVMEMSIZE);
return; return;
} }
...@@ -220,7 +220,7 @@ test_md4(void) ...@@ -220,7 +220,7 @@ test_md4(void)
} }
for (i = 0; i < MD4_TEST_VECTORS; i++) { for (i = 0; i < MD4_TEST_VECTORS; i++) {
printk("test %d:\n", i + 1); printk("test %u:\n", i + 1);
memset(result, 0, sizeof (result)); memset(result, 0, sizeof (result));
p = md4_tv[i].plaintext; p = md4_tv[i].plaintext;
...@@ -244,19 +244,19 @@ static void ...@@ -244,19 +244,19 @@ static void
test_sha1(void) test_sha1(void)
{ {
char *p; char *p;
int i; unsigned int i;
struct crypto_tfm *tfm; struct crypto_tfm *tfm;
struct sha1_testvec *sha1_tv; struct sha1_testvec *sha1_tv;
struct hmac_sha1_testvec *hmac_sha1_tv; struct hmac_sha1_testvec *hmac_sha1_tv;
struct scatterlist sg[2]; struct scatterlist sg[2];
size_t tsize; unsigned int tsize;
char result[SHA1_DIGEST_SIZE]; char result[SHA1_DIGEST_SIZE];
printk("\ntesting sha1\n"); printk("\ntesting sha1\n");
tsize = sizeof (sha1_tv_template); tsize = sizeof (sha1_tv_template);
if (tsize > TVMEMSIZE) { if (tsize > TVMEMSIZE) {
printk("template (%Zd) too big for tvmem (%d)\n", tsize, printk("template (%u) too big for tvmem (%u)\n", tsize,
TVMEMSIZE); TVMEMSIZE);
return; return;
} }
...@@ -271,7 +271,7 @@ test_sha1(void) ...@@ -271,7 +271,7 @@ test_sha1(void)
} }
for (i = 0; i < SHA1_TEST_VECTORS; i++) { for (i = 0; i < SHA1_TEST_VECTORS; i++) {
printk("test %d:\n", i + 1); printk("test %u:\n", i + 1);
memset(result, 0, sizeof (result)); memset(result, 0, sizeof (result));
p = sha1_tv[i].plaintext; p = sha1_tv[i].plaintext;
...@@ -318,7 +318,7 @@ test_sha1(void) ...@@ -318,7 +318,7 @@ test_sha1(void)
tsize = sizeof (hmac_sha1_tv_template); tsize = sizeof (hmac_sha1_tv_template);
if (tsize > TVMEMSIZE) { if (tsize > TVMEMSIZE) {
printk("template (%Zd) too big for tvmem (%d)\n", tsize, printk("template (%u) too big for tvmem (%u)\n", tsize,
TVMEMSIZE); TVMEMSIZE);
return; return;
} }
...@@ -327,7 +327,7 @@ test_sha1(void) ...@@ -327,7 +327,7 @@ test_sha1(void)
hmac_sha1_tv = (void *) tvmem; hmac_sha1_tv = (void *) tvmem;
for (i = 0; i < HMAC_SHA1_TEST_VECTORS; i++) { for (i = 0; i < HMAC_SHA1_TEST_VECTORS; i++) {
printk("test %d:\n", i + 1); printk("test %u:\n", i + 1);
memset(result, 0, sizeof (result)); memset(result, 0, sizeof (result));
p = hmac_sha1_tv[i].plaintext; p = hmac_sha1_tv[i].plaintext;
...@@ -377,8 +377,8 @@ test_sha1(void) ...@@ -377,8 +377,8 @@ test_sha1(void)
void void
test_des(void) test_des(void)
{ {
int ret, i, len; unsigned int ret, i, len;
size_t tsize; unsigned int tsize;
char *p, *q; char *p, *q;
struct crypto_tfm *tfm; struct crypto_tfm *tfm;
char *key; char *key;
...@@ -390,7 +390,7 @@ test_des(void) ...@@ -390,7 +390,7 @@ test_des(void)
tsize = sizeof (des_enc_tv_template); tsize = sizeof (des_enc_tv_template);
if (tsize > TVMEMSIZE) { if (tsize > TVMEMSIZE) {
printk("template (%Zd) too big for tvmem (%d)\n", tsize, printk("template (%u) too big for tvmem (%u)\n", tsize,
TVMEMSIZE); TVMEMSIZE);
return; return;
} }
...@@ -405,7 +405,7 @@ test_des(void) ...@@ -405,7 +405,7 @@ test_des(void)
} }
for (i = 0; i < DES_ENC_TEST_VECTORS; i++) { for (i = 0; i < DES_ENC_TEST_VECTORS; i++) {
printk("test %d:\n", i + 1); printk("test %u:\n", i + 1);
key = des_tv[i].key; key = des_tv[i].key;
tfm->crt_flags |= CRYPTO_TFM_REQ_WEAK_KEY; tfm->crt_flags |= CRYPTO_TFM_REQ_WEAK_KEY;
...@@ -815,7 +815,7 @@ test_des(void) ...@@ -815,7 +815,7 @@ test_des(void)
tsize = sizeof (des_dec_tv_template); tsize = sizeof (des_dec_tv_template);
if (tsize > TVMEMSIZE) { if (tsize > TVMEMSIZE) {
printk("template (%Zd) too big for tvmem (%d)\n", tsize, printk("template (%u) too big for tvmem (%u)\n", tsize,
TVMEMSIZE); TVMEMSIZE);
return; return;
} }
...@@ -823,7 +823,7 @@ test_des(void) ...@@ -823,7 +823,7 @@ test_des(void)
des_tv = (void *) tvmem; des_tv = (void *) tvmem;
for (i = 0; i < DES_DEC_TEST_VECTORS; i++) { for (i = 0; i < DES_DEC_TEST_VECTORS; i++) {
printk("test %d:\n", i + 1); printk("test %u:\n", i + 1);
key = des_tv[i].key; key = des_tv[i].key;
...@@ -975,7 +975,7 @@ test_des(void) ...@@ -975,7 +975,7 @@ test_des(void)
tsize = sizeof (des_cbc_enc_tv_template); tsize = sizeof (des_cbc_enc_tv_template);
if (tsize > TVMEMSIZE) { if (tsize > TVMEMSIZE) {
printk("template (%Zd) too big for tvmem (%d)\n", tsize, printk("template (%u) too big for tvmem (%u)\n", tsize,
TVMEMSIZE); TVMEMSIZE);
return; return;
} }
...@@ -991,7 +991,7 @@ test_des(void) ...@@ -991,7 +991,7 @@ test_des(void)
} }
for (i = 0; i < DES_CBC_ENC_TEST_VECTORS; i++) { for (i = 0; i < DES_CBC_ENC_TEST_VECTORS; i++) {
printk("test %d:\n", i + 1); printk("test %u:\n", i + 1);
key = des_tv[i].key; key = des_tv[i].key;
...@@ -1088,7 +1088,7 @@ test_des(void) ...@@ -1088,7 +1088,7 @@ test_des(void)
tsize = sizeof (des_cbc_dec_tv_template); tsize = sizeof (des_cbc_dec_tv_template);
if (tsize > TVMEMSIZE) { if (tsize > TVMEMSIZE) {
printk("template (%Zd) too big for tvmem (%d)\n", tsize, printk("template (%u) too big for tvmem (%u)\n", tsize,
TVMEMSIZE); TVMEMSIZE);
return; return;
} }
...@@ -1098,7 +1098,7 @@ test_des(void) ...@@ -1098,7 +1098,7 @@ test_des(void)
printk("\ntesting des cbc decryption\n"); printk("\ntesting des cbc decryption\n");
for (i = 0; i < DES_CBC_DEC_TEST_VECTORS; i++) { for (i = 0; i < DES_CBC_DEC_TEST_VECTORS; i++) {
printk("test %d:\n", i + 1); printk("test %u:\n", i + 1);
tfm->crt_flags = 0; tfm->crt_flags = 0;
key = des_tv[i].key; key = des_tv[i].key;
...@@ -1189,14 +1189,13 @@ test_des(void) ...@@ -1189,14 +1189,13 @@ test_des(void)
out: out:
crypto_free_tfm(tfm); crypto_free_tfm(tfm);
return;
} }
void void
test_des3_ede(void) test_des3_ede(void)
{ {
int ret, i, len; unsigned int ret, i, len;
size_t tsize; unsigned int tsize;
char *p, *q; char *p, *q;
struct crypto_tfm *tfm; struct crypto_tfm *tfm;
char *key; char *key;
...@@ -1208,7 +1207,7 @@ test_des3_ede(void) ...@@ -1208,7 +1207,7 @@ test_des3_ede(void)
tsize = sizeof (des3_ede_enc_tv_template); tsize = sizeof (des3_ede_enc_tv_template);
if (tsize > TVMEMSIZE) { if (tsize > TVMEMSIZE) {
printk("template (%Zd) too big for tvmem (%d)\n", tsize, printk("template (%u) too big for tvmem (%u)\n", tsize,
TVMEMSIZE); TVMEMSIZE);
return; return;
} }
...@@ -1223,7 +1222,7 @@ test_des3_ede(void) ...@@ -1223,7 +1222,7 @@ test_des3_ede(void)
} }
for (i = 0; i < DES3_EDE_ENC_TEST_VECTORS; i++) { for (i = 0; i < DES3_EDE_ENC_TEST_VECTORS; i++) {
printk("test %d:\n", i + 1); printk("test %u:\n", i + 1);
key = des_tv[i].key; key = des_tv[i].key;
ret = crypto_cipher_setkey(tfm, key, 24); ret = crypto_cipher_setkey(tfm, key, 24);
...@@ -1257,7 +1256,7 @@ test_des3_ede(void) ...@@ -1257,7 +1256,7 @@ test_des3_ede(void)
tsize = sizeof (des3_ede_dec_tv_template); tsize = sizeof (des3_ede_dec_tv_template);
if (tsize > TVMEMSIZE) { if (tsize > TVMEMSIZE) {
printk("template (%Zd) too big for tvmem (%d)\n", tsize, printk("template (%u) too big for tvmem (%u)\n", tsize,
TVMEMSIZE); TVMEMSIZE);
return; return;
} }
...@@ -1266,7 +1265,7 @@ test_des3_ede(void) ...@@ -1266,7 +1265,7 @@ test_des3_ede(void)
des_tv = (void *) tvmem; des_tv = (void *) tvmem;
for (i = 0; i < DES3_EDE_DEC_TEST_VECTORS; i++) { for (i = 0; i < DES3_EDE_DEC_TEST_VECTORS; i++) {
printk("test %d:\n", i + 1); printk("test %u:\n", i + 1);
key = des_tv[i].key; key = des_tv[i].key;
ret = crypto_cipher_setkey(tfm, key, 24); ret = crypto_cipher_setkey(tfm, key, 24);
...@@ -1298,7 +1297,6 @@ test_des3_ede(void) ...@@ -1298,7 +1297,6 @@ test_des3_ede(void)
out: out:
crypto_free_tfm(tfm); crypto_free_tfm(tfm);
return;
} }
static void static void
......
...@@ -370,7 +370,7 @@ struct sha1_testvec { ...@@ -370,7 +370,7 @@ struct sha1_testvec {
#define DES3_EDE_DEC_TEST_VECTORS 3 #define DES3_EDE_DEC_TEST_VECTORS 3
struct des_tv { struct des_tv {
int len; unsigned int len;
int fail; int fail;
char key[24]; char key[24];
char iv[8]; char iv[8];
......
...@@ -65,17 +65,18 @@ struct scatterlist; ...@@ -65,17 +65,18 @@ struct scatterlist;
* via crypto_register_alg() and crypto_unregister_alg(). * via crypto_register_alg() and crypto_unregister_alg().
*/ */
struct cipher_alg { struct cipher_alg {
size_t cia_keysize; unsigned int cia_keysize;
size_t cia_ivsize; unsigned int cia_ivsize;
int (*cia_setkey)(void *ctx, const u8 *key, size_t keylen, int *flags); int (*cia_setkey)(void *ctx, const u8 *key,
void (*cia_encrypt)(void *ctx, u8 *dst, u8 *src); unsigned int keylen, u32 *flags);
void (*cia_decrypt)(void *ctx, u8 *dst, u8 *src); void (*cia_encrypt)(void *ctx, u8 *dst, const u8 *src);
void (*cia_decrypt)(void *ctx, u8 *dst, const u8 *src);
}; };
struct digest_alg { struct digest_alg {
size_t dia_digestsize; unsigned int dia_digestsize;
void (*dia_init)(void *ctx); void (*dia_init)(void *ctx);
void (*dia_update)(void *ctx, const u8 *data, size_t len); void (*dia_update)(void *ctx, const u8 *data, unsigned int len);
void (*dia_final)(void *ctx, u8 *out); void (*dia_final)(void *ctx, u8 *out);
}; };
...@@ -90,10 +91,10 @@ struct compress_alg { ...@@ -90,10 +91,10 @@ struct compress_alg {
struct crypto_alg { struct crypto_alg {
struct list_head cra_list; struct list_head cra_list;
int cra_flags; u32 cra_flags;
size_t cra_blocksize; unsigned int cra_blocksize;
size_t cra_ctxsize; unsigned int cra_ctxsize;
char cra_name[CRYPTO_MAX_ALG_NAME]; const char cra_name[CRYPTO_MAX_ALG_NAME];
union { union {
struct cipher_alg cipher; struct cipher_alg cipher;
...@@ -120,22 +121,24 @@ struct crypto_tfm; ...@@ -120,22 +121,24 @@ struct crypto_tfm;
struct cipher_tfm { struct cipher_tfm {
void *cit_iv; void *cit_iv;
u32 cit_mode; u32 cit_mode;
int (*cit_setkey)(struct crypto_tfm *tfm, const u8 *key, size_t keylen); int (*cit_setkey)(struct crypto_tfm *tfm,
const u8 *key, unsigned int keylen);
int (*cit_encrypt)(struct crypto_tfm *tfm, int (*cit_encrypt)(struct crypto_tfm *tfm,
struct scatterlist *sg, size_t nsg); struct scatterlist *sg, unsigned int nsg);
int (*cit_decrypt)(struct crypto_tfm *tfm, int (*cit_decrypt)(struct crypto_tfm *tfm,
struct scatterlist *sg, size_t nsg); struct scatterlist *sg, unsigned int nsg);
}; };
struct digest_tfm { struct digest_tfm {
void (*dit_init)(struct crypto_tfm *tfm); void (*dit_init)(struct crypto_tfm *tfm);
void (*dit_update)(struct crypto_tfm *tfm, void (*dit_update)(struct crypto_tfm *tfm,
struct scatterlist *sg, size_t nsg); struct scatterlist *sg, unsigned int nsg);
void (*dit_final)(struct crypto_tfm *tfm, u8 *out); void (*dit_final)(struct crypto_tfm *tfm, u8 *out);
void (*dit_digest)(struct crypto_tfm *tfm, struct scatterlist *sg, void (*dit_digest)(struct crypto_tfm *tfm, struct scatterlist *sg,
size_t nsg, u8 *out); unsigned int nsg, u8 *out);
void (*dit_hmac)(struct crypto_tfm *tfm, u8 *key, size_t keylen, void (*dit_hmac)(struct crypto_tfm *tfm, u8 *key,
struct scatterlist *sg, size_t nsg, u8 *out); unsigned int keylen, struct scatterlist *sg,
unsigned int nsg, u8 *out);
}; };
struct compress_tfm { struct compress_tfm {
...@@ -150,7 +153,7 @@ struct compress_tfm { ...@@ -150,7 +153,7 @@ struct compress_tfm {
struct crypto_tfm { struct crypto_tfm {
void *crt_ctx; void *crt_ctx;
int crt_flags; u32 crt_flags;
union { union {
struct cipher_tfm cipher; struct cipher_tfm cipher;
...@@ -174,13 +177,13 @@ struct crypto_tfm { ...@@ -174,13 +177,13 @@ struct crypto_tfm {
* crypto_free_tfm() frees up the transform and any associated resources, * crypto_free_tfm() frees up the transform and any associated resources,
* then drops the refcount on the associated algorithm. * then drops the refcount on the associated algorithm.
*/ */
struct crypto_tfm *crypto_alloc_tfm(char *alg_name, u32 tfm_flags); struct crypto_tfm *crypto_alloc_tfm(const char *alg_name, u32 tfm_flags);
void crypto_free_tfm(struct crypto_tfm *tfm); void crypto_free_tfm(struct crypto_tfm *tfm);
/* /*
* Transform helpers which query the underlying algorithm. * Transform helpers which query the underlying algorithm.
*/ */
static inline char *crypto_tfm_alg_name(struct crypto_tfm *tfm) static inline const char *crypto_tfm_alg_name(struct crypto_tfm *tfm)
{ {
return tfm->__crt_alg->cra_name; return tfm->__crt_alg->cra_name;
} }
...@@ -200,22 +203,22 @@ static inline u32 crypto_tfm_alg_type(struct crypto_tfm *tfm) ...@@ -200,22 +203,22 @@ static inline u32 crypto_tfm_alg_type(struct crypto_tfm *tfm)
return tfm->__crt_alg->cra_flags & CRYPTO_ALG_TYPE_MASK; return tfm->__crt_alg->cra_flags & CRYPTO_ALG_TYPE_MASK;
} }
static inline size_t crypto_tfm_alg_keysize(struct crypto_tfm *tfm) static inline unsigned int crypto_tfm_alg_keysize(struct crypto_tfm *tfm)
{ {
return tfm->__crt_alg->cra_cipher.cia_keysize; return tfm->__crt_alg->cra_cipher.cia_keysize;
} }
static inline size_t crypto_tfm_alg_ivsize(struct crypto_tfm *tfm) static inline unsigned int crypto_tfm_alg_ivsize(struct crypto_tfm *tfm)
{ {
return tfm->__crt_alg->cra_cipher.cia_ivsize; return tfm->__crt_alg->cra_cipher.cia_ivsize;
} }
static inline size_t crypto_tfm_alg_blocksize(struct crypto_tfm *tfm) static inline unsigned int crypto_tfm_alg_blocksize(struct crypto_tfm *tfm)
{ {
return tfm->__crt_alg->cra_blocksize; return tfm->__crt_alg->cra_blocksize;
} }
static inline size_t crypto_tfm_alg_digestsize(struct crypto_tfm *tfm) static inline unsigned int crypto_tfm_alg_digestsize(struct crypto_tfm *tfm)
{ {
return tfm->__crt_alg->cra_digest.dia_digestsize; return tfm->__crt_alg->cra_digest.dia_digestsize;
} }
...@@ -230,7 +233,8 @@ static inline void crypto_digest_init(struct crypto_tfm *tfm) ...@@ -230,7 +233,8 @@ static inline void crypto_digest_init(struct crypto_tfm *tfm)
} }
static inline void crypto_digest_update(struct crypto_tfm *tfm, static inline void crypto_digest_update(struct crypto_tfm *tfm,
struct scatterlist *sg, size_t nsg) struct scatterlist *sg,
unsigned int nsg)
{ {
BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_DIGEST); BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_DIGEST);
tfm->crt_digest.dit_update(tfm, sg, nsg); tfm->crt_digest.dit_update(tfm, sg, nsg);
...@@ -244,15 +248,16 @@ static inline void crypto_digest_final(struct crypto_tfm *tfm, u8 *out) ...@@ -244,15 +248,16 @@ static inline void crypto_digest_final(struct crypto_tfm *tfm, u8 *out)
static inline void crypto_digest_digest(struct crypto_tfm *tfm, static inline void crypto_digest_digest(struct crypto_tfm *tfm,
struct scatterlist *sg, struct scatterlist *sg,
size_t nsg, u8 *out) unsigned int nsg, u8 *out)
{ {
BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_DIGEST); BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_DIGEST);
tfm->crt_digest.dit_digest(tfm, sg, nsg, out); tfm->crt_digest.dit_digest(tfm, sg, nsg, out);
} }
static inline void crypto_digest_hmac(struct crypto_tfm *tfm, u8 *key, static inline void crypto_digest_hmac(struct crypto_tfm *tfm,
size_t keylen, struct scatterlist *sg, u8 *key, unsigned int keylen,
size_t nsg, u8 *out) struct scatterlist *sg,
unsigned int nsg, u8 *out)
{ {
BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_DIGEST); BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_DIGEST);
...@@ -260,35 +265,37 @@ static inline void crypto_digest_hmac(struct crypto_tfm *tfm, u8 *key, ...@@ -260,35 +265,37 @@ static inline void crypto_digest_hmac(struct crypto_tfm *tfm, u8 *key,
} }
static inline int crypto_cipher_setkey(struct crypto_tfm *tfm, static inline int crypto_cipher_setkey(struct crypto_tfm *tfm,
const u8 *key, size_t keylen) const u8 *key, unsigned int keylen)
{ {
BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
return tfm->crt_cipher.cit_setkey(tfm, key, keylen); return tfm->crt_cipher.cit_setkey(tfm, key, keylen);
} }
static inline int crypto_cipher_encrypt(struct crypto_tfm *tfm, static inline int crypto_cipher_encrypt(struct crypto_tfm *tfm,
struct scatterlist *sg, size_t nsg) struct scatterlist *sg,
unsigned int nsg)
{ {
BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
return tfm->crt_cipher.cit_encrypt(tfm, sg, nsg); return tfm->crt_cipher.cit_encrypt(tfm, sg, nsg);
} }
static inline int crypto_cipher_decrypt(struct crypto_tfm *tfm, static inline int crypto_cipher_decrypt(struct crypto_tfm *tfm,
struct scatterlist *sg, size_t nsg) struct scatterlist *sg,
unsigned int nsg)
{ {
BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
return tfm->crt_cipher.cit_decrypt(tfm, sg, nsg); return tfm->crt_cipher.cit_decrypt(tfm, sg, nsg);
} }
static inline void crypto_cipher_set_iv(struct crypto_tfm *tfm, static inline void crypto_cipher_set_iv(struct crypto_tfm *tfm,
u8 *src, size_t len) const u8 *src, unsigned int len)
{ {
BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
memcpy(tfm->crt_cipher.cit_iv, src, len); memcpy(tfm->crt_cipher.cit_iv, src, len);
} }
static inline void crypto_cipher_get_iv(struct crypto_tfm *tfm, static inline void crypto_cipher_get_iv(struct crypto_tfm *tfm,
u8 *dst, size_t len) u8 *dst, unsigned int len)
{ {
BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
memcpy(dst, tfm->crt_cipher.cit_iv, len); memcpy(dst, tfm->crt_cipher.cit_iv, len);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment