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
91f70b00
Commit
91f70b00
authored
Dec 24, 2003
by
Kartikey Mahendra Bhatt
Committed by
David S. Miller
Dec 24, 2003
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[CRYPTO]: Clean up tcrypt module, part 1
parent
2b14075e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
1687 additions
and
3225 deletions
+1687
-3225
crypto/tcrypt.c
crypto/tcrypt.c
+401
-2331
crypto/tcrypt.h
crypto/tcrypt.h
+1286
-894
No files found.
crypto/tcrypt.c
View file @
91f70b00
...
...
@@ -6,2384 +6,409 @@
*
* Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
* Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org>
*
* 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/init.h>
#include <linux/module.h>
#include <linux/mm.h>
#include <linux/slab.h>
#include <asm/scatterlist.h>
#include <linux/string.h>
#include <linux/crypto.h>
#include <linux/highmem.h>
#include "tcrypt.h"
/*
* Need to kmalloc() memory for testing kmap().
*/
#define TVMEMSIZE 4096
#define XBUFSIZE 32768
/*
* Indexes into the xbuf to simulate cross-page access.
*/
#define IDX1 37
#define IDX2 32400
#define IDX3 1
#define IDX4 8193
#define IDX5 22222
#define IDX6 17101
#define IDX7 27333
#define IDX8 3000
static
int
mode
;
static
char
*
xbuf
;
static
char
*
tvmem
;
static
char
*
check
[]
=
{
"des"
,
"md5"
,
"des3_ede"
,
"rot13"
,
"sha1"
,
"sha256"
,
"blowfish"
,
"twofish"
,
"serpent"
,
"sha384"
,
"sha512"
,
"md4"
,
"aes"
,
"cast6"
,
"deflate"
,
NULL
};
static
void
hexdump
(
unsigned
char
*
buf
,
unsigned
int
len
)
{
while
(
len
--
)
printk
(
"%02x"
,
*
buf
++
);
printk
(
"
\n
"
);
}
static
void
test_md5
(
void
)
{
char
*
p
;
unsigned
int
i
;
struct
scatterlist
sg
[
2
];
char
result
[
128
];
struct
crypto_tfm
*
tfm
;
struct
md5_testvec
*
md5_tv
;
unsigned
int
tsize
;
printk
(
"
\n
testing md5
\n
"
);
tsize
=
sizeof
(
md5_tv_template
);
if
(
tsize
>
TVMEMSIZE
)
{
printk
(
"template (%u) too big for tvmem (%u)
\n
"
,
tsize
,
TVMEMSIZE
);
return
;
}
memcpy
(
tvmem
,
md5_tv_template
,
tsize
);
md5_tv
=
(
void
*
)
tvmem
;
tfm
=
crypto_alloc_tfm
(
"md5"
,
0
);
if
(
tfm
==
NULL
)
{
printk
(
"failed to load transform for md5
\n
"
);
return
;
}
for
(
i
=
0
;
i
<
MD5_TEST_VECTORS
;
i
++
)
{
printk
(
"test %u:
\n
"
,
i
+
1
);
memset
(
result
,
0
,
sizeof
(
result
));
p
=
md5_tv
[
i
].
plaintext
;
sg
[
0
].
page
=
virt_to_page
(
p
);
sg
[
0
].
offset
=
offset_in_page
(
p
);
sg
[
0
].
length
=
strlen
(
md5_tv
[
i
].
plaintext
);
crypto_digest_init
(
tfm
);
crypto_digest_update
(
tfm
,
sg
,
1
);
crypto_digest_final
(
tfm
,
result
);
hexdump
(
result
,
crypto_tfm_alg_digestsize
(
tfm
));
printk
(
"%s
\n
"
,
memcmp
(
result
,
md5_tv
[
i
].
digest
,
crypto_tfm_alg_digestsize
(
tfm
))
?
"fail"
:
"pass"
);
}
printk
(
"
\n
testing md5 across pages
\n
"
);
/* setup the dummy buffer first */
memset
(
xbuf
,
0
,
XBUFSIZE
);
memcpy
(
&
xbuf
[
IDX1
],
"abcdefghijklm"
,
13
);
memcpy
(
&
xbuf
[
IDX2
],
"nopqrstuvwxyz"
,
13
);
p
=
&
xbuf
[
IDX1
];
sg
[
0
].
page
=
virt_to_page
(
p
);
sg
[
0
].
offset
=
offset_in_page
(
p
);
sg
[
0
].
length
=
13
;
p
=
&
xbuf
[
IDX2
];
sg
[
1
].
page
=
virt_to_page
(
p
);
sg
[
1
].
offset
=
offset_in_page
(
p
);
sg
[
1
].
length
=
13
;
memset
(
result
,
0
,
sizeof
(
result
));
crypto_digest_digest
(
tfm
,
sg
,
2
,
result
);
hexdump
(
result
,
crypto_tfm_alg_digestsize
(
tfm
));
printk
(
"%s
\n
"
,
memcmp
(
result
,
md5_tv
[
4
].
digest
,
crypto_tfm_alg_digestsize
(
tfm
))
?
"fail"
:
"pass"
);
crypto_free_tfm
(
tfm
);
}
#ifdef CONFIG_CRYPTO_HMAC
static
void
test_hmac_md5
(
void
)
{
char
*
p
;
unsigned
int
i
,
klen
;
struct
scatterlist
sg
[
2
];
char
result
[
128
];
struct
crypto_tfm
*
tfm
;
struct
hmac_md5_testvec
*
hmac_md5_tv
;
unsigned
int
tsize
;
tfm
=
crypto_alloc_tfm
(
"md5"
,
0
);
if
(
tfm
==
NULL
)
{
printk
(
"failed to load transform for md5
\n
"
);
return
;
}
printk
(
"
\n
testing hmac_md5
\n
"
);
tsize
=
sizeof
(
hmac_md5_tv_template
);
if
(
tsize
>
TVMEMSIZE
)
{
printk
(
"template (%u) too big for tvmem (%u)
\n
"
,
tsize
,
TVMEMSIZE
);
goto
out
;
}
memcpy
(
tvmem
,
hmac_md5_tv_template
,
tsize
);
hmac_md5_tv
=
(
void
*
)
tvmem
;
for
(
i
=
0
;
i
<
HMAC_MD5_TEST_VECTORS
;
i
++
)
{
printk
(
"test %u:
\n
"
,
i
+
1
);
memset
(
result
,
0
,
sizeof
(
result
));
p
=
hmac_md5_tv
[
i
].
plaintext
;
sg
[
0
].
page
=
virt_to_page
(
p
);
sg
[
0
].
offset
=
offset_in_page
(
p
);
sg
[
0
].
length
=
strlen
(
hmac_md5_tv
[
i
].
plaintext
);
klen
=
strlen
(
hmac_md5_tv
[
i
].
key
);
crypto_hmac
(
tfm
,
hmac_md5_tv
[
i
].
key
,
&
klen
,
sg
,
1
,
result
);
hexdump
(
result
,
crypto_tfm_alg_digestsize
(
tfm
));
printk
(
"%s
\n
"
,
memcmp
(
result
,
hmac_md5_tv
[
i
].
digest
,
crypto_tfm_alg_digestsize
(
tfm
))
?
"fail"
:
"pass"
);
}
printk
(
"
\n
testing hmac_md5 across pages
\n
"
);
memset
(
xbuf
,
0
,
XBUFSIZE
);
memcpy
(
&
xbuf
[
IDX1
],
"what do ya want "
,
16
);
memcpy
(
&
xbuf
[
IDX2
],
"for nothing?"
,
12
);
p
=
&
xbuf
[
IDX1
];
sg
[
0
].
page
=
virt_to_page
(
p
);
sg
[
0
].
offset
=
offset_in_page
(
p
);
sg
[
0
].
length
=
16
;
p
=
&
xbuf
[
IDX2
];
sg
[
1
].
page
=
virt_to_page
(
p
);
sg
[
1
].
offset
=
offset_in_page
(
p
);
sg
[
1
].
length
=
12
;
memset
(
result
,
0
,
sizeof
(
result
));
klen
=
strlen
(
hmac_md5_tv
[
7
].
key
);
crypto_hmac
(
tfm
,
hmac_md5_tv
[
7
].
key
,
&
klen
,
sg
,
2
,
result
);
hexdump
(
result
,
crypto_tfm_alg_digestsize
(
tfm
));
printk
(
"%s
\n
"
,
memcmp
(
result
,
hmac_md5_tv
[
7
].
digest
,
crypto_tfm_alg_digestsize
(
tfm
))
?
"fail"
:
"pass"
);
out:
crypto_free_tfm
(
tfm
);
}
static
void
test_hmac_sha1
(
void
)
{
char
*
p
;
unsigned
int
i
,
klen
;
struct
crypto_tfm
*
tfm
;
struct
hmac_sha1_testvec
*
hmac_sha1_tv
;
struct
scatterlist
sg
[
2
];
unsigned
int
tsize
;
char
result
[
SHA1_DIGEST_SIZE
];
tfm
=
crypto_alloc_tfm
(
"sha1"
,
0
);
if
(
tfm
==
NULL
)
{
printk
(
"failed to load transform for sha1
\n
"
);
return
;
}
printk
(
"
\n
testing hmac_sha1
\n
"
);
tsize
=
sizeof
(
hmac_sha1_tv_template
);
if
(
tsize
>
TVMEMSIZE
)
{
printk
(
"template (%u) too big for tvmem (%u)
\n
"
,
tsize
,
TVMEMSIZE
);
goto
out
;
}
memcpy
(
tvmem
,
hmac_sha1_tv_template
,
tsize
);
hmac_sha1_tv
=
(
void
*
)
tvmem
;
for
(
i
=
0
;
i
<
HMAC_SHA1_TEST_VECTORS
;
i
++
)
{
printk
(
"test %u:
\n
"
,
i
+
1
);
memset
(
result
,
0
,
sizeof
(
result
));
p
=
hmac_sha1_tv
[
i
].
plaintext
;
sg
[
0
].
page
=
virt_to_page
(
p
);
sg
[
0
].
offset
=
offset_in_page
(
p
);
sg
[
0
].
length
=
strlen
(
hmac_sha1_tv
[
i
].
plaintext
);
klen
=
strlen
(
hmac_sha1_tv
[
i
].
key
);
crypto_hmac
(
tfm
,
hmac_sha1_tv
[
i
].
key
,
&
klen
,
sg
,
1
,
result
);
hexdump
(
result
,
sizeof
(
result
));
printk
(
"%s
\n
"
,
memcmp
(
result
,
hmac_sha1_tv
[
i
].
digest
,
crypto_tfm_alg_digestsize
(
tfm
))
?
"fail"
:
"pass"
);
}
printk
(
"
\n
testing hmac_sha1 across pages
\n
"
);
/* setup the dummy buffer first */
memset
(
xbuf
,
0
,
XBUFSIZE
);
memcpy
(
&
xbuf
[
IDX1
],
"what do ya want "
,
16
);
memcpy
(
&
xbuf
[
IDX2
],
"for nothing?"
,
12
);
p
=
&
xbuf
[
IDX1
];
sg
[
0
].
page
=
virt_to_page
(
p
);
sg
[
0
].
offset
=
offset_in_page
(
p
);
sg
[
0
].
length
=
16
;
p
=
&
xbuf
[
IDX2
];
sg
[
1
].
page
=
virt_to_page
(
p
);
sg
[
1
].
offset
=
offset_in_page
(
p
);
sg
[
1
].
length
=
12
;
memset
(
result
,
0
,
sizeof
(
result
));
klen
=
strlen
(
hmac_sha1_tv
[
7
].
key
);
crypto_hmac
(
tfm
,
hmac_sha1_tv
[
7
].
key
,
&
klen
,
sg
,
2
,
result
);
hexdump
(
result
,
crypto_tfm_alg_digestsize
(
tfm
));
printk
(
"%s
\n
"
,
memcmp
(
result
,
hmac_sha1_tv
[
7
].
digest
,
crypto_tfm_alg_digestsize
(
tfm
))
?
"fail"
:
"pass"
);
out:
crypto_free_tfm
(
tfm
);
}
static
void
test_hmac_sha256
(
void
)
{
char
*
p
;
unsigned
int
i
,
klen
;
struct
crypto_tfm
*
tfm
;
struct
hmac_sha256_testvec
*
hmac_sha256_tv
;
struct
scatterlist
sg
[
2
];
unsigned
int
tsize
;
char
result
[
SHA256_DIGEST_SIZE
];
tfm
=
crypto_alloc_tfm
(
"sha256"
,
0
);
if
(
tfm
==
NULL
)
{
printk
(
"failed to load transform for sha256
\n
"
);
return
;
}
printk
(
"
\n
testing hmac_sha256
\n
"
);
tsize
=
sizeof
(
hmac_sha256_tv_template
);
if
(
tsize
>
TVMEMSIZE
)
{
printk
(
"template (%u) too big for tvmem (%u)
\n
"
,
tsize
,
TVMEMSIZE
);
goto
out
;
}
memcpy
(
tvmem
,
hmac_sha256_tv_template
,
tsize
);
hmac_sha256_tv
=
(
void
*
)
tvmem
;
for
(
i
=
0
;
i
<
HMAC_SHA256_TEST_VECTORS
;
i
++
)
{
printk
(
"test %u:
\n
"
,
i
+
1
);
memset
(
result
,
0
,
sizeof
(
result
));
p
=
hmac_sha256_tv
[
i
].
plaintext
;
sg
[
0
].
page
=
virt_to_page
(
p
);
sg
[
0
].
offset
=
offset_in_page
(
p
);
sg
[
0
].
length
=
strlen
(
hmac_sha256_tv
[
i
].
plaintext
);
klen
=
strlen
(
hmac_sha256_tv
[
i
].
key
);
hexdump
(
hmac_sha256_tv
[
i
].
key
,
strlen
(
hmac_sha256_tv
[
i
].
key
));
crypto_hmac
(
tfm
,
hmac_sha256_tv
[
i
].
key
,
&
klen
,
sg
,
1
,
result
);
hexdump
(
result
,
crypto_tfm_alg_digestsize
(
tfm
));
printk
(
"%s
\n
"
,
memcmp
(
result
,
hmac_sha256_tv
[
i
].
digest
,
crypto_tfm_alg_digestsize
(
tfm
))
?
"fail"
:
"pass"
);
}
out:
crypto_free_tfm
(
tfm
);
}
#endif
/* CONFIG_CRYPTO_HMAC */
static
void
test_md4
(
void
)
{
char
*
p
;
unsigned
int
i
;
struct
scatterlist
sg
[
1
];
char
result
[
128
];
struct
crypto_tfm
*
tfm
;
struct
md4_testvec
*
md4_tv
;
unsigned
int
tsize
;
printk
(
"
\n
testing md4
\n
"
);
tsize
=
sizeof
(
md4_tv_template
);
if
(
tsize
>
TVMEMSIZE
)
{
printk
(
"template (%u) too big for tvmem (%u)
\n
"
,
tsize
,
TVMEMSIZE
);
return
;
}
memcpy
(
tvmem
,
md4_tv_template
,
tsize
);
md4_tv
=
(
void
*
)
tvmem
;
tfm
=
crypto_alloc_tfm
(
"md4"
,
0
);
if
(
tfm
==
NULL
)
{
printk
(
"failed to load transform for md4
\n
"
);
return
;
}
for
(
i
=
0
;
i
<
MD4_TEST_VECTORS
;
i
++
)
{
printk
(
"test %u:
\n
"
,
i
+
1
);
memset
(
result
,
0
,
sizeof
(
result
));
p
=
md4_tv
[
i
].
plaintext
;
sg
[
0
].
page
=
virt_to_page
(
p
);
sg
[
0
].
offset
=
offset_in_page
(
p
);
sg
[
0
].
length
=
strlen
(
md4_tv
[
i
].
plaintext
);
crypto_digest_digest
(
tfm
,
sg
,
1
,
result
);
hexdump
(
result
,
crypto_tfm_alg_digestsize
(
tfm
));
printk
(
"%s
\n
"
,
memcmp
(
result
,
md4_tv
[
i
].
digest
,
crypto_tfm_alg_digestsize
(
tfm
))
?
"fail"
:
"pass"
);
}
crypto_free_tfm
(
tfm
);
}
static
void
test_sha1
(
void
)
{
char
*
p
;
unsigned
int
i
;
struct
crypto_tfm
*
tfm
;
struct
sha1_testvec
*
sha1_tv
;
struct
scatterlist
sg
[
2
];
unsigned
int
tsize
;
char
result
[
SHA1_DIGEST_SIZE
];
printk
(
"
\n
testing sha1
\n
"
);
tsize
=
sizeof
(
sha1_tv_template
);
if
(
tsize
>
TVMEMSIZE
)
{
printk
(
"template (%u) too big for tvmem (%u)
\n
"
,
tsize
,
TVMEMSIZE
);
return
;
}
memcpy
(
tvmem
,
sha1_tv_template
,
tsize
);
sha1_tv
=
(
void
*
)
tvmem
;
tfm
=
crypto_alloc_tfm
(
"sha1"
,
0
);
if
(
tfm
==
NULL
)
{
printk
(
"failed to load transform for sha1
\n
"
);
return
;
}
for
(
i
=
0
;
i
<
SHA1_TEST_VECTORS
;
i
++
)
{
printk
(
"test %u:
\n
"
,
i
+
1
);
memset
(
result
,
0
,
sizeof
(
result
));
p
=
sha1_tv
[
i
].
plaintext
;
sg
[
0
].
page
=
virt_to_page
(
p
);
sg
[
0
].
offset
=
offset_in_page
(
p
);
sg
[
0
].
length
=
strlen
(
sha1_tv
[
i
].
plaintext
);
crypto_digest_init
(
tfm
);
crypto_digest_update
(
tfm
,
sg
,
1
);
crypto_digest_final
(
tfm
,
result
);
hexdump
(
result
,
crypto_tfm_alg_digestsize
(
tfm
));
printk
(
"%s
\n
"
,
memcmp
(
result
,
sha1_tv
[
i
].
digest
,
crypto_tfm_alg_digestsize
(
tfm
))
?
"fail"
:
"pass"
);
}
printk
(
"
\n
testing sha1 across pages
\n
"
);
/* setup the dummy buffer first */
memset
(
xbuf
,
0
,
XBUFSIZE
);
memcpy
(
&
xbuf
[
IDX1
],
"abcdbcdecdefdefgefghfghighij"
,
28
);
memcpy
(
&
xbuf
[
IDX2
],
"hijkijkljklmklmnlmnomnopnopq"
,
28
);
p
=
&
xbuf
[
IDX1
];
sg
[
0
].
page
=
virt_to_page
(
p
);
sg
[
0
].
offset
=
offset_in_page
(
p
);
sg
[
0
].
length
=
28
;
p
=
&
xbuf
[
IDX2
];
sg
[
1
].
page
=
virt_to_page
(
p
);
sg
[
1
].
offset
=
offset_in_page
(
p
);
sg
[
1
].
length
=
28
;
memset
(
result
,
0
,
sizeof
(
result
));
crypto_digest_digest
(
tfm
,
sg
,
2
,
result
);
hexdump
(
result
,
crypto_tfm_alg_digestsize
(
tfm
));
printk
(
"%s
\n
"
,
memcmp
(
result
,
sha1_tv
[
1
].
digest
,
crypto_tfm_alg_digestsize
(
tfm
))
?
"fail"
:
"pass"
);
crypto_free_tfm
(
tfm
);
}
static
void
test_sha256
(
void
)
{
char
*
p
;
unsigned
int
i
;
struct
crypto_tfm
*
tfm
;
struct
sha256_testvec
*
sha256_tv
;
struct
scatterlist
sg
[
2
];
unsigned
int
tsize
;
char
result
[
SHA256_DIGEST_SIZE
];
printk
(
"
\n
testing sha256
\n
"
);
tsize
=
sizeof
(
sha256_tv_template
);
if
(
tsize
>
TVMEMSIZE
)
{
printk
(
"template (%u) too big for tvmem (%u)
\n
"
,
tsize
,
TVMEMSIZE
);
return
;
}
memcpy
(
tvmem
,
sha256_tv_template
,
tsize
);
sha256_tv
=
(
void
*
)
tvmem
;
tfm
=
crypto_alloc_tfm
(
"sha256"
,
0
);
if
(
tfm
==
NULL
)
{
printk
(
"failed to load transform for sha256
\n
"
);
return
;
}
for
(
i
=
0
;
i
<
SHA256_TEST_VECTORS
;
i
++
)
{
printk
(
"test %u:
\n
"
,
i
+
1
);
memset
(
result
,
0
,
sizeof
(
result
));
p
=
sha256_tv
[
i
].
plaintext
;
sg
[
0
].
page
=
virt_to_page
(
p
);
sg
[
0
].
offset
=
offset_in_page
(
p
);
sg
[
0
].
length
=
strlen
(
sha256_tv
[
i
].
plaintext
);
crypto_digest_init
(
tfm
);
crypto_digest_update
(
tfm
,
sg
,
1
);
crypto_digest_final
(
tfm
,
result
);
hexdump
(
result
,
crypto_tfm_alg_digestsize
(
tfm
));
printk
(
"%s
\n
"
,
memcmp
(
result
,
sha256_tv
[
i
].
digest
,
crypto_tfm_alg_digestsize
(
tfm
))
?
"fail"
:
"pass"
);
}
printk
(
"
\n
testing sha256 across pages
\n
"
);
/* setup the dummy buffer first */
memset
(
xbuf
,
0
,
XBUFSIZE
);
memcpy
(
&
xbuf
[
IDX1
],
"abcdbcdecdefdefgefghfghighij"
,
28
);
memcpy
(
&
xbuf
[
IDX2
],
"hijkijkljklmklmnlmnomnopnopq"
,
28
);
p
=
&
xbuf
[
IDX1
];
sg
[
0
].
page
=
virt_to_page
(
p
);
sg
[
0
].
offset
=
offset_in_page
(
p
);
sg
[
0
].
length
=
28
;
p
=
&
xbuf
[
IDX2
];
sg
[
1
].
page
=
virt_to_page
(
p
);
sg
[
1
].
offset
=
offset_in_page
(
p
);
sg
[
1
].
length
=
28
;
memset
(
result
,
0
,
sizeof
(
result
));
crypto_digest_digest
(
tfm
,
sg
,
2
,
result
);
hexdump
(
result
,
crypto_tfm_alg_digestsize
(
tfm
));
printk
(
"%s
\n
"
,
memcmp
(
result
,
sha256_tv
[
1
].
digest
,
crypto_tfm_alg_digestsize
(
tfm
))
?
"fail"
:
"pass"
);
crypto_free_tfm
(
tfm
);
}
static
void
test_sha384
(
void
)
{
char
*
p
;
unsigned
int
i
;
struct
crypto_tfm
*
tfm
;
struct
sha384_testvec
*
sha384_tv
;
struct
scatterlist
sg
[
2
];
unsigned
int
tsize
;
char
result
[
SHA384_DIGEST_SIZE
];
printk
(
"
\n
testing sha384
\n
"
);
tsize
=
sizeof
(
sha384_tv_template
);
if
(
tsize
>
TVMEMSIZE
)
{
printk
(
"template (%u) too big for tvmem (%u)
\n
"
,
tsize
,
TVMEMSIZE
);
return
;
}
memcpy
(
tvmem
,
sha384_tv_template
,
tsize
);
sha384_tv
=
(
void
*
)
tvmem
;
tfm
=
crypto_alloc_tfm
(
"sha384"
,
0
);
if
(
tfm
==
NULL
)
{
printk
(
"failed to load transform for sha384
\n
"
);
return
;
}
for
(
i
=
0
;
i
<
SHA384_TEST_VECTORS
;
i
++
)
{
printk
(
"test %u:
\n
"
,
i
+
1
);
memset
(
result
,
0
,
sizeof
(
result
));
p
=
sha384_tv
[
i
].
plaintext
;
sg
[
0
].
page
=
virt_to_page
(
p
);
sg
[
0
].
offset
=
offset_in_page
(
p
);
sg
[
0
].
length
=
strlen
(
sha384_tv
[
i
].
plaintext
);
crypto_digest_init
(
tfm
);
crypto_digest_update
(
tfm
,
sg
,
1
);
crypto_digest_final
(
tfm
,
result
);
hexdump
(
result
,
crypto_tfm_alg_digestsize
(
tfm
));
printk
(
"%s
\n
"
,
memcmp
(
result
,
sha384_tv
[
i
].
digest
,
crypto_tfm_alg_digestsize
(
tfm
))
?
"fail"
:
"pass"
);
}
crypto_free_tfm
(
tfm
);
}
static
void
test_sha512
(
void
)
{
char
*
p
;
unsigned
int
i
;
struct
crypto_tfm
*
tfm
;
struct
sha512_testvec
*
sha512_tv
;
struct
scatterlist
sg
[
2
];
unsigned
int
tsize
;
char
result
[
SHA512_DIGEST_SIZE
];
printk
(
"
\n
testing sha512
\n
"
);
tsize
=
sizeof
(
sha512_tv_template
);
if
(
tsize
>
TVMEMSIZE
)
{
printk
(
"template (%u) too big for tvmem (%u)
\n
"
,
tsize
,
TVMEMSIZE
);
return
;
}
memcpy
(
tvmem
,
sha512_tv_template
,
tsize
);
sha512_tv
=
(
void
*
)
tvmem
;
tfm
=
crypto_alloc_tfm
(
"sha512"
,
0
);
if
(
tfm
==
NULL
)
{
printk
(
"failed to load transform for sha512
\n
"
);
return
;
}
for
(
i
=
0
;
i
<
SHA512_TEST_VECTORS
;
i
++
)
{
printk
(
"test %u:
\n
"
,
i
+
1
);
memset
(
result
,
0
,
sizeof
(
result
));
p
=
sha512_tv
[
i
].
plaintext
;
sg
[
0
].
page
=
virt_to_page
(
p
);
sg
[
0
].
offset
=
offset_in_page
(
p
);
sg
[
0
].
length
=
strlen
(
sha512_tv
[
i
].
plaintext
);
crypto_digest_init
(
tfm
);
crypto_digest_update
(
tfm
,
sg
,
1
);
crypto_digest_final
(
tfm
,
result
);
hexdump
(
result
,
crypto_tfm_alg_digestsize
(
tfm
));
printk
(
"%s
\n
"
,
memcmp
(
result
,
sha512_tv
[
i
].
digest
,
crypto_tfm_alg_digestsize
(
tfm
))
?
"fail"
:
"pass"
);
}
crypto_free_tfm
(
tfm
);
}
void
test_des
(
void
)
{
unsigned
int
ret
,
i
,
len
;
unsigned
int
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 des encryption
\n
"
);
tsize
=
sizeof
(
des_enc_tv_template
);
if
(
tsize
>
TVMEMSIZE
)
{
printk
(
"template (%u) too big for tvmem (%u)
\n
"
,
tsize
,
TVMEMSIZE
);
return
;
}
memcpy
(
tvmem
,
des_enc_tv_template
,
tsize
);
des_tv
=
(
void
*
)
tvmem
;
tfm
=
crypto_alloc_tfm
(
"des"
,
0
);
if
(
tfm
==
NULL
)
{
printk
(
"failed to load transform for des (default ecb)
\n
"
);
return
;
}
for
(
i
=
0
;
i
<
DES_ENC_TEST_VECTORS
;
i
++
)
{
printk
(
"test %u:
\n
"
,
i
+
1
);
key
=
des_tv
[
i
].
key
;
tfm
->
crt_flags
|=
CRYPTO_TFM_REQ_WEAK_KEY
;
ret
=
crypto_cipher_setkey
(
tfm
,
key
,
8
);
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
=
offset_in_page
(
p
);
sg
[
0
].
length
=
len
;
ret
=
crypto_cipher_encrypt
(
tfm
,
sg
,
sg
,
len
);
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 des ecb encryption across pages
\n
"
);
i
=
5
;
key
=
des_tv
[
i
].
key
;
tfm
->
crt_flags
=
0
;
hexdump
(
key
,
8
);
ret
=
crypto_cipher_setkey
(
tfm
,
key
,
8
);
if
(
ret
)
{
printk
(
"setkey() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
goto
out
;
}
/* setup the dummy buffer first */
memset
(
xbuf
,
0
,
sizeof
(
xbuf
));
memcpy
(
&
xbuf
[
IDX1
],
des_tv
[
i
].
plaintext
,
8
);
memcpy
(
&
xbuf
[
IDX2
],
des_tv
[
i
].
plaintext
+
8
,
8
);
p
=
&
xbuf
[
IDX1
];
sg
[
0
].
page
=
virt_to_page
(
p
);
sg
[
0
].
offset
=
offset_in_page
(
p
);
sg
[
0
].
length
=
8
;
p
=
&
xbuf
[
IDX2
];
sg
[
1
].
page
=
virt_to_page
(
p
);
sg
[
1
].
offset
=
offset_in_page
(
p
);
sg
[
1
].
length
=
8
;
ret
=
crypto_cipher_encrypt
(
tfm
,
sg
,
sg
,
16
);
if
(
ret
)
{
printk
(
"encrypt() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
goto
out
;
}
printk
(
"page 1
\n
"
);
q
=
kmap
(
sg
[
0
].
page
)
+
sg
[
0
].
offset
;
hexdump
(
q
,
8
);
printk
(
"%s
\n
"
,
memcmp
(
q
,
des_tv
[
i
].
result
,
8
)
?
"fail"
:
"pass"
);
printk
(
"page 2
\n
"
);
q
=
kmap
(
sg
[
1
].
page
)
+
sg
[
1
].
offset
;
hexdump
(
q
,
8
);
printk
(
"%s
\n
"
,
memcmp
(
q
,
des_tv
[
i
].
result
+
8
,
8
)
?
"fail"
:
"pass"
);
printk
(
"
\n
testing des ecb encryption chunking scenario A
\n
"
);
/*
* Scenario A:
*
* F1 F2 F3
* [8 + 6] [2 + 8] [8]
* ^^^^^^ ^
* a b c
*
* Chunking should begin at a, then end with b, and
* continue encrypting at an offset of 2 until c.
*
*/
i
=
7
;
key
=
des_tv
[
i
].
key
;
tfm
->
crt_flags
=
0
;
ret
=
crypto_cipher_setkey
(
tfm
,
key
,
8
);
if
(
ret
)
{
printk
(
"setkey() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
goto
out
;
}
/* setup the dummy buffer first */
memset
(
xbuf
,
0
,
sizeof
(
xbuf
));
/* Frag 1: 8 + 6 */
memcpy
(
&
xbuf
[
IDX3
],
des_tv
[
i
].
plaintext
,
14
);
/* Frag 2: 2 + 8 */
memcpy
(
&
xbuf
[
IDX4
],
des_tv
[
i
].
plaintext
+
14
,
10
);
/* Frag 3: 8 */
memcpy
(
&
xbuf
[
IDX5
],
des_tv
[
i
].
plaintext
+
24
,
8
);
p
=
&
xbuf
[
IDX3
];
sg
[
0
].
page
=
virt_to_page
(
p
);
sg
[
0
].
offset
=
offset_in_page
(
p
);
sg
[
0
].
length
=
14
;
p
=
&
xbuf
[
IDX4
];
sg
[
1
].
page
=
virt_to_page
(
p
);
sg
[
1
].
offset
=
offset_in_page
(
p
);
sg
[
1
].
length
=
10
;
p
=
&
xbuf
[
IDX5
];
sg
[
2
].
page
=
virt_to_page
(
p
);
sg
[
2
].
offset
=
offset_in_page
(
p
);
sg
[
2
].
length
=
8
;
ret
=
crypto_cipher_encrypt
(
tfm
,
sg
,
sg
,
32
);
if
(
ret
)
{
printk
(
"decrypt() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
goto
out
;
}
printk
(
"page 1
\n
"
);
q
=
kmap
(
sg
[
0
].
page
)
+
sg
[
0
].
offset
;
hexdump
(
q
,
14
);
printk
(
"%s
\n
"
,
memcmp
(
q
,
des_tv
[
i
].
result
,
14
)
?
"fail"
:
"pass"
);
printk
(
"page 2
\n
"
);
q
=
kmap
(
sg
[
1
].
page
)
+
sg
[
1
].
offset
;
hexdump
(
q
,
10
);
printk
(
"%s
\n
"
,
memcmp
(
q
,
des_tv
[
i
].
result
+
14
,
10
)
?
"fail"
:
"pass"
);
printk
(
"page 3
\n
"
);
q
=
kmap
(
sg
[
2
].
page
)
+
sg
[
2
].
offset
;
hexdump
(
q
,
8
);
printk
(
"%s
\n
"
,
memcmp
(
q
,
des_tv
[
i
].
result
+
24
,
8
)
?
"fail"
:
"pass"
);
printk
(
"
\n
testing des ecb encryption chunking scenario B
\n
"
);
/*
* Scenario B:
*
* F1 F2 F3 F4
* [2] [1] [3] [2 + 8 + 8]
*/
i
=
7
;
key
=
des_tv
[
i
].
key
;
tfm
->
crt_flags
=
0
;
ret
=
crypto_cipher_setkey
(
tfm
,
key
,
8
);
if
(
ret
)
{
printk
(
"setkey() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
goto
out
;
}
/* setup the dummy buffer first */
memset
(
xbuf
,
0
,
sizeof
(
xbuf
));
/* Frag 1: 2 */
memcpy
(
&
xbuf
[
IDX3
],
des_tv
[
i
].
plaintext
,
2
);
/* Frag 2: 1 */
memcpy
(
&
xbuf
[
IDX4
],
des_tv
[
i
].
plaintext
+
2
,
1
);
/* Frag 3: 3 */
memcpy
(
&
xbuf
[
IDX5
],
des_tv
[
i
].
plaintext
+
3
,
3
);
/* Frag 4: 2 + 8 + 8 */
memcpy
(
&
xbuf
[
IDX6
],
des_tv
[
i
].
plaintext
+
6
,
18
);
p
=
&
xbuf
[
IDX3
];
sg
[
0
].
page
=
virt_to_page
(
p
);
sg
[
0
].
offset
=
offset_in_page
(
p
);
sg
[
0
].
length
=
2
;
p
=
&
xbuf
[
IDX4
];
sg
[
1
].
page
=
virt_to_page
(
p
);
sg
[
1
].
offset
=
offset_in_page
(
p
);
sg
[
1
].
length
=
1
;
p
=
&
xbuf
[
IDX5
];
sg
[
2
].
page
=
virt_to_page
(
p
);
sg
[
2
].
offset
=
offset_in_page
(
p
);
sg
[
2
].
length
=
3
;
p
=
&
xbuf
[
IDX6
];
sg
[
3
].
page
=
virt_to_page
(
p
);
sg
[
3
].
offset
=
offset_in_page
(
p
);
sg
[
3
].
length
=
18
;
ret
=
crypto_cipher_encrypt
(
tfm
,
sg
,
sg
,
24
);
if
(
ret
)
{
printk
(
"encrypt() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
goto
out
;
}
printk
(
"page 1
\n
"
);
q
=
kmap
(
sg
[
0
].
page
)
+
sg
[
0
].
offset
;
hexdump
(
q
,
2
);
printk
(
"%s
\n
"
,
memcmp
(
q
,
des_tv
[
i
].
result
,
2
)
?
"fail"
:
"pass"
);
printk
(
"page 2
\n
"
);
q
=
kmap
(
sg
[
1
].
page
)
+
sg
[
1
].
offset
;
hexdump
(
q
,
1
);
printk
(
"%s
\n
"
,
memcmp
(
q
,
des_tv
[
i
].
result
+
2
,
1
)
?
"fail"
:
"pass"
);
printk
(
"page 3
\n
"
);
q
=
kmap
(
sg
[
2
].
page
)
+
sg
[
2
].
offset
;
hexdump
(
q
,
3
);
printk
(
"%s
\n
"
,
memcmp
(
q
,
des_tv
[
i
].
result
+
3
,
3
)
?
"fail"
:
"pass"
);
printk
(
"page 4
\n
"
);
q
=
kmap
(
sg
[
3
].
page
)
+
sg
[
3
].
offset
;
hexdump
(
q
,
18
);
printk
(
"%s
\n
"
,
memcmp
(
q
,
des_tv
[
i
].
result
+
6
,
18
)
?
"fail"
:
"pass"
);
printk
(
"
\n
testing des ecb encryption chunking scenario C
\n
"
);
/*
* Scenario B:
*
* F1 F2 F3 F4 F5
* [2] [2] [2] [2] [8]
*/
i
=
7
;
key
=
des_tv
[
i
].
key
;
tfm
->
crt_flags
=
0
;
ret
=
crypto_cipher_setkey
(
tfm
,
key
,
8
);
if
(
ret
)
{
printk
(
"setkey() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
goto
out
;
}
/* setup the dummy buffer first */
memset
(
xbuf
,
0
,
sizeof
(
xbuf
));
/* Frag 1: 2 */
memcpy
(
&
xbuf
[
IDX3
],
des_tv
[
i
].
plaintext
,
2
);
/* Frag 2: 2 */
memcpy
(
&
xbuf
[
IDX4
],
des_tv
[
i
].
plaintext
+
2
,
2
);
/* Frag 3: 2 */
memcpy
(
&
xbuf
[
IDX5
],
des_tv
[
i
].
plaintext
+
4
,
2
);
/* Frag 4: 2 */
memcpy
(
&
xbuf
[
IDX6
],
des_tv
[
i
].
plaintext
+
6
,
2
);
/* Frag 5: 8 */
memcpy
(
&
xbuf
[
IDX7
],
des_tv
[
i
].
plaintext
+
8
,
8
);
p
=
&
xbuf
[
IDX3
];
sg
[
0
].
page
=
virt_to_page
(
p
);
sg
[
0
].
offset
=
offset_in_page
(
p
);
sg
[
0
].
length
=
2
;
p
=
&
xbuf
[
IDX4
];
sg
[
1
].
page
=
virt_to_page
(
p
);
sg
[
1
].
offset
=
offset_in_page
(
p
);
sg
[
1
].
length
=
2
;
p
=
&
xbuf
[
IDX5
];
sg
[
2
].
page
=
virt_to_page
(
p
);
sg
[
2
].
offset
=
offset_in_page
(
p
);
sg
[
2
].
length
=
2
;
p
=
&
xbuf
[
IDX6
];
sg
[
3
].
page
=
virt_to_page
(
p
);
sg
[
3
].
offset
=
offset_in_page
(
p
);
sg
[
3
].
length
=
2
;
p
=
&
xbuf
[
IDX7
];
sg
[
4
].
page
=
virt_to_page
(
p
);
sg
[
4
].
offset
=
offset_in_page
(
p
);
sg
[
4
].
length
=
8
;
ret
=
crypto_cipher_encrypt
(
tfm
,
sg
,
sg
,
16
);
if
(
ret
)
{
printk
(
"encrypt() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
goto
out
;
}
printk
(
"page 1
\n
"
);
q
=
kmap
(
sg
[
0
].
page
)
+
sg
[
0
].
offset
;
hexdump
(
q
,
2
);
printk
(
"%s
\n
"
,
memcmp
(
q
,
des_tv
[
i
].
result
,
2
)
?
"fail"
:
"pass"
);
printk
(
"page 2
\n
"
);
q
=
kmap
(
sg
[
1
].
page
)
+
sg
[
1
].
offset
;
hexdump
(
q
,
2
);
printk
(
"%s
\n
"
,
memcmp
(
q
,
des_tv
[
i
].
result
+
2
,
2
)
?
"fail"
:
"pass"
);
printk
(
"page 3
\n
"
);
q
=
kmap
(
sg
[
2
].
page
)
+
sg
[
2
].
offset
;
hexdump
(
q
,
2
);
printk
(
"%s
\n
"
,
memcmp
(
q
,
des_tv
[
i
].
result
+
4
,
2
)
?
"fail"
:
"pass"
);
printk
(
"page 4
\n
"
);
q
=
kmap
(
sg
[
3
].
page
)
+
sg
[
3
].
offset
;
hexdump
(
q
,
2
);
printk
(
"%s
\n
"
,
memcmp
(
q
,
des_tv
[
i
].
result
+
6
,
2
)
?
"fail"
:
"pass"
);
printk
(
"page 5
\n
"
);
q
=
kmap
(
sg
[
4
].
page
)
+
sg
[
4
].
offset
;
hexdump
(
q
,
8
);
printk
(
"%s
\n
"
,
memcmp
(
q
,
des_tv
[
i
].
result
+
8
,
8
)
?
"fail"
:
"pass"
);
printk
(
"
\n
testing des ecb encryption chunking scenario D
\n
"
);
/*
* Scenario D, torture test, one byte per frag.
*/
i
=
7
;
key
=
des_tv
[
i
].
key
;
tfm
->
crt_flags
=
0
;
ret
=
crypto_cipher_setkey
(
tfm
,
key
,
8
);
if
(
ret
)
{
printk
(
"setkey() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
goto
out
;
}
/* setup the dummy buffer first */
memset
(
xbuf
,
0
,
XBUFSIZE
);
xbuf
[
IDX1
]
=
des_tv
[
i
].
plaintext
[
0
];
xbuf
[
IDX2
]
=
des_tv
[
i
].
plaintext
[
1
];
xbuf
[
IDX3
]
=
des_tv
[
i
].
plaintext
[
2
];
xbuf
[
IDX4
]
=
des_tv
[
i
].
plaintext
[
3
];
xbuf
[
IDX5
]
=
des_tv
[
i
].
plaintext
[
4
];
xbuf
[
IDX6
]
=
des_tv
[
i
].
plaintext
[
5
];
xbuf
[
IDX7
]
=
des_tv
[
i
].
plaintext
[
6
];
xbuf
[
IDX8
]
=
des_tv
[
i
].
plaintext
[
7
];
p
=
&
xbuf
[
IDX1
];
sg
[
0
].
page
=
virt_to_page
(
p
);
sg
[
0
].
offset
=
offset_in_page
(
p
);
sg
[
0
].
length
=
1
;
p
=
&
xbuf
[
IDX2
];
sg
[
1
].
page
=
virt_to_page
(
p
);
sg
[
1
].
offset
=
offset_in_page
(
p
);
sg
[
1
].
length
=
1
;
p
=
&
xbuf
[
IDX3
];
sg
[
2
].
page
=
virt_to_page
(
p
);
sg
[
2
].
offset
=
offset_in_page
(
p
);
sg
[
2
].
length
=
1
;
p
=
&
xbuf
[
IDX4
];
sg
[
3
].
page
=
virt_to_page
(
p
);
sg
[
3
].
offset
=
offset_in_page
(
p
);
sg
[
3
].
length
=
1
;
p
=
&
xbuf
[
IDX5
];
sg
[
4
].
page
=
virt_to_page
(
p
);
sg
[
4
].
offset
=
offset_in_page
(
p
);
sg
[
4
].
length
=
1
;
p
=
&
xbuf
[
IDX6
];
sg
[
5
].
page
=
virt_to_page
(
p
);
sg
[
5
].
offset
=
offset_in_page
(
p
);
sg
[
5
].
length
=
1
;
p
=
&
xbuf
[
IDX7
];
sg
[
6
].
page
=
virt_to_page
(
p
);
sg
[
6
].
offset
=
offset_in_page
(
p
);
sg
[
6
].
length
=
1
;
p
=
&
xbuf
[
IDX8
];
sg
[
7
].
page
=
virt_to_page
(
p
);
sg
[
7
].
offset
=
offset_in_page
(
p
);
sg
[
7
].
length
=
1
;
ret
=
crypto_cipher_encrypt
(
tfm
,
sg
,
sg
,
8
);
if
(
ret
)
{
printk
(
"encrypt() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
goto
out
;
}
for
(
i
=
0
;
i
<
8
;
i
++
)
res
[
i
]
=
*
(
char
*
)
(
kmap
(
sg
[
i
].
page
)
+
sg
[
i
].
offset
);
hexdump
(
res
,
8
);
printk
(
"%s
\n
"
,
memcmp
(
res
,
des_tv
[
7
].
result
,
8
)
?
"fail"
:
"pass"
);
printk
(
"
\n
testing des decryption
\n
"
);
tsize
=
sizeof
(
des_dec_tv_template
);
if
(
tsize
>
TVMEMSIZE
)
{
printk
(
"template (%u) too big for tvmem (%u)
\n
"
,
tsize
,
TVMEMSIZE
);
return
;
}
memcpy
(
tvmem
,
des_dec_tv_template
,
tsize
);
des_tv
=
(
void
*
)
tvmem
;
for
(
i
=
0
;
i
<
DES_DEC_TEST_VECTORS
;
i
++
)
{
printk
(
"test %u:
\n
"
,
i
+
1
);
key
=
des_tv
[
i
].
key
;
tfm
->
crt_flags
=
0
;
ret
=
crypto_cipher_setkey
(
tfm
,
key
,
8
);
if
(
ret
)
{
printk
(
"setkey() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
goto
out
;
}
len
=
des_tv
[
i
].
len
;
p
=
des_tv
[
i
].
plaintext
;
sg
[
0
].
page
=
virt_to_page
(
p
);
sg
[
0
].
offset
=
offset_in_page
(
p
);
sg
[
0
].
length
=
len
;
ret
=
crypto_cipher_decrypt
(
tfm
,
sg
,
sg
,
sg
[
0
].
length
);
if
(
ret
)
{
printk
(
"des_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"
);
}
printk
(
"
\n
testing des ecb decryption across pages
\n
"
);
i
=
6
;
key
=
des_tv
[
i
].
key
;
tfm
->
crt_flags
=
0
;
ret
=
crypto_cipher_setkey
(
tfm
,
key
,
8
);
if
(
ret
)
{
printk
(
"setkey() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
goto
out
;
}
/* setup the dummy buffer first */
memset
(
xbuf
,
0
,
sizeof
(
xbuf
));
memcpy
(
&
xbuf
[
IDX1
],
des_tv
[
i
].
plaintext
,
8
);
memcpy
(
&
xbuf
[
IDX2
],
des_tv
[
i
].
plaintext
+
8
,
8
);
p
=
&
xbuf
[
IDX1
];
sg
[
0
].
page
=
virt_to_page
(
p
);
sg
[
0
].
offset
=
offset_in_page
(
p
);
sg
[
0
].
length
=
8
;
p
=
&
xbuf
[
IDX2
];
sg
[
1
].
page
=
virt_to_page
(
p
);
sg
[
1
].
offset
=
offset_in_page
(
p
);
sg
[
1
].
length
=
8
;
ret
=
crypto_cipher_decrypt
(
tfm
,
sg
,
sg
,
16
);
if
(
ret
)
{
printk
(
"decrypt() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
goto
out
;
}
printk
(
"page 1
\n
"
);
q
=
kmap
(
sg
[
0
].
page
)
+
sg
[
0
].
offset
;
hexdump
(
q
,
8
);
printk
(
"%s
\n
"
,
memcmp
(
q
,
des_tv
[
i
].
result
,
8
)
?
"fail"
:
"pass"
);
printk
(
"page 2
\n
"
);
q
=
kmap
(
sg
[
1
].
page
)
+
sg
[
1
].
offset
;
hexdump
(
q
,
8
);
printk
(
"%s
\n
"
,
memcmp
(
q
,
des_tv
[
i
].
result
+
8
,
8
)
?
"fail"
:
"pass"
);
/*
* Scenario E:
*
* F1 F2 F3
* [3] [5 + 7] [1]
*
*/
printk
(
"
\n
testing des ecb decryption chunking scenario E
\n
"
);
i
=
2
;
key
=
des_tv
[
i
].
key
;
tfm
->
crt_flags
=
0
;
ret
=
crypto_cipher_setkey
(
tfm
,
key
,
8
);
if
(
ret
)
{
printk
(
"setkey() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
goto
out
;
}
/* setup the dummy buffer first */
memset
(
xbuf
,
0
,
sizeof
(
xbuf
));
memcpy
(
&
xbuf
[
IDX1
],
des_tv
[
i
].
plaintext
,
3
);
memcpy
(
&
xbuf
[
IDX2
],
des_tv
[
i
].
plaintext
+
3
,
12
);
memcpy
(
&
xbuf
[
IDX3
],
des_tv
[
i
].
plaintext
+
15
,
1
);
p
=
&
xbuf
[
IDX1
];
sg
[
0
].
page
=
virt_to_page
(
p
);
sg
[
0
].
offset
=
offset_in_page
(
p
);
sg
[
0
].
length
=
3
;
p
=
&
xbuf
[
IDX2
];
sg
[
1
].
page
=
virt_to_page
(
p
);
sg
[
1
].
offset
=
offset_in_page
(
p
);
sg
[
1
].
length
=
12
;
p
=
&
xbuf
[
IDX3
];
sg
[
2
].
page
=
virt_to_page
(
p
);
sg
[
2
].
offset
=
offset_in_page
(
p
);
sg
[
2
].
length
=
1
;
ret
=
crypto_cipher_decrypt
(
tfm
,
sg
,
sg
,
16
);
if
(
ret
)
{
printk
(
"decrypt() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
goto
out
;
}
printk
(
"page 1
\n
"
);
q
=
kmap
(
sg
[
0
].
page
)
+
sg
[
0
].
offset
;
hexdump
(
q
,
3
);
printk
(
"%s
\n
"
,
memcmp
(
q
,
des_tv
[
i
].
result
,
3
)
?
"fail"
:
"pass"
);
printk
(
"page 2
\n
"
);
q
=
kmap
(
sg
[
1
].
page
)
+
sg
[
1
].
offset
;
hexdump
(
q
,
12
);
printk
(
"%s
\n
"
,
memcmp
(
q
,
des_tv
[
i
].
result
+
3
,
12
)
?
"fail"
:
"pass"
);
printk
(
"page 3
\n
"
);
q
=
kmap
(
sg
[
2
].
page
)
+
sg
[
2
].
offset
;
hexdump
(
q
,
1
);
printk
(
"%s
\n
"
,
memcmp
(
q
,
des_tv
[
i
].
result
+
15
,
1
)
?
"fail"
:
"pass"
);
crypto_free_tfm
(
tfm
);
tfm
=
crypto_alloc_tfm
(
"des"
,
CRYPTO_TFM_MODE_CBC
);
if
(
tfm
==
NULL
)
{
printk
(
"failed to load transform for des cbc
\n
"
);
return
;
}
printk
(
"
\n
testing des cbc encryption
\n
"
);
tsize
=
sizeof
(
des_cbc_enc_tv_template
);
if
(
tsize
>
TVMEMSIZE
)
{
printk
(
"template (%u) too big for tvmem (%u)
\n
"
,
tsize
,
TVMEMSIZE
);
return
;
}
memcpy
(
tvmem
,
des_cbc_enc_tv_template
,
tsize
);
des_tv
=
(
void
*
)
tvmem
;
crypto_cipher_set_iv
(
tfm
,
des_tv
[
i
].
iv
,
crypto_tfm_alg_ivsize
(
tfm
));
crypto_cipher_get_iv
(
tfm
,
res
,
crypto_tfm_alg_ivsize
(
tfm
));
if
(
memcmp
(
res
,
des_tv
[
i
].
iv
,
sizeof
(
res
)))
{
printk
(
"crypto_cipher_[set|get]_iv() failed
\n
"
);
goto
out
;
}
for
(
i
=
0
;
i
<
DES_CBC_ENC_TEST_VECTORS
;
i
++
)
{
printk
(
"test %u:
\n
"
,
i
+
1
);
key
=
des_tv
[
i
].
key
;
ret
=
crypto_cipher_setkey
(
tfm
,
key
,
8
);
if
(
ret
)
{
printk
(
"setkey() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
goto
out
;
}
len
=
des_tv
[
i
].
len
;
p
=
des_tv
[
i
].
plaintext
;
sg
[
0
].
page
=
virt_to_page
(
p
);
sg
[
0
].
offset
=
offset_in_page
(
p
);
sg
[
0
].
length
=
len
;
crypto_cipher_set_iv
(
tfm
,
des_tv
[
i
].
iv
,
crypto_tfm_alg_ivsize
(
tfm
));
ret
=
crypto_cipher_encrypt
(
tfm
,
sg
,
sg
,
len
);
if
(
ret
)
{
printk
(
"des_cbc_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"
);
}
crypto_free_tfm
(
tfm
);
/*
* Scenario F:
*
* F1 F2
* [8 + 5] [3 + 8]
*
*/
printk
(
"
\n
testing des cbc encryption chunking scenario F
\n
"
);
i
=
4
;
tfm
=
crypto_alloc_tfm
(
"des"
,
CRYPTO_TFM_MODE_CBC
);
if
(
tfm
==
NULL
)
{
printk
(
"failed to load transform for CRYPTO_ALG_DES_CCB
\n
"
);
return
;
}
tfm
->
crt_flags
=
0
;
key
=
des_tv
[
i
].
key
;
ret
=
crypto_cipher_setkey
(
tfm
,
key
,
8
);
if
(
ret
)
{
printk
(
"setkey() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
goto
out
;
}
/* setup the dummy buffer first */
memset
(
xbuf
,
0
,
sizeof
(
xbuf
));
memcpy
(
&
xbuf
[
IDX1
],
des_tv
[
i
].
plaintext
,
13
);
memcpy
(
&
xbuf
[
IDX2
],
des_tv
[
i
].
plaintext
+
13
,
11
);
p
=
&
xbuf
[
IDX1
];
sg
[
0
].
page
=
virt_to_page
(
p
);
sg
[
0
].
offset
=
offset_in_page
(
p
);
sg
[
0
].
length
=
13
;
p
=
&
xbuf
[
IDX2
];
sg
[
1
].
page
=
virt_to_page
(
p
);
sg
[
1
].
offset
=
offset_in_page
(
p
);
sg
[
1
].
length
=
11
;
crypto_cipher_set_iv
(
tfm
,
des_tv
[
i
].
iv
,
crypto_tfm_alg_ivsize
(
tfm
));
ret
=
crypto_cipher_encrypt
(
tfm
,
sg
,
sg
,
24
);
if
(
ret
)
{
printk
(
"des_cbc_decrypt() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
goto
out
;
}
printk
(
"page 1
\n
"
);
q
=
kmap
(
sg
[
0
].
page
)
+
sg
[
0
].
offset
;
hexdump
(
q
,
13
);
printk
(
"%s
\n
"
,
memcmp
(
q
,
des_tv
[
i
].
result
,
13
)
?
"fail"
:
"pass"
);
printk
(
"page 2
\n
"
);
q
=
kmap
(
sg
[
1
].
page
)
+
sg
[
1
].
offset
;
hexdump
(
q
,
11
);
printk
(
"%s
\n
"
,
memcmp
(
q
,
des_tv
[
i
].
result
+
13
,
11
)
?
"fail"
:
"pass"
);
tsize
=
sizeof
(
des_cbc_dec_tv_template
);
if
(
tsize
>
TVMEMSIZE
)
{
printk
(
"template (%u) too big for tvmem (%u)
\n
"
,
tsize
,
TVMEMSIZE
);
return
;
}
memcpy
(
tvmem
,
des_cbc_dec_tv_template
,
tsize
);
des_tv
=
(
void
*
)
tvmem
;
printk
(
"
\n
testing des cbc decryption
\n
"
);
for
(
i
=
0
;
i
<
DES_CBC_DEC_TEST_VECTORS
;
i
++
)
{
printk
(
"test %u:
\n
"
,
i
+
1
);
tfm
->
crt_flags
=
0
;
key
=
des_tv
[
i
].
key
;
ret
=
crypto_cipher_setkey
(
tfm
,
key
,
8
);
if
(
ret
)
{
printk
(
"setkey() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
goto
out
;
}
len
=
des_tv
[
i
].
len
;
p
=
des_tv
[
i
].
plaintext
;
sg
[
0
].
page
=
virt_to_page
(
p
);
sg
[
0
].
offset
=
offset_in_page
(
p
);
sg
[
0
].
length
=
len
;
crypto_cipher_set_iv
(
tfm
,
des_tv
[
i
].
iv
,
crypto_tfm_alg_blocksize
(
tfm
));
ret
=
crypto_cipher_decrypt
(
tfm
,
sg
,
sg
,
len
);
if
(
ret
)
{
printk
(
"des_cbc_decrypt() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
goto
out
;
}
hexdump
(
tfm
->
crt_cipher
.
cit_iv
,
8
);
q
=
kmap
(
sg
[
0
].
page
)
+
sg
[
0
].
offset
;
hexdump
(
q
,
len
);
printk
(
"%s
\n
"
,
memcmp
(
q
,
des_tv
[
i
].
result
,
len
)
?
"fail"
:
"pass"
);
}
/*
* Scenario G:
*
* F1 F2
* [4] [4]
*
*/
printk
(
"
\n
testing des cbc decryption chunking scenario G
\n
"
);
i
=
3
;
tfm
->
crt_flags
=
0
;
key
=
des_tv
[
i
].
key
;
ret
=
crypto_cipher_setkey
(
tfm
,
key
,
8
);
if
(
ret
)
{
printk
(
"setkey() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
goto
out
;
}
/* setup the dummy buffer first */
memset
(
xbuf
,
0
,
sizeof
(
xbuf
));
memcpy
(
&
xbuf
[
IDX1
],
des_tv
[
i
].
plaintext
,
4
);
memcpy
(
&
xbuf
[
IDX2
],
des_tv
[
i
].
plaintext
+
4
,
4
);
p
=
&
xbuf
[
IDX1
];
sg
[
0
].
page
=
virt_to_page
(
p
);
sg
[
0
].
offset
=
offset_in_page
(
p
);
sg
[
0
].
length
=
4
;
p
=
&
xbuf
[
IDX2
];
sg
[
1
].
page
=
virt_to_page
(
p
);
sg
[
1
].
offset
=
offset_in_page
(
p
);
sg
[
1
].
length
=
4
;
crypto_cipher_set_iv
(
tfm
,
des_tv
[
i
].
iv
,
crypto_tfm_alg_ivsize
(
tfm
));
ret
=
crypto_cipher_decrypt
(
tfm
,
sg
,
sg
,
8
);
if
(
ret
)
{
printk
(
"des_cbc_decrypt() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
goto
out
;
}
printk
(
"page 1
\n
"
);
q
=
kmap
(
sg
[
0
].
page
)
+
sg
[
0
].
offset
;
hexdump
(
q
,
4
);
printk
(
"%s
\n
"
,
memcmp
(
q
,
des_tv
[
i
].
result
,
4
)
?
"fail"
:
"pass"
);
printk
(
"page 2
\n
"
);
q
=
kmap
(
sg
[
1
].
page
)
+
sg
[
1
].
offset
;
hexdump
(
q
,
4
);
printk
(
"%s
\n
"
,
memcmp
(
q
,
des_tv
[
i
].
result
+
4
,
4
)
?
"fail"
:
"pass"
);
out:
crypto_free_tfm
(
tfm
);
}
void
test_des3_ede
(
void
)
{
unsigned
int
ret
,
i
,
len
;
unsigned
int
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 (%u) too big for tvmem (%u)
\n
"
,
tsize
,
TVMEMSIZE
);
return
;
}
memcpy
(
tvmem
,
des3_ede_enc_tv_template
,
tsize
);
des_tv
=
(
void
*
)
tvmem
;
tfm
=
crypto_alloc_tfm
(
"des3_ede"
,
CRYPTO_TFM_MODE_ECB
);
if
(
tfm
==
NULL
)
{
printk
(
"failed to load transform for 3des ecb
\n
"
);
return
;
}
for
(
i
=
0
;
i
<
DES3_EDE_ENC_TEST_VECTORS
;
i
++
)
{
printk
(
"test %u:
\n
"
,
i
+
1
);
key
=
des_tv
[
i
].
key
;
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
=
offset_in_page
(
p
);
sg
[
0
].
length
=
len
;
ret
=
crypto_cipher_encrypt
(
tfm
,
sg
,
sg
,
len
);
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 (%u) too big for tvmem (%u)
\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 %u:
\n
"
,
i
+
1
);
key
=
des_tv
[
i
].
key
;
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
=
offset_in_page
(
p
);
sg
[
0
].
length
=
len
;
ret
=
crypto_cipher_decrypt
(
tfm
,
sg
,
sg
,
len
);
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
);
}
void
test_blowfish
(
void
)
{
unsigned
int
ret
,
i
;
unsigned
int
tsize
;
char
*
p
,
*
q
;
struct
crypto_tfm
*
tfm
;
char
*
key
;
struct
bf_tv
*
bf_tv
;
struct
scatterlist
sg
[
1
];
printk
(
"
\n
testing blowfish encryption
\n
"
);
tsize
=
sizeof
(
bf_enc_tv_template
);
if
(
tsize
>
TVMEMSIZE
)
{
printk
(
"template (%u) too big for tvmem (%u)
\n
"
,
tsize
,
TVMEMSIZE
);
return
;
}
memcpy
(
tvmem
,
bf_enc_tv_template
,
tsize
);
bf_tv
=
(
void
*
)
tvmem
;
tfm
=
crypto_alloc_tfm
(
"blowfish"
,
0
);
if
(
tfm
==
NULL
)
{
printk
(
"failed to load transform for blowfish (default ecb)
\n
"
);
return
;
}
for
(
i
=
0
;
i
<
BF_ENC_TEST_VECTORS
;
i
++
)
{
printk
(
"test %u (%d bit key):
\n
"
,
i
+
1
,
bf_tv
[
i
].
keylen
*
8
);
key
=
bf_tv
[
i
].
key
;
ret
=
crypto_cipher_setkey
(
tfm
,
key
,
bf_tv
[
i
].
keylen
);
if
(
ret
)
{
printk
(
"setkey() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
if
(
!
bf_tv
[
i
].
fail
)
goto
out
;
}
p
=
bf_tv
[
i
].
plaintext
;
sg
[
0
].
page
=
virt_to_page
(
p
);
sg
[
0
].
offset
=
offset_in_page
(
p
);
sg
[
0
].
length
=
bf_tv
[
i
].
plen
;
ret
=
crypto_cipher_encrypt
(
tfm
,
sg
,
sg
,
sg
[
0
].
length
);
if
(
ret
)
{
printk
(
"encrypt() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
goto
out
;
}
q
=
kmap
(
sg
[
0
].
page
)
+
sg
[
0
].
offset
;
hexdump
(
q
,
bf_tv
[
i
].
rlen
);
printk
(
"%s
\n
"
,
memcmp
(
q
,
bf_tv
[
i
].
result
,
bf_tv
[
i
].
rlen
)
?
"fail"
:
"pass"
);
}
printk
(
"
\n
testing blowfish decryption
\n
"
);
tsize
=
sizeof
(
bf_dec_tv_template
);
if
(
tsize
>
TVMEMSIZE
)
{
printk
(
"template (%u) too big for tvmem (%u)
\n
"
,
tsize
,
TVMEMSIZE
);
return
;
}
memcpy
(
tvmem
,
bf_dec_tv_template
,
tsize
);
bf_tv
=
(
void
*
)
tvmem
;
for
(
i
=
0
;
i
<
BF_DEC_TEST_VECTORS
;
i
++
)
{
printk
(
"test %u (%d bit key):
\n
"
,
i
+
1
,
bf_tv
[
i
].
keylen
*
8
);
key
=
bf_tv
[
i
].
key
;
ret
=
crypto_cipher_setkey
(
tfm
,
key
,
bf_tv
[
i
].
keylen
);
if
(
ret
)
{
printk
(
"setkey() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
if
(
!
bf_tv
[
i
].
fail
)
goto
out
;
}
p
=
bf_tv
[
i
].
plaintext
;
sg
[
0
].
page
=
virt_to_page
(
p
);
sg
[
0
].
offset
=
offset_in_page
(
p
);
sg
[
0
].
length
=
bf_tv
[
i
].
plen
;
ret
=
crypto_cipher_decrypt
(
tfm
,
sg
,
sg
,
sg
[
0
].
length
);
if
(
ret
)
{
printk
(
"decrypt() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
goto
out
;
}
q
=
kmap
(
sg
[
0
].
page
)
+
sg
[
0
].
offset
;
hexdump
(
q
,
bf_tv
[
i
].
rlen
);
printk
(
"%s
\n
"
,
memcmp
(
q
,
bf_tv
[
i
].
result
,
bf_tv
[
i
].
rlen
)
?
"fail"
:
"pass"
);
}
crypto_free_tfm
(
tfm
);
tfm
=
crypto_alloc_tfm
(
"blowfish"
,
CRYPTO_TFM_MODE_CBC
);
if
(
tfm
==
NULL
)
{
printk
(
"failed to load transform for blowfish cbc
\n
"
);
return
;
}
printk
(
"
\n
testing blowfish cbc encryption
\n
"
);
tsize
=
sizeof
(
bf_cbc_enc_tv_template
);
if
(
tsize
>
TVMEMSIZE
)
{
printk
(
"template (%u) too big for tvmem (%u)
\n
"
,
tsize
,
TVMEMSIZE
);
goto
out
;
}
memcpy
(
tvmem
,
bf_cbc_enc_tv_template
,
tsize
);
bf_tv
=
(
void
*
)
tvmem
;
for
(
i
=
0
;
i
<
BF_CBC_ENC_TEST_VECTORS
;
i
++
)
{
printk
(
"test %u (%d bit key):
\n
"
,
i
+
1
,
bf_tv
[
i
].
keylen
*
8
);
key
=
bf_tv
[
i
].
key
;
ret
=
crypto_cipher_setkey
(
tfm
,
key
,
bf_tv
[
i
].
keylen
);
if
(
ret
)
{
printk
(
"setkey() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
goto
out
;
}
p
=
bf_tv
[
i
].
plaintext
;
sg
[
0
].
page
=
virt_to_page
(
p
);
sg
[
0
].
offset
=
offset_in_page
(
p
);
sg
[
0
].
length
=
bf_tv
[
i
].
plen
;
crypto_cipher_set_iv
(
tfm
,
bf_tv
[
i
].
iv
,
crypto_tfm_alg_ivsize
(
tfm
));
ret
=
crypto_cipher_encrypt
(
tfm
,
sg
,
sg
,
sg
[
0
].
length
);
if
(
ret
)
{
printk
(
"blowfish_cbc_encrypt() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
goto
out
;
}
q
=
kmap
(
sg
[
0
].
page
)
+
sg
[
0
].
offset
;
hexdump
(
q
,
bf_tv
[
i
].
rlen
);
printk
(
"%s
\n
"
,
memcmp
(
q
,
bf_tv
[
i
].
result
,
bf_tv
[
i
].
rlen
)
?
"fail"
:
"pass"
);
}
printk
(
"
\n
testing blowfish cbc decryption
\n
"
);
tsize
=
sizeof
(
bf_cbc_dec_tv_template
);
if
(
tsize
>
TVMEMSIZE
)
{
printk
(
"template (%u) too big for tvmem (%u)
\n
"
,
tsize
,
TVMEMSIZE
);
goto
out
;
}
memcpy
(
tvmem
,
bf_cbc_dec_tv_template
,
tsize
);
bf_tv
=
(
void
*
)
tvmem
;
for
(
i
=
0
;
i
<
BF_CBC_ENC_TEST_VECTORS
;
i
++
)
{
printk
(
"test %u (%d bit key):
\n
"
,
i
+
1
,
bf_tv
[
i
].
keylen
*
8
);
key
=
bf_tv
[
i
].
key
;
ret
=
crypto_cipher_setkey
(
tfm
,
key
,
bf_tv
[
i
].
keylen
);
if
(
ret
)
{
printk
(
"setkey() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
goto
out
;
}
p
=
bf_tv
[
i
].
plaintext
;
sg
[
0
].
page
=
virt_to_page
(
p
);
sg
[
0
].
offset
=
offset_in_page
(
p
);
sg
[
0
].
length
=
bf_tv
[
i
].
plen
;
crypto_cipher_set_iv
(
tfm
,
bf_tv
[
i
].
iv
,
crypto_tfm_alg_ivsize
(
tfm
));
ret
=
crypto_cipher_decrypt
(
tfm
,
sg
,
sg
,
sg
[
0
].
length
);
if
(
ret
)
{
printk
(
"blowfish_cbc_decrypt() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
goto
out
;
}
q
=
kmap
(
sg
[
0
].
page
)
+
sg
[
0
].
offset
;
hexdump
(
q
,
bf_tv
[
i
].
rlen
);
printk
(
"%s
\n
"
,
memcmp
(
q
,
bf_tv
[
i
].
result
,
bf_tv
[
i
].
rlen
)
?
"fail"
:
"pass"
);
}
out:
crypto_free_tfm
(
tfm
);
}
void
test_twofish
(
void
)
{
unsigned
int
ret
,
i
;
unsigned
int
tsize
;
char
*
p
,
*
q
;
struct
crypto_tfm
*
tfm
;
char
*
key
;
struct
tf_tv
*
tf_tv
;
struct
scatterlist
sg
[
1
];
printk
(
"
\n
testing twofish encryption
\n
"
);
tsize
=
sizeof
(
tf_enc_tv_template
);
if
(
tsize
>
TVMEMSIZE
)
{
printk
(
"template (%u) too big for tvmem (%u)
\n
"
,
tsize
,
TVMEMSIZE
);
return
;
}
memcpy
(
tvmem
,
tf_enc_tv_template
,
tsize
);
tf_tv
=
(
void
*
)
tvmem
;
tfm
=
crypto_alloc_tfm
(
"twofish"
,
0
);
if
(
tfm
==
NULL
)
{
printk
(
"failed to load transform for blowfish (default ecb)
\n
"
);
return
;
}
for
(
i
=
0
;
i
<
TF_ENC_TEST_VECTORS
;
i
++
)
{
printk
(
"test %u (%d bit key):
\n
"
,
i
+
1
,
tf_tv
[
i
].
keylen
*
8
);
key
=
tf_tv
[
i
].
key
;
ret
=
crypto_cipher_setkey
(
tfm
,
key
,
tf_tv
[
i
].
keylen
);
if
(
ret
)
{
printk
(
"setkey() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
if
(
!
tf_tv
[
i
].
fail
)
goto
out
;
}
p
=
tf_tv
[
i
].
plaintext
;
sg
[
0
].
page
=
virt_to_page
(
p
);
sg
[
0
].
offset
=
offset_in_page
(
p
);
sg
[
0
].
length
=
tf_tv
[
i
].
plen
;
ret
=
crypto_cipher_encrypt
(
tfm
,
sg
,
sg
,
sg
[
0
].
length
);
if
(
ret
)
{
printk
(
"encrypt() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
goto
out
;
}
q
=
kmap
(
sg
[
0
].
page
)
+
sg
[
0
].
offset
;
hexdump
(
q
,
tf_tv
[
i
].
rlen
);
printk
(
"%s
\n
"
,
memcmp
(
q
,
tf_tv
[
i
].
result
,
tf_tv
[
i
].
rlen
)
?
"fail"
:
"pass"
);
}
printk
(
"
\n
testing twofish decryption
\n
"
);
tsize
=
sizeof
(
tf_dec_tv_template
);
if
(
tsize
>
TVMEMSIZE
)
{
printk
(
"template (%u) too big for tvmem (%u)
\n
"
,
tsize
,
TVMEMSIZE
);
return
;
}
memcpy
(
tvmem
,
tf_dec_tv_template
,
tsize
);
tf_tv
=
(
void
*
)
tvmem
;
for
(
i
=
0
;
i
<
TF_DEC_TEST_VECTORS
;
i
++
)
{
printk
(
"test %u (%d bit key):
\n
"
,
i
+
1
,
tf_tv
[
i
].
keylen
*
8
);
key
=
tf_tv
[
i
].
key
;
ret
=
crypto_cipher_setkey
(
tfm
,
key
,
tf_tv
[
i
].
keylen
);
if
(
ret
)
{
printk
(
"setkey() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
if
(
!
tf_tv
[
i
].
fail
)
goto
out
;
}
p
=
tf_tv
[
i
].
plaintext
;
sg
[
0
].
page
=
virt_to_page
(
p
);
sg
[
0
].
offset
=
offset_in_page
(
p
);
sg
[
0
].
length
=
tf_tv
[
i
].
plen
;
ret
=
crypto_cipher_decrypt
(
tfm
,
sg
,
sg
,
sg
[
0
].
length
);
if
(
ret
)
{
printk
(
"decrypt() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
goto
out
;
}
q
=
kmap
(
sg
[
0
].
page
)
+
sg
[
0
].
offset
;
hexdump
(
q
,
tf_tv
[
i
].
rlen
);
printk
(
"%s
\n
"
,
memcmp
(
q
,
tf_tv
[
i
].
result
,
tf_tv
[
i
].
rlen
)
?
"fail"
:
"pass"
);
}
crypto_free_tfm
(
tfm
);
tfm
=
crypto_alloc_tfm
(
"twofish"
,
CRYPTO_TFM_MODE_CBC
);
if
(
tfm
==
NULL
)
{
printk
(
"failed to load transform for twofish cbc
\n
"
);
return
;
}
printk
(
"
\n
testing twofish cbc encryption
\n
"
);
tsize
=
sizeof
(
tf_cbc_enc_tv_template
);
if
(
tsize
>
TVMEMSIZE
)
{
printk
(
"template (%u) too big for tvmem (%u)
\n
"
,
tsize
,
TVMEMSIZE
);
goto
out
;
}
memcpy
(
tvmem
,
tf_cbc_enc_tv_template
,
tsize
);
tf_tv
=
(
void
*
)
tvmem
;
for
(
i
=
0
;
i
<
TF_CBC_ENC_TEST_VECTORS
;
i
++
)
{
printk
(
"test %u (%d bit key):
\n
"
,
i
+
1
,
tf_tv
[
i
].
keylen
*
8
);
key
=
tf_tv
[
i
].
key
;
ret
=
crypto_cipher_setkey
(
tfm
,
key
,
tf_tv
[
i
].
keylen
);
if
(
ret
)
{
printk
(
"setkey() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
goto
out
;
}
p
=
tf_tv
[
i
].
plaintext
;
sg
[
0
].
page
=
virt_to_page
(
p
);
sg
[
0
].
offset
=
offset_in_page
(
p
);
sg
[
0
].
length
=
tf_tv
[
i
].
plen
;
crypto_cipher_set_iv
(
tfm
,
tf_tv
[
i
].
iv
,
crypto_tfm_alg_ivsize
(
tfm
));
ret
=
crypto_cipher_encrypt
(
tfm
,
sg
,
sg
,
sg
[
0
].
length
);
if
(
ret
)
{
printk
(
"blowfish_cbc_encrypt() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
goto
out
;
}
q
=
kmap
(
sg
[
0
].
page
)
+
sg
[
0
].
offset
;
hexdump
(
q
,
tf_tv
[
i
].
rlen
);
printk
(
"%s
\n
"
,
memcmp
(
q
,
tf_tv
[
i
].
result
,
tf_tv
[
i
].
rlen
)
?
"fail"
:
"pass"
);
}
printk
(
"
\n
testing twofish cbc decryption
\n
"
);
tsize
=
sizeof
(
tf_cbc_dec_tv_template
);
if
(
tsize
>
TVMEMSIZE
)
{
printk
(
"template (%u) too big for tvmem (%u)
\n
"
,
tsize
,
TVMEMSIZE
);
goto
out
;
}
memcpy
(
tvmem
,
tf_cbc_dec_tv_template
,
tsize
);
tf_tv
=
(
void
*
)
tvmem
;
for
(
i
=
0
;
i
<
TF_CBC_DEC_TEST_VECTORS
;
i
++
)
{
printk
(
"test %u (%d bit key):
\n
"
,
i
+
1
,
tf_tv
[
i
].
keylen
*
8
);
*
* 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.
*
* 14 - 09 - 2003
* Rewritten by Kartikey Mahendra Bhatt
*/
key
=
tf_tv
[
i
].
key
;
#include <linux/init.h>
#include <linux/module.h>
#include <linux/mm.h>
#include <linux/slab.h>
#include <asm/scatterlist.h>
#include <linux/string.h>
#include <linux/crypto.h>
#include <linux/highmem.h>
#include "tcrypt.h"
ret
=
crypto_cipher_setkey
(
tfm
,
key
,
tf_tv
[
i
].
keylen
);
if
(
ret
)
{
printk
(
"setkey() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
goto
out
;
}
/*
* Need to kmalloc() memory for testing kmap().
*/
#define TVMEMSIZE 4096
#define XBUFSIZE 32768
p
=
tf_tv
[
i
].
plaintext
;
/*
* Indexes into the xbuf to simulate cross-page access.
*/
#define IDX1 37
#define IDX2 32400
#define IDX3 1
#define IDX4 8193
#define IDX5 22222
#define IDX6 17101
#define IDX7 27333
#define IDX8 3000
sg
[
0
].
page
=
virt_to_page
(
p
);
sg
[
0
].
offset
=
offset_in_page
(
p
);
sg
[
0
].
length
=
tf_tv
[
i
].
plen
;
/*
* Used by test_cipher()
*/
#define ENCRYPT 1
#define DECRYPT 0
#define MODE_ECB 1
#define MODE_CBC 0
crypto_cipher_set_iv
(
tfm
,
tf_tv
[
i
].
iv
,
crypto_tfm_alg_ivsize
(
tfm
));
static
unsigned
int
IDX
[
8
]
=
{
IDX1
,
IDX2
,
IDX3
,
IDX4
,
IDX5
,
IDX6
,
IDX7
,
IDX8
};
ret
=
crypto_cipher_decrypt
(
tfm
,
sg
,
sg
,
sg
[
0
].
length
);
if
(
ret
)
{
printk
(
"blowfish_cbc_decrypt() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
goto
out
;
}
static
int
mode
;
static
char
*
xbuf
;
static
char
*
tvmem
;
q
=
kmap
(
sg
[
0
].
page
)
+
sg
[
0
].
offset
;
hexdump
(
q
,
tf_tv
[
i
].
rlen
);
static
char
*
check
[]
=
{
"des"
,
"md5"
,
"des3_ede"
,
"rot13"
,
"sha1"
,
"sha256"
,
"blowfish"
,
"twofish"
,
"serpent"
,
"sha384"
,
"sha512"
,
"md4"
,
"aes"
,
"cast6"
,
"deflate"
,
NULL
};
printk
(
"%s
\n
"
,
memcmp
(
q
,
tf_tv
[
i
].
result
,
tf_tv
[
i
].
rlen
)
?
"fail"
:
"pass"
);
}
static
void
hexdump
(
unsigned
char
*
buf
,
unsigned
int
len
)
{
while
(
len
--
)
printk
(
"%02x"
,
*
buf
++
);
out:
crypto_free_tfm
(
tfm
);
printk
(
"
\n
"
);
}
void
test_
serpent
(
void
)
static
void
test_
hash
(
char
*
algo
,
struct
hash_testvec
*
template
,
unsigned
int
tcount
)
{
unsigned
int
ret
,
i
,
tsize
;
u8
*
p
,
*
q
,
*
key
;
struct
crypto_tfm
*
tfm
;
struct
serpent_tv
*
serp_tv
;
struct
scatterlist
sg
[
1
];
printk
(
"
\n
testing serpent encryption
\n
"
);
tfm
=
crypto_alloc_tfm
(
"serpent"
,
0
);
if
(
tfm
==
NULL
)
{
printk
(
"failed to load transform for serpent (default ecb)
\n
"
);
char
*
p
;
unsigned
int
i
,
j
,
k
,
temp
;
struct
scatterlist
sg
[
8
];
char
result
[
64
];
struct
crypto_tfm
*
tfm
;
struct
hash_testvec
*
hash_tv
;
unsigned
int
tsize
;
printk
(
"
\n
testing %s
\n
"
,
algo
);
tsize
=
sizeof
(
struct
hash_testvec
);
tsize
*=
tcount
;
if
(
tsize
>
TVMEMSIZE
)
{
printk
(
"template (%u) too big for tvmem (%u)
\n
"
,
tsize
,
TVMEMSIZE
);
return
;
}
tsize
=
sizeof
(
serpent_enc_tv_template
);
if
(
tsize
>
TVMEMSIZE
)
{
printk
(
"template (%u) too big for tvmem (%u)
\n
"
,
tsize
,
TVMEMSIZE
);
memcpy
(
tvmem
,
template
,
tsize
);
hash_tv
=
(
void
*
)
tvmem
;
tfm
=
crypto_alloc_tfm
(
algo
,
0
);
if
(
tfm
==
NULL
)
{
printk
(
"failed to load transform for %s
\n
"
,
algo
);
return
;
}
memcpy
(
tvmem
,
serpent_enc_tv_template
,
tsize
);
serp_tv
=
(
void
*
)
tvmem
;
for
(
i
=
0
;
i
<
SERPENT_ENC_TEST_VECTORS
;
i
++
)
{
printk
(
"test %u (%d bit key):
\n
"
,
i
+
1
,
serp_tv
[
i
].
keylen
*
8
);
key
=
serp_tv
[
i
].
key
;
ret
=
crypto_cipher_setkey
(
tfm
,
key
,
serp_tv
[
i
].
keylen
);
if
(
ret
)
{
printk
(
"setkey() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
if
(
!
serp_tv
[
i
].
fail
)
goto
out
;
}
p
=
serp_tv
[
i
].
plaintext
;
sg
[
0
].
page
=
virt_to_page
(
p
);
sg
[
0
].
offset
=
offset_in_page
(
p
);
sg
[
0
].
length
=
sizeof
(
serp_tv
[
i
].
plaintext
);
ret
=
crypto_cipher_encrypt
(
tfm
,
sg
,
sg
,
sg
[
0
].
length
);
if
(
ret
)
{
printk
(
"encrypt() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
goto
out
;
}
for
(
i
=
0
;
i
<
tcount
;
i
++
)
{
printk
(
"test %u:
\n
"
,
i
+
1
);
memset
(
result
,
0
,
64
);
q
=
kmap
(
sg
[
0
].
page
)
+
sg
[
0
].
offset
;
hexdump
(
q
,
sizeof
(
serp_tv
[
i
].
result
));
p
=
hash_tv
[
i
].
plaintext
;
sg
[
0
].
page
=
virt_to_page
(
p
);
sg
[
0
].
offset
=
offset_in_page
(
p
);
sg
[
0
].
length
=
hash_tv
[
i
].
psize
;
printk
(
"%s
\n
"
,
memcmp
(
q
,
serp_tv
[
i
].
result
,
sizeof
(
serp_tv
[
i
].
result
))
?
"fail"
:
"pass"
);
}
printk
(
"
\n
testing serpent decryption
\n
"
);
crypto_digest_init
(
tfm
);
crypto_digest_update
(
tfm
,
sg
,
1
);
crypto_digest_final
(
tfm
,
result
);
tsize
=
sizeof
(
serpent_dec_tv_template
);
if
(
tsize
>
TVMEMSIZE
)
{
printk
(
"template (%u) too big for tvmem (%u)
\n
"
,
tsize
,
TVMEMSIZE
);
return
;
hexdump
(
result
,
crypto_tfm_alg_digestsize
(
tfm
)
);
printk
(
"%s
\n
"
,
memcmp
(
result
,
hash_tv
[
i
].
digest
,
crypto_tfm_alg_digestsize
(
tfm
))
?
"fail"
:
"pass"
)
;
}
memcpy
(
tvmem
,
serpent_dec_tv_template
,
tsize
);
serp_tv
=
(
void
*
)
tvmem
;
for
(
i
=
0
;
i
<
SERPENT_DEC_TEST_VECTORS
;
i
++
)
{
printk
(
"test %u (%d bit key):
\n
"
,
i
+
1
,
serp_tv
[
i
].
keylen
*
8
);
key
=
serp_tv
[
i
].
key
;
ret
=
crypto_cipher_setkey
(
tfm
,
key
,
serp_tv
[
i
].
keylen
);
if
(
ret
)
{
printk
(
"setkey() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
if
(
!
serp_tv
[
i
].
fail
)
goto
out
;
}
printk
(
"testing %s across pages
\n
"
,
algo
);
p
=
serp_tv
[
i
].
plaintext
;
sg
[
0
].
page
=
virt_to_page
(
p
);
sg
[
0
].
offset
=
offset_in_page
(
p
);
sg
[
0
].
length
=
sizeof
(
serp_tv
[
i
].
plaintext
);
ret
=
crypto_cipher_decrypt
(
tfm
,
sg
,
sg
,
sg
[
0
].
length
);
if
(
ret
)
{
printk
(
"decrypt() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
goto
out
;
/* setup the dummy buffer first */
memset
(
xbuf
,
0
,
XBUFSIZE
);
j
=
0
;
for
(
i
=
0
;
i
<
tcount
;
i
++
)
{
if
(
hash_tv
[
i
].
np
)
{
j
++
;
printk
(
"test %u:
\n
"
,
j
);
memset
(
result
,
0
,
64
);
temp
=
0
;
for
(
k
=
0
;
k
<
hash_tv
[
i
].
np
;
k
++
)
{
memcpy
(
&
xbuf
[
IDX
[
k
]],
hash_tv
[
i
].
plaintext
+
temp
,
hash_tv
[
i
].
tap
[
k
]);
temp
+=
hash_tv
[
i
].
tap
[
k
];
p
=
&
xbuf
[
IDX
[
k
]];
sg
[
k
].
page
=
virt_to_page
(
p
);
sg
[
k
].
offset
=
offset_in_page
(
p
);
sg
[
k
].
length
=
hash_tv
[
i
].
tap
[
k
];
}
crypto_digest_digest
(
tfm
,
sg
,
hash_tv
[
i
].
np
,
result
);
hexdump
(
result
,
crypto_tfm_alg_digestsize
(
tfm
));
printk
(
"%s
\n
"
,
memcmp
(
result
,
hash_tv
[
i
].
digest
,
crypto_tfm_alg_digestsize
(
tfm
))
?
"fail"
:
"pass"
);
}
q
=
kmap
(
sg
[
0
].
page
)
+
sg
[
0
].
offset
;
hexdump
(
q
,
sizeof
(
serp_tv
[
i
].
result
));
printk
(
"%s
\n
"
,
memcmp
(
q
,
serp_tv
[
i
].
result
,
sizeof
(
serp_tv
[
i
].
result
))
?
"fail"
:
"pass"
);
}
out:
crypto_free_tfm
(
tfm
);
crypto_free_tfm
(
tfm
);
}
#ifdef CONFIG_CRYPTO_HMAC
static
void
test_
cast6
(
void
)
test_
hmac
(
char
*
algo
,
struct
hmac_testvec
*
template
,
unsigned
int
tcount
)
{
unsigned
int
ret
,
i
,
tsize
;
u8
*
p
,
*
q
,
*
key
;
char
*
p
;
unsigned
int
i
,
j
,
k
,
temp
;
struct
scatterlist
sg
[
8
];
char
result
[
64
];
struct
crypto_tfm
*
tfm
;
struct
cast6_tv
*
cast
_tv
;
struct
scatterlist
sg
[
1
]
;
struct
hmac_testvec
*
hmac
_tv
;
unsigned
int
tsize
,
klen
;
printk
(
"
\n
testing cast6 encryption
\n
"
);
tfm
=
crypto_alloc_tfm
(
"cast6"
,
0
);
tfm
=
crypto_alloc_tfm
(
algo
,
0
);
if
(
tfm
==
NULL
)
{
printk
(
"failed to load transform for
cast6 (default ecb)
\n
"
);
printk
(
"failed to load transform for
%s
\n
"
,
algo
);
return
;
}
tsize
=
sizeof
(
cast6_enc_tv_template
);
printk
(
"
\n
testing hmac_%s
\n
"
,
algo
);
tsize
=
sizeof
(
struct
hmac_testvec
);
tsize
*=
tcount
;
if
(
tsize
>
TVMEMSIZE
)
{
printk
(
"template (%u) too big for tvmem (%u)
\n
"
,
tsize
,
TVMEMSIZE
);
return
;
goto
out
;
}
memcpy
(
tvmem
,
cast6_enc_tv_template
,
tsize
);
cast_tv
=
(
void
*
)
tvmem
;
for
(
i
=
0
;
i
<
CAST6_ENC_TEST_VECTORS
;
i
++
)
{
printk
(
"test %u (%d bit key):
\n
"
,
i
+
1
,
cast_tv
[
i
].
keylen
*
8
);
key
=
cast_tv
[
i
].
key
;
memcpy
(
tvmem
,
template
,
tsize
);
hmac_tv
=
(
void
*
)
tvmem
;
ret
=
crypto_cipher_setkey
(
tfm
,
key
,
cast_tv
[
i
].
keylen
);
if
(
ret
)
{
printk
(
"setkey() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
if
(
!
cast_tv
[
i
].
fail
)
goto
out
;
}
for
(
i
=
0
;
i
<
tcount
;
i
++
)
{
printk
(
"test %u:
\n
"
,
i
+
1
);
memset
(
result
,
0
,
sizeof
(
result
));
p
=
cast_tv
[
i
].
plaintext
;
p
=
hmac_tv
[
i
].
plaintext
;
klen
=
hmac_tv
[
i
].
ksize
;
sg
[
0
].
page
=
virt_to_page
(
p
);
sg
[
0
].
offset
=
((
long
)
p
&
~
PAGE_MASK
);
sg
[
0
].
length
=
sizeof
(
cast_tv
[
i
].
plaintext
);
ret
=
crypto_cipher_encrypt
(
tfm
,
sg
,
sg
,
sg
[
0
].
length
);
if
(
ret
)
{
printk
(
"encrypt() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
goto
out
;
}
q
=
kmap
(
sg
[
0
].
page
)
+
sg
[
0
].
offset
;
hexdump
(
q
,
sizeof
(
cast_tv
[
i
].
result
));
printk
(
"%s
\n
"
,
memcmp
(
q
,
cast_tv
[
i
].
result
,
sizeof
(
cast_tv
[
i
].
result
))
?
"fail"
:
"pass"
);
}
sg
[
0
].
offset
=
offset_in_page
(
p
);
sg
[
0
].
length
=
hmac_tv
[
i
].
psize
;
printk
(
"
\n
testing cast6 decryption
\n
"
);
crypto_hmac
(
tfm
,
hmac_tv
[
i
].
key
,
&
klen
,
sg
,
1
,
result
);
tsize
=
sizeof
(
cast6_dec_tv_template
);
if
(
tsize
>
TVMEMSIZE
)
{
printk
(
"template (%u) too big for tvmem (%u)
\n
"
,
tsize
,
TVMEMSIZE
);
return
;
hexdump
(
result
,
crypto_tfm_alg_digestsize
(
tfm
)
);
printk
(
"%s
\n
"
,
memcmp
(
result
,
hmac_tv
[
i
].
digest
,
crypto_tfm_alg_digestsize
(
tfm
))
?
"fail"
:
"pass"
)
;
}
memcpy
(
tvmem
,
cast6_dec_tv_template
,
tsize
);
cast_tv
=
(
void
*
)
tvmem
;
for
(
i
=
0
;
i
<
CAST6_DEC_TEST_VECTORS
;
i
++
)
{
printk
(
"test %u (%d bit key):
\n
"
,
i
+
1
,
cast_tv
[
i
].
keylen
*
8
);
key
=
cast_tv
[
i
].
key
;
printk
(
"
\n
testing hmac_%s across pages
\n
"
,
algo
);
ret
=
crypto_cipher_setkey
(
tfm
,
key
,
cast_tv
[
i
].
keylen
);
if
(
ret
)
{
printk
(
"setkey() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
if
(
!
cast_tv
[
i
].
fail
)
goto
out
;
}
p
=
cast_tv
[
i
].
plaintext
;
sg
[
0
].
page
=
virt_to_page
(
p
);
sg
[
0
].
offset
=
((
long
)
p
&
~
PAGE_MASK
);
sg
[
0
].
length
=
sizeof
(
cast_tv
[
i
].
plaintext
);
ret
=
crypto_cipher_decrypt
(
tfm
,
sg
,
sg
,
sg
[
0
].
length
);
if
(
ret
)
{
printk
(
"decrypt() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
goto
out
;
memset
(
xbuf
,
0
,
XBUFSIZE
);
j
=
0
;
for
(
i
=
0
;
i
<
tcount
;
i
++
)
{
if
(
hmac_tv
[
i
].
np
)
{
j
++
;
printk
(
"test %u:
\n
"
,
j
);
memset
(
result
,
0
,
64
);
temp
=
0
;
klen
=
hmac_tv
[
i
].
ksize
;
for
(
k
=
0
;
k
<
hmac_tv
[
i
].
np
;
k
++
)
{
memcpy
(
&
xbuf
[
IDX
[
k
]],
hmac_tv
[
i
].
plaintext
+
temp
,
hmac_tv
[
i
].
tap
[
k
]);
temp
+=
hmac_tv
[
i
].
tap
[
k
];
p
=
&
xbuf
[
IDX
[
k
]];
sg
[
k
].
page
=
virt_to_page
(
p
);
sg
[
k
].
offset
=
offset_in_page
(
p
);
sg
[
k
].
length
=
hmac_tv
[
i
].
tap
[
k
];
}
crypto_hmac
(
tfm
,
hmac_tv
[
i
].
key
,
&
klen
,
sg
,
hmac_tv
[
i
].
np
,
result
);
hexdump
(
result
,
crypto_tfm_alg_digestsize
(
tfm
));
printk
(
"%s
\n
"
,
memcmp
(
result
,
hmac_tv
[
i
].
digest
,
crypto_tfm_alg_digestsize
(
tfm
))
?
"fail"
:
"pass"
);
}
q
=
kmap
(
sg
[
0
].
page
)
+
sg
[
0
].
offset
;
hexdump
(
q
,
sizeof
(
cast_tv
[
i
].
result
));
printk
(
"%s
\n
"
,
memcmp
(
q
,
cast_tv
[
i
].
result
,
sizeof
(
cast_tv
[
i
].
result
))
?
"fail"
:
"pass"
);
}
out:
crypto_free_tfm
(
tfm
);
}
#endif
/* CONFIG_CRYPTO_HMAC */
void
test_
aes
(
void
)
test_
cipher
(
char
*
algo
,
int
mode
,
int
enc
,
struct
cipher_testvec
*
template
,
unsigned
int
tcount
)
{
unsigned
int
ret
,
i
;
unsigned
int
ret
,
i
,
j
,
k
,
temp
;
unsigned
int
tsize
;
char
*
p
,
*
q
;
struct
crypto_tfm
*
tfm
;
char
*
key
;
struct
aes_tv
*
aes_tv
;
struct
scatterlist
sg
[
1
];
printk
(
"
\n
testing aes encryption
\n
"
);
tsize
=
sizeof
(
aes_enc_tv_template
);
if
(
tsize
>
TVMEMSIZE
)
{
printk
(
"template (%u) too big for tvmem (%u)
\n
"
,
tsize
,
TVMEMSIZE
);
return
;
}
memcpy
(
tvmem
,
aes_enc_tv_template
,
tsize
);
aes_tv
=
(
void
*
)
tvmem
;
tfm
=
crypto_alloc_tfm
(
"aes"
,
0
);
if
(
tfm
==
NULL
)
{
printk
(
"failed to load transform for aes (default ecb)
\n
"
);
return
;
}
for
(
i
=
0
;
i
<
AES_ENC_TEST_VECTORS
;
i
++
)
{
printk
(
"test %u (%d bit key):
\n
"
,
i
+
1
,
aes_tv
[
i
].
keylen
*
8
);
key
=
aes_tv
[
i
].
key
;
ret
=
crypto_cipher_setkey
(
tfm
,
key
,
aes_tv
[
i
].
keylen
);
if
(
ret
)
{
printk
(
"setkey() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
if
(
!
aes_tv
[
i
].
fail
)
goto
out
;
}
struct
cipher_testvec
*
cipher_tv
;
struct
scatterlist
sg
[
8
];
char
e
[
11
],
m
[
4
];
p
=
aes_tv
[
i
].
plaintext
;
sg
[
0
].
page
=
virt_to_page
(
p
);
sg
[
0
].
offset
=
offset_in_page
(
p
);
sg
[
0
].
length
=
aes_tv
[
i
].
plen
;
ret
=
crypto_cipher_encrypt
(
tfm
,
sg
,
sg
,
sg
[
0
].
length
);
if
(
ret
)
{
printk
(
"encrypt() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
goto
out
;
}
if
(
enc
==
ENCRYPT
)
strncpy
(
e
,
"encryption"
,
11
);
else
strncpy
(
e
,
"decryption"
,
11
);
if
(
mode
==
MODE_ECB
)
strncpy
(
m
,
"ECB"
,
4
);
else
strncpy
(
m
,
"CBC"
,
4
);
q
=
kmap
(
sg
[
0
].
page
)
+
sg
[
0
].
offset
;
hexdump
(
q
,
aes_tv
[
i
].
rlen
);
printk
(
"
\n
testing %s %s %s
\n
"
,
algo
,
m
,
e
);
printk
(
"%s
\n
"
,
memcmp
(
q
,
aes_tv
[
i
].
result
,
aes_tv
[
i
].
rlen
)
?
"fail"
:
"pass"
);
}
tsize
=
sizeof
(
struct
cipher_testvec
);
tsize
*=
tcount
;
printk
(
"
\n
testing aes decryption
\n
"
);
tsize
=
sizeof
(
aes_dec_tv_template
);
if
(
tsize
>
TVMEMSIZE
)
{
printk
(
"template (%u) too big for tvmem (%u)
\n
"
,
tsize
,
TVMEMSIZE
);
return
;
}
memcpy
(
tvmem
,
aes_dec_tv_template
,
tsize
);
aes_tv
=
(
void
*
)
tvmem
;
for
(
i
=
0
;
i
<
AES_DEC_TEST_VECTORS
;
i
++
)
{
printk
(
"test %u (%d bit key):
\n
"
,
i
+
1
,
aes_tv
[
i
].
keylen
*
8
);
key
=
aes_tv
[
i
].
key
;
ret
=
crypto_cipher_setkey
(
tfm
,
key
,
aes_tv
[
i
].
keylen
);
if
(
ret
)
{
printk
(
"setkey() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
if
(
!
aes_tv
[
i
].
fail
)
goto
out
;
}
p
=
aes_tv
[
i
].
plaintext
;
sg
[
0
].
page
=
virt_to_page
(
p
);
sg
[
0
].
offset
=
offset_in_page
(
p
);
sg
[
0
].
length
=
aes_tv
[
i
].
plen
;
ret
=
crypto_cipher_decrypt
(
tfm
,
sg
,
sg
,
sg
[
0
].
length
);
if
(
ret
)
{
printk
(
"decrypt() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
goto
out
;
}
q
=
kmap
(
sg
[
0
].
page
)
+
sg
[
0
].
offset
;
hexdump
(
q
,
aes_tv
[
i
].
rlen
);
printk
(
"%s
\n
"
,
memcmp
(
q
,
aes_tv
[
i
].
result
,
aes_tv
[
i
].
rlen
)
?
"fail"
:
"pass"
);
}
out:
crypto_free_tfm
(
tfm
);
}
void
test_cast5
(
void
)
{
unsigned
int
ret
,
i
,
tsize
;
u8
*
p
,
*
q
,
*
key
;
struct
crypto_tfm
*
tfm
;
struct
cast5_tv
*
c5_tv
;
struct
scatterlist
sg
[
1
];
printk
(
"
\n
testing cast5 encryption
\n
"
);
memcpy
(
tvmem
,
template
,
tsize
);
cipher_tv
=
(
void
*
)
tvmem
;
tfm
=
crypto_alloc_tfm
(
"cast5"
,
0
);
if
(
mode
)
tfm
=
crypto_alloc_tfm
(
algo
,
0
);
else
tfm
=
crypto_alloc_tfm
(
algo
,
CRYPTO_TFM_MODE_CBC
);
if
(
tfm
==
NULL
)
{
printk
(
"failed to load transform for cast5 (default ecb)
\n
"
);
return
;
}
tsize
=
sizeof
(
cast5_enc_tv_template
);
if
(
tsize
>
TVMEMSIZE
)
{
printk
(
"template (%u) too big for tvmem (%u)
\n
"
,
tsize
,
TVMEMSIZE
);
printk
(
"failed to load transform for %s %s
\n
"
,
algo
,
m
);
return
;
}
memcpy
(
tvmem
,
cast5_enc_tv_template
,
tsize
);
c5_tv
=
(
void
*
)
tvmem
;
for
(
i
=
0
;
i
<
CAST5_ENC_TEST_VECTORS
;
i
++
)
{
printk
(
"test %u (%d bit key):
\n
"
,
i
+
1
,
c5_tv
[
i
].
keylen
*
8
);
key
=
c5_tv
[
i
].
key
;
ret
=
crypto_cipher_setkey
(
tfm
,
key
,
c5_tv
[
i
].
keylen
);
if
(
ret
)
{
printk
(
"setkey() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
if
(
!
c5_tv
[
i
].
fail
)
j
=
0
;
for
(
i
=
0
;
i
<
tcount
;
i
++
)
{
if
(
!
(
cipher_tv
[
i
].
np
))
{
j
++
;
printk
(
"test %u (%d bit key):
\n
"
,
j
,
cipher_tv
[
i
].
klen
*
8
);
tfm
->
crt_flags
=
0
;
if
(
cipher_tv
[
i
].
wk
)
tfm
->
crt_flags
|=
CRYPTO_TFM_REQ_WEAK_KEY
;
key
=
cipher_tv
[
i
].
key
;
ret
=
crypto_cipher_setkey
(
tfm
,
key
,
cipher_tv
[
i
].
klen
);
if
(
ret
)
{
printk
(
"setkey() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
if
(
!
cipher_tv
[
i
].
fail
)
goto
out
;
}
p
=
cipher_tv
[
i
].
input
;
sg
[
0
].
page
=
virt_to_page
(
p
);
sg
[
0
].
offset
=
offset_in_page
(
p
);
sg
[
0
].
length
=
cipher_tv
[
i
].
ilen
;
if
(
!
mode
)
{
crypto_cipher_set_iv
(
tfm
,
cipher_tv
[
i
].
iv
,
crypto_tfm_alg_ivsize
(
tfm
));
}
if
(
enc
)
ret
=
crypto_cipher_encrypt
(
tfm
,
sg
,
sg
,
cipher_tv
[
i
].
ilen
);
else
ret
=
crypto_cipher_decrypt
(
tfm
,
sg
,
sg
,
cipher_tv
[
i
].
ilen
);
if
(
ret
)
{
printk
(
"%s () failed flags=%x
\n
"
,
e
,
tfm
->
crt_flags
);
goto
out
;
}
q
=
kmap
(
sg
[
0
].
page
)
+
sg
[
0
].
offset
;
hexdump
(
q
,
cipher_tv
[
i
].
rlen
);
printk
(
"%s
\n
"
,
memcmp
(
q
,
cipher_tv
[
i
].
result
,
cipher_tv
[
i
].
rlen
)
?
"fail"
:
"pass"
);
}
p
=
c5_tv
[
i
].
plaintext
;
sg
[
0
].
page
=
virt_to_page
(
p
);
sg
[
0
].
offset
=
((
long
)
p
&
~
PAGE_MASK
);
sg
[
0
].
length
=
sizeof
(
c5_tv
[
i
].
plaintext
);
ret
=
crypto_cipher_encrypt
(
tfm
,
sg
,
sg
,
sg
[
0
].
length
);
if
(
ret
)
{
printk
(
"encrypt() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
goto
out
;
}
q
=
kmap
(
sg
[
0
].
page
)
+
sg
[
0
].
offset
;
hexdump
(
q
,
sizeof
(
c5_tv
[
i
].
ciphertext
));
printk
(
"%s
\n
"
,
memcmp
(
q
,
c5_tv
[
i
].
ciphertext
,
sizeof
(
c5_tv
[
i
].
ciphertext
))
?
"fail"
:
"pass"
);
}
tsize
=
sizeof
(
cast5_dec_tv_template
);
if
(
tsize
>
TVMEMSIZE
)
{
printk
(
"template (%u) too big for tvmem (%u)
\n
"
,
tsize
,
TVMEMSIZE
);
return
;
}
memcpy
(
tvmem
,
cast5_dec_tv_template
,
tsize
);
c5_tv
=
(
void
*
)
tvmem
;
for
(
i
=
0
;
i
<
CAST5_DEC_TEST_VECTORS
;
i
++
)
{
printk
(
"test %u (%d bit key):
\n
"
,
i
+
1
,
c5_tv
[
i
].
keylen
*
8
);
key
=
c5_tv
[
i
].
key
;
ret
=
crypto_cipher_setkey
(
tfm
,
key
,
c5_tv
[
i
].
keylen
);
if
(
ret
)
{
printk
(
"setkey() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
if
(
!
c5_tv
[
i
].
fail
)
printk
(
"
\n
testing %s %s %s across pages (chunking)
\n
"
,
algo
,
m
,
e
);
memset
(
xbuf
,
0
,
XBUFSIZE
);
j
=
0
;
for
(
i
=
0
;
i
<
tcount
;
i
++
)
{
if
(
cipher_tv
[
i
].
np
)
{
j
++
;
printk
(
"test %u (%d bit key):
\n
"
,
j
,
cipher_tv
[
i
].
klen
*
8
);
tfm
->
crt_flags
=
0
;
if
(
cipher_tv
[
i
].
wk
)
tfm
->
crt_flags
|=
CRYPTO_TFM_REQ_WEAK_KEY
;
key
=
cipher_tv
[
i
].
key
;
ret
=
crypto_cipher_setkey
(
tfm
,
key
,
cipher_tv
[
i
].
klen
);
if
(
ret
)
{
printk
(
"setkey() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
if
(
!
cipher_tv
[
i
].
fail
)
goto
out
;
}
temp
=
0
;
for
(
k
=
0
;
k
<
cipher_tv
[
i
].
np
;
k
++
)
{
memcpy
(
&
xbuf
[
IDX
[
k
]],
cipher_tv
[
i
].
input
+
temp
,
cipher_tv
[
i
].
tap
[
k
]);
temp
+=
cipher_tv
[
i
].
tap
[
k
];
p
=
&
xbuf
[
IDX
[
k
]];
sg
[
k
].
page
=
virt_to_page
(
p
);
sg
[
k
].
offset
=
offset_in_page
(
p
);
sg
[
k
].
length
=
cipher_tv
[
i
].
tap
[
k
];
}
if
(
!
mode
)
{
crypto_cipher_set_iv
(
tfm
,
cipher_tv
[
i
].
iv
,
crypto_tfm_alg_ivsize
(
tfm
));
}
if
(
enc
)
ret
=
crypto_cipher_encrypt
(
tfm
,
sg
,
sg
,
cipher_tv
[
i
].
ilen
);
else
ret
=
crypto_cipher_decrypt
(
tfm
,
sg
,
sg
,
cipher_tv
[
i
].
ilen
);
if
(
ret
)
{
printk
(
"%s () failed flags=%x
\n
"
,
e
,
tfm
->
crt_flags
);
goto
out
;
}
}
p
=
c5_tv
[
i
].
plaintext
;
sg
[
0
].
page
=
virt_to_page
(
p
);
sg
[
0
].
offset
=
((
long
)
p
&
~
PAGE_MASK
);
sg
[
0
].
length
=
sizeof
(
c5_tv
[
i
].
plaintext
);
ret
=
crypto_cipher_decrypt
(
tfm
,
sg
,
sg
,
sg
[
0
].
length
);
if
(
ret
)
{
printk
(
"decrypt() failed flags=%x
\n
"
,
tfm
->
crt_flags
);
goto
out
;
temp
=
0
;
for
(
k
=
0
;
k
<
cipher_tv
[
i
].
np
;
k
++
)
{
printk
(
"page %u
\n
"
,
k
);
q
=
kmap
(
sg
[
k
].
page
)
+
sg
[
k
].
offset
;
hexdump
(
q
,
cipher_tv
[
i
].
tap
[
k
]);
printk
(
"%s
\n
"
,
memcmp
(
q
,
cipher_tv
[
i
].
result
+
temp
,
cipher_tv
[
i
].
tap
[
k
])
?
"fail"
:
"pass"
);
temp
+=
cipher_tv
[
i
].
tap
[
k
];
}
}
q
=
kmap
(
sg
[
0
].
page
)
+
sg
[
0
].
offset
;
hexdump
(
q
,
sizeof
(
c5_tv
[
i
].
ciphertext
));
printk
(
"%s
\n
"
,
memcmp
(
q
,
c5_tv
[
i
].
ciphertext
,
sizeof
(
c5_tv
[
i
].
ciphertext
))
?
"fail"
:
"pass"
);
}
out:
crypto_free_tfm
(
tfm
);
crypto_free_tfm
(
tfm
);
}
static
void
...
...
@@ -2485,75 +510,118 @@ do_test(void)
switch
(
mode
)
{
case
0
:
test_md5
();
test_sha1
();
test_des
();
test_des3_ede
();
test_md4
();
test_sha256
();
test_blowfish
();
test_twofish
();
test_serpent
();
test_cast6
();
test_aes
();
test_sha384
();
test_sha512
();
test_deflate
();
test_cast5
();
test_cast6
();
test_hash
(
"md5"
,
md5_tv_template
,
MD5_TEST_VECTORS
);
test_hash
(
"sha1"
,
sha1_tv_template
,
SHA1_TEST_VECTORS
);
//DES
test_cipher
(
"des"
,
MODE_ECB
,
ENCRYPT
,
des_enc_tv_template
,
DES_ENC_TEST_VECTORS
);
test_cipher
(
"des"
,
MODE_ECB
,
DECRYPT
,
des_dec_tv_template
,
DES_DEC_TEST_VECTORS
);
test_cipher
(
"des"
,
MODE_CBC
,
ENCRYPT
,
des_cbc_enc_tv_template
,
DES_CBC_ENC_TEST_VECTORS
);
test_cipher
(
"des"
,
MODE_CBC
,
DECRYPT
,
des_cbc_dec_tv_template
,
DES_CBC_DEC_TEST_VECTORS
);
//DES3_EDE
test_cipher
(
"des3_ede"
,
MODE_ECB
,
ENCRYPT
,
des3_ede_enc_tv_template
,
DES3_EDE_ENC_TEST_VECTORS
);
test_cipher
(
"des3_ede"
,
MODE_ECB
,
DECRYPT
,
des3_ede_dec_tv_template
,
DES3_EDE_DEC_TEST_VECTORS
);
test_hash
(
"md4"
,
md4_tv_template
,
MD4_TEST_VECTORS
);
test_hash
(
"sha256"
,
sha256_tv_template
,
SHA256_TEST_VECTORS
);
//BLOWFISH
test_cipher
(
"blowfish"
,
MODE_ECB
,
ENCRYPT
,
bf_enc_tv_template
,
BF_ENC_TEST_VECTORS
);
test_cipher
(
"blowfish"
,
MODE_ECB
,
DECRYPT
,
bf_dec_tv_template
,
BF_DEC_TEST_VECTORS
);
test_cipher
(
"blowfish"
,
MODE_CBC
,
ENCRYPT
,
bf_cbc_enc_tv_template
,
BF_CBC_ENC_TEST_VECTORS
);
test_cipher
(
"blowfish"
,
MODE_CBC
,
DECRYPT
,
bf_cbc_dec_tv_template
,
BF_CBC_DEC_TEST_VECTORS
);
//TWOFISH
test_cipher
(
"twofish"
,
MODE_ECB
,
ENCRYPT
,
tf_enc_tv_template
,
TF_ENC_TEST_VECTORS
);
test_cipher
(
"twofish"
,
MODE_ECB
,
DECRYPT
,
tf_dec_tv_template
,
TF_DEC_TEST_VECTORS
);
test_cipher
(
"twofish"
,
MODE_CBC
,
ENCRYPT
,
tf_cbc_enc_tv_template
,
TF_CBC_ENC_TEST_VECTORS
);
test_cipher
(
"twofish"
,
MODE_CBC
,
DECRYPT
,
tf_cbc_dec_tv_template
,
TF_CBC_DEC_TEST_VECTORS
);
//SERPENT
test_cipher
(
"serpent"
,
MODE_ECB
,
ENCRYPT
,
serpent_enc_tv_template
,
SERPENT_ENC_TEST_VECTORS
);
test_cipher
(
"serpent"
,
MODE_ECB
,
DECRYPT
,
serpent_dec_tv_template
,
SERPENT_DEC_TEST_VECTORS
);
//AES
test_cipher
(
"aes"
,
MODE_ECB
,
ENCRYPT
,
aes_enc_tv_template
,
AES_ENC_TEST_VECTORS
);
test_cipher
(
"aes"
,
MODE_ECB
,
DECRYPT
,
aes_dec_tv_template
,
AES_DEC_TEST_VECTORS
);
//CAST5
test_cipher
(
"cast5"
,
MODE_ECB
,
ENCRYPT
,
cast5_enc_tv_template
,
CAST5_ENC_TEST_VECTORS
);
test_cipher
(
"cast5"
,
MODE_ECB
,
DECRYPT
,
cast5_dec_tv_template
,
CAST5_DEC_TEST_VECTORS
);
//CAST6
test_cipher
(
"cast6"
,
MODE_ECB
,
ENCRYPT
,
cast6_enc_tv_template
,
CAST6_ENC_TEST_VECTORS
);
test_cipher
(
"cast6"
,
MODE_ECB
,
DECRYPT
,
cast6_dec_tv_template
,
CAST6_DEC_TEST_VECTORS
);
test_hash
(
"sha384"
,
sha384_tv_template
,
SHA384_TEST_VECTORS
);
test_hash
(
"sha512"
,
sha512_tv_template
,
SHA512_TEST_VECTORS
);
test_deflate
();
#ifdef CONFIG_CRYPTO_HMAC
test_hmac
_md5
(
);
test_hmac
_sha1
();
test_hmac
_sha256
(
);
test_hmac
(
"md5"
,
hmac_md5_tv_template
,
HMAC_MD5_TEST_VECTORS
);
test_hmac
(
"sha1"
,
hmac_sha1_tv_template
,
HMAC_SHA1_TEST_VECTORS
);
test_hmac
(
"sha256"
,
hmac_sha256_tv_template
,
HMAC_SHA256_TEST_VECTORS
);
#endif
break
;
case
1
:
test_
md5
(
);
test_
hash
(
"md5"
,
md5_tv_template
,
MD5_TEST_VECTORS
);
break
;
case
2
:
test_
sha1
(
);
test_
hash
(
"sha1"
,
sha1_tv_template
,
SHA1_TEST_VECTORS
);
break
;
case
3
:
test_des
();
test_cipher
(
"des"
,
MODE_ECB
,
ENCRYPT
,
des_enc_tv_template
,
DES_ENC_TEST_VECTORS
);
test_cipher
(
"des"
,
MODE_ECB
,
DECRYPT
,
des_dec_tv_template
,
DES_DEC_TEST_VECTORS
);
test_cipher
(
"des"
,
MODE_CBC
,
ENCRYPT
,
des_cbc_enc_tv_template
,
DES_CBC_ENC_TEST_VECTORS
);
test_cipher
(
"des"
,
MODE_CBC
,
DECRYPT
,
des_cbc_dec_tv_template
,
DES_CBC_DEC_TEST_VECTORS
);
break
;
case
4
:
test_des3_ede
();
test_cipher
(
"des3_ede"
,
MODE_ECB
,
ENCRYPT
,
des3_ede_enc_tv_template
,
DES3_EDE_ENC_TEST_VECTORS
);
test_cipher
(
"des3_ede"
,
MODE_ECB
,
DECRYPT
,
des3_ede_dec_tv_template
,
DES3_EDE_DEC_TEST_VECTORS
);
break
;
case
5
:
test_
md4
(
);
test_
hash
(
"md4"
,
md4_tv_template
,
MD4_TEST_VECTORS
);
break
;
case
6
:
test_
sha256
(
);
test_
hash
(
"sha256"
,
sha256_tv_template
,
SHA256_TEST_VECTORS
);
break
;
case
7
:
test_blowfish
();
test_cipher
(
"blowfish"
,
MODE_ECB
,
ENCRYPT
,
bf_enc_tv_template
,
BF_ENC_TEST_VECTORS
);
test_cipher
(
"blowfish"
,
MODE_ECB
,
DECRYPT
,
bf_dec_tv_template
,
BF_DEC_TEST_VECTORS
);
test_cipher
(
"blowfish"
,
MODE_CBC
,
ENCRYPT
,
bf_cbc_enc_tv_template
,
BF_CBC_ENC_TEST_VECTORS
);
test_cipher
(
"blowfish"
,
MODE_CBC
,
DECRYPT
,
bf_cbc_dec_tv_template
,
BF_CBC_DEC_TEST_VECTORS
);
break
;
case
8
:
test_twofish
();
test_cipher
(
"twofish"
,
MODE_ECB
,
ENCRYPT
,
tf_enc_tv_template
,
TF_ENC_TEST_VECTORS
);
test_cipher
(
"twofish"
,
MODE_ECB
,
DECRYPT
,
tf_dec_tv_template
,
TF_DEC_TEST_VECTORS
);
test_cipher
(
"twofish"
,
MODE_CBC
,
ENCRYPT
,
tf_cbc_enc_tv_template
,
TF_CBC_ENC_TEST_VECTORS
);
test_cipher
(
"twofish"
,
MODE_CBC
,
DECRYPT
,
tf_cbc_dec_tv_template
,
TF_CBC_DEC_TEST_VECTORS
);
break
;
case
9
:
test_serpent
();
break
;
case
10
:
test_aes
();
test_cipher
(
"aes"
,
MODE_ECB
,
ENCRYPT
,
aes_enc_tv_template
,
AES_ENC_TEST_VECTORS
);
test_cipher
(
"aes"
,
MODE_ECB
,
DECRYPT
,
aes_dec_tv_template
,
AES_DEC_TEST_VECTORS
);
break
;
case
11
:
test_
sha384
(
);
test_
hash
(
"sha384"
,
sha384_tv_template
,
SHA384_TEST_VECTORS
);
break
;
case
12
:
test_
sha512
(
);
test_
hash
(
"sha512"
,
sha512_tv_template
,
SHA512_TEST_VECTORS
);
break
;
case
13
:
...
...
@@ -2561,24 +629,26 @@ do_test(void)
break
;
case
14
:
test_cast5
();
test_cipher
(
"cast5"
,
MODE_ECB
,
ENCRYPT
,
cast5_enc_tv_template
,
CAST5_ENC_TEST_VECTORS
);
test_cipher
(
"cast5"
,
MODE_ECB
,
DECRYPT
,
cast5_dec_tv_template
,
CAST5_DEC_TEST_VECTORS
);
break
;
case
15
:
test_cast6
();
test_cipher
(
"cast6"
,
MODE_ECB
,
ENCRYPT
,
cast6_enc_tv_template
,
CAST6_ENC_TEST_VECTORS
);
test_cipher
(
"cast6"
,
MODE_ECB
,
DECRYPT
,
cast6_dec_tv_template
,
CAST6_DEC_TEST_VECTORS
);
break
;
#ifdef CONFIG_CRYPTO_HMAC
case
100
:
test_hmac
_md5
(
);
test_hmac
(
"md5"
,
hmac_md5_tv_template
,
HMAC_MD5_TEST_VECTORS
);
break
;
case
101
:
test_hmac
_sha1
();
test_hmac
(
"sha1"
,
hmac_sha1_tv_template
,
HMAC_SHA1_TEST_VECTORS
);
break
;
case
102
:
test_hmac
_sha256
(
);
test_hmac
(
"sha256"
,
hmac_sha256_tv_template
,
HMAC_SHA256_TEST_VECTORS
);
break
;
#endif
...
...
crypto/tcrypt.h
View file @
91f70b00
/*
/*
* Quick & dirty crypto testing module.
*
* This will only exist until we have a better testing mechanism
...
...
@@ -6,66 +6,118 @@
*
* Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
* Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org>
*
*
* 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.
*
* 14 - 09 - 2003 Changes by Kartikey Mahendra Bhatt
*
*/
#ifndef _CRYPTO_TCRYPT_H
#define _CRYPTO_TCRYPT_H
#define MD5_DIGEST_SIZE 16
#define MD4_DIGEST_SIZE 16
#define SHA1_DIGEST_SIZE 20
#define SHA256_DIGEST_SIZE 32
#define SHA384_DIGEST_SIZE 48
#define SHA512_DIGEST_SIZE 64
#define MAX_DIGEST_SIZE 64
#define MAX_TAP 8
#define MAX_KEYLEN 56
#define MAX_IVLEN 32
struct
hash_testvec
{
char
plaintext
[
128
];
unsigned
char
psize
;
char
digest
[
MAX_DIGEST_SIZE
];
unsigned
char
np
;
unsigned
char
tap
[
MAX_TAP
];
};
struct
hmac_testvec
{
char
key
[
128
];
unsigned
char
ksize
;
char
plaintext
[
128
];
unsigned
char
psize
;
char
digest
[
MAX_DIGEST_SIZE
];
unsigned
char
np
;
unsigned
char
tap
[
MAX_TAP
];
};
struct
cipher_testvec
{
unsigned
char
fail
;
unsigned
char
wk
;
/* weak key flag */
char
key
[
MAX_KEYLEN
];
unsigned
char
klen
;
char
iv
[
MAX_IVLEN
];
char
input
[
48
];
unsigned
char
ilen
;
char
result
[
48
];
unsigned
char
rlen
;
int
np
;
unsigned
char
tap
[
MAX_TAP
];
};
/*
* MD4 test vectors from RFC1320
*/
#define MD4_TEST_VECTORS 7
struct
md4_testvec
{
char
plaintext
[
128
];
char
digest
[
MD4_DIGEST_SIZE
];
}
md4_tv_template
[]
=
{
{
""
,
struct
hash_testvec
md4_tv_template
[]
=
{
{
""
,
0
,
{
0x31
,
0xd6
,
0xcf
,
0xe0
,
0xd1
,
0x6a
,
0xe9
,
0x31
,
0xb7
,
0x3c
,
0x59
,
0xd7
,
0xe0
,
0xc0
,
0x89
,
0xc0
}
},
{
"a"
,
0xb7
,
0x3c
,
0x59
,
0xd7
,
0xe0
,
0xc0
,
0x89
,
0xc0
},
0
,
{}
},
{
"a"
,
1
,
{
0xbd
,
0xe5
,
0x2c
,
0xb3
,
0x1d
,
0xe3
,
0x3e
,
0x46
,
0x24
,
0x5e
,
0x05
,
0xfb
,
0xdb
,
0xd6
,
0xfb
,
0x24
}
0x24
,
0x5e
,
0x05
,
0xfb
,
0xdb
,
0xd6
,
0xfb
,
0x24
},
0
,
{}
},
{
"abc"
,
{
"abc"
,
3
,
{
0xa4
,
0x48
,
0x01
,
0x7a
,
0xaf
,
0x21
,
0xd8
,
0x52
,
0x5f
,
0xc1
,
0x0a
,
0xe8
,
0x7a
,
0xa6
,
0x72
,
0x9d
}
},
{
"message digest"
,
0x5f
,
0xc1
,
0x0a
,
0xe8
,
0x7a
,
0xa6
,
0x72
,
0x9d
},
0
,
{}
},
{
"message digest"
,
14
,
{
0xd9
,
0x13
,
0x0a
,
0x81
,
0x64
,
0x54
,
0x9f
,
0xe8
,
0x18
,
0x87
,
0x48
,
0x06
,
0xe1
,
0xc7
,
0x01
,
0x4b
}
},
{
"abcdefghijklmnopqrstuvwxyz"
,
0x18
,
0x87
,
0x48
,
0x06
,
0xe1
,
0xc7
,
0x01
,
0x4b
},
0
,
{}
},
{
"abcdefghijklmnopqrstuvwxyz"
,
26
,
{
0xd7
,
0x9e
,
0x1c
,
0x30
,
0x8a
,
0xa5
,
0xbb
,
0xcd
,
0xee
,
0xa8
,
0xed
,
0x63
,
0xdf
,
0x41
,
0x2d
,
0xa9
}
},
{
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
,
0xee
,
0xa8
,
0xed
,
0x63
,
0xdf
,
0x41
,
0x2d
,
0xa9
},
2
,
{
13
,
13
},
},
{
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
,
62
,
{
0x04
,
0x3f
,
0x85
,
0x82
,
0xf2
,
0x41
,
0xdb
,
0x35
,
0x1c
,
0xe6
,
0x27
,
0xe1
,
0x53
,
0xe7
,
0xf0
,
0xe4
}
},
{
"123456789012345678901234567890123456789012345678901234567890123"
0x1c
,
0xe6
,
0x27
,
0xe1
,
0x53
,
0xe7
,
0xf0
,
0xe4
},
0
,
{}
},
{
"123456789012345678901234567890123456789012345678901234567890123"
"45678901234567890"
,
80
,
{
0xe3
,
0x3b
,
0x4d
,
0xdc
,
0x9c
,
0x38
,
0xf2
,
0x19
,
0x9c
,
0x3e
,
0x7b
,
0x16
,
0x4f
,
0xcc
,
0x05
,
0x36
}
0x9c
,
0x3e
,
0x7b
,
0x16
,
0x4f
,
0xcc
,
0x05
,
0x36
},
0
,
{}
},
};
...
...
@@ -74,40 +126,244 @@ struct md4_testvec {
*/
#define MD5_TEST_VECTORS 7
struct
md5_testvec
{
char
plaintext
[
128
];
char
digest
[
MD5_DIGEST_SIZE
];
}
md5_tv_template
[]
=
{
{
""
,
struct
hash_testvec
md5_tv_template
[]
=
{
{
""
,
0
,
{
0xd4
,
0x1d
,
0x8c
,
0xd9
,
0x8f
,
0x00
,
0xb2
,
0x04
,
0xe9
,
0x80
,
0x09
,
0x98
,
0xec
,
0xf8
,
0x42
,
0x7e
}
},
{
"a"
,
0xe9
,
0x80
,
0x09
,
0x98
,
0xec
,
0xf8
,
0x42
,
0x7e
},
0
,
{}
},
{
"a"
,
1
,
{
0x0c
,
0xc1
,
0x75
,
0xb9
,
0xc0
,
0xf1
,
0xb6
,
0xa8
,
0x31
,
0xc3
,
0x99
,
0xe2
,
0x69
,
0x77
,
0x26
,
0x61
}
},
{
"abc"
,
0x31
,
0xc3
,
0x99
,
0xe2
,
0x69
,
0x77
,
0x26
,
0x61
},
0
,
{}
},
{
"abc"
,
3
,
{
0x90
,
0x01
,
0x50
,
0x98
,
0x3c
,
0xd2
,
0x4f
,
0xb0
,
0xd6
,
0x96
,
0x3f
,
0x7d
,
0x28
,
0xe1
,
0x7f
,
0x72
}
},
{
"message digest"
,
0xd6
,
0x96
,
0x3f
,
0x7d
,
0x28
,
0xe1
,
0x7f
,
0x72
},
0
,
{}
},
{
"message digest"
,
14
,
{
0xf9
,
0x6b
,
0x69
,
0x7d
,
0x7c
,
0xb7
,
0x93
,
0x8d
,
0x52
,
0x5a
,
0x2f
,
0x31
,
0xaa
,
0xf1
,
0x61
,
0xd0
}
},
{
"abcdefghijklmnopqrstuvwxyz"
,
0x52
,
0x5a
,
0x2f
,
0x31
,
0xaa
,
0xf1
,
0x61
,
0xd0
},
0
,
{}
},
{
"abcdefghijklmnopqrstuvwxyz"
,
26
,
{
0xc3
,
0xfc
,
0xd3
,
0xd7
,
0x61
,
0x92
,
0xe4
,
0x00
,
0x7d
,
0xfb
,
0x49
,
0x6c
,
0xca
,
0x67
,
0xe1
,
0x3b
}
},
{
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
,
0x7d
,
0xfb
,
0x49
,
0x6c
,
0xca
,
0x67
,
0xe1
,
0x3b
},
2
,
{
13
,
13
}
},
{
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
,
62
,
{
0xd1
,
0x74
,
0xab
,
0x98
,
0xd2
,
0x77
,
0xd9
,
0xf5
,
0xa5
,
0x61
,
0x1c
,
0x2c
,
0x9f
,
0x41
,
0x9d
,
0x9f
}
},
{
"12345678901234567890123456789012345678901234567890123456789012"
"345678901234567890"
,
0xa5
,
0x61
,
0x1c
,
0x2c
,
0x9f
,
0x41
,
0x9d
,
0x9f
},
0
,
{}
},
{
"12345678901234567890123456789012345678901234567890123456789012"
"345678901234567890"
,
80
,
{
0x57
,
0xed
,
0xf4
,
0xa2
,
0x2b
,
0xe3
,
0xc9
,
0x55
,
0xac
,
0x49
,
0xda
,
0x2e
,
0x21
,
0x07
,
0xb6
,
0x7a
}
}
0xac
,
0x49
,
0xda
,
0x2e
,
0x21
,
0x07
,
0xb6
,
0x7a
},
0
,
{}
}
};
/*
* SHA1 test vectors from from FIPS PUB 180-1
*/
#define SHA1_TEST_VECTORS 2
struct
hash_testvec
sha1_tv_template
[]
=
{
{
"abc"
,
3
,
{
0xA9
,
0x99
,
0x3E
,
0x36
,
0x47
,
0x06
,
0x81
,
0x6A
,
0xBA
,
0x3E
,
0x25
,
0x71
,
0x78
,
0x50
,
0xC2
,
0x6C
,
0x9C
,
0xD0
,
0xD8
,
0x9D
},
0
,
{}
},
{
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
,
56
,
{
0x84
,
0x98
,
0x3E
,
0x44
,
0x1C
,
0x3B
,
0xD2
,
0x6E
,
0xBA
,
0xAE
,
0x4A
,
0xA1
,
0xF9
,
0x51
,
0x29
,
0xE5
,
0xE5
,
0x46
,
0x70
,
0xF1
},
2
,
{
28
,
28
}
}
};
/*
* SHA256 test vectors from from NIST
*/
#define SHA256_TEST_VECTORS 2
struct
hash_testvec
sha256_tv_template
[]
=
{
{
"abc"
,
3
,
{
0xba
,
0x78
,
0x16
,
0xbf
,
0x8f
,
0x01
,
0xcf
,
0xea
,
0x41
,
0x41
,
0x40
,
0xde
,
0x5d
,
0xae
,
0x22
,
0x23
,
0xb0
,
0x03
,
0x61
,
0xa3
,
0x96
,
0x17
,
0x7a
,
0x9c
,
0xb4
,
0x10
,
0xff
,
0x61
,
0xf2
,
0x00
,
0x15
,
0xad
},
0
,
{}
},
{
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
,
56
,
{
0x24
,
0x8d
,
0x6a
,
0x61
,
0xd2
,
0x06
,
0x38
,
0xb8
,
0xe5
,
0xc0
,
0x26
,
0x93
,
0x0c
,
0x3e
,
0x60
,
0x39
,
0xa3
,
0x3c
,
0xe4
,
0x59
,
0x64
,
0xff
,
0x21
,
0x67
,
0xf6
,
0xec
,
0xed
,
0xd4
,
0x19
,
0xdb
,
0x06
,
0xc1
},
2
,
{
28
,
28
}
},
};
/*
* SHA384 test vectors from from NIST and kerneli
*/
#define SHA384_TEST_VECTORS 4
struct
hash_testvec
sha384_tv_template
[]
=
{
{
"abc"
,
3
,
{
0xcb
,
0x00
,
0x75
,
0x3f
,
0x45
,
0xa3
,
0x5e
,
0x8b
,
0xb5
,
0xa0
,
0x3d
,
0x69
,
0x9a
,
0xc6
,
0x50
,
0x07
,
0x27
,
0x2c
,
0x32
,
0xab
,
0x0e
,
0xde
,
0xd1
,
0x63
,
0x1a
,
0x8b
,
0x60
,
0x5a
,
0x43
,
0xff
,
0x5b
,
0xed
,
0x80
,
0x86
,
0x07
,
0x2b
,
0xa1
,
0xe7
,
0xcc
,
0x23
,
0x58
,
0xba
,
0xec
,
0xa1
,
0x34
,
0xc8
,
0x25
,
0xa7
},
0
,
{}
},
{
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
,
56
,
{
0x33
,
0x91
,
0xfd
,
0xdd
,
0xfc
,
0x8d
,
0xc7
,
0x39
,
0x37
,
0x07
,
0xa6
,
0x5b
,
0x1b
,
0x47
,
0x09
,
0x39
,
0x7c
,
0xf8
,
0xb1
,
0xd1
,
0x62
,
0xaf
,
0x05
,
0xab
,
0xfe
,
0x8f
,
0x45
,
0x0d
,
0xe5
,
0xf3
,
0x6b
,
0xc6
,
0xb0
,
0x45
,
0x5a
,
0x85
,
0x20
,
0xbc
,
0x4e
,
0x6f
,
0x5f
,
0xe9
,
0x5b
,
0x1f
,
0xe3
,
0xc8
,
0x45
,
0x2b
},
0
,
{}
},
{
"abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn"
"hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"
,
112
,
{
0x09
,
0x33
,
0x0c
,
0x33
,
0xf7
,
0x11
,
0x47
,
0xe8
,
0x3d
,
0x19
,
0x2f
,
0xc7
,
0x82
,
0xcd
,
0x1b
,
0x47
,
0x53
,
0x11
,
0x1b
,
0x17
,
0x3b
,
0x3b
,
0x05
,
0xd2
,
0x2f
,
0xa0
,
0x80
,
0x86
,
0xe3
,
0xb0
,
0xf7
,
0x12
,
0xfc
,
0xc7
,
0xc7
,
0x1a
,
0x55
,
0x7e
,
0x2d
,
0xb9
,
0x66
,
0xc3
,
0xe9
,
0xfa
,
0x91
,
0x74
,
0x60
,
0x39
},
0
,
{}
},
{
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd"
"efghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"
,
104
,
{
0x3d
,
0x20
,
0x89
,
0x73
,
0xab
,
0x35
,
0x08
,
0xdb
,
0xbd
,
0x7e
,
0x2c
,
0x28
,
0x62
,
0xba
,
0x29
,
0x0a
,
0xd3
,
0x01
,
0x0e
,
0x49
,
0x78
,
0xc1
,
0x98
,
0xdc
,
0x4d
,
0x8f
,
0xd0
,
0x14
,
0xe5
,
0x82
,
0x82
,
0x3a
,
0x89
,
0xe1
,
0x6f
,
0x9b
,
0x2a
,
0x7b
,
0xbc
,
0x1a
,
0xc9
,
0x38
,
0xe2
,
0xd1
,
0x99
,
0xe8
,
0xbe
,
0xa4
},
4
,
{
26
,
26
,
26
,
26
}
},
};
/*
* SHA512 test vectors from from NIST and kerneli
*/
#define SHA512_TEST_VECTORS 4
struct
hash_testvec
sha512_tv_template
[]
=
{
{
"abc"
,
3
,
{
0xdd
,
0xaf
,
0x35
,
0xa1
,
0x93
,
0x61
,
0x7a
,
0xba
,
0xcc
,
0x41
,
0x73
,
0x49
,
0xae
,
0x20
,
0x41
,
0x31
,
0x12
,
0xe6
,
0xfa
,
0x4e
,
0x89
,
0xa9
,
0x7e
,
0xa2
,
0x0a
,
0x9e
,
0xee
,
0xe6
,
0x4b
,
0x55
,
0xd3
,
0x9a
,
0x21
,
0x92
,
0x99
,
0x2a
,
0x27
,
0x4f
,
0xc1
,
0xa8
,
0x36
,
0xba
,
0x3c
,
0x23
,
0xa3
,
0xfe
,
0xeb
,
0xbd
,
0x45
,
0x4d
,
0x44
,
0x23
,
0x64
,
0x3c
,
0xe8
,
0x0e
,
0x2a
,
0x9a
,
0xc9
,
0x4f
,
0xa5
,
0x4c
,
0xa4
,
0x9f
},
0
,
{}
},
{
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
,
56
,
{
0x20
,
0x4a
,
0x8f
,
0xc6
,
0xdd
,
0xa8
,
0x2f
,
0x0a
,
0x0c
,
0xed
,
0x7b
,
0xeb
,
0x8e
,
0x08
,
0xa4
,
0x16
,
0x57
,
0xc1
,
0x6e
,
0xf4
,
0x68
,
0xb2
,
0x28
,
0xa8
,
0x27
,
0x9b
,
0xe3
,
0x31
,
0xa7
,
0x03
,
0xc3
,
0x35
,
0x96
,
0xfd
,
0x15
,
0xc1
,
0x3b
,
0x1b
,
0x07
,
0xf9
,
0xaa
,
0x1d
,
0x3b
,
0xea
,
0x57
,
0x78
,
0x9c
,
0xa0
,
0x31
,
0xad
,
0x85
,
0xc7
,
0xa7
,
0x1d
,
0xd7
,
0x03
,
0x54
,
0xec
,
0x63
,
0x12
,
0x38
,
0xca
,
0x34
,
0x45
},
0
,
{}
},
{
"abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn"
"hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"
,
112
,
{
0x8e
,
0x95
,
0x9b
,
0x75
,
0xda
,
0xe3
,
0x13
,
0xda
,
0x8c
,
0xf4
,
0xf7
,
0x28
,
0x14
,
0xfc
,
0x14
,
0x3f
,
0x8f
,
0x77
,
0x79
,
0xc6
,
0xeb
,
0x9f
,
0x7f
,
0xa1
,
0x72
,
0x99
,
0xae
,
0xad
,
0xb6
,
0x88
,
0x90
,
0x18
,
0x50
,
0x1d
,
0x28
,
0x9e
,
0x49
,
0x00
,
0xf7
,
0xe4
,
0x33
,
0x1b
,
0x99
,
0xde
,
0xc4
,
0xb5
,
0x43
,
0x3a
,
0xc7
,
0xd3
,
0x29
,
0xee
,
0xb6
,
0xdd
,
0x26
,
0x54
,
0x5e
,
0x96
,
0xe5
,
0x5b
,
0x87
,
0x4b
,
0xe9
,
0x09
},
0
,
{}
},
{
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd"
"efghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"
,
104
,
{
0x93
,
0x0d
,
0x0c
,
0xef
,
0xcb
,
0x30
,
0xff
,
0x11
,
0x33
,
0xb6
,
0x89
,
0x81
,
0x21
,
0xf1
,
0xcf
,
0x3d
,
0x27
,
0x57
,
0x8a
,
0xfc
,
0xaf
,
0xe8
,
0x67
,
0x7c
,
0x52
,
0x57
,
0xcf
,
0x06
,
0x99
,
0x11
,
0xf7
,
0x5d
,
0x8f
,
0x58
,
0x31
,
0xb5
,
0x6e
,
0xbf
,
0xda
,
0x67
,
0xb2
,
0x78
,
0xe6
,
0x6d
,
0xff
,
0x8b
,
0x84
,
0xfe
,
0x2b
,
0x28
,
0x70
,
0xf7
,
0x42
,
0xa5
,
0x80
,
0xd8
,
0xed
,
0xb4
,
0x19
,
0x87
,
0x23
,
0x28
,
0x50
,
0xc9
},
4
,
{
26
,
26
,
26
,
26
}
},
};
#ifdef CONFIG_CRYPTO_HMAC
/*
* HMAC-MD5 test vectors from RFC2202
...
...
@@ -115,76 +371,71 @@ struct md5_testvec {
*/
#define HMAC_MD5_TEST_VECTORS 7
struct
hmac_md5_testvec
{
char
key
[
128
];
char
plaintext
[
128
];
char
digest
[
MD5_DIGEST_SIZE
];
};
struct
hmac_md5_testvec
hmac_md5_tv_template
[]
=
{
struct
hmac_testvec
hmac_md5_tv_template
[]
=
{
{
{
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x00
},
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
},
16
,
"Hi There"
,
8
,
{
0x92
,
0x94
,
0x72
,
0x7a
,
0x36
,
0x38
,
0xbb
,
0x1c
,
0x13
,
0xf4
,
0x8e
,
0xf8
,
0x15
,
0x8b
,
0xfc
,
0x9d
}
},
0x13
,
0xf4
,
0x8e
,
0xf8
,
0x15
,
0x8b
,
0xfc
,
0x9d
},
0
,
{}
},
{
{
'J'
,
'e'
,
'f'
,
'e'
,
0
},
{
'J'
,
'e'
,
'f'
,
'e'
},
4
,
"what do ya want for nothing?"
,
28
,
{
0x75
,
0x0c
,
0x78
,
0x3e
,
0x6a
,
0xb0
,
0xb5
,
0x03
,
0xea
,
0xa8
,
0x6e
,
0x31
,
0x0a
,
0x5d
,
0xb7
,
0x38
}
},
0xea
,
0xa8
,
0x6e
,
0x31
,
0x0a
,
0x5d
,
0xb7
,
0x38
},
2
,
{
14
,
14
}
},
{
{
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0x00
},
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
},
16
,
{
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0x00
},
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
},
50
,
{
0x56
,
0xbe
,
0x34
,
0x52
,
0x1d
,
0x14
,
0x4c
,
0x88
,
0xdb
,
0xb8
,
0xc7
,
0x33
,
0xf0
,
0xe8
,
0xb3
,
0xf6
}
},
0xdb
,
0xb8
,
0xc7
,
0x33
,
0xf0
,
0xe8
,
0xb3
,
0xf6
},
0
,
{}
},
{
{
0x01
,
0x02
,
0x03
,
0x04
,
0x05
,
0x06
,
0x07
,
0x08
,
0x09
,
0x0a
,
0x0b
,
0x0c
,
0x0d
,
0x0e
,
0x0f
,
0x10
,
0x11
,
0x12
,
0x13
,
0x14
,
0x15
,
0x16
,
0x17
,
0x18
,
0x19
,
0x00
},
{
0x11
,
0x12
,
0x13
,
0x14
,
0x15
,
0x16
,
0x17
,
0x18
,
0x19
,
},
25
,
{
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0x00
},
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
},
50
,
{
0x69
,
0x7e
,
0xaf
,
0x0a
,
0xca
,
0x3a
,
0x3a
,
0xea
,
0x3a
,
0x75
,
0x16
,
0x47
,
0x46
,
0xff
,
0xaa
,
0x79
}
},
0x3a
,
0x75
,
0x16
,
0x47
,
0x46
,
0xff
,
0xaa
,
0x79
},
0
,
{}
},
{
{
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x00
},
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
},
16
,
"Test With Truncation"
,
20
,
{
0x56
,
0x46
,
0x1e
,
0xf2
,
0x34
,
0x2e
,
0xdc
,
0x00
,
0xf9
,
0xba
,
0xb9
,
0x95
,
0x69
,
0x0e
,
0xfd
,
0x4c
}
},
0xf9
,
0xba
,
0xb9
,
0x95
,
0x69
,
0x0e
,
0xfd
,
0x4c
},
0
,
{}
},
{
{
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
...
...
@@ -193,15 +444,15 @@ struct hmac_md5_testvec hmac_md5_tv_template[] =
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0x00
},
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
},
80
,
"Test Using Larger Than Block-Size Key - Hash Key First"
,
54
,
{
0x6b
,
0x1a
,
0xb7
,
0xfe
,
0x4b
,
0xd7
,
0xbf
,
0x8f
,
0x0b
,
0x62
,
0xe6
,
0xce
,
0x61
,
0xb9
,
0xd0
,
0xcd
}
},
0x0b
,
0x62
,
0xe6
,
0xce
,
0x61
,
0xb9
,
0xd0
,
0xcd
},
0
,
{}
},
{
{
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
...
...
@@ -210,27 +461,16 @@ struct hmac_md5_testvec hmac_md5_tv_template[] =
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0x00
},
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
},
80
,
"Test Using Larger Than Block-Size Key and Larger Than One "
"Block-Size Data"
,
73
,
{
0x6f
,
0x63
,
0x0f
,
0xad
,
0x67
,
0xcd
,
0xa0
,
0xee
,
0x1f
,
0xb1
,
0xf5
,
0x62
,
0xdb
,
0x3a
,
0xa5
,
0x3e
}
},
/* cross page test, need to retain key */
{
{
'J'
,
'e'
,
'f'
,
'e'
,
0
},
"what do ya want for nothing?"
,
{
0x75
,
0x0c
,
0x78
,
0x3e
,
0x6a
,
0xb0
,
0xb5
,
0x03
,
0xea
,
0xa8
,
0x6e
,
0x31
,
0x0a
,
0x5d
,
0xb7
,
0x38
}
},
0x1f
,
0xb1
,
0xf5
,
0x62
,
0xdb
,
0x3a
,
0xa5
,
0x3e
},
0
,
{}
},
};
...
...
@@ -240,82 +480,71 @@ struct hmac_md5_testvec hmac_md5_tv_template[] =
#define HMAC_SHA1_TEST_VECTORS 7
struct
hmac_sha1_testvec
{
char
key
[
128
];
char
plaintext
[
128
];
char
digest
[
SHA1_DIGEST_SIZE
];
}
hmac_sha1_tv_template
[]
=
{
struct
hmac_testvec
hmac_sha1_tv_template
[]
=
{
{
{
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x00
},
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
},
20
,
"Hi There"
,
8
,
{
0xb6
,
0x17
,
0x31
,
0x86
,
0x55
,
0x05
,
0x72
,
0x64
,
0xe2
,
0x8b
,
0xc0
,
0xb6
,
0xfb
,
0x37
,
0x8c
,
0x8e
,
0xf1
,
0x46
,
0xbe
,
0x00
}
},
0x46
,
0xbe
},
0
,
{}
},
{
{
'J'
,
'e'
,
'f'
,
'e'
,
0
},
{
'J'
,
'e'
,
'f'
,
'e'
},
4
,
"what do ya want for nothing?"
,
28
,
{
0xef
,
0xfc
,
0xdf
,
0x6a
,
0xe5
,
0xeb
,
0x2f
,
0xa2
,
0xd2
,
0x74
,
0x16
,
0xd5
,
0xf1
,
0x84
,
0xdf
,
0x9c
,
0x25
,
0x9a
,
0x7c
,
0x79
}
},
0x16
,
0xd5
,
0xf1
,
0x84
,
0xdf
,
0x9c
,
0x25
,
0x9a
,
0x7c
,
0x79
}
,
2
,
{
14
,
14
}
},
{
{
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0x00
},
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
},
20
,
{
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0x00
},
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
},
50
,
{
0x12
,
0x5d
,
0x73
,
0x42
,
0xb9
,
0xac
,
0x11
,
0xcd
,
0x91
,
0xa3
,
0x9a
,
0xf4
,
0x8a
,
0xa1
,
0x7b
,
0x4f
,
0x63
,
0xf1
,
0x75
,
0xd3
}
},
0x9a
,
0xf4
,
0x8a
,
0xa1
,
0x7b
,
0x4f
,
0x63
,
0xf1
,
0x75
,
0xd3
}
,
0
,
{}
},
{
{
0x01
,
0x02
,
0x03
,
0x04
,
0x05
,
0x06
,
0x07
,
0x08
,
0x09
,
0x0a
,
0x0b
,
0x0c
,
0x0d
,
0x0e
,
0x0f
,
0x10
,
0x11
,
0x12
,
0x13
,
0x14
,
0x15
,
0x16
,
0x17
,
0x18
,
0x19
,
0x00
},
{
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0x11
,
0x12
,
0x13
,
0x14
,
0x15
,
0x16
,
0x17
,
0x18
,
0x19
},
25
,
{
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0x
00
},
0x
cd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
},
50
,
{
0x4c
,
0x90
,
0x07
,
0xf4
,
0x02
,
0x62
,
0x50
,
0xc6
,
0xbc
,
0x84
,
0x14
,
0xf9
,
0xbf
,
0x50
,
0xc8
,
0x6c
,
0x2d
,
0x72
,
0x35
,
0xda
}
},
0x14
,
0xf9
,
0xbf
,
0x50
,
0xc8
,
0x6c
,
0x2d
,
0x72
,
0x35
,
0xda
}
,
0
,
{}
},
{
{
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x00
},
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
},
20
,
"Test With Truncation"
,
20
,
{
0x4c
,
0x1a
,
0x03
,
0x42
,
0x4b
,
0x55
,
0xe0
,
0x7f
,
0xe7
,
0xf2
,
0x7b
,
0xe1
,
0xd5
,
0x8b
,
0xb9
,
0x32
,
0x4a
,
0x9a
,
0x5a
,
0x04
}
},
0x7b
,
0xe1
,
0xd5
,
0x8b
,
0xb9
,
0x32
,
0x4a
,
0x9a
,
0x5a
,
0x04
}
,
0
,
{}
},
{
{
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
...
...
@@ -324,16 +553,15 @@ struct hmac_sha1_testvec {
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0x00
},
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
},
80
,
"Test Using Larger Than Block-Size Key - Hash Key First"
,
54
,
{
0xaa
,
0x4a
,
0xe5
,
0xe1
,
0x52
,
0x72
,
0xd0
,
0x0e
,
0x95
,
0x70
,
0x56
,
0x37
,
0xce
,
0x8a
,
0x3b
,
0x55
,
0xed
,
0x40
,
0x21
,
0x12
}
},
0x56
,
0x37
,
0xce
,
0x8a
,
0x3b
,
0x55
,
0xed
,
0x40
,
0x21
,
0x12
}
,
0
,
{}
},
{
{
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
...
...
@@ -342,27 +570,16 @@ struct hmac_sha1_testvec {
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0x00
},
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
},
80
,
"Test Using Larger Than Block-Size Key and Larger Than One "
"Block-Size Data"
,
73
,
{
0xe8
,
0xe9
,
0x9d
,
0x0f
,
0x45
,
0x23
,
0x7d
,
0x78
,
0x6d
,
0x6b
,
0xba
,
0xa7
,
0x96
,
0x5c
,
0x78
,
0x08
,
0xbb
,
0xff
,
0x1a
,
0x91
}
},
/* cross page test */
{
{
'J'
,
'e'
,
'f'
,
'e'
,
0
},
"what do ya want for nothing?"
,
{
0xef
,
0xfc
,
0xdf
,
0x6a
,
0xe5
,
0xeb
,
0x2f
,
0xa2
,
0xd2
,
0x74
,
0x16
,
0xd5
,
0xf1
,
0x84
,
0xdf
,
0x9c
,
0x25
,
0x9a
,
0x7c
,
0x79
}
0xba
,
0xa7
,
0x96
,
0x5c
,
0x78
,
0x08
,
0xbb
,
0xff
,
0x1a
,
0x91
},
0
,
{}
},
};
/*
...
...
@@ -371,137 +588,139 @@ struct hmac_sha1_testvec {
*/
#define HMAC_SHA256_TEST_VECTORS 10
struct
hmac_sha256_testvec
{
char
key
[
128
];
char
plaintext
[
128
];
char
digest
[
SHA256_DIGEST_SIZE
];
}
hmac_sha256_tv_template
[]
=
{
struct
hmac_testvec
hmac_sha256_tv_template
[]
=
{
{
{
0x01
,
0x02
,
0x03
,
0x04
,
0x05
,
0x06
,
0x07
,
0x08
,
0x09
,
0x0a
,
0x0b
,
0x0c
,
0x0d
,
0x0e
,
0x0f
,
0x10
,
0x11
,
0x12
,
0x13
,
0x14
,
0x15
,
0x16
,
0x17
,
0x18
,
0x19
,
0x1a
,
0x1b
,
0x1c
,
0x1d
,
0x1e
,
0x1f
,
0x20
,
0x00
},
{
"abc"
},
0x19
,
0x1a
,
0x1b
,
0x1c
,
0x1d
,
0x1e
,
0x1f
,
0x20
},
32
,
"abc"
,
3
,
{
0xa2
,
0x1b
,
0x1f
,
0x5d
,
0x4c
,
0xf4
,
0xf7
,
0x3a
,
0x4d
,
0xd9
,
0x39
,
0x75
,
0x0f
,
0x7a
,
0x06
,
0x6a
,
0x7f
,
0x98
,
0xcc
,
0x13
,
0x1c
,
0xb1
,
0x6a
,
0x66
,
0x92
,
0x75
,
0x90
,
0x21
,
0xcf
,
0xab
,
0x81
,
0x81
},
},
0
,
{}
},
{
{
0x01
,
0x02
,
0x03
,
0x04
,
0x05
,
0x06
,
0x07
,
0x08
,
0x09
,
0x0a
,
0x0b
,
0x0c
,
0x0d
,
0x0e
,
0x0f
,
0x10
,
0x11
,
0x12
,
0x13
,
0x14
,
0x15
,
0x16
,
0x17
,
0x18
,
0x19
,
0x1a
,
0x1b
,
0x1c
,
0x1d
,
0x1e
,
0x1f
,
0x20
,
0x0
0
},
{
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
}
,
0x19
,
0x1a
,
0x1b
,
0x1c
,
0x1d
,
0x1e
,
0x1f
,
0x2
0
},
32
,
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
,
56
,
{
0x10
,
0x4f
,
0xdc
,
0x12
,
0x57
,
0x32
,
0x8f
,
0x08
,
0x18
,
0x4b
,
0xa7
,
0x31
,
0x31
,
0xc5
,
0x3c
,
0xae
,
0xe6
,
0x98
,
0xe3
,
0x61
,
0x19
,
0x42
,
0x11
,
0x49
,
0xea
,
0x8c
,
0x71
,
0x24
,
0x56
,
0x69
,
0x7d
,
0x30
}
0xea
,
0x8c
,
0x71
,
0x24
,
0x56
,
0x69
,
0x7d
,
0x30
},
0
,
{}
},
{
{
0x01
,
0x02
,
0x03
,
0x04
,
0x05
,
0x06
,
0x07
,
0x08
,
0x09
,
0x0a
,
0x0b
,
0x0c
,
0x0d
,
0x0e
,
0x0f
,
0x10
,
0x11
,
0x12
,
0x13
,
0x14
,
0x15
,
0x16
,
0x17
,
0x18
,
0x19
,
0x1a
,
0x1b
,
0x1c
,
0x1d
,
0x1e
,
0x1f
,
0x20
,
0x00
},
{
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
}
,
0x19
,
0x1a
,
0x1b
,
0x1c
,
0x1d
,
0x1e
,
0x1f
,
0x20
},
32
,
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
,
112
,
{
0x47
,
0x03
,
0x05
,
0xfc
,
0x7e
,
0x40
,
0xfe
,
0x34
,
0xd3
,
0xee
,
0xb3
,
0xe7
,
0x73
,
0xd9
,
0x5a
,
0xab
,
0x73
,
0xac
,
0xf0
,
0xfd
,
0x06
,
0x04
,
0x47
,
0xa5
,
0xeb
,
0x45
,
0x95
,
0xbf
,
0x33
,
0xa9
,
0xd1
,
0xa3
}
0xeb
,
0x45
,
0x95
,
0xbf
,
0x33
,
0xa9
,
0xd1
,
0xa3
},
0
,
{}
},
{
{
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x00
},
{
"Hi There"
}
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
},
32
,
"Hi There"
,
8
,
{
0x19
,
0x8a
,
0x60
,
0x7e
,
0xb4
,
0x4b
,
0xfb
,
0xc6
,
0x99
,
0x03
,
0xa0
,
0xf1
,
0xcf
,
0x2b
,
0xbd
,
0xc5
,
0xba
,
0x0a
,
0xa3
,
0xf3
,
0xd9
,
0xae
,
0x3c
,
0x1c
,
0x7a
,
0x3b
,
0x16
,
0x96
,
0xa0
,
0xb6
,
0x8c
,
0xf7
}
0x7a
,
0x3b
,
0x16
,
0x96
,
0xa0
,
0xb6
,
0x8c
,
0xf7
},
0
,
{}
},
{
{
"Jefe"
}
,
{
"what do ya want for nothing?"
}
,
"Jefe"
,
4
,
"what do ya want for nothing?"
,
28
,
{
0x5b
,
0xdc
,
0xc1
,
0x46
,
0xbf
,
0x60
,
0x75
,
0x4e
,
0x6a
,
0x04
,
0x24
,
0x26
,
0x08
,
0x95
,
0x75
,
0xc7
,
0x5a
,
0x00
,
0x3f
,
0x08
,
0x9d
,
0x27
,
0x39
,
0x83
,
0x9d
,
0xec
,
0x58
,
0xb9
,
0x64
,
0xec
,
0x38
,
0x43
}
0x9d
,
0xec
,
0x58
,
0xb9
,
0x64
,
0xec
,
0x38
,
0x43
},
2
,
{
14
,
14
}
},
{
{
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0x00
},
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
},
32
,
{
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0xdd
,
0x00
},
0xdd
,
0xdd
},
50
,
{
0xcd
,
0xcb
,
0x12
,
0x20
,
0xd1
,
0xec
,
0xcc
,
0xea
,
0x91
,
0xe5
,
0x3a
,
0xba
,
0x30
,
0x92
,
0xf9
,
0x62
,
0xe5
,
0x49
,
0xfe
,
0x6c
,
0xe9
,
0xed
,
0x7f
,
0xdc
,
0x43
,
0x19
,
0x1f
,
0xbd
,
0xe4
,
0x5c
,
0x30
,
0xb0
}
0x43
,
0x19
,
0x1f
,
0xbd
,
0xe4
,
0x5c
,
0x30
,
0xb0
},
0
,
{}
},
{
{
0x01
,
0x02
,
0x03
,
0x04
,
0x05
,
0x06
,
0x07
,
0x08
,
0x09
,
0x0a
,
0x0b
,
0x0c
,
0x0d
,
0x0e
,
0x0f
,
0x10
,
0x11
,
0x12
,
0x13
,
0x14
,
0x15
,
0x16
,
0x17
,
0x18
,
0x19
,
0x1a
,
0x1b
,
0x1c
,
0x1d
,
0x1e
,
0x1f
,
0x20
,
0x21
,
0x22
,
0x23
,
0x24
,
0x25
,
0x00
},
0x21
,
0x22
,
0x23
,
0x24
,
0x25
},
37
,
{
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0xcd
,
0x00
},
0xcd
,
0xcd
},
50
,
{
0xd4
,
0x63
,
0x3c
,
0x17
,
0xf6
,
0xfb
,
0x8d
,
0x74
,
0x4c
,
0x66
,
0xde
,
0xe0
,
0xf8
,
0xf0
,
0x74
,
0x55
,
0x6e
,
0xc4
,
0xaf
,
0x55
,
0xef
,
0x07
,
0x99
,
0x85
,
0x41
,
0x46
,
0x8e
,
0xb4
,
0x9b
,
0xd2
,
0xe9
,
0x17
}
0x41
,
0x46
,
0x8e
,
0xb4
,
0x9b
,
0xd2
,
0xe9
,
0x17
},
0
,
{}
},
{
{
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x00
},
{
"Test With Truncation"
}
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
,
0x0c
},
32
,
"Test With Truncation"
,
20
,
{
0x75
,
0x46
,
0xaf
,
0x01
,
0x84
,
0x1f
,
0xc0
,
0x9b
,
0x1a
,
0xb9
,
0xc3
,
0x74
,
0x9a
,
0x5f
,
0x1c
,
0x17
,
0xd4
,
0xf5
,
0x89
,
0x66
,
0x8a
,
0x58
,
0x7b
,
0x27
,
0x00
,
0xa9
,
0xc9
,
0x7c
,
0x11
,
0x93
,
0xcf
,
0x42
}
},
0x00
,
0xa9
,
0xc9
,
0x7c
,
0x11
,
0x93
,
0xcf
,
0x42
},
0
,
{}
},
{
{
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
...
...
@@ -512,16 +731,17 @@ struct hmac_sha256_testvec {
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0x00
},
{
"Test Using Larger Than Block-Size Key - Hash Key First"
}
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
},
80
,
"Test Using Larger Than Block-Size Key - Hash Key First"
,
54
,
{
0x69
,
0x53
,
0x02
,
0x5e
,
0xd9
,
0x6f
,
0x0c
,
0x09
,
0xf8
,
0x0a
,
0x96
,
0xf7
,
0x8e
,
0x65
,
0x38
,
0xdb
,
0xe2
,
0xe7
,
0xb8
,
0x20
,
0xe3
,
0xdd
,
0x97
,
0x0e
,
0x7d
,
0xdd
,
0x39
,
0x09
,
0x1b
,
0x32
,
0x35
,
0x2f
}
0x7d
,
0xdd
,
0x39
,
0x09
,
0x1b
,
0x32
,
0x35
,
0x2f
},
0
,
{}
},
{
{
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
...
...
@@ -532,553 +752,491 @@ struct hmac_sha256_testvec {
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0x00
},
{
"Test Using Larger Than Block-Size Key and Larger Than "
"One Block-Size Data"
}
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
,
0xaa
},
80
,
"Test Using Larger Than Block-Size Key and Larger Than "
"One Block-Size Data"
,
73
,
{
0x63
,
0x55
,
0xac
,
0x22
,
0xe8
,
0x90
,
0xd0
,
0xa3
,
0xc8
,
0x48
,
0x1a
,
0x5c
,
0xa4
,
0x82
,
0x5b
,
0xc8
,
0x84
,
0xd3
,
0xe7
,
0xa1
,
0xff
,
0x98
,
0xa2
,
0xfc
,
0x2a
,
0xc7
,
0xd8
,
0xe0
,
0x64
,
0xc3
,
0xb2
,
0xe6
}
0x2a
,
0xc7
,
0xd8
,
0xe0
,
0x64
,
0xc3
,
0xb2
,
0xe6
},
0
,
{}
},
};
#endif
/* CONFIG_CRYPTO_HMAC */
/*
* SHA1 test vectors from from FIPS PUB 180-1
*/
#define SHA1_TEST_VECTORS 2
struct
sha1_testvec
{
char
plaintext
[
128
];
char
digest
[
SHA1_DIGEST_SIZE
];
}
sha1_tv_template
[]
=
{
{
"abc"
,
{
0xA9
,
0x99
,
0x3E
,
0x36
,
0x47
,
0x06
,
0x81
,
0x6A
,
0xBA
,
0x3E
,
0x25
,
0x71
,
0x78
,
0x50
,
0xC2
,
0x6C
,
0x9C
,
0xD0
,
0xD8
,
0x9D
}
},
{
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
,
{
0x84
,
0x98
,
0x3E
,
0x44
,
0x1C
,
0x3B
,
0xD2
,
0x6E
,
0xBA
,
0xAE
,
0x4A
,
0xA1
,
0xF9
,
0x51
,
0x29
,
0xE5
,
0xE5
,
0x46
,
0x70
,
0xF1
}
}
};
/*
* SHA256 test vectors from from NIST
*/
#define SHA256_TEST_VECTORS 2
struct
sha256_testvec
{
char
plaintext
[
128
];
char
digest
[
SHA256_DIGEST_SIZE
];
}
sha256_tv_template
[]
=
{
{
"abc"
,
{
0xba
,
0x78
,
0x16
,
0xbf
,
0x8f
,
0x01
,
0xcf
,
0xea
,
0x41
,
0x41
,
0x40
,
0xde
,
0x5d
,
0xae
,
0x22
,
0x23
,
0xb0
,
0x03
,
0x61
,
0xa3
,
0x96
,
0x17
,
0x7a
,
0x9c
,
0xb4
,
0x10
,
0xff
,
0x61
,
0xf2
,
0x00
,
0x15
,
0xad
}
},
{
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
,
{
0x24
,
0x8d
,
0x6a
,
0x61
,
0xd2
,
0x06
,
0x38
,
0xb8
,
0xe5
,
0xc0
,
0x26
,
0x93
,
0x0c
,
0x3e
,
0x60
,
0x39
,
0xa3
,
0x3c
,
0xe4
,
0x59
,
0x64
,
0xff
,
0x21
,
0x67
,
0xf6
,
0xec
,
0xed
,
0xd4
,
0x19
,
0xdb
,
0x06
,
0xc1
}
},
};
/*
* SHA384 test vectors from from NIST and kerneli
*/
#define SHA384_TEST_VECTORS 4
struct
sha384_testvec
{
char
plaintext
[
128
];
char
digest
[
SHA384_DIGEST_SIZE
];
}
sha384_tv_template
[]
=
{
{
"abc"
,
{
0xcb
,
0x00
,
0x75
,
0x3f
,
0x45
,
0xa3
,
0x5e
,
0x8b
,
0xb5
,
0xa0
,
0x3d
,
0x69
,
0x9a
,
0xc6
,
0x50
,
0x07
,
0x27
,
0x2c
,
0x32
,
0xab
,
0x0e
,
0xde
,
0xd1
,
0x63
,
0x1a
,
0x8b
,
0x60
,
0x5a
,
0x43
,
0xff
,
0x5b
,
0xed
,
0x80
,
0x86
,
0x07
,
0x2b
,
0xa1
,
0xe7
,
0xcc
,
0x23
,
0x58
,
0xba
,
0xec
,
0xa1
,
0x34
,
0xc8
,
0x25
,
0xa7
}
},
{
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
,
{
0x33
,
0x91
,
0xfd
,
0xdd
,
0xfc
,
0x8d
,
0xc7
,
0x39
,
0x37
,
0x07
,
0xa6
,
0x5b
,
0x1b
,
0x47
,
0x09
,
0x39
,
0x7c
,
0xf8
,
0xb1
,
0xd1
,
0x62
,
0xaf
,
0x05
,
0xab
,
0xfe
,
0x8f
,
0x45
,
0x0d
,
0xe5
,
0xf3
,
0x6b
,
0xc6
,
0xb0
,
0x45
,
0x5a
,
0x85
,
0x20
,
0xbc
,
0x4e
,
0x6f
,
0x5f
,
0xe9
,
0x5b
,
0x1f
,
0xe3
,
0xc8
,
0x45
,
0x2b
}
},
{
"abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn"
"hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"
,
{
0x09
,
0x33
,
0x0c
,
0x33
,
0xf7
,
0x11
,
0x47
,
0xe8
,
0x3d
,
0x19
,
0x2f
,
0xc7
,
0x82
,
0xcd
,
0x1b
,
0x47
,
0x53
,
0x11
,
0x1b
,
0x17
,
0x3b
,
0x3b
,
0x05
,
0xd2
,
0x2f
,
0xa0
,
0x80
,
0x86
,
0xe3
,
0xb0
,
0xf7
,
0x12
,
0xfc
,
0xc7
,
0xc7
,
0x1a
,
0x55
,
0x7e
,
0x2d
,
0xb9
,
0x66
,
0xc3
,
0xe9
,
0xfa
,
0x91
,
0x74
,
0x60
,
0x39
}
},
{
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd"
"efghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"
,
{
0x3d
,
0x20
,
0x89
,
0x73
,
0xab
,
0x35
,
0x08
,
0xdb
,
0xbd
,
0x7e
,
0x2c
,
0x28
,
0x62
,
0xba
,
0x29
,
0x0a
,
0xd3
,
0x01
,
0x0e
,
0x49
,
0x78
,
0xc1
,
0x98
,
0xdc
,
0x4d
,
0x8f
,
0xd0
,
0x14
,
0xe5
,
0x82
,
0x82
,
0x3a
,
0x89
,
0xe1
,
0x6f
,
0x9b
,
0x2a
,
0x7b
,
0xbc
,
0x1a
,
0xc9
,
0x38
,
0xe2
,
0xd1
,
0x99
,
0xe8
,
0xbe
,
0xa4
}
},
};
/*
* SHA512 test vectors from from NIST and kerneli
*/
#define SHA512_TEST_VECTORS 4
struct
sha512_testvec
{
char
plaintext
[
128
];
char
digest
[
SHA512_DIGEST_SIZE
];
}
sha512_tv_template
[]
=
{
{
"abc"
,
{
0xdd
,
0xaf
,
0x35
,
0xa1
,
0x93
,
0x61
,
0x7a
,
0xba
,
0xcc
,
0x41
,
0x73
,
0x49
,
0xae
,
0x20
,
0x41
,
0x31
,
0x12
,
0xe6
,
0xfa
,
0x4e
,
0x89
,
0xa9
,
0x7e
,
0xa2
,
0x0a
,
0x9e
,
0xee
,
0xe6
,
0x4b
,
0x55
,
0xd3
,
0x9a
,
0x21
,
0x92
,
0x99
,
0x2a
,
0x27
,
0x4f
,
0xc1
,
0xa8
,
0x36
,
0xba
,
0x3c
,
0x23
,
0xa3
,
0xfe
,
0xeb
,
0xbd
,
0x45
,
0x4d
,
0x44
,
0x23
,
0x64
,
0x3c
,
0xe8
,
0x0e
,
0x2a
,
0x9a
,
0xc9
,
0x4f
,
0xa5
,
0x4c
,
0xa4
,
0x9f
}
},
{
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
,
{
0x20
,
0x4a
,
0x8f
,
0xc6
,
0xdd
,
0xa8
,
0x2f
,
0x0a
,
0x0c
,
0xed
,
0x7b
,
0xeb
,
0x8e
,
0x08
,
0xa4
,
0x16
,
0x57
,
0xc1
,
0x6e
,
0xf4
,
0x68
,
0xb2
,
0x28
,
0xa8
,
0x27
,
0x9b
,
0xe3
,
0x31
,
0xa7
,
0x03
,
0xc3
,
0x35
,
0x96
,
0xfd
,
0x15
,
0xc1
,
0x3b
,
0x1b
,
0x07
,
0xf9
,
0xaa
,
0x1d
,
0x3b
,
0xea
,
0x57
,
0x78
,
0x9c
,
0xa0
,
0x31
,
0xad
,
0x85
,
0xc7
,
0xa7
,
0x1d
,
0xd7
,
0x03
,
0x54
,
0xec
,
0x63
,
0x12
,
0x38
,
0xca
,
0x34
,
0x45
}
},
{
"abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn"
"hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"
,
{
0x8e
,
0x95
,
0x9b
,
0x75
,
0xda
,
0xe3
,
0x13
,
0xda
,
0x8c
,
0xf4
,
0xf7
,
0x28
,
0x14
,
0xfc
,
0x14
,
0x3f
,
0x8f
,
0x77
,
0x79
,
0xc6
,
0xeb
,
0x9f
,
0x7f
,
0xa1
,
0x72
,
0x99
,
0xae
,
0xad
,
0xb6
,
0x88
,
0x90
,
0x18
,
0x50
,
0x1d
,
0x28
,
0x9e
,
0x49
,
0x00
,
0xf7
,
0xe4
,
0x33
,
0x1b
,
0x99
,
0xde
,
0xc4
,
0xb5
,
0x43
,
0x3a
,
0xc7
,
0xd3
,
0x29
,
0xee
,
0xb6
,
0xdd
,
0x26
,
0x54
,
0x5e
,
0x96
,
0xe5
,
0x5b
,
0x87
,
0x4b
,
0xe9
,
0x09
}
},
{
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd"
"efghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"
,
{
0x93
,
0x0d
,
0x0c
,
0xef
,
0xcb
,
0x30
,
0xff
,
0x11
,
0x33
,
0xb6
,
0x89
,
0x81
,
0x21
,
0xf1
,
0xcf
,
0x3d
,
0x27
,
0x57
,
0x8a
,
0xfc
,
0xaf
,
0xe8
,
0x67
,
0x7c
,
0x52
,
0x57
,
0xcf
,
0x06
,
0x99
,
0x11
,
0xf7
,
0x5d
,
0x8f
,
0x58
,
0x31
,
0xb5
,
0x6e
,
0xbf
,
0xda
,
0x67
,
0xb2
,
0x78
,
0xe6
,
0x6d
,
0xff
,
0x8b
,
0x84
,
0xfe
,
0x2b
,
0x28
,
0x70
,
0xf7
,
0x42
,
0xa5
,
0x80
,
0xd8
,
0xed
,
0xb4
,
0x19
,
0x87
,
0x23
,
0x28
,
0x50
,
0xc9
}
},
};
/*
* DES test vectors.
*/
#define DES_ENC_TEST_VECTORS
5
#define DES_DEC_TEST_VECTORS
2
#define DES_CBC_ENC_TEST_VECTORS
4
#define DES_CBC_DEC_TEST_VECTORS
3
#define DES_ENC_TEST_VECTORS
10
#define DES_DEC_TEST_VECTORS
4
#define DES_CBC_ENC_TEST_VECTORS
5
#define DES_CBC_DEC_TEST_VECTORS
4
#define DES3_EDE_ENC_TEST_VECTORS 3
#define DES3_EDE_DEC_TEST_VECTORS 3
struct
des_tv
{
unsigned
int
len
;
int
fail
;
char
key
[
24
];
char
iv
[
8
];
char
plaintext
[
128
];
char
result
[
128
];
};
struct
des_tv
des_enc_tv_template
[]
=
{
struct
cipher_testvec
des_enc_tv_template
[]
=
{
/* From Applied Cryptography */
{
8
,
0
,
0
,
0
,
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xab
,
0xcd
,
0xef
},
{
0
},
8
,
{},
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xab
,
0xcd
,
0xe7
},
{
0xc9
,
0x57
,
0x44
,
0x25
,
0x6a
,
0x5e
,
0xd3
,
0x1d
}
8
,
{
0xc9
,
0x57
,
0x44
,
0x25
,
0x6a
,
0x5e
,
0xd3
,
0x1d
},
8
,
0
,
{}
},
/* Same key, different plaintext block */
{
8
,
0
,
0
,
0
,
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xab
,
0xcd
,
0xef
},
{
0
},
8
,
{},
{
0x22
,
0x33
,
0x44
,
0x55
,
0x66
,
0x77
,
0x88
,
0x99
},
{
0xf7
,
0x9c
,
0x89
,
0x2a
,
0x33
,
0x8f
,
0x4a
,
0x8b
}
},
8
,
{
0xf7
,
0x9c
,
0x89
,
0x2a
,
0x33
,
0x8f
,
0x4a
,
0x8b
},
8
,
0
,
{}
},
/* Sbox test from NBS */
{
8
,
0
,
0
,
0
,
{
0x7C
,
0xA1
,
0x10
,
0x45
,
0x4A
,
0x1A
,
0x6E
,
0x57
},
{
0
},
8
,
{},
{
0x01
,
0xA1
,
0xD6
,
0xD0
,
0x39
,
0x77
,
0x67
,
0x42
},
{
0x69
,
0x0F
,
0x5B
,
0x0D
,
0x9A
,
0x26
,
0x93
,
0x9B
}
},
8
,
{
0x69
,
0x0F
,
0x5B
,
0x0D
,
0x9A
,
0x26
,
0x93
,
0x9B
},
8
,
0
,
{}
},
/* Three blocks */
{
24
,
0
,
0
,
0
,
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xab
,
0xcd
,
0xef
},
{
0
},
8
,
{},
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xab
,
0xcd
,
0xe7
,
0x22
,
0x33
,
0x44
,
0x55
,
0x66
,
0x77
,
0x88
,
0x99
,
0xca
,
0xfe
,
0xba
,
0xbe
,
0xfe
,
0xed
,
0xbe
,
0xef
},
24
,
{
0xc9
,
0x57
,
0x44
,
0x25
,
0x6a
,
0x5e
,
0xd3
,
0x1d
,
0xf7
,
0x9c
,
0x89
,
0x2a
,
0x33
,
0x8f
,
0x4a
,
0x8b
,
0xb4
,
0x99
,
0x26
,
0xf7
,
0x1f
,
0xe1
,
0xd4
,
0x90
},
},
0xb4
,
0x99
,
0x26
,
0xf7
,
0x1f
,
0xe1
,
0xd4
,
0x90
},
24
,
0
,
{}
},
/* Weak key */
{
8
,
1
,
1
,
1
,
{
0x01
,
0x01
,
0x01
,
0x01
,
0x01
,
0x01
,
0x01
,
0x01
},
{
0
},
8
,
{},
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xab
,
0xcd
,
0xe7
},
{
0xc9
,
0x57
,
0x44
,
0x25
,
0x6a
,
0x5e
,
0xd3
,
0x1d
}
},
8
,
{
0xc9
,
0x57
,
0x44
,
0x25
,
0x6a
,
0x5e
,
0xd3
,
0x1d
},
8
,
0
,
{}
},
/* Two blocks -- for testing encryption across pages */
{
16
,
0
,
0
,
0
,
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xab
,
0xcd
,
0xef
},
{
0
},
8
,
{},
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xab
,
0xcd
,
0xe7
,
0x22
,
0x33
,
0x44
,
0x55
,
0x66
,
0x77
,
0x88
,
0x99
},
{
0xc9
,
0x57
,
0x44
,
0x25
,
0x6a
,
0x5e
,
0xd3
,
0x1d
,
0xf7
,
0x9c
,
0x89
,
0x2a
,
0x33
,
0x8f
,
0x4a
,
0x8b
}
},
/* Two blocks -- for testing decryption across pages */
{
16
,
0
,
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xab
,
0xcd
,
0xef
},
{
0
},
16
,
{
0xc9
,
0x57
,
0x44
,
0x25
,
0x6a
,
0x5e
,
0xd3
,
0x1d
,
0xf7
,
0x9c
,
0x89
,
0x2a
,
0x33
,
0x8f
,
0x4a
,
0x8b
},
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xab
,
0xcd
,
0xe7
,
0x22
,
0x33
,
0x44
,
0x55
,
0x66
,
0x77
,
0x88
,
0x99
},
16
,
2
,
{
8
,
8
}
},
/* Four blocks -- for testing encryption with chunking */
{
24
,
0
,
0
,
0
,
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xab
,
0xcd
,
0xef
},
{
0
},
8
,
{},
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xab
,
0xcd
,
0xe7
,
0x22
,
0x33
,
0x44
,
0x55
,
0x66
,
0x77
,
0x88
,
0x99
,
0xca
,
0xfe
,
0xba
,
0xbe
,
0xfe
,
0xed
,
0xbe
,
0xef
,
0x22
,
0x33
,
0x44
,
0x55
,
0x66
,
0x77
,
0x88
,
0x99
},
32
,
{
0xc9
,
0x57
,
0x44
,
0x25
,
0x6a
,
0x5e
,
0xd3
,
0x1d
,
0xf7
,
0x9c
,
0x89
,
0x2a
,
0x33
,
0x8f
,
0x4a
,
0x8b
,
0xb4
,
0x99
,
0x26
,
0xf7
,
0x1f
,
0xe1
,
0xd4
,
0x90
,
0xf7
,
0x9c
,
0x89
,
0x2a
,
0x33
,
0x8f
,
0x4a
,
0x8b
},
32
,
3
,
{
14
,
10
,
8
}
},
{
0
,
0
,
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xab
,
0xcd
,
0xef
},
8
,
{},
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xab
,
0xcd
,
0xe7
,
0x22
,
0x33
,
0x44
,
0x55
,
0x66
,
0x77
,
0x88
,
0x99
,
0xca
,
0xfe
,
0xba
,
0xbe
,
0xfe
,
0xed
,
0xbe
,
0xef
},
24
,
{
0xc9
,
0x57
,
0x44
,
0x25
,
0x6a
,
0x5e
,
0xd3
,
0x1d
,
0xf7
,
0x9c
,
0x89
,
0x2a
,
0x33
,
0x8f
,
0x4a
,
0x8b
,
0xb4
,
0x99
,
0x26
,
0xf7
,
0x1f
,
0xe1
,
0xd4
,
0x90
},
24
,
4
,
{
2
,
1
,
3
,
18
}
},
{
0
,
0
,
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xab
,
0xcd
,
0xef
},
8
,
{},
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xab
,
0xcd
,
0xe7
,
0x22
,
0x33
,
0x44
,
0x55
,
0x66
,
0x77
,
0x88
,
0x99
},
16
,
{
0xc9
,
0x57
,
0x44
,
0x25
,
0x6a
,
0x5e
,
0xd3
,
0x1d
,
0xf7
,
0x9c
,
0x89
,
0x2a
,
0x33
,
0x8f
,
0x4a
,
0x8b
},
16
,
5
,
{
2
,
2
,
2
,
2
,
8
}
},
{
0
,
0
,
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xab
,
0xcd
,
0xef
},
8
,
{},
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xab
,
0xcd
,
0xe7
},
8
,
{
0xc9
,
0x57
,
0x44
,
0x25
,
0x6a
,
0x5e
,
0xd3
,
0x1d
},
8
,
8
,
{
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
}
},
};
struct
des_tv
des_dec_tv_template
[]
=
{
struct
cipher_testvec
des_dec_tv_template
[]
=
{
/* From Applied Cryptography */
{
8
,
0
,
0
,
0
,
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xab
,
0xcd
,
0xef
},
{
0
},
8
,
{},
{
0xc9
,
0x57
,
0x44
,
0x25
,
0x6a
,
0x5e
,
0xd3
,
0x1d
},
8
,
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xab
,
0xcd
,
0xe7
},
},
8
,
0
,
{}
},
/* Sbox test from NBS */
{
8
,
0
,
{
0x7C
,
0xA1
,
0x10
,
0x45
,
0x4A
,
0x1A
,
0x6E
,
0x57
},
{
0
},
0
,
0
,
{
0x7C
,
0xA1
,
0x10
,
0x45
,
0x4A
,
0x1A
,
0x6E
,
0x57
},
8
,
{},
{
0x69
,
0x0F
,
0x5B
,
0x0D
,
0x9A
,
0x26
,
0x93
,
0x9B
},
{
0x01
,
0xA1
,
0xD6
,
0xD0
,
0x39
,
0x77
,
0x67
,
0x42
}
},
8
,
{
0x01
,
0xA1
,
0xD6
,
0xD0
,
0x39
,
0x77
,
0x67
,
0x42
},
8
,
0
,
{}
},
/* Two blocks, for chunking test */
{
16
,
0
,
0
,
0
,
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xab
,
0xcd
,
0xef
},
8
,
{},
{
0xc9
,
0x57
,
0x44
,
0x25
,
0x6a
,
0x5e
,
0xd3
,
0x1d
,
0x69
,
0x0F
,
0x5B
,
0x0D
,
0x9A
,
0x26
,
0x93
,
0x9B
},
16
,
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xab
,
0xcd
,
0xe7
,
0xa3
,
0x99
,
0x7b
,
0xca
,
0xaf
,
0x69
,
0xa0
,
0xf5
},
16
,
2
,
{
8
,
8
}
},
{
0
,
0
,
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xab
,
0xcd
,
0xef
},
{
0
}
,
8
,
{},
{
0xc9
,
0x57
,
0x44
,
0x25
,
0x6a
,
0x5e
,
0xd3
,
0x1d
,
0x69
,
0x0F
,
0x5B
,
0x0D
,
0x9A
,
0x26
,
0x93
,
0x9B
},
16
,
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xab
,
0xcd
,
0xe7
,
0xa3
,
0x99
,
0x7b
,
0xca
,
0xaf
,
0x69
,
0xa0
,
0xf5
}
0xa3
,
0x99
,
0x7b
,
0xca
,
0xaf
,
0x69
,
0xa0
,
0xf5
},
16
,
3
,
{
3
,
12
,
1
}
},
};
struct
des_tv
des_cbc_enc_tv_template
[]
=
{
struct
cipher_testvec
des_cbc_enc_tv_template
[]
=
{
/* From OpenSSL */
{
24
,
0
,
0
,
0
,
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xab
,
0xcd
,
0xef
},
{
0xfe
,
0xdc
,
0xba
,
0x98
,
0x76
,
0x54
,
0x32
,
0x10
}
,
8
,
{
0xfe
,
0xdc
,
0xba
,
0x98
,
0x76
,
0x54
,
0x32
,
0x10
},
{
0x37
,
0x36
,
0x35
,
0x34
,
0x33
,
0x32
,
0x31
,
0x20
,
0x4E
,
0x6F
,
0x77
,
0x20
,
0x69
,
0x73
,
0x20
,
0x74
,
0x68
,
0x65
,
0x20
,
0x74
,
0x69
,
0x6D
,
0x65
,
0x20
,
0x66
,
0x6F
,
0x72
,
0x20
,
0x00
,
0x31
,
0x00
,
0x00
},
0x68
,
0x65
,
0x20
,
0x74
,
0x69
,
0x6D
,
0x65
,
0x20
},
24
,
{
0xcc
,
0xd1
,
0x73
,
0xff
,
0xab
,
0x20
,
0x39
,
0xf4
,
0xac
,
0xd8
,
0xae
,
0xfd
,
0xdf
,
0xd8
,
0xa1
,
0xeb
,
0x46
,
0x8e
,
0x91
,
0x15
,
0x78
,
0x88
,
0xba
,
0x68
,
0x1d
,
0x26
,
0x93
,
0x97
,
0xf7
,
0xfe
,
0x62
,
0xb4
}
0x46
,
0x8e
,
0x91
,
0x15
,
0x78
,
0x88
,
0xba
,
0x68
},
24
,
0
,
{}
},
/* FIPS Pub 81 */
{
8
,
0
,
0
,
0
,
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xab
,
0xcd
,
0xef
},
{
0x12
,
0x34
,
0x56
,
0x78
,
0x90
,
0xab
,
0xcd
,
0xef
},
8
,
{
0x12
,
0x34
,
0x56
,
0x78
,
0x90
,
0xab
,
0xcd
,
0xef
},
{
0x4e
,
0x6f
,
0x77
,
0x20
,
0x69
,
0x73
,
0x20
,
0x74
},
8
,
{
0xe5
,
0xc7
,
0xcd
,
0xde
,
0x87
,
0x2b
,
0xf2
,
0x7c
},
},
8
,
0
,
{}
},
{
8
,
0
,
0
,
0
,
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xab
,
0xcd
,
0xef
},
8
,
{
0xe5
,
0xc7
,
0xcd
,
0xde
,
0x87
,
0x2b
,
0xf2
,
0x7c
},
{
0x68
,
0x65
,
0x20
,
0x74
,
0x69
,
0x6d
,
0x65
,
0x20
},
8
,
{
0x43
,
0xe9
,
0x34
,
0x00
,
0x8c
,
0x38
,
0x9c
,
0x0f
},
},
8
,
0
,
{}
},
{
8
,
0
,
0
,
0
,
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xab
,
0xcd
,
0xef
},
8
,
{
0x43
,
0xe9
,
0x34
,
0x00
,
0x8c
,
0x38
,
0x9c
,
0x0f
},
{
0x66
,
0x6f
,
0x72
,
0x20
,
0x61
,
0x6c
,
0x6c
,
0x20
},
8
,
{
0x68
,
0x37
,
0x88
,
0x49
,
0x9a
,
0x7c
,
0x05
,
0xf6
},
},
/* Copy of openssl vector for chunk testing */
8
,
0
,
{}
},
/* Copy of openssl vector for chunk testing */
/* From OpenSSL */
{
24
,
0
,
0
,
0
,
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xab
,
0xcd
,
0xef
},
{
0xfe
,
0xdc
,
0xba
,
0x98
,
0x76
,
0x54
,
0x32
,
0x10
}
,
8
,
{
0xfe
,
0xdc
,
0xba
,
0x98
,
0x76
,
0x54
,
0x32
,
0x10
},
{
0x37
,
0x36
,
0x35
,
0x34
,
0x33
,
0x32
,
0x31
,
0x20
,
0x4E
,
0x6F
,
0x77
,
0x20
,
0x69
,
0x73
,
0x20
,
0x74
,
0x68
,
0x65
,
0x20
,
0x74
,
0x69
,
0x6D
,
0x65
,
0x20
,
0x66
,
0x6F
,
0x72
,
0x20
,
0x00
,
0x31
,
0x00
,
0x00
},
0x68
,
0x65
,
0x20
,
0x74
,
0x69
,
0x6D
,
0x65
,
0x20
},
24
,
{
0xcc
,
0xd1
,
0x73
,
0xff
,
0xab
,
0x20
,
0x39
,
0xf4
,
0xac
,
0xd8
,
0xae
,
0xfd
,
0xdf
,
0xd8
,
0xa1
,
0xeb
,
0x46
,
0x8e
,
0x91
,
0x15
,
0x78
,
0x88
,
0xba
,
0x68
,
0x1d
,
0x26
,
0x93
,
0x97
,
0xf7
,
0xfe
,
0x62
,
0xb4
}
}
,
0x46
,
0x8e
,
0x91
,
0x15
,
0x78
,
0x88
,
0xba
,
0x68
}
,
24
,
2
,
{
13
,
11
}
},
};
struct
des_tv
des_cbc_dec_tv_template
[]
=
{
struct
cipher_testvec
des_cbc_dec_tv_template
[]
=
{
/* FIPS Pub 81 */
{
8
,
0
,
0
,
0
,
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xab
,
0xcd
,
0xef
},
8
,
{
0x12
,
0x34
,
0x56
,
0x78
,
0x90
,
0xab
,
0xcd
,
0xef
},
{
0xe5
,
0xc7
,
0xcd
,
0xde
,
0x87
,
0x2b
,
0xf2
,
0x7c
},
8
,
{
0x4e
,
0x6f
,
0x77
,
0x20
,
0x69
,
0x73
,
0x20
,
0x74
},
},
8
,
0
,
{}
},
{
8
,
0
,
0
,
0
,
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xab
,
0xcd
,
0xef
},
{
0xe5
,
0xc7
,
0xcd
,
0xde
,
0x87
,
0x2b
,
0xf2
,
0x7c
},
8
,
{
0xe5
,
0xc7
,
0xcd
,
0xde
,
0x87
,
0x2b
,
0xf2
,
0x7c
},
{
0x43
,
0xe9
,
0x34
,
0x00
,
0x8c
,
0x38
,
0x9c
,
0x0f
},
8
,
{
0x68
,
0x65
,
0x20
,
0x74
,
0x69
,
0x6d
,
0x65
,
0x20
},
},
8
,
0
,
{}
},
{
8
,
0
,
0
,
0
,
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xab
,
0xcd
,
0xef
},
8
,
{
0x43
,
0xe9
,
0x34
,
0x00
,
0x8c
,
0x38
,
0x9c
,
0x0f
},
{
0x68
,
0x37
,
0x88
,
0x49
,
0x9a
,
0x7c
,
0x05
,
0xf6
},
8
,
{
0x66
,
0x6f
,
0x72
,
0x20
,
0x61
,
0x6c
,
0x6c
,
0x20
},
},
/* Copy of above, for chunk testing */
8
,
0
,
{}
},
/* Copy of above, for chunk testing */
{
8
,
0
,
0
,
0
,
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xab
,
0xcd
,
0xef
},
8
,
{
0x43
,
0xe9
,
0x34
,
0x00
,
0x8c
,
0x38
,
0x9c
,
0x0f
},
{
0x68
,
0x37
,
0x88
,
0x49
,
0x9a
,
0x7c
,
0x05
,
0xf6
},
8
,
{
0x66
,
0x6f
,
0x72
,
0x20
,
0x61
,
0x6c
,
0x6c
,
0x20
},
8
,
2
,
{
4
,
4
}
},
};
/*
* We really need some more test vectors, especially for DES3 CBC.
*/
struct
des_tv
des3_ede_enc_tv_template
[]
=
{
struct
cipher_testvec
des3_ede_enc_tv_template
[]
=
{
/* These are from openssl */
{
8
,
0
,
0
,
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
},
24
,
{},
{
0x73
,
0x6F
,
0x6D
,
0x65
,
0x64
,
0x61
,
0x74
,
0x61
},
8
,
{
0x18
,
0xd7
,
0x48
,
0xe5
,
0x63
,
0x62
,
0x05
,
0x72
},
8
,
0
,
{}
},
{
8
,
0
,
0
,
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
}
0x64
,
0x05
,
0x6A
,
0xBD
,
0xFE
,
0xA9
,
0x34
,
0x57
},
24
,
{},
{
0x73
,
0x71
,
0x75
,
0x69
,
0x67
,
0x67
,
0x6C
,
0x65
},
8
,
{
0xc0
,
0x7d
,
0x2a
,
0x0f
,
0xa5
,
0x66
,
0xfa
,
0x30
},
8
,
0
,
{}
},
{
8
,
0
,
0
,
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
}
0x19
,
0x07
,
0x92
,
0x10
,
0x98
,
0x1A
,
0x01
,
0x01
},
24
,
{},
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
},
8
,
{
0xe1
,
0xef
,
0x62
,
0xc3
,
0x32
,
0xfe
,
0x82
,
0x5b
},
8
,
0
,
{}
},
};
struct
des_tv
des3_ede_dec_tv_template
[]
=
{
struct
cipher_testvec
des3_ede_dec_tv_template
[]
=
{
/* These are from openssl */
{
8
,
0
,
0
,
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
},
24
,
{},
{
0x18
,
0xd7
,
0x48
,
0xe5
,
0x63
,
0x62
,
0x05
,
0x72
},
{
0x73
,
0x6F
,
0x6D
,
0x65
,
0x64
,
0x61
,
0x74
,
0x61
},
},
8
,
{
0x73
,
0x6F
,
0x6D
,
0x65
,
0x64
,
0x61
,
0x74
,
0x61
},
8
,
0
,
{}
},
{
8
,
0
,
0
,
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
},
0x64
,
0x05
,
0x6A
,
0xBD
,
0xFE
,
0xA9
,
0x34
,
0x57
},
24
,
{},
{
0xc0
,
0x7d
,
0x2a
,
0x0f
,
0xa5
,
0x66
,
0xfa
,
0x30
},
8
,
{
0x73
,
0x71
,
0x75
,
0x69
,
0x67
,
0x67
,
0x6C
,
0x65
},
8
,
0
,
{}
},
{
8
,
0
,
0
,
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
},
0x19
,
0x07
,
0x92
,
0x10
,
0x98
,
0x1A
,
0x01
,
0x01
},
24
,
{},
{
0xe1
,
0xef
,
0x62
,
0xc3
,
0x32
,
0xfe
,
0x82
,
0x5b
},
8
,
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
},
8
,
0
,
{}
},
};
...
...
@@ -1090,68 +1248,81 @@ struct des_tv des3_ede_dec_tv_template[] = {
#define BF_CBC_ENC_TEST_VECTORS 1
#define BF_CBC_DEC_TEST_VECTORS 1
struct
bf_tv
{
unsigned
int
keylen
;
unsigned
int
plen
;
unsigned
int
rlen
;
int
fail
;
char
key
[
56
];
char
iv
[
8
];
char
plaintext
[
32
];
char
result
[
32
];
};
struct
bf_tv
bf_enc_tv_template
[]
=
{
struct
cipher_testvec
bf_enc_tv_template
[]
=
{
/* DES test vectors from OpenSSL */
{
8
,
8
,
8
,
0
,
0
,
0
,
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
},
{
0
},
8
,
{},
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
},
8
,
{
0x4E
,
0xF9
,
0x97
,
0x45
,
0x61
,
0x98
,
0xDD
,
0x78
},
},
8
,
0
,
{}
},
{
8
,
8
,
8
,
0
,
{
0x1F
,
0x1F
,
0x1F
,
0x1F
,
0x0E
,
0x0E
,
0x0E
,
0x0E
,
},
{
0
},
0
,
0
,
{
0x1F
,
0x1F
,
0x1F
,
0x1F
,
0x0E
,
0x0E
,
0x0E
,
0x0E
},
8
,
{},
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xAB
,
0xCD
,
0xEF
},
8
,
{
0xA7
,
0x90
,
0x79
,
0x51
,
0x08
,
0xEA
,
0x3C
,
0xAE
},
},
8
,
0
,
{}
},
{
8
,
8
,
8
,
0
,
{
0xF0
,
0xE1
,
0xD2
,
0xC3
,
0xB4
,
0xA5
,
0x96
,
0x87
,
},
{
0
},
0
,
0
,
{
0xF0
,
0xE1
,
0xD2
,
0xC3
,
0xB4
,
0xA5
,
0x96
,
0x87
},
8
,
{},
{
0xFE
,
0xDC
,
0xBA
,
0x98
,
0x76
,
0x54
,
0x32
,
0x10
},
{
0xE8
,
0x7A
,
0x24
,
0x4E
,
0x2C
,
0xC8
,
0x5E
,
0x82
}
},
/* Vary the keylength... */
8
,
{
0xE8
,
0x7A
,
0x24
,
0x4E
,
0x2C
,
0xC8
,
0x5E
,
0x82
},
8
,
0
,
{}
},
/* Vary the keylength... */
{
16
,
8
,
8
,
0
,
0
,
0
,
{
0xF0
,
0xE1
,
0xD2
,
0xC3
,
0xB4
,
0xA5
,
0x96
,
0x87
,
0x78
,
0x69
,
0x5A
,
0x4B
,
0x3C
,
0x2D
,
0x1E
,
0x0F
},
{
0
},
16
,
{},
{
0xFE
,
0xDC
,
0xBA
,
0x98
,
0x76
,
0x54
,
0x32
,
0x10
},
{
0x93
,
0x14
,
0x28
,
0x87
,
0xEE
,
0x3B
,
0xE1
,
0x5C
}
},
8
,
{
0x93
,
0x14
,
0x28
,
0x87
,
0xEE
,
0x3B
,
0xE1
,
0x5C
},
8
,
0
,
{}
},
{
21
,
8
,
8
,
0
,
0
,
0
,
{
0xF0
,
0xE1
,
0xD2
,
0xC3
,
0xB4
,
0xA5
,
0x96
,
0x87
,
0x78
,
0x69
,
0x5A
,
0x4B
,
0x3C
,
0x2D
,
0x1E
,
0x0F
,
0x00
,
0x11
,
0x22
,
0x33
,
0x44
},
{
0
},
21
,
{},
{
0xFE
,
0xDC
,
0xBA
,
0x98
,
0x76
,
0x54
,
0x32
,
0x10
},
{
0xE6
,
0xF5
,
0x1E
,
0xD7
,
0x9B
,
0x9D
,
0xB2
,
0x1F
}
},
8
,
{
0xE6
,
0xF5
,
0x1E
,
0xD7
,
0x9B
,
0x9D
,
0xB2
,
0x1F
},
8
,
0
,
{}
},
/* Generated with bf488 */
{
56
,
8
,
8
,
0
,
0
,
0
,
{
0xF0
,
0xE1
,
0xD2
,
0xC3
,
0xB4
,
0xA5
,
0x96
,
0x87
,
0x78
,
0x69
,
0x5A
,
0x4B
,
0x3C
,
0x2D
,
0x1E
,
0x0F
,
0x00
,
0x11
,
0x22
,
0x33
,
0x44
,
0x55
,
0x66
,
0x77
,
...
...
@@ -1159,64 +1330,92 @@ struct bf_tv bf_enc_tv_template[] = {
0x58
,
0x40
,
0x23
,
0x64
,
0x1A
,
0xBA
,
0x61
,
0x76
,
0x1F
,
0x1F
,
0x1F
,
0x1F
,
0x0E
,
0x0E
,
0x0E
,
0x0E
,
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0xFF
},
{
0
},
{
0xFE
,
0xDC
,
0xBA
,
0x98
,
0x76
,
0x54
,
0x32
,
0x10
},
{
0xc0
,
0x45
,
0x04
,
0x01
,
0x2e
,
0x4e
,
0x1f
,
0x53
}
}
56
,
{},
{
0xFE
,
0xDC
,
0xBA
,
0x98
,
0x76
,
0x54
,
0x32
,
0x10
},
8
,
{
0xc0
,
0x45
,
0x04
,
0x01
,
0x2e
,
0x4e
,
0x1f
,
0x53
},
8
,
0
,
{}
}
};
struct
bf_tv
bf_dec_tv_template
[]
=
{
struct
cipher_testvec
bf_dec_tv_template
[]
=
{
/* DES test vectors from OpenSSL */
{
8
,
8
,
8
,
0
,
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
},
{
0
},
0
,
0
,
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
},
8
,
{},
{
0x4E
,
0xF9
,
0x97
,
0x45
,
0x61
,
0x98
,
0xDD
,
0x78
},
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
}
},
8
,
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
},
8
,
0
,
{}
},
{
8
,
8
,
8
,
0
,
{
0x1F
,
0x1F
,
0x1F
,
0x1F
,
0x0E
,
0x0E
,
0x0E
,
0x0E
,
},
{
0
},
0
,
0
,
{
0x1F
,
0x1F
,
0x1F
,
0x1F
,
0x0E
,
0x0E
,
0x0E
,
0x0E
},
8
,
{},
{
0xA7
,
0x90
,
0x79
,
0x51
,
0x08
,
0xEA
,
0x3C
,
0xAE
},
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xAB
,
0xCD
,
0xEF
}
},
8
,
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xAB
,
0xCD
,
0xEF
},
8
,
0
,
{}
},
{
8
,
8
,
8
,
0
,
{
0xF0
,
0xE1
,
0xD2
,
0xC3
,
0xB4
,
0xA5
,
0x96
,
0x87
,
},
{
0
},
0
,
0
,
{
0xF0
,
0xE1
,
0xD2
,
0xC3
,
0xB4
,
0xA5
,
0x96
,
0x87
},
8
,
{},
{
0xE8
,
0x7A
,
0x24
,
0x4E
,
0x2C
,
0xC8
,
0x5E
,
0x82
},
{
0xFE
,
0xDC
,
0xBA
,
0x98
,
0x76
,
0x54
,
0x32
,
0x10
}
},
/* Vary the keylength... */
8
,
{
0xFE
,
0xDC
,
0xBA
,
0x98
,
0x76
,
0x54
,
0x32
,
0x10
},
8
,
0
,
{}
},
/* Vary the keylength... */
{
16
,
8
,
8
,
0
,
0
,
0
,
{
0xF0
,
0xE1
,
0xD2
,
0xC3
,
0xB4
,
0xA5
,
0x96
,
0x87
,
0x78
,
0x69
,
0x5A
,
0x4B
,
0x3C
,
0x2D
,
0x1E
,
0x0F
},
{
0
},
16
,
{},
{
0x93
,
0x14
,
0x28
,
0x87
,
0xEE
,
0x3B
,
0xE1
,
0x5C
},
{
0xFE
,
0xDC
,
0xBA
,
0x98
,
0x76
,
0x54
,
0x32
,
0x10
}
},
8
,
{
0xFE
,
0xDC
,
0xBA
,
0x98
,
0x76
,
0x54
,
0x32
,
0x10
},
8
,
0
,
{}
},
{
21
,
8
,
8
,
0
,
0
,
0
,
{
0xF0
,
0xE1
,
0xD2
,
0xC3
,
0xB4
,
0xA5
,
0x96
,
0x87
,
0x78
,
0x69
,
0x5A
,
0x4B
,
0x3C
,
0x2D
,
0x1E
,
0x0F
,
0x00
,
0x11
,
0x22
,
0x33
,
0x44
},
{
0
},
21
,
{},
{
0xE6
,
0xF5
,
0x1E
,
0xD7
,
0x9B
,
0x9D
,
0xB2
,
0x1F
},
{
0xFE
,
0xDC
,
0xBA
,
0x98
,
0x76
,
0x54
,
0x32
,
0x10
}
},
8
,
{
0xFE
,
0xDC
,
0xBA
,
0x98
,
0x76
,
0x54
,
0x32
,
0x10
},
8
,
0
,
{}
},
/* Generated with bf488, using OpenSSL, Libgcrypt and Nettle */
{
56
,
8
,
8
,
0
,
0
,
0
,
{
0xF0
,
0xE1
,
0xD2
,
0xC3
,
0xB4
,
0xA5
,
0x96
,
0x87
,
0x78
,
0x69
,
0x5A
,
0x4B
,
0x3C
,
0x2D
,
0x1E
,
0x0F
,
0x00
,
0x11
,
0x22
,
0x33
,
0x44
,
0x55
,
0x66
,
0x77
,
...
...
@@ -1224,56 +1423,64 @@ struct bf_tv bf_dec_tv_template[] = {
0x58
,
0x40
,
0x23
,
0x64
,
0x1A
,
0xBA
,
0x61
,
0x76
,
0x1F
,
0x1F
,
0x1F
,
0x1F
,
0x0E
,
0x0E
,
0x0E
,
0x0E
,
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0xFF
},
{
0
},
56
,
{},
{
0xc0
,
0x45
,
0x04
,
0x01
,
0x2e
,
0x4e
,
0x1f
,
0x53
},
{
0xFE
,
0xDC
,
0xBA
,
0x98
,
0x76
,
0x54
,
0x32
,
0x10
}
}
};
8
,
{
0xFE
,
0xDC
,
0xBA
,
0x98
,
0x76
,
0x54
,
0x32
,
0x10
},
8
,
0
,
{}
},
struct
bf_tv
bf_cbc_enc_tv_template
[]
=
{
};
struct
cipher_testvec
bf_cbc_enc_tv_template
[]
=
{
/* From OpenSSL */
{
16
,
32
,
32
,
0
,
0
,
0
,
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xAB
,
0xCD
,
0xEF
,
0xF0
,
0xE1
,
0xD2
,
0xC3
,
0xB4
,
0xA5
,
0x96
,
0x87
},
{
0xFE
,
0xDC
,
0xBA
,
0x98
,
0x76
,
0x54
,
0x32
,
0x10
},
16
,
{
0xFE
,
0xDC
,
0xBA
,
0x98
,
0x76
,
0x54
,
0x32
,
0x10
},
{
0x37
,
0x36
,
0x35
,
0x34
,
0x33
,
0x32
,
0x31
,
0x20
,
0x4E
,
0x6F
,
0x77
,
0x20
,
0x69
,
0x73
,
0x20
,
0x74
,
0x68
,
0x65
,
0x20
,
0x74
,
0x69
,
0x6D
,
0x65
,
0x20
,
0x66
,
0x6F
,
0x72
,
0x20
,
0x00
,
0x00
,
0x00
,
0x00
},
32
,
{
0x6B
,
0x77
,
0xB4
,
0xD6
,
0x30
,
0x06
,
0xDE
,
0xE6
,
0x05
,
0xB1
,
0x56
,
0xE2
,
0x74
,
0x03
,
0x97
,
0x93
,
0x58
,
0xDE
,
0xB9
,
0xE7
,
0x15
,
0x46
,
0x16
,
0xD9
,
0x59
,
0xF1
,
0x65
,
0x2B
,
0xD5
,
0xFF
,
0x92
,
0xCC
}
},
0x59
,
0xF1
,
0x65
,
0x2B
,
0xD5
,
0xFF
,
0x92
,
0xCC
},
32
,
0
,
{}
}
};
struct
bf_tv
bf_cbc_dec_tv_template
[]
=
{
struct
cipher_testvec
bf_cbc_dec_tv_template
[]
=
{
/* From OpenSSL */
{
16
,
32
,
32
,
0
,
0
,
0
,
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xAB
,
0xCD
,
0xEF
,
0xF0
,
0xE1
,
0xD2
,
0xC3
,
0xB4
,
0xA5
,
0x96
,
0x87
},
{
0xFE
,
0xDC
,
0xBA
,
0x98
,
0x76
,
0x54
,
0x32
,
0x10
},
16
,
{
0xFE
,
0xDC
,
0xBA
,
0x98
,
0x76
,
0x54
,
0x32
,
0x10
},
{
0x6B
,
0x77
,
0xB4
,
0xD6
,
0x30
,
0x06
,
0xDE
,
0xE6
,
0x05
,
0xB1
,
0x56
,
0xE2
,
0x74
,
0x03
,
0x97
,
0x93
,
0x58
,
0xDE
,
0xB9
,
0xE7
,
0x15
,
0x46
,
0x16
,
0xD9
,
0x59
,
0xF1
,
0x65
,
0x2B
,
0xD5
,
0xFF
,
0x92
,
0xCC
},
32
,
{
0x37
,
0x36
,
0x35
,
0x34
,
0x33
,
0x32
,
0x31
,
0x20
,
0x4E
,
0x6F
,
0x77
,
0x20
,
0x69
,
0x73
,
0x20
,
0x74
,
0x68
,
0x65
,
0x20
,
0x74
,
0x69
,
0x6D
,
0x65
,
0x20
,
0x66
,
0x6F
,
0x72
,
0x20
,
0x00
,
0x00
,
0x00
,
0x00
}
},
0x66
,
0x6F
,
0x72
,
0x20
,
0x00
,
0x00
,
0x00
,
0x00
},
32
,
0
,
{}
}
};
/*
...
...
@@ -1284,135 +1491,173 @@ struct bf_tv bf_cbc_dec_tv_template[] = {
#define TF_CBC_ENC_TEST_VECTORS 4
#define TF_CBC_DEC_TEST_VECTORS 4
struct
tf_tv
{
unsigned
int
keylen
;
unsigned
int
plen
;
unsigned
int
rlen
;
int
fail
;
char
key
[
32
];
char
iv
[
16
];
char
plaintext
[
48
];
char
result
[
48
];
};
struct
tf_tv
tf_enc_tv_template
[]
=
{
struct
cipher_testvec
tf_enc_tv_template
[]
=
{
{
16
,
16
,
16
,
0
,
0
,
0
,
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
},
{
0
},
16
,
{},
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
},
16
,
{
0x9F
,
0x58
,
0x9F
,
0x5C
,
0xF6
,
0x12
,
0x2C
,
0x32
,
0xB6
,
0xBF
,
0xEC
,
0x2F
,
0x2A
,
0xE8
,
0xC3
,
0x5A
}
0xB6
,
0xBF
,
0xEC
,
0x2F
,
0x2A
,
0xE8
,
0xC3
,
0x5A
},
16
,
0
,
{}
},
{
24
,
16
,
16
,
0
,
0
,
0
,
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xAB
,
0xCD
,
0xEF
,
0xFE
,
0xDC
,
0xBA
,
0x98
,
0x76
,
0x54
,
0x32
,
0x10
,
0x00
,
0x11
,
0x22
,
0x33
,
0x44
,
0x55
,
0x66
,
0x77
},
{
0
},
24
,
{},
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
},
16
,
{
0xCF
,
0xD1
,
0xD2
,
0xE5
,
0xA9
,
0xBE
,
0x9C
,
0xDF
,
0x50
,
0x1F
,
0x13
,
0xB8
,
0x92
,
0xBD
,
0x22
,
0x48
}
0x50
,
0x1F
,
0x13
,
0xB8
,
0x92
,
0xBD
,
0x22
,
0x48
},
16
,
0
,
{}
},
{
32
,
16
,
16
,
0
,
0
,
0
,
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xAB
,
0xCD
,
0xEF
,
0xFE
,
0xDC
,
0xBA
,
0x98
,
0x76
,
0x54
,
0x32
,
0x10
,
0x00
,
0x11
,
0x22
,
0x33
,
0x44
,
0x55
,
0x66
,
0x77
,
0x88
,
0x99
,
0xAA
,
0xBB
,
0xCC
,
0xDD
,
0xEE
,
0xFF
},
{
0
},
32
,
{},
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
},
16
,
{
0x37
,
0x52
,
0x7B
,
0xE0
,
0x05
,
0x23
,
0x34
,
0xB8
,
0x9F
,
0x0C
,
0xFC
,
0xCA
,
0xE8
,
0x7C
,
0xFA
,
0x20
}
0x9F
,
0x0C
,
0xFC
,
0xCA
,
0xE8
,
0x7C
,
0xFA
,
0x20
},
16
,
0
,
{}
},
};
struct
tf_tv
tf_dec_tv_template
[]
=
{
struct
cipher_testvec
tf_dec_tv_template
[]
=
{
{
16
,
16
,
16
,
0
,
0
,
0
,
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
},
{
0
},
16
,
{},
{
0x9F
,
0x58
,
0x9F
,
0x5C
,
0xF6
,
0x12
,
0x2C
,
0x32
,
0xB6
,
0xBF
,
0xEC
,
0x2F
,
0x2A
,
0xE8
,
0xC3
,
0x5A
},
16
,
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
},
16
,
0
,
{}
},
{
24
,
16
,
16
,
0
,
0
,
0
,
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xAB
,
0xCD
,
0xEF
,
0xFE
,
0xDC
,
0xBA
,
0x98
,
0x76
,
0x54
,
0x32
,
0x10
,
0x00
,
0x11
,
0x22
,
0x33
,
0x44
,
0x55
,
0x66
,
0x77
},
{
0
},
24
,
{},
{
0xCF
,
0xD1
,
0xD2
,
0xE5
,
0xA9
,
0xBE
,
0x9C
,
0xDF
,
0x50
,
0x1F
,
0x13
,
0xB8
,
0x92
,
0xBD
,
0x22
,
0x48
},
16
,
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
},
16
,
0
,
{}
},
{
32
,
16
,
16
,
0
,
0
,
0
,
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xAB
,
0xCD
,
0xEF
,
0xFE
,
0xDC
,
0xBA
,
0x98
,
0x76
,
0x54
,
0x32
,
0x10
,
0x00
,
0x11
,
0x22
,
0x33
,
0x44
,
0x55
,
0x66
,
0x77
,
0x88
,
0x99
,
0xAA
,
0xBB
,
0xCC
,
0xDD
,
0xEE
,
0xFF
},
{
0
},
32
,
{},
{
0x37
,
0x52
,
0x7B
,
0xE0
,
0x05
,
0x23
,
0x34
,
0xB8
,
0x9F
,
0x0C
,
0xFC
,
0xCA
,
0xE8
,
0x7C
,
0xFA
,
0x20
},
16
,
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
},
16
,
0
,
{}
},
};
struct
tf_tv
tf_cbc_enc_tv_template
[]
=
{
struct
cipher_testvec
tf_cbc_enc_tv_template
[]
=
{
/* Generated with Nettle */
{
16
,
16
,
16
,
0
,
0
,
0
,
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
},
16
,
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
},
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
},
16
,
{
0x9f
,
0x58
,
0x9f
,
0x5c
,
0xf6
,
0x12
,
0x2c
,
0x32
,
0xb6
,
0xbf
,
0xec
,
0x2f
,
0x2a
,
0xe8
,
0xc3
,
0x5a
},
},
16
,
0
,
{}
},
{
16
,
16
,
16
,
0
,
0
,
0
,
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
},
16
,
{
0x9f
,
0x58
,
0x9f
,
0x5c
,
0xf6
,
0x12
,
0x2c
,
0x32
,
0xb6
,
0xbf
,
0xec
,
0x2f
,
0x2a
,
0xe8
,
0xc3
,
0x5a
},
0xb6
,
0xbf
,
0xec
,
0x2f
,
0x2a
,
0xe8
,
0xc3
,
0x5a
},
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
},
16
,
{
0xd4
,
0x91
,
0xdb
,
0x16
,
0xe7
,
0xb1
,
0xc3
,
0x9e
,
0x86
,
0xcb
,
0x08
,
0x6b
,
0x78
,
0x9f
,
0x54
,
0x19
},
},
16
,
0
,
{}
},
{
16
,
16
,
16
,
0
,
0
,
0
,
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
},
16
,
{
0xd4
,
0x91
,
0xdb
,
0x16
,
0xe7
,
0xb1
,
0xc3
,
0x9e
,
0x86
,
0xcb
,
0x08
,
0x6b
,
0x78
,
0x9f
,
0x54
,
0x19
},
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
},
16
,
{
0x05
,
0xef
,
0x8c
,
0x61
,
0xa8
,
0x11
,
0x58
,
0x26
,
0x34
,
0xba
,
0x5c
,
0xb7
,
0x10
,
0x6a
,
0xa6
,
0x41
},
},
16
,
0
,
{}
},
{
16
,
48
,
48
,
0
,
0
,
0
,
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
},
16
,
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
},
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
...
...
@@ -1421,61 +1666,78 @@ struct tf_tv tf_cbc_enc_tv_template[] = {
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
},
48
,
{
0x9f
,
0x58
,
0x9f
,
0x5c
,
0xf6
,
0x12
,
0x2c
,
0x32
,
0xb6
,
0xbf
,
0xec
,
0x2f
,
0x2a
,
0xe8
,
0xc3
,
0x5a
,
0xd4
,
0x91
,
0xdb
,
0x16
,
0xe7
,
0xb1
,
0xc3
,
0x9e
,
0x86
,
0xcb
,
0x08
,
0x6b
,
0x78
,
0x9f
,
0x54
,
0x19
,
0x05
,
0xef
,
0x8c
,
0x61
,
0xa8
,
0x11
,
0x58
,
0x26
,
0x34
,
0xba
,
0x5c
,
0xb7
,
0x10
,
0x6a
,
0xa6
,
0x41
},
48
,
0
,
{}
},
};
struct
tf_tv
tf_cbc_dec_tv_template
[]
=
{
struct
cipher_testvec
tf_cbc_dec_tv_template
[]
=
{
/* Reverse of the first four above */
{
16
,
16
,
16
,
0
,
0
,
0
,
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
},
16
,
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
},
{
0x9f
,
0x58
,
0x9f
,
0x5c
,
0xf6
,
0x12
,
0x2c
,
0x32
,
0xb6
,
0xbf
,
0xec
,
0x2f
,
0x2a
,
0xe8
,
0xc3
,
0x5a
},
16
,
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
},
},
16
,
0
,
{}
},
{
16
,
16
,
16
,
0
,
0
,
0
,
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
},
16
,
{
0x9f
,
0x58
,
0x9f
,
0x5c
,
0xf6
,
0x12
,
0x2c
,
0x32
,
0xb6
,
0xbf
,
0xec
,
0x2f
,
0x2a
,
0xe8
,
0xc3
,
0x5a
},
{
0xd4
,
0x91
,
0xdb
,
0x16
,
0xe7
,
0xb1
,
0xc3
,
0x9e
,
0x86
,
0xcb
,
0x08
,
0x6b
,
0x78
,
0x9f
,
0x54
,
0x19
},
16
,
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
},
},
16
,
0
,
{}
},
{
16
,
16
,
16
,
0
,
0
,
0
,
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
},
16
,
{
0xd4
,
0x91
,
0xdb
,
0x16
,
0xe7
,
0xb1
,
0xc3
,
0x9e
,
0x86
,
0xcb
,
0x08
,
0x6b
,
0x78
,
0x9f
,
0x54
,
0x19
},
{
0x05
,
0xef
,
0x8c
,
0x61
,
0xa8
,
0x11
,
0x58
,
0x26
,
0x34
,
0xba
,
0x5c
,
0xb7
,
0x10
,
0x6a
,
0xa6
,
0x41
},
16
,
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
},
},
16
,
0
,
{}
},
{
16
,
48
,
48
,
0
,
0
,
0
,
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
},
16
,
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
},
{
0x9f
,
0x58
,
0x9f
,
0x5c
,
0xf6
,
0x12
,
0x2c
,
0x32
,
...
...
@@ -1484,12 +1746,16 @@ struct tf_tv tf_cbc_dec_tv_template[] = {
0x86
,
0xcb
,
0x08
,
0x6b
,
0x78
,
0x9f
,
0x54
,
0x19
,
0x05
,
0xef
,
0x8c
,
0x61
,
0xa8
,
0x11
,
0x58
,
0x26
,
0x34
,
0xba
,
0x5c
,
0xb7
,
0x10
,
0x6a
,
0xa6
,
0x41
},
48
,
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
},
48
,
0
,
{}
},
};
...
...
@@ -1500,92 +1766,141 @@ struct tf_tv tf_cbc_dec_tv_template[] = {
#define SERPENT_ENC_TEST_VECTORS 4
#define SERPENT_DEC_TEST_VECTORS 4
struct
serpent_tv
{
unsigned
int
keylen
,
fail
;
u8
key
[
32
],
plaintext
[
16
],
result
[
16
];
};
struct
serpent_tv
serpent_enc_tv_template
[]
=
struct
cipher_testvec
serpent_enc_tv_template
[]
=
{
{
0
,
0
,
{
0
},
0
,
0
,
{},
0
,
{},
{
0x00
,
0x01
,
0x02
,
0x03
,
0x04
,
0x05
,
0x06
,
0x07
,
0x08
,
0x09
,
0x0a
,
0x0b
,
0x0c
,
0x0d
,
0x0e
,
0x0f
},
16
,
{
0x12
,
0x07
,
0xfc
,
0xce
,
0x9b
,
0xd0
,
0xd6
,
0x47
,
0x6a
,
0xe9
,
0x8f
,
0xbe
,
0xd1
,
0x43
,
0xa0
,
0xe2
}
0x6a
,
0xe9
,
0x8f
,
0xbe
,
0xd1
,
0x43
,
0xa0
,
0xe2
},
16
,
0
,
{}
},
{
16
,
0
,
0
,
0
,
{
0x00
,
0x01
,
0x02
,
0x03
,
0x04
,
0x05
,
0x06
,
0x07
,
0x08
,
0x09
,
0x0a
,
0x0b
,
0x0c
,
0x0d
,
0x0e
,
0x0f
},
16
,
{},
{
0x00
,
0x01
,
0x02
,
0x03
,
0x04
,
0x05
,
0x06
,
0x07
,
0x08
,
0x09
,
0x0a
,
0x0b
,
0x0c
,
0x0d
,
0x0e
,
0x0f
},
16
,
{
0x4c
,
0x7d
,
0x8a
,
0x32
,
0x80
,
0x72
,
0xa2
,
0x2c
,
0x82
,
0x3e
,
0x4a
,
0x1f
,
0x3a
,
0xcd
,
0xa1
,
0x6d
}
0x82
,
0x3e
,
0x4a
,
0x1f
,
0x3a
,
0xcd
,
0xa1
,
0x6d
},
16
,
0
,
{}
},
{
32
,
0
,
0
,
0
,
{
0x00
,
0x01
,
0x02
,
0x03
,
0x04
,
0x05
,
0x06
,
0x07
,
0x08
,
0x09
,
0x0a
,
0x0b
,
0x0c
,
0x0d
,
0x0e
,
0x0f
,
0x10
,
0x11
,
0x12
,
0x13
,
0x14
,
0x15
,
0x16
,
0x17
,
0x18
,
0x19
,
0x1a
,
0x1b
,
0x1c
,
0x1d
,
0x1e
,
0x1f
},
32
,
{},
{
0x00
,
0x01
,
0x02
,
0x03
,
0x04
,
0x05
,
0x06
,
0x07
,
0x08
,
0x09
,
0x0a
,
0x0b
,
0x0c
,
0x0d
,
0x0e
,
0x0f
},
16
,
{
0xde
,
0x26
,
0x9f
,
0xf8
,
0x33
,
0xe4
,
0x32
,
0xb8
,
0x5b
,
0x2e
,
0x88
,
0xd2
,
0x70
,
0x1c
,
0xe7
,
0x5c
}
0x5b
,
0x2e
,
0x88
,
0xd2
,
0x70
,
0x1c
,
0xe7
,
0x5c
},
16
,
0
,
{}
},
{
16
,
0
,
0
,
0
,
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x80
},
16
,
{},
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
},
16
,
{
0xdd
,
0xd2
,
0x6b
,
0x98
,
0xa5
,
0xff
,
0xd8
,
0x2c
,
0x05
,
0x34
,
0x5a
,
0x9d
,
0xad
,
0xbf
,
0xaf
,
0x49
}
0x05
,
0x34
,
0x5a
,
0x9d
,
0xad
,
0xbf
,
0xaf
,
0x49
},
16
,
0
,
{}
}
};
struct
serpent_tv
serpent_dec_tv_template
[]
=
struct
cipher_testvec
serpent_dec_tv_template
[]
=
{
{
0
,
0
,
{
0
},
0
,
0
,
{},
0
,
{},
{
0x12
,
0x07
,
0xfc
,
0xce
,
0x9b
,
0xd0
,
0xd6
,
0x47
,
0x6a
,
0xe9
,
0x8f
,
0xbe
,
0xd1
,
0x43
,
0xa0
,
0xe2
},
16
,
{
0x00
,
0x01
,
0x02
,
0x03
,
0x04
,
0x05
,
0x06
,
0x07
,
0x08
,
0x09
,
0x0a
,
0x0b
,
0x0c
,
0x0d
,
0x0e
,
0x0f
},
16
,
0
,
{}
},
{
16
,
0
,
0
,
0
,
{
0x00
,
0x01
,
0x02
,
0x03
,
0x04
,
0x05
,
0x06
,
0x07
,
0x08
,
0x09
,
0x0a
,
0x0b
,
0x0c
,
0x0d
,
0x0e
,
0x0f
},
16
,
{},
{
0x4c
,
0x7d
,
0x8a
,
0x32
,
0x80
,
0x72
,
0xa2
,
0x2c
,
0x82
,
0x3e
,
0x4a
,
0x1f
,
0x3a
,
0xcd
,
0xa1
,
0x6d
},
16
,
{
0x00
,
0x01
,
0x02
,
0x03
,
0x04
,
0x05
,
0x06
,
0x07
,
0x08
,
0x09
,
0x0a
,
0x0b
,
0x0c
,
0x0d
,
0x0e
,
0x0f
},
16
,
0
,
{}
},
{
32
,
0
,
0
,
0
,
{
0x00
,
0x01
,
0x02
,
0x03
,
0x04
,
0x05
,
0x06
,
0x07
,
0x08
,
0x09
,
0x0a
,
0x0b
,
0x0c
,
0x0d
,
0x0e
,
0x0f
,
0x10
,
0x11
,
0x12
,
0x13
,
0x14
,
0x15
,
0x16
,
0x17
,
0x18
,
0x19
,
0x1a
,
0x1b
,
0x1c
,
0x1d
,
0x1e
,
0x1f
},
32
,
{},
{
0xde
,
0x26
,
0x9f
,
0xf8
,
0x33
,
0xe4
,
0x32
,
0xb8
,
0x5b
,
0x2e
,
0x88
,
0xd2
,
0x70
,
0x1c
,
0xe7
,
0x5c
},
16
,
{
0x00
,
0x01
,
0x02
,
0x03
,
0x04
,
0x05
,
0x06
,
0x07
,
0x08
,
0x09
,
0x0a
,
0x0b
,
0x0c
,
0x0d
,
0x0e
,
0x0f
},
16
,
0
,
{}
},
{
16
,
0
,
0
,
0
,
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x80
},
16
,
{},
{
0xdd
,
0xd2
,
0x6b
,
0x98
,
0xa5
,
0xff
,
0xd8
,
0x2c
,
0x05
,
0x34
,
0x5a
,
0x9d
,
0xad
,
0xbf
,
0xaf
,
0x49
},
16
,
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
},
16
,
0
,
{}
}
};
...
...
@@ -1593,85 +1908,113 @@ struct serpent_tv serpent_dec_tv_template[] =
#define CAST6_ENC_TEST_VECTORS 3
#define CAST6_DEC_TEST_VECTORS 3
struct
cast6_tv
{
unsigned
keylen
;
unsigned
fail
;
u8
key
[
32
];
u8
plaintext
[
16
];
u8
result
[
16
];
};
struct
cast6_tv
cast6_enc_tv_template
[]
=
struct
cipher_testvec
cast6_enc_tv_template
[]
=
{
{
16
,
0
,
0
,
{
0x23
,
0x42
,
0xbb
,
0x9e
,
0xfa
,
0x38
,
0x54
,
0x2c
,
0x0a
,
0xf7
,
0x56
,
0x47
,
0xf2
,
0x9f
,
0x61
,
0x5d
},
16
,
{},
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
},
16
,
{
0xc8
,
0x42
,
0xa0
,
0x89
,
0x72
,
0xb4
,
0x3d
,
0x20
,
0x83
,
0x6c
,
0x91
,
0xd1
,
0xb7
,
0x53
,
0x0f
,
0x6b
},
16
,
0
,
{}
},
{
24
,
0
,
0
,
{
0x23
,
0x42
,
0xbb
,
0x9e
,
0xfa
,
0x38
,
0x54
,
0x2c
,
0xbe
,
0xd0
,
0xac
,
0x83
,
0x94
,
0x0a
,
0xc2
,
0x98
,
0xba
,
0xc7
,
0x7a
,
0x77
,
0x17
,
0x94
,
0x28
,
0x63
},
24
,
{},
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
},
16
,
{
0x1b
,
0x38
,
0x6c
,
0x02
,
0x10
,
0xdc
,
0xad
,
0xcb
,
0xdd
,
0x0e
,
0x41
,
0xaa
,
0x08
,
0xa7
,
0xa7
,
0xe8
},
16
,
0
,
{}
},
{
32
,
0
,
0
,
{
0x23
,
0x42
,
0xbb
,
0x9e
,
0xfa
,
0x38
,
0x54
,
0x2c
,
0xbe
,
0xd0
,
0xac
,
0x83
,
0x94
,
0x0a
,
0xc2
,
0x98
,
0x8d
,
0x7c
,
0x47
,
0xce
,
0x26
,
0x49
,
0x08
,
0x46
,
0x1c
,
0xc1
,
0xb5
,
0x13
,
0x7a
,
0xe6
,
0xb6
,
0x04
},
32
,
{},
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
},
16
,
{
0x4f
,
0x6a
,
0x20
,
0x38
,
0x28
,
0x68
,
0x97
,
0xb9
,
0xc9
,
0x87
,
0x01
,
0x36
,
0x55
,
0x33
,
0x17
,
0xfa
},
16
,
0
,
{}
}
};
struct
c
ast6_tv
cast6_dec_tv_template
[]
=
struct
c
ipher_testvec
cast6_dec_tv_template
[]
=
{
{
16
,
0
,
0
,
{
0x23
,
0x42
,
0xbb
,
0x9e
,
0xfa
,
0x38
,
0x54
,
0x2c
,
0x0a
,
0xf7
,
0x56
,
0x47
,
0xf2
,
0x9f
,
0x61
,
0x5d
},
16
,
{},
{
0xc8
,
0x42
,
0xa0
,
0x89
,
0x72
,
0xb4
,
0x3d
,
0x20
,
0x83
,
0x6c
,
0x91
,
0xd1
,
0xb7
,
0x53
,
0x0f
,
0x6b
},
16
,
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
},
16
,
0
,
{}
},
{
24
,
0
,
0
,
{
0x23
,
0x42
,
0xbb
,
0x9e
,
0xfa
,
0x38
,
0x54
,
0x2c
,
0xbe
,
0xd0
,
0xac
,
0x83
,
0x94
,
0x0a
,
0xc2
,
0x98
,
0xba
,
0xc7
,
0x7a
,
0x77
,
0x17
,
0x94
,
0x28
,
0x63
},
24
,
{},
{
0x1b
,
0x38
,
0x6c
,
0x02
,
0x10
,
0xdc
,
0xad
,
0xcb
,
0xdd
,
0x0e
,
0x41
,
0xaa
,
0x08
,
0xa7
,
0xa7
,
0xe8
},
16
,
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
},
16
,
0
,
{}
},
{
32
,
0
,
0
,
{
0x23
,
0x42
,
0xbb
,
0x9e
,
0xfa
,
0x38
,
0x54
,
0x2c
,
0xbe
,
0xd0
,
0xac
,
0x83
,
0x94
,
0x0a
,
0xc2
,
0x98
,
0x8d
,
0x7c
,
0x47
,
0xce
,
0x26
,
0x49
,
0x08
,
0x46
,
0x1c
,
0xc1
,
0xb5
,
0x13
,
0x7a
,
0xe6
,
0xb6
,
0x04
},
32
,
{},
{
0x4f
,
0x6a
,
0x20
,
0x38
,
0x28
,
0x68
,
0x97
,
0xb9
,
0xc9
,
0x87
,
0x01
,
0x36
,
0x55
,
0x33
,
0x17
,
0xfa
},
16
,
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
},
16
,
0
,
{}
}
};
...
...
@@ -1682,90 +2025,113 @@ struct cast6_tv cast6_dec_tv_template[] =
#define AES_ENC_TEST_VECTORS 3
#define AES_DEC_TEST_VECTORS 3
struct
aes_tv
{
unsigned
int
keylen
;
unsigned
int
plen
;
unsigned
int
rlen
;
int
fail
;
char
key
[
32
];
char
iv
[
8
];
char
plaintext
[
16
];
char
result
[
16
];
};
struct
aes_tv
aes_enc_tv_template
[]
=
{
struct
cipher_testvec
aes_enc_tv_template
[]
=
{
/* From FIPS-197 */
{
16
,
16
,
16
,
0
,
0
,
0
,
{
0x00
,
0x01
,
0x02
,
0x03
,
0x04
,
0x05
,
0x06
,
0x07
,
0x08
,
0x09
,
0x0a
,
0x0b
,
0x0c
,
0x0d
,
0x0e
,
0x0f
},
{
0
},
16
,
{},
{
0x00
,
0x11
,
0x22
,
0x33
,
0x44
,
0x55
,
0x66
,
0x77
,
0x88
,
0x99
,
0xaa
,
0xbb
,
0xcc
,
0xdd
,
0xee
,
0xff
},
16
,
{
0x69
,
0xc4
,
0xe0
,
0xd8
,
0x6a
,
0x7b
,
0x04
,
0x30
,
0xd8
,
0xcd
,
0xb7
,
0x80
,
0x70
,
0xb4
,
0xc5
,
0x5a
},
16
,
0
,
{}
},
{
24
,
16
,
16
,
0
,
0
,
0
,
{
0x00
,
0x01
,
0x02
,
0x03
,
0x04
,
0x05
,
0x06
,
0x07
,
0x08
,
0x09
,
0x0a
,
0x0b
,
0x0c
,
0x0d
,
0x0e
,
0x0f
,
0x10
,
0x11
,
0x12
,
0x13
,
0x14
,
0x15
,
0x16
,
0x17
},
{
0
},
24
,
{},
{
0x00
,
0x11
,
0x22
,
0x33
,
0x44
,
0x55
,
0x66
,
0x77
,
0x88
,
0x99
,
0xaa
,
0xbb
,
0xcc
,
0xdd
,
0xee
,
0xff
},
16
,
{
0xdd
,
0xa9
,
0x7c
,
0xa4
,
0x86
,
0x4c
,
0xdf
,
0xe0
,
0x6e
,
0xaf
,
0x70
,
0xa0
,
0xec
,
0x0d
,
0x71
,
0x91
},
16
,
0
,
{}
},
{
32
,
16
,
16
,
0
,
0
,
0
,
{
0x00
,
0x01
,
0x02
,
0x03
,
0x04
,
0x05
,
0x06
,
0x07
,
0x08
,
0x09
,
0x0a
,
0x0b
,
0x0c
,
0x0d
,
0x0e
,
0x0f
,
0x10
,
0x11
,
0x12
,
0x13
,
0x14
,
0x15
,
0x16
,
0x17
,
0x18
,
0x19
,
0x1a
,
0x1b
,
0x1c
,
0x1d
,
0x1e
,
0x1f
},
{
0
},
32
,
{},
{
0x00
,
0x11
,
0x22
,
0x33
,
0x44
,
0x55
,
0x66
,
0x77
,
0x88
,
0x99
,
0xaa
,
0xbb
,
0xcc
,
0xdd
,
0xee
,
0xff
},
16
,
{
0x8e
,
0xa2
,
0xb7
,
0xca
,
0x51
,
0x67
,
0x45
,
0xbf
,
0xea
,
0xfc
,
0x49
,
0x90
,
0x4b
,
0x49
,
0x60
,
0x89
},
16
,
0
,
{}
},
};
struct
aes_tv
aes_dec_tv_template
[]
=
{
struct
cipher_testvec
aes_dec_tv_template
[]
=
{
/* From FIPS-197 */
{
16
,
16
,
16
,
0
,
0
,
0
,
{
0x00
,
0x01
,
0x02
,
0x03
,
0x04
,
0x05
,
0x06
,
0x07
,
0x08
,
0x09
,
0x0a
,
0x0b
,
0x0c
,
0x0d
,
0x0e
,
0x0f
},
{
0
},
16
,
{},
{
0x69
,
0xc4
,
0xe0
,
0xd8
,
0x6a
,
0x7b
,
0x04
,
0x30
,
0xd8
,
0xcd
,
0xb7
,
0x80
,
0x70
,
0xb4
,
0xc5
,
0x5a
},
16
,
{
0x00
,
0x11
,
0x22
,
0x33
,
0x44
,
0x55
,
0x66
,
0x77
,
0x88
,
0x99
,
0xaa
,
0xbb
,
0xcc
,
0xdd
,
0xee
,
0xff
},
},
16
,
0
,
{}
},
{
24
,
16
,
16
,
0
,
0
,
0
,
{
0x00
,
0x01
,
0x02
,
0x03
,
0x04
,
0x05
,
0x06
,
0x07
,
0x08
,
0x09
,
0x0a
,
0x0b
,
0x0c
,
0x0d
,
0x0e
,
0x0f
,
0x10
,
0x11
,
0x12
,
0x13
,
0x14
,
0x15
,
0x16
,
0x17
},
{
0
},
24
,
{},
{
0xdd
,
0xa9
,
0x7c
,
0xa4
,
0x86
,
0x4c
,
0xdf
,
0xe0
,
0x6e
,
0xaf
,
0x70
,
0xa0
,
0xec
,
0x0d
,
0x71
,
0x91
},
16
,
{
0x00
,
0x11
,
0x22
,
0x33
,
0x44
,
0x55
,
0x66
,
0x77
,
0x88
,
0x99
,
0xaa
,
0xbb
,
0xcc
,
0xdd
,
0xee
,
0xff
},
16
,
0
,
{}
},
{
32
,
16
,
16
,
0
,
0
,
0
,
{
0x00
,
0x01
,
0x02
,
0x03
,
0x04
,
0x05
,
0x06
,
0x07
,
0x08
,
0x09
,
0x0a
,
0x0b
,
0x0c
,
0x0d
,
0x0e
,
0x0f
,
0x10
,
0x11
,
0x12
,
0x13
,
0x14
,
0x15
,
0x16
,
0x17
,
0x18
,
0x19
,
0x1a
,
0x1b
,
0x1c
,
0x1d
,
0x1e
,
0x1f
},
{
0
},
32
,
{},
{
0x8e
,
0xa2
,
0xb7
,
0xca
,
0x51
,
0x67
,
0x45
,
0xbf
,
0xea
,
0xfc
,
0x49
,
0x90
,
0x4b
,
0x49
,
0x60
,
0x89
},
16
,
{
0x00
,
0x11
,
0x22
,
0x33
,
0x44
,
0x55
,
0x66
,
0x77
,
0x88
,
0x99
,
0xaa
,
0xbb
,
0xcc
,
0xdd
,
0xee
,
0xff
},
16
,
0
,
{}
},
};
...
...
@@ -1773,67 +2139,93 @@ struct aes_tv aes_dec_tv_template[] = {
#define CAST5_ENC_TEST_VECTORS 3
#define CAST5_DEC_TEST_VECTORS 3
struct
cast5_tv
{
unsigned
keylen
;
unsigned
fail
;
u8
key
[
16
];
u8
plaintext
[
8
];
u8
ciphertext
[
8
];
};
struct
cast5_tv
cast5_enc_tv_template
[]
=
struct
cipher_testvec
cast5_enc_tv_template
[]
=
{
{
16
,
0
,
0
,
{
0x01
,
0x23
,
0x45
,
0x67
,
0x12
,
0x34
,
0x56
,
0x78
,
0x23
,
0x45
,
0x67
,
0x89
,
0x34
,
0x56
,
0x78
,
0x9A
},
16
,
{},
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xab
,
0xcd
,
0xef
},
8
,
{
0x23
,
0x8b
,
0x4f
,
0xe5
,
0x84
,
0x7e
,
0x44
,
0xb2
},
8
,
0
,
{}
},
{
1
0
,
0
,
0
,
{
0x01
,
0x23
,
0x45
,
0x67
,
0x12
,
0x34
,
0x56
,
0x78
,
0x23
,
0x45
},
10
,
{},
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xab
,
0xcd
,
0xef
},
8
,
{
0xeb
,
0x6a
,
0x71
,
0x1a
,
0x2c
,
0x02
,
0x27
,
0x1b
},
8
,
0
,
{}
},
{
5
,
0
,
0
,
{
0x01
,
0x23
,
0x45
,
0x67
,
0x12
},
5
,
{},
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xab
,
0xcd
,
0xef
},
8
,
{
0x7a
,
0xc8
,
0x16
,
0xd1
,
0x6e
,
0x9b
,
0x30
,
0x2e
},
8
,
0
,
{}
}
};
struct
c
ast5_tv
cast5_dec_tv_template
[]
=
struct
c
ipher_testvec
cast5_dec_tv_template
[]
=
{
{
16
,
0
,
0
,
{
0x01
,
0x23
,
0x45
,
0x67
,
0x12
,
0x34
,
0x56
,
0x78
,
0x23
,
0x45
,
0x67
,
0x89
,
0x34
,
0x56
,
0x78
,
0x9A
},
16
,
{},
{
0x23
,
0x8b
,
0x4f
,
0xe5
,
0x84
,
0x7e
,
0x44
,
0xb2
},
8
,
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xab
,
0xcd
,
0xef
},
8
,
0
,
{}
},
{
1
0
,
0
,
0
,
{
0x01
,
0x23
,
0x45
,
0x67
,
0x12
,
0x34
,
0x56
,
0x78
,
0x23
,
0x45
},
10
,
{},
{
0xeb
,
0x6a
,
0x71
,
0x1a
,
0x2c
,
0x02
,
0x27
,
0x1b
},
8
,
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xab
,
0xcd
,
0xef
},
8
,
0
,
{}
},
{
5
,
0
,
0
,
{
0x01
,
0x23
,
0x45
,
0x67
,
0x12
},
5
,
{},
{
0x7a
,
0xc8
,
0x16
,
0xd1
,
0x6e
,
0x9b
,
0x30
,
0x2e
},
8
,
{
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xab
,
0xcd
,
0xef
},
8
,
0
,
{}
}
};
...
...
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