Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4792417rdh; Wed, 29 Nov 2023 10:45:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IGoB3Vk6mn4dDQDAtHUjw/7r/MPde1SqnphpAhen8LfF9cRV1UihW9uSBMiQc1Pd4mumy+I X-Received: by 2002:a05:6358:9144:b0:16d:c941:94a3 with SMTP id r4-20020a056358914400b0016dc94194a3mr15315185rwr.22.1701283501574; Wed, 29 Nov 2023 10:45:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701283501; cv=none; d=google.com; s=arc-20160816; b=b08tju7xceetVDsU1lhD6Dptr/XzsRUibXSmUK0qAQd0dVaC2tfK9vygla000s9h7Y CNsJQe/6ed216RC/Fy9kycpSQhpdTaVZUBbLgTnG9bDzD9umIX4GwonAWpVyLThZC/if GCvToKx8t3RnlonUYrsB1Jd3De6oftHFCQPb6okPwD/2lAGU9mnogTnS8BAX2P2BQCxs 4/15uMUCbg+lPCd83o11zof2bcahoCs/qN9KNX7cShgVyb9HwtUhRr3CaZu8sHioKOFk 9zJahvU6cDiGubjfoySnlcrJxz1wte3gSENpXC92fvnq+ZeXfPWzdk5g8rsDIifwk7M6 gGzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Obn0SOZ4sVDm2h1gfdHA4qAbaHYxGk7I+IMSeis582Y=; fh=M0rEmD0Pic9jtX/RYmPDdUZgtiGxFo1iVCR6SQNjyx0=; b=Pp9JsGSjRDT70jNFXa040ZrSbmGry02t3NVWHwNTOjI5pDo+dtL/UDjpGoreoTVbKq Jsuz7BOiWY+xlc0CKW9ucnyJCw2AOhbcySSmCQeemzqMe97DzUlOVO+Ge6PYt2nSmLkp 1bfRPMUqaSPrrtmj8Rn1lFykxrlzfEwV5kiqynG9nAV0HIU0vrlHBe5RwIkkZ9AgLRxD 7R3pCfZxJJXzq7abmj18aYuFOmFvJ0D+MTRiX2EuG9pjxpqO9XQPPOC+ZRjVFrM9K9lr jriS6g7fY6ufqllExoLp6Ri0g1EFOt7XZoLLfcTzUFpNdoN/d0O33C5+4gZWkLoomAN5 RC7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@meta.com header.s=s2048-2021-q4 header.b=aV7BqWcS; spf=pass (google.com: domain of linux-crypto+bounces-389-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-crypto+bounces-389-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=meta.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id l4-20020a05622a174400b0041793b4dfcdsi14541780qtk.303.2023.11.29.10.45.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 10:45:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto+bounces-389-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@meta.com header.s=s2048-2021-q4 header.b=aV7BqWcS; spf=pass (google.com: domain of linux-crypto+bounces-389-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-crypto+bounces-389-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=meta.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 44A161C209CA for ; Wed, 29 Nov 2023 18:45:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A78575DF04 for ; Wed, 29 Nov 2023 18:45:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=meta.com header.i=@meta.com header.b="aV7BqWcS" X-Original-To: linux-crypto@vger.kernel.org Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABF20CA; Wed, 29 Nov 2023 09:33:45 -0800 (PST) Received: from pps.filterd (m0044010.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3ATH26Pw005681; Wed, 29 Nov 2023 09:33:31 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=meta.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=s2048-2021-q4; bh=Obn0SOZ4sVDm2h1gfdHA4qAbaHYxGk7I+IMSeis582Y=; b=aV7BqWcSL9j3l+DpLHRnpyrbRQzOuncRDuPrIh0n8VdjvMtFTWGMHpJwUU3GHK8opAK3 c9ijpOjxWDKYhcDETzUzVjiYeafcJOOpRcms0ccXRczc3QQ3IoGrffimc1hAlakktb58 4UxiYzH9TUMScFX6ncCVPBjylwZK//PYU+i2kP6GY6adH+GQiEyBtd2m5ROSq24WmWUc 3ECpSGEBnH29cVTcAsZgMNlZe4sJKO524BE5sxCNnrmdPBPkXP93X0Iy5zn3e44tQRbr MLAIrkFg1IUlbi+26Q8KgFhq5m1OyHlJwC2u74YnyoP3+rEY7/w/V+RGBAHhtVJRXfNd KQ== Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3up0rmk7fp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 29 Nov 2023 09:33:31 -0800 Received: from devvm4158.cln0.facebook.com (2620:10d:c085:108::4) by mail.thefacebook.com (2620:10d:c085:11d::8) with Microsoft SMTP Server id 15.1.2507.34; Wed, 29 Nov 2023 09:33:28 -0800 From: Vadim Fedorenko To: Vadim Fedorenko , Jakub Kicinski , Martin KaFai Lau , Andrii Nakryiko , Alexei Starovoitov , Mykola Lysenko , Herbert Xu CC: Vadim Fedorenko , , , Subject: [PATCH bpf-next v6 2/3] bpf: crypto: add skcipher to bpf crypto Date: Wed, 29 Nov 2023 09:33:11 -0800 Message-ID: <20231129173312.31008-2-vadfed@meta.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20231129173312.31008-1-vadfed@meta.com> References: <20231129173312.31008-1-vadfed@meta.com> Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-GUID: 7KgrupVWIWvNVetQ8u3YdiSqX8ntHEz1 X-Proofpoint-ORIG-GUID: 7KgrupVWIWvNVetQ8u3YdiSqX8ntHEz1 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-29_15,2023-11-29_01,2023-05-22_02 Implement skcipher crypto in BPF crypto framework. Signed-off-by: Vadim Fedorenko --- v6: - make skcipher implementation in separate patch --- kernel/bpf/Makefile | 3 ++ kernel/bpf/crypto_skcipher.c | 76 ++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 kernel/bpf/crypto_skcipher.c diff --git a/kernel/bpf/Makefile b/kernel/bpf/Makefile index bcde762bb2c2..f4827bb72bee 100644 --- a/kernel/bpf/Makefile +++ b/kernel/bpf/Makefile @@ -43,6 +43,9 @@ obj-${CONFIG_BPF_LSM} += bpf_lsm.o endif ifeq ($(CONFIG_CRYPTO),y) obj-$(CONFIG_BPF_SYSCALL) += crypto.o +ifeq ($(CONFIG_CRYPTO_SKCIPHER),y) +obj-$(CONFIG_BPF_SYSCALL) += crypto_skcipher.o +endif endif obj-$(CONFIG_BPF_PRELOAD) += preload/ diff --git a/kernel/bpf/crypto_skcipher.c b/kernel/bpf/crypto_skcipher.c new file mode 100644 index 000000000000..d036eb64c1e2 --- /dev/null +++ b/kernel/bpf/crypto_skcipher.c @@ -0,0 +1,76 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright (c) 2023 Meta, Inc */ +#include +#include +#include +#include + +static void *bpf_crypto_lskcipher_alloc_tfm(const char *algo) +{ + return crypto_alloc_lskcipher(algo, 0, 0); +} + +static void bpf_crypto_lskcipher_free_tfm(void *tfm) +{ + crypto_free_lskcipher(tfm); +} + +static int bpf_crypto_lskcipher_has_algo(const char *algo) +{ + return crypto_has_skcipher(algo, CRYPTO_ALG_TYPE_LSKCIPHER, CRYPTO_ALG_TYPE_MASK); +} + +static int bpf_crypto_lskcipher_setkey(void *tfm, const u8 *key, unsigned int keylen) +{ + return crypto_lskcipher_setkey(tfm, key, keylen); +} + +static u32 bpf_crypto_lskcipher_get_flags(void *tfm) +{ + return crypto_lskcipher_get_flags(tfm); +} + +static unsigned int bpf_crypto_lskcipher_ivsize(void *tfm) +{ + return crypto_lskcipher_ivsize(tfm); +} + +static int bpf_crypto_lskcipher_encrypt(void *tfm, const u8 *src, u8 *dst, + unsigned int len, u8 *iv) +{ + return crypto_lskcipher_encrypt(tfm, src, dst, len, iv); +} + +static int bpf_crypto_lskcipher_decrypt(void *tfm, const u8 *src, u8 *dst, + unsigned int len, u8 *iv) +{ + return crypto_lskcipher_decrypt(tfm, src, dst, len, iv); +} + +static const struct bpf_crypto_type bpf_crypto_lskcipher_type = { + .alloc_tfm = bpf_crypto_lskcipher_alloc_tfm, + .free_tfm = bpf_crypto_lskcipher_free_tfm, + .has_algo = bpf_crypto_lskcipher_has_algo, + .setkey = bpf_crypto_lskcipher_setkey, + .encrypt = bpf_crypto_lskcipher_encrypt, + .decrypt = bpf_crypto_lskcipher_decrypt, + .ivsize = bpf_crypto_lskcipher_ivsize, + .get_flags = bpf_crypto_lskcipher_get_flags, + .owner = THIS_MODULE, + .name = "skcipher", +}; + +static int __init bpf_crypto_skcipher_init(void) +{ + return bpf_crypto_register_type(&bpf_crypto_lskcipher_type); +} + +static void __exit bpf_crypto_skcipher_exit(void) +{ + int err = bpf_crypto_unregister_type(&bpf_crypto_lskcipher_type); + WARN_ON_ONCE(err); +} + +module_init(bpf_crypto_skcipher_init); +module_exit(bpf_crypto_skcipher_exit); +MODULE_LICENSE("GPL"); -- 2.39.3