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
Kirill Smelkov
linux
Commits
a5c660e6
Commit
a5c660e6
authored
Oct 23, 2002
by
James Morris
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[CRYPTO]: Add in 3des implementation.
parent
c7f36a27
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
452 additions
and
144 deletions
+452
-144
crypto/Config.help
crypto/Config.help
+1
-1
crypto/Config.in
crypto/Config.in
+1
-1
crypto/des.c
crypto/des.c
+231
-132
crypto/tcrypt.c
crypto/tcrypt.c
+114
-1
crypto/tcrypt.h
crypto/tcrypt.h
+100
-1
include/linux/crypto.h
include/linux/crypto.h
+5
-8
No files found.
crypto/Config.help
View file @
a5c660e6
...
...
@@ -11,7 +11,7 @@ CONFIG_CRYPTO_SHA1
SHA-1 secure hash standard (FIPS 180-1), including HMAC (RFC2104, RFC2404).
CONFIG_CRYPTO_DES
DES cipher algorithm (FIPS 46-2), and
3DES_EDE
.
DES cipher algorithm (FIPS 46-2), and
Triple DES EDE (FIPS 46-3)
.
CONFIG_CRYPTO_TEST
Quick & dirty crypto test module.
...
...
crypto/Config.in
View file @
a5c660e6
...
...
@@ -8,7 +8,7 @@ bool 'Cryptographic API' CONFIG_CRYPTO
if [ "$CONFIG_CRYPTO" = "y" ]; then
tristate ' MD5 digest algorithm' CONFIG_CRYPTO_MD5
tristate ' SHA-1 digest algorithm' CONFIG_CRYPTO_SHA1
tristate ' DES
/3DES
cipher algorithms' CONFIG_CRYPTO_DES
tristate ' DES
and Triple DES EDE
cipher algorithms' CONFIG_CRYPTO_DES
tristate ' Testing module' CONFIG_CRYPTO_TEST
fi
...
...
crypto/des.c
View file @
a5c660e6
/*
* Cryptographic API.
*
* DES &
3DES_
EDE Cipher Algorithms.
* DES &
Triple DES
EDE Cipher Algorithms.
*
* Originally released as descore by Dana L. How <how@isl.stanford.edu>.
* Modified by Raimar Falke <rf13@inf.tu-dresden.de> for the Linux-Kernel.
...
...
@@ -27,11 +27,25 @@
#include <linux/crypto.h>
#define DES_KEY_SIZE 8
#define DES_
KEY_SIZE_WORDS
2
#define DES_
EXPKEY_WORDS 3
2
#define DES_BLOCK_SIZE 8
#define DES3_EDE_KEY_SIZE (3 * DES_KEY_SIZE)
#define DES3_EDE_EXPKEY_WORDS (3 * DES_EXPKEY_WORDS)
#define DES3_EDE_BLOCK_SIZE DES_BLOCK_SIZE
#define ROR(d,c,o) ((d) = (d) >> (c) | (d) << (o))
struct
des_ctx
{
__u8
iv
[
DES_BLOCK_SIZE
];
__u32
expkey
[
DES_EXPKEY_WORDS
];
};
struct
des3_ede_ctx
{
__u8
iv
[
DES_BLOCK_SIZE
];
__u32
expkey
[
DES3_EDE_EXPKEY_WORDS
];
};
const
static
__u32
des_keymap
[]
=
{
0x02080008
,
0x02082000
,
0x00002008
,
0x00000000
,
0x02002000
,
0x00080008
,
0x02080000
,
0x02082008
,
...
...
@@ -263,30 +277,25 @@ const static char parity[] = {
4
,
8
,
8
,
0
,
8
,
0
,
0
,
8
,
8
,
0
,
0
,
8
,
0
,
8
,
8
,
0
,
8
,
5
,
0
,
8
,
0
,
8
,
8
,
0
,
0
,
8
,
8
,
0
,
8
,
0
,
6
,
8
,
};
struct
des_ctx
{
__u8
iv
[
DES_BLOCK_SIZE
];
__u32
keyinfo
[
32
];
};
static
void
des_small_fips_encrypt
(
void
*
ctx
,
__u8
*
dst
,
__u8
*
src
)
static
void
des_small_fips_encrypt
(
__u32
*
expkey
,
__u8
*
dst
,
__u8
*
src
)
{
__u32
*
keyinfo
=
((
struct
des_ctx
*
)
ctx
)
->
keyinfo
;
__u32
x
,
y
,
z
;
x
=
src
[
7
];
x
=
src
[
7
];
x
<<=
8
;
x
|=
src
[
6
];
x
|=
src
[
6
];
x
<<=
8
;
x
|=
src
[
5
];
x
|=
src
[
5
];
x
<<=
8
;
x
|=
src
[
4
];
y
=
src
[
3
];
x
|=
src
[
4
];
y
=
src
[
3
];
y
<<=
8
;
y
|=
src
[
2
];
y
|=
src
[
2
];
y
<<=
8
;
y
|=
src
[
1
];
y
|=
src
[
1
];
y
<<=
8
;
y
|=
src
[
0
];
y
|=
src
[
0
];
z
=
((
x
>>
004
)
^
y
)
&
0x0F0F0F0FL
;
x
^=
z
<<
004
;
y
^=
z
;
...
...
@@ -304,7 +313,7 @@ static void des_small_fips_encrypt(void *ctx, __u8 *dst, __u8 *src)
y
^=
z
;
x
^=
z
;
y
=
y
>>
1
|
y
<<
31
;
z
=
keyinfo
[
0
];
z
=
expkey
[
0
];
z
^=
y
;
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
192
)
+
(
0xFC
&
z
));
z
>>=
8
;
...
...
@@ -313,7 +322,7 @@ static void des_small_fips_encrypt(void *ctx, __u8 *dst, __u8 *src)
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
64
)
+
(
0xFC
&
z
));
z
>>=
8
;
x
^=
*
(
__u32
*
)
((
u8
*
)
des_keymap
+
(
0xFC
&
z
));
z
=
keyinfo
[
1
];
z
=
expkey
[
1
];
z
^=
y
;
z
=
z
<<
4
|
z
>>
28
;
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
448
)
+
(
0xFC
&
z
));
...
...
@@ -323,7 +332,7 @@ static void des_small_fips_encrypt(void *ctx, __u8 *dst, __u8 *src)
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
320
)
+
(
0xFC
&
z
));
z
>>=
8
;
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
256
)
+
(
0xFC
&
z
));
z
=
keyinfo
[
2
];
z
=
expkey
[
2
];
z
^=
x
;
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
192
)
+
(
0xFC
&
z
));
z
>>=
8
;
...
...
@@ -332,7 +341,7 @@ static void des_small_fips_encrypt(void *ctx, __u8 *dst, __u8 *src)
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
64
)
+
(
0xFC
&
z
));
z
>>=
8
;
y
^=
*
(
__u32
*
)
((
u8
*
)
des_keymap
+
(
0xFC
&
z
));
z
=
keyinfo
[
3
];
z
=
expkey
[
3
];
z
^=
x
;
z
=
z
<<
4
|
z
>>
28
;
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
448
)
+
(
0xFC
&
z
));
...
...
@@ -342,7 +351,7 @@ static void des_small_fips_encrypt(void *ctx, __u8 *dst, __u8 *src)
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
320
)
+
(
0xFC
&
z
));
z
>>=
8
;
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
256
)
+
(
0xFC
&
z
));
z
=
keyinfo
[
4
];
z
=
expkey
[
4
];
z
^=
y
;
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
192
)
+
(
0xFC
&
z
));
z
>>=
8
;
...
...
@@ -351,7 +360,7 @@ static void des_small_fips_encrypt(void *ctx, __u8 *dst, __u8 *src)
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
64
)
+
(
0xFC
&
z
));
z
>>=
8
;
x
^=
*
(
__u32
*
)
((
u8
*
)
des_keymap
+
(
0xFC
&
z
));
z
=
keyinfo
[
5
];
z
=
expkey
[
5
];
z
^=
y
;
z
=
z
<<
4
|
z
>>
28
;
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
448
)
+
(
0xFC
&
z
));
...
...
@@ -361,7 +370,7 @@ static void des_small_fips_encrypt(void *ctx, __u8 *dst, __u8 *src)
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
320
)
+
(
0xFC
&
z
));
z
>>=
8
;
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
256
)
+
(
0xFC
&
z
));
z
=
keyinfo
[
6
];
z
=
expkey
[
6
];
z
^=
x
;
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
192
)
+
(
0xFC
&
z
));
z
>>=
8
;
...
...
@@ -370,7 +379,7 @@ static void des_small_fips_encrypt(void *ctx, __u8 *dst, __u8 *src)
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
64
)
+
(
0xFC
&
z
));
z
>>=
8
;
y
^=
*
(
__u32
*
)
((
u8
*
)
des_keymap
+
(
0xFC
&
z
));
z
=
keyinfo
[
7
];
z
=
expkey
[
7
];
z
^=
x
;
z
=
z
<<
4
|
z
>>
28
;
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
448
)
+
(
0xFC
&
z
));
...
...
@@ -380,7 +389,7 @@ static void des_small_fips_encrypt(void *ctx, __u8 *dst, __u8 *src)
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
320
)
+
(
0xFC
&
z
));
z
>>=
8
;
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
256
)
+
(
0xFC
&
z
));
z
=
keyinfo
[
8
];
z
=
expkey
[
8
];
z
^=
y
;
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
192
)
+
(
0xFC
&
z
));
z
>>=
8
;
...
...
@@ -389,7 +398,7 @@ static void des_small_fips_encrypt(void *ctx, __u8 *dst, __u8 *src)
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
64
)
+
(
0xFC
&
z
));
z
>>=
8
;
x
^=
*
(
__u32
*
)
((
u8
*
)
des_keymap
+
(
0xFC
&
z
));
z
=
keyinfo
[
9
];
z
=
expkey
[
9
];
z
^=
y
;
z
=
z
<<
4
|
z
>>
28
;
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
448
)
+
(
0xFC
&
z
));
...
...
@@ -399,7 +408,7 @@ static void des_small_fips_encrypt(void *ctx, __u8 *dst, __u8 *src)
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
320
)
+
(
0xFC
&
z
));
z
>>=
8
;
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
256
)
+
(
0xFC
&
z
));
z
=
keyinfo
[
10
];
z
=
expkey
[
10
];
z
^=
x
;
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
192
)
+
(
0xFC
&
z
));
z
>>=
8
;
...
...
@@ -408,7 +417,7 @@ static void des_small_fips_encrypt(void *ctx, __u8 *dst, __u8 *src)
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
64
)
+
(
0xFC
&
z
));
z
>>=
8
;
y
^=
*
(
__u32
*
)
((
u8
*
)
des_keymap
+
(
0xFC
&
z
));
z
=
keyinfo
[
11
];
z
=
expkey
[
11
];
z
^=
x
;
z
=
z
<<
4
|
z
>>
28
;
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
448
)
+
(
0xFC
&
z
));
...
...
@@ -418,7 +427,7 @@ static void des_small_fips_encrypt(void *ctx, __u8 *dst, __u8 *src)
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
320
)
+
(
0xFC
&
z
));
z
>>=
8
;
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
256
)
+
(
0xFC
&
z
));
z
=
keyinfo
[
12
];
z
=
expkey
[
12
];
z
^=
y
;
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
192
)
+
(
0xFC
&
z
));
z
>>=
8
;
...
...
@@ -427,7 +436,7 @@ static void des_small_fips_encrypt(void *ctx, __u8 *dst, __u8 *src)
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
64
)
+
(
0xFC
&
z
));
z
>>=
8
;
x
^=
*
(
__u32
*
)
((
u8
*
)
des_keymap
+
(
0xFC
&
z
));
z
=
keyinfo
[
13
];
z
=
expkey
[
13
];
z
^=
y
;
z
=
z
<<
4
|
z
>>
28
;
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
448
)
+
(
0xFC
&
z
));
...
...
@@ -437,7 +446,7 @@ static void des_small_fips_encrypt(void *ctx, __u8 *dst, __u8 *src)
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
320
)
+
(
0xFC
&
z
));
z
>>=
8
;
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
256
)
+
(
0xFC
&
z
));
z
=
keyinfo
[
14
];
z
=
expkey
[
14
];
z
^=
x
;
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
192
)
+
(
0xFC
&
z
));
z
>>=
8
;
...
...
@@ -446,7 +455,7 @@ static void des_small_fips_encrypt(void *ctx, __u8 *dst, __u8 *src)
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
64
)
+
(
0xFC
&
z
));
z
>>=
8
;
y
^=
*
(
__u32
*
)
((
u8
*
)
des_keymap
+
(
0xFC
&
z
));
z
=
keyinfo
[
15
];
z
=
expkey
[
15
];
z
^=
x
;
z
=
z
<<
4
|
z
>>
28
;
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
448
)
+
(
0xFC
&
z
));
...
...
@@ -456,7 +465,7 @@ static void des_small_fips_encrypt(void *ctx, __u8 *dst, __u8 *src)
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
320
)
+
(
0xFC
&
z
));
z
>>=
8
;
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
256
)
+
(
0xFC
&
z
));
z
=
keyinfo
[
16
];
z
=
expkey
[
16
];
z
^=
y
;
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
192
)
+
(
0xFC
&
z
));
z
>>=
8
;
...
...
@@ -465,7 +474,7 @@ static void des_small_fips_encrypt(void *ctx, __u8 *dst, __u8 *src)
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
64
)
+
(
0xFC
&
z
));
z
>>=
8
;
x
^=
*
(
__u32
*
)
((
u8
*
)
des_keymap
+
(
0xFC
&
z
));
z
=
keyinfo
[
17
];
z
=
expkey
[
17
];
z
^=
y
;
z
=
z
<<
4
|
z
>>
28
;
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
448
)
+
(
0xFC
&
z
));
...
...
@@ -475,7 +484,7 @@ static void des_small_fips_encrypt(void *ctx, __u8 *dst, __u8 *src)
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
320
)
+
(
0xFC
&
z
));
z
>>=
8
;
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
256
)
+
(
0xFC
&
z
));
z
=
keyinfo
[
18
];
z
=
expkey
[
18
];
z
^=
x
;
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
192
)
+
(
0xFC
&
z
));
z
>>=
8
;
...
...
@@ -484,7 +493,7 @@ static void des_small_fips_encrypt(void *ctx, __u8 *dst, __u8 *src)
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
64
)
+
(
0xFC
&
z
));
z
>>=
8
;
y
^=
*
(
__u32
*
)
((
u8
*
)
des_keymap
+
(
0xFC
&
z
));
z
=
keyinfo
[
19
];
z
=
expkey
[
19
];
z
^=
x
;
z
=
z
<<
4
|
z
>>
28
;
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
448
)
+
(
0xFC
&
z
));
...
...
@@ -494,7 +503,7 @@ static void des_small_fips_encrypt(void *ctx, __u8 *dst, __u8 *src)
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
320
)
+
(
0xFC
&
z
));
z
>>=
8
;
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
256
)
+
(
0xFC
&
z
));
z
=
keyinfo
[
20
];
z
=
expkey
[
20
];
z
^=
y
;
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
192
)
+
(
0xFC
&
z
));
z
>>=
8
;
...
...
@@ -503,7 +512,7 @@ static void des_small_fips_encrypt(void *ctx, __u8 *dst, __u8 *src)
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
64
)
+
(
0xFC
&
z
));
z
>>=
8
;
x
^=
*
(
__u32
*
)
((
u8
*
)
des_keymap
+
(
0xFC
&
z
));
z
=
keyinfo
[
21
];
z
=
expkey
[
21
];
z
^=
y
;
z
=
z
<<
4
|
z
>>
28
;
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
448
)
+
(
0xFC
&
z
));
...
...
@@ -513,7 +522,7 @@ static void des_small_fips_encrypt(void *ctx, __u8 *dst, __u8 *src)
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
320
)
+
(
0xFC
&
z
));
z
>>=
8
;
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
256
)
+
(
0xFC
&
z
));
z
=
keyinfo
[
22
];
z
=
expkey
[
22
];
z
^=
x
;
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
192
)
+
(
0xFC
&
z
));
z
>>=
8
;
...
...
@@ -522,7 +531,7 @@ static void des_small_fips_encrypt(void *ctx, __u8 *dst, __u8 *src)
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
64
)
+
(
0xFC
&
z
));
z
>>=
8
;
y
^=
*
(
__u32
*
)
((
u8
*
)
des_keymap
+
(
0xFC
&
z
));
z
=
keyinfo
[
23
];
z
=
expkey
[
23
];
z
^=
x
;
z
=
z
<<
4
|
z
>>
28
;
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
448
)
+
(
0xFC
&
z
));
...
...
@@ -532,7 +541,7 @@ static void des_small_fips_encrypt(void *ctx, __u8 *dst, __u8 *src)
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
320
)
+
(
0xFC
&
z
));
z
>>=
8
;
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
256
)
+
(
0xFC
&
z
));
z
=
keyinfo
[
24
];
z
=
expkey
[
24
];
z
^=
y
;
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
192
)
+
(
0xFC
&
z
));
z
>>=
8
;
...
...
@@ -541,7 +550,7 @@ static void des_small_fips_encrypt(void *ctx, __u8 *dst, __u8 *src)
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
64
)
+
(
0xFC
&
z
));
z
>>=
8
;
x
^=
*
(
__u32
*
)
((
u8
*
)
des_keymap
+
(
0xFC
&
z
));
z
=
keyinfo
[
25
];
z
=
expkey
[
25
];
z
^=
y
;
z
=
z
<<
4
|
z
>>
28
;
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
448
)
+
(
0xFC
&
z
));
...
...
@@ -551,7 +560,7 @@ static void des_small_fips_encrypt(void *ctx, __u8 *dst, __u8 *src)
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
320
)
+
(
0xFC
&
z
));
z
>>=
8
;
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
256
)
+
(
0xFC
&
z
));
z
=
keyinfo
[
26
];
z
=
expkey
[
26
];
z
^=
x
;
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
192
)
+
(
0xFC
&
z
));
z
>>=
8
;
...
...
@@ -560,7 +569,7 @@ static void des_small_fips_encrypt(void *ctx, __u8 *dst, __u8 *src)
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
64
)
+
(
0xFC
&
z
));
z
>>=
8
;
y
^=
*
(
__u32
*
)
((
u8
*
)
des_keymap
+
(
0xFC
&
z
));
z
=
keyinfo
[
27
];
z
=
expkey
[
27
];
z
^=
x
;
z
=
z
<<
4
|
z
>>
28
;
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
448
)
+
(
0xFC
&
z
));
...
...
@@ -570,7 +579,7 @@ static void des_small_fips_encrypt(void *ctx, __u8 *dst, __u8 *src)
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
320
)
+
(
0xFC
&
z
));
z
>>=
8
;
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
256
)
+
(
0xFC
&
z
));
z
=
keyinfo
[
28
];
z
=
expkey
[
28
];
z
^=
y
;
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
192
)
+
(
0xFC
&
z
));
z
>>=
8
;
...
...
@@ -579,7 +588,7 @@ static void des_small_fips_encrypt(void *ctx, __u8 *dst, __u8 *src)
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
64
)
+
(
0xFC
&
z
));
z
>>=
8
;
x
^=
*
(
__u32
*
)
((
u8
*
)
des_keymap
+
(
0xFC
&
z
));
z
=
keyinfo
[
29
];
z
=
expkey
[
29
];
z
^=
y
;
z
=
z
<<
4
|
z
>>
28
;
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
448
)
+
(
0xFC
&
z
));
...
...
@@ -589,7 +598,7 @@ static void des_small_fips_encrypt(void *ctx, __u8 *dst, __u8 *src)
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
320
)
+
(
0xFC
&
z
));
z
>>=
8
;
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
256
)
+
(
0xFC
&
z
));
z
=
keyinfo
[
30
];
z
=
expkey
[
30
];
z
^=
x
;
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
192
)
+
(
0xFC
&
z
));
z
>>=
8
;
...
...
@@ -598,7 +607,7 @@ static void des_small_fips_encrypt(void *ctx, __u8 *dst, __u8 *src)
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
64
)
+
(
0xFC
&
z
));
z
>>=
8
;
y
^=
*
(
__u32
*
)
((
u8
*
)
des_keymap
+
(
0xFC
&
z
));
z
=
keyinfo
[
31
];
z
=
expkey
[
31
];
z
^=
x
;
z
=
z
<<
4
|
z
>>
28
;
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
448
)
+
(
0xFC
&
z
));
...
...
@@ -625,42 +634,41 @@ static void des_small_fips_encrypt(void *ctx, __u8 *dst, __u8 *src)
z
=
((
y
>>
004
)
^
x
)
&
0x0F0F0F0FL
;
y
^=
z
<<
004
;
x
^=
z
;
dst
[
0
]
=
x
;
dst
[
0
]
=
x
;
x
>>=
8
;
dst
[
1
]
=
x
;
dst
[
1
]
=
x
;
x
>>=
8
;
dst
[
2
]
=
x
;
dst
[
2
]
=
x
;
x
>>=
8
;
dst
[
3
]
=
x
;
dst
[
4
]
=
y
;
dst
[
3
]
=
x
;
dst
[
4
]
=
y
;
y
>>=
8
;
dst
[
5
]
=
y
;
dst
[
5
]
=
y
;
y
>>=
8
;
dst
[
6
]
=
y
;
dst
[
6
]
=
y
;
y
>>=
8
;
dst
[
7
]
=
y
;
dst
[
7
]
=
y
;
return
;
}
static
void
des_small_fips_decrypt
(
void
*
ctx
,
__u8
*
dst
,
__u8
*
src
)
static
void
des_small_fips_decrypt
(
__u32
*
expkey
,
__u8
*
dst
,
__u8
*
src
)
{
__u32
*
keyinfo
=
((
struct
des_ctx
*
)
ctx
)
->
keyinfo
;
__u32
x
,
y
,
z
;
x
=
src
[
7
];
x
=
src
[
7
];
x
<<=
8
;
x
|=
src
[
6
];
x
|=
src
[
6
];
x
<<=
8
;
x
|=
src
[
5
];
x
|=
src
[
5
];
x
<<=
8
;
x
|=
src
[
4
];
y
=
src
[
3
];
x
|=
src
[
4
];
y
=
src
[
3
];
y
<<=
8
;
y
|=
src
[
2
];
y
|=
src
[
2
];
y
<<=
8
;
y
|=
src
[
1
];
y
|=
src
[
1
];
y
<<=
8
;
y
|=
src
[
0
];
y
|=
src
[
0
];
z
=
((
x
>>
004
)
^
y
)
&
0x0F0F0F0FL
;
x
^=
z
<<
004
;
y
^=
z
;
...
...
@@ -678,7 +686,7 @@ static void des_small_fips_decrypt(void *ctx, __u8 *dst, __u8 *src)
y
^=
z
;
x
^=
z
;
y
=
y
>>
1
|
y
<<
31
;
z
=
keyinfo
[
31
];
z
=
expkey
[
31
];
z
^=
y
;
z
=
z
<<
4
|
z
>>
28
;
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
448
)
+
(
0xFC
&
z
));
...
...
@@ -688,7 +696,7 @@ static void des_small_fips_decrypt(void *ctx, __u8 *dst, __u8 *src)
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
320
)
+
(
0xFC
&
z
));
z
>>=
8
;
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
256
)
+
(
0xFC
&
z
));
z
=
keyinfo
[
30
];
z
=
expkey
[
30
];
z
^=
y
;
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
192
)
+
(
0xFC
&
z
));
z
>>=
8
;
...
...
@@ -697,7 +705,7 @@ static void des_small_fips_decrypt(void *ctx, __u8 *dst, __u8 *src)
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
64
)
+
(
0xFC
&
z
));
z
>>=
8
;
x
^=
*
(
__u32
*
)
((
u8
*
)
des_keymap
+
(
0xFC
&
z
));
z
=
keyinfo
[
29
];
z
=
expkey
[
29
];
z
^=
x
;
z
=
z
<<
4
|
z
>>
28
;
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
448
)
+
(
0xFC
&
z
));
...
...
@@ -707,7 +715,7 @@ static void des_small_fips_decrypt(void *ctx, __u8 *dst, __u8 *src)
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
320
)
+
(
0xFC
&
z
));
z
>>=
8
;
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
256
)
+
(
0xFC
&
z
));
z
=
keyinfo
[
28
];
z
=
expkey
[
28
];
z
^=
x
;
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
192
)
+
(
0xFC
&
z
));
z
>>=
8
;
...
...
@@ -716,7 +724,7 @@ static void des_small_fips_decrypt(void *ctx, __u8 *dst, __u8 *src)
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
64
)
+
(
0xFC
&
z
));
z
>>=
8
;
y
^=
*
(
__u32
*
)
((
u8
*
)
des_keymap
+
(
0xFC
&
z
));
z
=
keyinfo
[
27
];
z
=
expkey
[
27
];
z
^=
y
;
z
=
z
<<
4
|
z
>>
28
;
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
448
)
+
(
0xFC
&
z
));
...
...
@@ -726,7 +734,7 @@ static void des_small_fips_decrypt(void *ctx, __u8 *dst, __u8 *src)
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
320
)
+
(
0xFC
&
z
));
z
>>=
8
;
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
256
)
+
(
0xFC
&
z
));
z
=
keyinfo
[
26
];
z
=
expkey
[
26
];
z
^=
y
;
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
192
)
+
(
0xFC
&
z
));
z
>>=
8
;
...
...
@@ -735,7 +743,7 @@ static void des_small_fips_decrypt(void *ctx, __u8 *dst, __u8 *src)
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
64
)
+
(
0xFC
&
z
));
z
>>=
8
;
x
^=
*
(
__u32
*
)
((
u8
*
)
des_keymap
+
(
0xFC
&
z
));
z
=
keyinfo
[
25
];
z
=
expkey
[
25
];
z
^=
x
;
z
=
z
<<
4
|
z
>>
28
;
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
448
)
+
(
0xFC
&
z
));
...
...
@@ -745,7 +753,7 @@ static void des_small_fips_decrypt(void *ctx, __u8 *dst, __u8 *src)
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
320
)
+
(
0xFC
&
z
));
z
>>=
8
;
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
256
)
+
(
0xFC
&
z
));
z
=
keyinfo
[
24
];
z
=
expkey
[
24
];
z
^=
x
;
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
192
)
+
(
0xFC
&
z
));
z
>>=
8
;
...
...
@@ -754,7 +762,7 @@ static void des_small_fips_decrypt(void *ctx, __u8 *dst, __u8 *src)
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
64
)
+
(
0xFC
&
z
));
z
>>=
8
;
y
^=
*
(
__u32
*
)
((
u8
*
)
des_keymap
+
(
0xFC
&
z
));
z
=
keyinfo
[
23
];
z
=
expkey
[
23
];
z
^=
y
;
z
=
z
<<
4
|
z
>>
28
;
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
448
)
+
(
0xFC
&
z
));
...
...
@@ -764,7 +772,7 @@ static void des_small_fips_decrypt(void *ctx, __u8 *dst, __u8 *src)
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
320
)
+
(
0xFC
&
z
));
z
>>=
8
;
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
256
)
+
(
0xFC
&
z
));
z
=
keyinfo
[
22
];
z
=
expkey
[
22
];
z
^=
y
;
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
192
)
+
(
0xFC
&
z
));
z
>>=
8
;
...
...
@@ -773,7 +781,7 @@ static void des_small_fips_decrypt(void *ctx, __u8 *dst, __u8 *src)
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
64
)
+
(
0xFC
&
z
));
z
>>=
8
;
x
^=
*
(
__u32
*
)
((
u8
*
)
des_keymap
+
(
0xFC
&
z
));
z
=
keyinfo
[
21
];
z
=
expkey
[
21
];
z
^=
x
;
z
=
z
<<
4
|
z
>>
28
;
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
448
)
+
(
0xFC
&
z
));
...
...
@@ -783,7 +791,7 @@ static void des_small_fips_decrypt(void *ctx, __u8 *dst, __u8 *src)
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
320
)
+
(
0xFC
&
z
));
z
>>=
8
;
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
256
)
+
(
0xFC
&
z
));
z
=
keyinfo
[
20
];
z
=
expkey
[
20
];
z
^=
x
;
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
192
)
+
(
0xFC
&
z
));
z
>>=
8
;
...
...
@@ -792,7 +800,7 @@ static void des_small_fips_decrypt(void *ctx, __u8 *dst, __u8 *src)
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
64
)
+
(
0xFC
&
z
));
z
>>=
8
;
y
^=
*
(
__u32
*
)
((
u8
*
)
des_keymap
+
(
0xFC
&
z
));
z
=
keyinfo
[
19
];
z
=
expkey
[
19
];
z
^=
y
;
z
=
z
<<
4
|
z
>>
28
;
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
448
)
+
(
0xFC
&
z
));
...
...
@@ -802,7 +810,7 @@ static void des_small_fips_decrypt(void *ctx, __u8 *dst, __u8 *src)
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
320
)
+
(
0xFC
&
z
));
z
>>=
8
;
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
256
)
+
(
0xFC
&
z
));
z
=
keyinfo
[
18
];
z
=
expkey
[
18
];
z
^=
y
;
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
192
)
+
(
0xFC
&
z
));
z
>>=
8
;
...
...
@@ -811,7 +819,7 @@ static void des_small_fips_decrypt(void *ctx, __u8 *dst, __u8 *src)
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
64
)
+
(
0xFC
&
z
));
z
>>=
8
;
x
^=
*
(
__u32
*
)
((
u8
*
)
des_keymap
+
(
0xFC
&
z
));
z
=
keyinfo
[
17
];
z
=
expkey
[
17
];
z
^=
x
;
z
=
z
<<
4
|
z
>>
28
;
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
448
)
+
(
0xFC
&
z
));
...
...
@@ -821,7 +829,7 @@ static void des_small_fips_decrypt(void *ctx, __u8 *dst, __u8 *src)
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
320
)
+
(
0xFC
&
z
));
z
>>=
8
;
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
256
)
+
(
0xFC
&
z
));
z
=
keyinfo
[
16
];
z
=
expkey
[
16
];
z
^=
x
;
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
192
)
+
(
0xFC
&
z
));
z
>>=
8
;
...
...
@@ -830,7 +838,7 @@ static void des_small_fips_decrypt(void *ctx, __u8 *dst, __u8 *src)
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
64
)
+
(
0xFC
&
z
));
z
>>=
8
;
y
^=
*
(
__u32
*
)
((
u8
*
)
des_keymap
+
(
0xFC
&
z
));
z
=
keyinfo
[
15
];
z
=
expkey
[
15
];
z
^=
y
;
z
=
z
<<
4
|
z
>>
28
;
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
448
)
+
(
0xFC
&
z
));
...
...
@@ -840,7 +848,7 @@ static void des_small_fips_decrypt(void *ctx, __u8 *dst, __u8 *src)
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
320
)
+
(
0xFC
&
z
));
z
>>=
8
;
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
256
)
+
(
0xFC
&
z
));
z
=
keyinfo
[
14
];
z
=
expkey
[
14
];
z
^=
y
;
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
192
)
+
(
0xFC
&
z
));
z
>>=
8
;
...
...
@@ -849,7 +857,7 @@ static void des_small_fips_decrypt(void *ctx, __u8 *dst, __u8 *src)
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
64
)
+
(
0xFC
&
z
));
z
>>=
8
;
x
^=
*
(
__u32
*
)
((
u8
*
)
des_keymap
+
(
0xFC
&
z
));
z
=
keyinfo
[
13
];
z
=
expkey
[
13
];
z
^=
x
;
z
=
z
<<
4
|
z
>>
28
;
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
448
)
+
(
0xFC
&
z
));
...
...
@@ -859,7 +867,7 @@ static void des_small_fips_decrypt(void *ctx, __u8 *dst, __u8 *src)
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
320
)
+
(
0xFC
&
z
));
z
>>=
8
;
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
256
)
+
(
0xFC
&
z
));
z
=
keyinfo
[
12
];
z
=
expkey
[
12
];
z
^=
x
;
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
192
)
+
(
0xFC
&
z
));
z
>>=
8
;
...
...
@@ -868,7 +876,7 @@ static void des_small_fips_decrypt(void *ctx, __u8 *dst, __u8 *src)
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
64
)
+
(
0xFC
&
z
));
z
>>=
8
;
y
^=
*
(
__u32
*
)
((
u8
*
)
des_keymap
+
(
0xFC
&
z
));
z
=
keyinfo
[
11
];
z
=
expkey
[
11
];
z
^=
y
;
z
=
z
<<
4
|
z
>>
28
;
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
448
)
+
(
0xFC
&
z
));
...
...
@@ -878,7 +886,7 @@ static void des_small_fips_decrypt(void *ctx, __u8 *dst, __u8 *src)
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
320
)
+
(
0xFC
&
z
));
z
>>=
8
;
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
256
)
+
(
0xFC
&
z
));
z
=
keyinfo
[
10
];
z
=
expkey
[
10
];
z
^=
y
;
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
192
)
+
(
0xFC
&
z
));
z
>>=
8
;
...
...
@@ -887,7 +895,7 @@ static void des_small_fips_decrypt(void *ctx, __u8 *dst, __u8 *src)
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
64
)
+
(
0xFC
&
z
));
z
>>=
8
;
x
^=
*
(
__u32
*
)
((
u8
*
)
des_keymap
+
(
0xFC
&
z
));
z
=
keyinfo
[
9
];
z
=
expkey
[
9
];
z
^=
x
;
z
=
z
<<
4
|
z
>>
28
;
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
448
)
+
(
0xFC
&
z
));
...
...
@@ -897,7 +905,7 @@ static void des_small_fips_decrypt(void *ctx, __u8 *dst, __u8 *src)
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
320
)
+
(
0xFC
&
z
));
z
>>=
8
;
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
256
)
+
(
0xFC
&
z
));
z
=
keyinfo
[
8
];
z
=
expkey
[
8
];
z
^=
x
;
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
192
)
+
(
0xFC
&
z
));
z
>>=
8
;
...
...
@@ -906,7 +914,7 @@ static void des_small_fips_decrypt(void *ctx, __u8 *dst, __u8 *src)
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
64
)
+
(
0xFC
&
z
));
z
>>=
8
;
y
^=
*
(
__u32
*
)
((
u8
*
)
des_keymap
+
(
0xFC
&
z
));
z
=
keyinfo
[
7
];
z
=
expkey
[
7
];
z
^=
y
;
z
=
z
<<
4
|
z
>>
28
;
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
448
)
+
(
0xFC
&
z
));
...
...
@@ -916,7 +924,7 @@ static void des_small_fips_decrypt(void *ctx, __u8 *dst, __u8 *src)
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
320
)
+
(
0xFC
&
z
));
z
>>=
8
;
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
256
)
+
(
0xFC
&
z
));
z
=
keyinfo
[
6
];
z
=
expkey
[
6
];
z
^=
y
;
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
192
)
+
(
0xFC
&
z
));
z
>>=
8
;
...
...
@@ -925,7 +933,7 @@ static void des_small_fips_decrypt(void *ctx, __u8 *dst, __u8 *src)
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
64
)
+
(
0xFC
&
z
));
z
>>=
8
;
x
^=
*
(
__u32
*
)
((
u8
*
)
des_keymap
+
(
0xFC
&
z
));
z
=
keyinfo
[
5
];
z
=
expkey
[
5
];
z
^=
x
;
z
=
z
<<
4
|
z
>>
28
;
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
448
)
+
(
0xFC
&
z
));
...
...
@@ -935,7 +943,7 @@ static void des_small_fips_decrypt(void *ctx, __u8 *dst, __u8 *src)
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
320
)
+
(
0xFC
&
z
));
z
>>=
8
;
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
256
)
+
(
0xFC
&
z
));
z
=
keyinfo
[
4
];
z
=
expkey
[
4
];
z
^=
x
;
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
192
)
+
(
0xFC
&
z
));
z
>>=
8
;
...
...
@@ -944,7 +952,7 @@ static void des_small_fips_decrypt(void *ctx, __u8 *dst, __u8 *src)
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
64
)
+
(
0xFC
&
z
));
z
>>=
8
;
y
^=
*
(
__u32
*
)
((
u8
*
)
des_keymap
+
(
0xFC
&
z
));
z
=
keyinfo
[
3
];
z
=
expkey
[
3
];
z
^=
y
;
z
=
z
<<
4
|
z
>>
28
;
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
448
)
+
(
0xFC
&
z
));
...
...
@@ -954,7 +962,7 @@ static void des_small_fips_decrypt(void *ctx, __u8 *dst, __u8 *src)
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
320
)
+
(
0xFC
&
z
));
z
>>=
8
;
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
256
)
+
(
0xFC
&
z
));
z
=
keyinfo
[
2
];
z
=
expkey
[
2
];
z
^=
y
;
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
192
)
+
(
0xFC
&
z
));
z
>>=
8
;
...
...
@@ -963,7 +971,7 @@ static void des_small_fips_decrypt(void *ctx, __u8 *dst, __u8 *src)
x
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
64
)
+
(
0xFC
&
z
));
z
>>=
8
;
x
^=
*
(
__u32
*
)
((
u8
*
)
des_keymap
+
(
0xFC
&
z
));
z
=
keyinfo
[
1
];
z
=
expkey
[
1
];
z
^=
x
;
z
=
z
<<
4
|
z
>>
28
;
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
448
)
+
(
0xFC
&
z
));
...
...
@@ -973,7 +981,7 @@ static void des_small_fips_decrypt(void *ctx, __u8 *dst, __u8 *src)
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
320
)
+
(
0xFC
&
z
));
z
>>=
8
;
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
256
)
+
(
0xFC
&
z
));
z
=
keyinfo
[
0
];
z
=
expkey
[
0
];
z
^=
x
;
y
^=
*
(
__u32
*
)
((
u8
*
)
(
des_keymap
+
192
)
+
(
0xFC
&
z
));
z
>>=
8
;
...
...
@@ -999,33 +1007,32 @@ static void des_small_fips_decrypt(void *ctx, __u8 *dst, __u8 *src)
z
=
((
y
>>
004
)
^
x
)
&
0x0F0F0F0FL
;
y
^=
z
<<
004
;
x
^=
z
;
dst
[
0
]
=
x
;
dst
[
0
]
=
x
;
x
>>=
8
;
dst
[
1
]
=
x
;
dst
[
1
]
=
x
;
x
>>=
8
;
dst
[
2
]
=
x
;
dst
[
2
]
=
x
;
x
>>=
8
;
dst
[
3
]
=
x
;
dst
[
4
]
=
y
;
dst
[
3
]
=
x
;
dst
[
4
]
=
y
;
y
>>=
8
;
dst
[
5
]
=
y
;
dst
[
5
]
=
y
;
y
>>=
8
;
dst
[
6
]
=
y
;
dst
[
6
]
=
y
;
y
>>=
8
;
dst
[
7
]
=
y
;
dst
[
7
]
=
y
;
return
;
}
/*
* RFC2451: Weak key checks SHOULD be performed.
*/
static
int
des_setkey
(
void
*
ctx
,
const
__u8
*
key
,
size_t
keylen
,
int
*
flags
)
static
int
setkey
(
__u32
*
expkey
,
const
__u8
*
key
,
size_t
keylen
,
int
*
flags
)
{
struct
des_ctx
*
dctx
=
ctx
;
const
__u8
*
k
;
__u8
*
b0
,
*
b1
;
__u32
n
,
w
;
__u32
*
method
;
__u8
bits0
[
56
],
bits1
[
56
];
if
(
keylen
!=
DES_KEY_SIZE
)
{
...
...
@@ -1125,7 +1132,6 @@ static int des_setkey(void *ctx, const __u8 *key, size_t keylen, int *flags)
/* put the bits in the correct places */
n
=
16
;
k
=
rotors
;
method
=
dctx
->
keyinfo
;
do
{
w
=
(
b1
[
k
[
0
]]
|
b0
[
k
[
1
]])
<<
4
;
...
...
@@ -1143,7 +1149,7 @@ static int des_setkey(void *ctx, const __u8 *key, size_t keylen, int *flags)
w
|=
(
b1
[
k
[
18
]]
|
b0
[
k
[
19
]])
<<
4
;
w
|=
(
b1
[
k
[
20
]]
|
b0
[
k
[
21
]])
<<
2
;
w
|=
b1
[
k
[
22
]]
|
b0
[
k
[
23
]];
method
[
0
]
=
w
;
expkey
[
0
]
=
w
;
w
=
(
b1
[
k
[
0
+
24
]]
|
b0
[
k
[
1
+
24
]])
<<
4
;
w
|=
(
b1
[
k
[
2
+
24
]]
|
b0
[
k
[
3
+
24
]])
<<
2
;
...
...
@@ -1162,16 +1168,94 @@ static int des_setkey(void *ctx, const __u8 *key, size_t keylen, int *flags)
w
|=
b1
[
k
[
22
+
24
]]
|
b0
[
k
[
23
+
24
]];
ROR
(
w
,
4
,
28
);
/* could be eliminated */
method
[
1
]
=
w
;
expkey
[
1
]
=
w
;
k
+=
48
;
method
+=
2
;
expkey
+=
2
;
}
while
(
--
n
);
return
0
;
}
static
struct
crypto_alg
alg
=
{
static
int
des_setkey
(
void
*
ctx
,
const
__u8
*
key
,
size_t
keylen
,
int
*
flags
)
{
return
setkey
(((
struct
des_ctx
*
)
ctx
)
->
expkey
,
key
,
keylen
,
flags
);
}
static
void
des_encrypt
(
void
*
ctx
,
__u8
*
dst
,
__u8
*
src
)
{
des_small_fips_encrypt
(((
struct
des_ctx
*
)
ctx
)
->
expkey
,
dst
,
src
);
}
static
void
des_decrypt
(
void
*
ctx
,
__u8
*
dst
,
__u8
*
src
)
{
des_small_fips_decrypt
(((
struct
des_ctx
*
)
ctx
)
->
expkey
,
dst
,
src
);
}
/*
* RFC2451:
*
* For DES-EDE3, there is no known need to reject weak or
* complementation keys. Any weakness is obviated by the use of
* multiple keys.
*
* However, if the first two or last two independent 64-bit keys are
* equal (k1 == k2 or k2 == k3), then the DES3 operation is simply the
* same as DES. Implementers MUST reject keys that exhibit this
* property.
*
*/
static
int
des3_ede_setkey
(
void
*
ctx
,
const
__u8
*
key
,
size_t
keylen
,
int
*
flags
)
{
int
i
,
off
;
struct
des3_ede_ctx
*
dctx
=
ctx
;
if
(
keylen
!=
DES3_EDE_KEY_SIZE
)
{
*
flags
|=
CRYPTO_BAD_KEY_LEN
;
return
-
EINVAL
;
}
if
(
!
(
memcmp
(
key
,
&
key
[
DES_KEY_SIZE
],
DES_KEY_SIZE
)
&&
memcmp
(
&
key
[
DES_KEY_SIZE
],
&
key
[
DES_KEY_SIZE
*
2
],
DES_KEY_SIZE
)))
{
*
flags
|=
CRYPTO_BAD_KEY_SCHED
;
return
-
EINVAL
;
}
for
(
i
=
0
,
off
=
0
;
i
<
3
;
i
++
,
off
+=
DES_EXPKEY_WORDS
,
key
+=
DES_KEY_SIZE
)
{
int
ret
=
setkey
(
&
dctx
->
expkey
[
off
],
key
,
DES_KEY_SIZE
,
flags
);
if
(
ret
<
0
)
return
ret
;
}
return
0
;
}
static
void
des3_ede_encrypt
(
void
*
ctx
,
__u8
*
dst
,
__u8
*
src
)
{
struct
des3_ede_ctx
*
dctx
=
ctx
;
des_small_fips_encrypt
(
dctx
->
expkey
,
dst
,
src
);
des_small_fips_decrypt
(
&
dctx
->
expkey
[
DES_EXPKEY_WORDS
],
dst
,
dst
);
des_small_fips_encrypt
(
&
dctx
->
expkey
[
DES_EXPKEY_WORDS
*
2
],
dst
,
dst
);
return
;
}
static
void
des3_ede_decrypt
(
void
*
ctx
,
__u8
*
dst
,
__u8
*
src
)
{
struct
des3_ede_ctx
*
dctx
=
ctx
;
des_small_fips_decrypt
(
&
dctx
->
expkey
[
DES_EXPKEY_WORDS
*
2
],
dst
,
src
);
des_small_fips_encrypt
(
&
dctx
->
expkey
[
DES_EXPKEY_WORDS
],
dst
,
dst
);
des_small_fips_decrypt
(
dctx
->
expkey
,
dst
,
dst
);
return
;
}
static
struct
crypto_alg
des_alg
=
{
.
cra_id
=
CRYPTO_ALG_DES
,
.
cra_name
=
"des"
,
.
cra_blocksize
=
DES_BLOCK_SIZE
,
...
...
@@ -1180,19 +1264,47 @@ static struct crypto_alg alg = {
.
cia_keysize
=
DES_KEY_SIZE
,
.
cia_ivsize
=
DES_BLOCK_SIZE
,
.
cia_setkey
=
des_setkey
,
.
cia_encrypt
=
des_small_fips_encrypt
,
.
cia_decrypt
=
des_small_fips_decrypt
}
}
.
cia_encrypt
=
des_encrypt
,
.
cia_decrypt
=
des_decrypt
}
}
};
static
struct
crypto_alg
des3_ede_alg
=
{
.
cra_id
=
CRYPTO_ALG_DES3_EDE
,
.
cra_name
=
"des3_ede"
,
.
cra_blocksize
=
DES3_EDE_BLOCK_SIZE
,
.
cra_ctxsize
=
sizeof
(
struct
des3_ede_ctx
),
.
cra_u
=
{
.
cipher
=
{
.
cia_keysize
=
DES3_EDE_KEY_SIZE
,
.
cia_ivsize
=
DES3_EDE_BLOCK_SIZE
,
.
cia_setkey
=
des3_ede_setkey
,
.
cia_encrypt
=
des3_ede_encrypt
,
.
cia_decrypt
=
des3_ede_decrypt
}
}
};
static
int
__init
init
(
void
)
{
INIT_LIST_HEAD
(
&
alg
.
cra_list
);
return
crypto_register_alg
(
&
alg
);
int
ret
=
0
;
INIT_LIST_HEAD
(
&
des_alg
.
cra_list
);
INIT_LIST_HEAD
(
&
des3_ede_alg
.
cra_list
);
ret
=
crypto_register_alg
(
&
des_alg
);
if
(
ret
<
0
)
goto
out
;
ret
=
crypto_register_alg
(
&
des3_ede_alg
);
if
(
ret
<
0
)
{
crypto_unregister_alg
(
&
des_alg
);
goto
out
;
}
out:
return
ret
;
}
static
void
__exit
fini
(
void
)
{
crypto_unregister_alg
(
&
alg
);
crypto_unregister_alg
(
&
des3_ede_alg
);
crypto_unregister_alg
(
&
des_alg
);
}
module_init
(
init
);
...
...
@@ -1200,16 +1312,3 @@ module_exit(fini);
MODULE_LICENSE
(
"GPL"
);
MODULE_DESCRIPTION
(
"DES & Triple DES EDE Cipher Algorithms"
);
#if 0
/*
* RFC2451:
*
* However, if the first two or last two independent 64-bit keys are
* equal (k1 == k2 or k2 == k3), then the 3DES operation is simply the
* same as DES. Implementers MUST reject keys that exhibit this
* property.
*/
#endif
crypto/tcrypt.c
View file @
a5c660e6
...
...
@@ -42,7 +42,6 @@
#define IDX7 27333
#define IDX8 3000
static
int
mode
=
0
;
static
char
*
xbuf
;
static
char
*
tvmem
;
...
...
@@ -1094,6 +1093,115 @@ void test_des(void)
return
;
}
void
test_des3_ede
(
void
)
{
int
ret
,
i
,
len
;
size_t
tsize
;
char
*
p
,
*
q
;
struct
crypto_tfm
*
tfm
;
char
*
key
;
/*char res[8];*/
struct
des_tv
*
des_tv
;
struct
scatterlist
sg
[
8
];
printk
(
"
\n
testing des3 ede encryption
\n
"
);
tsize
=
sizeof
(
des3_ede_enc_tv_template
);
if
(
tsize
>
TVMEMSIZE
)
{
printk
(
"template (%Zd) too big for tvmem (%d)
\n
"
,
tsize
,
TVMEMSIZE
);
return
;
}
memcpy
(
tvmem
,
des3_ede_enc_tv_template
,
tsize
);
des_tv
=
(
void
*
)
tvmem
;
tfm
=
crypto_alloc_tfm
(
CRYPTO_ALG_DES3_EDE_ECB
);
if
(
tfm
==
NULL
)
{
printk
(
"failed to load transform for CRYPTO_ALG_DES3_EDE_ECB
\n
"
);
return
;
}
for
(
i
=
0
;
i
<
DES3_EDE_ENC_TEST_VECTORS
;
i
++
)
{
printk
(
"test %d:
\n
"
,
i
+
1
);
key
=
des_tv
[
i
].
key
;
tfm
->
crt_flags
=
CRYPTO_WEAK_KEY_CHECK
;
ret
=
crypto_cipher_setkey
(
tfm
,
key
,
24
);
if
(
ret
)
{
printk
(
"setkey() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
if
(
!
des_tv
[
i
].
fail
)
goto
out
;
}
len
=
des_tv
[
i
].
len
;
p
=
des_tv
[
i
].
plaintext
;
sg
[
0
].
page
=
virt_to_page
(
p
);
sg
[
0
].
offset
=
((
long
)
p
&
~
PAGE_MASK
);
sg
[
0
].
length
=
len
;
ret
=
crypto_cipher_encrypt
(
tfm
,
sg
,
1
);
if
(
ret
)
{
printk
(
"encrypt() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
goto
out
;
}
q
=
kmap
(
sg
[
0
].
page
)
+
sg
[
0
].
offset
;
hexdump
(
q
,
len
);
printk
(
"%s
\n
"
,
memcmp
(
q
,
des_tv
[
i
].
result
,
len
)
?
"fail"
:
"pass"
);
}
printk
(
"
\n
testing des3 ede decryption
\n
"
);
tsize
=
sizeof
(
des3_ede_dec_tv_template
);
if
(
tsize
>
TVMEMSIZE
)
{
printk
(
"template (%Zd) too big for tvmem (%d)
\n
"
,
tsize
,
TVMEMSIZE
);
return
;
}
memcpy
(
tvmem
,
des3_ede_dec_tv_template
,
tsize
);
des_tv
=
(
void
*
)
tvmem
;
for
(
i
=
0
;
i
<
DES3_EDE_DEC_TEST_VECTORS
;
i
++
)
{
printk
(
"test %d:
\n
"
,
i
+
1
);
key
=
des_tv
[
i
].
key
;
tfm
->
crt_flags
=
CRYPTO_WEAK_KEY_CHECK
;
ret
=
crypto_cipher_setkey
(
tfm
,
key
,
24
);
if
(
ret
)
{
printk
(
"setkey() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
if
(
!
des_tv
[
i
].
fail
)
goto
out
;
}
len
=
des_tv
[
i
].
len
;
p
=
des_tv
[
i
].
plaintext
;
sg
[
0
].
page
=
virt_to_page
(
p
);
sg
[
0
].
offset
=
((
long
)
p
&
~
PAGE_MASK
);
sg
[
0
].
length
=
len
;
ret
=
crypto_cipher_decrypt
(
tfm
,
sg
,
1
);
if
(
ret
)
{
printk
(
"decrypt() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
goto
out
;
}
q
=
kmap
(
sg
[
0
].
page
)
+
sg
[
0
].
offset
;
hexdump
(
q
,
len
);
printk
(
"%s
\n
"
,
memcmp
(
q
,
des_tv
[
i
].
result
,
len
)
?
"fail"
:
"pass"
);
}
out:
crypto_free_tfm
(
tfm
);
return
;
}
static
void
do_test
(
void
)
{
switch
(
mode
)
{
...
...
@@ -1102,6 +1210,7 @@ static void do_test(void)
test_md5
();
test_sha1
();
test_des
();
test_des3_ede
();
break
;
case
1
:
...
...
@@ -1116,6 +1225,10 @@ static void do_test(void)
test_des
();
break
;
case
4
:
test_des3_ede
();
break
;
default:
/* useful for debugging */
printk
(
"not testing anything
\n
"
);
...
...
crypto/tcrypt.h
View file @
a5c660e6
...
...
@@ -306,11 +306,13 @@ struct sha1_testvec {
#define DES_DEC_TEST_VECTORS 2
#define DES_CBC_ENC_TEST_VECTORS 4
#define DES_CBC_DEC_TEST_VECTORS 3
#define DES3_EDE_ENC_TEST_VECTORS 3
#define DES3_EDE_DEC_TEST_VECTORS 3
struct
des_tv
{
int
len
;
int
fail
;
char
key
[
8
];
char
key
[
24
];
char
iv
[
8
];
char
plaintext
[
128
];
char
result
[
128
];
...
...
@@ -581,7 +583,104 @@ struct des_tv des_cbc_dec_tv_template[] = {
},
};
/*
* We really need some more test vectors, especially for DES3 CBC.
*/
struct
des_tv
des3_ede_enc_tv_template
[]
=
{
/* These are from openssl */
{
8
,
0
,
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xAB
,
0xCD
,
0xEF
,
0x55
,
0x55
,
0x55
,
0x55
,
0x55
,
0x55
,
0x55
,
0x55
,
0xFE
,
0xDC
,
0xBA
,
0x98
,
0x76
,
0x54
,
0x32
,
0x10
},
{
0
},
{
0x73
,
0x6F
,
0x6D
,
0x65
,
0x64
,
0x61
,
0x74
,
0x61
},
{
0x18
,
0xd7
,
0x48
,
0xe5
,
0x63
,
0x62
,
0x05
,
0x72
},
},
{
8
,
0
,
{
0x03
,
0x52
,
0x02
,
0x07
,
0x67
,
0x20
,
0x82
,
0x17
,
0x86
,
0x02
,
0x87
,
0x66
,
0x59
,
0x08
,
0x21
,
0x98
,
0x64
,
0x05
,
0x6A
,
0xBD
,
0xFE
,
0xA9
,
0x34
,
0x57
},
{
0
},
{
0x73
,
0x71
,
0x75
,
0x69
,
0x67
,
0x67
,
0x6C
,
0x65
},
{
0xc0
,
0x7d
,
0x2a
,
0x0f
,
0xa5
,
0x66
,
0xfa
,
0x30
}
},
{
8
,
0
,
{
0x10
,
0x46
,
0x10
,
0x34
,
0x89
,
0x98
,
0x80
,
0x20
,
0x91
,
0x07
,
0xD0
,
0x15
,
0x89
,
0x19
,
0x01
,
0x01
,
0x19
,
0x07
,
0x92
,
0x10
,
0x98
,
0x1A
,
0x01
,
0x01
},
{
0
},
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
},
{
0xe1
,
0xef
,
0x62
,
0xc3
,
0x32
,
0xfe
,
0x82
,
0x5b
}
},
};
struct
des_tv
des3_ede_dec_tv_template
[]
=
{
/* These are from openssl */
{
8
,
0
,
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xAB
,
0xCD
,
0xEF
,
0x55
,
0x55
,
0x55
,
0x55
,
0x55
,
0x55
,
0x55
,
0x55
,
0xFE
,
0xDC
,
0xBA
,
0x98
,
0x76
,
0x54
,
0x32
,
0x10
},
{
0
},
{
0x18
,
0xd7
,
0x48
,
0xe5
,
0x63
,
0x62
,
0x05
,
0x72
},
{
0x73
,
0x6F
,
0x6D
,
0x65
,
0x64
,
0x61
,
0x74
,
0x61
},
},
{
8
,
0
,
{
0x03
,
0x52
,
0x02
,
0x07
,
0x67
,
0x20
,
0x82
,
0x17
,
0x86
,
0x02
,
0x87
,
0x66
,
0x59
,
0x08
,
0x21
,
0x98
,
0x64
,
0x05
,
0x6A
,
0xBD
,
0xFE
,
0xA9
,
0x34
,
0x57
},
{
0
},
{
0xc0
,
0x7d
,
0x2a
,
0x0f
,
0xa5
,
0x66
,
0xfa
,
0x30
},
{
0x73
,
0x71
,
0x75
,
0x69
,
0x67
,
0x67
,
0x6C
,
0x65
},
},
{
8
,
0
,
{
0x10
,
0x46
,
0x10
,
0x34
,
0x89
,
0x98
,
0x80
,
0x20
,
0x91
,
0x07
,
0xD0
,
0x15
,
0x89
,
0x19
,
0x01
,
0x01
,
0x19
,
0x07
,
0x92
,
0x10
,
0x98
,
0x1A
,
0x01
,
0x01
},
{
0
},
{
0xe1
,
0xef
,
0x62
,
0xc3
,
0x32
,
0xfe
,
0x82
,
0x5b
},
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
},
},
};
#endif
/* _CRYPTO_TCRYPT_H */
include/linux/crypto.h
View file @
a5c660e6
...
...
@@ -22,7 +22,8 @@
#define CRYPTO_WEAK_KEY_CHECK 0x0001
#define CRYPTO_WEAK_KEY 0x0008
#define CRYPTO_BAD_KEY_LEN 0x0010
#define CRYPTO_BAD_BLOCK_LEN 0x0020
#define CRYPTO_BAD_KEY_SCHED 0x0020
#define CRYPTO_BAD_BLOCK_LEN 0x0040
#define CRYPTO_ATOMIC 0x1000
/*
...
...
@@ -51,9 +52,9 @@
#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_
3DES
_EDE (0x00000002|CRYPTO_TYPE_CIPHER)
#define CRYPTO_ALG_
3DES_EDE_ECB (CRYPTO_ALG_3DES
_EDE|CRYPTO_MODE_ECB)
#define CRYPTO_ALG_
3DES_EDE_CBC (CRYPTO_ALG_3DES
_EDE|CRYPTO_MODE_CBC)
#define CRYPTO_ALG_
DES3
_EDE (0x00000002|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)
...
...
@@ -61,10 +62,6 @@
#define CRYPTO_MAX_ALG_NAME 64
#define CRYPTO_MAX_BLOCK_SIZE 16
#define cra_cipher cra_u.cipher
#define cra_digest cra_u.digest
#define cra_compress cra_u.compress
struct
scatterlist
;
struct
cipher_alg
{
...
...
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