int ecdsa_get_params(u32 type, u8 *p, u8 *a, u8 *b, u8 *N, u8 *Gx, u8 *Gy) { static u8 tbl[64 * 121]; char path[256]; u32 offset; if (type >= 64) return -1; if (key_build_path(path) < 0) return -1; strncat(path, "/curves", sizeof path); if (key_read(path, sizeof tbl, tbl) < 0) return -1; offset = type * 121; memcpy_inv(p, tbl + offset + 0, 20); memcpy_inv(a, tbl + offset + 20, 20); memcpy_inv(b, tbl + offset + 40, 20); memcpy_inv(N, tbl + offset + 60, 21); memcpy_inv(Gx, tbl + offset + 81, 20); memcpy_inv(Gy, tbl + offset + 101, 20); return 0; }
static int toh_eeprom_read_entry(struct toh_data *toh, void *dest, char *entry_name) { int i = toh_find_entry(toh, entry_name); ssize_t count; char temp[toh->eeprom[i].size]; count = toh_eeprom_read(toh, temp, toh->eeprom[i].offset, toh->eeprom[i].size); if (count != toh->eeprom[i].size) { dev_err(toh->dev, "Could not read entry %s\n", entry_name); return count; } memcpy_inv(dest, temp, toh->eeprom[i].size); return 0; }
static ssize_t toh_show(struct device *dev, struct device_attribute *attr, char *buf) { struct platform_device *pdev = container_of(dev, struct platform_device, dev); struct toh_data *toh = platform_get_drvdata(pdev); char ebuf[8]; char inv_buf[8]; int i = 0; ssize_t count; if (!toh->macc) { dev_err(dev, "No memory accessor set\n"); return -ENXIO; } memset(ebuf, 0, 8); memset(inv_buf, 0, 8); /* find the index for which attribute this call is meant to */ while (&toh->attrs[i] != attr) i++; count = toh_eeprom_read(toh, ebuf, toh->eeprom[i].offset, toh->eeprom[i].size); if (count != toh->eeprom[i].size) { dev_err(dev, "Could not read eeprom\n"); return count; } /* Reverse byte order of the buffer to make it cast properly to u64 */ memcpy_inv(inv_buf, ebuf, toh->eeprom[i].size); return snprintf(buf, PAGE_SIZE, "%llu\n", *(u64 *)inv_buf); }