From patchwork Thu Jun 28 13:07:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 140445 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2166571ljj; Thu, 28 Jun 2018 06:08:26 -0700 (PDT) X-Google-Smtp-Source: AAOMgpccVh5pA1fkI++dvryFRgGpXtDeT/QBDB38USFouswiLgFH8/c2j+BQeyULA6sb11sSAygQ X-Received: by 2002:a65:6411:: with SMTP id a17-v6mr5148249pgv.287.1530191306097; Thu, 28 Jun 2018 06:08:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530191306; cv=none; d=google.com; s=arc-20160816; b=V2ISB4mSKmvb0RaBqWaX7Pkk74WR1OHoZ1hYHdzVPQxUTJs/8xoTU5uko3S43adTe+ fxfdVCCQiiyNRIVF7USt3efJbNJDbCoz4L5g39S2EaMxlIMt2ZXT6o5zT1RP+jh+Wz8I 5aHLYpC9AKKJBAolsHfVN49kESOmF0AKO7MOszB1PAJIMtb1X8I/zR5z7hJSGzK3U1rc XPEAZwj3hRaBqkaHcZ7lPUkavbZrykRwBmQQOzCxmzXN49WQZ4yIKtlH1FNrgqhlkJbX vbjMwF/NSN5+F+pKkupAIi+ZB0a3Kfp+Srw7Z44sOXEUvacc/UEJzdWTgRf9RMeHccBF Q2Kw== 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=j7vnUMwkXU79GNOCdUCd+2LIZtCrXIjov+Vq8J0206g=; b=Nj2yjY4c76PPf+P0PWfRUOMaIBjw6ICUXAslDgYk+udD94jRexp827FSx/Ok7hXd9e OsaLED4wU0uDkvO9B6fQS+2Y5MRTjBzeov0tG+mpSm6yq75GPRJ97aKCJykkTbV1Lxv2 L0rRunMiJGRLQ3o/zyhFYwnMY25PwVr5A1K3PfurhXLPMLQDZG+qejgAgViLi1wX5lpk MZZ8BArtOwgGGnT03Vzucy03z2cMytejMY0kjunntFHZ7sVmn5Yx0WXlOTEvKHjX4WtU P8aCO9rGoU7m3l/zsRpZfhAGBsDqe48fgHkJc19EJ9AiW3XIaG+j15iCpf+Illr9w8le af6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kaYrVTpd; 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 p88-v6si6621399pfj.294.2018.06.28.06.08.25; Thu, 28 Jun 2018 06:08:26 -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=kaYrVTpd; 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 S965127AbeF1NIX (ORCPT + 1 other); Thu, 28 Jun 2018 09:08:23 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:41983 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934371AbeF1NHv (ORCPT ); Thu, 28 Jun 2018 09:07:51 -0400 Received: by mail-lj1-f195.google.com with SMTP id a17-v6so1345976ljd.8 for ; Thu, 28 Jun 2018 06:07:50 -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=j7vnUMwkXU79GNOCdUCd+2LIZtCrXIjov+Vq8J0206g=; b=kaYrVTpd3hSLzVmDIY0wNSrQtOHcPtxEyAY+EMwoV6y5KoHKHYvngNJwHUkuS8CReR A7yAJofqRfKKX5uyq/0iu0D8ofn7pVLqvCFJO9QzbUWd0aUf0fB0vKfnX1OYlgcyIMER f1pmwWyo8uq9I7jSMaIoU5UNDX3GSl0E59ySI= 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=j7vnUMwkXU79GNOCdUCd+2LIZtCrXIjov+Vq8J0206g=; b=iMAR0Ob+94VhHrqYdo2uaHHqlbzcQ2B8ljLqHeQCualOrbMB0EaMwICxJM1PqtK0WY DywaqiAeF7WWxX937Qbv7xuhDiHgt6rREYcO7Cm5glLWuVlWUiyUurMnQXXeq+Djr64r o330uqNx5n0yxHyYPU9GzOPeIQX3eXDiB1w6EE0Tw4+gSIiAg4iES7z9e9PlrdVXYANo vqZNbDD5tUfF3Iup81EvyyveERE4qlf1eUWyP8n1eRgXpqq02ossSo8PRWb1o74gpf5E FdE0r8fFQlyt/7KcBzQCz1H37fR5par3BsI7e2AvLk6wxZXCUgzYpBi1w7L71vCE+Vby 5IhA== X-Gm-Message-State: APt69E27tr4T70t8QJ+iAAizZhh7Yond32VK4rUwG7AqL/JaKg2YVfi4 lca0bAk6P78eU5ISAi/tMeqix70EhpI= X-Received: by 2002:a2e:86d5:: with SMTP id n21-v6mr3687615ljj.48.1530191269176; Thu, 28 Jun 2018 06:07:49 -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.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Jun 2018 06:07:47 -0700 (PDT) From: Linus Walleij To: linux-crypto@vger.kernel.org, Herbert Xu , Tudor Ambarus Cc: Linus Walleij Subject: [PATCH 7/9 v2] crypto: atmel-ecc: Print out serial number Date: Thu, 28 Jun 2018 15:07:27 +0200 Message-Id: <20180628130729.17589-7-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 reads out the serial number of the crypto chip and prints it, also toss this into the entropy pool as it is device-unique data. Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - kfree(cmd) was missed. Fix it with a goto construction. - Coding style fixes. --- drivers/crypto/atmel-ecc.c | 60 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) -- 2.17.0 diff --git a/drivers/crypto/atmel-ecc.c b/drivers/crypto/atmel-ecc.c index f3322fae454e..659cb3cf37a9 100644 --- a/drivers/crypto/atmel-ecc.c +++ b/drivers/crypto/atmel-ecc.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -610,6 +611,61 @@ static inline size_t atmel_ecc_wake_token_sz(u32 bus_clk_rate) return DIV_ROUND_UP(no_of_bits, 8); } +static int atmel_ecc_get_serial(struct i2c_client *client) +{ + struct atmel_ecc_cmd *cmd; + int ret; + int i; + u8 serial[9]; + + cmd = kmalloc(sizeof(*cmd), GFP_KERNEL); + if (!cmd) + return -ENOMEM; + + atmel_ecc_init_read_config_word(cmd, CONFIG_ZONE_SERIAL_0_3); + ret = atmel_ecc_send_receive(client, cmd); + if (ret) { + dev_err(&client->dev, + "failed to read serial byte 0-3\n"); + goto out_free_cmd; + } + for (i = 0; i < 4; i++) + serial[i] = cmd->data[RSP_DATA_IDX + i]; + + atmel_ecc_init_read_config_word(cmd, CONFIG_ZONE_SERIAL_4_7); + ret = atmel_ecc_send_receive(client, cmd); + if (ret) { + dev_err(&client->dev, + "failed to read serial byte 4-7\n"); + goto out_free_cmd; + } + for (i = 0; i < 4; i++) + serial[4 + i] = cmd->data[RSP_DATA_IDX + i]; + + + atmel_ecc_init_read_config_word(cmd, CONFIG_ZONE_SERIAL_8_I2CEN); + ret = atmel_ecc_send_receive(client, cmd); + if (ret) { + kfree(cmd); + dev_err(&client->dev, + "failed to read serial byte 8\n"); + goto out_free_cmd; + } + serial[8] = cmd->data[RSP_DATA_IDX]; + + /* This is device-unique data so it goes into the entropy pool */ + add_device_randomness(serial, sizeof(serial)); + + dev_info(&client->dev, + "serial number: %02x%02x%02x%02x%02x%02x%02x%02x%02x\n", + serial[0], serial[1], serial[2], serial[3], serial[4], + serial[5], serial[6], serial[7], serial[8]); + +out_free_cmd: + kfree(cmd); + return ret; +} + static int device_sanity_check(struct i2c_client *client) { struct atmel_ecc_cmd *cmd; @@ -692,6 +748,10 @@ static int atmel_ecc_probe(struct i2c_client *client, if (ret) return ret; + ret = atmel_ecc_get_serial(client); + if (ret) + return ret; + spin_lock(&driver_data.i2c_list_lock); list_add_tail(&i2c_priv->i2c_client_list_node, &driver_data.i2c_client_list);