From patchwork Tue Jun 5 13:49:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 10448343 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 8BD5860234 for ; Tue, 5 Jun 2018 13:50:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7C62D294A6 for ; Tue, 5 Jun 2018 13:50:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7159F294BE; Tue, 5 Jun 2018 13:50:46 +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 1A2CA294A6 for ; Tue, 5 Jun 2018 13:50:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751750AbeFENup (ORCPT ); Tue, 5 Jun 2018 09:50:45 -0400 Received: from mail-lf0-f68.google.com ([209.85.215.68]:33386 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751948AbeFENuo (ORCPT ); Tue, 5 Jun 2018 09:50:44 -0400 Received: by mail-lf0-f68.google.com with SMTP id y20-v6so3743624lfy.0 for ; Tue, 05 Jun 2018 06:50:44 -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=Q2W74LtUy6bEDliP9nAz4pPZgsJ1pQcETLnCm5qkJA4=; b=R2boDiWvUyB5VDzSQkPt8c1ndBIibwB41U5sT6SFJ3FMkFmJs3O+Id2nuB3cloAWSt yUauFSXENpTZDfzHukZkpXRjwi2Lsp+KeqzJxKq4k1l4IeRh1sv5cmA/s1Trfyl44jSU +c7v/P+bL72soB6UdHmE/rqQUD2Uk3N2/dZok= 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=Q2W74LtUy6bEDliP9nAz4pPZgsJ1pQcETLnCm5qkJA4=; b=rbGpjf3UTrxZCCyJ6otFI7Q4nlzppNlFyFsu3CYqN8G4ROQIaDypAli2t77/RRtJ9b 2mvNgMQfSW2RxMhJj1xJSW1umw1epqi2Ds9jU69qHS1zQHqrukuqR2FigwuwKgImwuWu l2QhVWOLOIz8W6tOeyYVf6VUSo1sRqwPIwnusszOuPh17W52PRjqoUp5CzLgp8GuJ9b4 cBnEruutPcdKfTf/AVF+BmaIFMTNIWoGgKphgtWTNbJCB26UkqJhdE5buuIQ2cDuVHAf CjBJJCAd9zNMl8Wu/42mzt6zckfXIBEC3O+Nuj198i1IcXlipWVU3YA413NG341SJjfX VKvg== X-Gm-Message-State: APt69E0I8absggwqw2CNz6NIzZ2PhFXkOSMfuQo+4/7Y8Xe6+J7Hz4xn w3PFMDfyuGfxQQRUz10xkD+SeOkd4kY= X-Google-Smtp-Source: ADUXVKJiFQZ/sDwdw4gtC0aaOgEHx9Q1qC304Om2x0VaClEMm8CP7El4nVrPkbMoSPqS5zXGpyNhlQ== X-Received: by 2002:a19:b54d:: with SMTP id e74-v6mr1551313lff.118.1528206643184; Tue, 05 Jun 2018 06:50:43 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id x72-v6sm5201092lfi.52.2018.06.05.06.50.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jun 2018 06:50:41 -0700 (PDT) From: Linus Walleij To: linux-crypto@vger.kernel.org, Herbert Xu , Tudor Ambarus Cc: Linus Walleij Subject: [PATCH 9/9] crypto: atmel-ecc: Break out lock check helper Date: Tue, 5 Jun 2018 15:49:50 +0200 Message-Id: <20180605134950.6605-9-linus.walleij@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180605134950.6605-1-linus.walleij@linaro.org> References: <20180605134950.6605-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 --- 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 2b6c8bb7bd1c..d15cc77ab739 100644 --- a/drivers/crypto/atmel-ecc.c +++ b/drivers/crypto/atmel-ecc.c @@ -668,7 +668,9 @@ static int atmel_ecc_get_serial(struct i2c_client *client) return 0; } -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; @@ -682,21 +684,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; }