From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stephan =?ISO-8859-1?Q?M=FCller?= Subject: [PATCH v25 05/12] crypto: DRBG - externalize DRBG functions for LRNG Date: Sat, 16 Nov 2019 10:35:01 +0100 Message-ID: <2476455.50z32j2Nbd@positron.chronox.de> References: <6157374.ptSnyUpaCn@positron.chronox.de> <2787174.DQlWHN5GGo@positron.chronox.de> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Return-path: In-Reply-To: <2787174.DQlWHN5GGo@positron.chronox.de> Sender: linux-kernel-owner@vger.kernel.org To: Arnd Bergmann Cc: Greg Kroah-Hartman , linux-crypto@vger.kernel.org, LKML , linux-api@vger.kernel.org, "Eric W. Biederman" , "Alexander E. Patrakov" , "Ahmed S. Darwish" , "Theodore Y. Ts'o" , Willy Tarreau , Matthew Garrett , Vito Caputo , Andreas Dilger , Jan Kara , Ray Strode , William Jon McCann , zhangjs , Andy Lutomirski , Florian Weimer , Lennart Poettering , Nicolai Stange , "Peter, Matthias" List-Id: linux-api@vger.kernel.org This patch allows several DRBG functions to be called by the LRNG kernel code paths outside the drbg.c file. CC: "Eric W. Biederman" CC: "Alexander E. Patrakov" CC: "Ahmed S. Darwish" CC: "Theodore Y. Ts'o" CC: Willy Tarreau CC: Matthew Garrett CC: Vito Caputo CC: Andreas Dilger CC: Jan Kara CC: Ray Strode CC: William Jon McCann CC: zhangjs CC: Andy Lutomirski CC: Florian Weimer CC: Lennart Poettering CC: Nicolai Stange Reviewed-by: Roman Drahtmueller Tested-by: Roman Drahtm=FCller Tested-by: Marcelo Henrique Cerri Tested-by: Neil Horman Signed-off-by: Stephan Mueller =2D-- crypto/drbg.c | 16 ++++++++++------ include/crypto/drbg.h | 7 +++++++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/crypto/drbg.c b/crypto/drbg.c index b6929eb5f565..5561dd0f09e1 100644 =2D-- a/crypto/drbg.c +++ b/crypto/drbg.c @@ -113,7 +113,7 @@ * the SHA256 / AES 256 over other ciphers. Thus, the favored * DRBGs are the latest entries in this array. */ =2Dstatic const struct drbg_core drbg_cores[] =3D { +const struct drbg_core drbg_cores[] =3D { #ifdef CONFIG_CRYPTO_DRBG_CTR { .flags =3D DRBG_CTR | DRBG_STRENGTH128, @@ -190,6 +190,7 @@ static const struct drbg_core drbg_cores[] =3D { }, #endif /* CONFIG_CRYPTO_DRBG_HMAC */ }; +EXPORT_SYMBOL(drbg_cores); =20 static int drbg_uninstantiate(struct drbg_state *drbg); =20 @@ -205,7 +206,7 @@ static int drbg_uninstantiate(struct drbg_state *drbg); * Return: normalized strength in *bytes* value or 32 as default * to counter programming errors */ =2Dstatic inline unsigned short drbg_sec_strength(drbg_flag_t flags) +unsigned short drbg_sec_strength(drbg_flag_t flags) { switch (flags & DRBG_STRENGTH_MASK) { case DRBG_STRENGTH128: @@ -218,6 +219,7 @@ static inline unsigned short drbg_sec_strength(drbg_fla= g_t flags) return 32; } } +EXPORT_SYMBOL(drbg_sec_strength); =20 /* * FIPS 140-2 continuous self test for the noise source @@ -1202,7 +1204,7 @@ static int drbg_seed(struct drbg_state *drbg, struct = drbg_string *pers, } =20 /* Free all substructures in a DRBG state without the DRBG state structure= */ =2Dstatic inline void drbg_dealloc_state(struct drbg_state *drbg) +void drbg_dealloc_state(struct drbg_state *drbg) { if (!drbg) return; @@ -1223,12 +1225,13 @@ static inline void drbg_dealloc_state(struct drbg_s= tate *drbg) drbg->fips_primed =3D false; } } +EXPORT_SYMBOL(drbg_dealloc_state); =20 /* * Allocate all sub-structures for a DRBG state. * The DRBG state structure must already be allocated. */ =2Dstatic inline int drbg_alloc_state(struct drbg_state *drbg) +int drbg_alloc_state(struct drbg_state *drbg) { int ret =3D -ENOMEM; unsigned int sb_size =3D 0; @@ -1307,6 +1310,7 @@ static inline int drbg_alloc_state(struct drbg_state = *drbg) drbg_dealloc_state(drbg); return ret; } +EXPORT_SYMBOL(drbg_alloc_state); =20 /************************************************************************* * DRBG interface functions @@ -1874,8 +1878,7 @@ static int drbg_kcapi_sym_ctr(struct drbg_state *drbg, * * return: flags */ =2Dstatic inline void drbg_convert_tfm_core(const char *cra_driver_name, =2D int *coreref, bool *pr) +void drbg_convert_tfm_core(const char *cra_driver_name, int *coreref, bool= *pr) { int i =3D 0; size_t start =3D 0; @@ -1902,6 +1905,7 @@ static inline void drbg_convert_tfm_core(const char *= cra_driver_name, } } } +EXPORT_SYMBOL(drbg_convert_tfm_core); =20 static int drbg_kcapi_init(struct crypto_tfm *tfm) { diff --git a/include/crypto/drbg.h b/include/crypto/drbg.h index 8c9af21efce1..c63b20375235 100644 =2D-- a/include/crypto/drbg.h +++ b/include/crypto/drbg.h @@ -282,4 +282,11 @@ enum drbg_prefixes { DRBG_PREFIX3 }; =20 +extern int drbg_alloc_state(struct drbg_state *drbg); +extern void drbg_dealloc_state(struct drbg_state *drbg); +extern void drbg_convert_tfm_core(const char *cra_driver_name, int *corere= f, + bool *pr); +extern const struct drbg_core drbg_cores[]; +extern unsigned short drbg_sec_strength(drbg_flag_t flags); + #endif /* _DRBG_H */ =2D-=20 2.23.0