Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Wim Lewis
nettle
Commits
75288e44
Commit
75288e44
authored
Sep 16, 2012
by
Niels Möller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Testsuite overhaul, including proper deallocation of storage.
parent
728a20ee
Changes
52
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
52 changed files
with
2477 additions
and
2545 deletions
+2477
-2545
ChangeLog
ChangeLog
+44
-0
testsuite/aes-test.c
testsuite/aes-test.c
+82
-81
testsuite/arcfour-test.c
testsuite/arcfour-test.c
+69
-71
testsuite/arctwo-test.c
testsuite/arctwo-test.c
+49
-49
testsuite/base16-test.c
testsuite/base16-test.c
+1
-3
testsuite/base64-test.c
testsuite/base64-test.c
+1
-3
testsuite/bignum-test.c
testsuite/bignum-test.c
+20
-24
testsuite/blowfish-test.c
testsuite/blowfish-test.c
+4
-6
testsuite/buffer-test.c
testsuite/buffer-test.c
+1
-3
testsuite/camellia-test.c
testsuite/camellia-test.c
+41
-37
testsuite/cast128-test.c
testsuite/cast128-test.c
+11
-13
testsuite/cbc-test.c
testsuite/cbc-test.c
+48
-58
testsuite/ctr-test.c
testsuite/ctr-test.c
+32
-34
testsuite/cxx-test.cxx
testsuite/cxx-test.cxx
+8
-16
testsuite/des-compat-test.c
testsuite/des-compat-test.c
+2
-3
testsuite/des-test.c
testsuite/des-test.c
+64
-59
testsuite/des3-test.c
testsuite/des3-test.c
+6
-8
testsuite/dsa-keygen-test.c
testsuite/dsa-keygen-test.c
+11
-13
testsuite/dsa-test.c
testsuite/dsa-test.c
+1
-2
testsuite/gcm-test.c
testsuite/gcm-test.c
+211
-213
testsuite/hmac-test.c
testsuite/hmac-test.c
+745
-753
testsuite/knuth-lfib-test.c
testsuite/knuth-lfib-test.c
+2
-5
testsuite/md2-test.c
testsuite/md2-test.c
+15
-17
testsuite/md4-test.c
testsuite/md4-test.c
+23
-25
testsuite/md5-compat-test.c
testsuite/md5-compat-test.c
+15
-23
testsuite/md5-test.c
testsuite/md5-test.c
+26
-28
testsuite/memxor-test.c
testsuite/memxor-test.c
+1
-3
testsuite/meta-armor-test.c
testsuite/meta-armor-test.c
+1
-2
testsuite/meta-cipher-test.c
testsuite/meta-cipher-test.c
+1
-2
testsuite/meta-hash-test.c
testsuite/meta-hash-test.c
+1
-2
testsuite/pkcs1-test.c
testsuite/pkcs1-test.c
+1
-3
testsuite/random-prime-test.c
testsuite/random-prime-test.c
+2
-2
testsuite/ripemd160-test.c
testsuite/ripemd160-test.c
+21
-23
testsuite/rsa-encrypt-test.c
testsuite/rsa-encrypt-test.c
+1
-2
testsuite/rsa-keygen-test.c
testsuite/rsa-keygen-test.c
+11
-13
testsuite/rsa-test.c
testsuite/rsa-test.c
+4
-10
testsuite/rsa2sexp-test.c
testsuite/rsa2sexp-test.c
+35
-36
testsuite/salsa20-test.c
testsuite/salsa20-test.c
+125
-118
testsuite/serpent-test.c
testsuite/serpent-test.c
+178
-180
testsuite/sexp-format-test.c
testsuite/sexp-format-test.c
+11
-5
testsuite/sexp-test.c
testsuite/sexp-test.c
+9
-8
testsuite/sexp2rsa-test.c
testsuite/sexp2rsa-test.c
+28
-29
testsuite/sha1-huge-test.c
testsuite/sha1-huge-test.c
+3
-5
testsuite/sha1-test.c
testsuite/sha1-test.c
+21
-23
testsuite/sha224-test.c
testsuite/sha224-test.c
+30
-32
testsuite/sha256-test.c
testsuite/sha256-test.c
+37
-39
testsuite/sha384-test.c
testsuite/sha384-test.c
+41
-43
testsuite/sha512-test.c
testsuite/sha512-test.c
+50
-52
testsuite/testutils.c
testsuite/testutils.c
+247
-258
testsuite/testutils.h
testsuite/testutils.h
+55
-66
testsuite/twofish-test.c
testsuite/twofish-test.c
+12
-14
testsuite/yarrow-test.c
testsuite/yarrow-test.c
+19
-28
No files found.
ChangeLog
View file @
75288e44
2012-09-16 Niels Möller <nisse@lysator.liu.se>
2012-09-16 Niels Möller <nisse@lysator.liu.se>
* testsuite/: Overhaul of testsuite, affecting almost all files.
+ Use struct tstring for allocated strings, and deallocate before
exit.
+ Changed most test functions to take struct tstring as arguments.
+ Made all test_main return on success.
* testsuite/testutils.h (struct tstring): New struct type.
(H2, HL, MEMEQH, SUCCESS): Deleted macros.
(SHEX, SDATA): New macros.
(H): Redefined to track storage.
* testsuite/testutils.c (tstring_alloc): New function.
(tstring_clear): New function.
(tstring_data): New function.
(tstring_hex): New function.
(tstring_print_hex): New function.
(decode_hex_length): Made static.
(decode_hex): Made static. No return value, abort on error.
(main): Expect test_main to return, and call tstring_clear before
exit.
(test_dsa_key): Added missing mpz_clear.
(test_mac): Deleted unused function.
* testsuite/rsa2sexp-test.c (test_main): Added missing
nettle_buffer_clear.
* testsuite/yarrow-test.c (open_file): Don't leak filename.
(test_main): fclose input file properly.
* testsuite/sexp-format-test.c (test_main): Added missing calls to
nettle_buffer_clear and mpz_clear.
* testsuite/serpent-test.c (tstring_hex_reverse): New function,
replacing...
(decode_hex_reverse): ... deleted function.
(RHEX): New macro, replacing...
(RH, RHL): ... deleted macros.
* testsuite/rsa2sexp-test.c (test_main): Added missing
nettle_buffer_clear.
* testsuite/random-prime-test.c (test_main): Added missing
mpz_clear.
* realloc.c (nettle_realloc): Only call libc realloc if length >
* realloc.c (nettle_realloc): Only call libc realloc if length >
0, otherwise call free. Fixes a small memory leak.
0, otherwise call free. Fixes a small memory leak.
(nettle_xrealloc): Likewise.
(nettle_xrealloc): Likewise.
...
...
testsuite/aes-test.c
View file @
75288e44
...
@@ -2,25 +2,28 @@
...
@@ -2,25 +2,28 @@
#include "aes.h"
#include "aes.h"
static
void
static
void
test_invert
(
unsigned
key_length
,
const
uint8_t
*
key
,
test_invert
(
const
struct
tstring
*
key
,
unsigned
length
,
const
uint8_t
*
cleartext
,
const
struct
tstring
*
cleartext
,
const
uint8_t
*
ciphertext
)
const
struct
tstring
*
ciphertext
)
{
{
struct
aes_ctx
encrypt
;
struct
aes_ctx
encrypt
;
struct
aes_ctx
decrypt
;
struct
aes_ctx
decrypt
;
uint8_t
*
data
=
xalloc
(
length
);
uint8_t
*
data
=
xalloc
(
cleartext
->
length
);
unsigned
length
;
ASSERT
(
cleartext
->
length
==
ciphertext
->
length
);
length
=
cleartext
->
length
;
aes_set_encrypt_key
(
&
encrypt
,
key
_
length
,
key
);
aes_set_encrypt_key
(
&
encrypt
,
key
->
length
,
key
->
data
);
aes_encrypt
(
&
encrypt
,
length
,
data
,
cleartext
);
aes_encrypt
(
&
encrypt
,
length
,
data
,
cleartext
->
data
);
if
(
!
MEMEQ
(
length
,
data
,
ciphertext
))
if
(
!
MEMEQ
(
length
,
data
,
ciphertext
->
data
))
{
{
fprintf
(
stderr
,
"test_invert: Encrypt failed:
\n
Input:"
);
fprintf
(
stderr
,
"test_invert: Encrypt failed:
\n
Input:"
);
print_hex
(
length
,
cleartext
);
tstring_
print_hex
(
cleartext
);
fprintf
(
stderr
,
"
\n
Output: "
);
fprintf
(
stderr
,
"
\n
Output: "
);
print_hex
(
length
,
data
);
print_hex
(
length
,
data
);
fprintf
(
stderr
,
"
\n
Expected:"
);
fprintf
(
stderr
,
"
\n
Expected:"
);
print_hex
(
length
,
ciphertext
);
tstring_
print_hex
(
ciphertext
);
fprintf
(
stderr
,
"
\n
"
);
fprintf
(
stderr
,
"
\n
"
);
FAIL
();
FAIL
();
}
}
...
@@ -28,71 +31,71 @@ test_invert(unsigned key_length, const uint8_t *key,
...
@@ -28,71 +31,71 @@ test_invert(unsigned key_length, const uint8_t *key,
aes_invert_key
(
&
decrypt
,
&
encrypt
);
aes_invert_key
(
&
decrypt
,
&
encrypt
);
aes_decrypt
(
&
decrypt
,
length
,
data
,
data
);
aes_decrypt
(
&
decrypt
,
length
,
data
,
data
);
if
(
!
MEMEQ
(
length
,
data
,
cleartext
))
if
(
!
MEMEQ
(
length
,
data
,
cleartext
->
data
))
{
{
fprintf
(
stderr
,
"test_invert: Decrypt failed:
\n
Input:"
);
fprintf
(
stderr
,
"test_invert: Decrypt failed:
\n
Input:"
);
print_hex
(
length
,
ciphertext
);
tstring_
print_hex
(
ciphertext
);
fprintf
(
stderr
,
"
\n
Output: "
);
fprintf
(
stderr
,
"
\n
Output: "
);
print_hex
(
length
,
data
);
print_hex
(
length
,
data
);
fprintf
(
stderr
,
"
\n
Expected:"
);
fprintf
(
stderr
,
"
\n
Expected:"
);
print_hex
(
length
,
cleartext
);
tstring_
print_hex
(
cleartext
);
fprintf
(
stderr
,
"
\n
"
);
fprintf
(
stderr
,
"
\n
"
);
FAIL
();
FAIL
();
}
}
free
(
data
);
free
(
data
);
}
}
int
void
test_main
(
void
)
test_main
(
void
)
{
{
/* 128 bit keys */
/* 128 bit keys */
test_cipher
(
&
nettle_aes128
,
test_cipher
(
&
nettle_aes128
,
HL
(
"0001020305060708 0A0B0C0D0F101112"
),
SHEX
(
"0001020305060708 0A0B0C0D0F101112"
),
HL
(
"506812A45F08C889 B97F5980038B8359"
),
SHEX
(
"506812A45F08C889 B97F5980038B8359"
),
H
(
"D8F532538289EF7D 06B506A4FD5BE9C9"
));
SHEX
(
"D8F532538289EF7D 06B506A4FD5BE9C9"
));
test_cipher
(
&
nettle_aes128
,
test_cipher
(
&
nettle_aes128
,
HL
(
"14151617191A1B1C 1E1F202123242526"
),
SHEX
(
"14151617191A1B1C 1E1F202123242526"
),
HL
(
"5C6D71CA30DE8B8B 00549984D2EC7D4B"
),
SHEX
(
"5C6D71CA30DE8B8B 00549984D2EC7D4B"
),
H
(
"59AB30F4D4EE6E4F F9907EF65B1FB68C"
));
SHEX
(
"59AB30F4D4EE6E4F F9907EF65B1FB68C"
));
test_cipher
(
&
nettle_aes128
,
test_cipher
(
&
nettle_aes128
,
HL
(
"28292A2B2D2E2F30 323334353738393A"
),
SHEX
(
"28292A2B2D2E2F30 323334353738393A"
),
HL
(
"53F3F4C64F8616E4 E7C56199F48F21F6"
),
SHEX
(
"53F3F4C64F8616E4 E7C56199F48F21F6"
),
H
(
"BF1ED2FCB2AF3FD4 1443B56D85025CB1"
));
SHEX
(
"BF1ED2FCB2AF3FD4 1443B56D85025CB1"
));
test_cipher
(
&
nettle_aes128
,
test_cipher
(
&
nettle_aes128
,
HL
(
"A0A1A2A3A5A6A7A8 AAABACADAFB0B1B2"
),
SHEX
(
"A0A1A2A3A5A6A7A8 AAABACADAFB0B1B2"
),
HL
(
"F5F4F7F684878689 A6A7A0A1D2CDCCCF"
),
SHEX
(
"F5F4F7F684878689 A6A7A0A1D2CDCCCF"
),
H
(
"CE52AF650D088CA5 59425223F4D32694"
));
SHEX
(
"CE52AF650D088CA5 59425223F4D32694"
));
/* 192 bit keys */
/* 192 bit keys */
test_cipher
(
&
nettle_aes192
,
test_cipher
(
&
nettle_aes192
,
HL
(
"0001020305060708 0A0B0C0D0F101112"
SHEX
(
"0001020305060708 0A0B0C0D0F101112"
"14151617191A1B1C"
),
"14151617191A1B1C"
),
HL
(
"2D33EEF2C0430A8A 9EBF45E809C40BB6"
),
SHEX
(
"2D33EEF2C0430A8A 9EBF45E809C40BB6"
),
H
(
"DFF4945E0336DF4C 1C56BC700EFF837F"
));
SHEX
(
"DFF4945E0336DF4C 1C56BC700EFF837F"
));
/* 256 bit keys */
/* 256 bit keys */
test_cipher
(
&
nettle_aes256
,
test_cipher
(
&
nettle_aes256
,
HL
(
"0001020305060708 0A0B0C0D0F101112"
SHEX
(
"0001020305060708 0A0B0C0D0F101112"
"14151617191A1B1C 1E1F202123242526"
),
"14151617191A1B1C 1E1F202123242526"
),
HL
(
"834EADFCCAC7E1B30664B1ABA44815AB"
),
SHEX
(
"834EADFCCAC7E1B30664B1ABA44815AB"
),
H
(
"1946DABF6A03A2A2 C3D0B05080AED6FC"
));
SHEX
(
"1946DABF6A03A2A2 C3D0B05080AED6FC"
));
/* This test case has been problematic with the CBC test case */
/* This test case has been problematic with the CBC test case */
test_cipher
(
&
nettle_aes256
,
test_cipher
(
&
nettle_aes256
,
HL
(
"8d ae 93 ff fc 78 c9 44"
SHEX
(
"8d ae 93 ff fc 78 c9 44"
"2a bd 0c 1e 68 bc a6 c7"
"2a bd 0c 1e 68 bc a6 c7"
"05 c7 84 e3 5a a9 11 8b"
"05 c7 84 e3 5a a9 11 8b"
"d3 16 aa 54 9b 44 08 9e"
),
"d3 16 aa 54 9b 44 08 9e"
),
HL
(
"a5 ce 55 d4 21 15 a1 c6 4a a4 0c b2 ca a6 d1 37"
),
SHEX
(
"a5 ce 55 d4 21 15 a1 c6 4a a4 0c b2 ca a6 d1 37"
),
/* In the cbc test, I once got the bad value
/* In the cbc test, I once got the bad value
* "b2 a0 6c d2 2f df 7d 2c 26 d2 42 88 8f 20 74 a2" */
* "b2 a0 6c d2 2f df 7d 2c 26 d2 42 88 8f 20 74 a2" */
H
(
"1f 94 fc 85 f2 36 21 06"
SHEX
(
"1f 94 fc 85 f2 36 21 06"
"4a ea e3 c9 cc 38 01 0e"
));
"4a ea e3 c9 cc 38 01 0e"
));
/* From draft NIST spec on AES modes.
/* From draft NIST spec on AES modes.
...
@@ -102,12 +105,12 @@ test_main(void)
...
@@ -102,12 +105,12 @@ test_main(void)
*/
*/
test_cipher
(
&
nettle_aes128
,
test_cipher
(
&
nettle_aes128
,
HL
(
"2b7e151628aed2a6abf7158809cf4f3c"
),
SHEX
(
"2b7e151628aed2a6abf7158809cf4f3c"
),
HL
(
"6bc1bee22e409f96e93d7e117393172a"
SHEX
(
"6bc1bee22e409f96e93d7e117393172a"
"ae2d8a571e03ac9c9eb76fac45af8e51"
"ae2d8a571e03ac9c9eb76fac45af8e51"
"30c81c46a35ce411e5fbc1191a0a52ef"
"30c81c46a35ce411e5fbc1191a0a52ef"
"f69f2445df4f9b17ad2b417be66c3710"
),
"f69f2445df4f9b17ad2b417be66c3710"
),
H
(
"3ad77bb40d7a3660a89ecaf32466ef97"
SHEX
(
"3ad77bb40d7a3660a89ecaf32466ef97"
"f5d3d58503b9699de785895a96fdbaaf"
"f5d3d58503b9699de785895a96fdbaaf"
"43b1cd7f598ece23881b00e3ed030688"
"43b1cd7f598ece23881b00e3ed030688"
"7b0c785e27e8ad3f8223207104725dd4"
));
"7b0c785e27e8ad3f8223207104725dd4"
));
...
@@ -115,43 +118,41 @@ test_main(void)
...
@@ -115,43 +118,41 @@ test_main(void)
/* F.1.3 ECB-AES192-Encrypt */
/* F.1.3 ECB-AES192-Encrypt */
test_cipher
(
&
nettle_aes192
,
test_cipher
(
&
nettle_aes192
,
HL
(
"8e73b0f7da0e6452c810f32b809079e5 62f8ead2522c6b7b"
),
SHEX
(
"8e73b0f7da0e6452c810f32b809079e5 62f8ead2522c6b7b"
),
HL
(
"6bc1bee22e409f96e93d7e117393172a"
SHEX
(
"6bc1bee22e409f96e93d7e117393172a"
"ae2d8a571e03ac9c9eb76fac45af8e51"
"ae2d8a571e03ac9c9eb76fac45af8e51"
"30c81c46a35ce411e5fbc1191a0a52ef"
"30c81c46a35ce411e5fbc1191a0a52ef"
"f69f2445df4f9b17ad2b417be66c3710"
),
"f69f2445df4f9b17ad2b417be66c3710"
),
H
(
"bd334f1d6e45f25ff712a214571fa5cc"
SHEX
(
"bd334f1d6e45f25ff712a214571fa5cc"
"974104846d0ad3ad7734ecb3ecee4eef"
"974104846d0ad3ad7734ecb3ecee4eef"
"ef7afd2270e2e60adce0ba2face6444e"
"ef7afd2270e2e60adce0ba2face6444e"
"9a4b41ba738d6c72fb16691603c18e0e"
));
"9a4b41ba738d6c72fb16691603c18e0e"
));
/* F.1.5 ECB-AES256-Encrypt */
/* F.1.5 ECB-AES256-Encrypt */
test_cipher
(
&
nettle_aes256
,
test_cipher
(
&
nettle_aes256
,
HL
(
"603deb1015ca71be2b73aef0857d7781"
SHEX
(
"603deb1015ca71be2b73aef0857d7781"
"1f352c073b6108d72d9810a30914dff4"
),
"1f352c073b6108d72d9810a30914dff4"
),
HL
(
"6bc1bee22e409f96e93d7e117393172a"
SHEX
(
"6bc1bee22e409f96e93d7e117393172a"
"ae2d8a571e03ac9c9eb76fac45af8e51"
"ae2d8a571e03ac9c9eb76fac45af8e51"
"30c81c46a35ce411e5fbc1191a0a52ef"
"30c81c46a35ce411e5fbc1191a0a52ef"
"f69f2445df4f9b17ad2b417be66c3710"
),
"f69f2445df4f9b17ad2b417be66c3710"
),
H
(
"f3eed1bdb5d2a03c064b5a7e3db181f8"
SHEX
(
"f3eed1bdb5d2a03c064b5a7e3db181f8"
"591ccb10d410ed26dc5ba74a31362870"
"591ccb10d410ed26dc5ba74a31362870"
"b6ed21b99ca6f4f9f153e7b1beafed1d"
"b6ed21b99ca6f4f9f153e7b1beafed1d"
"23304b7a39f9f3ff067d8d8f9e24ecc7"
));
"23304b7a39f9f3ff067d8d8f9e24ecc7"
));
/* Test aes_invert_key with src != dst */
/* Test aes_invert_key with src != dst */
test_invert
(
HL
(
"0001020305060708 0A0B0C0D0F101112"
),
test_invert
(
SHEX
(
"0001020305060708 0A0B0C0D0F101112"
),
HL
(
"506812A45F08C889 B97F5980038B8359"
),
SHEX
(
"506812A45F08C889 B97F5980038B8359"
),
H
(
"D8F532538289EF7D 06B506A4FD5BE9C9"
));
SHEX
(
"D8F532538289EF7D 06B506A4FD5BE9C9"
));
test_invert
(
HL
(
"0001020305060708 0A0B0C0D0F101112"
test_invert
(
SHEX
(
"0001020305060708 0A0B0C0D0F101112"
"14151617191A1B1C"
),
"14151617191A1B1C"
),
HL
(
"2D33EEF2C0430A8A 9EBF45E809C40BB6"
),
SHEX
(
"2D33EEF2C0430A8A 9EBF45E809C40BB6"
),
H
(
"DFF4945E0336DF4C 1C56BC700EFF837F"
));
SHEX
(
"DFF4945E0336DF4C 1C56BC700EFF837F"
));
test_invert
(
HL
(
"0001020305060708 0A0B0C0D0F101112"
test_invert
(
SHEX
(
"0001020305060708 0A0B0C0D0F101112"
"14151617191A1B1C 1E1F202123242526"
),
"14151617191A1B1C 1E1F202123242526"
),
HL
(
"834EADFCCAC7E1B30664B1ABA44815AB"
),
SHEX
(
"834EADFCCAC7E1B30664B1ABA44815AB"
),
H
(
"1946DABF6A03A2A2 C3D0B05080AED6FC"
));
SHEX
(
"1946DABF6A03A2A2 C3D0B05080AED6FC"
));
SUCCESS
();
}
}
/* Internal state for the first test case:
/* Internal state for the first test case:
...
...
testsuite/arcfour-test.c
View file @
75288e44
#include "testutils.h"
#include "testutils.h"
#include "arcfour.h"
#include "arcfour.h"
int
void
test_main
(
void
)
test_main
(
void
)
{
{
test_cipher_stream
(
&
nettle_arcfour128
,
test_cipher_stream
(
&
nettle_arcfour128
,
HL
(
"01234567 89ABCDEF 00000000 00000000"
),
SHEX
(
"01234567 89ABCDEF 00000000 00000000"
),
HL
(
"01234567 89ABCDEF"
),
SHEX
(
"01234567 89ABCDEF"
),
H
(
"69723659 1B5242B1"
));
SHEX
(
"69723659 1B5242B1"
));
/* More data. This ensures that we get some collisions between the S
/* More data. This ensures that we get some collisions between the S
accesses at index i,j and the access at si + sj. I.e. the cases
accesses at index i,j and the access at si + sj. I.e. the cases
where the ordering of loads and stores matter. */
where the ordering of loads and stores matter. */
test_cipher_stream
(
&
nettle_arcfour128
,
test_cipher_stream
(
&
nettle_arcfour128
,
HL
(
"aaaaaaaa bbbbbbbb cccccccc dddddddd"
),
SHEX
(
"aaaaaaaa bbbbbbbb cccccccc dddddddd"
),
HL
(
"00000000 00000000 00000000 00000000"
SHEX
(
"00000000 00000000 00000000 00000000"
"00000000 00000000 00000000 00000000"
"00000000 00000000 00000000 00000000"
"00000000 00000000 00000000 00000000"
"00000000 00000000 00000000 00000000"
"00000000 00000000 00000000 00000000"
"00000000 00000000 00000000 00000000"
...
@@ -53,7 +53,7 @@ test_main(void)
...
@@ -53,7 +53,7 @@ test_main(void)
"00000000 00000000 00000000 00000000"
"00000000 00000000 00000000 00000000"
"00000000 00000000 00000000 00000000"
"00000000 00000000 00000000 00000000"
"00000000 00000000 00000000 00000000"
),
"00000000 00000000 00000000 00000000"
),
H
(
"a2b35dc7 bf95ae1e 1c432d15 f4fb8c1c"
SHEX
(
"a2b35dc7 bf95ae1e 1c432d15 f4fb8c1c"
"f264e1d0 bd090831 6caa7d17 5401ae67"
"f264e1d0 bd090831 6caa7d17 5401ae67"
"3cfbd140 fd3dee42 1012d674 2fb69fa3"
"3cfbd140 fd3dee42 1012d674 2fb69fa3"
"6522631e bb3d4703 535de1ce 4a81ddce"
"6522631e bb3d4703 535de1ce 4a81ddce"
...
@@ -92,6 +92,4 @@ test_main(void)
...
@@ -92,6 +92,4 @@ test_main(void)
"af01f15a 491732fb 22aa09a3 d2e1e408"
"af01f15a 491732fb 22aa09a3 d2e1e408"
"fe94bdb4 993c68b1 1bb79eb1 bb7ec446"
"fe94bdb4 993c68b1 1bb79eb1 bb7ec446"
"760ef7bf 2caa8713 479760e5 a6e143cd"
));
"760ef7bf 2caa8713 479760e5 a6e143cd"
));
SUCCESS
();
}
}
testsuite/arctwo-test.c
View file @
75288e44
...
@@ -25,91 +25,91 @@
...
@@ -25,91 +25,91 @@
/* For tests with obscure values of ebk. */
/* For tests with obscure values of ebk. */
static
void
static
void
test_arctwo
(
unsigned
ekb
,
test_arctwo
(
unsigned
ekb
,
unsigned
key_length
,
const
struct
tstring
*
key
,
const
uint8_t
*
key
,
const
struct
tstring
*
cleartext
,
unsigned
length
,
const
struct
tstring
*
ciphertext
)
const
uint8_t
*
cleartext
,
const
uint8_t
*
ciphertext
)
{
{
struct
arctwo_ctx
ctx
;
struct
arctwo_ctx
ctx
;
uint8_t
*
data
=
xalloc
(
length
);
uint8_t
*
data
;
unsigned
length
;
arctwo_set_key_ekb
(
&
ctx
,
key_length
,
key
,
ekb
);
ASSERT
(
cleartext
->
length
==
ciphertext
->
length
);
arctwo_encrypt
(
&
ctx
,
length
,
data
,
cleartext
)
;
length
=
cleartext
->
length
;
if
(
!
MEMEQ
(
length
,
data
,
ciphertext
))
data
=
xalloc
(
length
);
FAIL
();
arctwo_set_key_ekb
(
&
ctx
,
key
->
length
,
key
->
data
,
ekb
);
arctwo_encrypt
(
&
ctx
,
length
,
data
,
cleartext
->
data
);
ASSERT
(
MEMEQ
(
length
,
data
,
ciphertext
->
data
));
arctwo_decrypt
(
&
ctx
,
length
,
data
,
data
);
arctwo_decrypt
(
&
ctx
,
length
,
data
,
data
);
if
(
!
MEMEQ
(
length
,
data
,
cleartext
))
ASSERT
(
MEMEQ
(
length
,
data
,
cleartext
->
data
));
FAIL
();
free
(
data
);
free
(
data
);
}
}
int
void
test_main
(
void
)
test_main
(
void
)
{
{
/* Test vectors from Peter Gutmann's paper. */
/* Test vectors from Peter Gutmann's paper. */
test_cipher
(
&
nettle_arctwo_gutmann128
,
test_cipher
(
&
nettle_arctwo_gutmann128
,
HL
(
"00000000 00000000 00000000 00000000"
),
SHEX
(
"00000000 00000000 00000000 00000000"
),
HL
(
"00000000 00000000"
),
SHEX
(
"00000000 00000000"
),
H
(
"1c198a83 8df028b7"
));
SHEX
(
"1c198a83 8df028b7"
));
test_cipher
(
&
nettle_arctwo_gutmann128
,
test_cipher
(
&
nettle_arctwo_gutmann128
,
HL
(
"00010203 04050607 08090a0b 0c0d0e0f"
),
SHEX
(
"00010203 04050607 08090a0b 0c0d0e0f"
),
HL
(
"00000000 00000000"
),
SHEX
(
"00000000 00000000"
),
H
(
"50dc0162 bd757f31"
));
SHEX
(
"50dc0162 bd757f31"
));
/* This one was checked against libmcrypt's RFC2268. */
/* This one was checked against libmcrypt's RFC2268. */
test_cipher
(
&
nettle_arctwo_gutmann128
,
test_cipher
(
&
nettle_arctwo_gutmann128
,
HL
(
"30000000 00000000 00000000 00000000"
),
SHEX
(
"30000000 00000000 00000000 00000000"
),
HL
(
"10000000 00000000"
),
SHEX
(
"10000000 00000000"
),
H
(
"8fd10389 336bf95e"
));
SHEX
(
"8fd10389 336bf95e"
));
/* Test vectors from RFC 2268. */
/* Test vectors from RFC 2268. */
test_cipher
(
&
nettle_arctwo64
,
test_cipher
(
&
nettle_arctwo64
,
HL
(
"ffffffff ffffffff"
),
SHEX
(
"ffffffff ffffffff"
),
HL
(
"ffffffff ffffffff"
),
SHEX
(
"ffffffff ffffffff"
),
H
(
"278b27e4 2e2f0d49"
));
SHEX
(
"278b27e4 2e2f0d49"
));
test_cipher
(
&
nettle_arctwo64
,
test_cipher
(
&
nettle_arctwo64
,
HL
(
"30000000 00000000"
),
SHEX
(
"30000000 00000000"
),
HL
(
"10000000 00000001"
),
SHEX
(
"10000000 00000001"
),
H
(
"30649edf 9be7d2c2"
));
SHEX
(
"30649edf 9be7d2c2"
));
test_cipher
(
&
nettle_arctwo128
,
test_cipher
(
&
nettle_arctwo128
,
HL
(
"88bca90e 90875a7f 0f79c384 627bafb2"
),
SHEX
(
"88bca90e 90875a7f 0f79c384 627bafb2"
),
HL
(
"00000000 00000000"
),
SHEX
(
"00000000 00000000"
),
H
(
"2269552a b0f85ca6"
));
SHEX
(
"2269552a b0f85ca6"
));
/* More obscure tests from RFC 2286 */
/* More obscure tests from RFC 2286 */
test_arctwo
(
63
,
test_arctwo
(
63
,
HL
(
"00000000 00000000"
),
SHEX
(
"00000000 00000000"
),
HL
(
"00000000 00000000"
),
SHEX
(
"00000000 00000000"
),
H
(
"ebb773f9 93278eff"
));
SHEX
(
"ebb773f9 93278eff"
));
test_arctwo
(
64
,
test_arctwo
(
64
,
HL
(
"88"
),
SHEX
(
"88"
),
HL
(
"00000000 00000000"
),
SHEX
(
"00000000 00000000"
),
H
(
"61a8a244 adacccf0"
));
SHEX
(
"61a8a244 adacccf0"
));
test_arctwo
(
64
,
test_arctwo
(
64
,
HL
(
"88bca90e 90875a"
),
SHEX
(
"88bca90e 90875a"
),
HL
(
"00000000 00000000"
),
SHEX
(
"00000000 00000000"
),
H
(
"6ccf4308 974c267f"
));
SHEX
(
"6ccf4308 974c267f"
));
test_arctwo
(
64
,
test_arctwo
(
64
,
HL
(
"88bca90e 90875a7f 0f79c384 627bafb2"
),
SHEX
(
"88bca90e 90875a7f 0f79c384 627bafb2"
),
HL
(
"00000000 00000000"
),
SHEX
(
"00000000 00000000"
),
H
(
"1a807d27 2bbe5db1"
));
SHEX
(
"1a807d27 2bbe5db1"
));
test_arctwo
(
129
,
test_arctwo
(
129
,
HL
(
"88bca90e 90875a7f 0f79c384 627bafb2"
SHEX
(
"88bca90e 90875a7f 0f79c384 627bafb2"
"16f80a6f 85920584 c42fceb0 be255daf 1e"
),
"16f80a6f 85920584 c42fceb0 be255daf 1e"
),
HL
(
"00000000 00000000"
),
SHEX
(
"00000000 00000000"
),
H
(
"5b78d3a4 3dfff1f1"
));
SHEX
(
"5b78d3a4 3dfff1f1"
));
SUCCESS
();
}
}
testsuite/base16-test.c
View file @
75288e44
#include "testutils.h"
#include "testutils.h"
#include "base16.h"
#include "base16.h"
int
void
test_main
(
void
)
test_main
(
void
)
{
{
ASSERT
(
BASE16_ENCODE_LENGTH
(
0
)
==
0
);
ASSERT
(
BASE16_ENCODE_LENGTH
(
0
)
==
0
);
...
@@ -21,7 +21,5 @@ test_main(void)
...
@@ -21,7 +21,5 @@ test_main(void)
test_armor
(
&
nettle_base16
,
4
,
"Hell"
,
"48656c6c"
);
test_armor
(
&
nettle_base16
,
4
,
"Hell"
,
"48656c6c"
);
test_armor
(
&
nettle_base16
,
5
,
"Hello"
,
"48656c6c6f"
);
test_armor
(
&
nettle_base16
,
5
,
"Hello"
,
"48656c6c6f"
);
test_armor
(
&
nettle_base16
,
6
,
"Hello"
,
"48656c6c6f00"
);
test_armor
(
&
nettle_base16
,
6
,
"Hello"
,
"48656c6c6f00"
);
SUCCESS
();
}
}
testsuite/base64-test.c
View file @
75288e44
#include "testutils.h"
#include "testutils.h"
#include "base64.h"
#include "base64.h"
int
void
test_main
(
void
)
test_main
(
void
)
{
{
ASSERT
(
BASE64_ENCODE_LENGTH
(
0
)
==
0
);
/* At most 4 bits */
ASSERT
(
BASE64_ENCODE_LENGTH
(
0
)
==
0
);
/* At most 4 bits */
...
@@ -45,6 +45,4 @@ test_main(void)
...
@@ -45,6 +45,4 @@ test_main(void)
ASSERT
(
MEMEQ
(
9
,
buffer
,
"HelloG8=x"
));
ASSERT
(
MEMEQ
(
9
,
buffer
,
"HelloG8=x"
));
}
}
SUCCESS
();
}
}
testsuite/bignum-test.c
View file @
75288e44
...
@@ -11,27 +11,24 @@
...
@@ -11,27 +11,24 @@
#include "bignum.h"
#include "bignum.h"
static
void
static
void