5
5
* Copyright (C) 2019, 2024 Marek Behún <[email protected] >
6
6
*/
7
7
8
- #include <crypto/sha2.h>
9
8
#include <linux/align.h>
10
9
#include <linux/armada-37xx-rwtm-mailbox.h>
11
10
#include <linux/completion.h>
12
11
#include <linux/container_of.h>
13
- #include <linux/debugfs.h>
14
12
#include <linux/device.h>
15
13
#include <linux/dma-mapping.h>
16
14
#include <linux/err.h>
17
- #include <linux/fs.h>
18
15
#include <linux/hw_random.h>
19
16
#include <linux/if_ether.h>
20
17
#include <linux/kobject.h>
37
34
* https://gitlab.labs.nic.cz/turris/mox-boot-builder/tree/master/wtmi.
38
35
*/
39
36
40
- #define MOX_ECC_NUMBER_WORDS 17
41
- #define MOX_ECC_NUMBER_LEN (MOX_ECC_NUMBER_WORDS * sizeof(u32))
42
-
43
- #define MOX_ECC_SIGNATURE_WORDS (2 * MOX_ECC_NUMBER_WORDS)
44
-
45
37
#define MBOX_STS_SUCCESS (0 << 30)
46
38
#define MBOX_STS_FAIL (1 << 30)
47
39
#define MBOX_STS_BADCMD (2 << 30)
@@ -77,10 +69,6 @@ enum mbox_cmd {
77
69
* @ram_size: RAM size of the device
78
70
* @mac_address1: first MAC address of the device
79
71
* @mac_address2: second MAC address of the device
80
- * @has_pubkey: whether board ECDSA public key is present
81
- * @pubkey: board ECDSA public key
82
- * @last_sig: last ECDSA signature generated with board ECDSA private key
83
- * @last_sig_done: whether the last ECDSA signing is complete
84
72
*/
85
73
struct mox_rwtm {
86
74
struct mbox_client mbox_client ;
@@ -99,53 +87,37 @@ struct mox_rwtm {
99
87
u64 serial_number ;
100
88
int board_version , ram_size ;
101
89
u8 mac_address1 [ETH_ALEN ], mac_address2 [ETH_ALEN ];
102
-
103
- bool has_pubkey ;
104
- u8 pubkey [135 ];
105
-
106
- #ifdef CONFIG_DEBUG_FS
107
- /*
108
- * Signature process. This is currently done via debugfs, because it
109
- * does not conform to the sysfs standard "one file per attribute".
110
- * It should be rewritten via crypto API once akcipher API is available
111
- * from userspace.
112
- */
113
- u32 last_sig [MOX_ECC_SIGNATURE_WORDS ];
114
- bool last_sig_done ;
115
- #endif
116
90
};
117
91
118
92
static inline struct device * rwtm_dev (struct mox_rwtm * rwtm )
119
93
{
120
94
return rwtm -> mbox_client .dev ;
121
95
}
122
96
123
- #define MOX_ATTR_RO (name , format , cat ) \
97
+ #define MOX_ATTR_RO (name , format ) \
124
98
static ssize_t \
125
99
name##_show(struct device *dev, struct device_attribute *a, \
126
100
char *buf) \
127
101
{ \
128
102
struct mox_rwtm *rwtm = dev_get_drvdata(dev); \
129
- if (!rwtm->has_##cat) \
103
+ if (!rwtm->has_board_info) \
130
104
return -ENODATA; \
131
105
return sysfs_emit(buf, format, rwtm->name); \
132
106
} \
133
107
static DEVICE_ATTR_RO(name)
134
108
135
- MOX_ATTR_RO (serial_number , "%016llX\n" , board_info );
136
- MOX_ATTR_RO (board_version , "%i\n" , board_info );
137
- MOX_ATTR_RO (ram_size , "%i\n" , board_info );
138
- MOX_ATTR_RO (mac_address1 , "%pM\n" , board_info );
139
- MOX_ATTR_RO (mac_address2 , "%pM\n" , board_info );
140
- MOX_ATTR_RO (pubkey , "%s\n" , pubkey );
109
+ MOX_ATTR_RO (serial_number , "%016llX\n" );
110
+ MOX_ATTR_RO (board_version , "%i\n" );
111
+ MOX_ATTR_RO (ram_size , "%i\n" );
112
+ MOX_ATTR_RO (mac_address1 , "%pM\n" );
113
+ MOX_ATTR_RO (mac_address2 , "%pM\n" );
141
114
142
115
static struct attribute * turris_mox_rwtm_attrs [] = {
143
116
& dev_attr_serial_number .attr ,
144
117
& dev_attr_board_version .attr ,
145
118
& dev_attr_ram_size .attr ,
146
119
& dev_attr_mac_address1 .attr ,
147
120
& dev_attr_mac_address2 .attr ,
148
- & dev_attr_pubkey .attr ,
149
121
NULL
150
122
};
151
123
ATTRIBUTE_GROUPS (turris_mox_rwtm );
@@ -247,24 +219,6 @@ static int mox_get_board_info(struct mox_rwtm *rwtm)
247
219
pr_info (" burned RAM size %i MiB\n" , rwtm -> ram_size );
248
220
}
249
221
250
- ret = mox_rwtm_exec (rwtm , MBOX_CMD_ECDSA_PUB_KEY , NULL , false);
251
- if (ret == - ENODATA ) {
252
- dev_warn (dev , "Board has no public key burned!\n" );
253
- } else if (ret == - EOPNOTSUPP ) {
254
- dev_notice (dev ,
255
- "Firmware does not support the ECDSA_PUB_KEY command\n" );
256
- } else if (ret < 0 ) {
257
- return ret ;
258
- } else {
259
- u32 * s = reply -> status ;
260
-
261
- rwtm -> has_pubkey = true;
262
- sprintf (rwtm -> pubkey ,
263
- "%06x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x" ,
264
- ret , s [0 ], s [1 ], s [2 ], s [3 ], s [4 ], s [5 ], s [6 ], s [7 ],
265
- s [8 ], s [9 ], s [10 ], s [11 ], s [12 ], s [13 ], s [14 ], s [15 ]);
266
- }
267
-
268
222
return 0 ;
269
223
}
270
224
@@ -306,128 +260,6 @@ static int mox_hwrng_read(struct hwrng *rng, void *data, size_t max, bool wait)
306
260
return ret ;
307
261
}
308
262
309
- #ifdef CONFIG_DEBUG_FS
310
- static int rwtm_debug_open (struct inode * inode , struct file * file )
311
- {
312
- file -> private_data = inode -> i_private ;
313
-
314
- return nonseekable_open (inode , file );
315
- }
316
-
317
- static ssize_t do_sign_read (struct file * file , char __user * buf , size_t len ,
318
- loff_t * ppos )
319
- {
320
- struct mox_rwtm * rwtm = file -> private_data ;
321
- ssize_t ret ;
322
-
323
- /* only allow one read, of whole signature, from position 0 */
324
- if (* ppos != 0 )
325
- return 0 ;
326
-
327
- if (len < sizeof (rwtm -> last_sig ))
328
- return - EINVAL ;
329
-
330
- if (!rwtm -> last_sig_done )
331
- return - ENODATA ;
332
-
333
- ret = simple_read_from_buffer (buf , len , ppos , rwtm -> last_sig ,
334
- sizeof (rwtm -> last_sig ));
335
- rwtm -> last_sig_done = false;
336
-
337
- return ret ;
338
- }
339
-
340
- static ssize_t do_sign_write (struct file * file , const char __user * buf ,
341
- size_t len , loff_t * ppos )
342
- {
343
- struct mox_rwtm * rwtm = file -> private_data ;
344
- struct armada_37xx_rwtm_tx_msg msg ;
345
- loff_t dummy = 0 ;
346
- ssize_t ret ;
347
-
348
- if (len != SHA512_DIGEST_SIZE )
349
- return - EINVAL ;
350
-
351
- /* if last result is not zero user has not read that information yet */
352
- if (rwtm -> last_sig_done )
353
- return - EBUSY ;
354
-
355
- if (!mutex_trylock (& rwtm -> busy ))
356
- return - EBUSY ;
357
-
358
- /*
359
- * Here we have to send:
360
- * 1. Address of the input to sign.
361
- * The input is an array of 17 32-bit words, the first (most
362
- * significat) is 0, the rest 16 words are copied from the SHA-512
363
- * hash given by the user and converted from BE to LE.
364
- * 2. Address of the buffer where ECDSA signature value R shall be
365
- * stored by the rWTM firmware.
366
- * 3. Address of the buffer where ECDSA signature value S shall be
367
- * stored by the rWTM firmware.
368
- */
369
- memset (rwtm -> buf , 0 , sizeof (u32 ));
370
- ret = simple_write_to_buffer (rwtm -> buf + sizeof (u32 ),
371
- SHA512_DIGEST_SIZE , & dummy , buf , len );
372
- if (ret < 0 )
373
- goto unlock_mutex ;
374
- be32_to_cpu_array (rwtm -> buf , rwtm -> buf , MOX_ECC_NUMBER_WORDS );
375
-
376
- msg .args [0 ] = 1 ;
377
- msg .args [1 ] = rwtm -> buf_phys ;
378
- msg .args [2 ] = rwtm -> buf_phys + MOX_ECC_NUMBER_LEN ;
379
- msg .args [3 ] = rwtm -> buf_phys + 2 * MOX_ECC_NUMBER_LEN ;
380
-
381
- ret = mox_rwtm_exec (rwtm , MBOX_CMD_SIGN , & msg , true);
382
- if (ret < 0 )
383
- goto unlock_mutex ;
384
-
385
- /*
386
- * Here we read the R and S values of the ECDSA signature
387
- * computed by the rWTM firmware and convert their words from
388
- * LE to BE.
389
- */
390
- memcpy (rwtm -> last_sig , rwtm -> buf + MOX_ECC_NUMBER_LEN ,
391
- sizeof (rwtm -> last_sig ));
392
- cpu_to_be32_array (rwtm -> last_sig , rwtm -> last_sig ,
393
- MOX_ECC_SIGNATURE_WORDS );
394
- rwtm -> last_sig_done = true;
395
-
396
- mutex_unlock (& rwtm -> busy );
397
- return len ;
398
- unlock_mutex :
399
- mutex_unlock (& rwtm -> busy );
400
- return ret ;
401
- }
402
-
403
- static const struct file_operations do_sign_fops = {
404
- .owner = THIS_MODULE ,
405
- .open = rwtm_debug_open ,
406
- .read = do_sign_read ,
407
- .write = do_sign_write ,
408
- };
409
-
410
- static void rwtm_debugfs_release (void * root )
411
- {
412
- debugfs_remove_recursive (root );
413
- }
414
-
415
- static void rwtm_register_debugfs (struct mox_rwtm * rwtm )
416
- {
417
- struct dentry * root ;
418
-
419
- root = debugfs_create_dir ("turris-mox-rwtm" , NULL );
420
-
421
- debugfs_create_file_unsafe ("do_sign" , 0600 , root , rwtm , & do_sign_fops );
422
-
423
- devm_add_action_or_reset (rwtm_dev (rwtm ), rwtm_debugfs_release , root );
424
- }
425
- #else
426
- static inline void rwtm_register_debugfs (struct mox_rwtm * rwtm )
427
- {
428
- }
429
- #endif
430
-
431
263
static void rwtm_devm_mbox_release (void * mbox )
432
264
{
433
265
mbox_free_channel (mbox );
@@ -491,8 +323,6 @@ static int turris_mox_rwtm_probe(struct platform_device *pdev)
491
323
if (ret )
492
324
return dev_err_probe (dev , ret , "Cannot register HWRNG!\n" );
493
325
494
- rwtm_register_debugfs (rwtm );
495
-
496
326
dev_info (dev , "HWRNG successfully registered\n" );
497
327
498
328
/*
0 commit comments