Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Openssl
提交
9b4eab50
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看板
提交
9b4eab50
编写于
10月 06, 2005
作者:
A
Andy Polyakov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refine logic in bn_mont.c and eliminate redundant BN_CTX pulls.
上级
ca04d7a2
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
55 addition
and
32 deletion
+55
-32
crypto/bn/bn_mont.c
crypto/bn/bn_mont.c
+55
-32
未找到文件。
crypto/bn/bn_mont.c
浏览文件 @
9b4eab50
...
@@ -69,23 +69,27 @@
...
@@ -69,23 +69,27 @@
#define MONT_WORD
/* use the faster word-based algorithm */
#define MONT_WORD
/* use the faster word-based algorithm */
#ifdef MONT_WORD
static
int
BN_from_montgomery_word
(
BIGNUM
*
ret
,
BIGNUM
*
r
,
BN_MONT_CTX
*
mont
);
#endif
int
BN_mod_mul_montgomery
(
BIGNUM
*
r
,
const
BIGNUM
*
a
,
const
BIGNUM
*
b
,
int
BN_mod_mul_montgomery
(
BIGNUM
*
r
,
const
BIGNUM
*
a
,
const
BIGNUM
*
b
,
BN_MONT_CTX
*
mont
,
BN_CTX
*
ctx
)
BN_MONT_CTX
*
mont
,
BN_CTX
*
ctx
)
{
{
BIGNUM
*
tmp
;
BIGNUM
*
tmp
;
int
ret
=
0
;
int
ret
=
0
;
#if
def OPENSSL_BN_ASM_MONT
#if
defined(OPENSSL_BN_ASM_MONT) && defined(MONT_WORD)
int
num
=
mont
->
N
.
top
;
int
num
=
mont
->
N
.
top
;
if
(
num
>
1
&&
a
->
top
==
num
&&
b
->
top
==
num
)
if
(
num
>
1
&&
a
->
top
==
num
&&
b
->
top
==
num
)
{
{
if
(
bn_wexpand
(
r
,
num
)
==
NULL
)
return
0
;
if
(
bn_wexpand
(
r
,
num
)
==
NULL
)
return
(
0
)
;
if
(
bn_mul_mont
(
r
->
d
,
a
->
d
,
b
->
d
,
mont
->
N
.
d
,
mont
->
n0
,
num
))
if
(
bn_mul_mont
(
r
->
d
,
a
->
d
,
b
->
d
,
mont
->
N
.
d
,
mont
->
n0
,
num
))
{
{
r
->
neg
=
a
->
neg
^
b
->
neg
;
r
->
neg
=
a
->
neg
^
b
->
neg
;
r
->
top
=
num
;
r
->
top
=
num
;
bn_
fix
_top
(
r
);
bn_
correct
_top
(
r
);
return
1
;
return
(
1
)
;
}
}
}
}
#endif
#endif
...
@@ -104,7 +108,11 @@ int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
...
@@ -104,7 +108,11 @@ int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
if
(
!
BN_mul
(
tmp
,
a
,
b
,
ctx
))
goto
err
;
if
(
!
BN_mul
(
tmp
,
a
,
b
,
ctx
))
goto
err
;
}
}
/* reduce from aRR to aR */
/* reduce from aRR to aR */
#ifdef MONT_WORD
if
(
!
BN_from_montgomery_word
(
r
,
tmp
,
mont
))
goto
err
;
#else
if
(
!
BN_from_montgomery
(
r
,
tmp
,
mont
,
ctx
))
goto
err
;
if
(
!
BN_from_montgomery
(
r
,
tmp
,
mont
,
ctx
))
goto
err
;
#endif
bn_check_top
(
r
);
bn_check_top
(
r
);
ret
=
1
;
ret
=
1
;
err:
err:
...
@@ -112,35 +120,25 @@ err:
...
@@ -112,35 +120,25 @@ err:
return
(
ret
);
return
(
ret
);
}
}
int
BN_from_montgomery
(
BIGNUM
*
ret
,
const
BIGNUM
*
a
,
BN_MONT_CTX
*
mont
,
BN_CTX
*
ctx
)
{
int
retn
=
0
;
#ifdef MONT_WORD
#ifdef MONT_WORD
BIGNUM
*
n
,
*
r
;
static
int
BN_from_montgomery_word
(
BIGNUM
*
ret
,
BIGNUM
*
r
,
BN_MONT_CTX
*
mont
)
{
BIGNUM
*
n
;
BN_ULONG
*
ap
,
*
np
,
*
rp
,
n0
,
v
,
*
nrp
;
BN_ULONG
*
ap
,
*
np
,
*
rp
,
n0
,
v
,
*
nrp
;
int
al
,
nl
,
max
,
i
,
x
,
ri
;
int
al
,
nl
,
max
,
i
,
x
,
ri
;
BN_CTX_start
(
ctx
);
if
((
r
=
BN_CTX_get
(
ctx
))
==
NULL
)
goto
err
;
if
(
!
BN_copy
(
r
,
a
))
goto
err
;
n
=
&
(
mont
->
N
);
n
=
&
(
mont
->
N
);
ap
=
a
->
d
;
/* mont->ri is the size of mont->N in bits (rounded up
/* mont->ri is the size of mont->N in bits (rounded up
to the word size) */
to the word size) */
al
=
ri
=
mont
->
ri
/
BN_BITS2
;
al
=
ri
=
mont
->
ri
/
BN_BITS2
;
nl
=
n
->
top
;
nl
=
n
->
top
;
if
((
al
==
0
)
||
(
nl
==
0
))
{
r
->
top
=
0
;
return
(
1
);
}
if
((
al
==
0
)
||
(
nl
==
0
))
{
r
et
->
top
=
0
;
return
(
1
);
}
max
=
(
nl
+
al
+
1
);
/* allow for overflow (no?) XXX */
max
=
(
nl
+
al
+
1
);
/* allow for overflow (no?) XXX */
if
(
bn_wexpand
(
r
,
max
)
==
NULL
)
goto
err
;
if
(
bn_wexpand
(
r
,
max
)
==
NULL
)
return
(
0
);
if
(
bn_wexpand
(
ret
,
max
)
==
NULL
)
goto
err
;
r
->
neg
=
a
->
neg
^
n
->
neg
;
r
->
neg
^=
n
->
neg
;
np
=
n
->
d
;
np
=
n
->
d
;
rp
=
r
->
d
;
rp
=
r
->
d
;
nrp
=
&
(
r
->
d
[
nl
]);
nrp
=
&
(
r
->
d
[
nl
]);
...
@@ -157,7 +155,7 @@ int BN_from_montgomery(BIGNUM *ret, const BIGNUM *a, BN_MONT_CTX *mont,
...
@@ -157,7 +155,7 @@ int BN_from_montgomery(BIGNUM *ret, const BIGNUM *a, BN_MONT_CTX *mont,
n0
=
mont
->
n0
;
n0
=
mont
->
n0
;
#ifdef BN_COUNT
#ifdef BN_COUNT
fprintf
(
stderr
,
"word BN_from_montgomery %d * %d
\n
"
,
nl
,
nl
);
fprintf
(
stderr
,
"word BN_from_montgomery
_word
%d * %d
\n
"
,
nl
,
nl
);
#endif
#endif
for
(
i
=
0
;
i
<
nl
;
i
++
)
for
(
i
=
0
;
i
<
nl
;
i
++
)
{
{
...
@@ -194,15 +192,18 @@ int BN_from_montgomery(BIGNUM *ret, const BIGNUM *a, BN_MONT_CTX *mont,
...
@@ -194,15 +192,18 @@ int BN_from_montgomery(BIGNUM *ret, const BIGNUM *a, BN_MONT_CTX *mont,
#if 0
#if 0
BN_rshift(ret,r,mont->ri);
BN_rshift(ret,r,mont->ri);
#else
#else
ret
->
neg
=
r
->
neg
;
if
(
r
->
top
<
ri
)
x
=
ri
;
{
rp
=
ret
->
d
;
ret
->
top
=
0
;
ap
=
&
(
r
->
d
[
x
]
);
return
(
1
);
if
(
r
->
top
<
x
)
}
al
=
0
;
al
=
r
->
top
-
ri
;
else
if
(
bn_wexpand
(
ret
,
al
)
==
NULL
)
return
(
0
);
al
=
r
->
top
-
x
;
ret
->
neg
=
r
->
neg
;
ret
->
top
=
al
;
ret
->
top
=
al
;
rp
=
ret
->
d
;
ap
=&
(
r
->
d
[
ri
]);
al
-=
4
;
al
-=
4
;
for
(
i
=
0
;
i
<
al
;
i
+=
4
)
for
(
i
=
0
;
i
<
al
;
i
+=
4
)
{
{
...
@@ -221,7 +222,29 @@ int BN_from_montgomery(BIGNUM *ret, const BIGNUM *a, BN_MONT_CTX *mont,
...
@@ -221,7 +222,29 @@ int BN_from_montgomery(BIGNUM *ret, const BIGNUM *a, BN_MONT_CTX *mont,
for
(;
i
<
al
;
i
++
)
for
(;
i
<
al
;
i
++
)
rp
[
i
]
=
ap
[
i
];
rp
[
i
]
=
ap
[
i
];
#endif
#endif
#else
/* !MONT_WORD */
if
(
BN_ucmp
(
ret
,
&
(
mont
->
N
))
>=
0
)
{
if
(
!
BN_usub
(
ret
,
ret
,
&
(
mont
->
N
)))
return
(
0
);
}
bn_check_top
(
ret
);
return
(
1
);
}
#endif
/* MONT_WORD */
int
BN_from_montgomery
(
BIGNUM
*
ret
,
const
BIGNUM
*
a
,
BN_MONT_CTX
*
mont
,
BN_CTX
*
ctx
)
{
int
retn
=
0
;
#ifdef MONT_WORD
BIGNUM
*
t
;
BN_CTX_start
(
ctx
);
if
((
t
=
BN_CTX_get
(
ctx
))
&&
BN_copy
(
t
,
a
))
retn
=
BN_from_montgomery_word
(
ret
,
t
,
mont
);
BN_CTX_end
(
ctx
);
#else
/* !MONT_WORD */
BIGNUM
*
t1
,
*
t2
;
BIGNUM
*
t1
,
*
t2
;
BN_CTX_start
(
ctx
);
BN_CTX_start
(
ctx
);
...
@@ -238,7 +261,6 @@ int BN_from_montgomery(BIGNUM *ret, const BIGNUM *a, BN_MONT_CTX *mont,
...
@@ -238,7 +261,6 @@ int BN_from_montgomery(BIGNUM *ret, const BIGNUM *a, BN_MONT_CTX *mont,
if
(
!
BN_mul
(
t1
,
t2
,
&
mont
->
N
,
ctx
))
goto
err
;
if
(
!
BN_mul
(
t1
,
t2
,
&
mont
->
N
,
ctx
))
goto
err
;
if
(
!
BN_add
(
t2
,
a
,
t1
))
goto
err
;
if
(
!
BN_add
(
t2
,
a
,
t1
))
goto
err
;
if
(
!
BN_rshift
(
ret
,
t2
,
mont
->
ri
))
goto
err
;
if
(
!
BN_rshift
(
ret
,
t2
,
mont
->
ri
))
goto
err
;
#endif
/* MONT_WORD */
if
(
BN_ucmp
(
ret
,
&
(
mont
->
N
))
>=
0
)
if
(
BN_ucmp
(
ret
,
&
(
mont
->
N
))
>=
0
)
{
{
...
@@ -248,6 +270,7 @@ int BN_from_montgomery(BIGNUM *ret, const BIGNUM *a, BN_MONT_CTX *mont,
...
@@ -248,6 +270,7 @@ int BN_from_montgomery(BIGNUM *ret, const BIGNUM *a, BN_MONT_CTX *mont,
bn_check_top
(
ret
);
bn_check_top
(
ret
);
err:
err:
BN_CTX_end
(
ctx
);
BN_CTX_end
(
ctx
);
#endif
/* MONT_WORD */
return
(
retn
);
return
(
retn
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录