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: 10493847 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 6FEA560230 for ; Thu, 28 Jun 2018 13:08:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5B17E29FE0 for ; Thu, 28 Jun 2018 13:08:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4DCCF2A013; Thu, 28 Jun 2018 13:08:26 +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 E154B29FE8 for ; Thu, 28 Jun 2018 13:08:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965127AbeF1NIX (ORCPT ); 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-Google-Smtp-Source: AAOMgpcYO7zH8l2Au0CCyAiQU6RVPue5NJ4/3p94TrG8gqieBclR5+O6Nq3WeARDxT1p4ZxsBtOQOA== 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 X-Virus-Scanned: ClamAV using ClamSMTP 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(+) 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);