From patchwork Thu Aug 22 11:01:43 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chun-Yi Lee X-Patchwork-Id: 2848208 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A7618BF546 for ; Thu, 22 Aug 2013 11:09:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7B4E62061E for ; Thu, 22 Aug 2013 11:09:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C0EB620622 for ; Thu, 22 Aug 2013 11:09:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753492Ab3HVLD4 (ORCPT ); Thu, 22 Aug 2013 07:03:56 -0400 Received: from mail-pa0-f47.google.com ([209.85.220.47]:60155 "EHLO mail-pa0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752918Ab3HVLDx (ORCPT ); Thu, 22 Aug 2013 07:03:53 -0400 Received: by mail-pa0-f47.google.com with SMTP id kl13so2055977pab.6 for ; Thu, 22 Aug 2013 04:03:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=cprvWSRlOtZFZoIPxKfgu6XoOxYxegO7EW8+KZG3/kQ=; b=l19YikOmazTZB8p7bgg678W2+2XXGPMyHmZ9cpLnNuC0oOgkJmFtc4Y5OoRim5swX5 ORiEJDQKnJBJPNxUeckWXd2D02aS4DYszf5RXlnoogc9Drt9RtkHPit2jm07YIi87AbS XsrH4AH9AC2EdPRaNyoBl1ZiEuQ62VYG3NId9bi/79CE+S6YliCTG3L2qIagXiMGI8A8 HNq1oFI0Vq26LG0CPJs0nrEIGPvkjeUokGQ2UoWryP6EFruPSEnIafzDQWugwIECxPwr XcemMqNHCF15byfr1G9yKBYIrU59WDPMyK6mq2L2iMdr1ACJmPHC6+qQdB6QpGClVzax raHA== X-Received: by 10.66.253.4 with SMTP id zw4mr4844152pac.119.1377169433113; Thu, 22 Aug 2013 04:03:53 -0700 (PDT) Received: from localhost.localdomain ([130.57.30.250]) by mx.google.com with ESMTPSA id ht5sm14182603pbb.29.1969.12.31.16.00.00 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 22 Aug 2013 04:03:52 -0700 (PDT) From: "Lee, Chun-Yi" To: linux-kernel@vger.kernel.org Cc: linux-security-module@vger.kernel.org, linux-efi@vger.kernel.org, linux-pm@vger.kernel.org, linux-crypto@vger.kernel.org, opensuse-kernel@opensuse.org, David Howells , "Rafael J. Wysocki" , Matthew Garrett , Len Brown , Pavel Machek , Josh Boyer , Vojtech Pavlik , Matt Fleming , James Bottomley , Greg KH , JKosina@suse.com, Rusty Russell , Herbert Xu , "David S. Miller" , "H. Peter Anvin" , Michal Marek , Gary Lin , Vivek Goyal , "Lee, Chun-Yi" Subject: [PATCH 04/18] asymmetric keys: implement OS2IP in rsa Date: Thu, 22 Aug 2013 19:01:43 +0800 Message-Id: <1377169317-5959-5-git-send-email-jlee@suse.com> X-Mailer: git-send-email 1.6.0.2 In-Reply-To: <1377169317-5959-1-git-send-email-jlee@suse.com> References: <1377169317-5959-1-git-send-email-jlee@suse.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Implement Octet String to Integer conversion [RFC3447 sec 4.2] in rsa.c. It's the second step of signature generation operation. This patch is temporary set non-RSASP1 message to pks->S for debugging. Reviewed-by: Jiri Kosina Signed-off-by: Lee, Chun-Yi --- crypto/asymmetric_keys/rsa.c | 29 ++++++++++++++++++++++++----- 1 files changed, 24 insertions(+), 5 deletions(-) diff --git a/crypto/asymmetric_keys/rsa.c b/crypto/asymmetric_keys/rsa.c index c26ae77..0862018 100644 --- a/crypto/asymmetric_keys/rsa.c +++ b/crypto/asymmetric_keys/rsa.c @@ -168,6 +168,20 @@ static int RSA_I2OSP(MPI x, size_t xLen, u8 **_X) } /* + * Octet String to Integer conversion [RFC3447 sec 4.2] + */ +static int RSA_OS2IP(u8 *X, size_t XLen, MPI *_x) +{ + MPI x; + + x = mpi_alloc((XLen + BYTES_PER_MPI_LIMB - 1) / BYTES_PER_MPI_LIMB); + mpi_set_buffer(x, X, XLen, 0); + + *_x = x; + return 0; +} + +/* * EMSA_PKCS1-v1_5-ENCODE [RFC3447 sec 9.2] * @M: message to be signed, and octet string * @emLen: intended length in octets of the encoded message @@ -412,6 +426,9 @@ static struct public_key_signature *RSA_generate_signature( { struct public_key_signature *pks; u8 *EM = NULL; + MPI m = NULL; + MPI s = NULL; + unsigned X_size; size_t emLen; int ret; @@ -431,14 +448,16 @@ static struct public_key_signature *RSA_generate_signature( if (ret < 0) goto error_v1_5_encode; - /* TODO 2): m = OS2IP (EM) */ + /* 2): m = OS2IP (EM) */ + ret = RSA_OS2IP(EM, emLen, &m); + if (ret < 0) + goto error_v1_5_encode; /* TODO 3): s = RSASP1 (K, m) */ + s = m; - /* TODO 4): S = I2OSP (s, k) */ - - /* TODO: signature S to a u8* S or set to sig->rsa.s? */ - pks->S = EM; /* TODO: temporary set S to EM */ + /* 4): S = I2OSP (s, k) */ + _RSA_I2OSP(s, &X_size, &pks->S); return pks;