Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
linux
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
linux
Commits
6c1e4919
Commit
6c1e4919
authored
Oct 24, 2002
by
James Morris
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[CRYPTO]: Use kmod to try to autoload modules.
parent
cd74bb13
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
138 additions
and
84 deletions
+138
-84
crypto/Makefile
crypto/Makefile
+1
-0
crypto/api.c
crypto/api.c
+78
-74
crypto/autoload.c
crypto/autoload.c
+44
-0
crypto/internal.h
crypto/internal.h
+4
-0
include/linux/crypto.h
include/linux/crypto.h
+11
-10
No files found.
crypto/Makefile
View file @
6c1e4919
...
...
@@ -5,6 +5,7 @@
export-objs
:=
api.o
obj-$(CONFIG_CRYPTO)
+=
api.o cipher.o digest.o compress.o
obj-$(CONFIG_KMOD)
+=
autoload.o
obj-$(CONFIG_CRYPTO_MD5)
+=
md5.o
obj-$(CONFIG_CRYPTO_SHA1)
+=
sha1.o
...
...
crypto/api.c
View file @
6c1e4919
...
...
@@ -25,76 +25,6 @@
static
LIST_HEAD
(
crypto_alg_list
);
static
struct
rw_semaphore
crypto_alg_sem
;
static
void
*
c_start
(
struct
seq_file
*
m
,
loff_t
*
pos
)
{
struct
list_head
*
v
;
loff_t
n
=
*
pos
;
down_read
(
&
crypto_alg_sem
);
list_for_each
(
v
,
&
crypto_alg_list
)
if
(
!
n
--
)
return
list_entry
(
v
,
struct
crypto_alg
,
cra_list
);
return
NULL
;
}
static
void
*
c_next
(
struct
seq_file
*
m
,
void
*
p
,
loff_t
*
pos
)
{
struct
list_head
*
v
=
p
;
(
*
pos
)
++
;
v
=
v
->
next
;
return
(
v
==
&
crypto_alg_list
)
?
NULL
:
list_entry
(
v
,
struct
crypto_alg
,
cra_list
);
}
static
void
c_stop
(
struct
seq_file
*
m
,
void
*
p
)
{
up_read
(
&
crypto_alg_sem
);
}
static
int
c_show
(
struct
seq_file
*
m
,
void
*
p
)
{
struct
crypto_alg
*
alg
=
(
struct
crypto_alg
*
)
p
;
seq_printf
(
m
,
"name : %s
\n
"
,
alg
->
cra_name
);
seq_printf
(
m
,
"id : 0x%08x
\n
"
,
alg
->
cra_id
);
seq_printf
(
m
,
"blocksize : %Zd
\n
"
,
alg
->
cra_blocksize
);
switch
(
alg
->
cra_id
&
CRYPTO_TYPE_MASK
)
{
case
CRYPTO_TYPE_CIPHER
:
seq_printf
(
m
,
"keysize : %Zd
\n
"
,
alg
->
cra_cipher
.
cia_keysize
);
seq_printf
(
m
,
"ivsize : %Zd
\n
"
,
alg
->
cra_cipher
.
cia_ivsize
);
break
;
case
CRYPTO_TYPE_DIGEST
:
seq_printf
(
m
,
"digestsize : %Zd
\n
"
,
alg
->
cra_digest
.
dia_digestsize
);
break
;
}
seq_putc
(
m
,
'\n'
);
return
0
;
}
static
struct
seq_operations
crypto_seq_ops
=
{
.
start
=
c_start
,
.
next
=
c_next
,
.
stop
=
c_stop
,
.
show
=
c_show
};
static
int
crypto_info_open
(
struct
inode
*
inode
,
struct
file
*
file
)
{
return
seq_open
(
file
,
&
crypto_seq_ops
);
}
struct
file_operations
proc_crypto_ops
=
{
.
open
=
crypto_info_open
,
.
read
=
seq_read
,
.
llseek
=
seq_lseek
,
.
release
=
seq_release
};
static
inline
int
crypto_alg_get
(
struct
crypto_alg
*
alg
)
{
if
(
alg
->
cra_module
)
...
...
@@ -105,6 +35,7 @@ static inline int crypto_alg_get(struct crypto_alg *alg)
static
inline
void
crypto_alg_put
(
struct
crypto_alg
*
alg
)
{
if
(
alg
->
cra_module
)
__MOD_DEC_USE_COUNT
(
alg
->
cra_module
);
}
...
...
@@ -149,15 +80,18 @@ static void crypto_init_ops(struct crypto_tfm *tfm)
}
}
/*
* Todo: try and load the module if the lookup fails.
*/
struct
crypto_tfm
*
crypto_alloc_tfm
(
u32
id
)
{
struct
crypto_tfm
*
tfm
=
NULL
;
struct
crypto_alg
*
alg
;
alg
=
crypto_alg_lookup
(
id
&
CRYPTO_ALG_MASK
);
#ifdef CONFIG_KMOD
if
(
alg
==
NULL
)
{
crypto_alg_autoload
(
id
&
CRYPTO_ALG_MASK
);
alg
=
crypto_alg_lookup
(
id
&
CRYPTO_ALG_MASK
);
}
#endif
if
(
alg
==
NULL
)
goto
out
;
...
...
@@ -251,6 +185,76 @@ int crypto_unregister_alg(struct crypto_alg *alg)
return
ret
;
}
static
void
*
c_start
(
struct
seq_file
*
m
,
loff_t
*
pos
)
{
struct
list_head
*
v
;
loff_t
n
=
*
pos
;
down_read
(
&
crypto_alg_sem
);
list_for_each
(
v
,
&
crypto_alg_list
)
if
(
!
n
--
)
return
list_entry
(
v
,
struct
crypto_alg
,
cra_list
);
return
NULL
;
}
static
void
*
c_next
(
struct
seq_file
*
m
,
void
*
p
,
loff_t
*
pos
)
{
struct
list_head
*
v
=
p
;
(
*
pos
)
++
;
v
=
v
->
next
;
return
(
v
==
&
crypto_alg_list
)
?
NULL
:
list_entry
(
v
,
struct
crypto_alg
,
cra_list
);
}
static
void
c_stop
(
struct
seq_file
*
m
,
void
*
p
)
{
up_read
(
&
crypto_alg_sem
);
}
static
int
c_show
(
struct
seq_file
*
m
,
void
*
p
)
{
struct
crypto_alg
*
alg
=
(
struct
crypto_alg
*
)
p
;
seq_printf
(
m
,
"name : %s
\n
"
,
alg
->
cra_name
);
seq_printf
(
m
,
"id : 0x%08x
\n
"
,
alg
->
cra_id
);
seq_printf
(
m
,
"blocksize : %Zd
\n
"
,
alg
->
cra_blocksize
);
switch
(
alg
->
cra_id
&
CRYPTO_TYPE_MASK
)
{
case
CRYPTO_TYPE_CIPHER
:
seq_printf
(
m
,
"keysize : %Zd
\n
"
,
alg
->
cra_cipher
.
cia_keysize
);
seq_printf
(
m
,
"ivsize : %Zd
\n
"
,
alg
->
cra_cipher
.
cia_ivsize
);
break
;
case
CRYPTO_TYPE_DIGEST
:
seq_printf
(
m
,
"digestsize : %Zd
\n
"
,
alg
->
cra_digest
.
dia_digestsize
);
break
;
}
seq_putc
(
m
,
'\n'
);
return
0
;
}
static
struct
seq_operations
crypto_seq_ops
=
{
.
start
=
c_start
,
.
next
=
c_next
,
.
stop
=
c_stop
,
.
show
=
c_show
};
static
int
crypto_info_open
(
struct
inode
*
inode
,
struct
file
*
file
)
{
return
seq_open
(
file
,
&
crypto_seq_ops
);
}
struct
file_operations
proc_crypto_ops
=
{
.
open
=
crypto_info_open
,
.
read
=
seq_read
,
.
llseek
=
seq_lseek
,
.
release
=
seq_release
};
static
int
__init
init_crypto
(
void
)
{
struct
proc_dir_entry
*
proc
;
...
...
crypto/autoload.c
0 → 100644
View file @
6c1e4919
/*
* Cryptographic API.
*
* Algorithm autoloader.
*
* Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
*/
#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/list.h>
#include <linux/string.h>
#include <linux/kmod.h>
#include <linux/crypto.h>
#include "internal.h"
static
struct
{
u32
algid
;
char
*
name
;
}
alg_modmap
[]
=
{
{
CRYPTO_ALG_DES
,
"des"
},
{
CRYPTO_ALG_DES3_EDE
,
"des"
},
{
CRYPTO_ALG_MD5
,
"md5"
},
{
CRYPTO_ALG_SHA1
,
"sha1"
},
};
#define ALG_MAX_MODMAP 4
void
crypto_alg_autoload
(
u32
algid
)
{
int
i
;
for
(
i
=
0
;
i
<
ALG_MAX_MODMAP
;
i
++
)
{
if
((
alg_modmap
[
i
].
algid
&
CRYPTO_ALG_MASK
)
==
algid
)
{
request_module
(
alg_modmap
[
i
].
name
);
break
;
}
}
return
;
}
crypto/internal.h
View file @
6c1e4919
...
...
@@ -46,6 +46,10 @@ static inline void crypto_yield(struct crypto_tfm *tfm)
cond_resched
();
}
#ifdef CONFIG_KMOD
void
crypto_alg_autoload
(
u32
algid
);
#endif
void
crypto_init_digest_ops
(
struct
crypto_tfm
*
tfm
);
void
crypto_init_cipher_ops
(
struct
crypto_tfm
*
tfm
);
void
crypto_init_compress_ops
(
struct
crypto_tfm
*
tfm
);
...
...
include/linux/crypto.h
View file @
6c1e4919
...
...
@@ -37,28 +37,29 @@
#define CRYPTO_MODE_MASK 0x0ff00000
#define CRYPTO_ALG_MASK 0x000fffff
#define CRYPTO_TYPE_CIPHER 0x
0
0000000
#define CRYPTO_TYPE_DIGEST 0x
1
0000000
#define CRYPTO_TYPE_COMP 0x
2
0000000
#define CRYPTO_TYPE_CIPHER 0x
1
0000000
#define CRYPTO_TYPE_DIGEST 0x
2
0000000
#define CRYPTO_TYPE_COMP 0x
4
0000000
#define CRYPTO_MODE_ECB 0x00
0
00000
#define CRYPTO_MODE_CBC 0x00
1
00000
#define CRYPTO_MODE_CFB 0x00
2
00000
#define CRYPTO_MODE_CTR 0x00
4
00000
#define CRYPTO_MODE_ECB 0x00
1
00000
#define CRYPTO_MODE_CBC 0x00
2
00000
#define CRYPTO_MODE_CFB 0x00
4
00000
#define CRYPTO_MODE_CTR 0x00
8
00000
#define CRYPTO_ALG_NULL 0x0000000
0
#define CRYPTO_ALG_NULL 0x0000000
1
#define CRYPTO_ALG_DES (0x0000000
1
|CRYPTO_TYPE_CIPHER)
#define CRYPTO_ALG_DES (0x0000000
2
|CRYPTO_TYPE_CIPHER)
#define CRYPTO_ALG_DES_ECB (CRYPTO_ALG_DES|CRYPTO_MODE_ECB)
#define CRYPTO_ALG_DES_CBC (CRYPTO_ALG_DES|CRYPTO_MODE_CBC)
#define CRYPTO_ALG_DES3_EDE (0x0000000
2
|CRYPTO_TYPE_CIPHER)
#define CRYPTO_ALG_DES3_EDE (0x0000000
3
|CRYPTO_TYPE_CIPHER)
#define CRYPTO_ALG_DES3_EDE_ECB (CRYPTO_ALG_DES3_EDE|CRYPTO_MODE_ECB)
#define CRYPTO_ALG_DES3_EDE_CBC (CRYPTO_ALG_DES3_EDE|CRYPTO_MODE_CBC)
#define CRYPTO_ALG_MD5 (0x00000f00|CRYPTO_TYPE_DIGEST)
#define CRYPTO_ALG_SHA1 (0x00000f01|CRYPTO_TYPE_DIGEST)
#define CRYPTO_UNSPEC 0
#define CRYPTO_MAX_ALG_NAME 64
#define CRYPTO_MAX_BLOCK_SIZE 16
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment