Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp860967rwl; Fri, 24 Mar 2023 03:05:00 -0700 (PDT) X-Google-Smtp-Source: AKy350Z9/dCj2JFtupuEoxnhGqApwmt/hwHxCCFMnJHBu4PM5M2J5egncaLhdZtr43UdvMWWw3+6 X-Received: by 2002:a17:906:73d3:b0:92f:38a6:d087 with SMTP id n19-20020a17090673d300b0092f38a6d087mr1866010ejl.4.1679652299810; Fri, 24 Mar 2023 03:04:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679652299; cv=none; d=google.com; s=arc-20160816; b=tBvFKwHRBUy2N4cv1gFyd3erI2Mdq48Exw0NJ30pnmyb5KtbLzCNQLrot/lxA18brq TdBUg8umZWE+wrh7G40mllfjh8xcUnub8AEKP6/2V65H71PWoHeItHMDtBhyKLDyH5of 0k7JITwEcHk86T1t/0LxqYWf/8aTmjVLiJ3US38uN7SUHKwr3d5S+F0eHzOPSWv3djO7 LxU4vttoQ1pPrPn3A2n9J+a/LC0rZ7CBRwmzpiIHbC4a3tm1xqTrbBFhUAizgPwBLd0+ WG9SOqbzcmm+Jbuzh0sDrkbGH6v8Xtz1emPLkYkVbMID1Y16bMfH45gU9x5kmXfOVw0B EJmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:to:from:date; bh=ah3wAU3HYkq629+rVlp0KpPEl/5fBzAVcaxYUvr05d8=; b=IcMDdPigxVMtyICfeD5fnXkQgsPr7EemPPylCZ8XxJrD8sY5IQQ39RCOQcvq2WKHP0 LpEXd9/XeYedyOMGGshy6BD9zcemR4yV6G8xJUh2o0E7R+mmTm7W/is4GMcfJBLE9k// wEbMNiAIbc4TR2YEWHHOoQptGY4t+TXFjp6qKvs+18pg+5Ragv5Mrq/R3vMnFTv9vDiD luIUEdPgr5Mhcx7QXMgRwccMcBu+7wyVzz7XLIHGXiJCE2PwPWXwFKyFbdLyhSkIHvgH H8ZlRARGYP/KVR2DWn8ibQ43s6yedWXye0AVTOgkQ5H7LFTk5VvyYInJ/zvHA+5pw1Z3 Y4vQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h3-20020a170906828300b008d6b51de6bcsi20172531ejx.32.2023.03.24.03.04.35; Fri, 24 Mar 2023 03:04:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231194AbjCXJ7r (ORCPT + 99 others); Fri, 24 Mar 2023 05:59:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231475AbjCXJ7q (ORCPT ); Fri, 24 Mar 2023 05:59:46 -0400 Received: from 167-179-156-38.a7b39c.syd.nbn.aussiebb.net (167-179-156-38.a7b39c.syd.nbn.aussiebb.net [167.179.156.38]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB14817CE9 for ; Fri, 24 Mar 2023 02:59:43 -0700 (PDT) Received: from loth.rohan.me.apana.org.au ([192.168.167.2]) by formenos.hmeau.com with smtp (Exim 4.94.2 #2 (Debian)) id 1pfeCw-008F4a-UG; Fri, 24 Mar 2023 17:59:40 +0800 Received: by loth.rohan.me.apana.org.au (sSMTP sendmail emulation); Fri, 24 Mar 2023 17:59:38 +0800 Date: Fri, 24 Mar 2023 17:59:38 +0800 From: Herbert Xu To: Linux Crypto Mailing List Subject: [PATCH] crypto: lib/utils - Move utilities into new header Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=4.3 required=5.0 tests=HELO_DYNAMIC_IPADDR2, PDS_RDNS_DYNAMIC_FP,RDNS_DYNAMIC,SPF_HELO_NONE,SPF_PASS,TVD_RCVD_IP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: **** X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The utilities have historically resided in algapi.h as they were first used internally before being exported. Move them into a new header file so external users don't see internal API details. Signed-off-by: Herbert Xu --- include/crypto/algapi.h | 63 ----------------------------------------- include/crypto/utils.h | 73 ++++++++++++++++++++++++++++++++++++++++++++++++ lib/crypto/utils.c | 2 - 3 files changed, 75 insertions(+), 63 deletions(-) diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h index e28957993b56..bbf8c43c3320 100644 --- a/include/crypto/algapi.h +++ b/include/crypto/algapi.h @@ -7,15 +7,12 @@ #ifndef _CRYPTO_ALGAPI_H #define _CRYPTO_ALGAPI_H +#include #include #include #include -#include -#include #include -#include - /* * Maximum values for blocksize and alignmask, used to allocate * static buffers that are big enough for any combination of @@ -172,47 +169,6 @@ static inline unsigned int crypto_queue_len(struct crypto_queue *queue) } void crypto_inc(u8 *a, unsigned int size); -void __crypto_xor(u8 *dst, const u8 *src1, const u8 *src2, unsigned int size); - -static inline void crypto_xor(u8 *dst, const u8 *src, unsigned int size) -{ - if (IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && - __builtin_constant_p(size) && - (size % sizeof(unsigned long)) == 0) { - unsigned long *d = (unsigned long *)dst; - unsigned long *s = (unsigned long *)src; - unsigned long l; - - while (size > 0) { - l = get_unaligned(d) ^ get_unaligned(s++); - put_unaligned(l, d++); - size -= sizeof(unsigned long); - } - } else { - __crypto_xor(dst, dst, src, size); - } -} - -static inline void crypto_xor_cpy(u8 *dst, const u8 *src1, const u8 *src2, - unsigned int size) -{ - if (IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && - __builtin_constant_p(size) && - (size % sizeof(unsigned long)) == 0) { - unsigned long *d = (unsigned long *)dst; - unsigned long *s1 = (unsigned long *)src1; - unsigned long *s2 = (unsigned long *)src2; - unsigned long l; - - while (size > 0) { - l = get_unaligned(s1++) ^ get_unaligned(s2++); - put_unaligned(l, d++); - size -= sizeof(unsigned long); - } - } else { - __crypto_xor(dst, src1, src2, size); - } -} static inline void *crypto_tfm_ctx(struct crypto_tfm *tfm) { @@ -291,23 +247,6 @@ static inline u32 crypto_algt_inherited_mask(struct crypto_attr_type *algt) return crypto_requires_off(algt, CRYPTO_ALG_INHERITED_FLAGS); } -noinline unsigned long __crypto_memneq(const void *a, const void *b, size_t size); - -/** - * crypto_memneq - Compare two areas of memory without leaking - * timing information. - * - * @a: One area of memory - * @b: Another area of memory - * @size: The size of the area. - * - * Returns 0 when data is equal, 1 otherwise. - */ -static inline int crypto_memneq(const void *a, const void *b, size_t size) -{ - return __crypto_memneq(a, b, size) != 0UL ? 1 : 0; -} - int crypto_register_notifier(struct notifier_block *nb); int crypto_unregister_notifier(struct notifier_block *nb); diff --git a/include/crypto/utils.h b/include/crypto/utils.h new file mode 100644 index 000000000000..acbb917a00c6 --- /dev/null +++ b/include/crypto/utils.h @@ -0,0 +1,73 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Cryptographic utilities + * + * Copyright (c) 2023 Herbert Xu + */ +#ifndef _CRYPTO_UTILS_H +#define _CRYPTO_UTILS_H + +#include +#include +#include + +void __crypto_xor(u8 *dst, const u8 *src1, const u8 *src2, unsigned int size); + +static inline void crypto_xor(u8 *dst, const u8 *src, unsigned int size) +{ + if (IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && + __builtin_constant_p(size) && + (size % sizeof(unsigned long)) == 0) { + unsigned long *d = (unsigned long *)dst; + unsigned long *s = (unsigned long *)src; + unsigned long l; + + while (size > 0) { + l = get_unaligned(d) ^ get_unaligned(s++); + put_unaligned(l, d++); + size -= sizeof(unsigned long); + } + } else { + __crypto_xor(dst, dst, src, size); + } +} + +static inline void crypto_xor_cpy(u8 *dst, const u8 *src1, const u8 *src2, + unsigned int size) +{ + if (IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && + __builtin_constant_p(size) && + (size % sizeof(unsigned long)) == 0) { + unsigned long *d = (unsigned long *)dst; + unsigned long *s1 = (unsigned long *)src1; + unsigned long *s2 = (unsigned long *)src2; + unsigned long l; + + while (size > 0) { + l = get_unaligned(s1++) ^ get_unaligned(s2++); + put_unaligned(l, d++); + size -= sizeof(unsigned long); + } + } else { + __crypto_xor(dst, src1, src2, size); + } +} + +noinline unsigned long __crypto_memneq(const void *a, const void *b, size_t size); + +/** + * crypto_memneq - Compare two areas of memory without leaking + * timing information. + * + * @a: One area of memory + * @b: Another area of memory + * @size: The size of the area. + * + * Returns 0 when data is equal, 1 otherwise. + */ +static inline int crypto_memneq(const void *a, const void *b, size_t size) +{ + return __crypto_memneq(a, b, size) != 0UL ? 1 : 0; +} + +#endif /* _CRYPTO_UTILS_H */ diff --git a/lib/crypto/utils.c b/lib/crypto/utils.c index 53230ab1b195..c852c7151b0a 100644 --- a/lib/crypto/utils.c +++ b/lib/crypto/utils.c @@ -6,7 +6,7 @@ */ #include -#include +#include #include /* -- Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt