From 27b2336029335ea3f02243ff170986cdab1f98ef Mon Sep 17 00:00:00 2001 From: Jean-Christophe PLAGNIOL-VILLARD Date: Wed, 11 Mar 2015 17:53:04 +0100 Subject: 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 Signed-off-by: Sascha Hauer --- include/digest.h | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'include/digest.h') 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 -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__ */ -- cgit v1.2.3