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: 137742 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp986247lji; Tue, 5 Jun 2018 06:50:46 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKatFz64dh/S36+oNNiaq9lC0Pw+CxROUGhZljStoLzn1VISTDAe5poF7dJ3R0uylHMDNFC X-Received: by 2002:a17:902:b784:: with SMTP id e4-v6mr16301703pls.264.1528206646303; Tue, 05 Jun 2018 06:50:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528206646; cv=none; d=google.com; s=arc-20160816; b=Bkqu1lq+3bFzUXyXqvPZnWjVq6RBN0ibXkwVClMeU7AL44nKlgeNpBCNg1I5fX0WFU 3gH/uLsyaT9Wy7CEh1zSqV7lZNkoJnBndcKzzycll07rVUvCB+Wf37pycSCr1NUjyNH2 eCCc3oD28+XbfWRKeMGBZQVWtif60Z977Uh39w3sZ9bWZojNx2xls5RT7/CCUVVVPZ8/ DlBI/XAsSBWRVf/V7+xEz7lDyBECJgAJ/QnHfc+y78ZDkiR74MT+md7anIZdgPWcygmv djd9mR+qgUcbsMU5NL2i9nKMyrLPgNh3AM8HpwNziX7rKJshyvpDdRxh6vedCa/xCGr4 8JCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=Q2W74LtUy6bEDliP9nAz4pPZgsJ1pQcETLnCm5qkJA4=; b=cw4/0rZ5Mc6uTplEVwqySQ32UAgyCgXgJkwEdl3p10cq110K0ThxbfuzAK6svydqIN 0mtnhwABBv+8yyygAhRyrXkryY/bv1cuEIFOgekkRb3UN/uSkN21Dtl1Yp3x0UYJ8NS2 ifztVvfIw/UnnimV+MUpfliPVbFP9RqiHeSPH/Lf+pXwskj+5vXHkn7MhdraoI8AQYPG 0qQ1l4ZMy9ZUIkZxt70aLLkbL/VE4pKCQycHEP+5xdJpeXHLaJNbz1dqiF+gR4pxR/Ug u/f8ATdcH+er8aViXAei3vvsW0yk+KieH2793X42jN9WxdrmLqd2LsEwzu9PVIAO2sLj ANHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=R2boDiWv; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j78-v6si24186154pfe.187.2018.06.05.06.50.46; Tue, 05 Jun 2018 06:50:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=R2boDiWv; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751750AbeFENup (ORCPT + 1 other); 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-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 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(-) -- 2.17.0 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; }