📄 z90hardware.c
字号:
/* * linux/drivers/s390/crypto/z90hardware.c * * z90crypt 1.3.2 * * Copyright (C) 2001, 2004 IBM Corporation * Author(s): Robert Burroughs (burrough@us.ibm.com) * Eric Rossman (edrossma@us.ibm.com) * * Hotplug & misc device support: Jochen Roehrig (roehrig@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. */#include <asm/uaccess.h>#include <linux/compiler.h>#include <linux/delay.h>#include <linux/init.h>#include <linux/module.h>#include "z90crypt.h"#include "z90common.h"#define VERSION_Z90HARDWARE_C "$Revision: 1.34 $"char z90hardware_version[] __initdata = "z90hardware.o (" VERSION_Z90HARDWARE_C "/" VERSION_Z90COMMON_H "/" VERSION_Z90CRYPT_H ")";struct cca_token_hdr { unsigned char token_identifier; unsigned char version; unsigned short token_length; unsigned char reserved[4];};#define CCA_TKN_HDR_ID_EXT 0x1Estruct 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];};#define CCA_PVT_USAGE_ALL 0x80struct 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; unsigned char exponent[3];};struct cca_private_ext_ME { struct cca_token_hdr pvtMEHdr; struct cca_private_ext_ME_sec pvtMESec; struct cca_public_sec pubMESec;};struct cca_public_key { struct cca_token_hdr pubHdr; struct cca_public_sec pubSec;};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];};#define CCA_PVT_EXT_CRT_SEC_ID_PVT 0x08#define CCA_PVT_EXT_CRT_SEC_FMT_CL 0x40struct cca_private_ext_CRT { struct cca_token_hdr pvtCrtHdr; struct cca_pvt_ext_CRT_sec pvtCrtSec; struct cca_public_sec pubCrtSec;};struct ap_status_word { unsigned char q_stat_flags; unsigned char response_code; unsigned char reserved[2];};#define AP_Q_STATUS_EMPTY 0x80#define AP_Q_STATUS_REPLIES_WAITING 0x40#define AP_Q_STATUS_ARRAY_FULL 0x20#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_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_MAX_CDX_BITL 4#define AP_RQID_RESERVED_BITL 4#define SKIP_BITL (AP_MAX_CDX_BITL + AP_RQID_RESERVED_BITL)struct type4_hdr { unsigned char reserved1; unsigned char msg_type_code; unsigned short msg_len; unsigned char request_code; unsigned char msg_fmt; unsigned short reserved2;};#define TYPE4_TYPE_CODE 0x04#define TYPE4_REQU_CODE 0x40#define TYPE4_SME_LEN 0x0188#define TYPE4_LME_LEN 0x0308#define TYPE4_SCR_LEN 0x01E0#define TYPE4_LCR_LEN 0x03A0#define TYPE4_SME_FMT 0x00#define TYPE4_LME_FMT 0x10#define TYPE4_SCR_FMT 0x40#define TYPE4_LCR_FMT 0x50struct type4_sme { struct type4_hdr header; unsigned char message[128]; unsigned char exponent[128]; unsigned char modulus[128];};struct type4_lme { struct type4_hdr header; unsigned char message[256]; unsigned char exponent[256]; unsigned char modulus[256];};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];};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];};union type4_msg { struct type4_sme sme; struct type4_lme lme; struct type4_scr scr; struct type4_lcr lcr;};struct type84_hdr { unsigned char reserved1; unsigned char code; unsigned short len; unsigned char reserved2[4];};#define TYPE84_RSP_CODE 0x84struct type6_hdr { unsigned char reserved1; unsigned char type; unsigned char reserved2[2]; unsigned char right[4]; unsigned char reserved3[2]; unsigned char reserved4[2]; unsigned char apfs[4]; unsigned int offset1; unsigned int offset2; unsigned int offset3; unsigned int offset4; unsigned char agent_id[16]; unsigned char rqid[2]; unsigned char reserved5[2]; unsigned char function_code[2]; unsigned char reserved6[2]; unsigned int ToCardLen1; unsigned int ToCardLen2; unsigned int ToCardLen3; unsigned int ToCardLen4; unsigned int FromCardLen1; unsigned int FromCardLen2; unsigned int FromCardLen3; unsigned int FromCardLen4;};struct CPRB { unsigned char cprb_len[2]; unsigned char cprb_ver_id; unsigned char pad_000; unsigned char srpi_rtcode[4]; unsigned char srpi_verb; unsigned char flags; unsigned char func_id[2]; unsigned char checkpoint_flag; unsigned char resv2; unsigned char req_parml[2]; unsigned char req_parmp[4]; unsigned char req_datal[4]; unsigned char req_datap[4]; unsigned char rpl_parml[2]; unsigned char pad_001[2]; unsigned char rpl_parmp[4]; unsigned char rpl_datal[4]; unsigned char rpl_datap[4]; unsigned char ccp_rscode[2]; unsigned char ccp_rtcode[2]; unsigned char repd_parml[2]; unsigned char mac_data_len[2]; unsigned char repd_datal[4]; unsigned char req_pc[2]; unsigned char res_origin[8]; unsigned char mac_value[8]; unsigned char logon_id[8]; unsigned char usage_domain[2]; unsigned char resv3[18]; unsigned char svr_namel[2]; unsigned char svr_name[8];};struct type6_msg { struct type6_hdr header; struct CPRB CPRB;};struct type86_hdr { unsigned char reserved1; unsigned char type; unsigned char format; unsigned char reserved2; unsigned char reply_code; unsigned char reserved3[3];};#define TYPE86_RSP_CODE 0x86#define TYPE86_FMT2 0x02struct type86_fmt2_msg { struct type86_hdr header; unsigned char reserved[4]; unsigned char apfs[4]; unsigned int count1; unsigned int offset1; unsigned int count2; unsigned int offset2; unsigned int count3; unsigned int offset3; unsigned int count4; unsigned int offset4;};static struct type6_hdr static_type6_hdr = { 0x00, 0x06, {0x00,0x00}, {0x00,0x00,0x00,0x00}, {0x00,0x00}, {0x00,0x00}, {0x00,0x00,0x00,0x00}, 0x00000058, 0x00000000, 0x00000000, 0x00000000, {0x01,0x00,0x43,0x43,0x41,0x2D,0x41,0x50, 0x50,0x4C,0x20,0x20,0x20,0x01,0x01,0x01}, {0x00,0x00}, {0x00,0x00}, {0x50,0x44}, {0x00,0x00}, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000};static struct type6_hdr static_type6_hdrX = { 0x00, 0x06, {0x00,0x00}, {0x00,0x00,0x00,0x00}, {0x00,0x00}, {0x00,0x00}, {0x00,0x00,0x00,0x00}, 0x00000058, 0x00000000, 0x00000000, 0x00000000, {0x43,0x41,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0x00,0x00}, {0x00,0x00}, {0x50,0x44}, {0x00,0x00}, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000};static struct CPRB static_cprb = { {0x70,0x00}, 0x41, 0x00, {0x00,0x00,0x00,0x00}, 0x00, 0x00, {0x54,0x32}, 0x01, 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}, {0x08,0x00}, {0x49,0x43,0x53,0x46,0x20,0x20,0x20,0x20}};struct function_and_rules_block { unsigned char function_code[2]; unsigned char ulen[2]; unsigned char only_rule[8];};static struct function_and_rules_block static_pkd_function_and_rules = { {0x50,0x44}, {0x0A,0x00}, {'P','K','C','S','-','1','.','2'}};static struct function_and_rules_block static_pke_function_and_rules = { {0x50,0x4B}, {0x0A,0x00}, {'P','K','C','S','-','1','.','2'}};struct T6_keyBlock_hdr { unsigned char blen[2]; unsigned char ulen[2]; unsigned char flags[2];};static struct T6_keyBlock_hdr static_T6_keyBlock_hdr = { {0x89,0x01}, {0x87,0x01}, {0x00}};static struct CPRBX static_cprbx = { 0x00DC, 0x02, {0x00,0x00,0x00}, {0x54,0x32}, {0x00,0x00,0x00,0x00}, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, {0x00,0x00,0x00,0x00}, 0x00000000, {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}, 0x0000, 0x0000, 0x00000000, {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, 0x00, 0x00, 0x0000, {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}};static struct function_and_rules_block static_pkd_function_and_rulesX_MCL2 = { {0x50,0x44}, {0x00,0x0A}, {'P','K','C','S','-','1','.','2'}};static struct function_and_rules_block static_pke_function_and_rulesX_MCL2 = { {0x50,0x4B}, {0x00,0x0A}, {'Z','E','R','O','-','P','A','D'}};static struct function_and_rules_block static_pkd_function_and_rulesX = { {0x50,0x44}, {0x00,0x0A}, {'Z','E','R','O','-','P','A','D'}};static struct function_and_rules_block static_pke_function_and_rulesX = { {0x50,0x4B}, {0x00,0x0A}, {'M','R','P',' ',' ',' ',' ',' '}};static unsigned char static_PKE_function_code[2] = {0x50, 0x4B};struct T6_keyBlock_hdrX { unsigned short blen; unsigned short ulen; unsigned char flags[2];};static unsigned char static_pad[256] = {0x1B,0x7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,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};static struct cca_private_ext_ME static_pvt_me_key = { { 0x1E, 0x00, 0x0183, {0x00,0x00,0x00,0x00} }, { 0x02, 0x00, 0x016C, {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}, {0x80,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,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -