mirror of
https://github.com/AetherDroid/android_kernel_samsung_on5xelte.git
synced 2025-09-08 09:08:05 -04:00
Fixed MTP to work with TWRP
This commit is contained in:
commit
f6dfaef42e
50820 changed files with 20846062 additions and 0 deletions
8
drivers/s390/crypto/Makefile
Normal file
8
drivers/s390/crypto/Makefile
Normal file
|
@ -0,0 +1,8 @@
|
|||
#
|
||||
# S/390 crypto devices
|
||||
#
|
||||
|
||||
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 zcrypt_cex4.o
|
||||
obj-$(CONFIG_ZCRYPT) += zcrypt_msgtype6.o zcrypt_msgtype50.o
|
2076
drivers/s390/crypto/ap_bus.c
Normal file
2076
drivers/s390/crypto/ap_bus.c
Normal file
File diff suppressed because it is too large
Load diff
242
drivers/s390/crypto/ap_bus.h
Normal file
242
drivers/s390/crypto/ap_bus.h
Normal file
|
@ -0,0 +1,242 @@
|
|||
/*
|
||||
* Copyright IBM Corp. 2006, 2012
|
||||
* Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
|
||||
* Martin Schwidefsky <schwidefsky@de.ibm.com>
|
||||
* Ralph Wuerthner <rwuerthn@de.ibm.com>
|
||||
* Felix Beck <felix.beck@de.ibm.com>
|
||||
* Holger Dengler <hd@linux.vnet.ibm.com>
|
||||
*
|
||||
* Adjunct processor bus header file.
|
||||
*
|
||||
* 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 _AP_BUS_H_
|
||||
#define _AP_BUS_H_
|
||||
|
||||
#include <linux/device.h>
|
||||
#include <linux/mod_devicetable.h>
|
||||
#include <linux/types.h>
|
||||
|
||||
#define AP_DEVICES 64 /* Number of AP devices. */
|
||||
#define AP_DOMAINS 256 /* Number of AP domains. */
|
||||
#define AP_MAX_RESET 90 /* Maximum number of resets. */
|
||||
#define AP_RESET_TIMEOUT (HZ*0.7) /* Time in ticks for reset timeouts. */
|
||||
#define AP_CONFIG_TIME 30 /* Time in seconds between AP bus rescans. */
|
||||
#define AP_POLL_TIME 1 /* Time in ticks between receive polls. */
|
||||
|
||||
extern int ap_domain_index;
|
||||
|
||||
/**
|
||||
* The ap_qid_t identifier of an ap queue. It contains a
|
||||
* 6 bit device index and a 4 bit queue index (domain).
|
||||
*/
|
||||
typedef unsigned int ap_qid_t;
|
||||
|
||||
#define AP_MKQID(_device, _queue) (((_device) & 63) << 8 | ((_queue) & 255))
|
||||
#define AP_QID_DEVICE(_qid) (((_qid) >> 8) & 63)
|
||||
#define AP_QID_QUEUE(_qid) ((_qid) & 255)
|
||||
|
||||
/**
|
||||
* structy ap_queue_status - Holds the AP queue status.
|
||||
* @queue_empty: Shows if queue is empty
|
||||
* @replies_waiting: Waiting replies
|
||||
* @queue_full: Is 1 if the queue is full
|
||||
* @pad: A 4 bit pad
|
||||
* @int_enabled: Shows if interrupts are enabled for the AP
|
||||
* @response_conde: Holds the 8 bit response code
|
||||
* @pad2: A 16 bit pad
|
||||
*
|
||||
* The ap queue status word is returned by all three AP functions
|
||||
* (PQAP, NQAP and DQAP). There's a set of flags in the first
|
||||
* byte, followed by a 1 byte response code.
|
||||
*/
|
||||
struct ap_queue_status {
|
||||
unsigned int queue_empty : 1;
|
||||
unsigned int replies_waiting : 1;
|
||||
unsigned int queue_full : 1;
|
||||
unsigned int pad1 : 4;
|
||||
unsigned int int_enabled : 1;
|
||||
unsigned int response_code : 8;
|
||||
unsigned int pad2 : 16;
|
||||
} __packed;
|
||||
|
||||
#define AP_QUEUE_STATUS_INVALID \
|
||||
{ 1, 1, 1, 0xF, 1, 0xFF, 0xFFFF }
|
||||
|
||||
static inline
|
||||
int ap_queue_status_invalid_test(struct ap_queue_status *status)
|
||||
{
|
||||
struct ap_queue_status invalid = AP_QUEUE_STATUS_INVALID;
|
||||
return !(memcmp(status, &invalid, sizeof(struct ap_queue_status)));
|
||||
}
|
||||
|
||||
#define AP_MAX_BITS 31
|
||||
static inline int ap_test_bit(unsigned int *ptr, unsigned int nr)
|
||||
{
|
||||
if (nr > AP_MAX_BITS)
|
||||
return 0;
|
||||
return (*ptr & (0x80000000u >> nr)) != 0;
|
||||
}
|
||||
|
||||
#define AP_RESPONSE_NORMAL 0x00
|
||||
#define AP_RESPONSE_Q_NOT_AVAIL 0x01
|
||||
#define AP_RESPONSE_RESET_IN_PROGRESS 0x02
|
||||
#define AP_RESPONSE_DECONFIGURED 0x03
|
||||
#define AP_RESPONSE_CHECKSTOPPED 0x04
|
||||
#define AP_RESPONSE_BUSY 0x05
|
||||
#define AP_RESPONSE_INVALID_ADDRESS 0x06
|
||||
#define AP_RESPONSE_OTHERWISE_CHANGED 0x07
|
||||
#define AP_RESPONSE_Q_FULL 0x10
|
||||
#define AP_RESPONSE_NO_PENDING_REPLY 0x10
|
||||
#define AP_RESPONSE_INDEX_TOO_BIG 0x11
|
||||
#define AP_RESPONSE_NO_FIRST_PART 0x13
|
||||
#define AP_RESPONSE_MESSAGE_TOO_BIG 0x15
|
||||
#define AP_RESPONSE_REQ_FAC_NOT_INST 0x16
|
||||
|
||||
/*
|
||||
* Known device types
|
||||
*/
|
||||
#define AP_DEVICE_TYPE_PCICC 3
|
||||
#define AP_DEVICE_TYPE_PCICA 4
|
||||
#define AP_DEVICE_TYPE_PCIXCC 5
|
||||
#define AP_DEVICE_TYPE_CEX2A 6
|
||||
#define AP_DEVICE_TYPE_CEX2C 7
|
||||
#define AP_DEVICE_TYPE_CEX3A 8
|
||||
#define AP_DEVICE_TYPE_CEX3C 9
|
||||
#define AP_DEVICE_TYPE_CEX4 10
|
||||
|
||||
/*
|
||||
* Known function facilities
|
||||
*/
|
||||
#define AP_FUNC_MEX4K 1
|
||||
#define AP_FUNC_CRT4K 2
|
||||
#define AP_FUNC_COPRO 3
|
||||
#define AP_FUNC_ACCEL 4
|
||||
#define AP_FUNC_EP11 5
|
||||
#define AP_FUNC_APXA 6
|
||||
|
||||
/*
|
||||
* AP reset flag states
|
||||
*/
|
||||
#define AP_RESET_IGNORE 0 /* request timeout will be ignored */
|
||||
#define AP_RESET_ARMED 1 /* request timeout timer is active */
|
||||
#define AP_RESET_DO 2 /* AP reset required */
|
||||
|
||||
struct ap_device;
|
||||
struct ap_message;
|
||||
|
||||
struct ap_driver {
|
||||
struct device_driver driver;
|
||||
struct ap_device_id *ids;
|
||||
|
||||
int (*probe)(struct ap_device *);
|
||||
void (*remove)(struct ap_device *);
|
||||
int request_timeout; /* request timeout in jiffies */
|
||||
};
|
||||
|
||||
#define to_ap_drv(x) container_of((x), struct ap_driver, driver)
|
||||
|
||||
int ap_driver_register(struct ap_driver *, struct module *, char *);
|
||||
void ap_driver_unregister(struct ap_driver *);
|
||||
|
||||
struct ap_device {
|
||||
struct device device;
|
||||
struct ap_driver *drv; /* Pointer to AP device driver. */
|
||||
spinlock_t lock; /* Per device lock. */
|
||||
struct list_head list; /* private list of all AP devices. */
|
||||
|
||||
ap_qid_t qid; /* AP queue id. */
|
||||
int queue_depth; /* AP queue depth.*/
|
||||
int device_type; /* AP device type. */
|
||||
int raw_hwtype; /* AP raw hardware type. */
|
||||
unsigned int functions; /* AP device function bitfield. */
|
||||
int unregistered; /* marks AP device as unregistered */
|
||||
struct timer_list timeout; /* Timer for request timeouts. */
|
||||
int reset; /* Reset required after req. timeout. */
|
||||
|
||||
int queue_count; /* # messages currently on AP queue. */
|
||||
|
||||
struct list_head pendingq; /* List of message sent to AP queue. */
|
||||
int pendingq_count; /* # requests on pendingq list. */
|
||||
struct list_head requestq; /* List of message yet to be sent. */
|
||||
int requestq_count; /* # requests on requestq list. */
|
||||
int total_request_count; /* # requests ever for this AP device. */
|
||||
|
||||
struct ap_message *reply; /* Per device reply message. */
|
||||
|
||||
void *private; /* ap driver private pointer. */
|
||||
};
|
||||
|
||||
#define to_ap_dev(x) container_of((x), struct ap_device, device)
|
||||
|
||||
struct ap_message {
|
||||
struct list_head list; /* Request queueing. */
|
||||
unsigned long long psmid; /* Message id. */
|
||||
void *message; /* Pointer to message buffer. */
|
||||
size_t length; /* Message length. */
|
||||
|
||||
void *private; /* ap driver private pointer. */
|
||||
unsigned int special:1; /* Used for special commands. */
|
||||
/* receive is called from tasklet context */
|
||||
void (*receive)(struct ap_device *, struct ap_message *,
|
||||
struct ap_message *);
|
||||
};
|
||||
|
||||
struct ap_config_info {
|
||||
unsigned int special_command:1;
|
||||
unsigned int ap_extended:1;
|
||||
unsigned char reserved1:6;
|
||||
unsigned char reserved2[15];
|
||||
unsigned int apm[8]; /* AP ID mask */
|
||||
unsigned int aqm[8]; /* AP queue mask */
|
||||
unsigned int adm[8]; /* AP domain mask */
|
||||
unsigned char reserved4[16];
|
||||
} __packed;
|
||||
|
||||
#define AP_DEVICE(dt) \
|
||||
.dev_type=(dt), \
|
||||
.match_flags=AP_DEVICE_ID_MATCH_DEVICE_TYPE,
|
||||
|
||||
/**
|
||||
* ap_init_message() - Initialize ap_message.
|
||||
* Initialize a message before using. Otherwise this might result in
|
||||
* unexpected behaviour.
|
||||
*/
|
||||
static inline void ap_init_message(struct ap_message *ap_msg)
|
||||
{
|
||||
ap_msg->psmid = 0;
|
||||
ap_msg->length = 0;
|
||||
ap_msg->special = 0;
|
||||
ap_msg->receive = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Note: don't use ap_send/ap_recv after using ap_queue_message
|
||||
* for the first time. Otherwise the ap message queue will get
|
||||
* confused.
|
||||
*/
|
||||
int ap_send(ap_qid_t, unsigned long long, void *, size_t);
|
||||
int ap_recv(ap_qid_t, unsigned long long *, void *, size_t);
|
||||
|
||||
void ap_queue_message(struct ap_device *ap_dev, struct ap_message *ap_msg);
|
||||
void ap_cancel_message(struct ap_device *ap_dev, struct ap_message *ap_msg);
|
||||
void ap_flush_queue(struct ap_device *ap_dev);
|
||||
void ap_bus_force_rescan(void);
|
||||
|
||||
int ap_module_init(void);
|
||||
void ap_module_exit(void);
|
||||
|
||||
#endif /* _AP_BUS_H_ */
|
1489
drivers/s390/crypto/zcrypt_api.c
Normal file
1489
drivers/s390/crypto/zcrypt_api.c
Normal file
File diff suppressed because it is too large
Load diff
139
drivers/s390/crypto/zcrypt_api.h
Normal file
139
drivers/s390/crypto/zcrypt_api.h
Normal file
|
@ -0,0 +1,139 @@
|
|||
/*
|
||||
* zcrypt 2.1.0
|
||||
*
|
||||
* Copyright IBM Corp. 2001, 2012
|
||||
* Author(s): Robert Burroughs
|
||||
* Eric Rossman (edrossma@us.ibm.com)
|
||||
* Cornelia Huck <cornelia.huck@de.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
|
||||
* 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_API_H_
|
||||
#define _ZCRYPT_API_H_
|
||||
|
||||
#include <linux/atomic.h>
|
||||
#include <asm/debug.h>
|
||||
#include <asm/zcrypt.h>
|
||||
#include "ap_bus.h"
|
||||
|
||||
/* deprecated status calls */
|
||||
#define ICAZ90STATUS _IOR(ZCRYPT_IOCTL_MAGIC, 0x10, struct ica_z90_status)
|
||||
#define Z90STAT_PCIXCCCOUNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x43, int)
|
||||
|
||||
/**
|
||||
* This structure is deprecated and the corresponding ioctl() has been
|
||||
* replaced with individual ioctl()s for each piece of data!
|
||||
*/
|
||||
struct ica_z90_status {
|
||||
int totalcount;
|
||||
int leedslitecount; // PCICA
|
||||
int leeds2count; // PCICC
|
||||
// int PCIXCCCount; is not in struct for backward compatibility
|
||||
int requestqWaitCount;
|
||||
int pendingqWaitCount;
|
||||
int totalOpenCount;
|
||||
int cryptoDomain;
|
||||
// status: 0=not there, 1=PCICA, 2=PCICC, 3=PCIXCC_MCL2, 4=PCIXCC_MCL3,
|
||||
// 5=CEX2C
|
||||
unsigned char status[64];
|
||||
// qdepth: # work elements waiting for each device
|
||||
unsigned char qdepth[64];
|
||||
};
|
||||
|
||||
/**
|
||||
* device type for an actual device is either PCICA, PCICC, PCIXCC_MCL2,
|
||||
* PCIXCC_MCL3, CEX2C, or CEX2A
|
||||
*
|
||||
* NOTE: PCIXCC_MCL3 refers to a PCIXCC with May 2004 version of Licensed
|
||||
* Internal Code (LIC) (EC J12220 level 29).
|
||||
* PCIXCC_MCL2 refers to any LIC before this level.
|
||||
*/
|
||||
#define ZCRYPT_PCICA 1
|
||||
#define ZCRYPT_PCICC 2
|
||||
#define ZCRYPT_PCIXCC_MCL2 3
|
||||
#define ZCRYPT_PCIXCC_MCL3 4
|
||||
#define ZCRYPT_CEX2C 5
|
||||
#define ZCRYPT_CEX2A 6
|
||||
#define ZCRYPT_CEX3C 7
|
||||
#define ZCRYPT_CEX3A 8
|
||||
#define ZCRYPT_CEX4 10
|
||||
|
||||
/**
|
||||
* Large random numbers are pulled in 4096 byte chunks from the crypto cards
|
||||
* and stored in a page. Be careful when increasing this buffer due to size
|
||||
* limitations for AP requests.
|
||||
*/
|
||||
#define ZCRYPT_RNG_BUFFER_SIZE 4096
|
||||
|
||||
struct zcrypt_device;
|
||||
|
||||
struct zcrypt_ops {
|
||||
long (*rsa_modexpo)(struct zcrypt_device *, struct ica_rsa_modexpo *);
|
||||
long (*rsa_modexpo_crt)(struct zcrypt_device *,
|
||||
struct ica_rsa_modexpo_crt *);
|
||||
long (*send_cprb)(struct zcrypt_device *, struct ica_xcRB *);
|
||||
long (*send_ep11_cprb)(struct zcrypt_device *, struct ep11_urb *);
|
||||
long (*rng)(struct zcrypt_device *, char *);
|
||||
struct list_head list; /* zcrypt ops list. */
|
||||
struct module *owner;
|
||||
int variant;
|
||||
};
|
||||
|
||||
struct zcrypt_device {
|
||||
struct list_head list; /* Device list. */
|
||||
spinlock_t lock; /* Per device lock. */
|
||||
struct kref refcount; /* device refcounting */
|
||||
struct ap_device *ap_dev; /* The "real" ap device. */
|
||||
struct zcrypt_ops *ops; /* Crypto operations. */
|
||||
int online; /* User online/offline */
|
||||
|
||||
int user_space_type; /* User space device id. */
|
||||
char *type_string; /* User space device name. */
|
||||
int min_mod_size; /* Min number of bits. */
|
||||
int max_mod_size; /* Max number of bits. */
|
||||
int short_crt; /* Card has crt length restriction. */
|
||||
int speed_rating; /* Speed of the crypto device. */
|
||||
|
||||
int request_count; /* # current requests. */
|
||||
|
||||
struct ap_message reply; /* Per-device reply structure. */
|
||||
int max_exp_bit_length;
|
||||
|
||||
debug_info_t *dbf_area; /* debugging */
|
||||
};
|
||||
|
||||
/* transport layer rescanning */
|
||||
extern atomic_t zcrypt_rescan_req;
|
||||
|
||||
struct zcrypt_device *zcrypt_device_alloc(size_t);
|
||||
void zcrypt_device_free(struct zcrypt_device *);
|
||||
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);
|
||||
|
||||
#endif /* _ZCRYPT_API_H_ */
|
348
drivers/s390/crypto/zcrypt_cca_key.h
Normal file
348
drivers/s390/crypto/zcrypt_cca_key.h
Normal file
|
@ -0,0 +1,348 @@
|
|||
/*
|
||||
* zcrypt 2.1.0
|
||||
*
|
||||
* Copyright IBM Corp. 2001, 2006
|
||||
* 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>
|
||||
*
|
||||
* 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_CCA_KEY_H_
|
||||
#define _ZCRYPT_CCA_KEY_H_
|
||||
|
||||
struct T6_keyBlock_hdr {
|
||||
unsigned short blen;
|
||||
unsigned short ulen;
|
||||
unsigned short flags;
|
||||
};
|
||||
|
||||
/**
|
||||
* mapping for the cca private ME key token.
|
||||
* Three parts of interest here: the header, the private section and
|
||||
* the public section.
|
||||
*
|
||||
* mapping for the cca key token header
|
||||
*/
|
||||
struct cca_token_hdr {
|
||||
unsigned char token_identifier;
|
||||
unsigned char version;
|
||||
unsigned short token_length;
|
||||
unsigned char reserved[4];
|
||||
} __attribute__((packed));
|
||||
|
||||
#define CCA_TKN_HDR_ID_EXT 0x1E
|
||||
|
||||
/**
|
||||
* mapping for the cca private ME section
|
||||
*/
|
||||
struct cca_private_ext_ME_sec {
|
||||
unsigned char section_identifier;
|
||||
unsigned char version;
|
||||
unsigned short section_length;
|
||||
unsigned char private_key_hash[20];
|
||||
unsigned char reserved1[4];
|
||||
unsigned char key_format;
|
||||
unsigned char reserved2;
|
||||
unsigned char key_name_hash[20];
|
||||
unsigned char key_use_flags[4];
|
||||
unsigned char reserved3[6];
|
||||
unsigned char reserved4[24];
|
||||
unsigned char confounder[24];
|
||||
unsigned char exponent[128];
|
||||
unsigned char modulus[128];
|
||||
} __attribute__((packed));
|
||||
|
||||
#define CCA_PVT_USAGE_ALL 0x80
|
||||
|
||||
/**
|
||||
* mapping for the cca public section
|
||||
* In a private key, the modulus doesn't appear in the public
|
||||
* section. So, an arbitrary public exponent of 0x010001 will be
|
||||
* used, for a section length of 0x0F always.
|
||||
*/
|
||||
struct cca_public_sec {
|
||||
unsigned char section_identifier;
|
||||
unsigned char version;
|
||||
unsigned short section_length;
|
||||
unsigned char reserved[2];
|
||||
unsigned short exponent_len;
|
||||
unsigned short modulus_bit_len;
|
||||
unsigned short modulus_byte_len; /* In a private key, this is 0 */
|
||||
} __attribute__((packed));
|
||||
|
||||
/**
|
||||
* mapping for the cca private CRT key 'token'
|
||||
* The first three parts (the only parts considered in this release)
|
||||
* are: the header, the private section and the public section.
|
||||
* The header and public section are the same as for the
|
||||
* struct cca_private_ext_ME
|
||||
*
|
||||
* Following the structure are the quantities p, q, dp, dq, u, pad,
|
||||
* and modulus, in that order, where pad_len is the modulo 8
|
||||
* complement of the residue modulo 8 of the sum of
|
||||
* (p_len + q_len + dp_len + dq_len + u_len).
|
||||
*/
|
||||
struct cca_pvt_ext_CRT_sec {
|
||||
unsigned char section_identifier;
|
||||
unsigned char version;
|
||||
unsigned short section_length;
|
||||
unsigned char private_key_hash[20];
|
||||
unsigned char reserved1[4];
|
||||
unsigned char key_format;
|
||||
unsigned char reserved2;
|
||||
unsigned char key_name_hash[20];
|
||||
unsigned char key_use_flags[4];
|
||||
unsigned short p_len;
|
||||
unsigned short q_len;
|
||||
unsigned short dp_len;
|
||||
unsigned short dq_len;
|
||||
unsigned short u_len;
|
||||
unsigned short mod_len;
|
||||
unsigned char reserved3[4];
|
||||
unsigned short pad_len;
|
||||
unsigned char reserved4[52];
|
||||
unsigned char confounder[8];
|
||||
} __attribute__((packed));
|
||||
|
||||
#define CCA_PVT_EXT_CRT_SEC_ID_PVT 0x08
|
||||
#define CCA_PVT_EXT_CRT_SEC_FMT_CL 0x40
|
||||
|
||||
/**
|
||||
* Set up private key fields of a type6 MEX message.
|
||||
* Note that all numerics in the key token are big-endian,
|
||||
* while the entries in the key block header are little-endian.
|
||||
*
|
||||
* @mex: pointer to user input data
|
||||
* @p: pointer to memory area for the key
|
||||
*
|
||||
* Returns the size of the key area or -EFAULT
|
||||
*/
|
||||
static inline int zcrypt_type6_mex_key_de(struct ica_rsa_modexpo *mex,
|
||||
void *p, int big_endian)
|
||||
{
|
||||
static struct cca_token_hdr static_pvt_me_hdr = {
|
||||
.token_identifier = 0x1E,
|
||||
.token_length = 0x0183,
|
||||
};
|
||||
static struct cca_private_ext_ME_sec static_pvt_me_sec = {
|
||||
.section_identifier = 0x02,
|
||||
.section_length = 0x016C,
|
||||
.key_use_flags = {0x80,0x00,0x00,0x00},
|
||||
};
|
||||
static struct cca_public_sec static_pub_me_sec = {
|
||||
.section_identifier = 0x04,
|
||||
.section_length = 0x000F,
|
||||
.exponent_len = 0x0003,
|
||||
};
|
||||
static char pk_exponent[3] = { 0x01, 0x00, 0x01 };
|
||||
struct {
|
||||
struct T6_keyBlock_hdr t6_hdr;
|
||||
struct cca_token_hdr pvtMeHdr;
|
||||
struct cca_private_ext_ME_sec pvtMeSec;
|
||||
struct cca_public_sec pubMeSec;
|
||||
char exponent[3];
|
||||
} __attribute__((packed)) *key = p;
|
||||
unsigned char *temp;
|
||||
|
||||
memset(key, 0, sizeof(*key));
|
||||
|
||||
if (big_endian) {
|
||||
key->t6_hdr.blen = cpu_to_be16(0x189);
|
||||
key->t6_hdr.ulen = cpu_to_be16(0x189 - 2);
|
||||
} else {
|
||||
key->t6_hdr.blen = cpu_to_le16(0x189);
|
||||
key->t6_hdr.ulen = cpu_to_le16(0x189 - 2);
|
||||
}
|
||||
key->pvtMeHdr = static_pvt_me_hdr;
|
||||
key->pvtMeSec = static_pvt_me_sec;
|
||||
key->pubMeSec = static_pub_me_sec;
|
||||
/*
|
||||
* In a private key, the modulus doesn't appear in the public
|
||||
* section. So, an arbitrary public exponent of 0x010001 will be
|
||||
* used.
|
||||
*/
|
||||
memcpy(key->exponent, pk_exponent, 3);
|
||||
|
||||
/* key parameter block */
|
||||
temp = key->pvtMeSec.exponent +
|
||||
sizeof(key->pvtMeSec.exponent) - mex->inputdatalength;
|
||||
if (copy_from_user(temp, mex->b_key, mex->inputdatalength))
|
||||
return -EFAULT;
|
||||
|
||||
/* modulus */
|
||||
temp = key->pvtMeSec.modulus +
|
||||
sizeof(key->pvtMeSec.modulus) - mex->inputdatalength;
|
||||
if (copy_from_user(temp, mex->n_modulus, mex->inputdatalength))
|
||||
return -EFAULT;
|
||||
key->pubMeSec.modulus_bit_len = 8 * mex->inputdatalength;
|
||||
return sizeof(*key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up private key fields of a type6 MEX message. The _pad variant
|
||||
* strips leading zeroes from the b_key.
|
||||
* Note that all numerics in the key token are big-endian,
|
||||
* while the entries in the key block header are little-endian.
|
||||
*
|
||||
* @mex: pointer to user input data
|
||||
* @p: pointer to memory area for the key
|
||||
*
|
||||
* Returns the size of the key area or -EFAULT
|
||||
*/
|
||||
static inline int zcrypt_type6_mex_key_en(struct ica_rsa_modexpo *mex,
|
||||
void *p, int big_endian)
|
||||
{
|
||||
static struct cca_token_hdr static_pub_hdr = {
|
||||
.token_identifier = 0x1E,
|
||||
};
|
||||
static struct cca_public_sec static_pub_sec = {
|
||||
.section_identifier = 0x04,
|
||||
};
|
||||
struct {
|
||||
struct T6_keyBlock_hdr t6_hdr;
|
||||
struct cca_token_hdr pubHdr;
|
||||
struct cca_public_sec pubSec;
|
||||
char exponent[0];
|
||||
} __attribute__((packed)) *key = p;
|
||||
unsigned char *temp;
|
||||
int i;
|
||||
|
||||
memset(key, 0, sizeof(*key));
|
||||
|
||||
key->pubHdr = static_pub_hdr;
|
||||
key->pubSec = static_pub_sec;
|
||||
|
||||
/* key parameter block */
|
||||
temp = key->exponent;
|
||||
if (copy_from_user(temp, mex->b_key, mex->inputdatalength))
|
||||
return -EFAULT;
|
||||
/* Strip leading zeroes from b_key. */
|
||||
for (i = 0; i < mex->inputdatalength; i++)
|
||||
if (temp[i])
|
||||
break;
|
||||
if (i >= mex->inputdatalength)
|
||||
return -EINVAL;
|
||||
memmove(temp, temp + i, mex->inputdatalength - i);
|
||||
temp += mex->inputdatalength - i;
|
||||
/* modulus */
|
||||
if (copy_from_user(temp, mex->n_modulus, mex->inputdatalength))
|
||||
return -EFAULT;
|
||||
|
||||
key->pubSec.modulus_bit_len = 8 * mex->inputdatalength;
|
||||
key->pubSec.modulus_byte_len = mex->inputdatalength;
|
||||
key->pubSec.exponent_len = mex->inputdatalength - i;
|
||||
key->pubSec.section_length = sizeof(key->pubSec) +
|
||||
2*mex->inputdatalength - i;
|
||||
key->pubHdr.token_length =
|
||||
key->pubSec.section_length + sizeof(key->pubHdr);
|
||||
if (big_endian) {
|
||||
key->t6_hdr.ulen = cpu_to_be16(key->pubHdr.token_length + 4);
|
||||
key->t6_hdr.blen = cpu_to_be16(key->pubHdr.token_length + 6);
|
||||
} else {
|
||||
key->t6_hdr.ulen = cpu_to_le16(key->pubHdr.token_length + 4);
|
||||
key->t6_hdr.blen = cpu_to_le16(key->pubHdr.token_length + 6);
|
||||
}
|
||||
return sizeof(*key) + 2*mex->inputdatalength - i;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up private key fields of a type6 CRT message.
|
||||
* Note that all numerics in the key token are big-endian,
|
||||
* while the entries in the key block header are little-endian.
|
||||
*
|
||||
* @mex: pointer to user input data
|
||||
* @p: pointer to memory area for the key
|
||||
*
|
||||
* Returns the size of the key area or -EFAULT
|
||||
*/
|
||||
static inline int zcrypt_type6_crt_key(struct ica_rsa_modexpo_crt *crt,
|
||||
void *p, int big_endian)
|
||||
{
|
||||
static struct cca_public_sec static_cca_pub_sec = {
|
||||
.section_identifier = 4,
|
||||
.section_length = 0x000f,
|
||||
.exponent_len = 0x0003,
|
||||
};
|
||||
static char pk_exponent[3] = { 0x01, 0x00, 0x01 };
|
||||
struct {
|
||||
struct T6_keyBlock_hdr t6_hdr;
|
||||
struct cca_token_hdr token;
|
||||
struct cca_pvt_ext_CRT_sec pvt;
|
||||
char key_parts[0];
|
||||
} __attribute__((packed)) *key = p;
|
||||
struct cca_public_sec *pub;
|
||||
int short_len, long_len, pad_len, key_len, size;
|
||||
|
||||
memset(key, 0, sizeof(*key));
|
||||
|
||||
short_len = crt->inputdatalength / 2;
|
||||
long_len = short_len + 8;
|
||||
pad_len = -(3*long_len + 2*short_len) & 7;
|
||||
key_len = 3*long_len + 2*short_len + pad_len + crt->inputdatalength;
|
||||
size = sizeof(*key) + key_len + sizeof(*pub) + 3;
|
||||
|
||||
/* parameter block.key block */
|
||||
if (big_endian) {
|
||||
key->t6_hdr.blen = cpu_to_be16(size);
|
||||
key->t6_hdr.ulen = cpu_to_be16(size - 2);
|
||||
} else {
|
||||
key->t6_hdr.blen = cpu_to_le16(size);
|
||||
key->t6_hdr.ulen = cpu_to_le16(size - 2);
|
||||
}
|
||||
|
||||
/* key token header */
|
||||
key->token.token_identifier = CCA_TKN_HDR_ID_EXT;
|
||||
key->token.token_length = size - 6;
|
||||
|
||||
/* private section */
|
||||
key->pvt.section_identifier = CCA_PVT_EXT_CRT_SEC_ID_PVT;
|
||||
key->pvt.section_length = sizeof(key->pvt) + key_len;
|
||||
key->pvt.key_format = CCA_PVT_EXT_CRT_SEC_FMT_CL;
|
||||
key->pvt.key_use_flags[0] = CCA_PVT_USAGE_ALL;
|
||||
key->pvt.p_len = key->pvt.dp_len = key->pvt.u_len = long_len;
|
||||
key->pvt.q_len = key->pvt.dq_len = short_len;
|
||||
key->pvt.mod_len = crt->inputdatalength;
|
||||
key->pvt.pad_len = pad_len;
|
||||
|
||||
/* key parts */
|
||||
if (copy_from_user(key->key_parts, crt->np_prime, long_len) ||
|
||||
copy_from_user(key->key_parts + long_len,
|
||||
crt->nq_prime, short_len) ||
|
||||
copy_from_user(key->key_parts + long_len + short_len,
|
||||
crt->bp_key, long_len) ||
|
||||
copy_from_user(key->key_parts + 2*long_len + short_len,
|
||||
crt->bq_key, short_len) ||
|
||||
copy_from_user(key->key_parts + 2*long_len + 2*short_len,
|
||||
crt->u_mult_inv, long_len))
|
||||
return -EFAULT;
|
||||
memset(key->key_parts + 3*long_len + 2*short_len + pad_len,
|
||||
0xff, crt->inputdatalength);
|
||||
pub = (struct cca_public_sec *)(key->key_parts + key_len);
|
||||
*pub = static_cca_pub_sec;
|
||||
pub->modulus_bit_len = 8 * crt->inputdatalength;
|
||||
/*
|
||||
* In a private key, the modulus doesn't appear in the public
|
||||
* section. So, an arbitrary public exponent of 0x010001 will be
|
||||
* used.
|
||||
*/
|
||||
memcpy((char *) (pub + 1), pk_exponent, 3);
|
||||
return size;
|
||||
}
|
||||
|
||||
#endif /* _ZCRYPT_CCA_KEY_H_ */
|
164
drivers/s390/crypto/zcrypt_cex2a.c
Normal file
164
drivers/s390/crypto/zcrypt_cex2a.c
Normal file
|
@ -0,0 +1,164 @@
|
|||
/*
|
||||
* 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>
|
||||
* 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
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/atomic.h>
|
||||
#include <asm/uaccess.h>
|
||||
|
||||
#include "ap_bus.h"
|
||||
#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 */
|
||||
#define CEX3A_MIN_MOD_SIZE CEX2A_MIN_MOD_SIZE
|
||||
#define CEX3A_MAX_MOD_SIZE 512 /* 4096 bits */
|
||||
|
||||
#define CEX2A_SPEED_RATING 970
|
||||
#define CEX3A_SPEED_RATING 900 /* Fixme: Needs finetuning */
|
||||
|
||||
#define CEX2A_MAX_MESSAGE_SIZE 0x390 /* sizeof(struct type50_crb2_msg) */
|
||||
#define CEX2A_MAX_RESPONSE_SIZE 0x110 /* max outputdatalength + type80_hdr */
|
||||
|
||||
#define CEX3A_MAX_RESPONSE_SIZE 0x210 /* 512 bit modulus
|
||||
* (max outputdatalength) +
|
||||
* type80_hdr*/
|
||||
#define CEX3A_MAX_MESSAGE_SIZE sizeof(struct type50_crb3_msg)
|
||||
|
||||
#define CEX2A_CLEANUP_TIME (15*HZ)
|
||||
#define CEX3A_CLEANUP_TIME CEX2A_CLEANUP_TIME
|
||||
|
||||
static struct ap_device_id zcrypt_cex2a_ids[] = {
|
||||
{ AP_DEVICE(AP_DEVICE_TYPE_CEX2A) },
|
||||
{ AP_DEVICE(AP_DEVICE_TYPE_CEX3A) },
|
||||
{ /* end of list */ },
|
||||
};
|
||||
|
||||
MODULE_DEVICE_TABLE(ap, zcrypt_cex2a_ids);
|
||||
MODULE_AUTHOR("IBM Corporation");
|
||||
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 struct ap_driver zcrypt_cex2a_driver = {
|
||||
.probe = zcrypt_cex2a_probe,
|
||||
.remove = zcrypt_cex2a_remove,
|
||||
.ids = zcrypt_cex2a_ids,
|
||||
.request_timeout = CEX2A_CLEANUP_TIME,
|
||||
};
|
||||
|
||||
/**
|
||||
* Probe function for CEX2A cards. It always accepts the AP device
|
||||
* since the bus_match already checked the hardware type.
|
||||
* @ap_dev: pointer to the AP device.
|
||||
*/
|
||||
static int zcrypt_cex2a_probe(struct ap_device *ap_dev)
|
||||
{
|
||||
struct zcrypt_device *zdev = NULL;
|
||||
int rc = 0;
|
||||
|
||||
switch (ap_dev->device_type) {
|
||||
case AP_DEVICE_TYPE_CEX2A:
|
||||
zdev = zcrypt_device_alloc(CEX2A_MAX_RESPONSE_SIZE);
|
||||
if (!zdev)
|
||||
return -ENOMEM;
|
||||
zdev->user_space_type = ZCRYPT_CEX2A;
|
||||
zdev->type_string = "CEX2A";
|
||||
zdev->min_mod_size = CEX2A_MIN_MOD_SIZE;
|
||||
zdev->max_mod_size = CEX2A_MAX_MOD_SIZE;
|
||||
zdev->short_crt = 1;
|
||||
zdev->speed_rating = CEX2A_SPEED_RATING;
|
||||
zdev->max_exp_bit_length = CEX2A_MAX_MOD_SIZE;
|
||||
break;
|
||||
case AP_DEVICE_TYPE_CEX3A:
|
||||
zdev = zcrypt_device_alloc(CEX3A_MAX_RESPONSE_SIZE);
|
||||
if (!zdev)
|
||||
return -ENOMEM;
|
||||
zdev->user_space_type = ZCRYPT_CEX3A;
|
||||
zdev->type_string = "CEX3A";
|
||||
zdev->min_mod_size = CEX2A_MIN_MOD_SIZE;
|
||||
zdev->max_mod_size = CEX2A_MAX_MOD_SIZE;
|
||||
zdev->max_exp_bit_length = CEX2A_MAX_MOD_SIZE;
|
||||
if (ap_test_bit(&ap_dev->functions, AP_FUNC_MEX4K) &&
|
||||
ap_test_bit(&ap_dev->functions, AP_FUNC_CRT4K)) {
|
||||
zdev->max_mod_size = CEX3A_MAX_MOD_SIZE;
|
||||
zdev->max_exp_bit_length = CEX3A_MAX_MOD_SIZE;
|
||||
}
|
||||
zdev->short_crt = 1;
|
||||
zdev->speed_rating = CEX3A_SPEED_RATING;
|
||||
break;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is called to remove the extended CEX2A driver information
|
||||
* if an AP device is removed.
|
||||
*/
|
||||
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)
|
||||
{
|
||||
return ap_driver_register(&zcrypt_cex2a_driver, THIS_MODULE, "cex2a");
|
||||
}
|
||||
|
||||
void __exit zcrypt_cex2a_exit(void)
|
||||
{
|
||||
ap_driver_unregister(&zcrypt_cex2a_driver);
|
||||
}
|
||||
|
||||
module_init(zcrypt_cex2a_init);
|
||||
module_exit(zcrypt_cex2a_exit);
|
149
drivers/s390/crypto/zcrypt_cex2a.h
Normal file
149
drivers/s390/crypto/zcrypt_cex2a.h
Normal file
|
@ -0,0 +1,149 @@
|
|||
/*
|
||||
* zcrypt 2.1.0
|
||||
*
|
||||
* Copyright IBM Corp. 2001, 2006
|
||||
* 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>
|
||||
*
|
||||
* 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_CEX2A_H_
|
||||
#define _ZCRYPT_CEX2A_H_
|
||||
|
||||
/**
|
||||
* The type 50 message family is associated with a CEX2A card.
|
||||
*
|
||||
* The four members of the family are described below.
|
||||
*
|
||||
* Note that all unsigned char arrays are right-justified and left-padded
|
||||
* with zeroes.
|
||||
*
|
||||
* Note that all reserved fields must be zeroes.
|
||||
*/
|
||||
struct type50_hdr {
|
||||
unsigned char reserved1;
|
||||
unsigned char msg_type_code; /* 0x50 */
|
||||
unsigned short msg_len;
|
||||
unsigned char reserved2;
|
||||
unsigned char ignored;
|
||||
unsigned short reserved3;
|
||||
} __attribute__((packed));
|
||||
|
||||
#define TYPE50_TYPE_CODE 0x50
|
||||
|
||||
#define TYPE50_MEB1_FMT 0x0001
|
||||
#define TYPE50_MEB2_FMT 0x0002
|
||||
#define TYPE50_MEB3_FMT 0x0003
|
||||
#define TYPE50_CRB1_FMT 0x0011
|
||||
#define TYPE50_CRB2_FMT 0x0012
|
||||
#define TYPE50_CRB3_FMT 0x0013
|
||||
|
||||
/* Mod-Exp, with a small modulus */
|
||||
struct type50_meb1_msg {
|
||||
struct type50_hdr header;
|
||||
unsigned short keyblock_type; /* 0x0001 */
|
||||
unsigned char reserved[6];
|
||||
unsigned char exponent[128];
|
||||
unsigned char modulus[128];
|
||||
unsigned char message[128];
|
||||
} __attribute__((packed));
|
||||
|
||||
/* Mod-Exp, with a large modulus */
|
||||
struct type50_meb2_msg {
|
||||
struct type50_hdr header;
|
||||
unsigned short keyblock_type; /* 0x0002 */
|
||||
unsigned char reserved[6];
|
||||
unsigned char exponent[256];
|
||||
unsigned char modulus[256];
|
||||
unsigned char message[256];
|
||||
} __attribute__((packed));
|
||||
|
||||
/* Mod-Exp, with a larger modulus */
|
||||
struct type50_meb3_msg {
|
||||
struct type50_hdr header;
|
||||
unsigned short keyblock_type; /* 0x0003 */
|
||||
unsigned char reserved[6];
|
||||
unsigned char exponent[512];
|
||||
unsigned char modulus[512];
|
||||
unsigned char message[512];
|
||||
} __attribute__((packed));
|
||||
|
||||
/* CRT, with a small modulus */
|
||||
struct type50_crb1_msg {
|
||||
struct type50_hdr header;
|
||||
unsigned short keyblock_type; /* 0x0011 */
|
||||
unsigned char reserved[6];
|
||||
unsigned char p[64];
|
||||
unsigned char q[64];
|
||||
unsigned char dp[64];
|
||||
unsigned char dq[64];
|
||||
unsigned char u[64];
|
||||
unsigned char message[128];
|
||||
} __attribute__((packed));
|
||||
|
||||
/* CRT, with a large modulus */
|
||||
struct type50_crb2_msg {
|
||||
struct type50_hdr header;
|
||||
unsigned short keyblock_type; /* 0x0012 */
|
||||
unsigned char reserved[6];
|
||||
unsigned char p[128];
|
||||
unsigned char q[128];
|
||||
unsigned char dp[128];
|
||||
unsigned char dq[128];
|
||||
unsigned char u[128];
|
||||
unsigned char message[256];
|
||||
} __attribute__((packed));
|
||||
|
||||
/* CRT, with a larger modulus */
|
||||
struct type50_crb3_msg {
|
||||
struct type50_hdr header;
|
||||
unsigned short keyblock_type; /* 0x0013 */
|
||||
unsigned char reserved[6];
|
||||
unsigned char p[256];
|
||||
unsigned char q[256];
|
||||
unsigned char dp[256];
|
||||
unsigned char dq[256];
|
||||
unsigned char u[256];
|
||||
unsigned char message[512];
|
||||
} __attribute__((packed));
|
||||
|
||||
/**
|
||||
* The type 80 response family is associated with a CEX2A card.
|
||||
*
|
||||
* Note that all unsigned char arrays are right-justified and left-padded
|
||||
* with zeroes.
|
||||
*
|
||||
* Note that all reserved fields must be zeroes.
|
||||
*/
|
||||
|
||||
#define TYPE80_RSP_CODE 0x80
|
||||
|
||||
struct type80_hdr {
|
||||
unsigned char reserved1;
|
||||
unsigned char type; /* 0x80 */
|
||||
unsigned short len;
|
||||
unsigned char code; /* 0x00 */
|
||||
unsigned char reserved2[3];
|
||||
unsigned char reserved3[8];
|
||||
} __attribute__((packed));
|
||||
|
||||
int zcrypt_cex2a_init(void);
|
||||
void zcrypt_cex2a_exit(void);
|
||||
|
||||
#endif /* _ZCRYPT_CEX2A_H_ */
|
167
drivers/s390/crypto/zcrypt_cex4.c
Normal file
167
drivers/s390/crypto/zcrypt_cex4.c
Normal file
|
@ -0,0 +1,167 @@
|
|||
/*
|
||||
* Copyright IBM Corp. 2012
|
||||
* Author(s): Holger Dengler <hd@linux.vnet.ibm.com>
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/atomic.h>
|
||||
#include <linux/uaccess.h>
|
||||
|
||||
#include "ap_bus.h"
|
||||
#include "zcrypt_api.h"
|
||||
#include "zcrypt_msgtype6.h"
|
||||
#include "zcrypt_msgtype50.h"
|
||||
#include "zcrypt_error.h"
|
||||
#include "zcrypt_cex4.h"
|
||||
|
||||
#define CEX4A_MIN_MOD_SIZE 1 /* 8 bits */
|
||||
#define CEX4A_MAX_MOD_SIZE_2K 256 /* 2048 bits */
|
||||
#define CEX4A_MAX_MOD_SIZE_4K 512 /* 4096 bits */
|
||||
|
||||
#define CEX4C_MIN_MOD_SIZE 16 /* 256 bits */
|
||||
#define CEX4C_MAX_MOD_SIZE 512 /* 4096 bits */
|
||||
|
||||
#define CEX4A_SPEED_RATING 900 /* TODO new card, new speed rating */
|
||||
#define CEX4C_SPEED_RATING 6500 /* TODO new card, new speed rating */
|
||||
|
||||
#define CEX4A_MAX_MESSAGE_SIZE MSGTYPE50_CRB3_MAX_MSG_SIZE
|
||||
#define CEX4C_MAX_MESSAGE_SIZE MSGTYPE06_MAX_MSG_SIZE
|
||||
|
||||
/* Waiting time for requests to be processed.
|
||||
* Currently there are some types of request which are not deterministic.
|
||||
* But the maximum time limit managed by the stomper code is set to 60sec.
|
||||
* Hence we have to wait at least that time period.
|
||||
*/
|
||||
#define CEX4_CLEANUP_TIME (61*HZ)
|
||||
|
||||
static struct ap_device_id zcrypt_cex4_ids[] = {
|
||||
{ AP_DEVICE(AP_DEVICE_TYPE_CEX4) },
|
||||
{ /* end of list */ },
|
||||
};
|
||||
|
||||
MODULE_DEVICE_TABLE(ap, zcrypt_cex4_ids);
|
||||
MODULE_AUTHOR("IBM Corporation");
|
||||
MODULE_DESCRIPTION("CEX4 Cryptographic Card device driver, " \
|
||||
"Copyright IBM Corp. 2012");
|
||||
MODULE_LICENSE("GPL");
|
||||
|
||||
static int zcrypt_cex4_probe(struct ap_device *ap_dev);
|
||||
static void zcrypt_cex4_remove(struct ap_device *ap_dev);
|
||||
|
||||
static struct ap_driver zcrypt_cex4_driver = {
|
||||
.probe = zcrypt_cex4_probe,
|
||||
.remove = zcrypt_cex4_remove,
|
||||
.ids = zcrypt_cex4_ids,
|
||||
.request_timeout = CEX4_CLEANUP_TIME,
|
||||
};
|
||||
|
||||
/**
|
||||
* Probe function for CEX4 cards. It always accepts the AP device
|
||||
* since the bus_match already checked the hardware type.
|
||||
* @ap_dev: pointer to the AP device.
|
||||
*/
|
||||
static int zcrypt_cex4_probe(struct ap_device *ap_dev)
|
||||
{
|
||||
struct zcrypt_device *zdev = NULL;
|
||||
int rc = 0;
|
||||
|
||||
switch (ap_dev->device_type) {
|
||||
case AP_DEVICE_TYPE_CEX4:
|
||||
if (ap_test_bit(&ap_dev->functions, AP_FUNC_ACCEL)) {
|
||||
zdev = zcrypt_device_alloc(CEX4A_MAX_MESSAGE_SIZE);
|
||||
if (!zdev)
|
||||
return -ENOMEM;
|
||||
zdev->type_string = "CEX4A";
|
||||
zdev->user_space_type = ZCRYPT_CEX3A;
|
||||
zdev->min_mod_size = CEX4A_MIN_MOD_SIZE;
|
||||
if (ap_test_bit(&ap_dev->functions, AP_FUNC_MEX4K) &&
|
||||
ap_test_bit(&ap_dev->functions, AP_FUNC_CRT4K)) {
|
||||
zdev->max_mod_size =
|
||||
CEX4A_MAX_MOD_SIZE_4K;
|
||||
zdev->max_exp_bit_length =
|
||||
CEX4A_MAX_MOD_SIZE_4K;
|
||||
} else {
|
||||
zdev->max_mod_size =
|
||||
CEX4A_MAX_MOD_SIZE_2K;
|
||||
zdev->max_exp_bit_length =
|
||||
CEX4A_MAX_MOD_SIZE_2K;
|
||||
}
|
||||
zdev->short_crt = 1;
|
||||
zdev->speed_rating = CEX4A_SPEED_RATING;
|
||||
zdev->ops = zcrypt_msgtype_request(MSGTYPE50_NAME,
|
||||
MSGTYPE50_VARIANT_DEFAULT);
|
||||
} else if (ap_test_bit(&ap_dev->functions, AP_FUNC_COPRO)) {
|
||||
zdev = zcrypt_device_alloc(CEX4C_MAX_MESSAGE_SIZE);
|
||||
if (!zdev)
|
||||
return -ENOMEM;
|
||||
zdev->type_string = "CEX4C";
|
||||
zdev->user_space_type = ZCRYPT_CEX3C;
|
||||
zdev->min_mod_size = CEX4C_MIN_MOD_SIZE;
|
||||
zdev->max_mod_size = CEX4C_MAX_MOD_SIZE;
|
||||
zdev->max_exp_bit_length = CEX4C_MAX_MOD_SIZE;
|
||||
zdev->short_crt = 0;
|
||||
zdev->speed_rating = CEX4C_SPEED_RATING;
|
||||
zdev->ops = zcrypt_msgtype_request(MSGTYPE06_NAME,
|
||||
MSGTYPE06_VARIANT_DEFAULT);
|
||||
} else if (ap_test_bit(&ap_dev->functions, AP_FUNC_EP11)) {
|
||||
zdev = zcrypt_device_alloc(CEX4C_MAX_MESSAGE_SIZE);
|
||||
if (!zdev)
|
||||
return -ENOMEM;
|
||||
zdev->type_string = "CEX4P";
|
||||
zdev->user_space_type = ZCRYPT_CEX4;
|
||||
zdev->min_mod_size = CEX4C_MIN_MOD_SIZE;
|
||||
zdev->max_mod_size = CEX4C_MAX_MOD_SIZE;
|
||||
zdev->max_exp_bit_length = CEX4C_MAX_MOD_SIZE;
|
||||
zdev->short_crt = 0;
|
||||
zdev->speed_rating = CEX4C_SPEED_RATING;
|
||||
zdev->ops = zcrypt_msgtype_request(MSGTYPE06_NAME,
|
||||
MSGTYPE06_VARIANT_EP11);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (!zdev)
|
||||
return -ENODEV;
|
||||
zdev->ap_dev = ap_dev;
|
||||
zdev->online = 1;
|
||||
ap_dev->reply = &zdev->reply;
|
||||
ap_dev->private = zdev;
|
||||
rc = zcrypt_device_register(zdev);
|
||||
if (rc) {
|
||||
zcrypt_msgtype_release(zdev->ops);
|
||||
ap_dev->private = NULL;
|
||||
zcrypt_device_free(zdev);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is called to remove the extended CEX4 driver information
|
||||
* if an AP device is removed.
|
||||
*/
|
||||
static void zcrypt_cex4_remove(struct ap_device *ap_dev)
|
||||
{
|
||||
struct zcrypt_device *zdev = ap_dev->private;
|
||||
struct zcrypt_ops *zops;
|
||||
|
||||
if (zdev) {
|
||||
zops = zdev->ops;
|
||||
zcrypt_device_unregister(zdev);
|
||||
zcrypt_msgtype_release(zops);
|
||||
}
|
||||
}
|
||||
|
||||
int __init zcrypt_cex4_init(void)
|
||||
{
|
||||
return ap_driver_register(&zcrypt_cex4_driver, THIS_MODULE, "cex4");
|
||||
}
|
||||
|
||||
void __exit zcrypt_cex4_exit(void)
|
||||
{
|
||||
ap_driver_unregister(&zcrypt_cex4_driver);
|
||||
}
|
||||
|
||||
module_init(zcrypt_cex4_init);
|
||||
module_exit(zcrypt_cex4_exit);
|
12
drivers/s390/crypto/zcrypt_cex4.h
Normal file
12
drivers/s390/crypto/zcrypt_cex4.h
Normal file
|
@ -0,0 +1,12 @@
|
|||
/*
|
||||
* Copyright IBM Corp. 2012
|
||||
* Author(s): Holger Dengler <hd@linux.vnet.ibm.com>
|
||||
*/
|
||||
|
||||
#ifndef _ZCRYPT_CEX4_H_
|
||||
#define _ZCRYPT_CEX4_H_
|
||||
|
||||
int zcrypt_cex4_init(void);
|
||||
void zcrypt_cex4_exit(void);
|
||||
|
||||
#endif /* _ZCRYPT_CEX4_H_ */
|
53
drivers/s390/crypto/zcrypt_debug.h
Normal file
53
drivers/s390/crypto/zcrypt_debug.h
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright IBM Corp. 2012
|
||||
* Author(s): Holger Dengler (hd@linux.vnet.ibm.com)
|
||||
*/
|
||||
#ifndef ZCRYPT_DEBUG_H
|
||||
#define ZCRYPT_DEBUG_H
|
||||
|
||||
#include <asm/debug.h>
|
||||
#include "zcrypt_api.h"
|
||||
|
||||
/* that gives us 15 characters in the text event views */
|
||||
#define ZCRYPT_DBF_LEN 16
|
||||
|
||||
#define DBF_ERR 3 /* error conditions */
|
||||
#define DBF_WARN 4 /* warning conditions */
|
||||
#define DBF_INFO 6 /* informational */
|
||||
|
||||
#define RC2WARN(rc) ((rc) ? DBF_WARN : DBF_INFO)
|
||||
|
||||
#define ZCRYPT_DBF_COMMON(level, text...) \
|
||||
do { \
|
||||
if (debug_level_enabled(zcrypt_dbf_common, level)) { \
|
||||
char debug_buffer[ZCRYPT_DBF_LEN]; \
|
||||
snprintf(debug_buffer, ZCRYPT_DBF_LEN, text); \
|
||||
debug_text_event(zcrypt_dbf_common, level, \
|
||||
debug_buffer); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define ZCRYPT_DBF_DEVICES(level, text...) \
|
||||
do { \
|
||||
if (debug_level_enabled(zcrypt_dbf_devices, level)) { \
|
||||
char debug_buffer[ZCRYPT_DBF_LEN]; \
|
||||
snprintf(debug_buffer, ZCRYPT_DBF_LEN, text); \
|
||||
debug_text_event(zcrypt_dbf_devices, level, \
|
||||
debug_buffer); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define ZCRYPT_DBF_DEV(level, device, text...) \
|
||||
do { \
|
||||
if (debug_level_enabled(device->dbf_area, level)) { \
|
||||
char debug_buffer[ZCRYPT_DBF_LEN]; \
|
||||
snprintf(debug_buffer, ZCRYPT_DBF_LEN, text); \
|
||||
debug_text_event(device->dbf_area, level, \
|
||||
debug_buffer); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
int zcrypt_debug_init(void);
|
||||
void zcrypt_debug_exit(void);
|
||||
|
||||
#endif /* ZCRYPT_DEBUG_H */
|
140
drivers/s390/crypto/zcrypt_error.h
Normal file
140
drivers/s390/crypto/zcrypt_error.h
Normal file
|
@ -0,0 +1,140 @@
|
|||
/*
|
||||
* zcrypt 2.1.0
|
||||
*
|
||||
* Copyright IBM Corp. 2001, 2006
|
||||
* 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>
|
||||
*
|
||||
* 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_ERROR_H_
|
||||
#define _ZCRYPT_ERROR_H_
|
||||
|
||||
#include <linux/atomic.h>
|
||||
#include "zcrypt_debug.h"
|
||||
#include "zcrypt_api.h"
|
||||
|
||||
/**
|
||||
* Reply Messages
|
||||
*
|
||||
* Error reply messages are of two types:
|
||||
* 82: Error (see below)
|
||||
* 88: Error (see below)
|
||||
* Both type 82 and type 88 have the same structure in the header.
|
||||
*
|
||||
* Request reply messages are of three known types:
|
||||
* 80: Reply from a Type 50 Request (see CEX2A-RELATED STRUCTS)
|
||||
* 84: Reply from a Type 4 Request (see PCICA-RELATED STRUCTS)
|
||||
* 86: Reply from a Type 6 Request (see PCICC/PCIXCC/CEX2C-RELATED STRUCTS)
|
||||
*
|
||||
*/
|
||||
struct error_hdr {
|
||||
unsigned char reserved1; /* 0x00 */
|
||||
unsigned char type; /* 0x82 or 0x88 */
|
||||
unsigned char reserved2[2]; /* 0x0000 */
|
||||
unsigned char reply_code; /* reply code */
|
||||
unsigned char reserved3[3]; /* 0x000000 */
|
||||
};
|
||||
|
||||
#define TYPE82_RSP_CODE 0x82
|
||||
#define TYPE88_RSP_CODE 0x88
|
||||
|
||||
#define REP82_ERROR_MACHINE_FAILURE 0x10
|
||||
#define REP82_ERROR_PREEMPT_FAILURE 0x12
|
||||
#define REP82_ERROR_CHECKPT_FAILURE 0x14
|
||||
#define REP82_ERROR_MESSAGE_TYPE 0x20
|
||||
#define REP82_ERROR_INVALID_COMM_CD 0x21 /* Type 84 */
|
||||
#define REP82_ERROR_INVALID_MSG_LEN 0x23
|
||||
#define REP82_ERROR_RESERVD_FIELD 0x24 /* was 0x50 */
|
||||
#define REP82_ERROR_FORMAT_FIELD 0x29
|
||||
#define REP82_ERROR_INVALID_COMMAND 0x30
|
||||
#define REP82_ERROR_MALFORMED_MSG 0x40
|
||||
#define REP82_ERROR_RESERVED_FIELDO 0x50 /* old value */
|
||||
#define REP82_ERROR_WORD_ALIGNMENT 0x60
|
||||
#define REP82_ERROR_MESSAGE_LENGTH 0x80
|
||||
#define REP82_ERROR_OPERAND_INVALID 0x82
|
||||
#define REP82_ERROR_OPERAND_SIZE 0x84
|
||||
#define REP82_ERROR_EVEN_MOD_IN_OPND 0x85
|
||||
#define REP82_ERROR_RESERVED_FIELD 0x88
|
||||
#define REP82_ERROR_TRANSPORT_FAIL 0x90
|
||||
#define REP82_ERROR_PACKET_TRUNCATED 0xA0
|
||||
#define REP82_ERROR_ZERO_BUFFER_LEN 0xB0
|
||||
|
||||
#define REP88_ERROR_MODULE_FAILURE 0x10
|
||||
|
||||
#define REP88_ERROR_MESSAGE_TYPE 0x20
|
||||
#define REP88_ERROR_MESSAGE_MALFORMD 0x22
|
||||
#define REP88_ERROR_MESSAGE_LENGTH 0x23
|
||||
#define REP88_ERROR_RESERVED_FIELD 0x24
|
||||
#define REP88_ERROR_KEY_TYPE 0x34
|
||||
#define REP88_ERROR_INVALID_KEY 0x82 /* CEX2A */
|
||||
#define REP88_ERROR_OPERAND 0x84 /* CEX2A */
|
||||
#define REP88_ERROR_OPERAND_EVEN_MOD 0x85 /* CEX2A */
|
||||
|
||||
static inline int convert_error(struct zcrypt_device *zdev,
|
||||
struct ap_message *reply)
|
||||
{
|
||||
struct error_hdr *ehdr = reply->message;
|
||||
|
||||
switch (ehdr->reply_code) {
|
||||
case REP82_ERROR_OPERAND_INVALID:
|
||||
case REP82_ERROR_OPERAND_SIZE:
|
||||
case REP82_ERROR_EVEN_MOD_IN_OPND:
|
||||
case REP88_ERROR_MESSAGE_MALFORMD:
|
||||
// REP88_ERROR_INVALID_KEY // '82' CEX2A
|
||||
// REP88_ERROR_OPERAND // '84' CEX2A
|
||||
// REP88_ERROR_OPERAND_EVEN_MOD // '85' CEX2A
|
||||
/* Invalid input data. */
|
||||
return -EINVAL;
|
||||
case REP82_ERROR_MESSAGE_TYPE:
|
||||
// REP88_ERROR_MESSAGE_TYPE // '20' CEX2A
|
||||
/*
|
||||
* To sent a message of the wrong type is a bug in the
|
||||
* device driver. Send error msg, disable the device
|
||||
* and then repeat the request.
|
||||
*/
|
||||
atomic_set(&zcrypt_rescan_req, 1);
|
||||
zdev->online = 0;
|
||||
pr_err("Cryptographic device %x failed and was set offline\n",
|
||||
zdev->ap_dev->qid);
|
||||
ZCRYPT_DBF_DEV(DBF_ERR, zdev, "dev%04xo%drc%d",
|
||||
zdev->ap_dev->qid, zdev->online, ehdr->reply_code);
|
||||
return -EAGAIN;
|
||||
case REP82_ERROR_TRANSPORT_FAIL:
|
||||
case REP82_ERROR_MACHINE_FAILURE:
|
||||
// REP88_ERROR_MODULE_FAILURE // '10' CEX2A
|
||||
/* If a card fails disable it and repeat the request. */
|
||||
atomic_set(&zcrypt_rescan_req, 1);
|
||||
zdev->online = 0;
|
||||
pr_err("Cryptographic device %x failed and was set offline\n",
|
||||
zdev->ap_dev->qid);
|
||||
ZCRYPT_DBF_DEV(DBF_ERR, zdev, "dev%04xo%drc%d",
|
||||
zdev->ap_dev->qid, zdev->online, ehdr->reply_code);
|
||||
return -EAGAIN;
|
||||
default:
|
||||
zdev->online = 0;
|
||||
pr_err("Cryptographic device %x failed and was set offline\n",
|
||||
zdev->ap_dev->qid);
|
||||
ZCRYPT_DBF_DEV(DBF_ERR, zdev, "dev%04xo%drc%d",
|
||||
zdev->ap_dev->qid, zdev->online, ehdr->reply_code);
|
||||
return -EAGAIN; /* repeat the request on a different device. */
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* _ZCRYPT_ERROR_H_ */
|
529
drivers/s390/crypto/zcrypt_msgtype50.c
Normal file
529
drivers/s390/crypto/zcrypt_msgtype50.c
Normal file
|
@ -0,0 +1,529 @@
|
|||
/*
|
||||
* 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>
|
||||
* 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
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#define KMSG_COMPONENT "zcrypt"
|
||||
#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/atomic.h>
|
||||
#include <linux/uaccess.h>
|
||||
|
||||
#include "ap_bus.h"
|
||||
#include "zcrypt_api.h"
|
||||
#include "zcrypt_error.h"
|
||||
#include "zcrypt_msgtype50.h"
|
||||
|
||||
#define CEX3A_MAX_MOD_SIZE 512 /* 4096 bits */
|
||||
|
||||
#define CEX2A_MAX_RESPONSE_SIZE 0x110 /* max outputdatalength + type80_hdr */
|
||||
|
||||
#define CEX3A_MAX_RESPONSE_SIZE 0x210 /* 512 bit modulus
|
||||
* (max outputdatalength) +
|
||||
* type80_hdr*/
|
||||
|
||||
MODULE_AUTHOR("IBM Corporation");
|
||||
MODULE_DESCRIPTION("Cryptographic Accelerator (message type 50), " \
|
||||
"Copyright IBM Corp. 2001, 2012");
|
||||
MODULE_LICENSE("GPL");
|
||||
|
||||
static void zcrypt_cex2a_receive(struct ap_device *, struct ap_message *,
|
||||
struct ap_message *);
|
||||
|
||||
/**
|
||||
* The type 50 message family is associated with a CEX2A card.
|
||||
*
|
||||
* The four members of the family are described below.
|
||||
*
|
||||
* Note that all unsigned char arrays are right-justified and left-padded
|
||||
* with zeroes.
|
||||
*
|
||||
* Note that all reserved fields must be zeroes.
|
||||
*/
|
||||
struct type50_hdr {
|
||||
unsigned char reserved1;
|
||||
unsigned char msg_type_code; /* 0x50 */
|
||||
unsigned short msg_len;
|
||||
unsigned char reserved2;
|
||||
unsigned char ignored;
|
||||
unsigned short reserved3;
|
||||
} __packed;
|
||||
|
||||
#define TYPE50_TYPE_CODE 0x50
|
||||
|
||||
#define TYPE50_MEB1_FMT 0x0001
|
||||
#define TYPE50_MEB2_FMT 0x0002
|
||||
#define TYPE50_MEB3_FMT 0x0003
|
||||
#define TYPE50_CRB1_FMT 0x0011
|
||||
#define TYPE50_CRB2_FMT 0x0012
|
||||
#define TYPE50_CRB3_FMT 0x0013
|
||||
|
||||
/* Mod-Exp, with a small modulus */
|
||||
struct type50_meb1_msg {
|
||||
struct type50_hdr header;
|
||||
unsigned short keyblock_type; /* 0x0001 */
|
||||
unsigned char reserved[6];
|
||||
unsigned char exponent[128];
|
||||
unsigned char modulus[128];
|
||||
unsigned char message[128];
|
||||
} __packed;
|
||||
|
||||
/* Mod-Exp, with a large modulus */
|
||||
struct type50_meb2_msg {
|
||||
struct type50_hdr header;
|
||||
unsigned short keyblock_type; /* 0x0002 */
|
||||
unsigned char reserved[6];
|
||||
unsigned char exponent[256];
|
||||
unsigned char modulus[256];
|
||||
unsigned char message[256];
|
||||
} __packed;
|
||||
|
||||
/* Mod-Exp, with a larger modulus */
|
||||
struct type50_meb3_msg {
|
||||
struct type50_hdr header;
|
||||
unsigned short keyblock_type; /* 0x0003 */
|
||||
unsigned char reserved[6];
|
||||
unsigned char exponent[512];
|
||||
unsigned char modulus[512];
|
||||
unsigned char message[512];
|
||||
} __packed;
|
||||
|
||||
/* CRT, with a small modulus */
|
||||
struct type50_crb1_msg {
|
||||
struct type50_hdr header;
|
||||
unsigned short keyblock_type; /* 0x0011 */
|
||||
unsigned char reserved[6];
|
||||
unsigned char p[64];
|
||||
unsigned char q[64];
|
||||
unsigned char dp[64];
|
||||
unsigned char dq[64];
|
||||
unsigned char u[64];
|
||||
unsigned char message[128];
|
||||
} __packed;
|
||||
|
||||
/* CRT, with a large modulus */
|
||||
struct type50_crb2_msg {
|
||||
struct type50_hdr header;
|
||||
unsigned short keyblock_type; /* 0x0012 */
|
||||
unsigned char reserved[6];
|
||||
unsigned char p[128];
|
||||
unsigned char q[128];
|
||||
unsigned char dp[128];
|
||||
unsigned char dq[128];
|
||||
unsigned char u[128];
|
||||
unsigned char message[256];
|
||||
} __packed;
|
||||
|
||||
/* CRT, with a larger modulus */
|
||||
struct type50_crb3_msg {
|
||||
struct type50_hdr header;
|
||||
unsigned short keyblock_type; /* 0x0013 */
|
||||
unsigned char reserved[6];
|
||||
unsigned char p[256];
|
||||
unsigned char q[256];
|
||||
unsigned char dp[256];
|
||||
unsigned char dq[256];
|
||||
unsigned char u[256];
|
||||
unsigned char message[512];
|
||||
} __packed;
|
||||
|
||||
/**
|
||||
* The type 80 response family is associated with a CEX2A card.
|
||||
*
|
||||
* Note that all unsigned char arrays are right-justified and left-padded
|
||||
* with zeroes.
|
||||
*
|
||||
* Note that all reserved fields must be zeroes.
|
||||
*/
|
||||
|
||||
#define TYPE80_RSP_CODE 0x80
|
||||
|
||||
struct type80_hdr {
|
||||
unsigned char reserved1;
|
||||
unsigned char type; /* 0x80 */
|
||||
unsigned short len;
|
||||
unsigned char code; /* 0x00 */
|
||||
unsigned char reserved2[3];
|
||||
unsigned char reserved3[8];
|
||||
} __packed;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
unsigned char *p, *q, *dp, *dq, *u, *inp;
|
||||
|
||||
mod_len = crt->inputdatalength;
|
||||
short_len = mod_len / 2;
|
||||
|
||||
/*
|
||||
* CEX2A and CEX3A w/o FW update can handle requests up to
|
||||
* 256 byte modulus (2k keys).
|
||||
* CEX3A with FW update and CEX4A cards are able to handle
|
||||
* 512 byte modulus (4k keys).
|
||||
*/
|
||||
if (mod_len <= 128) { /* up to 1024 bit key size */
|
||||
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) - short_len;
|
||||
q = crb1->q + sizeof(crb1->q) - short_len;
|
||||
dp = crb1->dp + sizeof(crb1->dp) - short_len;
|
||||
dq = crb1->dq + sizeof(crb1->dq) - short_len;
|
||||
u = crb1->u + sizeof(crb1->u) - short_len;
|
||||
inp = crb1->message + sizeof(crb1->message) - mod_len;
|
||||
} else if (mod_len <= 256) { /* up to 2048 bit key size */
|
||||
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) - short_len;
|
||||
q = crb2->q + sizeof(crb2->q) - short_len;
|
||||
dp = crb2->dp + sizeof(crb2->dp) - short_len;
|
||||
dq = crb2->dq + sizeof(crb2->dq) - short_len;
|
||||
u = crb2->u + sizeof(crb2->u) - short_len;
|
||||
inp = crb2->message + sizeof(crb2->message) - mod_len;
|
||||
} else if ((mod_len <= 512) && /* up to 4096 bit key size */
|
||||
(zdev->max_mod_size == CEX3A_MAX_MOD_SIZE)) { /* >= CEX3A */
|
||||
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) - short_len;
|
||||
q = crb3->q + sizeof(crb3->q) - short_len;
|
||||
dp = crb3->dp + sizeof(crb3->dp) - short_len;
|
||||
dq = crb3->dq + sizeof(crb3->dq) - short_len;
|
||||
u = crb3->u + sizeof(crb3->u) - short_len;
|
||||
inp = crb3->message + sizeof(crb3->message) - mod_len;
|
||||
} else
|
||||
return -EINVAL;
|
||||
|
||||
/*
|
||||
* correct the offset of p, bp and mult_inv according zcrypt.h
|
||||
* block size right aligned (skip the first byte)
|
||||
*/
|
||||
if (copy_from_user(p, crt->np_prime + MSGTYPE_ADJUSTMENT, short_len) ||
|
||||
copy_from_user(q, crt->nq_prime, short_len) ||
|
||||
copy_from_user(dp, crt->bp_key + MSGTYPE_ADJUSTMENT, short_len) ||
|
||||
copy_from_user(dq, crt->bq_key, short_len) ||
|
||||
copy_from_user(u, crt->u_mult_inv + MSGTYPE_ADJUSTMENT, short_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;
|
||||
pr_err("Cryptographic device %x failed and was set offline\n",
|
||||
zdev->ap_dev->qid);
|
||||
ZCRYPT_DBF_DEV(DBF_ERR, zdev, "dev%04xo%drc%d",
|
||||
zdev->ap_dev->qid, zdev->online, t80h->code);
|
||||
|
||||
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;
|
||||
pr_err("Cryptographic device %x failed and was set offline\n",
|
||||
zdev->ap_dev->qid);
|
||||
ZCRYPT_DBF_DEV(DBF_ERR, zdev, "dev%04xo%dfail",
|
||||
zdev->ap_dev->qid, zdev->online);
|
||||
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_t(int,
|
||||
CEX2A_MAX_RESPONSE_SIZE, t80h->len);
|
||||
else
|
||||
length = min_t(int,
|
||||
CEX3A_MAX_RESPONSE_SIZE, 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(MSGTYPE50_CRB2_MAX_MSG_SIZE,
|
||||
GFP_KERNEL);
|
||||
else
|
||||
ap_msg.message = kmalloc(MSGTYPE50_CRB3_MAX_MSG_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(MSGTYPE50_CRB2_MAX_MSG_SIZE,
|
||||
GFP_KERNEL);
|
||||
else
|
||||
ap_msg.message = kmalloc(MSGTYPE50_CRB3_MAX_MSG_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 message type 50.
|
||||
*/
|
||||
static struct zcrypt_ops zcrypt_msgtype50_ops = {
|
||||
.rsa_modexpo = zcrypt_cex2a_modexpo,
|
||||
.rsa_modexpo_crt = zcrypt_cex2a_modexpo_crt,
|
||||
.owner = THIS_MODULE,
|
||||
.variant = MSGTYPE50_VARIANT_DEFAULT,
|
||||
};
|
||||
|
||||
int __init zcrypt_msgtype50_init(void)
|
||||
{
|
||||
zcrypt_msgtype_register(&zcrypt_msgtype50_ops);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void __exit zcrypt_msgtype50_exit(void)
|
||||
{
|
||||
zcrypt_msgtype_unregister(&zcrypt_msgtype50_ops);
|
||||
}
|
||||
|
||||
module_init(zcrypt_msgtype50_init);
|
||||
module_exit(zcrypt_msgtype50_exit);
|
41
drivers/s390/crypto/zcrypt_msgtype50.h
Normal file
41
drivers/s390/crypto/zcrypt_msgtype50.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* 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)*/
|
||||
|
||||
#define MSGTYPE_ADJUSTMENT 0x08 /*type04 extension (not needed in type50)*/
|
||||
|
||||
int zcrypt_msgtype50_init(void);
|
||||
void zcrypt_msgtype50_exit(void);
|
||||
|
||||
#endif /* _ZCRYPT_MSGTYPE50_H_ */
|
1152
drivers/s390/crypto/zcrypt_msgtype6.c
Normal file
1152
drivers/s390/crypto/zcrypt_msgtype6.c
Normal file
File diff suppressed because it is too large
Load diff
171
drivers/s390/crypto/zcrypt_msgtype6.h
Normal file
171
drivers/s390/crypto/zcrypt_msgtype6.h
Normal file
|
@ -0,0 +1,171 @@
|
|||
/*
|
||||
* 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_VARIANT_EP11 2
|
||||
|
||||
#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 TYPE87_RSP_CODE 0x87
|
||||
#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_ */
|
420
drivers/s390/crypto/zcrypt_pcica.c
Normal file
420
drivers/s390/crypto/zcrypt_pcica.c
Normal file
|
@ -0,0 +1,420 @@
|
|||
/*
|
||||
* zcrypt 2.1.0
|
||||
*
|
||||
* Copyright IBM Corp. 2001, 2006
|
||||
* 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>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#define KMSG_COMPONENT "zcrypt"
|
||||
#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/atomic.h>
|
||||
#include <asm/uaccess.h>
|
||||
|
||||
#include "ap_bus.h"
|
||||
#include "zcrypt_api.h"
|
||||
#include "zcrypt_error.h"
|
||||
#include "zcrypt_pcica.h"
|
||||
|
||||
#define PCICA_MIN_MOD_SIZE 1 /* 8 bits */
|
||||
#define PCICA_MAX_MOD_SIZE 256 /* 2048 bits */
|
||||
|
||||
#define PCICA_SPEED_RATING 2800
|
||||
|
||||
#define PCICA_MAX_MESSAGE_SIZE 0x3a0 /* sizeof(struct type4_lcr) */
|
||||
#define PCICA_MAX_RESPONSE_SIZE 0x110 /* max outputdatalength + type80_hdr */
|
||||
|
||||
#define PCICA_CLEANUP_TIME (15*HZ)
|
||||
|
||||
static struct ap_device_id zcrypt_pcica_ids[] = {
|
||||
{ AP_DEVICE(AP_DEVICE_TYPE_PCICA) },
|
||||
{ /* end of list */ },
|
||||
};
|
||||
|
||||
MODULE_DEVICE_TABLE(ap, zcrypt_pcica_ids);
|
||||
MODULE_AUTHOR("IBM Corporation");
|
||||
MODULE_DESCRIPTION("PCICA Cryptographic Coprocessor device driver, "
|
||||
"Copyright IBM Corp. 2001, 2006");
|
||||
MODULE_LICENSE("GPL");
|
||||
|
||||
static int zcrypt_pcica_probe(struct ap_device *ap_dev);
|
||||
static void zcrypt_pcica_remove(struct ap_device *ap_dev);
|
||||
static void zcrypt_pcica_receive(struct ap_device *, struct ap_message *,
|
||||
struct ap_message *);
|
||||
|
||||
static struct ap_driver zcrypt_pcica_driver = {
|
||||
.probe = zcrypt_pcica_probe,
|
||||
.remove = zcrypt_pcica_remove,
|
||||
.ids = zcrypt_pcica_ids,
|
||||
.request_timeout = PCICA_CLEANUP_TIME,
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert a ICAMEX message to a type4 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_type4MEX_msg(struct zcrypt_device *zdev,
|
||||
struct ap_message *ap_msg,
|
||||
struct ica_rsa_modexpo *mex)
|
||||
{
|
||||
unsigned char *modulus, *exponent, *message;
|
||||
int mod_len;
|
||||
|
||||
mod_len = mex->inputdatalength;
|
||||
|
||||
if (mod_len <= 128) {
|
||||
struct type4_sme *sme = ap_msg->message;
|
||||
memset(sme, 0, sizeof(*sme));
|
||||
ap_msg->length = sizeof(*sme);
|
||||
sme->header.msg_fmt = TYPE4_SME_FMT;
|
||||
sme->header.msg_len = sizeof(*sme);
|
||||
sme->header.msg_type_code = TYPE4_TYPE_CODE;
|
||||
sme->header.request_code = TYPE4_REQU_CODE;
|
||||
modulus = sme->modulus + sizeof(sme->modulus) - mod_len;
|
||||
exponent = sme->exponent + sizeof(sme->exponent) - mod_len;
|
||||
message = sme->message + sizeof(sme->message) - mod_len;
|
||||
} else {
|
||||
struct type4_lme *lme = ap_msg->message;
|
||||
memset(lme, 0, sizeof(*lme));
|
||||
ap_msg->length = sizeof(*lme);
|
||||
lme->header.msg_fmt = TYPE4_LME_FMT;
|
||||
lme->header.msg_len = sizeof(*lme);
|
||||
lme->header.msg_type_code = TYPE4_TYPE_CODE;
|
||||
lme->header.request_code = TYPE4_REQU_CODE;
|
||||
modulus = lme->modulus + sizeof(lme->modulus) - mod_len;
|
||||
exponent = lme->exponent + sizeof(lme->exponent) - mod_len;
|
||||
message = lme->message + sizeof(lme->message) - mod_len;
|
||||
}
|
||||
|
||||
if (copy_from_user(modulus, mex->n_modulus, mod_len) ||
|
||||
copy_from_user(exponent, mex->b_key, mod_len) ||
|
||||
copy_from_user(message, mex->inputdata, mod_len))
|
||||
return -EFAULT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a ICACRT message to a type4 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_type4CRT_msg(struct zcrypt_device *zdev,
|
||||
struct ap_message *ap_msg,
|
||||
struct ica_rsa_modexpo_crt *crt)
|
||||
{
|
||||
unsigned char *p, *q, *dp, *dq, *u, *inp;
|
||||
int mod_len, short_len, long_len;
|
||||
|
||||
mod_len = crt->inputdatalength;
|
||||
short_len = mod_len / 2;
|
||||
long_len = mod_len / 2 + 8;
|
||||
|
||||
if (mod_len <= 128) {
|
||||
struct type4_scr *scr = ap_msg->message;
|
||||
memset(scr, 0, sizeof(*scr));
|
||||
ap_msg->length = sizeof(*scr);
|
||||
scr->header.msg_type_code = TYPE4_TYPE_CODE;
|
||||
scr->header.request_code = TYPE4_REQU_CODE;
|
||||
scr->header.msg_fmt = TYPE4_SCR_FMT;
|
||||
scr->header.msg_len = sizeof(*scr);
|
||||
p = scr->p + sizeof(scr->p) - long_len;
|
||||
q = scr->q + sizeof(scr->q) - short_len;
|
||||
dp = scr->dp + sizeof(scr->dp) - long_len;
|
||||
dq = scr->dq + sizeof(scr->dq) - short_len;
|
||||
u = scr->u + sizeof(scr->u) - long_len;
|
||||
inp = scr->message + sizeof(scr->message) - mod_len;
|
||||
} else {
|
||||
struct type4_lcr *lcr = ap_msg->message;
|
||||
memset(lcr, 0, sizeof(*lcr));
|
||||
ap_msg->length = sizeof(*lcr);
|
||||
lcr->header.msg_type_code = TYPE4_TYPE_CODE;
|
||||
lcr->header.request_code = TYPE4_REQU_CODE;
|
||||
lcr->header.msg_fmt = TYPE4_LCR_FMT;
|
||||
lcr->header.msg_len = sizeof(*lcr);
|
||||
p = lcr->p + sizeof(lcr->p) - long_len;
|
||||
q = lcr->q + sizeof(lcr->q) - short_len;
|
||||
dp = lcr->dp + sizeof(lcr->dp) - long_len;
|
||||
dq = lcr->dq + sizeof(lcr->dq) - short_len;
|
||||
u = lcr->u + sizeof(lcr->u) - long_len;
|
||||
inp = lcr->message + sizeof(lcr->message) - mod_len;
|
||||
}
|
||||
|
||||
if (copy_from_user(p, crt->np_prime, long_len) ||
|
||||
copy_from_user(q, crt->nq_prime, short_len) ||
|
||||
copy_from_user(dp, crt->bp_key, long_len) ||
|
||||
copy_from_user(dq, crt->bq_key, short_len) ||
|
||||
copy_from_user(u, crt->u_mult_inv, long_len) ||
|
||||
copy_from_user(inp, crt->inputdata, mod_len))
|
||||
return -EFAULT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy results from a type 84 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_type84(struct zcrypt_device *zdev,
|
||||
struct ap_message *reply,
|
||||
char __user *outputdata,
|
||||
unsigned int outputdatalength)
|
||||
{
|
||||
struct type84_hdr *t84h = reply->message;
|
||||
char *data;
|
||||
|
||||
if (t84h->len < sizeof(*t84h) + outputdatalength) {
|
||||
/* The result is too short, the PCICA card may not do that.. */
|
||||
zdev->online = 0;
|
||||
pr_err("Cryptographic device %x failed and was set offline\n",
|
||||
zdev->ap_dev->qid);
|
||||
ZCRYPT_DBF_DEV(DBF_ERR, zdev, "dev%04xo%drc%d",
|
||||
zdev->ap_dev->qid, zdev->online, t84h->code);
|
||||
return -EAGAIN; /* repeat the request on a different device. */
|
||||
}
|
||||
BUG_ON(t84h->len > PCICA_MAX_RESPONSE_SIZE);
|
||||
data = reply->message + t84h->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 TYPE84_RSP_CODE:
|
||||
return convert_type84(zdev, reply,
|
||||
outputdata, outputdatalength);
|
||||
default: /* Unknown response type, this should NEVER EVER happen */
|
||||
zdev->online = 0;
|
||||
pr_err("Cryptographic device %x failed and was set offline\n",
|
||||
zdev->ap_dev->qid);
|
||||
ZCRYPT_DBF_DEV(DBF_ERR, zdev, "dev%04xo%dfail",
|
||||
zdev->ap_dev->qid, zdev->online);
|
||||
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_pcica_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 type84_hdr *t84h;
|
||||
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;
|
||||
}
|
||||
t84h = reply->message;
|
||||
if (t84h->code == TYPE84_RSP_CODE) {
|
||||
length = min(PCICA_MAX_RESPONSE_SIZE, (int) t84h->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 PCICA
|
||||
* device to handle a modexpo request.
|
||||
* @zdev: pointer to zcrypt_device structure that identifies the
|
||||
* PCICA device to the request distributor
|
||||
* @mex: pointer to the modexpo request buffer
|
||||
*/
|
||||
static long zcrypt_pcica_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);
|
||||
ap_msg.message = kmalloc(PCICA_MAX_MESSAGE_SIZE, GFP_KERNEL);
|
||||
if (!ap_msg.message)
|
||||
return -ENOMEM;
|
||||
ap_msg.receive = zcrypt_pcica_receive;
|
||||
ap_msg.psmid = (((unsigned long long) current->pid) << 32) +
|
||||
atomic_inc_return(&zcrypt_step);
|
||||
ap_msg.private = &work;
|
||||
rc = ICAMEX_msg_to_type4MEX_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 PCICA
|
||||
* device to handle a modexpo_crt request.
|
||||
* @zdev: pointer to zcrypt_device structure that identifies the
|
||||
* PCICA device to the request distributor
|
||||
* @crt: pointer to the modexpoc_crt request buffer
|
||||
*/
|
||||
static long zcrypt_pcica_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);
|
||||
ap_msg.message = kmalloc(PCICA_MAX_MESSAGE_SIZE, GFP_KERNEL);
|
||||
if (!ap_msg.message)
|
||||
return -ENOMEM;
|
||||
ap_msg.receive = zcrypt_pcica_receive;
|
||||
ap_msg.psmid = (((unsigned long long) current->pid) << 32) +
|
||||
atomic_inc_return(&zcrypt_step);
|
||||
ap_msg.private = &work;
|
||||
rc = ICACRT_msg_to_type4CRT_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 PCICA card.
|
||||
*/
|
||||
static struct zcrypt_ops zcrypt_pcica_ops = {
|
||||
.rsa_modexpo = zcrypt_pcica_modexpo,
|
||||
.rsa_modexpo_crt = zcrypt_pcica_modexpo_crt,
|
||||
};
|
||||
|
||||
/**
|
||||
* Probe function for PCICA cards. It always accepts the AP device
|
||||
* since the bus_match already checked the hardware type.
|
||||
* @ap_dev: pointer to the AP device.
|
||||
*/
|
||||
static int zcrypt_pcica_probe(struct ap_device *ap_dev)
|
||||
{
|
||||
struct zcrypt_device *zdev;
|
||||
int rc;
|
||||
|
||||
zdev = zcrypt_device_alloc(PCICA_MAX_RESPONSE_SIZE);
|
||||
if (!zdev)
|
||||
return -ENOMEM;
|
||||
zdev->ap_dev = ap_dev;
|
||||
zdev->ops = &zcrypt_pcica_ops;
|
||||
zdev->online = 1;
|
||||
zdev->user_space_type = ZCRYPT_PCICA;
|
||||
zdev->type_string = "PCICA";
|
||||
zdev->min_mod_size = PCICA_MIN_MOD_SIZE;
|
||||
zdev->max_mod_size = PCICA_MAX_MOD_SIZE;
|
||||
zdev->speed_rating = PCICA_SPEED_RATING;
|
||||
zdev->max_exp_bit_length = PCICA_MAX_MOD_SIZE;
|
||||
ap_dev->reply = &zdev->reply;
|
||||
ap_dev->private = zdev;
|
||||
rc = zcrypt_device_register(zdev);
|
||||
if (rc)
|
||||
goto out_free;
|
||||
return 0;
|
||||
|
||||
out_free:
|
||||
ap_dev->private = NULL;
|
||||
zcrypt_device_free(zdev);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is called to remove the extended PCICA driver information
|
||||
* if an AP device is removed.
|
||||
*/
|
||||
static void zcrypt_pcica_remove(struct ap_device *ap_dev)
|
||||
{
|
||||
struct zcrypt_device *zdev = ap_dev->private;
|
||||
|
||||
zcrypt_device_unregister(zdev);
|
||||
}
|
||||
|
||||
int __init zcrypt_pcica_init(void)
|
||||
{
|
||||
return ap_driver_register(&zcrypt_pcica_driver, THIS_MODULE, "pcica");
|
||||
}
|
||||
|
||||
void zcrypt_pcica_exit(void)
|
||||
{
|
||||
ap_driver_unregister(&zcrypt_pcica_driver);
|
||||
}
|
||||
|
||||
module_init(zcrypt_pcica_init);
|
||||
module_exit(zcrypt_pcica_exit);
|
115
drivers/s390/crypto/zcrypt_pcica.h
Normal file
115
drivers/s390/crypto/zcrypt_pcica.h
Normal file
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
* zcrypt 2.1.0
|
||||
*
|
||||
* Copyright IBM Corp. 2001, 2006
|
||||
* 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>
|
||||
*
|
||||
* 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_PCICA_H_
|
||||
#define _ZCRYPT_PCICA_H_
|
||||
|
||||
/**
|
||||
* The type 4 message family is associated with a PCICA card.
|
||||
*
|
||||
* The four members of the family are described below.
|
||||
*
|
||||
* Note that all unsigned char arrays are right-justified and left-padded
|
||||
* with zeroes.
|
||||
*
|
||||
* Note that all reserved fields must be zeroes.
|
||||
*/
|
||||
struct type4_hdr {
|
||||
unsigned char reserved1;
|
||||
unsigned char msg_type_code; /* 0x04 */
|
||||
unsigned short msg_len;
|
||||
unsigned char request_code; /* 0x40 */
|
||||
unsigned char msg_fmt;
|
||||
unsigned short reserved2;
|
||||
} __attribute__((packed));
|
||||
|
||||
#define TYPE4_TYPE_CODE 0x04
|
||||
#define TYPE4_REQU_CODE 0x40
|
||||
|
||||
#define TYPE4_SME_FMT 0x00
|
||||
#define TYPE4_LME_FMT 0x10
|
||||
#define TYPE4_SCR_FMT 0x40
|
||||
#define TYPE4_LCR_FMT 0x50
|
||||
|
||||
/* Mod-Exp, with a small modulus */
|
||||
struct type4_sme {
|
||||
struct type4_hdr header;
|
||||
unsigned char message[128];
|
||||
unsigned char exponent[128];
|
||||
unsigned char modulus[128];
|
||||
} __attribute__((packed));
|
||||
|
||||
/* Mod-Exp, with a large modulus */
|
||||
struct type4_lme {
|
||||
struct type4_hdr header;
|
||||
unsigned char message[256];
|
||||
unsigned char exponent[256];
|
||||
unsigned char modulus[256];
|
||||
} __attribute__((packed));
|
||||
|
||||
/* CRT, with a small modulus */
|
||||
struct type4_scr {
|
||||
struct type4_hdr header;
|
||||
unsigned char message[128];
|
||||
unsigned char dp[72];
|
||||
unsigned char dq[64];
|
||||
unsigned char p[72];
|
||||
unsigned char q[64];
|
||||
unsigned char u[72];
|
||||
} __attribute__((packed));
|
||||
|
||||
/* CRT, with a large modulus */
|
||||
struct type4_lcr {
|
||||
struct type4_hdr header;
|
||||
unsigned char message[256];
|
||||
unsigned char dp[136];
|
||||
unsigned char dq[128];
|
||||
unsigned char p[136];
|
||||
unsigned char q[128];
|
||||
unsigned char u[136];
|
||||
} __attribute__((packed));
|
||||
|
||||
/**
|
||||
* The type 84 response family is associated with a PCICA card.
|
||||
*
|
||||
* Note that all unsigned char arrays are right-justified and left-padded
|
||||
* with zeroes.
|
||||
*
|
||||
* Note that all reserved fields must be zeroes.
|
||||
*/
|
||||
|
||||
struct type84_hdr {
|
||||
unsigned char reserved1;
|
||||
unsigned char code;
|
||||
unsigned short len;
|
||||
unsigned char reserved2[4];
|
||||
} __attribute__((packed));
|
||||
|
||||
#define TYPE84_RSP_CODE 0x84
|
||||
|
||||
int zcrypt_pcica_init(void);
|
||||
void zcrypt_pcica_exit(void);
|
||||
|
||||
#endif /* _ZCRYPT_PCICA_H_ */
|
627
drivers/s390/crypto/zcrypt_pcicc.c
Normal file
627
drivers/s390/crypto/zcrypt_pcicc.c
Normal file
|
@ -0,0 +1,627 @@
|
|||
/*
|
||||
* zcrypt 2.1.0
|
||||
*
|
||||
* Copyright IBM Corp. 2001, 2006
|
||||
* 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>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#define KMSG_COMPONENT "zcrypt"
|
||||
#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/gfp.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/atomic.h>
|
||||
#include <asm/uaccess.h>
|
||||
|
||||
#include "ap_bus.h"
|
||||
#include "zcrypt_api.h"
|
||||
#include "zcrypt_error.h"
|
||||
#include "zcrypt_pcicc.h"
|
||||
#include "zcrypt_cca_key.h"
|
||||
|
||||
#define PCICC_MIN_MOD_SIZE 64 /* 512 bits */
|
||||
#define PCICC_MAX_MOD_SIZE_OLD 128 /* 1024 bits */
|
||||
#define PCICC_MAX_MOD_SIZE 256 /* 2048 bits */
|
||||
|
||||
/*
|
||||
* PCICC cards need a speed rating of 0. This keeps them at the end of
|
||||
* the zcrypt device list (see zcrypt_api.c). PCICC cards are only
|
||||
* used if no other cards are present because they are slow and can only
|
||||
* cope with PKCS12 padded requests. The logic is queer. PKCS11 padded
|
||||
* requests are rejected. The modexpo function encrypts PKCS12 padded data
|
||||
* and decrypts any non-PKCS12 padded data (except PKCS11) in the assumption
|
||||
* that it's encrypted PKCS12 data. The modexpo_crt function always decrypts
|
||||
* the data in the assumption that its PKCS12 encrypted data.
|
||||
*/
|
||||
#define PCICC_SPEED_RATING 0
|
||||
|
||||
#define PCICC_MAX_MESSAGE_SIZE 0x710 /* max size type6 v1 crt message */
|
||||
#define PCICC_MAX_RESPONSE_SIZE 0x710 /* max size type86 v1 reply */
|
||||
|
||||
#define PCICC_CLEANUP_TIME (15*HZ)
|
||||
|
||||
static struct ap_device_id zcrypt_pcicc_ids[] = {
|
||||
{ AP_DEVICE(AP_DEVICE_TYPE_PCICC) },
|
||||
{ /* end of list */ },
|
||||
};
|
||||
|
||||
MODULE_DEVICE_TABLE(ap, zcrypt_pcicc_ids);
|
||||
MODULE_AUTHOR("IBM Corporation");
|
||||
MODULE_DESCRIPTION("PCICC Cryptographic Coprocessor device driver, "
|
||||
"Copyright IBM Corp. 2001, 2006");
|
||||
MODULE_LICENSE("GPL");
|
||||
|
||||
static int zcrypt_pcicc_probe(struct ap_device *ap_dev);
|
||||
static void zcrypt_pcicc_remove(struct ap_device *ap_dev);
|
||||
static void zcrypt_pcicc_receive(struct ap_device *, struct ap_message *,
|
||||
struct ap_message *);
|
||||
|
||||
static struct ap_driver zcrypt_pcicc_driver = {
|
||||
.probe = zcrypt_pcicc_probe,
|
||||
.remove = zcrypt_pcicc_remove,
|
||||
.ids = zcrypt_pcicc_ids,
|
||||
.request_timeout = PCICC_CLEANUP_TIME,
|
||||
};
|
||||
|
||||
/**
|
||||
* The following is used to initialize the CPRB passed to the PCICC card
|
||||
* in a type6 message. The 3 fields that must be filled in at execution
|
||||
* time are req_parml, rpl_parml and usage_domain. Note that all three
|
||||
* fields are *little*-endian. Actually, everything about this interface
|
||||
* is ascii/little-endian, since the device has 'Intel inside'.
|
||||
*
|
||||
* The CPRB is followed immediately by the parm block.
|
||||
* The parm block contains:
|
||||
* - function code ('PD' 0x5044 or 'PK' 0x504B)
|
||||
* - rule block (0x0A00 'PKCS-1.2' or 0x0A00 'ZERO-PAD')
|
||||
* - VUD block
|
||||
*/
|
||||
static struct CPRB static_cprb = {
|
||||
.cprb_len = __constant_cpu_to_le16(0x0070),
|
||||
.cprb_ver_id = 0x41,
|
||||
.func_id = {0x54,0x32},
|
||||
.checkpoint_flag= 0x01,
|
||||
.svr_namel = __constant_cpu_to_le16(0x0008),
|
||||
.svr_name = {'I','C','S','F',' ',' ',' ',' '}
|
||||
};
|
||||
|
||||
/**
|
||||
* Check the message for PKCS11 padding.
|
||||
*/
|
||||
static inline int is_PKCS11_padded(unsigned char *buffer, int length)
|
||||
{
|
||||
int i;
|
||||
if ((buffer[0] != 0x00) || (buffer[1] != 0x01))
|
||||
return 0;
|
||||
for (i = 2; i < length; i++)
|
||||
if (buffer[i] != 0xFF)
|
||||
break;
|
||||
if (i < 10 || i == length)
|
||||
return 0;
|
||||
if (buffer[i] != 0x00)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the message for PKCS12 padding.
|
||||
*/
|
||||
static inline int is_PKCS12_padded(unsigned char *buffer, int length)
|
||||
{
|
||||
int i;
|
||||
if ((buffer[0] != 0x00) || (buffer[1] != 0x02))
|
||||
return 0;
|
||||
for (i = 2; i < length; i++)
|
||||
if (buffer[i] == 0x00)
|
||||
break;
|
||||
if ((i < 10) || (i == length))
|
||||
return 0;
|
||||
if (buffer[i] != 0x00)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a ICAMEX message to a type6 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_type6MEX_msg(struct zcrypt_device *zdev,
|
||||
struct ap_message *ap_msg,
|
||||
struct ica_rsa_modexpo *mex)
|
||||
{
|
||||
static struct type6_hdr static_type6_hdr = {
|
||||
.type = 0x06,
|
||||
.offset1 = 0x00000058,
|
||||
.agent_id = {0x01,0x00,0x43,0x43,0x41,0x2D,0x41,0x50,
|
||||
0x50,0x4C,0x20,0x20,0x20,0x01,0x01,0x01},
|
||||
.function_code = {'P','K'},
|
||||
};
|
||||
static struct function_and_rules_block static_pke_function_and_rules ={
|
||||
.function_code = {'P','K'},
|
||||
.ulen = __constant_cpu_to_le16(10),
|
||||
.only_rule = {'P','K','C','S','-','1','.','2'}
|
||||
};
|
||||
struct {
|
||||
struct type6_hdr hdr;
|
||||
struct CPRB cprb;
|
||||
struct function_and_rules_block fr;
|
||||
unsigned short length;
|
||||
char text[0];
|
||||
} __attribute__((packed)) *msg = ap_msg->message;
|
||||
int vud_len, pad_len, size;
|
||||
|
||||
/* VUD.ciphertext */
|
||||
if (copy_from_user(msg->text, mex->inputdata, mex->inputdatalength))
|
||||
return -EFAULT;
|
||||
|
||||
if (is_PKCS11_padded(msg->text, mex->inputdatalength))
|
||||
return -EINVAL;
|
||||
|
||||
/* static message header and f&r */
|
||||
msg->hdr = static_type6_hdr;
|
||||
msg->fr = static_pke_function_and_rules;
|
||||
|
||||
if (is_PKCS12_padded(msg->text, mex->inputdatalength)) {
|
||||
/* strip the padding and adjust the data length */
|
||||
pad_len = strnlen(msg->text + 2, mex->inputdatalength - 2) + 3;
|
||||
if (pad_len <= 9 || pad_len >= mex->inputdatalength)
|
||||
return -ENODEV;
|
||||
vud_len = mex->inputdatalength - pad_len;
|
||||
memmove(msg->text, msg->text + pad_len, vud_len);
|
||||
msg->length = cpu_to_le16(vud_len + 2);
|
||||
|
||||
/* Set up key after the variable length text. */
|
||||
size = zcrypt_type6_mex_key_en(mex, msg->text + vud_len, 0);
|
||||
if (size < 0)
|
||||
return size;
|
||||
size += sizeof(*msg) + vud_len; /* total size of msg */
|
||||
} else {
|
||||
vud_len = mex->inputdatalength;
|
||||
msg->length = cpu_to_le16(2 + vud_len);
|
||||
|
||||
msg->hdr.function_code[1] = 'D';
|
||||
msg->fr.function_code[1] = 'D';
|
||||
|
||||
/* Set up key after the variable length text. */
|
||||
size = zcrypt_type6_mex_key_de(mex, msg->text + vud_len, 0);
|
||||
if (size < 0)
|
||||
return size;
|
||||
size += sizeof(*msg) + vud_len; /* total size of msg */
|
||||
}
|
||||
|
||||
/* message header, cprb and f&r */
|
||||
msg->hdr.ToCardLen1 = (size - sizeof(msg->hdr) + 3) & -4;
|
||||
msg->hdr.FromCardLen1 = PCICC_MAX_RESPONSE_SIZE - sizeof(msg->hdr);
|
||||
|
||||
msg->cprb = static_cprb;
|
||||
msg->cprb.usage_domain[0]= AP_QID_QUEUE(zdev->ap_dev->qid);
|
||||
msg->cprb.req_parml = cpu_to_le16(size - sizeof(msg->hdr) -
|
||||
sizeof(msg->cprb));
|
||||
msg->cprb.rpl_parml = cpu_to_le16(msg->hdr.FromCardLen1);
|
||||
|
||||
ap_msg->length = (size + 3) & -4;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a ICACRT message to a type6 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_type6CRT_msg(struct zcrypt_device *zdev,
|
||||
struct ap_message *ap_msg,
|
||||
struct ica_rsa_modexpo_crt *crt)
|
||||
{
|
||||
static struct type6_hdr static_type6_hdr = {
|
||||
.type = 0x06,
|
||||
.offset1 = 0x00000058,
|
||||
.agent_id = {0x01,0x00,0x43,0x43,0x41,0x2D,0x41,0x50,
|
||||
0x50,0x4C,0x20,0x20,0x20,0x01,0x01,0x01},
|
||||
.function_code = {'P','D'},
|
||||
};
|
||||
static struct function_and_rules_block static_pkd_function_and_rules ={
|
||||
.function_code = {'P','D'},
|
||||
.ulen = __constant_cpu_to_le16(10),
|
||||
.only_rule = {'P','K','C','S','-','1','.','2'}
|
||||
};
|
||||
struct {
|
||||
struct type6_hdr hdr;
|
||||
struct CPRB cprb;
|
||||
struct function_and_rules_block fr;
|
||||
unsigned short length;
|
||||
char text[0];
|
||||
} __attribute__((packed)) *msg = ap_msg->message;
|
||||
int size;
|
||||
|
||||
/* VUD.ciphertext */
|
||||
msg->length = cpu_to_le16(2 + crt->inputdatalength);
|
||||
if (copy_from_user(msg->text, crt->inputdata, crt->inputdatalength))
|
||||
return -EFAULT;
|
||||
|
||||
if (is_PKCS11_padded(msg->text, crt->inputdatalength))
|
||||
return -EINVAL;
|
||||
|
||||
/* Set up key after the variable length text. */
|
||||
size = zcrypt_type6_crt_key(crt, msg->text + crt->inputdatalength, 0);
|
||||
if (size < 0)
|
||||
return size;
|
||||
size += sizeof(*msg) + crt->inputdatalength; /* total size of msg */
|
||||
|
||||
/* message header, cprb and f&r */
|
||||
msg->hdr = static_type6_hdr;
|
||||
msg->hdr.ToCardLen1 = (size - sizeof(msg->hdr) + 3) & -4;
|
||||
msg->hdr.FromCardLen1 = PCICC_MAX_RESPONSE_SIZE - sizeof(msg->hdr);
|
||||
|
||||
msg->cprb = static_cprb;
|
||||
msg->cprb.usage_domain[0] = AP_QID_QUEUE(zdev->ap_dev->qid);
|
||||
msg->cprb.req_parml = msg->cprb.rpl_parml =
|
||||
cpu_to_le16(size - sizeof(msg->hdr) - sizeof(msg->cprb));
|
||||
|
||||
msg->fr = static_pkd_function_and_rules;
|
||||
|
||||
ap_msg->length = (size + 3) & -4;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy results from a type 86 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 -EINVAL, -EFAULT, -EAGAIN in case of an error.
|
||||
*/
|
||||
struct type86_reply {
|
||||
struct type86_hdr hdr;
|
||||
struct type86_fmt2_ext fmt2;
|
||||
struct CPRB cprb;
|
||||
unsigned char pad[4]; /* 4 byte function code/rules block ? */
|
||||
unsigned short length;
|
||||
char text[0];
|
||||
} __attribute__((packed));
|
||||
|
||||
static int convert_type86(struct zcrypt_device *zdev,
|
||||
struct ap_message *reply,
|
||||
char __user *outputdata,
|
||||
unsigned int outputdatalength)
|
||||
{
|
||||
static unsigned char static_pad[] = {
|
||||
0x00,0x02,
|
||||
0x1B,0x7B,0x5D,0xB5,0x75,0x01,0x3D,0xFD,
|
||||
0x8D,0xD1,0xC7,0x03,0x2D,0x09,0x23,0x57,
|
||||
0x89,0x49,0xB9,0x3F,0xBB,0x99,0x41,0x5B,
|
||||
0x75,0x21,0x7B,0x9D,0x3B,0x6B,0x51,0x39,
|
||||
0xBB,0x0D,0x35,0xB9,0x89,0x0F,0x93,0xA5,
|
||||
0x0B,0x47,0xF1,0xD3,0xBB,0xCB,0xF1,0x9D,
|
||||
0x23,0x73,0x71,0xFF,0xF3,0xF5,0x45,0xFB,
|
||||
0x61,0x29,0x23,0xFD,0xF1,0x29,0x3F,0x7F,
|
||||
0x17,0xB7,0x1B,0xA9,0x19,0xBD,0x57,0xA9,
|
||||
0xD7,0x95,0xA3,0xCB,0xED,0x1D,0xDB,0x45,
|
||||
0x7D,0x11,0xD1,0x51,0x1B,0xED,0x71,0xE9,
|
||||
0xB1,0xD1,0xAB,0xAB,0x21,0x2B,0x1B,0x9F,
|
||||
0x3B,0x9F,0xF7,0xF7,0xBD,0x63,0xEB,0xAD,
|
||||
0xDF,0xB3,0x6F,0x5B,0xDB,0x8D,0xA9,0x5D,
|
||||
0xE3,0x7D,0x77,0x49,0x47,0xF5,0xA7,0xFD,
|
||||
0xAB,0x2F,0x27,0x35,0x77,0xD3,0x49,0xC9,
|
||||
0x09,0xEB,0xB1,0xF9,0xBF,0x4B,0xCB,0x2B,
|
||||
0xEB,0xEB,0x05,0xFF,0x7D,0xC7,0x91,0x8B,
|
||||
0x09,0x83,0xB9,0xB9,0x69,0x33,0x39,0x6B,
|
||||
0x79,0x75,0x19,0xBF,0xBB,0x07,0x1D,0xBD,
|
||||
0x29,0xBF,0x39,0x95,0x93,0x1D,0x35,0xC7,
|
||||
0xC9,0x4D,0xE5,0x97,0x0B,0x43,0x9B,0xF1,
|
||||
0x16,0x93,0x03,0x1F,0xA5,0xFB,0xDB,0xF3,
|
||||
0x27,0x4F,0x27,0x61,0x05,0x1F,0xB9,0x23,
|
||||
0x2F,0xC3,0x81,0xA9,0x23,0x71,0x55,0x55,
|
||||
0xEB,0xED,0x41,0xE5,0xF3,0x11,0xF1,0x43,
|
||||
0x69,0x03,0xBD,0x0B,0x37,0x0F,0x51,0x8F,
|
||||
0x0B,0xB5,0x89,0x5B,0x67,0xA9,0xD9,0x4F,
|
||||
0x01,0xF9,0x21,0x77,0x37,0x73,0x79,0xC5,
|
||||
0x7F,0x51,0xC1,0xCF,0x97,0xA1,0x75,0xAD,
|
||||
0x35,0x9D,0xD3,0xD3,0xA7,0x9D,0x5D,0x41,
|
||||
0x6F,0x65,0x1B,0xCF,0xA9,0x87,0x91,0x09
|
||||
};
|
||||
struct type86_reply *msg = reply->message;
|
||||
unsigned short service_rc, service_rs;
|
||||
unsigned int reply_len, pad_len;
|
||||
char *data;
|
||||
|
||||
service_rc = le16_to_cpu(msg->cprb.ccp_rtcode);
|
||||
if (unlikely(service_rc != 0)) {
|
||||
service_rs = le16_to_cpu(msg->cprb.ccp_rscode);
|
||||
if (service_rc == 8 && service_rs == 66)
|
||||
return -EINVAL;
|
||||
if (service_rc == 8 && service_rs == 65)
|
||||
return -EINVAL;
|
||||
if (service_rc == 8 && service_rs == 770) {
|
||||
zdev->max_mod_size = PCICC_MAX_MOD_SIZE_OLD;
|
||||
return -EAGAIN;
|
||||
}
|
||||
if (service_rc == 8 && service_rs == 783) {
|
||||
zdev->max_mod_size = PCICC_MAX_MOD_SIZE_OLD;
|
||||
return -EAGAIN;
|
||||
}
|
||||
if (service_rc == 8 && service_rs == 72)
|
||||
return -EINVAL;
|
||||
zdev->online = 0;
|
||||
pr_err("Cryptographic device %x failed and was set offline\n",
|
||||
zdev->ap_dev->qid);
|
||||
ZCRYPT_DBF_DEV(DBF_ERR, zdev, "dev%04xo%drc%d",
|
||||
zdev->ap_dev->qid, zdev->online,
|
||||
msg->hdr.reply_code);
|
||||
return -EAGAIN; /* repeat the request on a different device. */
|
||||
}
|
||||
data = msg->text;
|
||||
reply_len = le16_to_cpu(msg->length) - 2;
|
||||
if (reply_len > outputdatalength)
|
||||
return -EINVAL;
|
||||
/*
|
||||
* For all encipher requests, the length of the ciphertext (reply_len)
|
||||
* will always equal the modulus length. For MEX decipher requests
|
||||
* the output needs to get padded. Minimum pad size is 10.
|
||||
*
|
||||
* Currently, the cases where padding will be added is for:
|
||||
* - PCIXCC_MCL2 using a CRT form token (since PKD didn't support
|
||||
* ZERO-PAD and CRT is only supported for PKD requests)
|
||||
* - PCICC, always
|
||||
*/
|
||||
pad_len = outputdatalength - reply_len;
|
||||
if (pad_len > 0) {
|
||||
if (pad_len < 10)
|
||||
return -EINVAL;
|
||||
/* 'restore' padding left in the PCICC/PCIXCC card. */
|
||||
if (copy_to_user(outputdata, static_pad, pad_len - 1))
|
||||
return -EFAULT;
|
||||
if (put_user(0, outputdata + pad_len - 1))
|
||||
return -EFAULT;
|
||||
}
|
||||
/* Copy the crypto response to user space. */
|
||||
if (copy_to_user(outputdata + pad_len, data, reply_len))
|
||||
return -EFAULT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int convert_response(struct zcrypt_device *zdev,
|
||||
struct ap_message *reply,
|
||||
char __user *outputdata,
|
||||
unsigned int outputdatalength)
|
||||
{
|
||||
struct type86_reply *msg = reply->message;
|
||||
|
||||
/* Response type byte is the second byte in the response. */
|
||||
switch (msg->hdr.type) {
|
||||
case TYPE82_RSP_CODE:
|
||||
case TYPE88_RSP_CODE:
|
||||
return convert_error(zdev, reply);
|
||||
case TYPE86_RSP_CODE:
|
||||
if (msg->hdr.reply_code)
|
||||
return convert_error(zdev, reply);
|
||||
if (msg->cprb.cprb_ver_id == 0x01)
|
||||
return convert_type86(zdev, reply,
|
||||
outputdata, outputdatalength);
|
||||
/* no break, incorrect cprb version is an unknown response */
|
||||
default: /* Unknown response type, this should NEVER EVER happen */
|
||||
zdev->online = 0;
|
||||
pr_err("Cryptographic device %x failed and was set offline\n",
|
||||
zdev->ap_dev->qid);
|
||||
ZCRYPT_DBF_DEV(DBF_ERR, zdev, "dev%04xo%dfail",
|
||||
zdev->ap_dev->qid, zdev->online);
|
||||
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_pcicc_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 type86_reply *t86r;
|
||||
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;
|
||||
}
|
||||
t86r = reply->message;
|
||||
if (t86r->hdr.type == TYPE86_RSP_CODE &&
|
||||
t86r->cprb.cprb_ver_id == 0x01) {
|
||||
length = sizeof(struct type86_reply) + t86r->length - 2;
|
||||
length = min(PCICC_MAX_RESPONSE_SIZE, length);
|
||||
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 PCICC
|
||||
* device to handle a modexpo request.
|
||||
* @zdev: pointer to zcrypt_device structure that identifies the
|
||||
* PCICC device to the request distributor
|
||||
* @mex: pointer to the modexpo request buffer
|
||||
*/
|
||||
static long zcrypt_pcicc_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);
|
||||
ap_msg.message = (void *) get_zeroed_page(GFP_KERNEL);
|
||||
if (!ap_msg.message)
|
||||
return -ENOMEM;
|
||||
ap_msg.receive = zcrypt_pcicc_receive;
|
||||
ap_msg.length = PAGE_SIZE;
|
||||
ap_msg.psmid = (((unsigned long long) current->pid) << 32) +
|
||||
atomic_inc_return(&zcrypt_step);
|
||||
ap_msg.private = &work;
|
||||
rc = ICAMEX_msg_to_type6MEX_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:
|
||||
free_page((unsigned long) ap_msg.message);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
* The request distributor calls this function if it picked the PCICC
|
||||
* device to handle a modexpo_crt request.
|
||||
* @zdev: pointer to zcrypt_device structure that identifies the
|
||||
* PCICC device to the request distributor
|
||||
* @crt: pointer to the modexpoc_crt request buffer
|
||||
*/
|
||||
static long zcrypt_pcicc_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);
|
||||
ap_msg.message = (void *) get_zeroed_page(GFP_KERNEL);
|
||||
if (!ap_msg.message)
|
||||
return -ENOMEM;
|
||||
ap_msg.receive = zcrypt_pcicc_receive;
|
||||
ap_msg.length = PAGE_SIZE;
|
||||
ap_msg.psmid = (((unsigned long long) current->pid) << 32) +
|
||||
atomic_inc_return(&zcrypt_step);
|
||||
ap_msg.private = &work;
|
||||
rc = ICACRT_msg_to_type6CRT_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:
|
||||
free_page((unsigned long) ap_msg.message);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
* The crypto operations for a PCICC card.
|
||||
*/
|
||||
static struct zcrypt_ops zcrypt_pcicc_ops = {
|
||||
.rsa_modexpo = zcrypt_pcicc_modexpo,
|
||||
.rsa_modexpo_crt = zcrypt_pcicc_modexpo_crt,
|
||||
};
|
||||
|
||||
/**
|
||||
* Probe function for PCICC cards. It always accepts the AP device
|
||||
* since the bus_match already checked the hardware type.
|
||||
* @ap_dev: pointer to the AP device.
|
||||
*/
|
||||
static int zcrypt_pcicc_probe(struct ap_device *ap_dev)
|
||||
{
|
||||
struct zcrypt_device *zdev;
|
||||
int rc;
|
||||
|
||||
zdev = zcrypt_device_alloc(PCICC_MAX_RESPONSE_SIZE);
|
||||
if (!zdev)
|
||||
return -ENOMEM;
|
||||
zdev->ap_dev = ap_dev;
|
||||
zdev->ops = &zcrypt_pcicc_ops;
|
||||
zdev->online = 1;
|
||||
zdev->user_space_type = ZCRYPT_PCICC;
|
||||
zdev->type_string = "PCICC";
|
||||
zdev->min_mod_size = PCICC_MIN_MOD_SIZE;
|
||||
zdev->max_mod_size = PCICC_MAX_MOD_SIZE;
|
||||
zdev->speed_rating = PCICC_SPEED_RATING;
|
||||
zdev->max_exp_bit_length = PCICC_MAX_MOD_SIZE;
|
||||
ap_dev->reply = &zdev->reply;
|
||||
ap_dev->private = zdev;
|
||||
rc = zcrypt_device_register(zdev);
|
||||
if (rc)
|
||||
goto out_free;
|
||||
return 0;
|
||||
|
||||
out_free:
|
||||
ap_dev->private = NULL;
|
||||
zcrypt_device_free(zdev);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is called to remove the extended PCICC driver information
|
||||
* if an AP device is removed.
|
||||
*/
|
||||
static void zcrypt_pcicc_remove(struct ap_device *ap_dev)
|
||||
{
|
||||
struct zcrypt_device *zdev = ap_dev->private;
|
||||
|
||||
zcrypt_device_unregister(zdev);
|
||||
}
|
||||
|
||||
int __init zcrypt_pcicc_init(void)
|
||||
{
|
||||
return ap_driver_register(&zcrypt_pcicc_driver, THIS_MODULE, "pcicc");
|
||||
}
|
||||
|
||||
void zcrypt_pcicc_exit(void)
|
||||
{
|
||||
ap_driver_unregister(&zcrypt_pcicc_driver);
|
||||
}
|
||||
|
||||
module_init(zcrypt_pcicc_init);
|
||||
module_exit(zcrypt_pcicc_exit);
|
174
drivers/s390/crypto/zcrypt_pcicc.h
Normal file
174
drivers/s390/crypto/zcrypt_pcicc.h
Normal file
|
@ -0,0 +1,174 @@
|
|||
/*
|
||||
* zcrypt 2.1.0
|
||||
*
|
||||
* Copyright IBM Corp. 2001, 2006
|
||||
* 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>
|
||||
*
|
||||
* 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_PCICC_H_
|
||||
#define _ZCRYPT_PCICC_H_
|
||||
|
||||
/**
|
||||
* 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 */
|
||||
} __attribute__((packed));
|
||||
|
||||
/**
|
||||
* CPRB
|
||||
* Note that all shorts, ints and longs are little-endian.
|
||||
* All pointer fields are 32-bits long, and mean nothing
|
||||
*
|
||||
* A request CPRB is followed by a request_parameter_block.
|
||||
*
|
||||
* The request (or reply) parameter block is organized thus:
|
||||
* function code
|
||||
* VUD block
|
||||
* key block
|
||||
*/
|
||||
struct CPRB {
|
||||
unsigned short cprb_len; /* CPRB length */
|
||||
unsigned char cprb_ver_id; /* CPRB version id. */
|
||||
unsigned char pad_000; /* Alignment pad byte. */
|
||||
unsigned char srpi_rtcode[4]; /* SRPI return code LELONG */
|
||||
unsigned char srpi_verb; /* SRPI verb type */
|
||||
unsigned char flags; /* flags */
|
||||
unsigned char func_id[2]; /* function id */
|
||||
unsigned char checkpoint_flag; /* */
|
||||
unsigned char resv2; /* reserved */
|
||||
unsigned short req_parml; /* request parameter buffer */
|
||||
/* length 16-bit little endian */
|
||||
unsigned char req_parmp[4]; /* request parameter buffer *
|
||||
* pointer (means nothing: the *
|
||||
* parameter buffer follows *
|
||||
* the CPRB). */
|
||||
unsigned char req_datal[4]; /* request data buffer */
|
||||
/* length ULELONG */
|
||||
unsigned char req_datap[4]; /* request data buffer */
|
||||
/* pointer */
|
||||
unsigned short rpl_parml; /* reply parameter buffer */
|
||||
/* length 16-bit little endian */
|
||||
unsigned char pad_001[2]; /* Alignment pad bytes. ULESHORT */
|
||||
unsigned char rpl_parmp[4]; /* reply parameter buffer *
|
||||
* pointer (means nothing: the *
|
||||
* parameter buffer follows *
|
||||
* the CPRB). */
|
||||
unsigned char rpl_datal[4]; /* reply data buffer len ULELONG */
|
||||
unsigned char rpl_datap[4]; /* reply data buffer */
|
||||
/* pointer */
|
||||
unsigned short ccp_rscode; /* server reason code ULESHORT */
|
||||
unsigned short ccp_rtcode; /* server return code ULESHORT */
|
||||
unsigned char repd_parml[2]; /* replied parameter len ULESHORT*/
|
||||
unsigned char mac_data_len[2]; /* Mac Data Length ULESHORT */
|
||||
unsigned char repd_datal[4]; /* replied data length ULELONG */
|
||||
unsigned char req_pc[2]; /* PC identifier */
|
||||
unsigned char res_origin[8]; /* resource origin */
|
||||
unsigned char mac_value[8]; /* Mac Value */
|
||||
unsigned char logon_id[8]; /* Logon Identifier */
|
||||
unsigned char usage_domain[2]; /* cdx */
|
||||
unsigned char resv3[18]; /* reserved for requestor */
|
||||
unsigned short svr_namel; /* server name length ULESHORT */
|
||||
unsigned char svr_name[8]; /* server name */
|
||||
} __attribute__((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 */
|
||||
} __attribute__((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 */
|
||||
} __attribute__((packed));
|
||||
|
||||
struct function_and_rules_block {
|
||||
unsigned char function_code[2];
|
||||
unsigned short ulen;
|
||||
unsigned char only_rule[8];
|
||||
} __attribute__((packed));
|
||||
|
||||
int zcrypt_pcicc_init(void);
|
||||
void zcrypt_pcicc_exit(void);
|
||||
|
||||
#endif /* _ZCRYPT_PCICC_H_ */
|
368
drivers/s390/crypto/zcrypt_pcixcc.c
Normal file
368
drivers/s390/crypto/zcrypt_pcixcc.c
Normal file
|
@ -0,0 +1,368 @@
|
|||
/*
|
||||
* 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>
|
||||
* 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
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/atomic.h>
|
||||
#include <asm/uaccess.h>
|
||||
|
||||
#include "ap_bus.h"
|
||||
#include "zcrypt_api.h"
|
||||
#include "zcrypt_error.h"
|
||||
#include "zcrypt_msgtype6.h"
|
||||
#include "zcrypt_pcixcc.h"
|
||||
#include "zcrypt_cca_key.h"
|
||||
|
||||
#define PCIXCC_MIN_MOD_SIZE 16 /* 128 bits */
|
||||
#define PCIXCC_MIN_MOD_SIZE_OLD 64 /* 512 bits */
|
||||
#define PCIXCC_MAX_MOD_SIZE 256 /* 2048 bits */
|
||||
#define CEX3C_MIN_MOD_SIZE PCIXCC_MIN_MOD_SIZE
|
||||
#define CEX3C_MAX_MOD_SIZE 512 /* 4096 bits */
|
||||
|
||||
#define PCIXCC_MCL2_SPEED_RATING 7870
|
||||
#define PCIXCC_MCL3_SPEED_RATING 7870
|
||||
#define CEX2C_SPEED_RATING 7000
|
||||
#define CEX3C_SPEED_RATING 6500
|
||||
|
||||
#define PCIXCC_MAX_ICA_MESSAGE_SIZE 0x77c /* max size type6 v2 crt message */
|
||||
#define PCIXCC_MAX_ICA_RESPONSE_SIZE 0x77c /* max size type86 v2 reply */
|
||||
|
||||
#define PCIXCC_MAX_XCRB_MESSAGE_SIZE (12*1024)
|
||||
|
||||
#define PCIXCC_CLEANUP_TIME (15*HZ)
|
||||
|
||||
#define CEIL4(x) ((((x)+3)/4)*4)
|
||||
|
||||
struct response_type {
|
||||
struct completion work;
|
||||
int type;
|
||||
};
|
||||
#define PCIXCC_RESPONSE_TYPE_ICA 0
|
||||
#define PCIXCC_RESPONSE_TYPE_XCRB 1
|
||||
|
||||
static struct ap_device_id zcrypt_pcixcc_ids[] = {
|
||||
{ AP_DEVICE(AP_DEVICE_TYPE_PCIXCC) },
|
||||
{ AP_DEVICE(AP_DEVICE_TYPE_CEX2C) },
|
||||
{ AP_DEVICE(AP_DEVICE_TYPE_CEX3C) },
|
||||
{ /* end of list */ },
|
||||
};
|
||||
|
||||
MODULE_DEVICE_TABLE(ap, zcrypt_pcixcc_ids);
|
||||
MODULE_AUTHOR("IBM Corporation");
|
||||
MODULE_DESCRIPTION("PCIXCC Cryptographic Coprocessor device driver, " \
|
||||
"Copyright IBM Corp. 2001, 2012");
|
||||
MODULE_LICENSE("GPL");
|
||||
|
||||
static int zcrypt_pcixcc_probe(struct ap_device *ap_dev);
|
||||
static void zcrypt_pcixcc_remove(struct ap_device *ap_dev);
|
||||
|
||||
static struct ap_driver zcrypt_pcixcc_driver = {
|
||||
.probe = zcrypt_pcixcc_probe,
|
||||
.remove = zcrypt_pcixcc_remove,
|
||||
.ids = zcrypt_pcixcc_ids,
|
||||
.request_timeout = PCIXCC_CLEANUP_TIME,
|
||||
};
|
||||
|
||||
/**
|
||||
* Micro-code detection function. Its sends a message to a pcixcc card
|
||||
* to find out the microcode level.
|
||||
* @ap_dev: pointer to the AP device.
|
||||
*/
|
||||
static int zcrypt_pcixcc_mcl(struct ap_device *ap_dev)
|
||||
{
|
||||
static unsigned char msg[] = {
|
||||
0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x58,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x43,0x41,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x50,0x4B,0x00,0x00,
|
||||
0x00,0x00,0x01,0xC4,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x07,0x24,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0xDC,0x02,0x00,0x00,0x00,0x54,0x32,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE8,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x24,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x50,0x4B,0x00,0x0A,
|
||||
0x4D,0x52,0x50,0x20,0x20,0x20,0x20,0x20,
|
||||
0x00,0x42,0x00,0x01,0x02,0x03,0x04,0x05,
|
||||
0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,
|
||||
0x0E,0x0F,0x00,0x11,0x22,0x33,0x44,0x55,
|
||||
0x66,0x77,0x88,0x99,0xAA,0xBB,0xCC,0xDD,
|
||||
0xEE,0xFF,0xFF,0xEE,0xDD,0xCC,0xBB,0xAA,
|
||||
0x99,0x88,0x77,0x66,0x55,0x44,0x33,0x22,
|
||||
0x11,0x00,0x01,0x23,0x45,0x67,0x89,0xAB,
|
||||
0xCD,0xEF,0xFE,0xDC,0xBA,0x98,0x76,0x54,
|
||||
0x32,0x10,0x00,0x9A,0x00,0x98,0x00,0x00,
|
||||
0x1E,0x00,0x00,0x94,0x00,0x00,0x00,0x00,
|
||||
0x04,0x00,0x00,0x8C,0x00,0x00,0x00,0x40,
|
||||
0x02,0x00,0x00,0x40,0xBA,0xE8,0x23,0x3C,
|
||||
0x75,0xF3,0x91,0x61,0xD6,0x73,0x39,0xCF,
|
||||
0x7B,0x6D,0x8E,0x61,0x97,0x63,0x9E,0xD9,
|
||||
0x60,0x55,0xD6,0xC7,0xEF,0xF8,0x1E,0x63,
|
||||
0x95,0x17,0xCC,0x28,0x45,0x60,0x11,0xC5,
|
||||
0xC4,0x4E,0x66,0xC6,0xE6,0xC3,0xDE,0x8A,
|
||||
0x19,0x30,0xCF,0x0E,0xD7,0xAA,0xDB,0x01,
|
||||
0xD8,0x00,0xBB,0x8F,0x39,0x9F,0x64,0x28,
|
||||
0xF5,0x7A,0x77,0x49,0xCC,0x6B,0xA3,0x91,
|
||||
0x97,0x70,0xE7,0x60,0x1E,0x39,0xE1,0xE5,
|
||||
0x33,0xE1,0x15,0x63,0x69,0x08,0x80,0x4C,
|
||||
0x67,0xC4,0x41,0x8F,0x48,0xDF,0x26,0x98,
|
||||
0xF1,0xD5,0x8D,0x88,0xD9,0x6A,0xA4,0x96,
|
||||
0xC5,0x84,0xD9,0x30,0x49,0x67,0x7D,0x19,
|
||||
0xB1,0xB3,0x45,0x4D,0xB2,0x53,0x9A,0x47,
|
||||
0x3C,0x7C,0x55,0xBF,0xCC,0x85,0x00,0x36,
|
||||
0xF1,0x3D,0x93,0x53
|
||||
};
|
||||
unsigned long long psmid;
|
||||
struct CPRBX *cprbx;
|
||||
char *reply;
|
||||
int rc, i;
|
||||
|
||||
reply = (void *) get_zeroed_page(GFP_KERNEL);
|
||||
if (!reply)
|
||||
return -ENOMEM;
|
||||
|
||||
rc = ap_send(ap_dev->qid, 0x0102030405060708ULL, msg, sizeof(msg));
|
||||
if (rc)
|
||||
goto out_free;
|
||||
|
||||
/* Wait for the test message to complete. */
|
||||
for (i = 0; i < 6; i++) {
|
||||
mdelay(300);
|
||||
rc = ap_recv(ap_dev->qid, &psmid, reply, 4096);
|
||||
if (rc == 0 && psmid == 0x0102030405060708ULL)
|
||||
break;
|
||||
}
|
||||
|
||||
if (i >= 6) {
|
||||
/* Got no answer. */
|
||||
rc = -ENODEV;
|
||||
goto out_free;
|
||||
}
|
||||
|
||||
cprbx = (struct CPRBX *) (reply + 48);
|
||||
if (cprbx->ccp_rtcode == 8 && cprbx->ccp_rscode == 33)
|
||||
rc = ZCRYPT_PCIXCC_MCL2;
|
||||
else
|
||||
rc = ZCRYPT_PCIXCC_MCL3;
|
||||
out_free:
|
||||
free_page((unsigned long) reply);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Large random number detection function. Its sends a message to a pcixcc
|
||||
* card to find out if large random numbers are supported.
|
||||
* @ap_dev: pointer to the AP device.
|
||||
*
|
||||
* Returns 1 if large random numbers are supported, 0 if not and < 0 on error.
|
||||
*/
|
||||
static int zcrypt_pcixcc_rng_supported(struct ap_device *ap_dev)
|
||||
{
|
||||
struct ap_message ap_msg;
|
||||
unsigned long long psmid;
|
||||
struct {
|
||||
struct type86_hdr hdr;
|
||||
struct type86_fmt2_ext fmt2;
|
||||
struct CPRBX cprbx;
|
||||
} __attribute__((packed)) *reply;
|
||||
int rc, i;
|
||||
|
||||
ap_init_message(&ap_msg);
|
||||
ap_msg.message = (void *) get_zeroed_page(GFP_KERNEL);
|
||||
if (!ap_msg.message)
|
||||
return -ENOMEM;
|
||||
|
||||
rng_type6CPRB_msgX(ap_dev, &ap_msg, 4);
|
||||
rc = ap_send(ap_dev->qid, 0x0102030405060708ULL, ap_msg.message,
|
||||
ap_msg.length);
|
||||
if (rc)
|
||||
goto out_free;
|
||||
|
||||
/* Wait for the test message to complete. */
|
||||
for (i = 0; i < 2 * HZ; i++) {
|
||||
msleep(1000 / HZ);
|
||||
rc = ap_recv(ap_dev->qid, &psmid, ap_msg.message, 4096);
|
||||
if (rc == 0 && psmid == 0x0102030405060708ULL)
|
||||
break;
|
||||
}
|
||||
|
||||
if (i >= 2 * HZ) {
|
||||
/* Got no answer. */
|
||||
rc = -ENODEV;
|
||||
goto out_free;
|
||||
}
|
||||
|
||||
reply = ap_msg.message;
|
||||
if (reply->cprbx.ccp_rtcode == 0 && reply->cprbx.ccp_rscode == 0)
|
||||
rc = 1;
|
||||
else
|
||||
rc = 0;
|
||||
out_free:
|
||||
free_page((unsigned long) ap_msg.message);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Probe function for PCIXCC/CEX2C cards. It always accepts the AP device
|
||||
* since the bus_match already checked the hardware type. The PCIXCC
|
||||
* cards come in two flavours: micro code level 2 and micro code level 3.
|
||||
* This is checked by sending a test message to the device.
|
||||
* @ap_dev: pointer to the AP device.
|
||||
*/
|
||||
static int zcrypt_pcixcc_probe(struct ap_device *ap_dev)
|
||||
{
|
||||
struct zcrypt_device *zdev;
|
||||
int rc = 0;
|
||||
|
||||
zdev = zcrypt_device_alloc(PCIXCC_MAX_XCRB_MESSAGE_SIZE);
|
||||
if (!zdev)
|
||||
return -ENOMEM;
|
||||
zdev->ap_dev = ap_dev;
|
||||
zdev->online = 1;
|
||||
switch (ap_dev->device_type) {
|
||||
case AP_DEVICE_TYPE_PCIXCC:
|
||||
rc = zcrypt_pcixcc_mcl(ap_dev);
|
||||
if (rc < 0) {
|
||||
zcrypt_device_free(zdev);
|
||||
return rc;
|
||||
}
|
||||
zdev->user_space_type = rc;
|
||||
if (rc == ZCRYPT_PCIXCC_MCL2) {
|
||||
zdev->type_string = "PCIXCC_MCL2";
|
||||
zdev->speed_rating = PCIXCC_MCL2_SPEED_RATING;
|
||||
zdev->min_mod_size = PCIXCC_MIN_MOD_SIZE_OLD;
|
||||
zdev->max_mod_size = PCIXCC_MAX_MOD_SIZE;
|
||||
zdev->max_exp_bit_length = PCIXCC_MAX_MOD_SIZE;
|
||||
} else {
|
||||
zdev->type_string = "PCIXCC_MCL3";
|
||||
zdev->speed_rating = PCIXCC_MCL3_SPEED_RATING;
|
||||
zdev->min_mod_size = PCIXCC_MIN_MOD_SIZE;
|
||||
zdev->max_mod_size = PCIXCC_MAX_MOD_SIZE;
|
||||
zdev->max_exp_bit_length = PCIXCC_MAX_MOD_SIZE;
|
||||
}
|
||||
break;
|
||||
case AP_DEVICE_TYPE_CEX2C:
|
||||
zdev->user_space_type = ZCRYPT_CEX2C;
|
||||
zdev->type_string = "CEX2C";
|
||||
zdev->speed_rating = CEX2C_SPEED_RATING;
|
||||
zdev->min_mod_size = PCIXCC_MIN_MOD_SIZE;
|
||||
zdev->max_mod_size = PCIXCC_MAX_MOD_SIZE;
|
||||
zdev->max_exp_bit_length = PCIXCC_MAX_MOD_SIZE;
|
||||
break;
|
||||
case AP_DEVICE_TYPE_CEX3C:
|
||||
zdev->user_space_type = ZCRYPT_CEX3C;
|
||||
zdev->type_string = "CEX3C";
|
||||
zdev->speed_rating = CEX3C_SPEED_RATING;
|
||||
zdev->min_mod_size = CEX3C_MIN_MOD_SIZE;
|
||||
zdev->max_mod_size = CEX3C_MAX_MOD_SIZE;
|
||||
zdev->max_exp_bit_length = CEX3C_MAX_MOD_SIZE;
|
||||
break;
|
||||
default:
|
||||
goto out_free;
|
||||
}
|
||||
|
||||
rc = zcrypt_pcixcc_rng_supported(ap_dev);
|
||||
if (rc < 0) {
|
||||
zcrypt_device_free(zdev);
|
||||
return rc;
|
||||
}
|
||||
if (rc)
|
||||
zdev->ops = zcrypt_msgtype_request(MSGTYPE06_NAME,
|
||||
MSGTYPE06_VARIANT_DEFAULT);
|
||||
else
|
||||
zdev->ops = zcrypt_msgtype_request(MSGTYPE06_NAME,
|
||||
MSGTYPE06_VARIANT_NORNG);
|
||||
ap_dev->reply = &zdev->reply;
|
||||
ap_dev->private = zdev;
|
||||
rc = zcrypt_device_register(zdev);
|
||||
if (rc)
|
||||
goto out_free;
|
||||
return 0;
|
||||
|
||||
out_free:
|
||||
ap_dev->private = NULL;
|
||||
zcrypt_msgtype_release(zdev->ops);
|
||||
zcrypt_device_free(zdev);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is called to remove the extended PCIXCC/CEX2C driver information
|
||||
* if an AP device is removed.
|
||||
*/
|
||||
static void zcrypt_pcixcc_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_pcixcc_init(void)
|
||||
{
|
||||
return ap_driver_register(&zcrypt_pcixcc_driver, THIS_MODULE, "pcixcc");
|
||||
}
|
||||
|
||||
void zcrypt_pcixcc_exit(void)
|
||||
{
|
||||
ap_driver_unregister(&zcrypt_pcixcc_driver);
|
||||
}
|
||||
|
||||
module_init(zcrypt_pcixcc_init);
|
||||
module_exit(zcrypt_pcixcc_exit);
|
33
drivers/s390/crypto/zcrypt_pcixcc.h
Normal file
33
drivers/s390/crypto/zcrypt_pcixcc.h
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* 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_PCIXCC_H_
|
||||
#define _ZCRYPT_PCIXCC_H_
|
||||
|
||||
int zcrypt_pcixcc_init(void);
|
||||
void zcrypt_pcixcc_exit(void);
|
||||
|
||||
#endif /* _ZCRYPT_PCIXCC_H_ */
|
Loading…
Add table
Add a link
Reference in a new issue