Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Openssl
提交
b0513819
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看板
提交
b0513819
编写于
5月 27, 2014
作者:
F
Felix Laurie von Massenbach
提交者:
Ben Laurie
6月 01, 2014
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add a method to generate a prime that is guaranteed not to be divisible by 3 or 5.
Possibly some reduction in bias, but no speed gains.
上级
b359642f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
80 addition
and
29 deletion
+80
-29
apps/speed.c
apps/speed.c
+23
-0
crypto/bn/bn_lcl.h
crypto/bn/bn_lcl.h
+2
-0
crypto/bn/bn_prime.c
crypto/bn/bn_prime.c
+55
-29
未找到文件。
apps/speed.c
浏览文件 @
b0513819
...
...
@@ -2041,6 +2041,29 @@ int MAIN(int argc, char **argv)
BN_free
(
rnd
);
}
if
(
prime_doit
[
D_PRIME_COPRIME
])
{
BIGNUM
*
rnd
=
BN_new
();
BIGNUM
*
add
=
BN_new
();
BN_CTX
*
ctx
=
BN_CTX_new
();
BN_set_word
(
add
,
2
);
prime_print_message
(
prime_names
[
D_PRIME_COPRIME
],
prime_c
[
D_PRIME_COPRIME
]);
Time_F
(
START
);
for
(
count
=
0
,
run
=
1
;
COND
(
prime_c
[
D_PRIME_COPRIME
]);
count
++
)
bn_probable_prime_dh_coprime
(
rnd
,
1024
,
add
,
NULL
,
ctx
);
d
=
Time_F
(
STOP
);
prime_print_result
(
D_PRIME_COPRIME
,
count
,
d
);
BN_CTX_free
(
ctx
);
BN_free
(
add
);
BN_free
(
rnd
);
}
RAND_pseudo_bytes
(
buf
,
36
);
#ifndef OPENSSL_NO_RSA
...
...
crypto/bn/bn_lcl.h
浏览文件 @
b0513819
...
...
@@ -536,6 +536,8 @@ BIGNUM *int_bn_mod_inverse(BIGNUM *in,
int
bn_probable_prime_dh
(
BIGNUM
*
rnd
,
int
bits
,
const
BIGNUM
*
add
,
const
BIGNUM
*
rem
,
BN_CTX
*
ctx
);
int
bn_probable_prime_dh_coprime
(
BIGNUM
*
rnd
,
int
bits
,
const
BIGNUM
*
add
,
const
BIGNUM
*
rem
,
BN_CTX
*
ctx
);
#ifdef __cplusplus
}
...
...
crypto/bn/bn_prime.c
浏览文件 @
b0513819
...
...
@@ -129,9 +129,13 @@
static
int
witness
(
BIGNUM
*
w
,
const
BIGNUM
*
a
,
const
BIGNUM
*
a1
,
const
BIGNUM
*
a1_odd
,
int
k
,
BN_CTX
*
ctx
,
BN_MONT_CTX
*
mont
);
static
int
probable_prime
(
BIGNUM
*
rnd
,
int
bits
);
static
int
probable_prime_dh
(
BIGNUM
*
rnd
,
const
BIGNUM
*
add
,
const
BIGNUM
*
rem
,
BN_CTX
*
ctx
,
int
first_prime_index
);
static
int
probable_prime_dh_safe
(
BIGNUM
*
rnd
,
int
bits
,
const
BIGNUM
*
add
,
const
BIGNUM
*
rem
,
BN_CTX
*
ctx
);
static
int
prime_offsets
[
8
]
=
{
7
,
11
,
13
,
17
,
19
,
23
,
29
,
31
};
int
BN_GENCB_call
(
BN_GENCB
*
cb
,
int
a
,
int
b
)
{
/* No callback means continue */
...
...
@@ -363,40 +367,25 @@ err:
int
bn_probable_prime_dh
(
BIGNUM
*
rnd
,
int
bits
,
const
BIGNUM
*
add
,
const
BIGNUM
*
rem
,
BN_CTX
*
ctx
)
{
int
i
,
ret
=
0
;
BIGNUM
*
t1
;
if
(
!
BN_rand
(
rnd
,
bits
,
0
,
1
))
return
(
0
);
BN_CTX_start
(
ctx
);
if
((
t1
=
BN_CTX_get
(
ctx
))
==
NULL
)
goto
err
;
if
(
!
BN_rand
(
rnd
,
bits
,
0
,
1
))
goto
err
;
return
(
probable_prime_dh
(
rnd
,
add
,
rem
,
ctx
,
1
));
}
/* we need ((rnd-rem) % add) == 0 */
int
bn_probable_prime_dh_coprime
(
BIGNUM
*
rnd
,
int
bits
,
const
BIGNUM
*
add
,
const
BIGNUM
*
rem
,
BN_CTX
*
ctx
)
{
BIGNUM
*
offset_index
=
BN_new
();
if
(
!
BN_mod
(
t1
,
rnd
,
add
,
ctx
))
goto
err
;
if
(
!
BN_sub
(
rnd
,
rnd
,
t1
))
goto
err
;
if
(
rem
==
NULL
)
{
if
(
!
BN_add_word
(
rnd
,
1
))
goto
err
;
}
else
{
if
(
!
BN_add
(
rnd
,
rnd
,
rem
))
goto
err
;
}
if
(
!
BN_rand
(
rnd
,
bits
,
0
,
1
))
return
(
0
);
if
(
!
BN_rand
(
offset_index
,
3
,
-
1
,
-
1
))
return
(
0
);
/* we now have a random number 'rand' to test. */
BN_mul_word
(
rnd
,
30
);
BN_add_word
(
rnd
,
prime_offsets
[
BN_get_word
(
offset_index
)]);
BN_free
(
offset_index
);
loop:
for
(
i
=
1
;
i
<
NUMPRIMES
;
i
++
)
{
/* check that rnd is a prime */
if
(
BN_mod_word
(
rnd
,(
BN_ULONG
)
primes
[
i
])
<=
1
)
{
if
(
!
BN_add
(
rnd
,
rnd
,
add
))
goto
err
;
goto
loop
;
}
}
ret
=
1
;
err:
BN_CTX_end
(
ctx
);
bn_check_top
(
rnd
);
return
(
ret
);
return
(
probable_prime_dh
(
rnd
,
add
,
rem
,
ctx
,
3
));
}
static
int
witness
(
BIGNUM
*
w
,
const
BIGNUM
*
a
,
const
BIGNUM
*
a1
,
...
...
@@ -491,6 +480,43 @@ loop:
return
(
1
);
}
static
int
probable_prime_dh
(
BIGNUM
*
rnd
,
const
BIGNUM
*
add
,
const
BIGNUM
*
rem
,
BN_CTX
*
ctx
,
int
first_prime_index
)
{
int
i
,
ret
=
0
;
BIGNUM
*
t1
;
BN_CTX_start
(
ctx
);
if
((
t1
=
BN_CTX_get
(
ctx
))
==
NULL
)
goto
err
;
/* we need ((rnd-rem) % add) == 0 */
if
(
!
BN_mod
(
t1
,
rnd
,
add
,
ctx
))
goto
err
;
if
(
!
BN_sub
(
rnd
,
rnd
,
t1
))
goto
err
;
if
(
rem
==
NULL
)
{
if
(
!
BN_add_word
(
rnd
,
1
))
goto
err
;
}
else
{
if
(
!
BN_add
(
rnd
,
rnd
,
rem
))
goto
err
;
}
/* we now have a random number 'rand' to test. */
loop:
for
(
i
=
first_prime_index
;
i
<
NUMPRIMES
;
i
++
)
{
/* check that rnd is a prime */
if
(
BN_mod_word
(
rnd
,(
BN_ULONG
)
primes
[
i
])
<=
1
)
{
if
(
!
BN_add
(
rnd
,
rnd
,
add
))
goto
err
;
goto
loop
;
}
}
ret
=
1
;
err:
BN_CTX_end
(
ctx
);
bn_check_top
(
rnd
);
return
(
ret
);
}
static
int
probable_prime_dh_safe
(
BIGNUM
*
p
,
int
bits
,
const
BIGNUM
*
padd
,
const
BIGNUM
*
rem
,
BN_CTX
*
ctx
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录