From a3e1e63c353ba0f7f6c564f3da043952399bdb19 Mon Sep 17 00:00:00 2001 From: John Johansen Date: Mon, 1 May 2017 18:20:25 -0700 Subject: [PATCH] apparmor: add/use fns to print hash string hex value Signed-off-by: John Johansen Signed-off-by: Seth Forshee --- security/apparmor/crypto.c | 19 +++++++++++++++++++ security/apparmor/include/crypto.h | 11 +++++++++++ 2 files changed, 30 insertions(+) diff --git a/security/apparmor/crypto.c b/security/apparmor/crypto.c index 136f2a047836..cfedacb0a197 100644 --- a/security/apparmor/crypto.c +++ b/security/apparmor/crypto.c @@ -29,6 +29,25 @@ unsigned int aa_hash_size(void) return apparmor_hash_size; } +void aa_snprint_hashstr(char *out, unsigned char *hash, unsigned int hsize) +{ + unsigned int i; + + for (i = 0; i < hsize; i++) + sprintf(out + i*2, "%.2x", hash[i]); + out[hsize*2] = 0; +} + +char *aa_asprint_hashstr(unsigned char *hash, unsigned int hsize, gfp_t gfp) +{ + char *buffer = kmalloc(hsize*2 + 1, gfp); + if (!buffer) + return NULL; + aa_snprint_hashstr(buffer, hash, hsize); + + return buffer; +} + char *aa_calc_hash(void *data, size_t len) { SHASH_DESC_ON_STACK(desc, apparmor_tfm); diff --git a/security/apparmor/include/crypto.h b/security/apparmor/include/crypto.h index c1469f8db174..4d927dc1ed30 100644 --- a/security/apparmor/include/crypto.h +++ b/security/apparmor/include/crypto.h @@ -18,6 +18,8 @@ #ifdef CONFIG_SECURITY_APPARMOR_HASH unsigned int aa_hash_size(void); +void aa_snprint_hashstr(char *out, unsigned char *hash, unsigned int hsize); +char *aa_asprint_hashstr(unsigned char *hash, unsigned int hsize, gfp_t gfp); char *aa_calc_hash(void *data, size_t len); int aa_calc_profile_hash(struct aa_profile *profile, u32 version, void *start, size_t len); @@ -36,6 +38,15 @@ static inline unsigned int aa_hash_size(void) { return 0; } + +void aa_snprint_hashstr(char *out, unsigned char *hash, unsigned int hsize) +{ +} + +char *aa_asprint_hashstr(unsigned char *hash, unsigned int hsize, gfp_t gfp); +{ + return NULL; +} #endif #endif /* __APPARMOR_CRYPTO_H */ -- 2.39.2