Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

s390/zcrypt: remove support for PCICC and PCICA cards

Remove the code for really old crypt cards, PCICC and PCICA.
These cards have been out of service for several years.

Reviewd-by: Ingo Tuchscherer <ingo.tuchscherer@linux.vnet.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>

+2 -1445
+2 -2
drivers/s390/crypto/Makefile
··· 3 3 # 4 4 5 5 ap-objs := ap_bus.o 6 - obj-$(CONFIG_ZCRYPT) += ap.o zcrypt_api.o zcrypt_pcicc.o zcrypt_pcixcc.o 7 - obj-$(CONFIG_ZCRYPT) += zcrypt_pcica.o zcrypt_cex2a.o zcrypt_cex4.o 6 + obj-$(CONFIG_ZCRYPT) += ap.o zcrypt_api.o zcrypt_pcixcc.o 7 + obj-$(CONFIG_ZCRYPT) += zcrypt_cex2a.o zcrypt_cex4.o 8 8 obj-$(CONFIG_ZCRYPT) += zcrypt_msgtype6.o zcrypt_msgtype50.o
-103
drivers/s390/crypto/ap_bus.c
··· 1591 1591 } 1592 1592 1593 1593 /** 1594 - * ap_probe_device_type(): Find the device type of an AP. 1595 - * @ap_dev: pointer to the AP device. 1596 - * 1597 - * Find the device type if query queue returned a device type of 0. 1598 - */ 1599 - static int ap_probe_device_type(struct ap_device *ap_dev) 1600 - { 1601 - static unsigned char msg[] = { 1602 - 0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x00, 1603 - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 1604 - 0x00,0x00,0x00,0x58,0x00,0x00,0x00,0x00, 1605 - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 1606 - 0x01,0x00,0x43,0x43,0x41,0x2d,0x41,0x50, 1607 - 0x50,0x4c,0x20,0x20,0x20,0x01,0x01,0x01, 1608 - 0x00,0x00,0x00,0x00,0x50,0x4b,0x00,0x00, 1609 - 0x00,0x00,0x01,0x1c,0x00,0x00,0x00,0x00, 1610 - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 1611 - 0x00,0x00,0x05,0xb8,0x00,0x00,0x00,0x00, 1612 - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 1613 - 0x70,0x00,0x41,0x00,0x00,0x00,0x00,0x00, 1614 - 0x00,0x00,0x54,0x32,0x01,0x00,0xa0,0x00, 1615 - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 1616 - 0x00,0x00,0x00,0x00,0xb8,0x05,0x00,0x00, 1617 - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 1618 - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 1619 - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 1620 - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 1621 - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 1622 - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 1623 - 0x00,0x00,0x0a,0x00,0x00,0x00,0x00,0x00, 1624 - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 1625 - 0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00, 1626 - 0x49,0x43,0x53,0x46,0x20,0x20,0x20,0x20, 1627 - 0x50,0x4b,0x0a,0x00,0x50,0x4b,0x43,0x53, 1628 - 0x2d,0x31,0x2e,0x32,0x37,0x00,0x11,0x22, 1629 - 0x33,0x44,0x55,0x66,0x77,0x88,0x99,0x00, 1630 - 0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88, 1631 - 0x99,0x00,0x11,0x22,0x33,0x44,0x55,0x66, 1632 - 0x77,0x88,0x99,0x00,0x11,0x22,0x33,0x44, 1633 - 0x55,0x66,0x77,0x88,0x99,0x00,0x11,0x22, 1634 - 0x33,0x44,0x55,0x66,0x77,0x88,0x99,0x00, 1635 - 0x11,0x22,0x33,0x5d,0x00,0x5b,0x00,0x77, 1636 - 0x88,0x1e,0x00,0x00,0x57,0x00,0x00,0x00, 1637 - 0x00,0x04,0x00,0x00,0x4f,0x00,0x00,0x00, 1638 - 0x03,0x02,0x00,0x00,0x40,0x01,0x00,0x01, 1639 - 0xce,0x02,0x68,0x2d,0x5f,0xa9,0xde,0x0c, 1640 - 0xf6,0xd2,0x7b,0x58,0x4b,0xf9,0x28,0x68, 1641 - 0x3d,0xb4,0xf4,0xef,0x78,0xd5,0xbe,0x66, 1642 - 0x63,0x42,0xef,0xf8,0xfd,0xa4,0xf8,0xb0, 1643 - 0x8e,0x29,0xc2,0xc9,0x2e,0xd8,0x45,0xb8, 1644 - 0x53,0x8c,0x6f,0x4e,0x72,0x8f,0x6c,0x04, 1645 - 0x9c,0x88,0xfc,0x1e,0xc5,0x83,0x55,0x57, 1646 - 0xf7,0xdd,0xfd,0x4f,0x11,0x36,0x95,0x5d, 1647 - }; 1648 - struct ap_queue_status status; 1649 - unsigned long long psmid; 1650 - char *reply; 1651 - int rc, i; 1652 - 1653 - reply = (void *) get_zeroed_page(GFP_KERNEL); 1654 - if (!reply) { 1655 - rc = -ENOMEM; 1656 - goto out; 1657 - } 1658 - 1659 - status = __ap_send(ap_dev->qid, 0x0102030405060708ULL, 1660 - msg, sizeof(msg), 0); 1661 - if (status.response_code != AP_RESPONSE_NORMAL) { 1662 - rc = -ENODEV; 1663 - goto out_free; 1664 - } 1665 - 1666 - /* Wait for the test message to complete. */ 1667 - for (i = 0; i < 6; i++) { 1668 - msleep(300); 1669 - status = __ap_recv(ap_dev->qid, &psmid, reply, 4096); 1670 - if (status.response_code == AP_RESPONSE_NORMAL && 1671 - psmid == 0x0102030405060708ULL) 1672 - break; 1673 - } 1674 - if (i < 6) { 1675 - /* Got an answer. */ 1676 - if (reply[0] == 0x00 && reply[1] == 0x86) 1677 - ap_dev->device_type = AP_DEVICE_TYPE_PCICC; 1678 - else 1679 - ap_dev->device_type = AP_DEVICE_TYPE_PCICA; 1680 - rc = 0; 1681 - } else 1682 - rc = -ENODEV; 1683 - 1684 - out_free: 1685 - free_page((unsigned long) reply); 1686 - out: 1687 - return rc; 1688 - } 1689 - 1690 - /** 1691 1594 * __ap_scan_bus(): Scan the AP bus. 1692 1595 * @dev: Pointer to device 1693 1596 * @data: Pointer to data ··· 1653 1750 INIT_LIST_HEAD(&ap_dev->list); 1654 1751 setup_timer(&ap_dev->timeout, ap_request_timeout, 1655 1752 (unsigned long) ap_dev); 1656 - if (ap_dev->device_type == 0) 1657 - /* device type probing for old cards */ 1658 - if (ap_probe_device_type(ap_dev)) { 1659 - kfree(ap_dev); 1660 - continue; 1661 - } 1662 1753 1663 1754 ap_dev->device.bus = &ap_bus_type; 1664 1755 ap_dev->device.parent = ap_root_device;
-422
drivers/s390/crypto/zcrypt_pcica.c
··· 1 - /* 2 - * zcrypt 2.1.0 3 - * 4 - * Copyright IBM Corp. 2001, 2006 5 - * Author(s): Robert Burroughs 6 - * Eric Rossman (edrossma@us.ibm.com) 7 - * 8 - * Hotplug & misc device support: Jochen Roehrig (roehrig@de.ibm.com) 9 - * Major cleanup & driver split: Martin Schwidefsky <schwidefsky@de.ibm.com> 10 - * Ralph Wuerthner <rwuerthn@de.ibm.com> 11 - * 12 - * This program is free software; you can redistribute it and/or modify 13 - * it under the terms of the GNU General Public License as published by 14 - * the Free Software Foundation; either version 2, or (at your option) 15 - * any later version. 16 - * 17 - * This program is distributed in the hope that it will be useful, 18 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 - * GNU General Public License for more details. 21 - * 22 - * You should have received a copy of the GNU General Public License 23 - * along with this program; if not, write to the Free Software 24 - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 25 - */ 26 - 27 - #define KMSG_COMPONENT "zcrypt" 28 - #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt 29 - 30 - #include <linux/module.h> 31 - #include <linux/slab.h> 32 - #include <linux/init.h> 33 - #include <linux/err.h> 34 - #include <linux/atomic.h> 35 - #include <asm/uaccess.h> 36 - 37 - #include "ap_bus.h" 38 - #include "zcrypt_api.h" 39 - #include "zcrypt_error.h" 40 - #include "zcrypt_pcica.h" 41 - 42 - #define PCICA_MIN_MOD_SIZE 1 /* 8 bits */ 43 - #define PCICA_MAX_MOD_SIZE 256 /* 2048 bits */ 44 - 45 - #define PCICA_SPEED_RATING 2800 46 - 47 - #define PCICA_MAX_MESSAGE_SIZE 0x3a0 /* sizeof(struct type4_lcr) */ 48 - #define PCICA_MAX_RESPONSE_SIZE 0x110 /* max outputdatalength + type80_hdr */ 49 - 50 - #define PCICA_CLEANUP_TIME (15*HZ) 51 - 52 - static struct ap_device_id zcrypt_pcica_ids[] = { 53 - { AP_DEVICE(AP_DEVICE_TYPE_PCICA) }, 54 - { /* end of list */ }, 55 - }; 56 - 57 - MODULE_DEVICE_TABLE(ap, zcrypt_pcica_ids); 58 - MODULE_AUTHOR("IBM Corporation"); 59 - MODULE_DESCRIPTION("PCICA Cryptographic Coprocessor device driver, " 60 - "Copyright IBM Corp. 2001, 2006"); 61 - MODULE_LICENSE("GPL"); 62 - 63 - static int zcrypt_pcica_probe(struct ap_device *ap_dev); 64 - static void zcrypt_pcica_remove(struct ap_device *ap_dev); 65 - static void zcrypt_pcica_receive(struct ap_device *, struct ap_message *, 66 - struct ap_message *); 67 - 68 - static struct ap_driver zcrypt_pcica_driver = { 69 - .probe = zcrypt_pcica_probe, 70 - .remove = zcrypt_pcica_remove, 71 - .ids = zcrypt_pcica_ids, 72 - .request_timeout = PCICA_CLEANUP_TIME, 73 - }; 74 - 75 - /** 76 - * Convert a ICAMEX message to a type4 MEX message. 77 - * 78 - * @zdev: crypto device pointer 79 - * @zreq: crypto request pointer 80 - * @mex: pointer to user input data 81 - * 82 - * Returns 0 on success or -EFAULT. 83 - */ 84 - static int ICAMEX_msg_to_type4MEX_msg(struct zcrypt_device *zdev, 85 - struct ap_message *ap_msg, 86 - struct ica_rsa_modexpo *mex) 87 - { 88 - unsigned char *modulus, *exponent, *message; 89 - int mod_len; 90 - 91 - mod_len = mex->inputdatalength; 92 - 93 - if (mod_len <= 128) { 94 - struct type4_sme *sme = ap_msg->message; 95 - memset(sme, 0, sizeof(*sme)); 96 - ap_msg->length = sizeof(*sme); 97 - sme->header.msg_fmt = TYPE4_SME_FMT; 98 - sme->header.msg_len = sizeof(*sme); 99 - sme->header.msg_type_code = TYPE4_TYPE_CODE; 100 - sme->header.request_code = TYPE4_REQU_CODE; 101 - modulus = sme->modulus + sizeof(sme->modulus) - mod_len; 102 - exponent = sme->exponent + sizeof(sme->exponent) - mod_len; 103 - message = sme->message + sizeof(sme->message) - mod_len; 104 - } else { 105 - struct type4_lme *lme = ap_msg->message; 106 - memset(lme, 0, sizeof(*lme)); 107 - ap_msg->length = sizeof(*lme); 108 - lme->header.msg_fmt = TYPE4_LME_FMT; 109 - lme->header.msg_len = sizeof(*lme); 110 - lme->header.msg_type_code = TYPE4_TYPE_CODE; 111 - lme->header.request_code = TYPE4_REQU_CODE; 112 - modulus = lme->modulus + sizeof(lme->modulus) - mod_len; 113 - exponent = lme->exponent + sizeof(lme->exponent) - mod_len; 114 - message = lme->message + sizeof(lme->message) - mod_len; 115 - } 116 - 117 - if (copy_from_user(modulus, mex->n_modulus, mod_len) || 118 - copy_from_user(exponent, mex->b_key, mod_len) || 119 - copy_from_user(message, mex->inputdata, mod_len)) 120 - return -EFAULT; 121 - return 0; 122 - } 123 - 124 - /** 125 - * Convert a ICACRT message to a type4 CRT message. 126 - * 127 - * @zdev: crypto device pointer 128 - * @zreq: crypto request pointer 129 - * @crt: pointer to user input data 130 - * 131 - * Returns 0 on success or -EFAULT. 132 - */ 133 - static int ICACRT_msg_to_type4CRT_msg(struct zcrypt_device *zdev, 134 - struct ap_message *ap_msg, 135 - struct ica_rsa_modexpo_crt *crt) 136 - { 137 - unsigned char *p, *q, *dp, *dq, *u, *inp; 138 - int mod_len, short_len, long_len; 139 - 140 - mod_len = crt->inputdatalength; 141 - short_len = (mod_len + 1) / 2; 142 - long_len = mod_len / 2 + 8; 143 - 144 - if (mod_len <= 128) { 145 - struct type4_scr *scr = ap_msg->message; 146 - memset(scr, 0, sizeof(*scr)); 147 - ap_msg->length = sizeof(*scr); 148 - scr->header.msg_type_code = TYPE4_TYPE_CODE; 149 - scr->header.request_code = TYPE4_REQU_CODE; 150 - scr->header.msg_fmt = TYPE4_SCR_FMT; 151 - scr->header.msg_len = sizeof(*scr); 152 - p = scr->p + sizeof(scr->p) - long_len; 153 - q = scr->q + sizeof(scr->q) - short_len; 154 - dp = scr->dp + sizeof(scr->dp) - long_len; 155 - dq = scr->dq + sizeof(scr->dq) - short_len; 156 - u = scr->u + sizeof(scr->u) - long_len; 157 - inp = scr->message + sizeof(scr->message) - mod_len; 158 - } else { 159 - struct type4_lcr *lcr = ap_msg->message; 160 - memset(lcr, 0, sizeof(*lcr)); 161 - ap_msg->length = sizeof(*lcr); 162 - lcr->header.msg_type_code = TYPE4_TYPE_CODE; 163 - lcr->header.request_code = TYPE4_REQU_CODE; 164 - lcr->header.msg_fmt = TYPE4_LCR_FMT; 165 - lcr->header.msg_len = sizeof(*lcr); 166 - p = lcr->p + sizeof(lcr->p) - long_len; 167 - q = lcr->q + sizeof(lcr->q) - short_len; 168 - dp = lcr->dp + sizeof(lcr->dp) - long_len; 169 - dq = lcr->dq + sizeof(lcr->dq) - short_len; 170 - u = lcr->u + sizeof(lcr->u) - long_len; 171 - inp = lcr->message + sizeof(lcr->message) - mod_len; 172 - } 173 - 174 - if (copy_from_user(p, crt->np_prime, long_len) || 175 - copy_from_user(q, crt->nq_prime, short_len) || 176 - copy_from_user(dp, crt->bp_key, long_len) || 177 - copy_from_user(dq, crt->bq_key, short_len) || 178 - copy_from_user(u, crt->u_mult_inv, long_len) || 179 - copy_from_user(inp, crt->inputdata, mod_len)) 180 - return -EFAULT; 181 - return 0; 182 - } 183 - 184 - /** 185 - * Copy results from a type 84 reply message back to user space. 186 - * 187 - * @zdev: crypto device pointer 188 - * @reply: reply AP message. 189 - * @data: pointer to user output data 190 - * @length: size of user output data 191 - * 192 - * Returns 0 on success or -EFAULT. 193 - */ 194 - static int convert_type84(struct zcrypt_device *zdev, 195 - struct ap_message *reply, 196 - char __user *outputdata, 197 - unsigned int outputdatalength) 198 - { 199 - struct type84_hdr *t84h = reply->message; 200 - char *data; 201 - 202 - if (t84h->len < sizeof(*t84h) + outputdatalength) { 203 - /* The result is too short, the PCICA card may not do that.. */ 204 - zdev->online = 0; 205 - pr_err("Cryptographic device %x failed and was set offline\n", 206 - zdev->ap_dev->qid); 207 - ZCRYPT_DBF_DEV(DBF_ERR, zdev, "dev%04xo%drc%d", 208 - zdev->ap_dev->qid, zdev->online, t84h->code); 209 - return -EAGAIN; /* repeat the request on a different device. */ 210 - } 211 - BUG_ON(t84h->len > PCICA_MAX_RESPONSE_SIZE); 212 - data = reply->message + t84h->len - outputdatalength; 213 - if (copy_to_user(outputdata, data, outputdatalength)) 214 - return -EFAULT; 215 - return 0; 216 - } 217 - 218 - static int convert_response(struct zcrypt_device *zdev, 219 - struct ap_message *reply, 220 - char __user *outputdata, 221 - unsigned int outputdatalength) 222 - { 223 - /* Response type byte is the second byte in the response. */ 224 - switch (((unsigned char *) reply->message)[1]) { 225 - case TYPE82_RSP_CODE: 226 - case TYPE88_RSP_CODE: 227 - return convert_error(zdev, reply); 228 - case TYPE84_RSP_CODE: 229 - return convert_type84(zdev, reply, 230 - outputdata, outputdatalength); 231 - default: /* Unknown response type, this should NEVER EVER happen */ 232 - zdev->online = 0; 233 - pr_err("Cryptographic device %x failed and was set offline\n", 234 - zdev->ap_dev->qid); 235 - ZCRYPT_DBF_DEV(DBF_ERR, zdev, "dev%04xo%dfail", 236 - zdev->ap_dev->qid, zdev->online); 237 - return -EAGAIN; /* repeat the request on a different device. */ 238 - } 239 - } 240 - 241 - /** 242 - * This function is called from the AP bus code after a crypto request 243 - * "msg" has finished with the reply message "reply". 244 - * It is called from tasklet context. 245 - * @ap_dev: pointer to the AP device 246 - * @msg: pointer to the AP message 247 - * @reply: pointer to the AP reply message 248 - */ 249 - static void zcrypt_pcica_receive(struct ap_device *ap_dev, 250 - struct ap_message *msg, 251 - struct ap_message *reply) 252 - { 253 - static struct error_hdr error_reply = { 254 - .type = TYPE82_RSP_CODE, 255 - .reply_code = REP82_ERROR_MACHINE_FAILURE, 256 - }; 257 - struct type84_hdr *t84h; 258 - int length; 259 - 260 - /* Copy the reply message to the request message buffer. */ 261 - if (!reply) 262 - goto out; /* ap_msg->rc indicates the error */ 263 - t84h = reply->message; 264 - if (t84h->code == TYPE84_RSP_CODE) { 265 - length = min(PCICA_MAX_RESPONSE_SIZE, (int) t84h->len); 266 - memcpy(msg->message, reply->message, length); 267 - } else 268 - memcpy(msg->message, reply->message, sizeof error_reply); 269 - out: 270 - complete((struct completion *) msg->private); 271 - } 272 - 273 - static atomic_t zcrypt_step = ATOMIC_INIT(0); 274 - 275 - /** 276 - * The request distributor calls this function if it picked the PCICA 277 - * device to handle a modexpo request. 278 - * @zdev: pointer to zcrypt_device structure that identifies the 279 - * PCICA device to the request distributor 280 - * @mex: pointer to the modexpo request buffer 281 - */ 282 - static long zcrypt_pcica_modexpo(struct zcrypt_device *zdev, 283 - struct ica_rsa_modexpo *mex) 284 - { 285 - struct ap_message ap_msg; 286 - struct completion work; 287 - int rc; 288 - 289 - ap_init_message(&ap_msg); 290 - ap_msg.message = kmalloc(PCICA_MAX_MESSAGE_SIZE, GFP_KERNEL); 291 - if (!ap_msg.message) 292 - return -ENOMEM; 293 - ap_msg.receive = zcrypt_pcica_receive; 294 - ap_msg.psmid = (((unsigned long long) current->pid) << 32) + 295 - atomic_inc_return(&zcrypt_step); 296 - ap_msg.private = &work; 297 - rc = ICAMEX_msg_to_type4MEX_msg(zdev, &ap_msg, mex); 298 - if (rc) 299 - goto out_free; 300 - init_completion(&work); 301 - ap_queue_message(zdev->ap_dev, &ap_msg); 302 - rc = wait_for_completion_interruptible(&work); 303 - if (rc == 0) { 304 - rc = ap_msg.rc; 305 - if (rc == 0) 306 - rc = convert_response(zdev, &ap_msg, mex->outputdata, 307 - mex->outputdatalength); 308 - } else 309 - /* Signal pending. */ 310 - ap_cancel_message(zdev->ap_dev, &ap_msg); 311 - out_free: 312 - kfree(ap_msg.message); 313 - return rc; 314 - } 315 - 316 - /** 317 - * The request distributor calls this function if it picked the PCICA 318 - * device to handle a modexpo_crt request. 319 - * @zdev: pointer to zcrypt_device structure that identifies the 320 - * PCICA device to the request distributor 321 - * @crt: pointer to the modexpoc_crt request buffer 322 - */ 323 - static long zcrypt_pcica_modexpo_crt(struct zcrypt_device *zdev, 324 - struct ica_rsa_modexpo_crt *crt) 325 - { 326 - struct ap_message ap_msg; 327 - struct completion work; 328 - int rc; 329 - 330 - ap_init_message(&ap_msg); 331 - ap_msg.message = kmalloc(PCICA_MAX_MESSAGE_SIZE, GFP_KERNEL); 332 - if (!ap_msg.message) 333 - return -ENOMEM; 334 - ap_msg.receive = zcrypt_pcica_receive; 335 - ap_msg.psmid = (((unsigned long long) current->pid) << 32) + 336 - atomic_inc_return(&zcrypt_step); 337 - ap_msg.private = &work; 338 - rc = ICACRT_msg_to_type4CRT_msg(zdev, &ap_msg, crt); 339 - if (rc) 340 - goto out_free; 341 - init_completion(&work); 342 - ap_queue_message(zdev->ap_dev, &ap_msg); 343 - rc = wait_for_completion_interruptible(&work); 344 - if (rc == 0) { 345 - rc = ap_msg.rc; 346 - if (rc == 0) 347 - rc = convert_response(zdev, &ap_msg, crt->outputdata, 348 - crt->outputdatalength); 349 - } else 350 - /* Signal pending. */ 351 - ap_cancel_message(zdev->ap_dev, &ap_msg); 352 - out_free: 353 - kfree(ap_msg.message); 354 - return rc; 355 - } 356 - 357 - /** 358 - * The crypto operations for a PCICA card. 359 - */ 360 - static struct zcrypt_ops zcrypt_pcica_ops = { 361 - .rsa_modexpo = zcrypt_pcica_modexpo, 362 - .rsa_modexpo_crt = zcrypt_pcica_modexpo_crt, 363 - }; 364 - 365 - /** 366 - * Probe function for PCICA cards. It always accepts the AP device 367 - * since the bus_match already checked the hardware type. 368 - * @ap_dev: pointer to the AP device. 369 - */ 370 - static int zcrypt_pcica_probe(struct ap_device *ap_dev) 371 - { 372 - struct zcrypt_device *zdev; 373 - int rc; 374 - 375 - zdev = zcrypt_device_alloc(PCICA_MAX_RESPONSE_SIZE); 376 - if (!zdev) 377 - return -ENOMEM; 378 - zdev->ap_dev = ap_dev; 379 - zdev->ops = &zcrypt_pcica_ops; 380 - zdev->online = 1; 381 - zdev->user_space_type = ZCRYPT_PCICA; 382 - zdev->type_string = "PCICA"; 383 - zdev->min_mod_size = PCICA_MIN_MOD_SIZE; 384 - zdev->max_mod_size = PCICA_MAX_MOD_SIZE; 385 - zdev->speed_rating = PCICA_SPEED_RATING; 386 - zdev->max_exp_bit_length = PCICA_MAX_MOD_SIZE; 387 - ap_dev->reply = &zdev->reply; 388 - ap_dev->private = zdev; 389 - rc = zcrypt_device_register(zdev); 390 - if (rc) 391 - goto out_free; 392 - return 0; 393 - 394 - out_free: 395 - ap_dev->private = NULL; 396 - zcrypt_device_free(zdev); 397 - return rc; 398 - } 399 - 400 - /** 401 - * This is called to remove the extended PCICA driver information 402 - * if an AP device is removed. 403 - */ 404 - static void zcrypt_pcica_remove(struct ap_device *ap_dev) 405 - { 406 - struct zcrypt_device *zdev = ap_dev->private; 407 - 408 - zcrypt_device_unregister(zdev); 409 - } 410 - 411 - int __init zcrypt_pcica_init(void) 412 - { 413 - return ap_driver_register(&zcrypt_pcica_driver, THIS_MODULE, "pcica"); 414 - } 415 - 416 - void zcrypt_pcica_exit(void) 417 - { 418 - ap_driver_unregister(&zcrypt_pcica_driver); 419 - } 420 - 421 - module_init(zcrypt_pcica_init); 422 - module_exit(zcrypt_pcica_exit);
-115
drivers/s390/crypto/zcrypt_pcica.h
··· 1 - /* 2 - * zcrypt 2.1.0 3 - * 4 - * Copyright IBM Corp. 2001, 2006 5 - * Author(s): Robert Burroughs 6 - * Eric Rossman (edrossma@us.ibm.com) 7 - * 8 - * Hotplug & misc device support: Jochen Roehrig (roehrig@de.ibm.com) 9 - * Major cleanup & driver split: Martin Schwidefsky <schwidefsky@de.ibm.com> 10 - * 11 - * This program is free software; you can redistribute it and/or modify 12 - * it under the terms of the GNU General Public License as published by 13 - * the Free Software Foundation; either version 2, or (at your option) 14 - * any later version. 15 - * 16 - * This program is distributed in the hope that it will be useful, 17 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 - * GNU General Public License for more details. 20 - * 21 - * You should have received a copy of the GNU General Public License 22 - * along with this program; if not, write to the Free Software 23 - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 - */ 25 - 26 - #ifndef _ZCRYPT_PCICA_H_ 27 - #define _ZCRYPT_PCICA_H_ 28 - 29 - /** 30 - * The type 4 message family is associated with a PCICA card. 31 - * 32 - * The four members of the family are described below. 33 - * 34 - * Note that all unsigned char arrays are right-justified and left-padded 35 - * with zeroes. 36 - * 37 - * Note that all reserved fields must be zeroes. 38 - */ 39 - struct type4_hdr { 40 - unsigned char reserved1; 41 - unsigned char msg_type_code; /* 0x04 */ 42 - unsigned short msg_len; 43 - unsigned char request_code; /* 0x40 */ 44 - unsigned char msg_fmt; 45 - unsigned short reserved2; 46 - } __attribute__((packed)); 47 - 48 - #define TYPE4_TYPE_CODE 0x04 49 - #define TYPE4_REQU_CODE 0x40 50 - 51 - #define TYPE4_SME_FMT 0x00 52 - #define TYPE4_LME_FMT 0x10 53 - #define TYPE4_SCR_FMT 0x40 54 - #define TYPE4_LCR_FMT 0x50 55 - 56 - /* Mod-Exp, with a small modulus */ 57 - struct type4_sme { 58 - struct type4_hdr header; 59 - unsigned char message[128]; 60 - unsigned char exponent[128]; 61 - unsigned char modulus[128]; 62 - } __attribute__((packed)); 63 - 64 - /* Mod-Exp, with a large modulus */ 65 - struct type4_lme { 66 - struct type4_hdr header; 67 - unsigned char message[256]; 68 - unsigned char exponent[256]; 69 - unsigned char modulus[256]; 70 - } __attribute__((packed)); 71 - 72 - /* CRT, with a small modulus */ 73 - struct type4_scr { 74 - struct type4_hdr header; 75 - unsigned char message[128]; 76 - unsigned char dp[72]; 77 - unsigned char dq[64]; 78 - unsigned char p[72]; 79 - unsigned char q[64]; 80 - unsigned char u[72]; 81 - } __attribute__((packed)); 82 - 83 - /* CRT, with a large modulus */ 84 - struct type4_lcr { 85 - struct type4_hdr header; 86 - unsigned char message[256]; 87 - unsigned char dp[136]; 88 - unsigned char dq[128]; 89 - unsigned char p[136]; 90 - unsigned char q[128]; 91 - unsigned char u[136]; 92 - } __attribute__((packed)); 93 - 94 - /** 95 - * The type 84 response family is associated with a PCICA card. 96 - * 97 - * Note that all unsigned char arrays are right-justified and left-padded 98 - * with zeroes. 99 - * 100 - * Note that all reserved fields must be zeroes. 101 - */ 102 - 103 - struct type84_hdr { 104 - unsigned char reserved1; 105 - unsigned char code; 106 - unsigned short len; 107 - unsigned char reserved2[4]; 108 - } __attribute__((packed)); 109 - 110 - #define TYPE84_RSP_CODE 0x84 111 - 112 - int zcrypt_pcica_init(void); 113 - void zcrypt_pcica_exit(void); 114 - 115 - #endif /* _ZCRYPT_PCICA_H_ */
-629
drivers/s390/crypto/zcrypt_pcicc.c
··· 1 - /* 2 - * zcrypt 2.1.0 3 - * 4 - * Copyright IBM Corp. 2001, 2006 5 - * Author(s): Robert Burroughs 6 - * Eric Rossman (edrossma@us.ibm.com) 7 - * 8 - * Hotplug & misc device support: Jochen Roehrig (roehrig@de.ibm.com) 9 - * Major cleanup & driver split: Martin Schwidefsky <schwidefsky@de.ibm.com> 10 - * Ralph Wuerthner <rwuerthn@de.ibm.com> 11 - * 12 - * This program is free software; you can redistribute it and/or modify 13 - * it under the terms of the GNU General Public License as published by 14 - * the Free Software Foundation; either version 2, or (at your option) 15 - * any later version. 16 - * 17 - * This program is distributed in the hope that it will be useful, 18 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 - * GNU General Public License for more details. 21 - * 22 - * You should have received a copy of the GNU General Public License 23 - * along with this program; if not, write to the Free Software 24 - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 25 - */ 26 - 27 - #define KMSG_COMPONENT "zcrypt" 28 - #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt 29 - 30 - #include <linux/module.h> 31 - #include <linux/init.h> 32 - #include <linux/gfp.h> 33 - #include <linux/err.h> 34 - #include <linux/atomic.h> 35 - #include <asm/uaccess.h> 36 - 37 - #include "ap_bus.h" 38 - #include "zcrypt_api.h" 39 - #include "zcrypt_error.h" 40 - #include "zcrypt_pcicc.h" 41 - #include "zcrypt_cca_key.h" 42 - 43 - #define PCICC_MIN_MOD_SIZE 64 /* 512 bits */ 44 - #define PCICC_MAX_MOD_SIZE_OLD 128 /* 1024 bits */ 45 - #define PCICC_MAX_MOD_SIZE 256 /* 2048 bits */ 46 - 47 - /* 48 - * PCICC cards need a speed rating of 0. This keeps them at the end of 49 - * the zcrypt device list (see zcrypt_api.c). PCICC cards are only 50 - * used if no other cards are present because they are slow and can only 51 - * cope with PKCS12 padded requests. The logic is queer. PKCS11 padded 52 - * requests are rejected. The modexpo function encrypts PKCS12 padded data 53 - * and decrypts any non-PKCS12 padded data (except PKCS11) in the assumption 54 - * that it's encrypted PKCS12 data. The modexpo_crt function always decrypts 55 - * the data in the assumption that its PKCS12 encrypted data. 56 - */ 57 - #define PCICC_SPEED_RATING 0 58 - 59 - #define PCICC_MAX_MESSAGE_SIZE 0x710 /* max size type6 v1 crt message */ 60 - #define PCICC_MAX_RESPONSE_SIZE 0x710 /* max size type86 v1 reply */ 61 - 62 - #define PCICC_CLEANUP_TIME (15*HZ) 63 - 64 - static struct ap_device_id zcrypt_pcicc_ids[] = { 65 - { AP_DEVICE(AP_DEVICE_TYPE_PCICC) }, 66 - { /* end of list */ }, 67 - }; 68 - 69 - MODULE_DEVICE_TABLE(ap, zcrypt_pcicc_ids); 70 - MODULE_AUTHOR("IBM Corporation"); 71 - MODULE_DESCRIPTION("PCICC Cryptographic Coprocessor device driver, " 72 - "Copyright IBM Corp. 2001, 2006"); 73 - MODULE_LICENSE("GPL"); 74 - 75 - static int zcrypt_pcicc_probe(struct ap_device *ap_dev); 76 - static void zcrypt_pcicc_remove(struct ap_device *ap_dev); 77 - static void zcrypt_pcicc_receive(struct ap_device *, struct ap_message *, 78 - struct ap_message *); 79 - 80 - static struct ap_driver zcrypt_pcicc_driver = { 81 - .probe = zcrypt_pcicc_probe, 82 - .remove = zcrypt_pcicc_remove, 83 - .ids = zcrypt_pcicc_ids, 84 - .request_timeout = PCICC_CLEANUP_TIME, 85 - }; 86 - 87 - /** 88 - * The following is used to initialize the CPRB passed to the PCICC card 89 - * in a type6 message. The 3 fields that must be filled in at execution 90 - * time are req_parml, rpl_parml and usage_domain. Note that all three 91 - * fields are *little*-endian. Actually, everything about this interface 92 - * is ascii/little-endian, since the device has 'Intel inside'. 93 - * 94 - * The CPRB is followed immediately by the parm block. 95 - * The parm block contains: 96 - * - function code ('PD' 0x5044 or 'PK' 0x504B) 97 - * - rule block (0x0A00 'PKCS-1.2' or 0x0A00 'ZERO-PAD') 98 - * - VUD block 99 - */ 100 - static struct CPRB static_cprb = { 101 - .cprb_len = cpu_to_le16(0x0070), 102 - .cprb_ver_id = 0x41, 103 - .func_id = {0x54,0x32}, 104 - .checkpoint_flag= 0x01, 105 - .svr_namel = cpu_to_le16(0x0008), 106 - .svr_name = {'I','C','S','F',' ',' ',' ',' '} 107 - }; 108 - 109 - /** 110 - * Check the message for PKCS11 padding. 111 - */ 112 - static inline int is_PKCS11_padded(unsigned char *buffer, int length) 113 - { 114 - int i; 115 - if ((buffer[0] != 0x00) || (buffer[1] != 0x01)) 116 - return 0; 117 - for (i = 2; i < length; i++) 118 - if (buffer[i] != 0xFF) 119 - break; 120 - if (i < 10 || i == length) 121 - return 0; 122 - if (buffer[i] != 0x00) 123 - return 0; 124 - return 1; 125 - } 126 - 127 - /** 128 - * Check the message for PKCS12 padding. 129 - */ 130 - static inline int is_PKCS12_padded(unsigned char *buffer, int length) 131 - { 132 - int i; 133 - if ((buffer[0] != 0x00) || (buffer[1] != 0x02)) 134 - return 0; 135 - for (i = 2; i < length; i++) 136 - if (buffer[i] == 0x00) 137 - break; 138 - if ((i < 10) || (i == length)) 139 - return 0; 140 - if (buffer[i] != 0x00) 141 - return 0; 142 - return 1; 143 - } 144 - 145 - /** 146 - * Convert a ICAMEX message to a type6 MEX message. 147 - * 148 - * @zdev: crypto device pointer 149 - * @zreq: crypto request pointer 150 - * @mex: pointer to user input data 151 - * 152 - * Returns 0 on success or -EFAULT. 153 - */ 154 - static int ICAMEX_msg_to_type6MEX_msg(struct zcrypt_device *zdev, 155 - struct ap_message *ap_msg, 156 - struct ica_rsa_modexpo *mex) 157 - { 158 - static struct type6_hdr static_type6_hdr = { 159 - .type = 0x06, 160 - .offset1 = 0x00000058, 161 - .agent_id = {0x01,0x00,0x43,0x43,0x41,0x2D,0x41,0x50, 162 - 0x50,0x4C,0x20,0x20,0x20,0x01,0x01,0x01}, 163 - .function_code = {'P','K'}, 164 - }; 165 - static struct function_and_rules_block static_pke_function_and_rules ={ 166 - .function_code = {'P','K'}, 167 - .ulen = cpu_to_le16(10), 168 - .only_rule = {'P','K','C','S','-','1','.','2'} 169 - }; 170 - struct { 171 - struct type6_hdr hdr; 172 - struct CPRB cprb; 173 - struct function_and_rules_block fr; 174 - unsigned short length; 175 - char text[0]; 176 - } __attribute__((packed)) *msg = ap_msg->message; 177 - int vud_len, pad_len, size; 178 - 179 - /* VUD.ciphertext */ 180 - if (copy_from_user(msg->text, mex->inputdata, mex->inputdatalength)) 181 - return -EFAULT; 182 - 183 - if (is_PKCS11_padded(msg->text, mex->inputdatalength)) 184 - return -EINVAL; 185 - 186 - /* static message header and f&r */ 187 - msg->hdr = static_type6_hdr; 188 - msg->fr = static_pke_function_and_rules; 189 - 190 - if (is_PKCS12_padded(msg->text, mex->inputdatalength)) { 191 - /* strip the padding and adjust the data length */ 192 - pad_len = strnlen(msg->text + 2, mex->inputdatalength - 2) + 3; 193 - if (pad_len <= 9 || pad_len >= mex->inputdatalength) 194 - return -ENODEV; 195 - vud_len = mex->inputdatalength - pad_len; 196 - memmove(msg->text, msg->text + pad_len, vud_len); 197 - msg->length = cpu_to_le16(vud_len + 2); 198 - 199 - /* Set up key after the variable length text. */ 200 - size = zcrypt_type6_mex_key_en(mex, msg->text + vud_len, 0); 201 - if (size < 0) 202 - return size; 203 - size += sizeof(*msg) + vud_len; /* total size of msg */ 204 - } else { 205 - vud_len = mex->inputdatalength; 206 - msg->length = cpu_to_le16(2 + vud_len); 207 - 208 - msg->hdr.function_code[1] = 'D'; 209 - msg->fr.function_code[1] = 'D'; 210 - 211 - /* Set up key after the variable length text. */ 212 - size = zcrypt_type6_mex_key_de(mex, msg->text + vud_len, 0); 213 - if (size < 0) 214 - return size; 215 - size += sizeof(*msg) + vud_len; /* total size of msg */ 216 - } 217 - 218 - /* message header, cprb and f&r */ 219 - msg->hdr.ToCardLen1 = (size - sizeof(msg->hdr) + 3) & -4; 220 - msg->hdr.FromCardLen1 = PCICC_MAX_RESPONSE_SIZE - sizeof(msg->hdr); 221 - 222 - msg->cprb = static_cprb; 223 - msg->cprb.usage_domain[0]= AP_QID_QUEUE(zdev->ap_dev->qid); 224 - msg->cprb.req_parml = cpu_to_le16(size - sizeof(msg->hdr) - 225 - sizeof(msg->cprb)); 226 - msg->cprb.rpl_parml = cpu_to_le16(msg->hdr.FromCardLen1); 227 - 228 - ap_msg->length = (size + 3) & -4; 229 - return 0; 230 - } 231 - 232 - /** 233 - * Convert a ICACRT message to a type6 CRT message. 234 - * 235 - * @zdev: crypto device pointer 236 - * @zreq: crypto request pointer 237 - * @crt: pointer to user input data 238 - * 239 - * Returns 0 on success or -EFAULT. 240 - */ 241 - static int ICACRT_msg_to_type6CRT_msg(struct zcrypt_device *zdev, 242 - struct ap_message *ap_msg, 243 - struct ica_rsa_modexpo_crt *crt) 244 - { 245 - static struct type6_hdr static_type6_hdr = { 246 - .type = 0x06, 247 - .offset1 = 0x00000058, 248 - .agent_id = {0x01,0x00,0x43,0x43,0x41,0x2D,0x41,0x50, 249 - 0x50,0x4C,0x20,0x20,0x20,0x01,0x01,0x01}, 250 - .function_code = {'P','D'}, 251 - }; 252 - static struct function_and_rules_block static_pkd_function_and_rules ={ 253 - .function_code = {'P','D'}, 254 - .ulen = cpu_to_le16(10), 255 - .only_rule = {'P','K','C','S','-','1','.','2'} 256 - }; 257 - struct { 258 - struct type6_hdr hdr; 259 - struct CPRB cprb; 260 - struct function_and_rules_block fr; 261 - unsigned short length; 262 - char text[0]; 263 - } __attribute__((packed)) *msg = ap_msg->message; 264 - int size; 265 - 266 - /* VUD.ciphertext */ 267 - msg->length = cpu_to_le16(2 + crt->inputdatalength); 268 - if (copy_from_user(msg->text, crt->inputdata, crt->inputdatalength)) 269 - return -EFAULT; 270 - 271 - if (is_PKCS11_padded(msg->text, crt->inputdatalength)) 272 - return -EINVAL; 273 - 274 - /* Set up key after the variable length text. */ 275 - size = zcrypt_type6_crt_key(crt, msg->text + crt->inputdatalength, 0); 276 - if (size < 0) 277 - return size; 278 - size += sizeof(*msg) + crt->inputdatalength; /* total size of msg */ 279 - 280 - /* message header, cprb and f&r */ 281 - msg->hdr = static_type6_hdr; 282 - msg->hdr.ToCardLen1 = (size - sizeof(msg->hdr) + 3) & -4; 283 - msg->hdr.FromCardLen1 = PCICC_MAX_RESPONSE_SIZE - sizeof(msg->hdr); 284 - 285 - msg->cprb = static_cprb; 286 - msg->cprb.usage_domain[0] = AP_QID_QUEUE(zdev->ap_dev->qid); 287 - msg->cprb.req_parml = msg->cprb.rpl_parml = 288 - cpu_to_le16(size - sizeof(msg->hdr) - sizeof(msg->cprb)); 289 - 290 - msg->fr = static_pkd_function_and_rules; 291 - 292 - ap_msg->length = (size + 3) & -4; 293 - return 0; 294 - } 295 - 296 - /** 297 - * Copy results from a type 86 reply message back to user space. 298 - * 299 - * @zdev: crypto device pointer 300 - * @reply: reply AP message. 301 - * @data: pointer to user output data 302 - * @length: size of user output data 303 - * 304 - * Returns 0 on success or -EINVAL, -EFAULT, -EAGAIN in case of an error. 305 - */ 306 - struct type86_reply { 307 - struct type86_hdr hdr; 308 - struct type86_fmt2_ext fmt2; 309 - struct CPRB cprb; 310 - unsigned char pad[4]; /* 4 byte function code/rules block ? */ 311 - unsigned short length; 312 - char text[0]; 313 - } __attribute__((packed)); 314 - 315 - static int convert_type86(struct zcrypt_device *zdev, 316 - struct ap_message *reply, 317 - char __user *outputdata, 318 - unsigned int outputdatalength) 319 - { 320 - static unsigned char static_pad[] = { 321 - 0x00,0x02, 322 - 0x1B,0x7B,0x5D,0xB5,0x75,0x01,0x3D,0xFD, 323 - 0x8D,0xD1,0xC7,0x03,0x2D,0x09,0x23,0x57, 324 - 0x89,0x49,0xB9,0x3F,0xBB,0x99,0x41,0x5B, 325 - 0x75,0x21,0x7B,0x9D,0x3B,0x6B,0x51,0x39, 326 - 0xBB,0x0D,0x35,0xB9,0x89,0x0F,0x93,0xA5, 327 - 0x0B,0x47,0xF1,0xD3,0xBB,0xCB,0xF1,0x9D, 328 - 0x23,0x73,0x71,0xFF,0xF3,0xF5,0x45,0xFB, 329 - 0x61,0x29,0x23,0xFD,0xF1,0x29,0x3F,0x7F, 330 - 0x17,0xB7,0x1B,0xA9,0x19,0xBD,0x57,0xA9, 331 - 0xD7,0x95,0xA3,0xCB,0xED,0x1D,0xDB,0x45, 332 - 0x7D,0x11,0xD1,0x51,0x1B,0xED,0x71,0xE9, 333 - 0xB1,0xD1,0xAB,0xAB,0x21,0x2B,0x1B,0x9F, 334 - 0x3B,0x9F,0xF7,0xF7,0xBD,0x63,0xEB,0xAD, 335 - 0xDF,0xB3,0x6F,0x5B,0xDB,0x8D,0xA9,0x5D, 336 - 0xE3,0x7D,0x77,0x49,0x47,0xF5,0xA7,0xFD, 337 - 0xAB,0x2F,0x27,0x35,0x77,0xD3,0x49,0xC9, 338 - 0x09,0xEB,0xB1,0xF9,0xBF,0x4B,0xCB,0x2B, 339 - 0xEB,0xEB,0x05,0xFF,0x7D,0xC7,0x91,0x8B, 340 - 0x09,0x83,0xB9,0xB9,0x69,0x33,0x39,0x6B, 341 - 0x79,0x75,0x19,0xBF,0xBB,0x07,0x1D,0xBD, 342 - 0x29,0xBF,0x39,0x95,0x93,0x1D,0x35,0xC7, 343 - 0xC9,0x4D,0xE5,0x97,0x0B,0x43,0x9B,0xF1, 344 - 0x16,0x93,0x03,0x1F,0xA5,0xFB,0xDB,0xF3, 345 - 0x27,0x4F,0x27,0x61,0x05,0x1F,0xB9,0x23, 346 - 0x2F,0xC3,0x81,0xA9,0x23,0x71,0x55,0x55, 347 - 0xEB,0xED,0x41,0xE5,0xF3,0x11,0xF1,0x43, 348 - 0x69,0x03,0xBD,0x0B,0x37,0x0F,0x51,0x8F, 349 - 0x0B,0xB5,0x89,0x5B,0x67,0xA9,0xD9,0x4F, 350 - 0x01,0xF9,0x21,0x77,0x37,0x73,0x79,0xC5, 351 - 0x7F,0x51,0xC1,0xCF,0x97,0xA1,0x75,0xAD, 352 - 0x35,0x9D,0xD3,0xD3,0xA7,0x9D,0x5D,0x41, 353 - 0x6F,0x65,0x1B,0xCF,0xA9,0x87,0x91,0x09 354 - }; 355 - struct type86_reply *msg = reply->message; 356 - unsigned short service_rc, service_rs; 357 - unsigned int reply_len, pad_len; 358 - char *data; 359 - 360 - service_rc = le16_to_cpu(msg->cprb.ccp_rtcode); 361 - if (unlikely(service_rc != 0)) { 362 - service_rs = le16_to_cpu(msg->cprb.ccp_rscode); 363 - if (service_rc == 8 && service_rs == 66) 364 - return -EINVAL; 365 - if (service_rc == 8 && service_rs == 65) 366 - return -EINVAL; 367 - if (service_rc == 8 && service_rs == 770) { 368 - zdev->max_mod_size = PCICC_MAX_MOD_SIZE_OLD; 369 - return -EAGAIN; 370 - } 371 - if (service_rc == 8 && service_rs == 783) { 372 - zdev->max_mod_size = PCICC_MAX_MOD_SIZE_OLD; 373 - return -EAGAIN; 374 - } 375 - if (service_rc == 8 && service_rs == 72) 376 - return -EINVAL; 377 - zdev->online = 0; 378 - pr_err("Cryptographic device %x failed and was set offline\n", 379 - zdev->ap_dev->qid); 380 - ZCRYPT_DBF_DEV(DBF_ERR, zdev, "dev%04xo%drc%d", 381 - zdev->ap_dev->qid, zdev->online, 382 - msg->hdr.reply_code); 383 - return -EAGAIN; /* repeat the request on a different device. */ 384 - } 385 - data = msg->text; 386 - reply_len = le16_to_cpu(msg->length) - 2; 387 - if (reply_len > outputdatalength) 388 - return -EINVAL; 389 - /* 390 - * For all encipher requests, the length of the ciphertext (reply_len) 391 - * will always equal the modulus length. For MEX decipher requests 392 - * the output needs to get padded. Minimum pad size is 10. 393 - * 394 - * Currently, the cases where padding will be added is for: 395 - * - PCIXCC_MCL2 using a CRT form token (since PKD didn't support 396 - * ZERO-PAD and CRT is only supported for PKD requests) 397 - * - PCICC, always 398 - */ 399 - pad_len = outputdatalength - reply_len; 400 - if (pad_len > 0) { 401 - if (pad_len < 10) 402 - return -EINVAL; 403 - /* 'restore' padding left in the PCICC/PCIXCC card. */ 404 - if (copy_to_user(outputdata, static_pad, pad_len - 1)) 405 - return -EFAULT; 406 - if (put_user(0, outputdata + pad_len - 1)) 407 - return -EFAULT; 408 - } 409 - /* Copy the crypto response to user space. */ 410 - if (copy_to_user(outputdata + pad_len, data, reply_len)) 411 - return -EFAULT; 412 - return 0; 413 - } 414 - 415 - static int convert_response(struct zcrypt_device *zdev, 416 - struct ap_message *reply, 417 - char __user *outputdata, 418 - unsigned int outputdatalength) 419 - { 420 - struct type86_reply *msg = reply->message; 421 - 422 - /* Response type byte is the second byte in the response. */ 423 - switch (msg->hdr.type) { 424 - case TYPE82_RSP_CODE: 425 - case TYPE88_RSP_CODE: 426 - return convert_error(zdev, reply); 427 - case TYPE86_RSP_CODE: 428 - if (msg->hdr.reply_code) 429 - return convert_error(zdev, reply); 430 - if (msg->cprb.cprb_ver_id == 0x01) 431 - return convert_type86(zdev, reply, 432 - outputdata, outputdatalength); 433 - /* no break, incorrect cprb version is an unknown response */ 434 - default: /* Unknown response type, this should NEVER EVER happen */ 435 - zdev->online = 0; 436 - pr_err("Cryptographic device %x failed and was set offline\n", 437 - zdev->ap_dev->qid); 438 - ZCRYPT_DBF_DEV(DBF_ERR, zdev, "dev%04xo%dfail", 439 - zdev->ap_dev->qid, zdev->online); 440 - return -EAGAIN; /* repeat the request on a different device. */ 441 - } 442 - } 443 - 444 - /** 445 - * This function is called from the AP bus code after a crypto request 446 - * "msg" has finished with the reply message "reply". 447 - * It is called from tasklet context. 448 - * @ap_dev: pointer to the AP device 449 - * @msg: pointer to the AP message 450 - * @reply: pointer to the AP reply message 451 - */ 452 - static void zcrypt_pcicc_receive(struct ap_device *ap_dev, 453 - struct ap_message *msg, 454 - struct ap_message *reply) 455 - { 456 - static struct error_hdr error_reply = { 457 - .type = TYPE82_RSP_CODE, 458 - .reply_code = REP82_ERROR_MACHINE_FAILURE, 459 - }; 460 - struct type86_reply *t86r; 461 - int length; 462 - 463 - /* Copy the reply message to the request message buffer. */ 464 - if (!reply) 465 - goto out; /* ap_msg->rc indicates the error */ 466 - t86r = reply->message; 467 - if (t86r->hdr.type == TYPE86_RSP_CODE && 468 - t86r->cprb.cprb_ver_id == 0x01) { 469 - length = sizeof(struct type86_reply) + t86r->length - 2; 470 - length = min(PCICC_MAX_RESPONSE_SIZE, length); 471 - memcpy(msg->message, reply->message, length); 472 - } else 473 - memcpy(msg->message, reply->message, sizeof error_reply); 474 - out: 475 - complete((struct completion *) msg->private); 476 - } 477 - 478 - static atomic_t zcrypt_step = ATOMIC_INIT(0); 479 - 480 - /** 481 - * The request distributor calls this function if it picked the PCICC 482 - * device to handle a modexpo request. 483 - * @zdev: pointer to zcrypt_device structure that identifies the 484 - * PCICC device to the request distributor 485 - * @mex: pointer to the modexpo request buffer 486 - */ 487 - static long zcrypt_pcicc_modexpo(struct zcrypt_device *zdev, 488 - struct ica_rsa_modexpo *mex) 489 - { 490 - struct ap_message ap_msg; 491 - struct completion work; 492 - int rc; 493 - 494 - ap_init_message(&ap_msg); 495 - ap_msg.message = (void *) get_zeroed_page(GFP_KERNEL); 496 - if (!ap_msg.message) 497 - return -ENOMEM; 498 - ap_msg.receive = zcrypt_pcicc_receive; 499 - ap_msg.length = PAGE_SIZE; 500 - ap_msg.psmid = (((unsigned long long) current->pid) << 32) + 501 - atomic_inc_return(&zcrypt_step); 502 - ap_msg.private = &work; 503 - rc = ICAMEX_msg_to_type6MEX_msg(zdev, &ap_msg, mex); 504 - if (rc) 505 - goto out_free; 506 - init_completion(&work); 507 - ap_queue_message(zdev->ap_dev, &ap_msg); 508 - rc = wait_for_completion_interruptible(&work); 509 - if (rc == 0) { 510 - rc = ap_msg.rc; 511 - if (rc == 0) 512 - rc = convert_response(zdev, &ap_msg, mex->outputdata, 513 - mex->outputdatalength); 514 - } else 515 - /* Signal pending. */ 516 - ap_cancel_message(zdev->ap_dev, &ap_msg); 517 - out_free: 518 - free_page((unsigned long) ap_msg.message); 519 - return rc; 520 - } 521 - 522 - /** 523 - * The request distributor calls this function if it picked the PCICC 524 - * device to handle a modexpo_crt request. 525 - * @zdev: pointer to zcrypt_device structure that identifies the 526 - * PCICC device to the request distributor 527 - * @crt: pointer to the modexpoc_crt request buffer 528 - */ 529 - static long zcrypt_pcicc_modexpo_crt(struct zcrypt_device *zdev, 530 - struct ica_rsa_modexpo_crt *crt) 531 - { 532 - struct ap_message ap_msg; 533 - struct completion work; 534 - int rc; 535 - 536 - ap_init_message(&ap_msg); 537 - ap_msg.message = (void *) get_zeroed_page(GFP_KERNEL); 538 - if (!ap_msg.message) 539 - return -ENOMEM; 540 - ap_msg.receive = zcrypt_pcicc_receive; 541 - ap_msg.length = PAGE_SIZE; 542 - ap_msg.psmid = (((unsigned long long) current->pid) << 32) + 543 - atomic_inc_return(&zcrypt_step); 544 - ap_msg.private = &work; 545 - rc = ICACRT_msg_to_type6CRT_msg(zdev, &ap_msg, crt); 546 - if (rc) 547 - goto out_free; 548 - init_completion(&work); 549 - ap_queue_message(zdev->ap_dev, &ap_msg); 550 - rc = wait_for_completion_interruptible(&work); 551 - if (rc == 0) { 552 - rc = ap_msg.rc; 553 - if (rc == 0) 554 - rc = convert_response(zdev, &ap_msg, crt->outputdata, 555 - crt->outputdatalength); 556 - } else 557 - /* Signal pending. */ 558 - ap_cancel_message(zdev->ap_dev, &ap_msg); 559 - out_free: 560 - free_page((unsigned long) ap_msg.message); 561 - return rc; 562 - } 563 - 564 - /** 565 - * The crypto operations for a PCICC card. 566 - */ 567 - static struct zcrypt_ops zcrypt_pcicc_ops = { 568 - .rsa_modexpo = zcrypt_pcicc_modexpo, 569 - .rsa_modexpo_crt = zcrypt_pcicc_modexpo_crt, 570 - }; 571 - 572 - /** 573 - * Probe function for PCICC cards. It always accepts the AP device 574 - * since the bus_match already checked the hardware type. 575 - * @ap_dev: pointer to the AP device. 576 - */ 577 - static int zcrypt_pcicc_probe(struct ap_device *ap_dev) 578 - { 579 - struct zcrypt_device *zdev; 580 - int rc; 581 - 582 - zdev = zcrypt_device_alloc(PCICC_MAX_RESPONSE_SIZE); 583 - if (!zdev) 584 - return -ENOMEM; 585 - zdev->ap_dev = ap_dev; 586 - zdev->ops = &zcrypt_pcicc_ops; 587 - zdev->online = 1; 588 - zdev->user_space_type = ZCRYPT_PCICC; 589 - zdev->type_string = "PCICC"; 590 - zdev->min_mod_size = PCICC_MIN_MOD_SIZE; 591 - zdev->max_mod_size = PCICC_MAX_MOD_SIZE; 592 - zdev->speed_rating = PCICC_SPEED_RATING; 593 - zdev->max_exp_bit_length = PCICC_MAX_MOD_SIZE; 594 - ap_dev->reply = &zdev->reply; 595 - ap_dev->private = zdev; 596 - rc = zcrypt_device_register(zdev); 597 - if (rc) 598 - goto out_free; 599 - return 0; 600 - 601 - out_free: 602 - ap_dev->private = NULL; 603 - zcrypt_device_free(zdev); 604 - return rc; 605 - } 606 - 607 - /** 608 - * This is called to remove the extended PCICC driver information 609 - * if an AP device is removed. 610 - */ 611 - static void zcrypt_pcicc_remove(struct ap_device *ap_dev) 612 - { 613 - struct zcrypt_device *zdev = ap_dev->private; 614 - 615 - zcrypt_device_unregister(zdev); 616 - } 617 - 618 - int __init zcrypt_pcicc_init(void) 619 - { 620 - return ap_driver_register(&zcrypt_pcicc_driver, THIS_MODULE, "pcicc"); 621 - } 622 - 623 - void zcrypt_pcicc_exit(void) 624 - { 625 - ap_driver_unregister(&zcrypt_pcicc_driver); 626 - } 627 - 628 - module_init(zcrypt_pcicc_init); 629 - module_exit(zcrypt_pcicc_exit);
-174
drivers/s390/crypto/zcrypt_pcicc.h
··· 1 - /* 2 - * zcrypt 2.1.0 3 - * 4 - * Copyright IBM Corp. 2001, 2006 5 - * Author(s): Robert Burroughs 6 - * Eric Rossman (edrossma@us.ibm.com) 7 - * 8 - * Hotplug & misc device support: Jochen Roehrig (roehrig@de.ibm.com) 9 - * Major cleanup & driver split: Martin Schwidefsky <schwidefsky@de.ibm.com> 10 - * 11 - * This program is free software; you can redistribute it and/or modify 12 - * it under the terms of the GNU General Public License as published by 13 - * the Free Software Foundation; either version 2, or (at your option) 14 - * any later version. 15 - * 16 - * This program is distributed in the hope that it will be useful, 17 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 - * GNU General Public License for more details. 20 - * 21 - * You should have received a copy of the GNU General Public License 22 - * along with this program; if not, write to the Free Software 23 - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 - */ 25 - 26 - #ifndef _ZCRYPT_PCICC_H_ 27 - #define _ZCRYPT_PCICC_H_ 28 - 29 - /** 30 - * The type 6 message family is associated with PCICC or PCIXCC cards. 31 - * 32 - * It contains a message header followed by a CPRB, both of which 33 - * are described below. 34 - * 35 - * Note that all reserved fields must be zeroes. 36 - */ 37 - struct type6_hdr { 38 - unsigned char reserved1; /* 0x00 */ 39 - unsigned char type; /* 0x06 */ 40 - unsigned char reserved2[2]; /* 0x0000 */ 41 - unsigned char right[4]; /* 0x00000000 */ 42 - unsigned char reserved3[2]; /* 0x0000 */ 43 - unsigned char reserved4[2]; /* 0x0000 */ 44 - unsigned char apfs[4]; /* 0x00000000 */ 45 - unsigned int offset1; /* 0x00000058 (offset to CPRB) */ 46 - unsigned int offset2; /* 0x00000000 */ 47 - unsigned int offset3; /* 0x00000000 */ 48 - unsigned int offset4; /* 0x00000000 */ 49 - unsigned char agent_id[16]; /* PCICC: */ 50 - /* 0x0100 */ 51 - /* 0x4343412d4150504c202020 */ 52 - /* 0x010101 */ 53 - /* PCIXCC: */ 54 - /* 0x4341000000000000 */ 55 - /* 0x0000000000000000 */ 56 - unsigned char rqid[2]; /* rqid. internal to 603 */ 57 - unsigned char reserved5[2]; /* 0x0000 */ 58 - unsigned char function_code[2]; /* for PKD, 0x5044 (ascii 'PD') */ 59 - unsigned char reserved6[2]; /* 0x0000 */ 60 - unsigned int ToCardLen1; /* (request CPRB len + 3) & -4 */ 61 - unsigned int ToCardLen2; /* db len 0x00000000 for PKD */ 62 - unsigned int ToCardLen3; /* 0x00000000 */ 63 - unsigned int ToCardLen4; /* 0x00000000 */ 64 - unsigned int FromCardLen1; /* response buffer length */ 65 - unsigned int FromCardLen2; /* db len 0x00000000 for PKD */ 66 - unsigned int FromCardLen3; /* 0x00000000 */ 67 - unsigned int FromCardLen4; /* 0x00000000 */ 68 - } __attribute__((packed)); 69 - 70 - /** 71 - * CPRB 72 - * Note that all shorts, ints and longs are little-endian. 73 - * All pointer fields are 32-bits long, and mean nothing 74 - * 75 - * A request CPRB is followed by a request_parameter_block. 76 - * 77 - * The request (or reply) parameter block is organized thus: 78 - * function code 79 - * VUD block 80 - * key block 81 - */ 82 - struct CPRB { 83 - unsigned short cprb_len; /* CPRB length */ 84 - unsigned char cprb_ver_id; /* CPRB version id. */ 85 - unsigned char pad_000; /* Alignment pad byte. */ 86 - unsigned char srpi_rtcode[4]; /* SRPI return code LELONG */ 87 - unsigned char srpi_verb; /* SRPI verb type */ 88 - unsigned char flags; /* flags */ 89 - unsigned char func_id[2]; /* function id */ 90 - unsigned char checkpoint_flag; /* */ 91 - unsigned char resv2; /* reserved */ 92 - unsigned short req_parml; /* request parameter buffer */ 93 - /* length 16-bit little endian */ 94 - unsigned char req_parmp[4]; /* request parameter buffer * 95 - * pointer (means nothing: the * 96 - * parameter buffer follows * 97 - * the CPRB). */ 98 - unsigned char req_datal[4]; /* request data buffer */ 99 - /* length ULELONG */ 100 - unsigned char req_datap[4]; /* request data buffer */ 101 - /* pointer */ 102 - unsigned short rpl_parml; /* reply parameter buffer */ 103 - /* length 16-bit little endian */ 104 - unsigned char pad_001[2]; /* Alignment pad bytes. ULESHORT */ 105 - unsigned char rpl_parmp[4]; /* reply parameter buffer * 106 - * pointer (means nothing: the * 107 - * parameter buffer follows * 108 - * the CPRB). */ 109 - unsigned char rpl_datal[4]; /* reply data buffer len ULELONG */ 110 - unsigned char rpl_datap[4]; /* reply data buffer */ 111 - /* pointer */ 112 - unsigned short ccp_rscode; /* server reason code ULESHORT */ 113 - unsigned short ccp_rtcode; /* server return code ULESHORT */ 114 - unsigned char repd_parml[2]; /* replied parameter len ULESHORT*/ 115 - unsigned char mac_data_len[2]; /* Mac Data Length ULESHORT */ 116 - unsigned char repd_datal[4]; /* replied data length ULELONG */ 117 - unsigned char req_pc[2]; /* PC identifier */ 118 - unsigned char res_origin[8]; /* resource origin */ 119 - unsigned char mac_value[8]; /* Mac Value */ 120 - unsigned char logon_id[8]; /* Logon Identifier */ 121 - unsigned char usage_domain[2]; /* cdx */ 122 - unsigned char resv3[18]; /* reserved for requestor */ 123 - unsigned short svr_namel; /* server name length ULESHORT */ 124 - unsigned char svr_name[8]; /* server name */ 125 - } __attribute__((packed)); 126 - 127 - /** 128 - * The type 86 message family is associated with PCICC and PCIXCC cards. 129 - * 130 - * It contains a message header followed by a CPRB. The CPRB is 131 - * the same as the request CPRB, which is described above. 132 - * 133 - * If format is 1, an error condition exists and no data beyond 134 - * the 8-byte message header is of interest. 135 - * 136 - * The non-error message is shown below. 137 - * 138 - * Note that all reserved fields must be zeroes. 139 - */ 140 - struct type86_hdr { 141 - unsigned char reserved1; /* 0x00 */ 142 - unsigned char type; /* 0x86 */ 143 - unsigned char format; /* 0x01 (error) or 0x02 (ok) */ 144 - unsigned char reserved2; /* 0x00 */ 145 - unsigned char reply_code; /* reply code (see above) */ 146 - unsigned char reserved3[3]; /* 0x000000 */ 147 - } __attribute__((packed)); 148 - 149 - #define TYPE86_RSP_CODE 0x86 150 - #define TYPE86_FMT2 0x02 151 - 152 - struct type86_fmt2_ext { 153 - unsigned char reserved[4]; /* 0x00000000 */ 154 - unsigned char apfs[4]; /* final status */ 155 - unsigned int count1; /* length of CPRB + parameters */ 156 - unsigned int offset1; /* offset to CPRB */ 157 - unsigned int count2; /* 0x00000000 */ 158 - unsigned int offset2; /* db offset 0x00000000 for PKD */ 159 - unsigned int count3; /* 0x00000000 */ 160 - unsigned int offset3; /* 0x00000000 */ 161 - unsigned int count4; /* 0x00000000 */ 162 - unsigned int offset4; /* 0x00000000 */ 163 - } __attribute__((packed)); 164 - 165 - struct function_and_rules_block { 166 - unsigned char function_code[2]; 167 - unsigned short ulen; 168 - unsigned char only_rule[8]; 169 - } __attribute__((packed)); 170 - 171 - int zcrypt_pcicc_init(void); 172 - void zcrypt_pcicc_exit(void); 173 - 174 - #endif /* _ZCRYPT_PCICC_H_ */