crypto: ahash - make hash walk functions private to ahash.c
Due to the removal of the Niagara2 SPU driver, crypto_hash_walk_first(), crypto_hash_walk_done(), crypto_hash_walk_last(), and struct crypto_hash_walk are now only used in crypto/ahash.c. Therefore, make them all private to crypto/ahash.c. I.e. un-export the two functions that were exported, make the functions static, and move the struct definition to the .c file. As part of this, move the functions to earlier in the file to avoid needing to add forward declarations. Signed-off-by: Eric Biggers <ebiggers@google.com> Acked-by: Ard Biesheuvel <ardb@kernel.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
parent
9ff6e943bc
commit
7fa4817340
2 changed files with 87 additions and 94 deletions
158
crypto/ahash.c
158
crypto/ahash.c
|
@ -27,6 +27,93 @@
|
|||
|
||||
#define CRYPTO_ALG_TYPE_AHASH_MASK 0x0000000e
|
||||
|
||||
struct crypto_hash_walk {
|
||||
char *data;
|
||||
|
||||
unsigned int offset;
|
||||
unsigned int flags;
|
||||
|
||||
struct page *pg;
|
||||
unsigned int entrylen;
|
||||
|
||||
unsigned int total;
|
||||
struct scatterlist *sg;
|
||||
};
|
||||
|
||||
static int hash_walk_next(struct crypto_hash_walk *walk)
|
||||
{
|
||||
unsigned int offset = walk->offset;
|
||||
unsigned int nbytes = min(walk->entrylen,
|
||||
((unsigned int)(PAGE_SIZE)) - offset);
|
||||
|
||||
walk->data = kmap_local_page(walk->pg);
|
||||
walk->data += offset;
|
||||
walk->entrylen -= nbytes;
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
static int hash_walk_new_entry(struct crypto_hash_walk *walk)
|
||||
{
|
||||
struct scatterlist *sg;
|
||||
|
||||
sg = walk->sg;
|
||||
walk->offset = sg->offset;
|
||||
walk->pg = sg_page(walk->sg) + (walk->offset >> PAGE_SHIFT);
|
||||
walk->offset = offset_in_page(walk->offset);
|
||||
walk->entrylen = sg->length;
|
||||
|
||||
if (walk->entrylen > walk->total)
|
||||
walk->entrylen = walk->total;
|
||||
walk->total -= walk->entrylen;
|
||||
|
||||
return hash_walk_next(walk);
|
||||
}
|
||||
|
||||
static int crypto_hash_walk_first(struct ahash_request *req,
|
||||
struct crypto_hash_walk *walk)
|
||||
{
|
||||
walk->total = req->nbytes;
|
||||
|
||||
if (!walk->total) {
|
||||
walk->entrylen = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
walk->sg = req->src;
|
||||
walk->flags = req->base.flags;
|
||||
|
||||
return hash_walk_new_entry(walk);
|
||||
}
|
||||
|
||||
static int crypto_hash_walk_done(struct crypto_hash_walk *walk, int err)
|
||||
{
|
||||
walk->data -= walk->offset;
|
||||
|
||||
kunmap_local(walk->data);
|
||||
crypto_yield(walk->flags);
|
||||
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
if (walk->entrylen) {
|
||||
walk->offset = 0;
|
||||
walk->pg++;
|
||||
return hash_walk_next(walk);
|
||||
}
|
||||
|
||||
if (!walk->total)
|
||||
return 0;
|
||||
|
||||
walk->sg = sg_next(walk->sg);
|
||||
|
||||
return hash_walk_new_entry(walk);
|
||||
}
|
||||
|
||||
static inline int crypto_hash_walk_last(struct crypto_hash_walk *walk)
|
||||
{
|
||||
return !(walk->entrylen | walk->total);
|
||||
}
|
||||
|
||||
/*
|
||||
* For an ahash tfm that is using an shash algorithm (instead of an ahash
|
||||
* algorithm), this returns the underlying shash tfm.
|
||||
|
@ -137,77 +224,6 @@ static int crypto_init_ahash_using_shash(struct crypto_tfm *tfm)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int hash_walk_next(struct crypto_hash_walk *walk)
|
||||
{
|
||||
unsigned int offset = walk->offset;
|
||||
unsigned int nbytes = min(walk->entrylen,
|
||||
((unsigned int)(PAGE_SIZE)) - offset);
|
||||
|
||||
walk->data = kmap_local_page(walk->pg);
|
||||
walk->data += offset;
|
||||
walk->entrylen -= nbytes;
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
static int hash_walk_new_entry(struct crypto_hash_walk *walk)
|
||||
{
|
||||
struct scatterlist *sg;
|
||||
|
||||
sg = walk->sg;
|
||||
walk->offset = sg->offset;
|
||||
walk->pg = sg_page(walk->sg) + (walk->offset >> PAGE_SHIFT);
|
||||
walk->offset = offset_in_page(walk->offset);
|
||||
walk->entrylen = sg->length;
|
||||
|
||||
if (walk->entrylen > walk->total)
|
||||
walk->entrylen = walk->total;
|
||||
walk->total -= walk->entrylen;
|
||||
|
||||
return hash_walk_next(walk);
|
||||
}
|
||||
|
||||
int crypto_hash_walk_done(struct crypto_hash_walk *walk, int err)
|
||||
{
|
||||
walk->data -= walk->offset;
|
||||
|
||||
kunmap_local(walk->data);
|
||||
crypto_yield(walk->flags);
|
||||
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
if (walk->entrylen) {
|
||||
walk->offset = 0;
|
||||
walk->pg++;
|
||||
return hash_walk_next(walk);
|
||||
}
|
||||
|
||||
if (!walk->total)
|
||||
return 0;
|
||||
|
||||
walk->sg = sg_next(walk->sg);
|
||||
|
||||
return hash_walk_new_entry(walk);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(crypto_hash_walk_done);
|
||||
|
||||
int crypto_hash_walk_first(struct ahash_request *req,
|
||||
struct crypto_hash_walk *walk)
|
||||
{
|
||||
walk->total = req->nbytes;
|
||||
|
||||
if (!walk->total) {
|
||||
walk->entrylen = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
walk->sg = req->src;
|
||||
walk->flags = req->base.flags;
|
||||
|
||||
return hash_walk_new_entry(walk);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(crypto_hash_walk_first);
|
||||
|
||||
static int ahash_nosetkey(struct crypto_ahash *tfm, const u8 *key,
|
||||
unsigned int keylen)
|
||||
{
|
||||
|
|
|
@ -12,20 +12,6 @@
|
|||
#include <crypto/hash.h>
|
||||
|
||||
struct ahash_request;
|
||||
struct scatterlist;
|
||||
|
||||
struct crypto_hash_walk {
|
||||
char *data;
|
||||
|
||||
unsigned int offset;
|
||||
unsigned int flags;
|
||||
|
||||
struct page *pg;
|
||||
unsigned int entrylen;
|
||||
|
||||
unsigned int total;
|
||||
struct scatterlist *sg;
|
||||
};
|
||||
|
||||
struct ahash_instance {
|
||||
void (*free)(struct ahash_instance *inst);
|
||||
|
@ -57,15 +43,6 @@ struct crypto_shash_spawn {
|
|||
struct crypto_spawn base;
|
||||
};
|
||||
|
||||
int crypto_hash_walk_done(struct crypto_hash_walk *walk, int err);
|
||||
int crypto_hash_walk_first(struct ahash_request *req,
|
||||
struct crypto_hash_walk *walk);
|
||||
|
||||
static inline int crypto_hash_walk_last(struct crypto_hash_walk *walk)
|
||||
{
|
||||
return !(walk->entrylen | walk->total);
|
||||
}
|
||||
|
||||
int crypto_register_ahash(struct ahash_alg *alg);
|
||||
void crypto_unregister_ahash(struct ahash_alg *alg);
|
||||
int crypto_register_ahashes(struct ahash_alg *algs, int count);
|
||||
|
|
Loading…
Add table
Reference in a new issue