Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Openssl
提交
c1a7dcbe
T
Third Party Openssl
项目概览
OpenHarmony
/
Third Party Openssl
1 年多 前同步成功
通知
10
Star
18
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Third Party Openssl
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
c1a7dcbe
编写于
8月 21, 2016
作者:
A
Andy Polyakov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
evp/bio_enc.c: refine non-overlapping logic.
RT#4628 Reviewed-by:
N
Rich Salz
<
rsalz@openssl.org
>
上级
2e929e53
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
42 addition
and
27 deletion
+42
-27
crypto/evp/bio_enc.c
crypto/evp/bio_enc.c
+42
-27
未找到文件。
crypto/evp/bio_enc.c
浏览文件 @
c1a7dcbe
...
...
@@ -27,7 +27,8 @@ static int enc_new(BIO *h);
static
int
enc_free
(
BIO
*
data
);
static
long
enc_callback_ctrl
(
BIO
*
h
,
int
cmd
,
bio_info_cb
*
fps
);
#define ENC_BLOCK_SIZE (1024*4)
#define BUF_OFFSET (EVP_MAX_BLOCK_LENGTH*2)
#define ENC_MIN_CHUNK (256)
#define BUF_OFFSET (ENC_MIN_CHUNK + EVP_MAX_BLOCK_LENGTH)
typedef
struct
enc_struct
{
int
buf_len
;
...
...
@@ -36,11 +37,12 @@ typedef struct enc_struct {
int
finished
;
int
ok
;
/* bad decrypt */
EVP_CIPHER_CTX
*
cipher
;
unsigned
char
*
read_start
,
*
read_end
;
/*
* buf is larger than ENC_BLOCK_SIZE because EVP_DecryptUpdate can return
* up to a block more data than is presented to it
*/
unsigned
char
buf
[
ENC_BLOCK_SIZE
+
BUF_OFFSET
+
2
];
unsigned
char
buf
[
BUF_OFFSET
+
ENC_BLOCK_SIZE
];
}
BIO_ENC_CTX
;
static
const
BIO_METHOD
methods_enc
=
{
...
...
@@ -75,6 +77,7 @@ static int enc_new(BIO *bi)
}
ctx
->
cont
=
1
;
ctx
->
ok
=
1
;
ctx
->
read_end
=
ctx
->
read_start
=
&
(
ctx
->
buf
[
BUF_OFFSET
]);
BIO_set_data
(
bi
,
ctx
);
BIO_set_init
(
bi
,
1
);
...
...
@@ -102,7 +105,7 @@ static int enc_free(BIO *a)
static
int
enc_read
(
BIO
*
b
,
char
*
out
,
int
outl
)
{
int
ret
=
0
,
i
;
int
ret
=
0
,
i
,
blocksize
;
BIO_ENC_CTX
*
ctx
;
BIO
*
next
;
...
...
@@ -130,27 +133,24 @@ static int enc_read(BIO *b, char *out, int outl)
}
}
blocksize
=
EVP_CIPHER_CTX_block_size
(
ctx
->
cipher
);
if
(
blocksize
==
1
)
blocksize
=
0
;
/*
* At this point, we have room of outl bytes and an empty buffer, so we
* should read in some more.
*/
while
(
outl
>
0
)
{
int
buf_len
;
if
(
ctx
->
cont
<=
0
)
break
;
buf_len
=
outl
+
EVP_MAX_BLOCK_LENGTH
-
1
;
buf_len
-=
buf_len
%
EVP_MAX_BLOCK_LENGTH
;
if
(
buf_len
>
ENC_BLOCK_SIZE
)
{
buf_len
=
ENC_BLOCK_SIZE
;
if
(
ctx
->
read_start
==
ctx
->
read_end
)
{
/* time to read more data */
ctx
->
read_end
=
ctx
->
read_start
=
&
(
ctx
->
buf
[
BUF_OFFSET
]);
ctx
->
read_end
+=
BIO_read
(
next
,
ctx
->
read_start
,
ENC_BLOCK_SIZE
);
}
/*
* read in at IV offset, read the EVP_Cipher documentation about why
*/
i
=
BIO_read
(
next
,
&
(
ctx
->
buf
[
BUF_OFFSET
]),
buf_len
);
i
=
ctx
->
read_end
-
ctx
->
read_start
;
if
(
i
<=
0
)
{
/* Should be continue next time we are called? */
...
...
@@ -164,26 +164,41 @@ static int enc_read(BIO *b, char *out, int outl)
ret
=
(
ret
==
0
)
?
i
:
ret
;
break
;
}
}
else
if
(
outl
>=
EVP_MAX_BLOCK_LENGTH
)
{
if
(
!
EVP_CipherUpdate
(
ctx
->
cipher
,
(
unsigned
char
*
)
out
,
&
buf_len
,
&
(
ctx
->
buf
[
BUF_OFFSET
]),
i
))
{
BIO_clear_retry_flags
(
b
);
return
0
;
}
ret
+=
buf_len
;
outl
-=
buf_len
;
out
+=
buf_len
;
continue
;
}
else
{
if
(
outl
>
ENC_MIN_CHUNK
)
{
/*
* Depending on flags block cipher decrypt can write
* one extra block and then back off, i.e. output buffer
* has to accommodate extra block...
*/
int
j
=
outl
-
blocksize
,
buf_len
;
if
(
!
EVP_CipherUpdate
(
ctx
->
cipher
,
(
unsigned
char
*
)
out
,
&
buf_len
,
ctx
->
read_start
,
i
>
j
?
j
:
i
))
{
BIO_clear_retry_flags
(
b
);
return
0
;
}
ret
+=
buf_len
;
out
+=
buf_len
;
outl
-=
buf_len
;
if
((
i
-=
j
)
<=
0
)
{
ctx
->
read_start
=
ctx
->
read_end
;
continue
;
}
ctx
->
read_start
+=
j
;
}
if
(
i
>
ENC_MIN_CHUNK
)
i
=
ENC_MIN_CHUNK
;
if
(
!
EVP_CipherUpdate
(
ctx
->
cipher
,
ctx
->
buf
,
&
ctx
->
buf_len
,
&
(
ctx
->
buf
[
BUF_OFFSET
])
,
i
))
{
ctx
->
read_start
,
i
))
{
BIO_clear_retry_flags
(
b
);
ctx
->
ok
=
0
;
return
0
;
}
ctx
->
read_start
+=
i
;
ctx
->
cont
=
1
;
/*
* Note: it is possible for EVP_CipherUpdate to decrypt zero
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录