Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
af601942
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
af601942
编写于
1月 07, 2015
作者:
X
xuelei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8048607: Test key generation of DES and DESEDE
Reviewed-by: xuelei Contributed-by:
N
Zaiyao Liu
<
zaiyao.liu@oracle.com
>
上级
045e336c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
153 addition
and
18 deletion
+153
-18
test/com/sun/crypto/provider/Cipher/DES/TestUtility.java
test/com/sun/crypto/provider/Cipher/DES/TestUtility.java
+32
-18
test/javax/crypto/KeyGenerator/TestKGParity.java
test/javax/crypto/KeyGenerator/TestKGParity.java
+121
-0
未找到文件。
test/com/sun/crypto/provider/Cipher/DES/TestUtility.java
浏览文件 @
af601942
...
...
@@ -27,39 +27,52 @@
public
class
TestUtility
{
private
static
final
String
digits
=
"0123456789abcdef"
;
private
static
final
String
DIGITS
=
"0123456789abcdef"
;
p
ublic
TestUtility
()
{
p
rivate
TestUtility
()
{
}
public
static
String
hexDump
(
byte
[]
bytes
)
{
StringBu
ffer
buf
=
new
StringBuffer
(
bytes
.
length
*
2
);
int
i
;
StringBu
ilder
buf
=
new
StringBuilder
(
bytes
.
length
*
2
);
int
i
;
buf
.
append
(
" "
);
// four spaces
buf
.
append
(
" "
);
// four spaces
for
(
i
=
0
;
i
<
bytes
.
length
;
i
++)
{
buf
.
append
(
digits
.
charAt
((
bytes
[
i
]
>>
4
)
&
0x0f
));
buf
.
append
(
digits
.
charAt
(
bytes
[
i
]
&
0x0f
));
if
(((
i
+
1
)
%
32
)
==
0
)
{
if
((
i
+
1
)
!=
bytes
.
length
)
buf
.
append
(
"\n "
);
// line after four words
}
else
if
(((
i
+
1
)
%
4
)
==
0
)
buf
.
append
(
' '
);
// space between words
buf
.
append
(
DIGITS
.
charAt
(
bytes
[
i
]
>>
4
&
0x0f
));
buf
.
append
(
DIGITS
.
charAt
(
bytes
[
i
]
&
0x0f
));
if
((
i
+
1
)
%
32
==
0
)
{
if
(
i
+
1
!=
bytes
.
length
)
{
buf
.
append
(
"\n "
);
// line after four words
}
}
else
if
((
i
+
1
)
%
4
==
0
)
{
buf
.
append
(
' '
);
// space between words
}
}
return
buf
.
toString
();
return
buf
.
toString
();
}
public
static
String
hexDump
(
byte
[]
bytes
,
int
index
)
{
StringBuilder
buf
=
new
StringBuilder
(
bytes
.
length
*
2
);
int
i
;
buf
.
append
(
" "
);
// four spaces
buf
.
append
(
DIGITS
.
charAt
(
bytes
[
index
]
>>
4
&
0x0f
));
buf
.
append
(
DIGITS
.
charAt
(
bytes
[
index
]
&
0x0f
));
return
buf
.
toString
();
}
public
static
boolean
equalsBlock
(
byte
[]
b1
,
byte
[]
b2
)
{
if
(
b1
.
length
!=
b2
.
length
)
if
(
b1
.
length
!=
b2
.
length
)
{
return
false
;
}
for
(
int
i
=
0
;
i
<
b1
.
length
;
i
++)
{
if
(
b1
[
i
]
!=
b2
[
i
])
for
(
int
i
=
0
;
i
<
b1
.
length
;
i
++)
{
if
(
b1
[
i
]
!=
b2
[
i
])
{
return
false
;
}
}
return
true
;
...
...
@@ -67,9 +80,10 @@ public class TestUtility {
public
static
boolean
equalsBlock
(
byte
[]
b1
,
byte
[]
b2
,
int
len
)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
if
(
b1
[
i
]
!=
b2
[
i
])
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
if
(
b1
[
i
]
!=
b2
[
i
])
{
return
false
;
}
}
return
true
;
...
...
test/javax/crypto/KeyGenerator/TestKGParity.java
0 → 100644
浏览文件 @
af601942
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import
java.io.PrintStream
;
import
java.lang.String
;
import
java.lang.System
;
import
java.security.Provider
;
import
java.security.SecureRandom
;
import
java.security.Security
;
import
javax.crypto.KeyGenerator
;
import
static
java
.
lang
.
System
.
out
;
/*
* @test
* @bug 8048607
* @compile ../../../com/sun/crypto/provider/Cipher/DES/TestUtility.java
* @summary Test key generation of DES and DESEDE
*/
public
class
TestKGParity
{
private
static
final
String
[]
ALGORITHM_ARR
=
{
"deS"
,
"DesEDE"
};
public
static
void
main
(
String
argv
[])
throws
Exception
{
TestKGParity
test
=
new
TestKGParity
();
test
.
run
();
}
private
void
run
()
throws
Exception
{
Provider
[]
providers
=
Security
.
getProviders
();
for
(
Provider
p
:
providers
)
{
String
prvName
=
p
.
getName
();
if
(
prvName
.
startsWith
(
"SunJCE"
)
||
prvName
.
startsWith
(
"SunPKCS11-"
))
{
for
(
String
algorithm
:
ALGORITHM_ARR
)
{
if
(!
runTest
(
p
,
algorithm
))
{
throw
new
RuntimeException
(
"Test failed with provider/algorithm:"
+
p
.
getName
()
+
"/"
+
algorithm
);
}
else
{
out
.
println
(
"Test passed with provider/algorithm:"
+
p
.
getName
()
+
"/"
+
algorithm
);
}
}
}
}
}
public
boolean
runTest
(
Provider
p
,
String
algo
)
throws
Exception
{
byte
[]
keyValue
=
null
;
try
{
// Initialization
SecureRandom
sRdm
=
new
SecureRandom
();
KeyGenerator
kg
=
KeyGenerator
.
getInstance
(
algo
,
p
);
kg
.
init
(
sRdm
);
// Generate a SecretKey and retrieve its value
keyValue
=
kg
.
generateKey
().
getEncoded
();
// Verify its parity in the unit of byte
for
(
int
i
=
0
;
i
<
keyValue
.
length
;
i
++)
{
if
(!
checkParity
(
keyValue
[
i
]))
{
out
.
println
(
"Testing: "
+
p
.
getName
()
+
"/"
+
algo
+
" failed when verify its parity in the unit of byte:"
+
TestUtility
.
hexDump
(
keyValue
,
i
));
return
false
;
}
}
return
true
;
}
catch
(
Exception
ex
)
{
out
.
println
(
"Testing: "
+
p
.
getName
()
+
"/"
+
algo
+
" failed with unexpected exception"
);
ex
.
printStackTrace
();
throw
ex
;
}
}
private
boolean
checkParity
(
byte
keyByte
)
{
boolean
even
=
false
;
byte
[]
PARITY_BIT_MASK
=
{
(
byte
)
0x40
,
(
byte
)
0x20
,
(
byte
)
0x10
,
(
byte
)
0x08
,
(
byte
)
0x04
,
(
byte
)
0x02
,
(
byte
)
0x01
};
for
(
int
i
=
0
;
i
<
7
;
i
++)
{
if
((
keyByte
&
PARITY_BIT_MASK
[
i
])
>
0
)
{
even
=
!
even
;
}
}
if
(
keyByte
<
0
)
{
even
=
!
even
;
}
return
even
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录