Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
2fee68c2
Y
YTBP
项目概览
YottaChain
/
YTBP
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
YTBP
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
2fee68c2
编写于
3月 16, 2018
作者:
D
Daniel Larimer
提交者:
GitHub
3月 16, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1670 from EOSIO/applesedemo_fix_openssl11
Fix applesedemo to work with either openssl 1.0 or 1.1
上级
f7350fd0
fc4778e7
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
25 addition
and
11 deletion
+25
-11
programs/eosio-applesedemo/main.cpp
programs/eosio-applesedemo/main.cpp
+4
-2
programs/eosio-applesedemo/r1_signature_compactor.cpp
programs/eosio-applesedemo/r1_signature_compactor.cpp
+21
-9
未找到文件。
programs/eosio-applesedemo/main.cpp
浏览文件 @
2fee68c2
...
...
@@ -187,6 +187,7 @@ void sign(const string& hex) {
}
fc
::
ecdsa_sig
sig
=
ECDSA_SIG_new
();
BIGNUM
*
r
=
BN_new
(),
*
s
=
BN_new
();
const
UInt8
*
der_bytes
=
nullptr
;
fc
::
sha256
digest
(
hex
);
CFErrorRef
error
=
nullptr
;
...
...
@@ -210,8 +211,9 @@ void sign(const string& hex) {
assert
(
der_bytes
[
2
]
==
0x02
);
assert
(
der_bytes
[
4
+
der_bytes
[
3
]]
==
0x02
);
BN_bin2bn
(
der_bytes
+
4
,
der_bytes
[
3
],
sig
->
r
);
BN_bin2bn
(
der_bytes
+
6
+
der_bytes
[
3
],
der_bytes
[
4
+
der_bytes
[
3
]
+
1
],
sig
->
s
);
BN_bin2bn
(
der_bytes
+
4
,
der_bytes
[
3
],
r
);
BN_bin2bn
(
der_bytes
+
6
+
der_bytes
[
3
],
der_bytes
[
4
+
der_bytes
[
3
]
+
1
],
s
);
ECDSA_SIG_set0
(
sig
,
r
,
s
);
pub
=
get_compressed_pub_for_key
(
key
);
...
...
programs/eosio-applesedemo/r1_signature_compactor.cpp
浏览文件 @
2fee68c2
...
...
@@ -23,6 +23,9 @@ static int ECDSA_SIG_recover_key_GFp(EC_KEY *eckey, ECDSA_SIG *ecsig, const unsi
int
n
=
0
;
int
i
=
recid
/
2
;
const
BIGNUM
*
r
,
*
s
;
ECDSA_SIG_get0
(
ecsig
,
&
r
,
&
s
);
const
EC_GROUP
*
group
=
EC_KEY_get0_group
(
eckey
);
if
((
ctx
=
BN_CTX_new
())
==
NULL
)
{
ret
=
-
1
;
goto
err
;
}
BN_CTX_start
(
ctx
);
...
...
@@ -31,7 +34,7 @@ static int ECDSA_SIG_recover_key_GFp(EC_KEY *eckey, ECDSA_SIG *ecsig, const unsi
x
=
BN_CTX_get
(
ctx
);
if
(
!
BN_copy
(
x
,
order
))
{
ret
=-
1
;
goto
err
;
}
if
(
!
BN_mul_word
(
x
,
i
))
{
ret
=-
1
;
goto
err
;
}
if
(
!
BN_add
(
x
,
x
,
ecsig
->
r
))
{
ret
=-
1
;
goto
err
;
}
if
(
!
BN_add
(
x
,
x
,
r
))
{
ret
=-
1
;
goto
err
;
}
field
=
BN_CTX_get
(
ctx
);
if
(
!
EC_GROUP_get_curve_GFp
(
group
,
field
,
NULL
,
NULL
,
ctx
))
{
ret
=-
2
;
goto
err
;
}
if
(
BN_cmp
(
x
,
field
)
>=
0
)
{
ret
=
0
;
goto
err
;
}
...
...
@@ -52,9 +55,9 @@ static int ECDSA_SIG_recover_key_GFp(EC_KEY *eckey, ECDSA_SIG *ecsig, const unsi
if
(
!
BN_zero
(
zero
))
{
ret
=-
1
;
goto
err
;
}
if
(
!
BN_mod_sub
(
e
,
zero
,
e
,
order
,
ctx
))
{
ret
=-
1
;
goto
err
;
}
rr
=
BN_CTX_get
(
ctx
);
if
(
!
BN_mod_inverse
(
rr
,
ecsig
->
r
,
order
,
ctx
))
{
ret
=-
1
;
goto
err
;
}
if
(
!
BN_mod_inverse
(
rr
,
r
,
order
,
ctx
))
{
ret
=-
1
;
goto
err
;
}
sor
=
BN_CTX_get
(
ctx
);
if
(
!
BN_mod_mul
(
sor
,
ecsig
->
s
,
rr
,
order
,
ctx
))
{
ret
=-
1
;
goto
err
;
}
if
(
!
BN_mod_mul
(
sor
,
s
,
rr
,
order
,
ctx
))
{
ret
=-
1
;
goto
err
;
}
eor
=
BN_CTX_get
(
ctx
);
if
(
!
BN_mod_mul
(
eor
,
e
,
rr
,
order
,
ctx
))
{
ret
=-
1
;
goto
err
;
}
if
(
!
EC_POINT_mul
(
group
,
Q
,
eor
,
R
,
sor
,
ctx
))
{
ret
=-
2
;
goto
err
;
}
...
...
@@ -79,19 +82,28 @@ fc::crypto::r1::compact_signature compact_r1(fc::crypto::r1::public_key_data& pu
fc
::
crypto
::
r1
::
compact_signature
csig
;
ec_key
key
=
EC_KEY_new_by_curve_name
(
NID_X9_62_prime256v1
);
//We can't use ssl_bignum here; _get0() does not transfer ownership to us; _set0() does transfer ownership to fc::ecdsa_sig
const
BIGNUM
*
sig_r
,
*
sig_s
;
BIGNUM
*
r
=
BN_new
(),
*
s
=
BN_new
();
ECDSA_SIG_get0
(
sig
,
&
sig_r
,
&
sig_s
);
BN_copy
(
r
,
sig_r
);
BN_copy
(
s
,
sig_s
);
//want to always use the low S value
const
EC_GROUP
*
group
=
EC_KEY_get0_group
(
key
);
ssl_bignum
order
,
halforder
;
EC_GROUP_get_order
(
group
,
order
,
nullptr
);
BN_rshift1
(
halforder
,
order
);
if
(
BN_cmp
(
s
ig
->
s
,
halforder
)
>
0
)
BN_sub
(
s
ig
->
s
,
order
,
sig
->
s
);
if
(
BN_cmp
(
s
,
halforder
)
>
0
)
BN_sub
(
s
,
order
,
s
);
int
nBitsR
=
BN_num_bits
(
sig
->
r
);
int
nBitsS
=
BN_num_bits
(
s
ig
->
s
);
int
nBitsR
=
BN_num_bits
(
r
);
int
nBitsS
=
BN_num_bits
(
s
);
if
(
nBitsR
>
256
||
nBitsS
>
256
)
FC_THROW_EXCEPTION
(
exception
,
"Unable to sign"
);
ECDSA_SIG_set0
(
sig
,
r
,
s
);
int
nRecId
=
-
1
;
for
(
int
i
=
0
;
i
<
4
;
i
++
)
{
...
...
@@ -113,8 +125,8 @@ fc::crypto::r1::compact_signature compact_r1(fc::crypto::r1::public_key_data& pu
if
(
nRecId
==
-
1
)
FC_THROW_EXCEPTION
(
exception
,
"unable to construct recoverable key"
);
BN_bn2bin
(
sig
->
r
,
&
csig
.
data
[
33
-
(
nBitsR
+
7
)
/
8
]);
BN_bn2bin
(
s
ig
->
s
,
&
csig
.
data
[
65
-
(
nBitsS
+
7
)
/
8
]);
BN_bn2bin
(
r
,
&
csig
.
data
[
33
-
(
nBitsR
+
7
)
/
8
]);
BN_bn2bin
(
s
,
&
csig
.
data
[
65
-
(
nBitsS
+
7
)
/
8
]);
csig
.
data
[
0
]
=
nRecId
+
27
+
4
;
return
csig
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录