Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Openssl
提交
63077bd4
T
Third Party Openssl
项目概览
OpenHarmony
/
Third Party Openssl
大约 1 年 前同步成功
通知
9
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看板
提交
63077bd4
编写于
5月 20, 2004
作者:
A
Andy Polyakov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
SHA-256/-512 update. A bug fix, SHA-512 tune-up for AMD64, hook for SSE2
code, Makefile update.
上级
df364f1b
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
78 addition
and
12 deletion
+78
-12
crypto/sha/Makefile.ssl
crypto/sha/Makefile.ssl
+5
-3
crypto/sha/sha256.c
crypto/sha/sha256.c
+9
-6
crypto/sha/sha512.c
crypto/sha/sha512.c
+64
-3
未找到文件。
crypto/sha/Makefile.ssl
浏览文件 @
63077bd4
...
...
@@ -23,12 +23,12 @@ CFLAGS= $(INCLUDES) $(CFLAG)
ASFLAGS
=
$(INCLUDES)
$(ASFLAG)
GENERAL
=
Makefile
TEST
=
shatest.c sha1test.c
TEST
=
shatest.c sha1test.c
sha256t.c sha512t.c
APPS
=
LIB
=
$(TOP)
/libcrypto.a
LIBSRC
=
sha_dgst.c sha1dgst.c sha_one.c sha1_one.c
LIBOBJ
=
sha_dgst.o sha1dgst.o sha_one.o sha1_one.o
$(SHA1_ASM_OBJ)
LIBSRC
=
sha_dgst.c sha1dgst.c sha_one.c sha1_one.c
sha256.c sha512.c
LIBOBJ
=
sha_dgst.o sha1dgst.o sha_one.o sha1_one.o
sha256.o sha512.o
$(SHA1_ASM_OBJ)
SRC
=
$(LIBSRC)
...
...
@@ -50,6 +50,8 @@ lib: $(LIBOBJ)
# elf
asm/sx86-elf.s
:
asm/sha1-586.pl ../perlasm/x86asm.pl
(
cd
asm
;
$(PERL)
sha1-586.pl elf
$(CFLAGS)
$(PROCESSOR)
>
sx86-elf.s
)
asm/sse2-elf.s
:
asm/sha512-sse2.pl ../perlasm/x86asm.pl
(
cd
asm
;
$(PERL)
sha512-sse2.pl elf
$(CFLAGS)
$(PROCESSOR)
>
sse2-elf.s
)
# a.out
asm/sx86-out.o
:
asm/sx86unix.cpp
...
...
crypto/sha/sha256.c
浏览文件 @
63077bd4
/* crypto/sha/sha256.c */
/* ====================================================================
* Copyright (c) 2004 The OpenSSL Project. All rights reserved.
* Copyright (c) 2004 The OpenSSL Project. All rights reserved
* according to the OpenSSL license [found in ../../LICENSE].
* ====================================================================
*/
#include <stdlib.h>
...
...
@@ -131,6 +132,7 @@ static void sha256_block (SHA256_CTX *ctx, const void *in, size_t num, int host)
unsigned
MD32_REG_T
a
,
b
,
c
,
d
,
e
,
f
,
g
,
h
,
s0
,
s1
,
T1
,
T2
;
SHA_LONG
X
[
16
];
int
i
;
const
unsigned
char
*
data
=
in
;
while
(
num
--
)
{
...
...
@@ -139,7 +141,7 @@ static void sha256_block (SHA256_CTX *ctx, const void *in, size_t num, int host)
if
(
host
)
{
const
SHA_LONG
*
W
=
in
;
const
SHA_LONG
*
W
=
(
const
SHA_LONG
*
)
data
;
for
(
i
=
0
;
i
<
16
;
i
++
)
{
...
...
@@ -152,7 +154,6 @@ static void sha256_block (SHA256_CTX *ctx, const void *in, size_t num, int host)
}
else
{
const
unsigned
char
*
data
=
in
;
SHA_LONG
l
;
for
(
i
=
0
;
i
<
16
;
i
++
)
...
...
@@ -180,6 +181,7 @@ static void sha256_block (SHA256_CTX *ctx, const void *in, size_t num, int host)
ctx
->
h
[
0
]
+=
a
;
ctx
->
h
[
1
]
+=
b
;
ctx
->
h
[
2
]
+=
c
;
ctx
->
h
[
3
]
+=
d
;
ctx
->
h
[
4
]
+=
e
;
ctx
->
h
[
5
]
+=
f
;
ctx
->
h
[
6
]
+=
g
;
ctx
->
h
[
7
]
+=
h
;
data
+=
SHA256_CBLOCK
;
}
}
...
...
@@ -193,7 +195,7 @@ static void sha256_block (SHA256_CTX *ctx, const void *in, size_t num, int host)
#define ROUND_16_63(i,a,b,c,d,e,f,g,h,X) do { \
s0 = X[(i+1)&0x0f]; s0 = sigma0(s0); \
s1 = X[(i+14)&0x0f]; s1 = sigma1(s1); \
T1 = X[
i
&0x0f] += s0 + s1 + X[(i+9)&0x0f]; \
T1 = X[
(i)
&0x0f] += s0 + s1 + X[(i+9)&0x0f]; \
ROUND_00_15(i,a,b,c,d,e,f,g,h); } while (0)
static
void
sha256_block
(
SHA256_CTX
*
ctx
,
const
void
*
in
,
size_t
num
,
int
host
)
...
...
@@ -201,6 +203,7 @@ static void sha256_block (SHA256_CTX *ctx, const void *in, size_t num, int host)
unsigned
MD32_REG_T
a
,
b
,
c
,
d
,
e
,
f
,
g
,
h
,
s0
,
s1
,
T1
;
SHA_LONG
X
[
16
];
int
i
;
const
unsigned
char
*
data
=
in
;
while
(
num
--
)
{
...
...
@@ -209,7 +212,7 @@ static void sha256_block (SHA256_CTX *ctx, const void *in, size_t num, int host)
if
(
host
)
{
const
SHA_LONG
*
W
=
in
;
const
SHA_LONG
*
W
=
(
const
SHA_LONG
*
)
data
;
T1
=
X
[
0
]
=
W
[
0
];
ROUND_00_15
(
0
,
a
,
b
,
c
,
d
,
e
,
f
,
g
,
h
);
T1
=
X
[
1
]
=
W
[
1
];
ROUND_00_15
(
1
,
h
,
a
,
b
,
c
,
d
,
e
,
f
,
g
);
...
...
@@ -230,7 +233,6 @@ static void sha256_block (SHA256_CTX *ctx, const void *in, size_t num, int host)
}
else
{
const
unsigned
char
*
data
=
in
;
SHA_LONG
l
;
HOST_c2l
(
data
,
l
);
T1
=
X
[
0
]
=
l
;
ROUND_00_15
(
0
,
a
,
b
,
c
,
d
,
e
,
f
,
g
,
h
);
...
...
@@ -266,6 +268,7 @@ static void sha256_block (SHA256_CTX *ctx, const void *in, size_t num, int host)
ctx
->
h
[
0
]
+=
a
;
ctx
->
h
[
1
]
+=
b
;
ctx
->
h
[
2
]
+=
c
;
ctx
->
h
[
3
]
+=
d
;
ctx
->
h
[
4
]
+=
e
;
ctx
->
h
[
5
]
+=
f
;
ctx
->
h
[
6
]
+=
g
;
ctx
->
h
[
7
]
+=
h
;
data
+=
SHA256_CBLOCK
;
}
}
...
...
crypto/sha/sha512.c
浏览文件 @
63077bd4
/* crypto/sha/sha512.c */
/* ====================================================================
* Copyright (c) 2004 The OpenSSL Project. All rights reserved.
* Copyright (c) 2004 The OpenSSL Project. All rights reserved
* according to the OpenSSL license [found in ../../LICENSE].
* ====================================================================
*/
/*
...
...
@@ -48,6 +49,10 @@
const
char
*
SHA512_version
=
"SHA-512"
OPENSSL_VERSION_PTEXT
;
#if defined(_M_IX86) || defined(_M_AMD64) || defined(__i386) || defined(__x86_64)
#define SHA512_BLOCK_CAN_MANAGE_UNALIGNED_DATA
#endif
int
SHA384_Init
(
SHA512_CTX
*
c
)
{
c
->
h
[
0
]
=
U64
(
0xcbbb9d5dc1059ed8
);
...
...
@@ -167,7 +172,7 @@ int SHA512_Update (SHA512_CTX *c, const void *_data, size_t len)
if
(
len
>=
sizeof
(
c
->
u
))
{
#ifndef SHA512_BLOCK_CAN_MANAGE_UNALIGNED_DATA
if
((
in
t
)
data
%
sizeof
(
c
->
u
.
d
[
0
])
!=
0
)
if
((
size_
t
)
data
%
sizeof
(
c
->
u
.
d
[
0
])
!=
0
)
while
(
len
>=
sizeof
(
c
->
u
))
memcpy
(
p
,
data
,
sizeof
(
c
->
u
)),
sha512_block
(
c
,
p
,
1
),
...
...
@@ -260,10 +265,47 @@ static const SHA_LONG64 K512[80] = {
U64
(
0x4cc5d4becb3e42b6
),
U64
(
0x597f299cfc657e2a
),
U64
(
0x5fcb6fab3ad6faec
),
U64
(
0x6c44198c4a475817
)
};
#ifndef PEDANTIC
# if defined(__GNUC__) && __GNUC__>=2 && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM)
# if defined(__x86_64) || defined(__x86_64__)
# define PULL64(x) ({ SHA_LONG64 ret=*((SHA_LONG64 *)(&(x))); \
asm ("bswapq %0" \
: "=r"(ret) \
: "0"(ret)); ret; })
# endif
# endif
#endif
#ifndef PULL64
#define B(x,j) (((SHA_LONG64)(*(((unsigned char *)(&x))+j)))<<((7-j)*8))
#define PULL64(x) (B(x,0)|B(x,1)|B(x,2)|B(x,3)|B(x,4)|B(x,5)|B(x,6)|B(x,7))
#endif
#ifndef PEDANTIC
# if defined(_MSC_VER)
# if defined(_WIN64)
/* applies to both IA-64 and AMD64 */
# define ROTR(a,n) _rotr64((a),n)
# endif
# elif defined(__GNUC__) && __GNUC__>=2 && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM)
# if defined(__x86_64) || defined(__x86_64__)
# define ROTR(a,n) ({ unsigned long ret; \
asm ("rorq %1,%0" \
: "=r"(ret) \
: "J"(n),"0"(a) \
: "cc"); ret; })
# elif defined(_ARCH_PPC) && defined(__64BIT__)
# define ROTR(a,n) ({ unsigned long ret; \
asm ("rotrdi %0,%1,%2" \
: "=r"(ret) \
: "r"(a),"K"(n)); ret; })
# endif
# endif
#endif
#ifndef ROTR
#define ROTR(x,s) (((x)>>s) | (x)<<(64-s))
#endif
#define Sigma0(x) (ROTR((x),28) ^ ROTR((x),34) ^ ROTR((x),39))
#define Sigma1(x) (ROTR((x),14) ^ ROTR((x),18) ^ ROTR((x),41))
#define sigma0(x) (ROTR((x),1) ^ ROTR((x),8) ^ ((x)>>7))
...
...
@@ -272,6 +314,15 @@ static const SHA_LONG64 K512[80] = {
#define Ch(x,y,z) (((x) & (y)) ^ ((~(x)) & (z)))
#define Maj(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))
#if defined(OPENSSL_IA32_SSE2) && !defined(OPENSSL_NO_ASM)
#define GO_FOR_SSE2(ctx,in,num) do { \
extern int OPENSSL_ia32cap; \
void sha512_block_sse2(void *,const void *,size_t); \
if (!(OPENSSL_ia32cap & (1<<26))) break; \
sha512_block_sse2(ctx->h,in,num); return; \
} while (0)
#endif
#ifdef OPENSSL_SMALL_FOOTPRINT
static
void
sha512_block
(
SHA512_CTX
*
ctx
,
const
void
*
in
,
size_t
num
)
...
...
@@ -281,6 +332,10 @@ static void sha512_block (SHA512_CTX *ctx, const void *in, size_t num)
SHA_LONG64
X
[
16
];
int
i
;
#ifdef GO_FOR_SSE2
GO_FOR_SSE2
(
ctx
,
in
,
num
);
#endif
while
(
num
--
)
{
a
=
ctx
->
h
[
0
];
b
=
ctx
->
h
[
1
];
c
=
ctx
->
h
[
2
];
d
=
ctx
->
h
[
3
];
...
...
@@ -314,6 +369,7 @@ static void sha512_block (SHA512_CTX *ctx, const void *in, size_t num)
ctx
->
h
[
0
]
+=
a
;
ctx
->
h
[
1
]
+=
b
;
ctx
->
h
[
2
]
+=
c
;
ctx
->
h
[
3
]
+=
d
;
ctx
->
h
[
4
]
+=
e
;
ctx
->
h
[
5
]
+=
f
;
ctx
->
h
[
6
]
+=
g
;
ctx
->
h
[
7
]
+=
h
;
W
+=
SHA_LBLOCK
;
}
}
...
...
@@ -327,7 +383,7 @@ static void sha512_block (SHA512_CTX *ctx, const void *in, size_t num)
#define ROUND_16_80(i,a,b,c,d,e,f,g,h,X) do { \
s0 = X[(i+1)&0x0f]; s0 = sigma0(s0); \
s1 = X[(i+14)&0x0f]; s1 = sigma1(s1); \
T1 = X[
i
&0x0f] += s0 + s1 + X[(i+9)&0x0f]; \
T1 = X[
(i)
&0x0f] += s0 + s1 + X[(i+9)&0x0f]; \
ROUND_00_15(i,a,b,c,d,e,f,g,h); } while (0)
static
void
sha512_block
(
SHA512_CTX
*
ctx
,
const
void
*
in
,
size_t
num
)
...
...
@@ -337,6 +393,10 @@ static void sha512_block (SHA512_CTX *ctx, const void *in, size_t num)
SHA_LONG64
X
[
16
];
int
i
;
#ifdef GO_FOR_SSE2
GO_FOR_SSE2
(
ctx
,
in
,
num
);
#endif
while
(
num
--
)
{
a
=
ctx
->
h
[
0
];
b
=
ctx
->
h
[
1
];
c
=
ctx
->
h
[
2
];
d
=
ctx
->
h
[
3
];
...
...
@@ -393,6 +453,7 @@ static void sha512_block (SHA512_CTX *ctx, const void *in, size_t num)
ctx
->
h
[
0
]
+=
a
;
ctx
->
h
[
1
]
+=
b
;
ctx
->
h
[
2
]
+=
c
;
ctx
->
h
[
3
]
+=
d
;
ctx
->
h
[
4
]
+=
e
;
ctx
->
h
[
5
]
+=
f
;
ctx
->
h
[
6
]
+=
g
;
ctx
->
h
[
7
]
+=
h
;
W
+=
SHA_LBLOCK
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录