Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
btwise
openssl
提交
2c4226c4
O
openssl
项目概览
btwise
/
openssl
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
openssl
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2c4226c4
编写于
4月 09, 2008
作者:
A
Andy Polyakov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Do BN_nist_mod_384 by the book, as cheating doesn't work. Other functions
will be revised too. PR: 1593
上级
86173db8
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
63 addition
and
59 deletion
+63
-59
crypto/bn/bn_nist.c
crypto/bn/bn_nist.c
+63
-59
未找到文件。
crypto/bn/bn_nist.c
浏览文件 @
2c4226c4
...
...
@@ -176,10 +176,6 @@ const BIGNUM *BN_get0_nist_prime_521(void)
static
BN_ULONG
_256_data
[
BN_NIST_256_TOP
*
6
];
static
int
_is_set_256_data
=
0
;
static
void
_init_256_data
(
void
);
static
BN_ULONG
_384_data
[
BN_NIST_384_TOP
*
8
];
static
int
_is_set_384_data
=
0
;
static
void
_init_384_data
(
void
);
#endif
#define BN_NIST_ADD_ONE(a) while (!(*(a)=(*(a)+1)&BN_MASK2)) ++(a);
...
...
@@ -527,26 +523,6 @@ int BN_nist_mod_256(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
#endif
}
#if BN_BITS2 == 32
static
void
_init_384_data
(
void
)
{
int
i
;
BN_ULONG
*
tmp1
=
_384_data
;
const
BN_ULONG
*
tmp2
=
tmp1
;
memcpy
(
tmp1
,
_nist_p_384
,
BN_NIST_384_TOP
*
sizeof
(
BN_ULONG
));
tmp1
+=
BN_NIST_384_TOP
;
for
(
i
=
0
;
i
<
7
;
i
++
)
{
bn_add_words
(
tmp1
,
_nist_p_384
,
tmp2
,
BN_NIST_384_TOP
);
tmp2
=
tmp1
;
tmp1
+=
BN_NIST_384_TOP
;
}
_is_set_384_data
=
1
;
}
#endif
#define nist_set_384(to,from,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12) \
{ \
if (a12 != 0) bn_cp_32(to, 0, from, (a12) - 12) else bn_32_set_0(to, 0)\
...
...
@@ -571,17 +547,10 @@ int BN_nist_mod_384(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
int
carry
=
0
;
register
BN_ULONG
*
r_d
,
*
a_d
=
a
->
d
;
BN_ULONG
t_d
[
BN_NIST_384_TOP
],
buf
[
BN_NIST_384_TOP
];
if
(
!
_is_set_384_data
)
{
CRYPTO_w_lock
(
CRYPTO_LOCK_BN
);
if
(
!
_is_set_384_data
)
_init_384_data
();
CRYPTO_w_unlock
(
CRYPTO_LOCK_BN
);
}
buf
[
BN_NIST_384_TOP
],
c_d
[
BN_NIST_384_TOP
],
*
res
;
size_t
mask
;
i
=
BN_ucmp
(
field
,
a
);
if
(
i
==
0
)
...
...
@@ -624,48 +593,83 @@ int BN_nist_mod_384(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
}
carry
=
bn_add_words
(
r_d
+
(
128
/
BN_BITS2
),
r_d
+
(
128
/
BN_BITS2
),
t_d
,
BN_NIST_256_TOP
);
/* this is equivalent to if (result >= module) */
mask
=
0
-
(
size_t
)
bn_sub_words
(
c_d
,
r_d
,
_nist_p_384
,
BN_NIST_384_TOP
);
mask
=
~
mask
|
(
0
-
(
size_t
)
carry
);
res
=
(
BN_ULONG
*
)(((
size_t
)
c_d
&
mask
)
|
((
size_t
)
r_d
&~
mask
));
/*S2 */
carry
+=
bn_add_words
(
r_d
,
r_d
,
buf
,
BN_NIST_384_TOP
);
carry
=
bn_add_words
(
r_d
,
res
,
buf
,
BN_NIST_384_TOP
);
mask
=
0
-
(
size_t
)
bn_sub_words
(
c_d
,
r_d
,
_nist_p_384
,
BN_NIST_384_TOP
);
mask
=
~
mask
|
(
0
-
(
size_t
)
carry
);
res
=
(
BN_ULONG
*
)(((
size_t
)
c_d
&
mask
)
|
((
size_t
)
r_d
&~
mask
));
/*S3*/
nist_set_384
(
t_d
,
buf
,
20
,
19
,
18
,
17
,
16
,
15
,
14
,
13
,
12
,
23
,
22
,
21
);
carry
+=
bn_add_words
(
r_d
,
r_d
,
t_d
,
BN_NIST_384_TOP
);
carry
=
bn_add_words
(
r_d
,
res
,
t_d
,
BN_NIST_384_TOP
);
mask
=
0
-
(
size_t
)
bn_sub_words
(
c_d
,
r_d
,
_nist_p_384
,
BN_NIST_384_TOP
);
mask
=
~
mask
|
(
0
-
(
size_t
)
carry
);
res
=
(
BN_ULONG
*
)(((
size_t
)
c_d
&
mask
)
|
((
size_t
)
r_d
&~
mask
));
/*S4*/
nist_set_384
(
t_d
,
buf
,
19
,
18
,
17
,
16
,
15
,
14
,
13
,
12
,
20
,
0
,
23
,
0
);
carry
+=
bn_add_words
(
r_d
,
r_d
,
t_d
,
BN_NIST_384_TOP
);
carry
=
bn_add_words
(
r_d
,
res
,
t_d
,
BN_NIST_384_TOP
);
mask
=
0
-
(
size_t
)
bn_sub_words
(
c_d
,
r_d
,
_nist_p_384
,
BN_NIST_384_TOP
);
mask
=
~
mask
|
(
0
-
(
size_t
)
carry
);
res
=
(
BN_ULONG
*
)(((
size_t
)
c_d
&
mask
)
|
((
size_t
)
r_d
&~
mask
));
/*S5*/
nist_set_256
(
t_d
,
buf
,
0
,
0
,
0
,
0
,
23
-
4
,
22
-
4
,
21
-
4
,
20
-
4
);
carry
+=
bn_add_words
(
r_d
+
(
128
/
BN_BITS2
),
r_d
+
(
128
/
BN_BITS2
),
t_d
,
BN_NIST_256_TOP
);
nist_set_384
(
t_d
,
buf
,
0
,
0
,
0
,
0
,
23
,
22
,
21
,
20
,
0
,
0
,
0
,
0
);
carry
=
bn_add_words
(
r_d
,
res
,
t_d
,
BN_NIST_384_TOP
);
mask
=
0
-
(
size_t
)
bn_sub_words
(
c_d
,
r_d
,
_nist_p_384
,
BN_NIST_384_TOP
);
mask
=
~
mask
|
(
0
-
(
size_t
)
carry
);
res
=
(
BN_ULONG
*
)(((
size_t
)
c_d
&
mask
)
|
((
size_t
)
r_d
&~
mask
));
/*S6*/
nist_set_384
(
t_d
,
buf
,
0
,
0
,
0
,
0
,
0
,
0
,
23
,
22
,
21
,
0
,
0
,
20
);
carry
+=
bn_add_words
(
r_d
,
r_d
,
t_d
,
BN_NIST_384_TOP
);
if
(
carry
)
bn_sub_words
(
r_d
,
r_d
,
_384_data
+
BN_NIST_384_TOP
*
(
carry
-
1
),
BN_NIST_384_TOP
);
carry
=
bn_add_words
(
r_d
,
res
,
t_d
,
BN_NIST_384_TOP
);
mask
=
0
-
(
size_t
)
bn_sub_words
(
c_d
,
r_d
,
_nist_p_384
,
BN_NIST_384_TOP
);
mask
=
~
mask
|
(
0
-
(
size_t
)
carry
);
res
=
(
BN_ULONG
*
)(((
size_t
)
c_d
&
mask
)
|
((
size_t
)
r_d
&~
mask
));
/*D1*/
nist_set_384
(
t_d
,
buf
,
22
,
21
,
20
,
19
,
18
,
17
,
16
,
15
,
14
,
13
,
12
,
23
);
carry
=
bn_sub_words
(
r_d
,
r_d
,
t_d
,
BN_NIST_384_TOP
);
#if BRANCH_FREE
carry
=
bn_sub_words
(
r_d
,
res
,
t_d
,
BN_NIST_384_TOP
);
bn_add_words
(
c_d
,
r_d
,
_nist_p_384
,
BN_NIST_384_TOP
);
mask
=
0
-
(
size_t
)
carry
;
res
=
(
BN_ULONG
*
)(((
size_t
)
c_d
&
mask
)
|
((
size_t
)
r_d
&~
mask
));
#else
if
(
bn_sub_words
(
r_d
,
res
,
t_d
,
BN_NIST_384_TOP
))
bn_add_words
(
r_d
,
r_d
,
_nist_p_384
,
BN_NIST_384_TOP
);
#endif
/*D2*/
nist_set_384
(
t_d
,
buf
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
23
,
22
,
21
,
20
,
0
);
carry
+=
bn_sub_words
(
r_d
,
r_d
,
t_d
,
BN_NIST_384_TOP
);
#if BRANCH_FREE
carry
=
bn_sub_words
(
r_d
,
res
,
t_d
,
BN_NIST_384_TOP
);
bn_add_words
(
c_d
,
r_d
,
_nist_p_384
,
BN_NIST_384_TOP
);
mask
=
0
-
(
size_t
)
carry
;
res
=
(
BN_ULONG
*
)(((
size_t
)
c_d
&
mask
)
|
((
size_t
)
r_d
&~
mask
));
#else
if
(
bn_sub_words
(
r_d
,
r_d
,
t_d
,
BN_NIST_384_TOP
))
bn_add_words
(
r_d
,
r_d
,
_nist_p_384
,
BN_NIST_384_TOP
);
#endif
/*D3*/
nist_set_384
(
t_d
,
buf
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
23
,
23
,
0
,
0
,
0
);
carry
+=
bn_sub_words
(
r_d
,
r_d
,
t_d
,
BN_NIST_384_TOP
);
if
(
carry
)
bn_add_words
(
r_d
,
r_d
,
_384_data
+
BN_NIST_384_TOP
*
(
carry
-
1
),
BN_NIST_384_TOP
);
#if BRANCH_FREE
carry
=
bn_sub_words
(
r_d
,
res
,
t_d
,
BN_NIST_384_TOP
);
bn_add_words
(
c_d
,
r_d
,
_nist_p_384
,
BN_NIST_384_TOP
);
mask
=
0
-
(
size_t
)
carry
;
res
=
(
BN_ULONG
*
)(((
size_t
)
c_d
&
mask
)
|
((
size_t
)
r_d
&~
mask
)
);
nist_cp_bn
(
r_d
,
res
,
BN_NIST_384_TOP
);
#else
if
(
bn_sub_words
(
r_d
,
r_d
,
t_d
,
BN_NIST_384_TOP
))
bn_add_words
(
r_d
,
r_d
,
_nist_p_384
,
BN_NIST_384_TOP
);
#endif
r
->
top
=
BN_NIST_384_TOP
;
bn_correct_top
(
r
);
if
(
BN_ucmp
(
r
,
field
)
>=
0
)
{
bn_sub_words
(
r_d
,
r_d
,
_nist_p_384
,
BN_NIST_384_TOP
);
bn_correct_top
(
r
);
}
bn_check_top
(
r
);
return
1
;
#else
return
0
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录