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: 137740 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp986110lji; Tue, 5 Jun 2018 06:50:40 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKW7MAVebR+SYSC5xbiHJoyiFuxsrlO5ZBwM+R1JdENCIS1ttZ2hc8txyWrEXz4Kr6pjDuY X-Received: by 2002:a62:8b9b:: with SMTP id e27-v6mr25902785pfl.82.1528206639969; Tue, 05 Jun 2018 06:50:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528206639; cv=none; d=google.com; s=arc-20160816; b=ojbXYsINCeVVL+2RgBWKEhYqDxm5eU8PtH5D+cWaJ7F2GiIcrv5KTU95B395Rz/Ju7 TIFlF3dReOTpK5i4V1Z1+UjkQ5E1o396sUXGXMJrwZvL+JYv+ddCS6+RblXZg6Ebu9QA ERABnG6k50fWbY0Zyi1DGmN3TXXyQbAc2UDoaEhRJREuu7FwLNgwHiIttZ7kmUwjLU2w 8t1mnto8u1petljb3pAmrKoE+5rIFqiaV3AV+QsVXnjJoKBKKurI1MIcfUTVcOuMWUnx bFketKFH76BPy/KAhTbPECAhCHF3fAD9Cp/ZMKVkMudBL17ZwQ7HOsuqeWGEnqP4JGwq xHXQ== 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=OxiVk9lTluBzygsYhGigdmpo7mqiFb3R0THq7IvYYH0=; b=Pv3rOWToh2IS0fYl/90HpsV0i53gCyiTmG7xOGRUkLhECN8ofOYEaKA2KQ8/BOSs2G mI4zDYTgmRg34fF3usli1Xb0d7ZCRCXrWxK3eJvYluWn8KyZPdpXIZVGM8PbW+Nn5Up6 pzsF+cSHbis1hujFVJlEEy5+ccgHPIuNeA7m1KXhEfWTpCXgdKUIqkYqfP0urrkWXqaP gzc61RgXAMOoizYRq3BZb/a/AkEkEZyPIOl2mxnqtnIWI2wVc0R//eAXI8cXHAXJb5Z2 I5wZ8qbCD+JfZPyojspQtX2WOqywc/Q6WJvmi19ZawkKAexg5Wo8ZUCgfkm64STMogTD SB+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TGi1Cq0i; 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.39; Tue, 05 Jun 2018 06:50:39 -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=TGi1Cq0i; 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 S1751954AbeFENui (ORCPT + 1 other); 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-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 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(+) -- 2.17.0 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);