Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp822261pxb; Thu, 21 Jan 2021 23:17:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJz5OhBgfe9llij0H21I/8vUwcUDqO81bu3vuGFZCFX0q6l4335I+MC/cwi5i5GvqmYuChcJ X-Received: by 2002:a05:6402:3088:: with SMTP id de8mr853876edb.221.1611299828867; Thu, 21 Jan 2021 23:17:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611299828; cv=none; d=google.com; s=arc-20160816; b=tjVVnIw5+qkSKkZrm0E4rqAqHpyrmAvahxSLMY0ZdHQphpVcxZwiq+SosArilGqe5z Z/tRPDWXYBMR8wSeJyyYJ+yLM6JCz5PwtXc/UIBra3EVHb4iaUEQBg/W6JTA+C7onIZ/ St+iznyHduOAhPQkWAirqQmOaFGiDolHaPxSDXnetpayclnJacJDyfTzvWTx4Semi6gD YdML1aAI5y6akdZ0nJYrRZ25CeYoYeOAjdFC87SG+83eluT7ejvLjTQKOFaYSilbylNI N5C7wNpXwpkmz0FEPIRlug3v3FqYnAJHUsbZCgqBg9LTYNPWgbF9nq0rhPMo2+B0U+g4 P68A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=qKq/F62G033RcoX3udC4VQ3pbTaFmGpQ+uAmVC7o46w=; b=jKUToeDh8HQGMKdxzT7hClGneWTt6xev4RjSausQjjyNBig+3Ec+Xysw5/dn0l8dg1 H4+oy7iEvpA0akjW2zCN3D6145Xs+rXDp6JbPj3Gpna5nLeqytWuwa+HjTnudkwcFuWo 3gfSZyr2xB8RjzRgHWJaxaDf00EFgzUACugpMRUmcYl+WKQRmBLgskGFRujN9hZuY/ic oIRLK200rKwNjN7dPNJrYudKMndC2sUM+rhlUR3LLupqvBUZ9nJRsOYAZZTcfIcPUKRo B2Or3VQMJ1CcGiL/fKi/5stAT9q47nJFKVD/iSsCZS2h2rrueL61O01US5/4gEkwcmO1 9t9g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p8si2692913ejb.474.2021.01.21.23.16.45; Thu, 21 Jan 2021 23:17:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726793AbhAVHOn (ORCPT + 99 others); Fri, 22 Jan 2021 02:14:43 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:11479 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726724AbhAVHNF (ORCPT ); Fri, 22 Jan 2021 02:13:05 -0500 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4DMVmH3DW0zjC3L; Fri, 22 Jan 2021 15:11:11 +0800 (CST) Received: from localhost.localdomain (10.67.165.24) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.498.0; Fri, 22 Jan 2021 15:12:10 +0800 From: Meng Yu To: , CC: , , , , Subject: [PATCH v7 5/7] crypto: add curve 25519 and expose them Date: Fri, 22 Jan 2021 15:09:53 +0800 Message-ID: <1611299395-675-6-git-send-email-yumeng18@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1611299395-675-1-git-send-email-yumeng18@huawei.com> References: <1611299395-675-1-git-send-email-yumeng18@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.165.24] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 1. Add curve 25519 parameters; 2. Add curve25519 function 'ecc_get_curve25519_param', to be exposed to everyone in kernel tree. Signed-off-by: Meng Yu Reviewed-by: Zaibo Xu --- crypto/ecc.c | 7 +++++++ crypto/ecc_curve_defs.h | 17 +++++++++++++++++ include/crypto/ecc_curve.h | 7 +++++++ 3 files changed, 31 insertions(+) diff --git a/crypto/ecc.c b/crypto/ecc.c index cfa1dc3..025b5e6e 100644 --- a/crypto/ecc.c +++ b/crypto/ecc.c @@ -53,6 +53,13 @@ const struct ecc_curve *ecc_get_curve_by_id(unsigned int curve_id) } EXPORT_SYMBOL(ecc_get_curve_by_id); +/* Returns curv25519 curve param */ +const struct ecc_curve *ecc_get_curve25519(void) +{ + return &ecc_25519; +} +EXPORT_SYMBOL(ecc_get_curve25519); + static inline const struct ecc_curve *ecc_get_curve(unsigned int curve_id) { switch (curve_id) { diff --git a/crypto/ecc_curve_defs.h b/crypto/ecc_curve_defs.h index b81e580..91b3d4b 100644 --- a/crypto/ecc_curve_defs.h +++ b/crypto/ecc_curve_defs.h @@ -160,4 +160,21 @@ static const struct ecc_curve ecc_curve_list[] = { } }; +/* curve25519 */ +static u64 curve25519_g_x[] = { 0x0000000000000009, 0x0000000000000000, + 0x0000000000000000, 0x0000000000000000 }; +static u64 curve25519_p[] = { 0xffffffffffffffed, 0xffffffffffffffff, + 0xffffffffffffffff, 0x7fffffffffffffff }; +static u64 curve25519_a[] = { 0x000000000001DB41, 0x0000000000000000, + 0x0000000000000000, 0x0000000000000000 }; +static const struct ecc_curve ecc_25519 = { + .name = "curve25519", + .g = { + .x = curve25519_g_x, + .ndigits = 4, + }, + .p = curve25519_p, + .a = curve25519_a, +}; + #endif diff --git a/include/crypto/ecc_curve.h b/include/crypto/ecc_curve.h index a3adf1e..2d22647 100644 --- a/include/crypto/ecc_curve.h +++ b/include/crypto/ecc_curve.h @@ -50,4 +50,11 @@ struct ecc_curve { */ const struct ecc_curve *ecc_get_curve_by_id(unsigned int curve_id); +/** + * ecc_get_curve25519() - get curve25519 curve; + * + * Returns curve25519 + */ +const struct ecc_curve *ecc_get_curve25519(void); + #endif \ No newline at end of file -- 2.8.1