402 lines
13 KiB
XML
402 lines
13 KiB
XML
<?xml version="1.0" encoding="UTF-8" ?>
|
||
<packet extend="base">
|
||
<req>
|
||
|
||
<command>
|
||
<hex>E0</hex>
|
||
</command>
|
||
<data extend="data" >
|
||
|
||
<packSn len="1" cn="消息块号">
|
||
<options>
|
||
<option cn="仅一块">
|
||
<hex>0</hex>
|
||
</option>
|
||
<option cn="第一块">
|
||
<hex>1</hex>
|
||
</option>
|
||
<option cn="中间块">
|
||
<hex>2</hex>
|
||
</option>
|
||
<option cn="最后块">
|
||
<hex>3</hex>
|
||
</option>
|
||
</options>
|
||
</packSn>
|
||
|
||
<alg len="1" cn="密钥模式">
|
||
<options>
|
||
<option cn="DES加密">
|
||
<hex>0</hex>
|
||
</option>
|
||
<option cn="DES解密">
|
||
<hex>1</hex>
|
||
</option>
|
||
<option cn="AES加密">
|
||
<hex>2</hex>
|
||
</option>
|
||
<option cn="AES解密">
|
||
<hex>3</hex>
|
||
</option>
|
||
<option cn="SSF33 加密">
|
||
<hex>4</hex>
|
||
</option>
|
||
<option cn="SSF33 解密">
|
||
<hex>5</hex>
|
||
</option>
|
||
<option cn="SM1加密">
|
||
<hex>6</hex>
|
||
</option>
|
||
<option cn="SM1解密">
|
||
<hex>7</hex>
|
||
</option>
|
||
<option cn="SM4加密">
|
||
<hex>8</hex>
|
||
</option>
|
||
<option cn="SM4解密">
|
||
<hex>9</hex>
|
||
</option>
|
||
<option cn="IDEA 加密">
|
||
<hex>A</hex>
|
||
</option>
|
||
<option cn="IDEA 解密">
|
||
<hex>B</hex>
|
||
</option>
|
||
<option cn="AES256 加密">
|
||
<hex>C</hex>
|
||
</option>
|
||
<option cn="AES256 解密">
|
||
<hex>D</hex>
|
||
</option>
|
||
</options>
|
||
</alg>
|
||
|
||
<roundModel len="1" cn="轮模式">
|
||
<options>
|
||
<option cn="ECB">
|
||
<hex>1</hex>
|
||
</option>
|
||
<option cn="CBC">
|
||
<hex>2</hex>
|
||
</option>
|
||
<option cn="CFB">
|
||
<hex>3</hex>
|
||
</option>
|
||
<option cn="OFB">
|
||
<hex>4</hex>
|
||
</option>
|
||
</options>
|
||
</roundModel>
|
||
|
||
<keyType len="1" cn="密钥类型">
|
||
<options>
|
||
<option cn="ZEK">
|
||
<hex>0</hex>
|
||
</option>
|
||
<option cn="TEK">
|
||
<hex>1</hex>
|
||
</option>
|
||
</options>
|
||
</keyType>
|
||
|
||
|
||
<key cn="密钥">
|
||
LMK30-31 对下保护的 ZEK
|
||
LMK32-33 对下保护的 TEK
|
||
</key>
|
||
|
||
<inType len="1" cn="输入消息类型">
|
||
<options>
|
||
<option cn="二进制">
|
||
<hex>0</hex>
|
||
</option>
|
||
<option cn="扩展十六进制">
|
||
<hex>1</hex>
|
||
</option>
|
||
</options>
|
||
</inType>
|
||
|
||
<outType len="1" cn="输出消息类型">
|
||
<options>
|
||
<option cn="二进制">
|
||
<hex>0</hex>
|
||
</option>
|
||
<option cn="扩展十六进制">
|
||
<hex>1</hex>
|
||
</option>
|
||
</options>
|
||
</outType>
|
||
|
||
<fullMode len="1" :if="0 == $packet.data.packSn$option || 3 == $packet.data.packSn$option" cn="填充模式">
|
||
仅当消息块号为 0,3 时有此域
|
||
<options>
|
||
<option cn="饥饿模式">
|
||
如果数据块长度为 8/16 的整数倍,不需要填
|
||
充;如果长度不为 8/16 的整数倍,填充至长度满
|
||
8/16 的整数倍(填充方式按 Pad character 域中
|
||
描述的规则进行,由加密机内部自动完成)
|
||
<hex>0</hex>
|
||
</option>
|
||
<option cn="贪婪模式">
|
||
如果数据块长度为 8/16 的整数倍,填充一个
|
||
整 8/16 字节的数据(填充方式按 Pad character
|
||
域中描述的规则进行,由加密机内部自动完成);
|
||
如果长度不为8/16的整数倍,填充至长度满8/16
|
||
的整数倍(填充方式按 Pad character 域中描述
|
||
的规则进行,由加密机内部自动完成)
|
||
<hex>1</hex>
|
||
</option>
|
||
</options>
|
||
</fullMode>
|
||
|
||
<fullChar len="4" :if="0 == $packet.data.packSn$option || 3 == $packet.data.packSn$option" cn="填充字符">
|
||
仅当消息块号为 0,3 时有此域
|
||
Pad character 为4H (以 XXYY 表示来进行说
|
||
明),其中XX为第一个字节的填充字符,之后的其
|
||
他所有需要填充的字节都填充为 YY。
|
||
<options>
|
||
<option cn="0000">
|
||
<text>0000</text>
|
||
</option>
|
||
<option cn="8000">
|
||
<text>8000</text>
|
||
</option>
|
||
<option cn="7FFF">
|
||
<text>7FFF</text>
|
||
</option>
|
||
</options>
|
||
</fullChar>
|
||
|
||
|
||
<fullType len="1" :if="0 == $packet.data.packSn$option || 3 == $packet.data.packSn$option" cn="填充字符">
|
||
仅当消息块号为 0,3 时有此域
|
||
Pad character 为4H (以 XXYY 表示来进行说
|
||
明),其中XX为第一个字节的填充字符,之后的其
|
||
他所有需要填充的字节都填充为 YY。
|
||
<options>
|
||
<option cn="不计尾">
|
||
填充数据的最后一个字节不填充计数位。解
|
||
密后的数据包含填充数据,由应用摘取实际数据。
|
||
<hex>0</hex>
|
||
</option>
|
||
<option cn="计尾">
|
||
填充数据的最后一个字节填充计数位。计数
|
||
位取值在 X’01 to X’08/ X’10 之间。解密后
|
||
的数据由加密机根据 Pad count flag值在内部自
|
||
动去掉填充数据
|
||
<hex>1</hex>
|
||
</option>
|
||
<option cn="pkcs">
|
||
pkcs5 和 pkcs7 填充
|
||
<hex>2</hex>
|
||
</option>
|
||
</options>
|
||
</fullType>
|
||
|
||
<iv :len="ivLen()" cn="IV" :if="0 != $packet.data.roundModel$option">
|
||
初始值,仅当密钥加密模式为 2,3,4 时有此域。
|
||
当密钥模式为 0,1 时,该域为 16H
|
||
当密钥模式为 2,3,4,5,6,7 时,该域为 32H
|
||
</iv>
|
||
|
||
<msgLen len="3" format="X" :value="msgLen()" cn="消息数据长度">
|
||
将要作 MAC的消息长度(若消息类型为二进制,则为
|
||
随后域长度;若消息类型为扩展十六进制,则为随后
|
||
域长度的一半)。
|
||
</msgLen>
|
||
|
||
<msg :len="" cn="消息数据">
|
||
二进制或扩展十六进制形式的消息块。
|
||
</msg>
|
||
</data>
|
||
|
||
|
||
|
||
</req>
|
||
<res>
|
||
|
||
<command>
|
||
<hex>E1</hex>
|
||
</command>
|
||
<data>
|
||
<error len="2" cn="错误码" format="X" :catch="catchError('%s')">
|
||
<options>
|
||
<option cn="无错误">
|
||
<hex>00</hex>
|
||
</option>
|
||
<option cn="模式标志错">
|
||
<hex>04</hex>
|
||
</option>
|
||
<option cn="未定义的方案 ID">
|
||
<hex>05</hex>
|
||
</option>
|
||
<option cn="根密钥奇偶校验错">
|
||
<hex>10</hex>
|
||
</option>
|
||
<option cn="保护密钥奇偶校验错">
|
||
<hex>11</hex>
|
||
</option>
|
||
<option cn="用户存储区没有装载密钥">
|
||
<hex>12</hex>
|
||
</option>
|
||
<option cn="LMK 错误">
|
||
LMK 错误;报告给管理员。
|
||
<hex>13</hex>
|
||
</option>
|
||
<option cn="输入数据错">
|
||
<hex>15</hex>
|
||
</option>
|
||
<option cn="离散次数错">
|
||
<hex>34</hex>
|
||
</option>
|
||
<option cn="密钥类型错">
|
||
<hex>28</hex>
|
||
</option>
|
||
<option cn="保护密钥类型错">
|
||
<hex>50</hex>
|
||
</option>
|
||
<option cn="输入数据长度错误">
|
||
<hex>80</hex>
|
||
</option>
|
||
</options>
|
||
</error>
|
||
|
||
<outType len="1" cn="输出消息类型">
|
||
<options>
|
||
<option cn="二进制">
|
||
<hex>0</hex>
|
||
</option>
|
||
<option cn="扩展十六进制">
|
||
<hex>1</hex>
|
||
</option>
|
||
</options>
|
||
</outType>
|
||
|
||
<msgLen len="3" format="X" cn="消息数据长度">
|
||
将要作 MAC的消息长度(若消息类型为二进制,则为
|
||
随后域长度;若消息类型为扩展十六进制,则为随后
|
||
域长度的一半)。
|
||
</msgLen>
|
||
|
||
<msg :len="getMsgLen()" cn="消息数据">
|
||
二进制或扩展十六进制形式的消息块。
|
||
</msg>
|
||
|
||
<iv :len="ivLen()" cn="IV 数据域" required="false">
|
||
在 CBC, OFB, CFB, PCBC模式下,当数据块为“first
|
||
block 或 middle block”时,命令输出的 IV 域为下
|
||
一个数据块输入的IV域(IV数据格式固定为Expanded
|
||
Hex-16 字节)。当数据块为“only block 或 last
|
||
block”时,输出不包含 IV 数据域
|
||
</iv>
|
||
</data>
|
||
|
||
|
||
|
||
</res>
|
||
<script>function ivLen() {
|
||
if( 0 == $packet.data.alg$option || 1 == $packet.data.alg$option ){
|
||
return 16;
|
||
}else{
|
||
return 32;
|
||
}
|
||
}
|
||
|
||
|
||
function msgLen() {
|
||
int len = $packet.data.msg.length;
|
||
if ( 0 == $packet.data.inType$option ){
|
||
return len;
|
||
}else{
|
||
return 2 * len;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 触发重载指令
|
||
*
|
||
* 参数 v 表示 reload 所在字段的值
|
||
* 如果是动态值,一定是先求值
|
||
*
|
||
*
|
||
* 返回值表示本次渲染继续还是终止
|
||
* true 继续
|
||
* false 终止
|
||
*/
|
||
function reload() {
|
||
var packlen = 2048
|
||
if( null == $packet.data.packSn$option ){
|
||
// 第一次进来
|
||
// 计算重载包数
|
||
int v = msgLen();
|
||
int loop = v / packlen;
|
||
int tailLen = v % packlen;
|
||
if ( tailLen ){
|
||
loop++;
|
||
}else{
|
||
tailLen = packlen;
|
||
}
|
||
$packet.data.msgAll = $packet.data.msg
|
||
$packet.data.loop = loop;
|
||
$packet.data.loopIndex = 0;
|
||
$packet.data.tailLen = tailLen;
|
||
|
||
}
|
||
|
||
int loop = $packet.data.loop;
|
||
int i = $packet.data.loopIndex;
|
||
//println("包个数 " + $packet.data.loop)
|
||
//println("包序号 " + $packet.data.loopIndex)
|
||
|
||
if( 0 == i ){
|
||
if( 1 == loop ){
|
||
// 唯一包
|
||
$packet.data.packSn$option = 0;
|
||
$packet.data.msg = $packet.data.msgAll
|
||
println("唯一包")
|
||
return false;
|
||
}else {
|
||
// 首包
|
||
$packet.data.packSn$option = 1;
|
||
$packet.data.msg = new byte[packlen];
|
||
System.arraycopy($packet.data.msgAll, 0, $packet.data.msg,0, packlen);
|
||
//println("首包")
|
||
}
|
||
}else{
|
||
if( i == (loop -1) ){
|
||
// 尾包
|
||
$packet.data.packSn$option = 3;
|
||
$packet.data.msg = new byte[$packet.data.tailLen];
|
||
System.arraycopy($packet.data.msgAll, i * packlen, $packet.data.msg,0, $packet.data.tailLen);
|
||
//println("尾包")
|
||
return false;
|
||
}else {
|
||
// 中间包
|
||
$packet.data.packSn$option = 2;
|
||
$packet.data.msg = new byte[packlen];
|
||
System.arraycopy($packet.data.msgAll, i * packlen, $packet.data.msg,0, packlen);
|
||
//println("中间包")
|
||
}
|
||
}
|
||
|
||
$packet.data.loopIndex += 1;
|
||
return true;
|
||
}
|
||
|
||
function getMsgLen() {
|
||
int len = Util.a2i( $final.getSection('data').getSection('msgLen') )
|
||
if (
|
||
Arrays.equals(
|
||
"0".getBytes(),
|
||
$final.getSection('data').getSection('outType').getValue()
|
||
)
|
||
){
|
||
return len;
|
||
}else{
|
||
return 2 * len;
|
||
}
|
||
}
|
||
|
||
</script>
|
||
</packet>
|