From patchwork Mon Dec 12 20:48:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Dryomov X-Patchwork-Id: 9471303 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BE9CE607D3 for ; Mon, 12 Dec 2016 20:50:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B4B7828518 for ; Mon, 12 Dec 2016 20:50:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A9CB72851B; Mon, 12 Dec 2016 20:50:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 48FDC28518 for ; Mon, 12 Dec 2016 20:50:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932502AbcLLUuL (ORCPT ); Mon, 12 Dec 2016 15:50:11 -0500 Received: from mail-wj0-f195.google.com ([209.85.210.195]:35996 "EHLO mail-wj0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932478AbcLLUuJ (ORCPT ); Mon, 12 Dec 2016 15:50:09 -0500 Received: by mail-wj0-f195.google.com with SMTP id j10so13588164wjb.3 for ; Mon, 12 Dec 2016 12:50:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:in-reply-to:references; bh=AXd1ZODvOg+M2rl4aC+arTyiZ6NlP2jaWHf6ySt5AG4=; b=YQE3e+O9kJVO4bOFgeyZ8dspJ3bRU0e7Sxv2Q0zWVPJenAbB3li4bCuaSrmwAyJ/V5 wquPJ3vbyfmfDGM5R79VkqnL7cpiSb2gSNfc2AL03PyJS28wP2K6GYpqWHTniXQnmMnJ XYI04eUl0OHuPzlKqvhMqI7xwAujzg2vdKVoGVIoDq2Onj32c1HvTpveb4Qjzns2C/68 NQIA3nipfjnmXjy+RmZ4MDJ275oruy8J2e8UA2gp5Szawu3zTGk01qNyei4JDj7P0bBK 4CTaeCKJ/3U/eEOKo+dMEgDrKrJtLe4BILLGITgJzh4a/EVVoMcGpElTw9h2cSfZz4Mn 2hIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=AXd1ZODvOg+M2rl4aC+arTyiZ6NlP2jaWHf6ySt5AG4=; b=d3sfUOsyGj9giqFToNiZvU0ir64iVBLPvxBFEt5GdNAUOO4DV0ec/feMrpAeOTdSsQ yDwEHJ57fUV5w8ow0IXJc0tdVl+1tyKuy5WmIfXKsbZNQvU0o/rRN6SD4PiSKhV+ujb6 Riy8psAPzZvGerISlpD/bTcIBLkLoCYpG12ogMwIFW1YTCDMTfGGCCvBIZYaUOXaJK8q nt4jag7C+vmAIVI3NJnBBLRTvR8F8nJwo6V5E3ZCxrKN74MqFr6FRRs2GjGtJCRPR39b xwO/MiWqD6rzBwFEBVLRJtYsvEvz4nxocFCflDXU9mjRp6YmRTW1RpfrNFIQEvQFffQt nrog== X-Gm-Message-State: AKaTC00T49Agt36NSBjjnIWfYriob66xgbSHomdckCJfhQubkkGMM66DMYjHJRKhaGKz9Q== X-Received: by 10.194.20.68 with SMTP id l4mr82003047wje.49.1481575807650; Mon, 12 Dec 2016 12:50:07 -0800 (PST) Received: from dhcp-1-105.brq.redhat.com ([213.175.37.12]) by smtp.gmail.com with ESMTPSA id 135sm37201887wmh.14.2016.12.12.12.50.06 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Dec 2016 12:50:07 -0800 (PST) From: Ilya Dryomov To: ceph-devel@vger.kernel.org Subject: [PATCH 06/15] libceph: tweak calcu_signature() a little Date: Mon, 12 Dec 2016 21:48:51 +0100 Message-Id: <1481575740-1834-7-git-send-email-idryomov@gmail.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1481575740-1834-1-git-send-email-idryomov@gmail.com> References: <1481575740-1834-1-git-send-email-idryomov@gmail.com> Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP - replace an ad-hoc array with a struct - rename to calc_signature() for consistency Signed-off-by: Ilya Dryomov --- net/ceph/auth_x.c | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/net/ceph/auth_x.c b/net/ceph/auth_x.c index ef1423294517..78c1675b0df7 100644 --- a/net/ceph/auth_x.c +++ b/net/ceph/auth_x.c @@ -707,35 +707,48 @@ static void ceph_x_invalidate_authorizer(struct ceph_auth_client *ac, invalidate_ticket(ac, CEPH_ENTITY_TYPE_AUTH); } -static int calcu_signature(struct ceph_x_authorizer *au, - struct ceph_msg *msg, __le64 *sig) +static int calc_signature(struct ceph_x_authorizer *au, struct ceph_msg *msg, + __le64 *psig) { - int ret; char tmp_enc[40]; - __le32 tmp[5] = { - cpu_to_le32(16), msg->hdr.crc, msg->footer.front_crc, - msg->footer.middle_crc, msg->footer.data_crc, - }; - ret = ceph_x_encrypt(&au->session_key, &tmp, sizeof(tmp), + struct { + __le32 len; + __le32 header_crc; + __le32 front_crc; + __le32 middle_crc; + __le32 data_crc; + } __packed sigblock; + int ret; + + sigblock.len = cpu_to_le32(4*sizeof(u32)); + sigblock.header_crc = msg->hdr.crc; + sigblock.front_crc = msg->footer.front_crc; + sigblock.middle_crc = msg->footer.middle_crc; + sigblock.data_crc = msg->footer.data_crc; + ret = ceph_x_encrypt(&au->session_key, &sigblock, sizeof(sigblock), tmp_enc, sizeof(tmp_enc)); if (ret < 0) return ret; - *sig = *(__le64*)(tmp_enc + 4); + + *psig = *(__le64 *)(tmp_enc + sizeof(u32)); return 0; } static int ceph_x_sign_message(struct ceph_auth_handshake *auth, struct ceph_msg *msg) { + __le64 sig; int ret; if (ceph_test_opt(from_msgr(msg->con->msgr), NOMSGSIGN)) return 0; - ret = calcu_signature((struct ceph_x_authorizer *)auth->authorizer, - msg, &msg->footer.sig); - if (ret < 0) + ret = calc_signature((struct ceph_x_authorizer *)auth->authorizer, + msg, &sig); + if (ret) return ret; + + msg->footer.sig = sig; msg->footer.flags |= CEPH_MSG_FOOTER_SIGNED; return 0; } @@ -749,9 +762,9 @@ static int ceph_x_check_message_signature(struct ceph_auth_handshake *auth, if (ceph_test_opt(from_msgr(msg->con->msgr), NOMSGSIGN)) return 0; - ret = calcu_signature((struct ceph_x_authorizer *)auth->authorizer, - msg, &sig_check); - if (ret < 0) + ret = calc_signature((struct ceph_x_authorizer *)auth->authorizer, + msg, &sig_check); + if (ret) return ret; if (sig_check == msg->footer.sig) return 0;