Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Gpdb
提交
067a5cdb
G
Gpdb
项目概览
Greenplum
/
Gpdb
通知
7
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
Gpdb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
067a5cdb
编写于
7月 11, 2005
作者:
T
Tom Lane
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Avoid bzero/bxopy in favor of more standard library routines.
Marko Kreen
上级
e997758c
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
27 addition
and
32 deletion
+27
-32
contrib/pgcrypto/sha2.c
contrib/pgcrypto/sha2.c
+27
-32
未找到文件。
contrib/pgcrypto/sha2.c
浏览文件 @
067a5cdb
...
...
@@ -33,7 +33,7 @@
*
* $From: sha2.c,v 1.1 2001/11/08 00:01:51 adg Exp adg $
*
* $PostgreSQL: pgsql/contrib/pgcrypto/sha2.c,v 1.
2 2005/07/11 15:07:59
tgl Exp $
* $PostgreSQL: pgsql/contrib/pgcrypto/sha2.c,v 1.
3 2005/07/11 15:40:38
tgl Exp $
*/
#include "postgres.h"
...
...
@@ -42,11 +42,6 @@
#include "sha2.h"
#undef bcopy
#undef bzero
#define bcopy(src, dst, len) memcpy((dst), (src), (len))
#define bzero(ptr, len) memset((ptr), 0, (len))
/*
* UNROLLED TRANSFORM LOOP NOTE:
* You can define SHA2_UNROLL_TRANSFORM to use the unrolled transform
...
...
@@ -281,8 +276,8 @@ SHA256_Init(SHA256_CTX *context)
{
if
(
context
==
NULL
)
return
;
bcopy
(
sha256_initial_hash_value
,
context
->
stat
e
,
SHA256_DIGEST_LENGTH
);
bzero
(
context
->
buffer
,
SHA256_BLOCK_LENGTH
);
memcpy
(
context
->
state
,
sha256_initial_hash_valu
e
,
SHA256_DIGEST_LENGTH
);
memset
(
context
->
buffer
,
0
,
SHA256_BLOCK_LENGTH
);
context
->
bitcount
=
0
;
}
...
...
@@ -466,14 +461,14 @@ SHA256_Update(SHA256_CTX *context, const uint8 *data, size_t len)
if
(
len
>=
freespace
)
{
/* Fill the buffer completely and process it */
bcopy
(
data
,
&
context
->
buffer
[
usedspace
]
,
freespace
);
memcpy
(
&
context
->
buffer
[
usedspace
],
data
,
freespace
);
context
->
bitcount
+=
freespace
<<
3
;
len
-=
freespace
;
data
+=
freespace
;
SHA256_Transform
(
context
,
context
->
buffer
);
}
else
{
/* The buffer is not yet full */
bcopy
(
data
,
&
context
->
buffer
[
usedspace
]
,
len
);
memcpy
(
&
context
->
buffer
[
usedspace
],
data
,
len
);
context
->
bitcount
+=
len
<<
3
;
/* Clean up: */
usedspace
=
freespace
=
0
;
...
...
@@ -489,7 +484,7 @@ SHA256_Update(SHA256_CTX *context, const uint8 *data, size_t len)
}
if
(
len
>
0
)
{
/* There's left-overs, so save 'em */
bcopy
(
data
,
context
->
buffer
,
len
);
memcpy
(
context
->
buffer
,
data
,
len
);
context
->
bitcount
+=
len
<<
3
;
}
/* Clean up: */
...
...
@@ -514,20 +509,20 @@ SHA256_Final(uint8 digest[], SHA256_CTX *context)
if
(
usedspace
<=
SHA256_SHORT_BLOCK_LENGTH
)
{
/* Set-up for the last transform: */
bzero
(
&
context
->
buffer
[
usedspace
]
,
SHA256_SHORT_BLOCK_LENGTH
-
usedspace
);
memset
(
&
context
->
buffer
[
usedspace
],
0
,
SHA256_SHORT_BLOCK_LENGTH
-
usedspace
);
}
else
{
if
(
usedspace
<
SHA256_BLOCK_LENGTH
)
{
bzero
(
&
context
->
buffer
[
usedspace
]
,
SHA256_BLOCK_LENGTH
-
usedspace
);
memset
(
&
context
->
buffer
[
usedspace
],
0
,
SHA256_BLOCK_LENGTH
-
usedspace
);
}
/* Do second-to-last transform: */
SHA256_Transform
(
context
,
context
->
buffer
);
/* And set-up for the last transform: */
bzero
(
context
->
buffer
,
SHA256_SHORT_BLOCK_LENGTH
);
memset
(
context
->
buffer
,
0
,
SHA256_SHORT_BLOCK_LENGTH
);
}
}
else
{
/* Set-up for the last transform: */
bzero
(
context
->
buffer
,
SHA256_SHORT_BLOCK_LENGTH
);
memset
(
context
->
buffer
,
0
,
SHA256_SHORT_BLOCK_LENGTH
);
/* Begin padding with a 1 bit: */
*
context
->
buffer
=
0x80
;
...
...
@@ -547,11 +542,11 @@ SHA256_Final(uint8 digest[], SHA256_CTX *context)
}
}
#endif
bcopy
(
context
->
state
,
digest
,
SHA256_DIGEST_LENGTH
);
memcpy
(
digest
,
context
->
state
,
SHA256_DIGEST_LENGTH
);
}
/* Clean up state data: */
bzero
(
context
,
sizeof
(
*
context
));
memset
(
context
,
0
,
sizeof
(
*
context
));
usedspace
=
0
;
}
...
...
@@ -562,8 +557,8 @@ SHA512_Init(SHA512_CTX *context)
{
if
(
context
==
NULL
)
return
;
bcopy
(
sha512_initial_hash_value
,
context
->
stat
e
,
SHA512_DIGEST_LENGTH
);
bzero
(
context
->
buffer
,
SHA512_BLOCK_LENGTH
);
memcpy
(
context
->
state
,
sha512_initial_hash_valu
e
,
SHA512_DIGEST_LENGTH
);
memset
(
context
->
buffer
,
0
,
SHA512_BLOCK_LENGTH
);
context
->
bitcount
[
0
]
=
context
->
bitcount
[
1
]
=
0
;
}
...
...
@@ -747,14 +742,14 @@ SHA512_Update(SHA512_CTX *context, const uint8 *data, size_t len)
if
(
len
>=
freespace
)
{
/* Fill the buffer completely and process it */
bcopy
(
data
,
&
context
->
buffer
[
usedspace
]
,
freespace
);
memcpy
(
&
context
->
buffer
[
usedspace
],
data
,
freespace
);
ADDINC128
(
context
->
bitcount
,
freespace
<<
3
);
len
-=
freespace
;
data
+=
freespace
;
SHA512_Transform
(
context
,
context
->
buffer
);
}
else
{
/* The buffer is not yet full */
bcopy
(
data
,
&
context
->
buffer
[
usedspace
]
,
len
);
memcpy
(
&
context
->
buffer
[
usedspace
],
data
,
len
);
ADDINC128
(
context
->
bitcount
,
len
<<
3
);
/* Clean up: */
usedspace
=
freespace
=
0
;
...
...
@@ -770,7 +765,7 @@ SHA512_Update(SHA512_CTX *context, const uint8 *data, size_t len)
}
if
(
len
>
0
)
{
/* There's left-overs, so save 'em */
bcopy
(
data
,
context
->
buffer
,
len
);
memcpy
(
context
->
buffer
,
data
,
len
);
ADDINC128
(
context
->
bitcount
,
len
<<
3
);
}
/* Clean up: */
...
...
@@ -794,20 +789,20 @@ SHA512_Last(SHA512_CTX *context)
if
(
usedspace
<=
SHA512_SHORT_BLOCK_LENGTH
)
{
/* Set-up for the last transform: */
bzero
(
&
context
->
buffer
[
usedspace
]
,
SHA512_SHORT_BLOCK_LENGTH
-
usedspace
);
memset
(
&
context
->
buffer
[
usedspace
],
0
,
SHA512_SHORT_BLOCK_LENGTH
-
usedspace
);
}
else
{
if
(
usedspace
<
SHA512_BLOCK_LENGTH
)
{
bzero
(
&
context
->
buffer
[
usedspace
]
,
SHA512_BLOCK_LENGTH
-
usedspace
);
memset
(
&
context
->
buffer
[
usedspace
],
0
,
SHA512_BLOCK_LENGTH
-
usedspace
);
}
/* Do second-to-last transform: */
SHA512_Transform
(
context
,
context
->
buffer
);
/* And set-up for the last transform: */
bzero
(
context
->
buffer
,
SHA512_BLOCK_LENGTH
-
2
);
memset
(
context
->
buffer
,
0
,
SHA512_BLOCK_LENGTH
-
2
);
}
}
else
{
/* Prepare for final transform: */
bzero
(
context
->
buffer
,
SHA512_SHORT_BLOCK_LENGTH
);
memset
(
context
->
buffer
,
0
,
SHA512_SHORT_BLOCK_LENGTH
);
/* Begin padding with a 1 bit: */
*
context
->
buffer
=
0x80
;
...
...
@@ -837,11 +832,11 @@ SHA512_Final(uint8 digest[], SHA512_CTX *context)
}
}
#endif
bcopy
(
context
->
state
,
digest
,
SHA512_DIGEST_LENGTH
);
memcpy
(
digest
,
context
->
state
,
SHA512_DIGEST_LENGTH
);
}
/* Zero out state data */
bzero
(
context
,
sizeof
(
*
context
));
memset
(
context
,
0
,
sizeof
(
*
context
));
}
...
...
@@ -851,8 +846,8 @@ SHA384_Init(SHA384_CTX *context)
{
if
(
context
==
NULL
)
return
;
bcopy
(
sha384_initial_hash_value
,
context
->
stat
e
,
SHA512_DIGEST_LENGTH
);
bzero
(
context
->
buffer
,
SHA384_BLOCK_LENGTH
);
memcpy
(
context
->
state
,
sha384_initial_hash_valu
e
,
SHA512_DIGEST_LENGTH
);
memset
(
context
->
buffer
,
0
,
SHA384_BLOCK_LENGTH
);
context
->
bitcount
[
0
]
=
context
->
bitcount
[
1
]
=
0
;
}
...
...
@@ -879,9 +874,9 @@ SHA384_Final(uint8 digest[], SHA384_CTX *context)
}
}
#endif
bcopy
(
context
->
state
,
digest
,
SHA384_DIGEST_LENGTH
);
memcpy
(
digest
,
context
->
state
,
SHA384_DIGEST_LENGTH
);
}
/* Zero out state data */
bzero
(
context
,
sizeof
(
*
context
));
memset
(
context
,
0
,
sizeof
(
*
context
));
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录