diff options
author | Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> | 2015-03-11 17:53:04 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2015-03-12 07:58:24 +0100 |
commit | 27b2336029335ea3f02243ff170986cdab1f98ef (patch) | |
tree | 722083808d1ce9b3bb69d3cca3520ce61a09064d /include/digest.h | |
parent | 804fae5d16c8c48c6fca8d54f2878a2e382a0bc2 (diff) | |
download | barebox-27b2336029335ea3f02243ff170986cdab1f98ef.tar.gz |
digest: make it multi-instance
Now you need to call digest_alloc and when you finish to use it digest_free.
We need this for upcomming aes encryption support and secure boot
as we will need multiple instance of the same digest.
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'include/digest.h')
-rw-r--r-- | include/digest.h | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/include/digest.h b/include/digest.h index 208a463793..2fd1135175 100644 --- a/include/digest.h +++ b/include/digest.h @@ -21,26 +21,36 @@ #include <linux/list.h> -struct digest -{ +struct digest; + +struct digest_algo { char *name; + int (*alloc)(struct digest *d); + void (*free)(struct digest *d); int (*init)(struct digest *d); int (*update)(struct digest *d, const void *data, unsigned long len); int (*final)(struct digest *d, unsigned char *md); unsigned int length; + unsigned int ctx_length; struct list_head list; }; +struct digest { + struct digest_algo *algo; + void *ctx; +}; + /* * digest functions */ -int digest_register(struct digest *d); -void digest_unregister(struct digest *d); +int digest_algo_register(struct digest_algo *d); +void digest_algo_unregister(struct digest_algo *d); -struct digest* digest_get_by_name(char* name); +struct digest *digest_alloc(char* name); +void digest_free(struct digest *d); int digest_file_window(struct digest *d, char *filename, unsigned char *hash, @@ -52,23 +62,23 @@ int digest_file_by_name(char *algo, char *filename, static inline int digest_init(struct digest *d) { - return d->init(d); + return d->algo->init(d); } static inline int digest_update(struct digest *d, const void *data, unsigned long len) { - return d->update(d, data, len); + return d->algo->update(d, data, len); } static inline int digest_final(struct digest *d, unsigned char *md) { - return d->final(d, md); + return d->algo->final(d, md); } static inline int digest_length(struct digest *d) { - return d->length; + return d->algo->length; } #endif /* __SH_ST_DEVICES_H__ */ |