Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Openssl
提交
35e33f0e
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,发现更多精彩内容 >>
提交
35e33f0e
编写于
8月 26, 2001
作者:
B
Ben Laurie
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add digests.
上级
a844e27b
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
144 addition
and
12 deletion
+144
-12
crypto/evp/openbsd_hw.c
crypto/evp/openbsd_hw.c
+144
-12
未找到文件。
crypto/evp/openbsd_hw.c
浏览文件 @
35e33f0e
...
...
@@ -57,6 +57,7 @@
#include <unistd.h>
#include <openssl/evp.h>
#include <openssl/objects.h>
#include <openssl/rsa.h>
#include "evp_locl.h"
#include <assert.h>
...
...
@@ -64,6 +65,9 @@
#define MAX_HW_KEY 24
#define MAX_HW_IV 8
#define MD5_DIGEST_LENGTH 16
#define MD5_CBLOCK 64
static
int
fd
;
static
int
dev_failed
;
...
...
@@ -76,7 +80,7 @@ static void err(const char *str)
fprintf
(
stderr
,
"%s: errno %d
\n
"
,
str
,
errno
);
}
static
int
dev_crypto_init
(
EVP_CIPHER_CTX
*
ctx
)
static
int
dev_crypto_init
(
session_op
*
ses
)
{
if
(
dev_failed
)
return
0
;
...
...
@@ -99,9 +103,8 @@ static int dev_crypto_init(EVP_CIPHER_CTX *ctx)
}
close
(
cryptodev_fd
);
}
assert
(
data
(
ctx
));
memset
(
data
(
ctx
),
'\0'
,
sizeof
*
data
(
ctx
));
data
(
ctx
)
->
key
=
OPENSSL_malloc
(
MAX_HW_KEY
);
assert
(
ses
);
memset
(
ses
,
'\0'
,
sizeof
*
ses
);
return
1
;
}
...
...
@@ -117,19 +120,19 @@ static int dev_crypto_cleanup(EVP_CIPHER_CTX *ctx)
return
1
;
}
/* FIXME: there should be some non-fatal way to report we fell back to s/w? */
static
int
dev_crypto_init_key
(
EVP_CIPHER_CTX
*
ctx
,
int
cipher
,
const
unsigned
char
*
key
,
int
klen
)
{
if
(
!
dev_crypto_init
(
ctx
))
if
(
!
dev_crypto_init
(
data
(
ctx
)
))
return
0
;
data
(
ctx
)
->
key
=
OPENSSL_malloc
(
MAX_HW_KEY
);
assert
(
ctx
->
cipher
->
iv_len
<=
MAX_HW_IV
);
memcpy
(
data
(
ctx
)
->
key
,
key
,
klen
);
data
(
ctx
)
->
cipher
=
cipher
;
data
(
ctx
)
->
mac
=
0
;
data
(
ctx
)
->
keylen
=
klen
;
if
(
ioctl
(
fd
,
CIOCGSESSION
,
data
(
ctx
))
==
-
1
)
...
...
@@ -141,12 +144,31 @@ static int dev_crypto_init_key(EVP_CIPHER_CTX *ctx,int cipher,
return
1
;
}
static
int
dev_crypto_init_digest
(
session_op
*
ses
,
int
mac
)
{
if
(
!
dev_crypto_init
(
ses
))
return
0
;
ses
->
mac
=
mac
;
if
(
ioctl
(
fd
,
CIOCGSESSION
,
ses
)
==
-
1
)
{
err
(
"CIOCGSESSION failed"
);
return
0
;
}
printf
(
"Init MAC %d
\n
"
,
ses
->
ses
);
return
1
;
}
static
int
dev_crypto_cipher
(
EVP_CIPHER_CTX
*
ctx
,
unsigned
char
*
out
,
const
unsigned
char
*
in
,
unsigned
int
inl
)
{
struct
crypt_op
cryp
;
unsigned
char
lb
[
MAX_HW_IV
];
if
(
!
inl
)
return
1
;
assert
(
data
(
ctx
));
assert
(
!
dev_failed
);
...
...
@@ -155,7 +177,7 @@ static int dev_crypto_cipher(EVP_CIPHER_CTX *ctx,unsigned char *out,
cryp
.
op
=
ctx
->
encrypt
?
COP_ENCRYPT
:
COP_DECRYPT
;
cryp
.
flags
=
0
;
cryp
.
len
=
inl
;
assert
((
inl
&
ctx
->
cipher
->
block_size
)
==
0
);
assert
((
inl
&
(
ctx
->
cipher
->
block_size
-
1
)
)
==
0
);
cryp
.
src
=
(
caddr_t
)
in
;
cryp
.
dst
=
(
caddr_t
)
out
;
cryp
.
mac
=
0
;
...
...
@@ -165,12 +187,55 @@ static int dev_crypto_cipher(EVP_CIPHER_CTX *ctx,unsigned char *out,
if
(
!
ctx
->
encrypt
)
memcpy
(
lb
,
&
in
[
cryp
.
len
-
ctx
->
cipher
->
iv_len
],
ctx
->
cipher
->
iv_len
);
if
(
ioctl
(
fd
,
CIOCCRYPT
,
&
cryp
)
==
-
1
)
if
(
ioctl
(
fd
,
CIOCCRYPT
,
&
cryp
)
==
-
1
)
{
if
(
errno
==
EINVAL
)
/* buffers are misaligned */
{
unsigned
int
cinl
=
0
;
char
*
cin
=
NULL
;
char
*
cout
=
NULL
;
/* NB: this can only make cinl != inl with stream ciphers */
cinl
=
(
inl
+
3
)
/
4
*
4
;
if
(((
unsigned
long
)
in
&
3
)
||
cinl
!=
inl
)
{
cin
=
OPENSSL_malloc
(
cinl
);
memcpy
(
cin
,
in
,
inl
);
cryp
.
src
=
cin
;
}
if
(((
unsigned
long
)
out
&
3
)
||
cinl
!=
inl
)
{
cout
=
OPENSSL_malloc
(
cinl
);
cryp
.
dst
=
cout
;
}
cryp
.
len
=
cinl
;
if
(
ioctl
(
fd
,
CIOCCRYPT
,
&
cryp
)
==
-
1
)
{
err
(
"CIOCCRYPT(2) failed"
);
printf
(
"src=%p dst=%p
\n
"
,
cryp
.
src
,
cryp
.
dst
);
abort
();
return
0
;
}
if
(
cout
)
{
memcpy
(
out
,
cout
,
inl
);
OPENSSL_free
(
cout
);
}
if
(
cin
)
OPENSSL_free
(
cin
);
}
else
{
err
(
"CIOCCRYPT failed"
);
abort
();
return
0
;
}
}
if
(
ctx
->
encrypt
)
memcpy
(
ctx
->
iv
,
&
out
[
cryp
.
len
-
ctx
->
cipher
->
iv_len
],
ctx
->
cipher
->
iv_len
);
...
...
@@ -216,6 +281,73 @@ static const EVP_CIPHER r4_cipher=
const
EVP_CIPHER
*
EVP_dev_crypto_rc4
(
void
)
{
return
&
r4_cipher
;
}
static
int
dev_crypto_md5_init
(
void
*
md_data
)
{
return
dev_crypto_init_digest
(
md_data
,
CRYPTO_MD5
);
}
static
int
dev_crypto_md5_update
(
void
*
md_data
,
const
void
*
data
,
unsigned
long
len
)
{
struct
crypt_op
cryp
;
session_op
*
ses
=
md_data
;
char
buf
[
MD5_DIGEST_LENGTH
];
printf
(
"update
\n
"
);
memset
(
&
cryp
,
'\0'
,
sizeof
cryp
);
cryp
.
ses
=
ses
->
ses
;
cryp
.
len
=
len
;
cryp
.
src
=
(
caddr_t
)
data
;
cryp
.
dst
=
buf
;
if
(
ioctl
(
fd
,
CIOCCRYPT
,
&
cryp
)
==
-
1
)
{
err
(
"CIOCCRYPT(MAC) failed"
);
abort
();
return
0
;
}
printf
(
"update done
\n
"
);
return
1
;
}
static
int
dev_crypto_md5_final
(
unsigned
char
*
md
,
void
*
md_data
)
{
struct
crypt_op
cryp
;
session_op
*
ses
=
md_data
;
printf
(
"final
\n
"
);
memset
(
&
cryp
,
'\0'
,
sizeof
cryp
);
cryp
.
ses
=
ses
->
ses
;
cryp
.
len
=
0
;
cryp
.
op
=
COP_ENCRYPT
;
/* required to do the MAC rather than check it */
cryp
.
src
=
(
caddr_t
)
md
;
cryp
.
dst
=
(
caddr_t
)
md
;
if
(
ioctl
(
fd
,
CIOCCRYPT
,
&
cryp
)
==
-
1
)
{
err
(
"CIOCCRYPT(MAC,final) failed"
);
abort
();
return
0
;
}
printf
(
"final done
\n
"
);
return
1
;
}
static
const
EVP_MD
md5_md
=
{
NID_md5
,
NID_md5WithRSAEncryption
,
MD5_DIGEST_LENGTH
,
dev_crypto_md5_init
,
dev_crypto_md5_update
,
dev_crypto_md5_final
,
EVP_PKEY_RSA_method
,
MD5_CBLOCK
,
sizeof
(
session_op
),
};
const
EVP_MD
*
EVP_dev_crypto_md5
(
void
)
{
return
&
md5_md
;
}
#else
static
void
*
dummy
=&
dummy
;
#endif
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录