Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
0e6a4ca6
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看板
提交
0e6a4ca6
编写于
6月 07, 2016
作者:
A
akosarev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8157603: TestCipher.java doesn't check one of the decrypted message as expected
Reviewed-by: valeriep
上级
9f0a804e
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
18 addition
and
19 deletion
+18
-19
test/com/sun/crypto/provider/Cipher/TestCipher.java
test/com/sun/crypto/provider/Cipher/TestCipher.java
+18
-19
未找到文件。
test/com/sun/crypto/provider/Cipher/TestCipher.java
浏览文件 @
0e6a4ca6
/*
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015,
2016,
Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
*
* This code is free software; you can redistribute it and/or modify it
* This code is free software; you can redistribute it and/or modify it
...
@@ -150,11 +150,6 @@ public abstract class TestCipher {
...
@@ -150,11 +150,6 @@ public abstract class TestCipher {
}
}
// Encryption
// Encryption
int
PAD_LEN
=
0
;
if
(
pad
.
equalsIgnoreCase
(
"PKCS5Padding"
))
{
// Need to consider pad bytes
PAD_LEN
=
8
;
}
byte
[]
plainText
=
INPUT_TEXT
.
clone
();
byte
[]
plainText
=
INPUT_TEXT
.
clone
();
...
@@ -162,12 +157,13 @@ public abstract class TestCipher {
...
@@ -162,12 +157,13 @@ public abstract class TestCipher {
byte
[]
cipherText
=
ci
.
doFinal
(
INPUT_TEXT
,
ENC_OFFSET
,
TEXT_LEN
);
byte
[]
cipherText
=
ci
.
doFinal
(
INPUT_TEXT
,
ENC_OFFSET
,
TEXT_LEN
);
// Generate cipher and save to same buffer
// Generate cipher and save to same buffer
int
offset
=
ci
.
update
(
int
enc_bytes
=
ci
.
update
(
INPUT_TEXT
,
ENC_OFFSET
,
TEXT_LEN
,
INPUT_TEXT
,
STORAGE_OFFSET
);
INPUT_TEXT
,
ENC_OFFSET
,
TEXT_LEN
,
INPUT_TEXT
,
STORAGE_OFFSET
);
ci
.
doFinal
(
INPUT_TEXT
,
offset
+
STORAGE_OFFSET
);
enc_bytes
+=
ci
.
doFinal
(
INPUT_TEXT
,
enc_bytes
+
STORAGE_OFFSET
);
if
(!
equalsBlock
(
if
(!
equalsBlock
(
INPUT_TEXT
,
STORAGE_OFFSET
,
cipherText
,
0
,
cipherText
.
length
))
{
INPUT_TEXT
,
STORAGE_OFFSET
,
enc_bytes
,
cipherText
,
0
,
cipherText
.
length
))
{
throw
new
RuntimeException
(
throw
new
RuntimeException
(
"Different ciphers generated with same buffer"
);
"Different ciphers generated with same buffer"
);
}
}
...
@@ -183,8 +179,8 @@ public abstract class TestCipher {
...
@@ -183,8 +179,8 @@ public abstract class TestCipher {
byte
[]
recoveredText
=
ci
.
doFinal
(
cipherText
,
0
,
cipherText
.
length
);
byte
[]
recoveredText
=
ci
.
doFinal
(
cipherText
,
0
,
cipherText
.
length
);
if
(!
equalsBlock
(
if
(!
equalsBlock
(
plainText
,
ENC_OFFSET
,
recoveredText
,
0
,
plainText
,
ENC_OFFSET
,
TEXT_LEN
,
recoveredText
.
length
))
{
recoveredText
,
0
,
recoveredText
.
length
))
{
throw
new
RuntimeException
(
throw
new
RuntimeException
(
"Recovered text not same as plain text"
);
"Recovered text not same as plain text"
);
}
else
{
}
else
{
...
@@ -192,13 +188,13 @@ public abstract class TestCipher {
...
@@ -192,13 +188,13 @@ public abstract class TestCipher {
}
}
// Recover text from cipher and save to same buffer
// Recover text from cipher and save to same buffer
ci
.
update
(
INPUT_TEXT
,
STORAGE_OFFSET
,
TEXT_LEN
+
PAD_LEN
,
INPUT_TEXT
,
int
dec_bytes
=
ci
.
update
(
ENC_OFFSET
);
INPUT_TEXT
,
STORAGE_OFFSET
,
enc_bytes
,
INPUT_TEXT
,
ENC_OFFSET
);
ci
.
doFinal
(
INPUT_TEXT
,
ENC_OFFSET
);
dec_bytes
+=
ci
.
doFinal
(
INPUT_TEXT
,
dec_bytes
+
ENC_OFFSET
);
if
(!
equalsBlock
(
if
(!
equalsBlock
(
plainText
,
ENC_OFFSET
,
recoveredText
,
0
,
plainText
,
ENC_OFFSET
,
TEXT_LEN
,
recoveredText
.
length
))
{
INPUT_TEXT
,
ENC_OFFSET
,
dec_bytes
))
{
throw
new
RuntimeException
(
throw
new
RuntimeException
(
"Recovered text not same as plain text with same buffer"
);
"Recovered text not same as plain text with same buffer"
);
}
else
{
}
else
{
...
@@ -208,9 +204,12 @@ public abstract class TestCipher {
...
@@ -208,9 +204,12 @@ public abstract class TestCipher {
out
.
println
(
"Test Passed."
);
out
.
println
(
"Test Passed."
);
}
}
private
static
boolean
equalsBlock
(
byte
[]
b1
,
int
off1
,
byte
[]
b2
,
int
off2
,
private
static
boolean
equalsBlock
(
byte
[]
b1
,
int
off1
,
int
len1
,
int
len
)
{
byte
[]
b2
,
int
off2
,
int
len2
)
{
for
(
int
i
=
off1
,
j
=
off2
,
k
=
0
;
k
<
len
;
i
++,
j
++,
k
++)
{
if
(
len1
!=
len2
)
{
return
false
;
}
for
(
int
i
=
off1
,
j
=
off2
,
k
=
0
;
k
<
len1
;
i
++,
j
++,
k
++)
{
if
(
b1
[
i
]
!=
b2
[
j
])
{
if
(
b1
[
i
]
!=
b2
[
j
])
{
return
false
;
return
false
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录