Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Openssl
提交
e869d4bd
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e869d4bd
编写于
3月 07, 2001
作者:
B
Bodo Möller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
More method functions.
上级
60428dbf
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
168 addition
and
12 deletion
+168
-12
crypto/ec/ec.h
crypto/ec/ec.h
+2
-1
crypto/ec/ec_err.c
crypto/ec/ec_err.c
+1
-0
crypto/ec/ec_lcl.h
crypto/ec/ec_lcl.h
+3
-3
crypto/ec/ec_lib.c
crypto/ec/ec_lib.c
+1
-1
crypto/ec/ecp_smpl.c
crypto/ec/ecp_smpl.c
+161
-7
未找到文件。
crypto/ec/ec.h
浏览文件 @
e869d4bd
...
...
@@ -133,7 +133,7 @@ int EC_POINT_dbl(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, BN_CTX *);
int
EC_POINT_is_at_infinity
(
const
EC_GROUP
*
,
const
EC_POINT
*
);
int
EC_POINT_is_on_curve
(
const
EC_GROUP
*
,
const
EC_POINT
*
,
BN_CTX
*
);
int
EC_POINT_make_affine
(
const
EC_GROUP
*
,
const
EC_POINT
*
,
BN_CTX
*
);
int
EC_POINT_make_affine
(
const
EC_GROUP
*
,
EC_POINT
*
,
BN_CTX
*
);
...
...
@@ -150,6 +150,7 @@ int EC_POINT_make_affine(const EC_GROUP *, const EC_POINT *, BN_CTX *);
/* Function codes. */
#define EC_F_EC_GFP_SIMPLE_GROUP_SET_GENERATOR 117
#define EC_F_EC_GFP_SIMPLE_MAKE_AFFINE 118
#define EC_F_EC_GROUP_CLEAR_FREE 103
#define EC_F_EC_GROUP_COPY 102
#define EC_F_EC_GROUP_FREE 104
...
...
crypto/ec/ec_err.c
浏览文件 @
e869d4bd
...
...
@@ -67,6 +67,7 @@
static
ERR_STRING_DATA
EC_str_functs
[]
=
{
{
ERR_PACK
(
0
,
EC_F_EC_GFP_SIMPLE_GROUP_SET_GENERATOR
,
0
),
"EC_GFP_SIMPLE_GROUP_SET_GENERATOR"
},
{
ERR_PACK
(
0
,
EC_F_EC_GFP_SIMPLE_MAKE_AFFINE
,
0
),
"EC_GFP_SIMPLE_MAKE_AFFINE"
},
{
ERR_PACK
(
0
,
EC_F_EC_GROUP_CLEAR_FREE
,
0
),
"EC_GROUP_clear_free"
},
{
ERR_PACK
(
0
,
EC_F_EC_GROUP_COPY
,
0
),
"EC_GROUP_copy"
},
{
ERR_PACK
(
0
,
EC_F_EC_GROUP_FREE
,
0
),
"EC_GROUP_free"
},
...
...
crypto/ec/ec_lcl.h
浏览文件 @
e869d4bd
...
...
@@ -99,7 +99,7 @@ struct ec_method_st {
/* used by EC_POINT_is_at_infinity, EC_POINT_is_on_curve, EC_POINT_make_affine */
int
(
*
is_at_infinity
)(
const
EC_GROUP
*
,
const
EC_POINT
*
);
int
(
*
is_on_curve
)(
const
EC_GROUP
*
,
const
EC_POINT
*
,
BN_CTX
*
);
int
(
*
make_affine
)(
const
EC_GROUP
*
,
const
EC_POINT
*
,
BN_CTX
*
);
int
(
*
make_affine
)(
const
EC_GROUP
*
,
EC_POINT
*
,
BN_CTX
*
);
/* internal functions */
...
...
@@ -134,7 +134,7 @@ struct ec_group_st {
* or abused for all kinds of fields, not just GF(p).)
* For characteristic > 3, the curve is defined
* by a Weierstrass equation of the form
*
Y^2 = X^3 + a*X
+ b.
*
y^2 = x^3 + a*x
+ b.
*/
int
a_is_minus3
;
/* enable optimized point arithmetics for special case */
...
...
@@ -197,7 +197,7 @@ int ec_GFp_simple_add(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, const EC
int
ec_GFp_simple_dbl
(
const
EC_GROUP
*
,
EC_POINT
*
r
,
const
EC_POINT
*
a
,
BN_CTX
*
);
int
ec_GFp_simple_is_at_infinity
(
const
EC_GROUP
*
,
const
EC_POINT
*
);
int
ec_GFp_simple_is_on_curve
(
const
EC_GROUP
*
,
const
EC_POINT
*
,
BN_CTX
*
);
int
ec_GFp_simple_make_affine
(
const
EC_GROUP
*
,
const
EC_POINT
*
,
BN_CTX
*
);
int
ec_GFp_simple_make_affine
(
const
EC_GROUP
*
,
EC_POINT
*
,
BN_CTX
*
);
int
ec_GFp_simple_field_mul
(
const
EC_GROUP
*
,
BIGNUM
*
r
,
const
BIGNUM
*
a
,
const
BIGNUM
*
b
,
BN_CTX
*
);
int
ec_GFp_simple_field_sqr
(
const
EC_GROUP
*
,
BIGNUM
*
r
,
const
BIGNUM
*
a
,
BN_CTX
*
);
...
...
crypto/ec/ec_lib.c
浏览文件 @
e869d4bd
...
...
@@ -421,7 +421,7 @@ int EC_POINT_is_on_curve(const EC_GROUP *group, const EC_POINT *point, BN_CTX *c
}
int
EC_POINT_make_affine
(
const
EC_GROUP
*
group
,
const
EC_POINT
*
point
,
BN_CTX
*
ctx
)
int
EC_POINT_make_affine
(
const
EC_GROUP
*
group
,
EC_POINT
*
point
,
BN_CTX
*
ctx
)
{
if
(
group
->
meth
->
make_affine
==
0
)
{
...
...
crypto/ec/ecp_smpl.c
浏览文件 @
e869d4bd
...
...
@@ -385,8 +385,8 @@ int ec_GFp_simple_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, con
{
/* a is the same point as b */
BN_CTX_end
(
ctx
);
ctx
=
NULL
;
ret
=
EC_POINT_dbl
(
group
,
r
,
a
,
ctx
);
ctx
=
NULL
;
goto
end
;
}
else
...
...
@@ -491,8 +491,6 @@ int ec_GFp_simple_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, BN_
n3
=
BN_CTX_get
(
ctx
);
if
(
n3
==
NULL
)
goto
err
;
/* TODO: optimization for group->a_is_minus3 */
/* n1 */
if
(
a
->
Z_is_one
)
{
...
...
@@ -577,12 +575,168 @@ int ec_GFp_simple_is_at_infinity(const EC_GROUP *group, const EC_POINT *point)
}
int
ec_GFp_simple_is_on_curve
(
const
EC_GROUP
*
group
,
const
EC_POINT
*
point
,
BN_CTX
*
ctx
);
/* TODO */
int
ec_GFp_simple_is_on_curve
(
const
EC_GROUP
*
group
,
const
EC_POINT
*
point
,
BN_CTX
*
ctx
)
{
int
(
*
field_mul
)(
const
EC_GROUP
*
,
BIGNUM
*
,
const
BIGNUM
*
,
const
BIGNUM
*
,
BN_CTX
*
);
int
(
*
field_sqr
)(
const
EC_GROUP
*
,
BIGNUM
*
,
const
BIGNUM
*
,
BN_CTX
*
);
const
BIGNUM
*
p
;
BN_CTX
*
new_ctx
=
NULL
;
BIGNUM
*
rh
,
*
tmp1
,
*
tmp2
,
*
Z4
,
*
Z6
;
int
ret
=
-
1
;
if
(
EC_POINT_is_at_infinity
(
group
,
point
))
return
1
;
int
ec_GFp_simple_make_affine
(
const
EC_GROUP
*
group
,
const
EC_POINT
*
point
,
BN_CTX
*
ctx
);
/* TODO */
field_mul
=
group
->
meth
->
field_mul
;
field_sqr
=
group
->
meth
->
field_sqr
;
p
=
&
group
->
field
;
if
(
ctx
==
NULL
)
{
ctx
=
new_ctx
=
BN_CTX_new
();
if
(
ctx
==
NULL
)
return
0
;
}
BN_CTX_start
(
ctx
);
rh
=
BN_CTX_get
(
ctx
);
tmp1
=
BN_CTX_get
(
ctx
);
tmp2
=
BN_CTX_get
(
ctx
);
Z4
=
BN_CTX_get
(
ctx
);
Z6
=
BN_CTX_get
(
ctx
);
if
(
Z6
==
NULL
)
goto
err
;
/* We have a curve defined by a Weierstrass equation
* y^2 = x^3 + a*x + b.
* The point to consider is given in Jacobian projective coordinates
* where (X, Y, Z) represents (x, y) = (X/Z^2, Y/Z^3).
* Substituting this and multiplying by Z^6 transforms the above equation into
* Y^2 = X^3 + a*X*Z^4 + b*Z^6.
* To test this, we add up the right-hand side in 'rh'.
*/
/* rh := X^3 */
if
(
!
field_sqr
(
group
,
rh
,
&
point
->
X
,
ctx
))
goto
err
;
if
(
!
field_mul
(
group
,
rh
,
rh
,
&
point
->
X
,
ctx
))
goto
err
;
if
(
!
point
->
Z_is_one
)
{
if
(
!
field_sqr
(
group
,
tmp1
,
&
point
->
Z
,
ctx
))
goto
err
;
if
(
!
field_sqr
(
group
,
Z4
,
tmp1
,
ctx
))
goto
err
;
if
(
!
field_mul
(
group
,
Z6
,
Z4
,
tmp1
,
ctx
))
goto
err
;
/* rh := rh + a*X*Z^4 */
if
(
!
field_mul
(
group
,
tmp1
,
&
point
->
X
,
Z4
,
ctx
))
goto
err
;
if
(
&
group
->
a_is_minus3
)
{
if
(
!
BN_mod_lshift1_quick
(
tmp2
,
tmp1
,
p
))
goto
err
;
if
(
!
BN_mod_add_quick
(
tmp2
,
tmp2
,
tmp1
,
p
))
goto
err
;
if
(
!
BN_mod_sub_quick
(
rh
,
rh
,
tmp2
,
p
))
goto
err
;
}
else
{
if
(
!
field_mul
(
group
,
tmp2
,
tmp1
,
&
group
->
a
,
ctx
))
goto
err
;
if
(
!
BN_mod_add_quick
(
rh
,
rh
,
tmp2
,
p
))
goto
err
;
}
/* rh := rh + b*Z^6 */
if
(
!
field_mul
(
group
,
tmp1
,
&
group
->
b
,
Z6
,
ctx
))
goto
err
;
if
(
!
BN_mod_add_quick
(
rh
,
rh
,
tmp1
,
p
))
goto
err
;
}
else
{
/* point->Z_is_one */
/* rh := rh + a*X */
if
(
&
group
->
a_is_minus3
)
{
if
(
!
BN_mod_lshift1_quick
(
tmp2
,
&
point
->
X
,
p
))
goto
err
;
if
(
!
BN_mod_add_quick
(
tmp2
,
tmp2
,
&
point
->
X
,
p
))
goto
err
;
if
(
!
BN_mod_sub_quick
(
rh
,
rh
,
tmp2
,
p
))
goto
err
;
}
else
{
if
(
!
field_mul
(
group
,
tmp2
,
&
point
->
X
,
&
group
->
a
,
ctx
))
goto
err
;
if
(
!
BN_mod_add_quick
(
rh
,
rh
,
tmp2
,
p
))
goto
err
;
}
/* rh := rh + b */
if
(
!
BN_mod_add_quick
(
rh
,
rh
,
&
group
->
b
,
p
))
goto
err
;
}
/* 'lh' := Y^2 */
if
(
!
field_sqr
(
group
,
tmp1
,
&
point
->
Y
,
ctx
))
goto
err
;
ret
=
(
0
==
BN_cmp
(
tmp1
,
rh
));
err:
BN_CTX_end
(
ctx
);
if
(
new_ctx
!=
NULL
)
BN_CTX_free
(
new_ctx
);
return
ret
;
}
int
ec_GFp_simple_make_affine
(
const
EC_GROUP
*
group
,
EC_POINT
*
point
,
BN_CTX
*
ctx
)
{
BN_CTX
*
new_ctx
=
NULL
;
BIGNUM
*
Z
,
*
Z_1
,
*
Z_2
,
*
Z_3
;
int
ret
=
0
;
if
(
point
->
Z_is_one
||
EC_POINT_is_at_infinity
(
group
,
point
))
return
1
;
if
(
ctx
==
NULL
)
{
ctx
=
new_ctx
=
BN_CTX_new
();
if
(
ctx
==
NULL
)
return
0
;
}
BN_CTX_start
(
ctx
);
Z
=
BN_CTX_get
(
ctx
);
Z_1
=
BN_CTX_get
(
ctx
);
Z_2
=
BN_CTX_get
(
ctx
);
Z_3
=
BN_CTX_get
(
ctx
);
if
(
Z_3
==
NULL
)
goto
end
;
/* transform (X, Y, Z) into (X/Z^2, Y/Z^3, 1) */
if
(
group
->
meth
->
field_decode
)
{
if
(
!
group
->
meth
->
field_decode
(
group
,
Z
,
&
point
->
Z
,
ctx
))
goto
end
;
}
else
Z
=
&
point
->
Z
;
if
(
BN_is_one
(
Z
))
{
point
->
Z_is_one
=
1
;
ret
=
1
;
goto
end
;
}
if
(
!
BN_mod_inverse
(
Z_1
,
Z
,
&
group
->
field
,
ctx
))
{
ECerr
(
EC_F_EC_GFP_SIMPLE_MAKE_AFFINE
,
ERR_R_BN_LIB
);
goto
end
;
}
if
(
!
BN_mod_sqr
(
Z_2
,
Z_1
,
&
group
->
field
,
ctx
))
goto
end
;
if
(
!
BN_mod_mul
(
Z_3
,
Z_2
,
Z_1
,
&
group
->
field
,
ctx
))
goto
end
;
if
(
!
BN_mod_mul
(
&
point
->
X
,
&
point
->
X
,
Z_2
,
&
group
->
field
,
ctx
))
goto
end
;
if
(
!
BN_mod_mul
(
&
point
->
Y
,
&
point
->
Y
,
Z_2
,
&
group
->
field
,
ctx
))
goto
end
;
if
(
!
BN_set_word
(
&
point
->
Z
,
1
))
goto
end
;
point
->
Z_is_one
=
1
;
ret
=
1
;
end:
BN_CTX_end
(
ctx
);
if
(
new_ctx
!=
NULL
)
BN_CTX_free
(
new_ctx
);
return
ret
;
}
int
ec_GFp_simple_field_mul
(
const
EC_GROUP
*
group
,
BIGNUM
*
r
,
const
BIGNUM
*
a
,
const
BIGNUM
*
b
,
BN_CTX
*
ctx
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录