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: 140442 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2166072ljj; Thu, 28 Jun 2018 06:08:02 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcdRNfruaBSjTAMHYtdnrfVODdvnM10lv/alIIavKhb6n1YWJmDBNH4En7G2Gbwuhcfy1o+ X-Received: by 2002:a65:4a49:: with SMTP id a9-v6mr7078153pgu.267.1530191282743; Thu, 28 Jun 2018 06:08:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530191282; cv=none; d=google.com; s=arc-20160816; b=lvZDek9i/c5L/EklKsL4QqgdNw49bwRxDQshZKwtWFHExFiYa3qnQITLeMbVPAXpvx cqWL30glaFX8E0crl+haqOIGm/LBzwUEZWgJi1ERPkKNB1GQWkS1IRcFiUH9jO+fxabO B++qxkyfKEAyq9br8szg3NAte6nkVz8j5Vgf5TJXdEFYG+sVHy96PqHrgKx4gRVsuShZ JO1Ps4oqqZBodTRhiq2dC/NsuRswbMh0NOoDDKqZE9Pf8V8ZvpCGT2uMq5nRpFdcDPHj xyOoZ6jiQHTFXLqthvSM2+XqqkNxE/qLEOnmQdn1vzGR1yqDPCII6e6gzcZJ2i2iKHNO yCow== 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=/znJ1zhTl++d3m411IYML5IV0OCEtg98TAu77s/1Qmk=; b=pdgqZ98TUpnbm7n2Hi1crky+RSnSB5kf5BublA+FJoBb4y/6BxnN3mmffOFb69BiXb P48/MgHzM99XxFWpJRGqlk0eSwnI4M8j7U1hYzYYMErYCyFghgO3t/g5zXNJfTYHUmvO NwKXZ9LUKzRyhHTfGxI+zawvLOa7fdCcMmy/h/13AOJ+u2j7Jbxrcaiw+P4bR+LHuDEt M1Q8/hZ6CcAuiTyPoX2x7x9haTTQyVF8F1vuWbLOaTS2oXfHEiDcwhmd+shgrd2f/SAy IFFiqXzhxx4YL44O33m3wTOg3jeIufnq1m9K/qn38YfyYfS+P+LAcIdlIzuDNPYodwc6 TvaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=h3NLwFUg; 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 f9-v6si6556676plo.206.2018.06.28.06.08.02; Thu, 28 Jun 2018 06:08:02 -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=h3NLwFUg; 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 S965723AbeF1NH6 (ORCPT + 1 other); 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-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 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(-) -- 2.17.0 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; }