Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
btwise
openssl
提交
4c97a04e
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,发现更多精彩内容 >>
提交
4c97a04e
编写于
4月 12, 2006
作者:
D
Dr. Stephen Henson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
PKCS#3 DH PKCS#8 ASN1 support.
上级
fb05e1cd
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
121 addition
and
2 deletion
+121
-2
crypto/dh/dh.h
crypto/dh/dh.h
+4
-0
crypto/dh/dh_ameth.c
crypto/dh/dh_ameth.c
+113
-2
crypto/dh/dh_err.c
crypto/dh/dh_err.c
+4
-0
未找到文件。
crypto/dh/dh.h
浏览文件 @
4c97a04e
...
...
@@ -216,14 +216,18 @@ void ERR_load_DH_strings(void);
#define DH_F_DH_BUILTIN_GENPARAMS 106
#define DH_F_DH_NEW_METHOD 105
#define DH_F_DH_PARAM_DECODE 107
#define DH_F_DH_PRIV_DECODE 110
#define DH_F_DH_PRIV_ENCODE 111
#define DH_F_DH_PUB_DECODE 108
#define DH_F_DH_PUB_ENCODE 109
#define DH_F_DSA_PRIV_ENCODE 112
#define DH_F_GENERATE_KEY 103
#define DH_F_GENERATE_PARAMETERS 104
/* Reason codes. */
#define DH_R_BAD_GENERATOR 101
#define DH_R_BN_DECODE_ERROR 103
#define DH_R_BN_ERROR 106
#define DH_R_DECODE_ERROR 104
#define DH_R_INVALID_PUBKEY 102
#define DH_R_NO_PRIVATE_VALUE 100
...
...
crypto/dh/dh_ameth.c
浏览文件 @
4c97a04e
...
...
@@ -174,6 +174,117 @@ static int dh_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey)
return
0
;
}
/* PKCS#8 DH is defined in PKCS#11 of all places. It is similar to DH in
* that the AlgorithmIdentifier contains the paramaters, the private key
* is explcitly included and the pubkey must be recalculated.
*/
static
int
dh_priv_decode
(
EVP_PKEY
*
pkey
,
PKCS8_PRIV_KEY_INFO
*
p8
)
{
const
unsigned
char
*
p
,
*
pm
;
int
pklen
,
pmlen
;
int
ptype
;
void
*
pval
;
ASN1_STRING
*
pstr
;
X509_ALGOR
*
palg
;
ASN1_INTEGER
*
privkey
=
NULL
;
DH
*
dh
=
NULL
;
if
(
!
PKCS8_pkey_get0
(
NULL
,
&
p
,
&
pklen
,
&
palg
,
p8
))
return
0
;
X509_ALGOR_get0
(
NULL
,
&
ptype
,
&
pval
,
palg
);
if
(
ptype
!=
V_ASN1_SEQUENCE
)
goto
decerr
;
if
(
!
(
privkey
=
d2i_ASN1_INTEGER
(
NULL
,
&
p
,
pklen
)))
goto
decerr
;
pstr
=
pval
;
pm
=
pstr
->
data
;
pmlen
=
pstr
->
length
;
if
(
!
(
dh
=
d2i_DHparams
(
NULL
,
&
pm
,
pmlen
)))
goto
decerr
;
/* We have parameters now set private key */
if
(
!
(
dh
->
priv_key
=
ASN1_INTEGER_to_BN
(
privkey
,
NULL
)))
{
DHerr
(
DH_F_DH_PRIV_DECODE
,
DH_R_BN_ERROR
);
goto
dherr
;
}
/* Calculate public key */
if
(
!
DH_generate_key
(
dh
))
goto
dherr
;
EVP_PKEY_assign_DH
(
pkey
,
dh
);
ASN1_INTEGER_free
(
privkey
);
return
1
;
decerr:
DHerr
(
DH_F_DH_PRIV_DECODE
,
EVP_R_DECODE_ERROR
);
dherr:
DH_free
(
dh
);
return
0
;
}
static
int
dh_priv_encode
(
PKCS8_PRIV_KEY_INFO
*
p8
,
const
EVP_PKEY
*
pkey
)
{
ASN1_STRING
*
params
=
NULL
;
ASN1_INTEGER
*
prkey
=
NULL
;
unsigned
char
*
dp
=
NULL
;
int
dplen
;
params
=
ASN1_STRING_new
();
if
(
!
params
)
{
DHerr
(
DH_F_DH_PRIV_ENCODE
,
ERR_R_MALLOC_FAILURE
);
goto
err
;
}
params
->
length
=
i2d_DHparams
(
pkey
->
pkey
.
dh
,
&
params
->
data
);
if
(
params
->
length
<=
0
)
{
DHerr
(
DH_F_DH_PRIV_ENCODE
,
ERR_R_MALLOC_FAILURE
);
goto
err
;
}
params
->
type
=
V_ASN1_SEQUENCE
;
/* Get private key into integer */
prkey
=
BN_to_ASN1_INTEGER
(
pkey
->
pkey
.
dh
->
priv_key
,
NULL
);
if
(
!
prkey
)
{
DHerr
(
DH_F_DSA_PRIV_ENCODE
,
DH_R_BN_ERROR
);
goto
err
;
}
dplen
=
i2d_ASN1_INTEGER
(
prkey
,
&
dp
);
ASN1_INTEGER_free
(
prkey
);
if
(
!
PKCS8_pkey_set0
(
p8
,
OBJ_nid2obj
(
NID_dsa
),
0
,
V_ASN1_SEQUENCE
,
params
,
dp
,
dplen
))
goto
err
;
return
1
;
err:
if
(
dp
!=
NULL
)
OPENSSL_free
(
dp
);
if
(
params
!=
NULL
)
ASN1_STRING_free
(
params
);
if
(
prkey
!=
NULL
)
ASN1_INTEGER_free
(
prkey
);
return
0
;
}
static
void
update_buflen
(
const
BIGNUM
*
b
,
size_t
*
pbuflen
)
{
int
i
;
...
...
@@ -361,8 +472,8 @@ const EVP_PKEY_ASN1_METHOD dh_asn1_meth =
dh_pub_cmp
,
dh_public_print
,
0
,
0
,
dh_priv_decode
,
dh_priv_encode
,
dh_private_print
,
int_dh_size
,
...
...
crypto/dh/dh_err.c
浏览文件 @
4c97a04e
...
...
@@ -76,8 +76,11 @@ static ERR_STRING_DATA DH_str_functs[]=
{
ERR_FUNC
(
DH_F_DH_BUILTIN_GENPARAMS
),
"DH_BUILTIN_GENPARAMS"
},
{
ERR_FUNC
(
DH_F_DH_NEW_METHOD
),
"DH_new_method"
},
{
ERR_FUNC
(
DH_F_DH_PARAM_DECODE
),
"DH_PARAM_DECODE"
},
{
ERR_FUNC
(
DH_F_DH_PRIV_DECODE
),
"DH_PRIV_DECODE"
},
{
ERR_FUNC
(
DH_F_DH_PRIV_ENCODE
),
"DH_PRIV_ENCODE"
},
{
ERR_FUNC
(
DH_F_DH_PUB_DECODE
),
"DH_PUB_DECODE"
},
{
ERR_FUNC
(
DH_F_DH_PUB_ENCODE
),
"DH_PUB_ENCODE"
},
{
ERR_FUNC
(
DH_F_DSA_PRIV_ENCODE
),
"DSA_PRIV_ENCODE"
},
{
ERR_FUNC
(
DH_F_GENERATE_KEY
),
"GENERATE_KEY"
},
{
ERR_FUNC
(
DH_F_GENERATE_PARAMETERS
),
"GENERATE_PARAMETERS"
},
{
0
,
NULL
}
...
...
@@ -87,6 +90,7 @@ static ERR_STRING_DATA DH_str_reasons[]=
{
{
ERR_REASON
(
DH_R_BAD_GENERATOR
)
,
"bad generator"
},
{
ERR_REASON
(
DH_R_BN_DECODE_ERROR
)
,
"bn decode error"
},
{
ERR_REASON
(
DH_R_BN_ERROR
)
,
"bn error"
},
{
ERR_REASON
(
DH_R_DECODE_ERROR
)
,
"decode error"
},
{
ERR_REASON
(
DH_R_INVALID_PUBKEY
)
,
"invalid public key"
},
{
ERR_REASON
(
DH_R_NO_PRIVATE_VALUE
)
,
"no private value"
},
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录