From patchwork Tue Jun 5 13:49:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 10448339 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 3D9F2600CA for ; Tue, 5 Jun 2018 13:50:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2E48B294A4 for ; Tue, 5 Jun 2018 13:50:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2311F294AD; Tue, 5 Jun 2018 13:50:40 +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 BBCC4294A4 for ; Tue, 5 Jun 2018 13:50:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751954AbeFENui (ORCPT ); Tue, 5 Jun 2018 09:50:38 -0400 Received: from mail-lf0-f65.google.com ([209.85.215.65]:35507 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751750AbeFENui (ORCPT ); Tue, 5 Jun 2018 09:50:38 -0400 Received: by mail-lf0-f65.google.com with SMTP id y72-v6so3718105lfd.2 for ; Tue, 05 Jun 2018 06:50:37 -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=OxiVk9lTluBzygsYhGigdmpo7mqiFb3R0THq7IvYYH0=; b=TGi1Cq0iWcej5ngjCDA6JmHEjVhVwVccvusrY3IsSysAlNayj7HyaQXiobdFyz+OKk jSli1XM7EWd79+zULp+vgA0lxM4141BAqlbwAnH390j2x4ws9i/n+VW5zNfRXS5dBoxe fQkqIYnv9kqqeky5OJVHlna/31Px6YGNCK+8U= 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=OxiVk9lTluBzygsYhGigdmpo7mqiFb3R0THq7IvYYH0=; b=GrBfaYAw2mEVhCDpfCX1t5dS7ddN8dxmhAv25EZag+4cq9KaFQ3bVGKXhy0TP1y4DF mYHyP/EouIofMMXzWTP5qy0g72G1r7PCTHyTJ+K+uC13lpn/byWSBaEyxbdOXt99ez78 yXztipK5ljRGPn8efSFwJJgR/fxGLCGptwgM3M9+aPbk1Qs9AoNUvXTR11fbZr2E5TMT cxSCI7BP16QnYZ663O3BBaFJwJBwVA17OjHkAwnn3Is5AIuRfIDCY5gr90ZZU34xXlJd nj0Gec8thUqEZvZaxwKjDb/qANElfRAkcfXM02rRgb8IHafIdSSl5e6gZp7t+T2On8cb h5cA== X-Gm-Message-State: ALKqPwduiLJpwvK4y6Pc7RvBmsoiqZidN7T9peRkNnIzkLpF9o3ceOuQ 72xMpV7x2ECiEL/Ocp11brweKqa6eoY= X-Google-Smtp-Source: ADUXVKK+RvB3k1oZjDq1/PZQ6Rn53bn/mo7qNnizOiqjBtRtiMeajz5tU53etL/h0DY23Ikk58cj6w== X-Received: by 2002:a2e:594d:: with SMTP id n74-v6mr19050374ljb.128.1528206636648; Tue, 05 Jun 2018 06:50:36 -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.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jun 2018 06:50:35 -0700 (PDT) From: Linus Walleij To: linux-crypto@vger.kernel.org, Herbert Xu , Tudor Ambarus Cc: Linus Walleij Subject: [PATCH 7/9] crypto: atmel-ecc: Print out serial number Date: Tue, 5 Jun 2018 15:49:48 +0200 Message-Id: <20180605134950.6605-7-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 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 --- drivers/crypto/atmel-ecc.c | 56 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/drivers/crypto/atmel-ecc.c b/drivers/crypto/atmel-ecc.c index 603e29bdcb97..fd8149313104 100644 --- a/drivers/crypto/atmel-ecc.c +++ b/drivers/crypto/atmel-ecc.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -616,6 +617,57 @@ 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; + u8 serial[9]; + int ret; + int i; + + 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"); + return ret; + } + for (i = 0; i < 4; i++) + serial[0+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"); + return ret; + } + 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) { + dev_err(&client->dev, + "failed to read serial byte 8\n"); + return ret; + } + 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]); + return 0; +} + static int device_sanity_check(struct i2c_client *client) { struct atmel_ecc_cmd *cmd; @@ -700,6 +752,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);