From patchwork Thu Jun 28 13:07:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 10493841 X-Patchwork-Delegate: herbert@gondor.apana.org.au 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 1416660230 for ; Thu, 28 Jun 2018 13:08:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 001212A004 for ; Thu, 28 Jun 2018 13:08:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E6FB72A000; Thu, 28 Jun 2018 13:08:02 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 82D362A000 for ; Thu, 28 Jun 2018 13:08:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965723AbeF1NH6 (ORCPT ); Thu, 28 Jun 2018 09:07:58 -0400 Received: from mail-lf0-f68.google.com ([209.85.215.68]:45179 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965616AbeF1NHz (ORCPT ); Thu, 28 Jun 2018 09:07:55 -0400 Received: by mail-lf0-f68.google.com with SMTP id m13-v6so4146110lfb.12 for ; Thu, 28 Jun 2018 06:07:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=/znJ1zhTl++d3m411IYML5IV0OCEtg98TAu77s/1Qmk=; b=h3NLwFUg9b9cnLltKFS3ak6mq60aJI4A5zgK/ak3SLF57+VAtqo+R2KbZWkriWFOEK 59ZKTO26SaEl6sqlO3C57aikynuoyjfcE5KVQAhdThUNBvoYahz/UBXDoj4RBhtxbPw6 9t4aGG/c5A3CKgwpPblsmLSWnoJyKdGvtDrJk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=/znJ1zhTl++d3m411IYML5IV0OCEtg98TAu77s/1Qmk=; b=bE3aqjk919hbKSUutEw8dD9pgnWKczHXjzT9NEO+iqBzQLl2AV1Yb5oEmfuvKIPrsI Oto/H/PYfwDtwgmaNd/ruRwnoCQIOhH7DaonDg+CSTSnREaMHAQrToGKwnb25m8Ydr6+ +eZT3zX2aGVulVjQC3c3uWuxFKwbNoJ/3k0uJUQ1c8mTPV6rZuKS4xsND6MbnKonC4vm H9KuNCJynbjM2Wudha01SohkWJ0cRJLos9BUMh1KNSgAv+kM8iNVlGSbGPYEMLJ6SgfP udPJ0oZKVp8BGbJPxLPHIeWDgzcoWdsMai1Op0rMcFiLY2pHQ7Qbu6NFRh3UtFKLnKOL heFg== X-Gm-Message-State: APt69E0tNdzwnRQG6uD+axFiet2Nf4i5ZJU3UQFkYgzDCd3xiv+Y9+wE 4VeypH5v3jM3pTEcR+rGlh6LXByO2oM= X-Google-Smtp-Source: AAOMgpc5O4jmrdgrUUBD75ujKBJzR7XkiPzerqyGjQpfcSiWrZSDm8zs0+qwLbS90gTlREgpoWQn1Q== X-Received: by 2002:a19:6a0f:: with SMTP id u15-v6mr7321445lfu.81.1530191274170; Thu, 28 Jun 2018 06:07:54 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id d24-v6sm1314649lfl.53.2018.06.28.06.07.52 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Jun 2018 06:07:52 -0700 (PDT) From: Linus Walleij To: linux-crypto@vger.kernel.org, Herbert Xu , Tudor Ambarus Cc: Linus Walleij Subject: [PATCH 9/9 v2] crypto: atmel-ecc: Break out lock check helper Date: Thu, 28 Jun 2018 15:07:29 +0200 Message-Id: <20180628130729.17589-9-linus.walleij@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180628130729.17589-1-linus.walleij@linaro.org> References: <20180628130729.17589-1-linus.walleij@linaro.org> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This breaks out a lock status checker to be used with further refactorings. Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Rebased --- drivers/crypto/atmel-ecc.c | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/drivers/crypto/atmel-ecc.c b/drivers/crypto/atmel-ecc.c index 0dfea6eadc56..549ec7190287 100644 --- a/drivers/crypto/atmel-ecc.c +++ b/drivers/crypto/atmel-ecc.c @@ -666,7 +666,9 @@ static int atmel_ecc_get_serial(struct i2c_client *client) return ret; } -static int device_sanity_check(struct i2c_client *client) +static int atmel_ecc_get_lock_status(struct i2c_client *client, + bool *config_is_locked, + bool *otp_data_is_locked) { struct atmel_ecc_cmd *cmd; int ret; @@ -680,21 +682,49 @@ static int device_sanity_check(struct i2c_client *client) ret = atmel_ecc_send_receive(client, cmd); if (ret) { dev_err(&client->dev, - "failed to send ECC init command\n"); + "failed to send config read command\n"); goto free_cmd; } + /* According to datasheet anything else than 0x55 means "locked" */ + if (cmd->data[RSP_DATA_IDX+3] == 0x55) + *config_is_locked = false; + else + *config_is_locked = true; + + if (cmd->data[RSP_DATA_IDX+2] == 0x55) + *otp_data_is_locked = false; + else + *otp_data_is_locked = true; + +free_cmd: + kfree(cmd); + return ret; +} + +static int device_sanity_check(struct i2c_client *client) +{ + struct atmel_ecc_cmd *cmd; + bool config_locked; + bool otp_data_locked; + int ret; + /* * It is vital that the Configuration, Data and OTP zones be locked * prior to release into the field of the system containing the device. * Failure to lock these zones may permit modification of any secret * keys and may lead to other security problems. */ - if (cmd->data[RSP_DATA_IDX+3] == 0x55) { + ret = atmel_ecc_get_lock_status(client, &config_locked, + &otp_data_locked); + if (ret) + return ret; + + if (!config_locked) { dev_err(&client->dev, "configuration zone is unlocked\n"); ret = -ENOTSUPP; } - if (cmd->data[RSP_DATA_IDX+2] == 0x55) { + if (!otp_data_locked) { dev_err(&client->dev, "data and OTP zones are unlocked\n"); ret = -ENOTSUPP; }