Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Openssl
提交
39e8d0ce
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,发现更多精彩内容 >>
提交
39e8d0ce
编写于
12月 18, 2015
作者:
R
Richard Levitte
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Adapt all engines that need it to opaque EVP_CIPHER
Reviewed-by:
N
Rich Salz
<
rsalz@openssl.org
>
上级
6435f0f6
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
236 addition
and
148 deletion
+236
-148
crypto/engine/eng_openssl.c
crypto/engine/eng_openssl.c
+72
-34
engines/ccgost/gost_crypt.c
engines/ccgost/gost_crypt.c
+70
-33
engines/ccgost/gost_eng.c
engines/ccgost/gost_eng.c
+4
-4
engines/ccgost/gost_lcl.h
engines/ccgost/gost_lcl.h
+3
-3
engines/e_ossltest.c
engines/e_ossltest.c
+31
-30
engines/e_padlock.c
engines/e_padlock.c
+56
-44
未找到文件。
crypto/engine/eng_openssl.c
浏览文件 @
39e8d0ce
...
@@ -242,9 +242,6 @@ IMPLEMENT_DYNAMIC_CHECK_FN()
...
@@ -242,9 +242,6 @@ IMPLEMENT_DYNAMIC_CHECK_FN()
*/
*/
# include <openssl/rc4.h>
# include <openssl/rc4.h>
# define TEST_RC4_KEY_SIZE 16
# define TEST_RC4_KEY_SIZE 16
static
const
int
test_cipher_nids
[]
=
{
NID_rc4
,
NID_rc4_40
};
static
const
int
test_cipher_nids_number
=
2
;
typedef
struct
{
typedef
struct
{
unsigned
char
key
[
TEST_RC4_KEY_SIZE
];
unsigned
char
key
[
TEST_RC4_KEY_SIZE
];
RC4_KEY
ks
;
RC4_KEY
ks
;
...
@@ -272,47 +269,86 @@ static int test_rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
...
@@ -272,47 +269,86 @@ static int test_rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
return
1
;
return
1
;
}
}
static
const
EVP_CIPHER
test_r4_cipher
=
{
static
EVP_CIPHER
*
r4_cipher
=
NULL
;
NID_rc4
,
static
const
EVP_CIPHER
*
test_r4_cipher
(
void
)
1
,
TEST_RC4_KEY_SIZE
,
0
,
{
EVP_CIPH_VARIABLE_LENGTH
,
if
(
r4_cipher
==
NULL
)
{
test_rc4_init_key
,
EVP_CIPHER
*
cipher
;
test_rc4_cipher
,
NULL
,
if
((
cipher
=
EVP_CIPHER_meth_new
(
NID_rc4
,
1
,
TEST_RC4_KEY_SIZE
))
==
NULL
sizeof
(
TEST_RC4_KEY
),
||
!
EVP_CIPHER_meth_set_iv_length
(
cipher
,
0
)
NULL
,
||
!
EVP_CIPHER_meth_set_flags
(
cipher
,
EVP_CIPH_VARIABLE_LENGTH
)
NULL
,
||
!
EVP_CIPHER_meth_set_init
(
cipher
,
test_rc4_init_key
)
NULL
,
||
!
EVP_CIPHER_meth_set_do_cipher
(
cipher
,
test_rc4_cipher
)
NULL
||
!
EVP_CIPHER_meth_set_impl_ctx_size
(
cipher
,
sizeof
(
TEST_RC4_KEY
)))
{
};
EVP_CIPHER_meth_free
(
cipher
);
cipher
=
NULL
;
static
const
EVP_CIPHER
test_r4_40_cipher
=
{
}
NID_rc4_40
,
r4_cipher
=
cipher
;
1
,
5
/* 40 bit */
,
0
,
}
EVP_CIPH_VARIABLE_LENGTH
,
return
r4_cipher
;
test_rc4_init_key
,
}
test_rc4_cipher
,
static
void
test_r4_cipher_destroy
(
void
)
NULL
,
{
sizeof
(
TEST_RC4_KEY
),
EVP_CIPHER_meth_free
(
r4_cipher
);
NULL
,
r4_cipher
=
NULL
;
NULL
,
}
NULL
,
NULL
static
EVP_CIPHER
*
r4_40_cipher
=
NULL
;
};
static
const
EVP_CIPHER
*
test_r4_40_cipher
(
void
)
{
if
(
r4_40_cipher
==
NULL
)
{
EVP_CIPHER
*
cipher
;
if
((
cipher
=
EVP_CIPHER_meth_new
(
NID_rc4
,
1
,
5
/* 40 bits */
))
==
NULL
||
!
EVP_CIPHER_meth_set_iv_length
(
cipher
,
0
)
||
!
EVP_CIPHER_meth_set_flags
(
cipher
,
EVP_CIPH_VARIABLE_LENGTH
)
||
!
EVP_CIPHER_meth_set_init
(
cipher
,
test_rc4_init_key
)
||
!
EVP_CIPHER_meth_set_do_cipher
(
cipher
,
test_rc4_cipher
)
||
!
EVP_CIPHER_meth_set_impl_ctx_size
(
cipher
,
sizeof
(
TEST_RC4_KEY
)))
{
EVP_CIPHER_meth_free
(
cipher
);
cipher
=
NULL
;
}
r4_40_cipher
=
cipher
;
}
return
r4_40_cipher
;
}
static
void
test_r4_40_cipher_destroy
(
void
)
{
EVP_CIPHER_meth_free
(
r4_40_cipher
);
r4_40_cipher
=
NULL
;
}
static
int
test_cipher_nids
(
const
int
**
nids
)
{
static
int
cipher_nids
[
4
]
=
{
0
,
0
,
0
};
static
int
pos
=
0
;
static
int
init
=
0
;
if
(
!
init
)
{
const
EVP_CIPHER
*
cipher
;
if
((
cipher
=
test_r4_cipher
())
!=
NULL
)
cipher_nids
[
pos
++
]
=
EVP_CIPHER_nid
(
cipher
);
if
((
cipher
=
test_r4_40_cipher
())
!=
NULL
)
cipher_nids
[
pos
++
]
=
EVP_CIPHER_nid
(
cipher
);
cipher_nids
[
pos
]
=
0
;
init
=
1
;
}
*
nids
=
cipher_nids
;
return
pos
;
}
static
int
openssl_ciphers
(
ENGINE
*
e
,
const
EVP_CIPHER
**
cipher
,
static
int
openssl_ciphers
(
ENGINE
*
e
,
const
EVP_CIPHER
**
cipher
,
const
int
**
nids
,
int
nid
)
const
int
**
nids
,
int
nid
)
{
{
if
(
!
cipher
)
{
if
(
!
cipher
)
{
/* We are returning a list of supported nids */
/* We are returning a list of supported nids */
*
nids
=
test_cipher_nids
;
return
test_cipher_nids
(
nids
);
return
test_cipher_nids_number
;
}
}
/* We are being asked for a specific cipher */
/* We are being asked for a specific cipher */
if
(
nid
==
NID_rc4
)
if
(
nid
==
NID_rc4
)
*
cipher
=
&
test_r4_cipher
;
*
cipher
=
test_r4_cipher
()
;
else
if
(
nid
==
NID_rc4_40
)
else
if
(
nid
==
NID_rc4_40
)
*
cipher
=
&
test_r4_40_cipher
;
*
cipher
=
test_r4_40_cipher
()
;
else
{
else
{
# ifdef TEST_ENG_OPENSSL_RC4_OTHERS
# ifdef TEST_ENG_OPENSSL_RC4_OTHERS
fprintf
(
stderr
,
"(TEST_ENG_OPENSSL_RC4) returning NULL for "
fprintf
(
stderr
,
"(TEST_ENG_OPENSSL_RC4) returning NULL for "
...
@@ -648,6 +684,8 @@ static int ossl_pkey_meths(ENGINE *e, EVP_PKEY_METHOD **pmeth,
...
@@ -648,6 +684,8 @@ static int ossl_pkey_meths(ENGINE *e, EVP_PKEY_METHOD **pmeth,
int
openssl_destroy
(
ENGINE
*
e
)
int
openssl_destroy
(
ENGINE
*
e
)
{
{
test_sha_md_destroy
();
test_sha_md_destroy
();
test_r4_cipher_destroy
();
test_r4_40_cipher_destroy
();
return
1
;
return
1
;
}
}
engines/ccgost/gost_crypt.c
浏览文件 @
39e8d0ce
...
@@ -12,6 +12,7 @@
...
@@ -12,6 +12,7 @@
#include <openssl/rand.h>
#include <openssl/rand.h>
#include "e_gost_err.h"
#include "e_gost_err.h"
#include "gost_lcl.h"
#include "gost_lcl.h"
#include <openssl/evp.h>
#if !defined(CCGOST_DEBUG) && !defined(DEBUG)
#if !defined(CCGOST_DEBUG) && !defined(DEBUG)
# ifndef NDEBUG
# ifndef NDEBUG
...
@@ -38,39 +39,75 @@ static int gost89_get_asn1_parameters(EVP_CIPHER_CTX *ctx, ASN1_TYPE *params);
...
@@ -38,39 +39,75 @@ static int gost89_get_asn1_parameters(EVP_CIPHER_CTX *ctx, ASN1_TYPE *params);
/* Control function */
/* Control function */
static
int
gost_cipher_ctl
(
EVP_CIPHER_CTX
*
ctx
,
int
type
,
int
arg
,
void
*
ptr
);
static
int
gost_cipher_ctl
(
EVP_CIPHER_CTX
*
ctx
,
int
type
,
int
arg
,
void
*
ptr
);
EVP_CIPHER
cipher_gost
=
{
static
EVP_CIPHER
*
_hidden_Gost28147_89_cipher
=
NULL
;
NID_id_Gost28147_89
,
const
EVP_CIPHER
*
cipher_gost
(
void
)
1
,
/* block_size */
{
32
,
/* key_size */
if
(
_hidden_Gost28147_89_cipher
==
NULL
8
,
/* iv_len */
&&
((
_hidden_Gost28147_89_cipher
=
EVP_CIPH_CFB_MODE
|
EVP_CIPH_NO_PADDING
|
EVP_CIPHER_meth_new
(
NID_id_Gost28147_89
,
EVP_CIPH_CUSTOM_IV
|
EVP_CIPH_RAND_KEY
|
EVP_CIPH_ALWAYS_CALL_INIT
,
1
/* block_size */
,
gost_cipher_init
,
32
/* key_size */
))
==
NULL
gost_cipher_do_cfb
,
||
!
EVP_CIPHER_meth_set_iv_length
(
_hidden_Gost28147_89_cipher
,
8
)
gost_cipher_cleanup
,
||
!
EVP_CIPHER_meth_set_flags
(
_hidden_Gost28147_89_cipher
,
sizeof
(
struct
ossl_gost_cipher_ctx
),
/* ctx_size */
EVP_CIPH_CFB_MODE
|
gost89_set_asn1_parameters
,
EVP_CIPH_NO_PADDING
|
gost89_get_asn1_parameters
,
EVP_CIPH_CUSTOM_IV
|
gost_cipher_ctl
,
EVP_CIPH_RAND_KEY
|
NULL
,
EVP_CIPH_ALWAYS_CALL_INIT
)
};
||
!
EVP_CIPHER_meth_set_init
(
_hidden_Gost28147_89_cipher
,
gost_cipher_init
)
||
!
EVP_CIPHER_meth_set_do_cipher
(
_hidden_Gost28147_89_cipher
,
gost_cipher_do_cfb
)
||
!
EVP_CIPHER_meth_set_cleanup
(
_hidden_Gost28147_89_cipher
,
gost_cipher_cleanup
)
||
!
EVP_CIPHER_meth_set_impl_ctx_size
(
_hidden_Gost28147_89_cipher
,
sizeof
(
struct
ossl_gost_cipher_ctx
))
||
!
EVP_CIPHER_meth_set_set_asn1_params
(
_hidden_Gost28147_89_cipher
,
gost89_set_asn1_parameters
)
||
!
EVP_CIPHER_meth_set_get_asn1_params
(
_hidden_Gost28147_89_cipher
,
gost89_get_asn1_parameters
)
||
!
EVP_CIPHER_meth_set_ctrl
(
_hidden_Gost28147_89_cipher
,
gost_cipher_ctl
)))
{
EVP_CIPHER_meth_free
(
_hidden_Gost28147_89_cipher
);
_hidden_Gost28147_89_cipher
=
NULL
;
}
return
_hidden_Gost28147_89_cipher
;
}
EVP_CIPHER
cipher_gost_cpacnt
=
{
static
EVP_CIPHER
*
_hidden_gost89_cnt
=
NULL
;
NID_gost89_cnt
,
const
EVP_CIPHER
*
cipher_gost_cpacnt
(
void
)
1
,
/* block_size */
{
32
,
/* key_size */
if
(
_hidden_gost89_cnt
==
NULL
8
,
/* iv_len */
&&
((
_hidden_gost89_cnt
=
EVP_CIPH_OFB_MODE
|
EVP_CIPH_NO_PADDING
|
EVP_CIPHER_meth_new
(
NID_gost89_cnt
,
EVP_CIPH_CUSTOM_IV
|
EVP_CIPH_RAND_KEY
|
EVP_CIPH_ALWAYS_CALL_INIT
,
1
/* block_size */
,
gost_cipher_init_cpa
,
32
/* key_size */
))
==
NULL
gost_cipher_do_cnt
,
||
!
EVP_CIPHER_meth_set_iv_length
(
_hidden_gost89_cnt
,
8
)
gost_cipher_cleanup
,
||
!
EVP_CIPHER_meth_set_flags
(
_hidden_gost89_cnt
,
sizeof
(
struct
ossl_gost_cipher_ctx
),
/* ctx_size */
EVP_CIPH_OFB_MODE
|
gost89_set_asn1_parameters
,
EVP_CIPH_NO_PADDING
|
gost89_get_asn1_parameters
,
EVP_CIPH_CUSTOM_IV
|
gost_cipher_ctl
,
EVP_CIPH_RAND_KEY
|
NULL
,
EVP_CIPH_ALWAYS_CALL_INIT
)
};
||
!
EVP_CIPHER_meth_set_init
(
_hidden_gost89_cnt
,
gost_cipher_init_cpa
)
||
!
EVP_CIPHER_meth_set_do_cipher
(
_hidden_gost89_cnt
,
gost_cipher_do_cnt
)
||
!
EVP_CIPHER_meth_set_cleanup
(
_hidden_gost89_cnt
,
gost_cipher_cleanup
)
||
!
EVP_CIPHER_meth_set_impl_ctx_size
(
_hidden_gost89_cnt
,
sizeof
(
struct
ossl_gost_cipher_ctx
))
||
!
EVP_CIPHER_meth_set_set_asn1_params
(
_hidden_gost89_cnt
,
gost89_set_asn1_parameters
)
||
!
EVP_CIPHER_meth_set_get_asn1_params
(
_hidden_gost89_cnt
,
gost89_get_asn1_parameters
)
||
!
EVP_CIPHER_meth_set_ctrl
(
_hidden_gost89_cnt
,
gost_cipher_ctl
)))
{
EVP_CIPHER_meth_free
(
_hidden_gost89_cnt
);
_hidden_gost89_cnt
=
NULL
;
}
return
_hidden_gost89_cnt
;
}
/* Implementation of GOST 28147-89 in MAC (imitovstavka) mode */
/* Implementation of GOST 28147-89 in MAC (imitovstavka) mode */
/* Init functions which set specific parameters */
/* Init functions which set specific parameters */
...
@@ -86,7 +123,7 @@ static int gost_imit_cleanup(EVP_MD_CTX *ctx);
...
@@ -86,7 +123,7 @@ static int gost_imit_cleanup(EVP_MD_CTX *ctx);
static
int
gost_imit_ctrl
(
EVP_MD_CTX
*
ctx
,
int
type
,
int
arg
,
void
*
ptr
);
static
int
gost_imit_ctrl
(
EVP_MD_CTX
*
ctx
,
int
type
,
int
arg
,
void
*
ptr
);
static
EVP_MD
*
_hidden_Gost28147_89_MAC_md
=
NULL
;
static
EVP_MD
*
_hidden_Gost28147_89_MAC_md
=
NULL
;
EVP_MD
*
imit_gost_cpa
(
void
)
const
EVP_MD
*
imit_gost_cpa
(
void
)
{
{
if
(
_hidden_Gost28147_89_MAC_md
==
NULL
)
{
if
(
_hidden_Gost28147_89_MAC_md
==
NULL
)
{
...
...
engines/ccgost/gost_eng.c
浏览文件 @
39e8d0ce
...
@@ -153,8 +153,8 @@ static int bind_gost(ENGINE *e, const char *id)
...
@@ -153,8 +153,8 @@ static int bind_gost(ENGINE *e, const char *id)
||
!
ENGINE_register_digests
(
e
)
||
!
ENGINE_register_digests
(
e
)
||
!
ENGINE_register_pkey_meths
(
e
)
||
!
ENGINE_register_pkey_meths
(
e
)
/* These two actually should go in LIST_ADD command */
/* These two actually should go in LIST_ADD command */
||
!
EVP_add_cipher
(
&
cipher_gost
)
||
!
EVP_add_cipher
(
cipher_gost
()
)
||
!
EVP_add_cipher
(
&
cipher_gost_cpacnt
)
||
!
EVP_add_cipher
(
cipher_gost_cpacnt
()
)
||
!
EVP_add_digest
(
digest_gost
())
||
!
EVP_add_digest
(
digest_gost
())
||
!
EVP_add_digest
(
imit_gost_cpa
())
||
!
EVP_add_digest
(
imit_gost_cpa
())
)
{
)
{
...
@@ -202,9 +202,9 @@ static int gost_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
...
@@ -202,9 +202,9 @@ static int gost_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
}
}
if
(
nid
==
NID_id_Gost28147_89
)
{
if
(
nid
==
NID_id_Gost28147_89
)
{
*
cipher
=
&
cipher_gost
;
*
cipher
=
cipher_gost
()
;
}
else
if
(
nid
==
NID_gost89_cnt
)
{
}
else
if
(
nid
==
NID_gost89_cnt
)
{
*
cipher
=
&
cipher_gost_cpacnt
;
*
cipher
=
cipher_gost_cpacnt
()
;
}
else
{
}
else
{
ok
=
0
;
ok
=
0
;
*
cipher
=
NULL
;
*
cipher
=
NULL
;
...
...
engines/ccgost/gost_lcl.h
浏览文件 @
39e8d0ce
...
@@ -146,7 +146,7 @@ struct ossl_gost_digest_ctx {
...
@@ -146,7 +146,7 @@ struct ossl_gost_digest_ctx {
EVP_MD
*
digest_gost
(
void
);
EVP_MD
*
digest_gost
(
void
);
void
digest_gost_destroy
(
void
);
void
digest_gost_destroy
(
void
);
/* EVP_MD structure for GOST 28147 in MAC mode */
/* EVP_MD structure for GOST 28147 in MAC mode */
EVP_MD
*
imit_gost_cpa
(
void
);
const
EVP_MD
*
imit_gost_cpa
(
void
);
void
imit_gost_cpa_destroy
(
void
);
void
imit_gost_cpa_destroy
(
void
);
/* Cipher context used for EVP_CIPHER operation */
/* Cipher context used for EVP_CIPHER operation */
struct
ossl_gost_cipher_ctx
{
struct
ossl_gost_cipher_ctx
{
...
@@ -176,8 +176,8 @@ extern struct gost_cipher_info gost_cipher_list[];
...
@@ -176,8 +176,8 @@ extern struct gost_cipher_info gost_cipher_list[];
/* Find encryption params from ASN1_OBJECT */
/* Find encryption params from ASN1_OBJECT */
const
struct
gost_cipher_info
*
get_encryption_params
(
ASN1_OBJECT
*
obj
);
const
struct
gost_cipher_info
*
get_encryption_params
(
ASN1_OBJECT
*
obj
);
/* Implementation of GOST 28147-89 cipher in CFB and CNT modes */
/* Implementation of GOST 28147-89 cipher in CFB and CNT modes */
extern
EVP_CIPHER
cipher_gost
;
const
EVP_CIPHER
*
cipher_gost
(
void
)
;
extern
EVP_CIPHER
cipher_gost_cpacnt
;
const
EVP_CIPHER
*
cipher_gost_cpacnt
(
void
)
;
# define EVP_MD_CTRL_KEY_LEN (EVP_MD_CTRL_ALG_CTRL+3)
# define EVP_MD_CTRL_KEY_LEN (EVP_MD_CTRL_ALG_CTRL+3)
# define EVP_MD_CTRL_SET_KEY (EVP_MD_CTRL_ALG_CTRL+4)
# define EVP_MD_CTRL_SET_KEY (EVP_MD_CTRL_ALG_CTRL+4)
/* EVP_PKEY_METHOD key encryption callbacks */
/* EVP_PKEY_METHOD key encryption callbacks */
...
...
engines/e_ossltest.c
浏览文件 @
39e8d0ce
...
@@ -279,19 +279,33 @@ int ossltest_aes128_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
...
@@ -279,19 +279,33 @@ int ossltest_aes128_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
int
ossltest_aes128_cbc_cipher
(
EVP_CIPHER_CTX
*
ctx
,
unsigned
char
*
out
,
int
ossltest_aes128_cbc_cipher
(
EVP_CIPHER_CTX
*
ctx
,
unsigned
char
*
out
,
const
unsigned
char
*
in
,
size_t
inl
);
const
unsigned
char
*
in
,
size_t
inl
);
static
const
EVP_CIPHER
ossltest_aes_128_cbc
=
{
\
static
EVP_CIPHER
*
_hidden_aes_128_cbc
=
NULL
;
NID_aes_128_cbc
,
static
const
EVP_CIPHER
*
ossltest_aes_128_cbc
(
void
)
16
,
/* block size */
{
16
,
/* key len */
if
(
_hidden_aes_128_cbc
==
NULL
16
,
/* iv len */
&&
((
_hidden_aes_128_cbc
=
EVP_CIPHER_meth_new
(
NID_aes_128_cbc
,
EVP_CIPH_FLAG_DEFAULT_ASN1
|
EVP_CIPH_CBC_MODE
,
16
/* block size */
,
ossltest_aes128_init_key
,
16
/* key len */
))
==
NULL
ossltest_aes128_cbc_cipher
,
||
!
EVP_CIPHER_meth_set_iv_length
(
_hidden_aes_128_cbc
,
16
)
NULL
,
/* FIXME: when EVP_CIPHER goes opaque, this should be set to EVP_aes_128_cbc()->ctx_size */
||
!
EVP_CIPHER_meth_set_flags
(
_hidden_aes_128_cbc
,
0
,
/* We don't know the size of cipher_data at compile time */
EVP_CIPH_FLAG_DEFAULT_ASN1
NULL
,
NULL
,
NULL
,
NULL
|
EVP_CIPH_CBC_MODE
)
};
||
!
EVP_CIPHER_meth_set_init
(
_hidden_aes_128_cbc
,
ossltest_aes128_init_key
)
||
!
EVP_CIPHER_meth_set_do_cipher
(
_hidden_aes_128_cbc
,
ossltest_aes128_cbc_cipher
)
||
!
EVP_CIPHER_meth_set_impl_ctx_size
(
_hidden_aes_128_cbc
,
EVP_CIPHER_impl_ctx_size
(
EVP_aes_128_cbc
()))))
{
EVP_CIPHER_meth_free
(
_hidden_aes_128_cbc
);
_hidden_aes_128_cbc
=
NULL
;
}
return
_hidden_aes_128_cbc
;
}
static
void
destroy_ciphers
(
void
)
{
EVP_CIPHER_meth_free
(
_hidden_aes_128_cbc
);
_hidden_aes_128_cbc
=
NULL
;
}
static
int
bind_ossltest
(
ENGINE
*
e
)
static
int
bind_ossltest
(
ENGINE
*
e
)
{
{
...
@@ -365,6 +379,7 @@ static int ossltest_finish(ENGINE *e)
...
@@ -365,6 +379,7 @@ static int ossltest_finish(ENGINE *e)
static
int
ossltest_destroy
(
ENGINE
*
e
)
static
int
ossltest_destroy
(
ENGINE
*
e
)
{
{
destroy_digests
();
destroy_digests
();
destroy_ciphers
();
ERR_unload_OSSLTEST_strings
();
ERR_unload_OSSLTEST_strings
();
return
1
;
return
1
;
}
}
...
@@ -415,7 +430,7 @@ static int ossltest_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
...
@@ -415,7 +430,7 @@ static int ossltest_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
/* We are being asked for a specific cipher */
/* We are being asked for a specific cipher */
switch
(
nid
)
{
switch
(
nid
)
{
case
NID_aes_128_cbc
:
case
NID_aes_128_cbc
:
*
cipher
=
&
ossltest_aes_128_cbc
;
*
cipher
=
ossltest_aes_128_cbc
()
;
break
;
break
;
default:
default:
ok
=
0
;
ok
=
0
;
...
@@ -569,21 +584,7 @@ static int digest_sha512_final(EVP_MD_CTX *ctx, unsigned char *md)
...
@@ -569,21 +584,7 @@ static int digest_sha512_final(EVP_MD_CTX *ctx, unsigned char *md)
int
ossltest_aes128_init_key
(
EVP_CIPHER_CTX
*
ctx
,
const
unsigned
char
*
key
,
int
ossltest_aes128_init_key
(
EVP_CIPHER_CTX
*
ctx
,
const
unsigned
char
*
key
,
const
unsigned
char
*
iv
,
int
enc
)
const
unsigned
char
*
iv
,
int
enc
)
{
{
if
(
EVP_CIPHER_CTX_cipher_data
(
ctx
)
==
NULL
)
{
return
EVP_CIPHER_meth_get_init
(
EVP_aes_128_cbc
())
(
ctx
,
key
,
iv
,
enc
);
/*
* Normally cipher_data is allocated automatically for an engine but
* we don't know the ctx_size as compile time so we have to do it at
* run time
*/
/* FIXME: when EVP_CIPHER goes opaque, we won't need this trickery any more */
EVP_CIPHER_CTX_new_cipher_data
(
ctx
,
EVP_aes_128_cbc
()
->
ctx_size
);
if
(
EVP_CIPHER_CTX_cipher_data
(
ctx
)
==
NULL
)
{
OSSLTESTerr
(
OSSLTEST_F_OSSLTEST_AES128_INIT_KEY
,
ERR_R_MALLOC_FAILURE
);
return
0
;
}
}
return
EVP_aes_128_cbc
()
->
init
(
ctx
,
key
,
iv
,
enc
);
}
}
int
ossltest_aes128_cbc_cipher
(
EVP_CIPHER_CTX
*
ctx
,
unsigned
char
*
out
,
int
ossltest_aes128_cbc_cipher
(
EVP_CIPHER_CTX
*
ctx
,
unsigned
char
*
out
,
...
@@ -600,7 +601,7 @@ int ossltest_aes128_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
...
@@ -600,7 +601,7 @@ int ossltest_aes128_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
memcpy
(
tmpbuf
,
in
,
inl
);
memcpy
(
tmpbuf
,
in
,
inl
);
/* Go through the motions of encrypting it */
/* Go through the motions of encrypting it */
ret
=
EVP_
aes_128_cbc
()
->
do_cipher
(
ctx
,
out
,
in
,
inl
);
ret
=
EVP_
CIPHER_meth_get_do_cipher
(
EVP_aes_128_cbc
())
(
ctx
,
out
,
in
,
inl
);
/* Throw it all away and just use the plaintext as the output */
/* Throw it all away and just use the plaintext as the output */
memcpy
(
out
,
tmpbuf
,
inl
);
memcpy
(
out
,
tmpbuf
,
inl
);
...
...
engines/e_padlock.c
浏览文件 @
39e8d0ce
...
@@ -546,39 +546,51 @@ padlock_ctr_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out_arg,
...
@@ -546,39 +546,51 @@ padlock_ctr_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out_arg,
* of preprocessor magic :-)
* of preprocessor magic :-)
*/
*/
# define DECLARE_AES_EVP(ksize,lmode,umode) \
# define DECLARE_AES_EVP(ksize,lmode,umode) \
static const EVP_CIPHER padlock_aes_##ksize##_##lmode = { \
static EVP_CIPHER *_hidden_aes_##ksize##_##lmode = NULL; \
NID_aes_##ksize##_##lmode, \
static const EVP_CIPHER *padlock_aes_##ksize##_##lmode(void) \
EVP_CIPHER_block_size_##umode, \
{ \
AES_KEY_SIZE_##ksize, \
if (_hidden_aes_##ksize##_##lmode == NULL \
AES_BLOCK_SIZE, \
&& ((_hidden_aes_##ksize##_##lmode = \
0 | EVP_CIPH_##umode##_MODE, \
EVP_CIPHER_meth_new(NID_aes_##ksize##_##lmode, \
padlock_aes_init_key, \
EVP_CIPHER_block_size_##umode, \
padlock_##lmode##_cipher, \
AES_KEY_SIZE_##ksize)) == NULL \
NULL, \
|| !EVP_CIPHER_meth_set_iv_length(_hidden_aes_##ksize##_##lmode, \
sizeof(struct padlock_cipher_data) + 16, \
AES_BLOCK_SIZE) \
EVP_CIPHER_set_asn1_iv, \
|| !EVP_CIPHER_meth_set_flags(_hidden_aes_##ksize##_##lmode, \
EVP_CIPHER_get_asn1_iv, \
0 | EVP_CIPH_##umode##_MODE) \
NULL, \
|| !EVP_CIPHER_meth_set_init(_hidden_aes_##ksize##_##lmode, \
NULL \
padlock_aes_init_key) \
|| !EVP_CIPHER_meth_set_do_cipher(_hidden_aes_##ksize##_##lmode, \
padlock_##lmode##_cipher) \
|| !EVP_CIPHER_meth_set_impl_ctx_size(_hidden_aes_##ksize##_##lmode, \
sizeof(struct padlock_cipher_data) + 16) \
|| !EVP_CIPHER_meth_set_set_asn1_params(_hidden_aes_##ksize##_##lmode, \
EVP_CIPHER_set_asn1_iv) \
|| !EVP_CIPHER_meth_set_get_asn1_params(_hidden_aes_##ksize##_##lmode, \
EVP_CIPHER_get_asn1_iv))) { \
EVP_CIPHER_meth_free(_hidden_aes_##ksize##_##lmode); \
_hidden_aes_##ksize##_##lmode = NULL; \
} \
return _hidden_aes_##ksize##_##lmode; \
}
}
DECLARE_AES_EVP
(
128
,
ecb
,
ECB
)
;
DECLARE_AES_EVP
(
128
,
ecb
,
ECB
)
DECLARE_AES_EVP
(
128
,
cbc
,
CBC
)
;
DECLARE_AES_EVP
(
128
,
cbc
,
CBC
)
DECLARE_AES_EVP
(
128
,
cfb
,
CFB
)
;
DECLARE_AES_EVP
(
128
,
cfb
,
CFB
)
DECLARE_AES_EVP
(
128
,
ofb
,
OFB
)
;
DECLARE_AES_EVP
(
128
,
ofb
,
OFB
)
DECLARE_AES_EVP
(
128
,
ctr
,
CTR
)
;
DECLARE_AES_EVP
(
128
,
ctr
,
CTR
)
DECLARE_AES_EVP
(
192
,
ecb
,
ECB
)
;
DECLARE_AES_EVP
(
192
,
ecb
,
ECB
)
DECLARE_AES_EVP
(
192
,
cbc
,
CBC
)
;
DECLARE_AES_EVP
(
192
,
cbc
,
CBC
)
DECLARE_AES_EVP
(
192
,
cfb
,
CFB
)
;
DECLARE_AES_EVP
(
192
,
cfb
,
CFB
)
DECLARE_AES_EVP
(
192
,
ofb
,
OFB
)
;
DECLARE_AES_EVP
(
192
,
ofb
,
OFB
)
DECLARE_AES_EVP
(
192
,
ctr
,
CTR
)
;
DECLARE_AES_EVP
(
192
,
ctr
,
CTR
)
DECLARE_AES_EVP
(
256
,
ecb
,
ECB
)
;
DECLARE_AES_EVP
(
256
,
ecb
,
ECB
)
DECLARE_AES_EVP
(
256
,
cbc
,
CBC
)
;
DECLARE_AES_EVP
(
256
,
cbc
,
CBC
)
DECLARE_AES_EVP
(
256
,
cfb
,
CFB
)
;
DECLARE_AES_EVP
(
256
,
cfb
,
CFB
)
DECLARE_AES_EVP
(
256
,
ofb
,
OFB
)
;
DECLARE_AES_EVP
(
256
,
ofb
,
OFB
)
DECLARE_AES_EVP
(
256
,
ctr
,
CTR
)
;
DECLARE_AES_EVP
(
256
,
ctr
,
CTR
)
static
int
static
int
padlock_ciphers
(
ENGINE
*
e
,
const
EVP_CIPHER
**
cipher
,
const
int
**
nids
,
padlock_ciphers
(
ENGINE
*
e
,
const
EVP_CIPHER
**
cipher
,
const
int
**
nids
,
...
@@ -593,51 +605,51 @@ padlock_ciphers(ENGINE *e, const EVP_CIPHER **cipher, const int **nids,
...
@@ -593,51 +605,51 @@ padlock_ciphers(ENGINE *e, const EVP_CIPHER **cipher, const int **nids,
/* ... or the requested "cipher" otherwise */
/* ... or the requested "cipher" otherwise */
switch
(
nid
)
{
switch
(
nid
)
{
case
NID_aes_128_ecb
:
case
NID_aes_128_ecb
:
*
cipher
=
&
padlock_aes_128_ecb
;
*
cipher
=
padlock_aes_128_ecb
()
;
break
;
break
;
case
NID_aes_128_cbc
:
case
NID_aes_128_cbc
:
*
cipher
=
&
padlock_aes_128_cbc
;
*
cipher
=
padlock_aes_128_cbc
()
;
break
;
break
;
case
NID_aes_128_cfb
:
case
NID_aes_128_cfb
:
*
cipher
=
&
padlock_aes_128_cfb
;
*
cipher
=
padlock_aes_128_cfb
()
;
break
;
break
;
case
NID_aes_128_ofb
:
case
NID_aes_128_ofb
:
*
cipher
=
&
padlock_aes_128_ofb
;
*
cipher
=
padlock_aes_128_ofb
()
;
break
;
break
;
case
NID_aes_128_ctr
:
case
NID_aes_128_ctr
:
*
cipher
=
&
padlock_aes_128_ctr
;
*
cipher
=
padlock_aes_128_ctr
()
;
break
;
break
;
case
NID_aes_192_ecb
:
case
NID_aes_192_ecb
:
*
cipher
=
&
padlock_aes_192_ecb
;
*
cipher
=
padlock_aes_192_ecb
()
;
break
;
break
;
case
NID_aes_192_cbc
:
case
NID_aes_192_cbc
:
*
cipher
=
&
padlock_aes_192_cbc
;
*
cipher
=
padlock_aes_192_cbc
()
;
break
;
break
;
case
NID_aes_192_cfb
:
case
NID_aes_192_cfb
:
*
cipher
=
&
padlock_aes_192_cfb
;
*
cipher
=
padlock_aes_192_cfb
()
;
break
;
break
;
case
NID_aes_192_ofb
:
case
NID_aes_192_ofb
:
*
cipher
=
&
padlock_aes_192_ofb
;
*
cipher
=
padlock_aes_192_ofb
()
;
break
;
break
;
case
NID_aes_192_ctr
:
case
NID_aes_192_ctr
:
*
cipher
=
&
padlock_aes_192_ctr
;
*
cipher
=
padlock_aes_192_ctr
()
;
break
;
break
;
case
NID_aes_256_ecb
:
case
NID_aes_256_ecb
:
*
cipher
=
&
padlock_aes_256_ecb
;
*
cipher
=
padlock_aes_256_ecb
()
;
break
;
break
;
case
NID_aes_256_cbc
:
case
NID_aes_256_cbc
:
*
cipher
=
&
padlock_aes_256_cbc
;
*
cipher
=
padlock_aes_256_cbc
()
;
break
;
break
;
case
NID_aes_256_cfb
:
case
NID_aes_256_cfb
:
*
cipher
=
&
padlock_aes_256_cfb
;
*
cipher
=
padlock_aes_256_cfb
()
;
break
;
break
;
case
NID_aes_256_ofb
:
case
NID_aes_256_ofb
:
*
cipher
=
&
padlock_aes_256_ofb
;
*
cipher
=
padlock_aes_256_ofb
()
;
break
;
break
;
case
NID_aes_256_ctr
:
case
NID_aes_256_ctr
:
*
cipher
=
&
padlock_aes_256_ctr
;
*
cipher
=
padlock_aes_256_ctr
()
;
break
;
break
;
default:
default:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录