mirror of
https://github.com/ukui/kernel.git
synced 2026-03-09 10:07:04 -07:00
s390/zcrypt: Separate msgtype implementation from card modules.
Msgtype implementations are now separated from card specific modules and can be dynamically registered. Existing msgtype implementations are restructured in modules. Signed-off-by: Holger Dengler <hd@linux.vnet.ibm.com> Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
This commit is contained in:
committed by
Martin Schwidefsky
parent
b26bd9413c
commit
5e55a488c8
@@ -5,3 +5,4 @@
|
||||
ap-objs := ap_bus.o
|
||||
obj-$(CONFIG_ZCRYPT) += ap.o zcrypt_api.o zcrypt_pcicc.o zcrypt_pcixcc.o
|
||||
obj-$(CONFIG_ZCRYPT) += zcrypt_pcica.o zcrypt_cex2a.o
|
||||
obj-$(CONFIG_ZCRYPT) += zcrypt_msgtype6.o zcrypt_msgtype50.o
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* zcrypt 2.1.0
|
||||
*
|
||||
* Copyright IBM Corp. 2001, 2006
|
||||
* Copyright IBM Corp. 2001, 2012
|
||||
* Author(s): Robert Burroughs
|
||||
* Eric Rossman (edrossma@us.ibm.com)
|
||||
* Cornelia Huck <cornelia.huck@de.ibm.com>
|
||||
@@ -9,6 +9,7 @@
|
||||
* Hotplug & misc device support: Jochen Roehrig (roehrig@de.ibm.com)
|
||||
* Major cleanup & driver split: Martin Schwidefsky <schwidefsky@de.ibm.com>
|
||||
* Ralph Wuerthner <rwuerthn@de.ibm.com>
|
||||
* MSGTYPE restruct: Holger Dengler <hd@linux.vnet.ibm.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -44,8 +45,8 @@
|
||||
* Module description.
|
||||
*/
|
||||
MODULE_AUTHOR("IBM Corporation");
|
||||
MODULE_DESCRIPTION("Cryptographic Coprocessor interface, "
|
||||
"Copyright IBM Corp. 2001, 2006");
|
||||
MODULE_DESCRIPTION("Cryptographic Coprocessor interface, " \
|
||||
"Copyright IBM Corp. 2001, 2012");
|
||||
MODULE_LICENSE("GPL");
|
||||
|
||||
static DEFINE_SPINLOCK(zcrypt_device_lock);
|
||||
@@ -56,6 +57,9 @@ static atomic_t zcrypt_open_count = ATOMIC_INIT(0);
|
||||
static int zcrypt_rng_device_add(void);
|
||||
static void zcrypt_rng_device_remove(void);
|
||||
|
||||
static DEFINE_SPINLOCK(zcrypt_ops_list_lock);
|
||||
static LIST_HEAD(zcrypt_ops_list);
|
||||
|
||||
/*
|
||||
* Device attributes common for all crypto devices.
|
||||
*/
|
||||
@@ -215,6 +219,8 @@ int zcrypt_device_register(struct zcrypt_device *zdev)
|
||||
{
|
||||
int rc;
|
||||
|
||||
if (!zdev->ops)
|
||||
return -ENODEV;
|
||||
rc = sysfs_create_group(&zdev->ap_dev->device.kobj,
|
||||
&zcrypt_device_attr_group);
|
||||
if (rc)
|
||||
@@ -269,6 +275,67 @@ void zcrypt_device_unregister(struct zcrypt_device *zdev)
|
||||
}
|
||||
EXPORT_SYMBOL(zcrypt_device_unregister);
|
||||
|
||||
void zcrypt_msgtype_register(struct zcrypt_ops *zops)
|
||||
{
|
||||
if (zops->owner) {
|
||||
spin_lock_bh(&zcrypt_ops_list_lock);
|
||||
list_add_tail(&zops->list, &zcrypt_ops_list);
|
||||
spin_unlock_bh(&zcrypt_ops_list_lock);
|
||||
}
|
||||
}
|
||||
EXPORT_SYMBOL(zcrypt_msgtype_register);
|
||||
|
||||
void zcrypt_msgtype_unregister(struct zcrypt_ops *zops)
|
||||
{
|
||||
spin_lock_bh(&zcrypt_ops_list_lock);
|
||||
list_del_init(&zops->list);
|
||||
spin_unlock_bh(&zcrypt_ops_list_lock);
|
||||
}
|
||||
EXPORT_SYMBOL(zcrypt_msgtype_unregister);
|
||||
|
||||
static inline
|
||||
struct zcrypt_ops *__ops_lookup(unsigned char *name, int variant)
|
||||
{
|
||||
struct zcrypt_ops *zops;
|
||||
int found = 0;
|
||||
|
||||
spin_lock_bh(&zcrypt_ops_list_lock);
|
||||
list_for_each_entry(zops, &zcrypt_ops_list, list) {
|
||||
if ((zops->variant == variant) &&
|
||||
(!strncmp(zops->owner->name, name, MODULE_NAME_LEN))) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
spin_unlock_bh(&zcrypt_ops_list_lock);
|
||||
|
||||
if (!found)
|
||||
return NULL;
|
||||
return zops;
|
||||
}
|
||||
|
||||
struct zcrypt_ops *zcrypt_msgtype_request(unsigned char *name, int variant)
|
||||
{
|
||||
struct zcrypt_ops *zops = NULL;
|
||||
|
||||
zops = __ops_lookup(name, variant);
|
||||
if (!zops) {
|
||||
request_module(name);
|
||||
zops = __ops_lookup(name, variant);
|
||||
}
|
||||
if ((!zops) || (!try_module_get(zops->owner)))
|
||||
return NULL;
|
||||
return zops;
|
||||
}
|
||||
EXPORT_SYMBOL(zcrypt_msgtype_request);
|
||||
|
||||
void zcrypt_msgtype_release(struct zcrypt_ops *zops)
|
||||
{
|
||||
if (zops)
|
||||
module_put(zops->owner);
|
||||
}
|
||||
EXPORT_SYMBOL(zcrypt_msgtype_release);
|
||||
|
||||
/**
|
||||
* zcrypt_read (): Not supported beyond zcrypt 1.3.1.
|
||||
*
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* zcrypt 2.1.0
|
||||
*
|
||||
* Copyright IBM Corp. 2001, 2006
|
||||
* Copyright IBM Corp. 2001, 2012
|
||||
* Author(s): Robert Burroughs
|
||||
* Eric Rossman (edrossma@us.ibm.com)
|
||||
* Cornelia Huck <cornelia.huck@de.ibm.com>
|
||||
@@ -9,6 +9,7 @@
|
||||
* Hotplug & misc device support: Jochen Roehrig (roehrig@de.ibm.com)
|
||||
* Major cleanup & driver split: Martin Schwidefsky <schwidefsky@de.ibm.com>
|
||||
* Ralph Wuerthner <rwuerthn@de.ibm.com>
|
||||
* MSGTYPE restruct: Holger Dengler <hd@linux.vnet.ibm.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -87,6 +88,9 @@ struct zcrypt_ops {
|
||||
struct ica_rsa_modexpo_crt *);
|
||||
long (*send_cprb)(struct zcrypt_device *, struct ica_xcRB *);
|
||||
long (*rng)(struct zcrypt_device *, char *);
|
||||
struct list_head list; /* zcrypt ops list. */
|
||||
struct module *owner;
|
||||
int variant;
|
||||
};
|
||||
|
||||
struct zcrypt_device {
|
||||
@@ -116,6 +120,10 @@ void zcrypt_device_get(struct zcrypt_device *);
|
||||
int zcrypt_device_put(struct zcrypt_device *);
|
||||
int zcrypt_device_register(struct zcrypt_device *);
|
||||
void zcrypt_device_unregister(struct zcrypt_device *);
|
||||
void zcrypt_msgtype_register(struct zcrypt_ops *);
|
||||
void zcrypt_msgtype_unregister(struct zcrypt_ops *);
|
||||
struct zcrypt_ops *zcrypt_msgtype_request(unsigned char *, int);
|
||||
void zcrypt_msgtype_release(struct zcrypt_ops *);
|
||||
int zcrypt_api_init(void);
|
||||
void zcrypt_api_exit(void);
|
||||
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
/*
|
||||
* zcrypt 2.1.0
|
||||
*
|
||||
* Copyright IBM Corp. 2001, 2006
|
||||
* Copyright IBM Corp. 2001, 2012
|
||||
* Author(s): Robert Burroughs
|
||||
* Eric Rossman (edrossma@us.ibm.com)
|
||||
*
|
||||
* Hotplug & misc device support: Jochen Roehrig (roehrig@de.ibm.com)
|
||||
* Major cleanup & driver split: Martin Schwidefsky <schwidefsky@de.ibm.com>
|
||||
* Ralph Wuerthner <rwuerthn@de.ibm.com>
|
||||
* MSGTYPE restruct: Holger Dengler <hd@linux.vnet.ibm.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -35,6 +36,7 @@
|
||||
#include "zcrypt_api.h"
|
||||
#include "zcrypt_error.h"
|
||||
#include "zcrypt_cex2a.h"
|
||||
#include "zcrypt_msgtype50.h"
|
||||
|
||||
#define CEX2A_MIN_MOD_SIZE 1 /* 8 bits */
|
||||
#define CEX2A_MAX_MOD_SIZE 256 /* 2048 bits */
|
||||
@@ -63,14 +65,12 @@ static struct ap_device_id zcrypt_cex2a_ids[] = {
|
||||
|
||||
MODULE_DEVICE_TABLE(ap, zcrypt_cex2a_ids);
|
||||
MODULE_AUTHOR("IBM Corporation");
|
||||
MODULE_DESCRIPTION("CEX2A Cryptographic Coprocessor device driver, "
|
||||
"Copyright IBM Corp. 2001, 2006");
|
||||
MODULE_DESCRIPTION("CEX2A Cryptographic Coprocessor device driver, " \
|
||||
"Copyright IBM Corp. 2001, 2012");
|
||||
MODULE_LICENSE("GPL");
|
||||
|
||||
static int zcrypt_cex2a_probe(struct ap_device *ap_dev);
|
||||
static void zcrypt_cex2a_remove(struct ap_device *ap_dev);
|
||||
static void zcrypt_cex2a_receive(struct ap_device *, struct ap_message *,
|
||||
struct ap_message *);
|
||||
|
||||
static struct ap_driver zcrypt_cex2a_driver = {
|
||||
.probe = zcrypt_cex2a_probe,
|
||||
@@ -79,344 +79,6 @@ static struct ap_driver zcrypt_cex2a_driver = {
|
||||
.request_timeout = CEX2A_CLEANUP_TIME,
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert a ICAMEX message to a type50 MEX message.
|
||||
*
|
||||
* @zdev: crypto device pointer
|
||||
* @zreq: crypto request pointer
|
||||
* @mex: pointer to user input data
|
||||
*
|
||||
* Returns 0 on success or -EFAULT.
|
||||
*/
|
||||
static int ICAMEX_msg_to_type50MEX_msg(struct zcrypt_device *zdev,
|
||||
struct ap_message *ap_msg,
|
||||
struct ica_rsa_modexpo *mex)
|
||||
{
|
||||
unsigned char *mod, *exp, *inp;
|
||||
int mod_len;
|
||||
|
||||
mod_len = mex->inputdatalength;
|
||||
|
||||
if (mod_len <= 128) {
|
||||
struct type50_meb1_msg *meb1 = ap_msg->message;
|
||||
memset(meb1, 0, sizeof(*meb1));
|
||||
ap_msg->length = sizeof(*meb1);
|
||||
meb1->header.msg_type_code = TYPE50_TYPE_CODE;
|
||||
meb1->header.msg_len = sizeof(*meb1);
|
||||
meb1->keyblock_type = TYPE50_MEB1_FMT;
|
||||
mod = meb1->modulus + sizeof(meb1->modulus) - mod_len;
|
||||
exp = meb1->exponent + sizeof(meb1->exponent) - mod_len;
|
||||
inp = meb1->message + sizeof(meb1->message) - mod_len;
|
||||
} else if (mod_len <= 256) {
|
||||
struct type50_meb2_msg *meb2 = ap_msg->message;
|
||||
memset(meb2, 0, sizeof(*meb2));
|
||||
ap_msg->length = sizeof(*meb2);
|
||||
meb2->header.msg_type_code = TYPE50_TYPE_CODE;
|
||||
meb2->header.msg_len = sizeof(*meb2);
|
||||
meb2->keyblock_type = TYPE50_MEB2_FMT;
|
||||
mod = meb2->modulus + sizeof(meb2->modulus) - mod_len;
|
||||
exp = meb2->exponent + sizeof(meb2->exponent) - mod_len;
|
||||
inp = meb2->message + sizeof(meb2->message) - mod_len;
|
||||
} else {
|
||||
/* mod_len > 256 = 4096 bit RSA Key */
|
||||
struct type50_meb3_msg *meb3 = ap_msg->message;
|
||||
memset(meb3, 0, sizeof(*meb3));
|
||||
ap_msg->length = sizeof(*meb3);
|
||||
meb3->header.msg_type_code = TYPE50_TYPE_CODE;
|
||||
meb3->header.msg_len = sizeof(*meb3);
|
||||
meb3->keyblock_type = TYPE50_MEB3_FMT;
|
||||
mod = meb3->modulus + sizeof(meb3->modulus) - mod_len;
|
||||
exp = meb3->exponent + sizeof(meb3->exponent) - mod_len;
|
||||
inp = meb3->message + sizeof(meb3->message) - mod_len;
|
||||
}
|
||||
|
||||
if (copy_from_user(mod, mex->n_modulus, mod_len) ||
|
||||
copy_from_user(exp, mex->b_key, mod_len) ||
|
||||
copy_from_user(inp, mex->inputdata, mod_len))
|
||||
return -EFAULT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a ICACRT message to a type50 CRT message.
|
||||
*
|
||||
* @zdev: crypto device pointer
|
||||
* @zreq: crypto request pointer
|
||||
* @crt: pointer to user input data
|
||||
*
|
||||
* Returns 0 on success or -EFAULT.
|
||||
*/
|
||||
static int ICACRT_msg_to_type50CRT_msg(struct zcrypt_device *zdev,
|
||||
struct ap_message *ap_msg,
|
||||
struct ica_rsa_modexpo_crt *crt)
|
||||
{
|
||||
int mod_len, short_len, long_len, long_offset, limit;
|
||||
unsigned char *p, *q, *dp, *dq, *u, *inp;
|
||||
|
||||
mod_len = crt->inputdatalength;
|
||||
short_len = mod_len / 2;
|
||||
long_len = mod_len / 2 + 8;
|
||||
|
||||
/*
|
||||
* CEX2A cannot handle p, dp, or U > 128 bytes.
|
||||
* If we have one of these, we need to do extra checking.
|
||||
* For CEX3A the limit is 256 bytes.
|
||||
*/
|
||||
if (zdev->max_mod_size == CEX3A_MAX_MOD_SIZE)
|
||||
limit = 256;
|
||||
else
|
||||
limit = 128;
|
||||
|
||||
if (long_len > limit) {
|
||||
/*
|
||||
* zcrypt_rsa_crt already checked for the leading
|
||||
* zeroes of np_prime, bp_key and u_mult_inc.
|
||||
*/
|
||||
long_offset = long_len - limit;
|
||||
long_len = limit;
|
||||
} else
|
||||
long_offset = 0;
|
||||
|
||||
/*
|
||||
* Instead of doing extra work for p, dp, U > 64 bytes, we'll just use
|
||||
* the larger message structure.
|
||||
*/
|
||||
if (long_len <= 64) {
|
||||
struct type50_crb1_msg *crb1 = ap_msg->message;
|
||||
memset(crb1, 0, sizeof(*crb1));
|
||||
ap_msg->length = sizeof(*crb1);
|
||||
crb1->header.msg_type_code = TYPE50_TYPE_CODE;
|
||||
crb1->header.msg_len = sizeof(*crb1);
|
||||
crb1->keyblock_type = TYPE50_CRB1_FMT;
|
||||
p = crb1->p + sizeof(crb1->p) - long_len;
|
||||
q = crb1->q + sizeof(crb1->q) - short_len;
|
||||
dp = crb1->dp + sizeof(crb1->dp) - long_len;
|
||||
dq = crb1->dq + sizeof(crb1->dq) - short_len;
|
||||
u = crb1->u + sizeof(crb1->u) - long_len;
|
||||
inp = crb1->message + sizeof(crb1->message) - mod_len;
|
||||
} else if (long_len <= 128) {
|
||||
struct type50_crb2_msg *crb2 = ap_msg->message;
|
||||
memset(crb2, 0, sizeof(*crb2));
|
||||
ap_msg->length = sizeof(*crb2);
|
||||
crb2->header.msg_type_code = TYPE50_TYPE_CODE;
|
||||
crb2->header.msg_len = sizeof(*crb2);
|
||||
crb2->keyblock_type = TYPE50_CRB2_FMT;
|
||||
p = crb2->p + sizeof(crb2->p) - long_len;
|
||||
q = crb2->q + sizeof(crb2->q) - short_len;
|
||||
dp = crb2->dp + sizeof(crb2->dp) - long_len;
|
||||
dq = crb2->dq + sizeof(crb2->dq) - short_len;
|
||||
u = crb2->u + sizeof(crb2->u) - long_len;
|
||||
inp = crb2->message + sizeof(crb2->message) - mod_len;
|
||||
} else {
|
||||
/* long_len >= 256 */
|
||||
struct type50_crb3_msg *crb3 = ap_msg->message;
|
||||
memset(crb3, 0, sizeof(*crb3));
|
||||
ap_msg->length = sizeof(*crb3);
|
||||
crb3->header.msg_type_code = TYPE50_TYPE_CODE;
|
||||
crb3->header.msg_len = sizeof(*crb3);
|
||||
crb3->keyblock_type = TYPE50_CRB3_FMT;
|
||||
p = crb3->p + sizeof(crb3->p) - long_len;
|
||||
q = crb3->q + sizeof(crb3->q) - short_len;
|
||||
dp = crb3->dp + sizeof(crb3->dp) - long_len;
|
||||
dq = crb3->dq + sizeof(crb3->dq) - short_len;
|
||||
u = crb3->u + sizeof(crb3->u) - long_len;
|
||||
inp = crb3->message + sizeof(crb3->message) - mod_len;
|
||||
}
|
||||
|
||||
if (copy_from_user(p, crt->np_prime + long_offset, long_len) ||
|
||||
copy_from_user(q, crt->nq_prime, short_len) ||
|
||||
copy_from_user(dp, crt->bp_key + long_offset, long_len) ||
|
||||
copy_from_user(dq, crt->bq_key, short_len) ||
|
||||
copy_from_user(u, crt->u_mult_inv + long_offset, long_len) ||
|
||||
copy_from_user(inp, crt->inputdata, mod_len))
|
||||
return -EFAULT;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy results from a type 80 reply message back to user space.
|
||||
*
|
||||
* @zdev: crypto device pointer
|
||||
* @reply: reply AP message.
|
||||
* @data: pointer to user output data
|
||||
* @length: size of user output data
|
||||
*
|
||||
* Returns 0 on success or -EFAULT.
|
||||
*/
|
||||
static int convert_type80(struct zcrypt_device *zdev,
|
||||
struct ap_message *reply,
|
||||
char __user *outputdata,
|
||||
unsigned int outputdatalength)
|
||||
{
|
||||
struct type80_hdr *t80h = reply->message;
|
||||
unsigned char *data;
|
||||
|
||||
if (t80h->len < sizeof(*t80h) + outputdatalength) {
|
||||
/* The result is too short, the CEX2A card may not do that.. */
|
||||
zdev->online = 0;
|
||||
return -EAGAIN; /* repeat the request on a different device. */
|
||||
}
|
||||
if (zdev->user_space_type == ZCRYPT_CEX2A)
|
||||
BUG_ON(t80h->len > CEX2A_MAX_RESPONSE_SIZE);
|
||||
else
|
||||
BUG_ON(t80h->len > CEX3A_MAX_RESPONSE_SIZE);
|
||||
data = reply->message + t80h->len - outputdatalength;
|
||||
if (copy_to_user(outputdata, data, outputdatalength))
|
||||
return -EFAULT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int convert_response(struct zcrypt_device *zdev,
|
||||
struct ap_message *reply,
|
||||
char __user *outputdata,
|
||||
unsigned int outputdatalength)
|
||||
{
|
||||
/* Response type byte is the second byte in the response. */
|
||||
switch (((unsigned char *) reply->message)[1]) {
|
||||
case TYPE82_RSP_CODE:
|
||||
case TYPE88_RSP_CODE:
|
||||
return convert_error(zdev, reply);
|
||||
case TYPE80_RSP_CODE:
|
||||
return convert_type80(zdev, reply,
|
||||
outputdata, outputdatalength);
|
||||
default: /* Unknown response type, this should NEVER EVER happen */
|
||||
zdev->online = 0;
|
||||
return -EAGAIN; /* repeat the request on a different device. */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is called from the AP bus code after a crypto request
|
||||
* "msg" has finished with the reply message "reply".
|
||||
* It is called from tasklet context.
|
||||
* @ap_dev: pointer to the AP device
|
||||
* @msg: pointer to the AP message
|
||||
* @reply: pointer to the AP reply message
|
||||
*/
|
||||
static void zcrypt_cex2a_receive(struct ap_device *ap_dev,
|
||||
struct ap_message *msg,
|
||||
struct ap_message *reply)
|
||||
{
|
||||
static struct error_hdr error_reply = {
|
||||
.type = TYPE82_RSP_CODE,
|
||||
.reply_code = REP82_ERROR_MACHINE_FAILURE,
|
||||
};
|
||||
struct type80_hdr *t80h;
|
||||
int length;
|
||||
|
||||
/* Copy the reply message to the request message buffer. */
|
||||
if (IS_ERR(reply)) {
|
||||
memcpy(msg->message, &error_reply, sizeof(error_reply));
|
||||
goto out;
|
||||
}
|
||||
t80h = reply->message;
|
||||
if (t80h->type == TYPE80_RSP_CODE) {
|
||||
if (ap_dev->device_type == AP_DEVICE_TYPE_CEX2A)
|
||||
length = min(CEX2A_MAX_RESPONSE_SIZE, (int) t80h->len);
|
||||
else
|
||||
length = min(CEX3A_MAX_RESPONSE_SIZE, (int) t80h->len);
|
||||
memcpy(msg->message, reply->message, length);
|
||||
} else
|
||||
memcpy(msg->message, reply->message, sizeof error_reply);
|
||||
out:
|
||||
complete((struct completion *) msg->private);
|
||||
}
|
||||
|
||||
static atomic_t zcrypt_step = ATOMIC_INIT(0);
|
||||
|
||||
/**
|
||||
* The request distributor calls this function if it picked the CEX2A
|
||||
* device to handle a modexpo request.
|
||||
* @zdev: pointer to zcrypt_device structure that identifies the
|
||||
* CEX2A device to the request distributor
|
||||
* @mex: pointer to the modexpo request buffer
|
||||
*/
|
||||
static long zcrypt_cex2a_modexpo(struct zcrypt_device *zdev,
|
||||
struct ica_rsa_modexpo *mex)
|
||||
{
|
||||
struct ap_message ap_msg;
|
||||
struct completion work;
|
||||
int rc;
|
||||
|
||||
ap_init_message(&ap_msg);
|
||||
if (zdev->user_space_type == ZCRYPT_CEX2A)
|
||||
ap_msg.message = kmalloc(CEX2A_MAX_MESSAGE_SIZE, GFP_KERNEL);
|
||||
else
|
||||
ap_msg.message = kmalloc(CEX3A_MAX_MESSAGE_SIZE, GFP_KERNEL);
|
||||
if (!ap_msg.message)
|
||||
return -ENOMEM;
|
||||
ap_msg.receive = zcrypt_cex2a_receive;
|
||||
ap_msg.psmid = (((unsigned long long) current->pid) << 32) +
|
||||
atomic_inc_return(&zcrypt_step);
|
||||
ap_msg.private = &work;
|
||||
rc = ICAMEX_msg_to_type50MEX_msg(zdev, &ap_msg, mex);
|
||||
if (rc)
|
||||
goto out_free;
|
||||
init_completion(&work);
|
||||
ap_queue_message(zdev->ap_dev, &ap_msg);
|
||||
rc = wait_for_completion_interruptible(&work);
|
||||
if (rc == 0)
|
||||
rc = convert_response(zdev, &ap_msg, mex->outputdata,
|
||||
mex->outputdatalength);
|
||||
else
|
||||
/* Signal pending. */
|
||||
ap_cancel_message(zdev->ap_dev, &ap_msg);
|
||||
out_free:
|
||||
kfree(ap_msg.message);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
* The request distributor calls this function if it picked the CEX2A
|
||||
* device to handle a modexpo_crt request.
|
||||
* @zdev: pointer to zcrypt_device structure that identifies the
|
||||
* CEX2A device to the request distributor
|
||||
* @crt: pointer to the modexpoc_crt request buffer
|
||||
*/
|
||||
static long zcrypt_cex2a_modexpo_crt(struct zcrypt_device *zdev,
|
||||
struct ica_rsa_modexpo_crt *crt)
|
||||
{
|
||||
struct ap_message ap_msg;
|
||||
struct completion work;
|
||||
int rc;
|
||||
|
||||
ap_init_message(&ap_msg);
|
||||
if (zdev->user_space_type == ZCRYPT_CEX2A)
|
||||
ap_msg.message = kmalloc(CEX2A_MAX_MESSAGE_SIZE, GFP_KERNEL);
|
||||
else
|
||||
ap_msg.message = kmalloc(CEX3A_MAX_MESSAGE_SIZE, GFP_KERNEL);
|
||||
if (!ap_msg.message)
|
||||
return -ENOMEM;
|
||||
ap_msg.receive = zcrypt_cex2a_receive;
|
||||
ap_msg.psmid = (((unsigned long long) current->pid) << 32) +
|
||||
atomic_inc_return(&zcrypt_step);
|
||||
ap_msg.private = &work;
|
||||
rc = ICACRT_msg_to_type50CRT_msg(zdev, &ap_msg, crt);
|
||||
if (rc)
|
||||
goto out_free;
|
||||
init_completion(&work);
|
||||
ap_queue_message(zdev->ap_dev, &ap_msg);
|
||||
rc = wait_for_completion_interruptible(&work);
|
||||
if (rc == 0)
|
||||
rc = convert_response(zdev, &ap_msg, crt->outputdata,
|
||||
crt->outputdatalength);
|
||||
else
|
||||
/* Signal pending. */
|
||||
ap_cancel_message(zdev->ap_dev, &ap_msg);
|
||||
out_free:
|
||||
kfree(ap_msg.message);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
* The crypto operations for a CEX2A card.
|
||||
*/
|
||||
static struct zcrypt_ops zcrypt_cex2a_ops = {
|
||||
.rsa_modexpo = zcrypt_cex2a_modexpo,
|
||||
.rsa_modexpo_crt = zcrypt_cex2a_modexpo_crt,
|
||||
};
|
||||
|
||||
/**
|
||||
* Probe function for CEX2A cards. It always accepts the AP device
|
||||
* since the bus_match already checked the hardware type.
|
||||
@@ -458,16 +120,18 @@ static int zcrypt_cex2a_probe(struct ap_device *ap_dev)
|
||||
zdev->speed_rating = CEX3A_SPEED_RATING;
|
||||
break;
|
||||
}
|
||||
if (zdev != NULL) {
|
||||
zdev->ap_dev = ap_dev;
|
||||
zdev->ops = &zcrypt_cex2a_ops;
|
||||
zdev->online = 1;
|
||||
ap_dev->reply = &zdev->reply;
|
||||
ap_dev->private = zdev;
|
||||
rc = zcrypt_device_register(zdev);
|
||||
}
|
||||
if (!zdev)
|
||||
return -ENODEV;
|
||||
zdev->ops = zcrypt_msgtype_request(MSGTYPE50_NAME,
|
||||
MSGTYPE50_VARIANT_DEFAULT);
|
||||
zdev->ap_dev = ap_dev;
|
||||
zdev->online = 1;
|
||||
ap_dev->reply = &zdev->reply;
|
||||
ap_dev->private = zdev;
|
||||
rc = zcrypt_device_register(zdev);
|
||||
if (rc) {
|
||||
ap_dev->private = NULL;
|
||||
zcrypt_msgtype_release(zdev->ops);
|
||||
zcrypt_device_free(zdev);
|
||||
}
|
||||
return rc;
|
||||
@@ -480,8 +144,10 @@ static int zcrypt_cex2a_probe(struct ap_device *ap_dev)
|
||||
static void zcrypt_cex2a_remove(struct ap_device *ap_dev)
|
||||
{
|
||||
struct zcrypt_device *zdev = ap_dev->private;
|
||||
struct zcrypt_ops *zops = zdev->ops;
|
||||
|
||||
zcrypt_device_unregister(zdev);
|
||||
zcrypt_msgtype_release(zops);
|
||||
}
|
||||
|
||||
int __init zcrypt_cex2a_init(void)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* zcrypt 2.1.0
|
||||
*
|
||||
* Copyright IBM Corp. 2001, 2012
|
||||
* Author(s): Robert Burroughs
|
||||
* Eric Rossman (edrossma@us.ibm.com)
|
||||
*
|
||||
* Hotplug & misc device support: Jochen Roehrig (roehrig@de.ibm.com)
|
||||
* Major cleanup & driver split: Martin Schwidefsky <schwidefsky@de.ibm.com>
|
||||
* MSGTYPE restruct: Holger Dengler <hd@linux.vnet.ibm.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifndef _ZCRYPT_MSGTYPE50_H_
|
||||
#define _ZCRYPT_MSGTYPE50_H_
|
||||
|
||||
#define MSGTYPE50_NAME "zcrypt_msgtype50"
|
||||
#define MSGTYPE50_VARIANT_DEFAULT 0
|
||||
|
||||
#define MSGTYPE50_CRB2_MAX_MSG_SIZE 0x390 /*sizeof(struct type50_crb2_msg)*/
|
||||
#define MSGTYPE50_CRB3_MAX_MSG_SIZE 0x710 /*sizeof(struct type50_crb3_msg)*/
|
||||
|
||||
int zcrypt_msgtype50_init(void);
|
||||
void zcrypt_msgtype50_exit(void);
|
||||
|
||||
#endif /* _ZCRYPT_MSGTYPE50_H_ */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
* zcrypt 2.1.0
|
||||
*
|
||||
* Copyright IBM Corp. 2001, 2012
|
||||
* Author(s): Robert Burroughs
|
||||
* Eric Rossman (edrossma@us.ibm.com)
|
||||
*
|
||||
* Hotplug & misc device support: Jochen Roehrig (roehrig@de.ibm.com)
|
||||
* Major cleanup & driver split: Martin Schwidefsky <schwidefsky@de.ibm.com>
|
||||
* MSGTYPE restruct: Holger Dengler <hd@linux.vnet.ibm.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifndef _ZCRYPT_MSGTYPE6_H_
|
||||
#define _ZCRYPT_MSGTYPE6_H_
|
||||
|
||||
#include <asm/zcrypt.h>
|
||||
|
||||
#define MSGTYPE06_NAME "zcrypt_msgtype6"
|
||||
#define MSGTYPE06_VARIANT_DEFAULT 0
|
||||
#define MSGTYPE06_VARIANT_NORNG 1
|
||||
|
||||
#define MSGTYPE06_MAX_MSG_SIZE (12*1024)
|
||||
|
||||
/**
|
||||
* The type 6 message family is associated with PCICC or PCIXCC cards.
|
||||
*
|
||||
* It contains a message header followed by a CPRB, both of which
|
||||
* are described below.
|
||||
*
|
||||
* Note that all reserved fields must be zeroes.
|
||||
*/
|
||||
struct type6_hdr {
|
||||
unsigned char reserved1; /* 0x00 */
|
||||
unsigned char type; /* 0x06 */
|
||||
unsigned char reserved2[2]; /* 0x0000 */
|
||||
unsigned char right[4]; /* 0x00000000 */
|
||||
unsigned char reserved3[2]; /* 0x0000 */
|
||||
unsigned char reserved4[2]; /* 0x0000 */
|
||||
unsigned char apfs[4]; /* 0x00000000 */
|
||||
unsigned int offset1; /* 0x00000058 (offset to CPRB) */
|
||||
unsigned int offset2; /* 0x00000000 */
|
||||
unsigned int offset3; /* 0x00000000 */
|
||||
unsigned int offset4; /* 0x00000000 */
|
||||
unsigned char agent_id[16]; /* PCICC: */
|
||||
/* 0x0100 */
|
||||
/* 0x4343412d4150504c202020 */
|
||||
/* 0x010101 */
|
||||
/* PCIXCC: */
|
||||
/* 0x4341000000000000 */
|
||||
/* 0x0000000000000000 */
|
||||
unsigned char rqid[2]; /* rqid. internal to 603 */
|
||||
unsigned char reserved5[2]; /* 0x0000 */
|
||||
unsigned char function_code[2]; /* for PKD, 0x5044 (ascii 'PD') */
|
||||
unsigned char reserved6[2]; /* 0x0000 */
|
||||
unsigned int ToCardLen1; /* (request CPRB len + 3) & -4 */
|
||||
unsigned int ToCardLen2; /* db len 0x00000000 for PKD */
|
||||
unsigned int ToCardLen3; /* 0x00000000 */
|
||||
unsigned int ToCardLen4; /* 0x00000000 */
|
||||
unsigned int FromCardLen1; /* response buffer length */
|
||||
unsigned int FromCardLen2; /* db len 0x00000000 for PKD */
|
||||
unsigned int FromCardLen3; /* 0x00000000 */
|
||||
unsigned int FromCardLen4; /* 0x00000000 */
|
||||
} __packed;
|
||||
|
||||
/**
|
||||
* The type 86 message family is associated with PCICC and PCIXCC cards.
|
||||
*
|
||||
* It contains a message header followed by a CPRB. The CPRB is
|
||||
* the same as the request CPRB, which is described above.
|
||||
*
|
||||
* If format is 1, an error condition exists and no data beyond
|
||||
* the 8-byte message header is of interest.
|
||||
*
|
||||
* The non-error message is shown below.
|
||||
*
|
||||
* Note that all reserved fields must be zeroes.
|
||||
*/
|
||||
struct type86_hdr {
|
||||
unsigned char reserved1; /* 0x00 */
|
||||
unsigned char type; /* 0x86 */
|
||||
unsigned char format; /* 0x01 (error) or 0x02 (ok) */
|
||||
unsigned char reserved2; /* 0x00 */
|
||||
unsigned char reply_code; /* reply code (see above) */
|
||||
unsigned char reserved3[3]; /* 0x000000 */
|
||||
} __packed;
|
||||
|
||||
#define TYPE86_RSP_CODE 0x86
|
||||
#define TYPE86_FMT2 0x02
|
||||
|
||||
struct type86_fmt2_ext {
|
||||
unsigned char reserved[4]; /* 0x00000000 */
|
||||
unsigned char apfs[4]; /* final status */
|
||||
unsigned int count1; /* length of CPRB + parameters */
|
||||
unsigned int offset1; /* offset to CPRB */
|
||||
unsigned int count2; /* 0x00000000 */
|
||||
unsigned int offset2; /* db offset 0x00000000 for PKD */
|
||||
unsigned int count3; /* 0x00000000 */
|
||||
unsigned int offset3; /* 0x00000000 */
|
||||
unsigned int count4; /* 0x00000000 */
|
||||
unsigned int offset4; /* 0x00000000 */
|
||||
} __packed;
|
||||
|
||||
/**
|
||||
* Prepare a type6 CPRB message for random number generation
|
||||
*
|
||||
* @ap_dev: AP device pointer
|
||||
* @ap_msg: pointer to AP message
|
||||
*/
|
||||
static inline void rng_type6CPRB_msgX(struct ap_device *ap_dev,
|
||||
struct ap_message *ap_msg,
|
||||
unsigned random_number_length)
|
||||
{
|
||||
struct {
|
||||
struct type6_hdr hdr;
|
||||
struct CPRBX cprbx;
|
||||
char function_code[2];
|
||||
short int rule_length;
|
||||
char rule[8];
|
||||
short int verb_length;
|
||||
short int key_length;
|
||||
} __packed * msg = ap_msg->message;
|
||||
static struct type6_hdr static_type6_hdrX = {
|
||||
.type = 0x06,
|
||||
.offset1 = 0x00000058,
|
||||
.agent_id = {'C', 'A'},
|
||||
.function_code = {'R', 'L'},
|
||||
.ToCardLen1 = sizeof(*msg) - sizeof(msg->hdr),
|
||||
.FromCardLen1 = sizeof(*msg) - sizeof(msg->hdr),
|
||||
};
|
||||
static struct CPRBX local_cprbx = {
|
||||
.cprb_len = 0x00dc,
|
||||
.cprb_ver_id = 0x02,
|
||||
.func_id = {0x54, 0x32},
|
||||
.req_parml = sizeof(*msg) - sizeof(msg->hdr) -
|
||||
sizeof(msg->cprbx),
|
||||
.rpl_msgbl = sizeof(*msg) - sizeof(msg->hdr),
|
||||
};
|
||||
|
||||
msg->hdr = static_type6_hdrX;
|
||||
msg->hdr.FromCardLen2 = random_number_length,
|
||||
msg->cprbx = local_cprbx;
|
||||
msg->cprbx.rpl_datal = random_number_length,
|
||||
msg->cprbx.domain = AP_QID_QUEUE(ap_dev->qid);
|
||||
memcpy(msg->function_code, msg->hdr.function_code, 0x02);
|
||||
msg->rule_length = 0x0a;
|
||||
memcpy(msg->rule, "RANDOM ", 8);
|
||||
msg->verb_length = 0x02;
|
||||
msg->key_length = 0x02;
|
||||
ap_msg->length = sizeof(*msg);
|
||||
}
|
||||
|
||||
int zcrypt_msgtype6_init(void);
|
||||
void zcrypt_msgtype6_exit(void);
|
||||
|
||||
#endif /* _ZCRYPT_MSGTYPE6_H_ */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,12 +1,13 @@
|
||||
/*
|
||||
* zcrypt 2.1.0
|
||||
*
|
||||
* Copyright IBM Corp. 2001, 2006
|
||||
* Copyright IBM Corp. 2001, 2012
|
||||
* Author(s): Robert Burroughs
|
||||
* Eric Rossman (edrossma@us.ibm.com)
|
||||
*
|
||||
* Hotplug & misc device support: Jochen Roehrig (roehrig@de.ibm.com)
|
||||
* Major cleanup & driver split: Martin Schwidefsky <schwidefsky@de.ibm.com>
|
||||
* MSGTYPE restruct: Holger Dengler <hd@linux.vnet.ibm.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
Reference in New Issue
Block a user