Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp1029615imj; Sat, 9 Feb 2019 13:44:21 -0800 (PST) X-Google-Smtp-Source: AHgI3IZkkHqUCYeZk06SAjoOHsLQTEB5LHezpQb7lxnji/BWIIMgVZStp+MHyUk8D5nLwV/VpOd3 X-Received: by 2002:a63:440d:: with SMTP id r13mr336224pga.5.1549748661808; Sat, 09 Feb 2019 13:44:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549748661; cv=none; d=google.com; s=arc-20160816; b=erLwRRi6KxI89gDBDHmJJ6BQ5HVUKmRGV0q2bHKPL1r20Ne0cF7UsRlL24r9NkuJ0V yWUr5UO1HrJlU2wk7OS5zZncDymLNDJ2BPvqSjI1na9QfC01fbUHWzhFgbhsDkJnh9h1 ZqwpnUTMiXVp6sP9FWY/QM8OvXBL99QXEjyG5DqV9mcpYg2IoqBi5S5CgiFROFDhcgz7 FcbO47MPb/GsrcU7H/pG1IN0qoDJxsxlIen8hgPsNPjF8IQbPiie3CRVkPmR3qUR9Vfb 37zKgOxv7a3o1I2oRrlhbFEUakDIlFsykzBOuVu3S3KQhdepuBhTXpmlxviiNCE8hgfJ b/ag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:mail-followup-to :message-id:subject:to:from:date; bh=YFOsC04J+Pq8z500jo3OCnawmWtMCqgVZokNZYlSf/s=; b=LWezO3kMEdya2eZ1+OQDWkWmcwZ2DJWt7X5IE5h8091qqdML95d7u/I9742QdYZwgm KFrLCLsTTzsMYFhqIMEva49Q6jR1ucaIEtocpwyhJVMPSs8Mvh3b0aTLmNH0jychkYnW M3oQCBEzJfD/RhjYDxUJ5Pr3mrNqzoASw0YfmiyFM1IuCtoGP467laMoshHmxrVkLr6b u0f4vGLqIDpmN+dUA7tMx2nMHzNz1Ni7l8s85uuIwgFmeXtmRakL08GecVdIVRn9miLi QBlg85qwbB29bmoGDoY5gJjUWnzqwGgISAIQxeoUVWnB9bxYYByP5JD5iMJEwRwbKbUj 5R4w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u8si6378468plh.385.2019.02.09.13.44.05; Sat, 09 Feb 2019 13:44:21 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727068AbfBIVmp (ORCPT + 99 others); Sat, 9 Feb 2019 16:42:45 -0500 Received: from vmicros1.altlinux.org ([194.107.17.57]:39330 "EHLO vmicros1.altlinux.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726898AbfBIVmo (ORCPT ); Sat, 9 Feb 2019 16:42:44 -0500 Received: from imap.altlinux.org (imap.altlinux.org [194.107.17.38]) by vmicros1.altlinux.org (Postfix) with ESMTP id 05C3972CC53; Sun, 10 Feb 2019 00:42:41 +0300 (MSK) Received: from altlinux.org (sole.flsd.net [185.75.180.6]) by imap.altlinux.org (Postfix) with ESMTPSA id D6CEF4A4A14; Sun, 10 Feb 2019 00:42:40 +0300 (MSK) Date: Sun, 10 Feb 2019 00:42:40 +0300 From: Vitaly Chikunov To: David Howells , Herbert Xu , Mimi Zohar , Dmitry Kasatkin , linux-integrity@vger.kernel.org, keyrings@vger.kernel.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH 1/4] X.509: Parse public key parameters from x509 for akcipher Message-ID: <20190209214240.56gq7ivn3pw3bssf@altlinux.org> Mail-Followup-To: David Howells , Herbert Xu , Mimi Zohar , Dmitry Kasatkin , linux-integrity@vger.kernel.org, keyrings@vger.kernel.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org References: <20190106133608.820-1-vt@altlinux.org> <20190106133608.820-2-vt@altlinux.org> MIME-Version: 1.0 Content-Type: text/plain; charset=koi8-r Content-Disposition: inline In-Reply-To: <20190106133608.820-2-vt@altlinux.org> User-Agent: NeoMutt/20171215-106-ac61c7 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Jan 06, 2019 at 04:36:05PM +0300, Vitaly Chikunov wrote: > Some public key algorithms (like ECDSA) keep in parameters field > important data such as digest and curve OIDs (possibly more for > different ECDSA variants). Thus, just setting a public key (as > for RSA) is not enough. > > Introduce set_params() callback for akcipher which will be used to > pass DER encoded parameters array, with additional argument of > algorithm OID. > > This is done with the intent of adding support for EC-RDSA (ISO/IEC > 14888-3:2018, RFC 7091, and basically ECDSA variant) public keys (which > will be finally used in IMA subsystem). Thus, also oid_registry.h is > updated. > > Rationale: > > - For such keys just setting public key without parameters is > meaningless, so it would be possible to add parameters in > crypto_akcipher_set_pub_key (and .set_pub_key) calls. But, this will > needlessly change API for RSA akcipher. Also, additional callback > making it possible to pass parameters after > crypto_akcipher_set_priv_key (and .set_priv_key) in the future. > > - Algorithm OID is passed to be validated in .set_params callback, > otherwise, it could have the wrong value. > > - Particular algorithm OIDs are checked in x509_note_params, (because > this is called from AlgorithmIdentifier (ASN.1) parser, which is > called multiple times, as it's used multiple times in X.509 > certificate), to distinguish a public key call from a signature call. > > Signed-off-by: Vitaly Chikunov > --- > @@ -263,6 +274,11 @@ int public_key_verify_signature(const struct public_key *pkey, > if (pkey->key_is_private) > ret = crypto_akcipher_set_priv_key(tfm, > pkey->key, pkey->keylen); > else > ret = crypto_akcipher_set_pub_key(tfm, > pkey->key, pkey->keylen); > if (ret) > goto error_free_req; > + ret = crypto_akcipher_set_params(tfm, pkey->algo, pkey->params, > + pkey->paramlen); Nobody said anything if this is a good idea to call set_params after set_{pub,priv}_key and not before. When `struct crypto_akcipher' is allocated ctx data is never zeroed, thus either call will be the first to zero ctx, making these calls not swappable in the future. Also, algorithm parameters could be interpreted without knowing the key, but the key cannot be interpreted without knowing the parameters. > + if (ret) > + goto error_free_req; > + > ret = -ENOMEM; > outlen = crypto_akcipher_maxsize(tfm); > output = kmalloc(outlen, GFP_KERNEL);