Commit 75288e44 authored by Niels Möller's avatar Niels Möller

Testsuite overhaul, including proper deallocation of storage.

parent 728a20ee
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 >
0, otherwise call free. Fixes a small memory leak.
(nettle_xrealloc): Likewise.
......
......@@ -2,25 +2,28 @@
#include "aes.h"
static void
test_invert(unsigned key_length, const uint8_t *key,
unsigned length, const uint8_t *cleartext,
const uint8_t *ciphertext)
test_invert(const struct tstring *key,
const struct tstring *cleartext,
const struct tstring *ciphertext)
{
struct aes_ctx encrypt;
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_encrypt (&encrypt, length, data, cleartext);
aes_set_encrypt_key (&encrypt, key->length, key->data);
aes_encrypt (&encrypt, length, data, cleartext->data);
if (!MEMEQ(length, data, ciphertext))
if (!MEMEQ(length, data, ciphertext->data))
{
fprintf(stderr, "test_invert: Encrypt failed:\nInput:");
print_hex(length, cleartext);
tstring_print_hex(cleartext);
fprintf(stderr, "\nOutput: ");
print_hex(length, data);
fprintf(stderr, "\nExpected:");
print_hex(length, ciphertext);
tstring_print_hex(ciphertext);
fprintf(stderr, "\n");
FAIL();
}
......@@ -28,72 +31,72 @@ test_invert(unsigned key_length, const uint8_t *key,
aes_invert_key (&decrypt, &encrypt);
aes_decrypt (&decrypt, length, data, data);
if (!MEMEQ(length, data, cleartext))
if (!MEMEQ(length, data, cleartext->data))
{
fprintf(stderr, "test_invert: Decrypt failed:\nInput:");
print_hex(length, ciphertext);
tstring_print_hex(ciphertext);
fprintf(stderr, "\nOutput: ");
print_hex(length, data);
fprintf(stderr, "\nExpected:");
print_hex(length, cleartext);
tstring_print_hex(cleartext);
fprintf(stderr, "\n");
FAIL();
}
free (data);
}
int
void
test_main(void)
{
/* 128 bit keys */
test_cipher(&nettle_aes128,
HL("0001020305060708 0A0B0C0D0F101112"),
HL("506812A45F08C889 B97F5980038B8359"),
H("D8F532538289EF7D 06B506A4FD5BE9C9"));
SHEX("0001020305060708 0A0B0C0D0F101112"),
SHEX("506812A45F08C889 B97F5980038B8359"),
SHEX("D8F532538289EF7D 06B506A4FD5BE9C9"));
test_cipher(&nettle_aes128,
HL("14151617191A1B1C 1E1F202123242526"),
HL("5C6D71CA30DE8B8B 00549984D2EC7D4B"),
H("59AB30F4D4EE6E4F F9907EF65B1FB68C"));
SHEX("14151617191A1B1C 1E1F202123242526"),
SHEX("5C6D71CA30DE8B8B 00549984D2EC7D4B"),
SHEX("59AB30F4D4EE6E4F F9907EF65B1FB68C"));
test_cipher(&nettle_aes128,
HL("28292A2B2D2E2F30 323334353738393A"),
HL("53F3F4C64F8616E4 E7C56199F48F21F6"),
H("BF1ED2FCB2AF3FD4 1443B56D85025CB1"));
SHEX("28292A2B2D2E2F30 323334353738393A"),
SHEX("53F3F4C64F8616E4 E7C56199F48F21F6"),
SHEX("BF1ED2FCB2AF3FD4 1443B56D85025CB1"));
test_cipher(&nettle_aes128,
HL("A0A1A2A3A5A6A7A8 AAABACADAFB0B1B2"),
HL("F5F4F7F684878689 A6A7A0A1D2CDCCCF"),
H("CE52AF650D088CA5 59425223F4D32694"));
SHEX("A0A1A2A3A5A6A7A8 AAABACADAFB0B1B2"),
SHEX("F5F4F7F684878689 A6A7A0A1D2CDCCCF"),
SHEX("CE52AF650D088CA5 59425223F4D32694"));
/* 192 bit keys */
test_cipher(&nettle_aes192,
HL("0001020305060708 0A0B0C0D0F101112"
"14151617191A1B1C"),
HL("2D33EEF2C0430A8A 9EBF45E809C40BB6"),
H("DFF4945E0336DF4C 1C56BC700EFF837F"));
SHEX("0001020305060708 0A0B0C0D0F101112"
"14151617191A1B1C"),
SHEX("2D33EEF2C0430A8A 9EBF45E809C40BB6"),
SHEX("DFF4945E0336DF4C 1C56BC700EFF837F"));
/* 256 bit keys */
test_cipher(&nettle_aes256,
HL("0001020305060708 0A0B0C0D0F101112"
"14151617191A1B1C 1E1F202123242526"),
HL("834EADFCCAC7E1B30664B1ABA44815AB"),
H("1946DABF6A03A2A2 C3D0B05080AED6FC"));
SHEX("0001020305060708 0A0B0C0D0F101112"
"14151617191A1B1C 1E1F202123242526"),
SHEX("834EADFCCAC7E1B30664B1ABA44815AB"),
SHEX("1946DABF6A03A2A2 C3D0B05080AED6FC"));
/* This test case has been problematic with the CBC test case */
test_cipher(&nettle_aes256,
HL("8d ae 93 ff fc 78 c9 44"
"2a bd 0c 1e 68 bc a6 c7"
"05 c7 84 e3 5a a9 11 8b"
"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("8d ae 93 ff fc 78 c9 44"
"2a bd 0c 1e 68 bc a6 c7"
"05 c7 84 e3 5a a9 11 8b"
"d3 16 aa 54 9b 44 08 9e"),
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
* "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"
"4a ea e3 c9 cc 38 01 0e"));
SHEX("1f 94 fc 85 f2 36 21 06"
"4a ea e3 c9 cc 38 01 0e"));
/* From draft NIST spec on AES modes.
*
......@@ -102,56 +105,54 @@ test_main(void)
*/
test_cipher(&nettle_aes128,
HL("2b7e151628aed2a6abf7158809cf4f3c"),
HL("6bc1bee22e409f96e93d7e117393172a"
"ae2d8a571e03ac9c9eb76fac45af8e51"
"30c81c46a35ce411e5fbc1191a0a52ef"
"f69f2445df4f9b17ad2b417be66c3710"),
H("3ad77bb40d7a3660a89ecaf32466ef97"
"f5d3d58503b9699de785895a96fdbaaf"
"43b1cd7f598ece23881b00e3ed030688"
"7b0c785e27e8ad3f8223207104725dd4"));
SHEX("2b7e151628aed2a6abf7158809cf4f3c"),
SHEX("6bc1bee22e409f96e93d7e117393172a"
"ae2d8a571e03ac9c9eb76fac45af8e51"
"30c81c46a35ce411e5fbc1191a0a52ef"
"f69f2445df4f9b17ad2b417be66c3710"),
SHEX("3ad77bb40d7a3660a89ecaf32466ef97"
"f5d3d58503b9699de785895a96fdbaaf"
"43b1cd7f598ece23881b00e3ed030688"
"7b0c785e27e8ad3f8223207104725dd4"));
/* F.1.3 ECB-AES192-Encrypt */
test_cipher(&nettle_aes192,
HL("8e73b0f7da0e6452c810f32b809079e5 62f8ead2522c6b7b"),
HL("6bc1bee22e409f96e93d7e117393172a"
"ae2d8a571e03ac9c9eb76fac45af8e51"
"30c81c46a35ce411e5fbc1191a0a52ef"
"f69f2445df4f9b17ad2b417be66c3710"),
H("bd334f1d6e45f25ff712a214571fa5cc"
"974104846d0ad3ad7734ecb3ecee4eef"
"ef7afd2270e2e60adce0ba2face6444e"
"9a4b41ba738d6c72fb16691603c18e0e"));
SHEX("8e73b0f7da0e6452c810f32b809079e5 62f8ead2522c6b7b"),
SHEX("6bc1bee22e409f96e93d7e117393172a"
"ae2d8a571e03ac9c9eb76fac45af8e51"
"30c81c46a35ce411e5fbc1191a0a52ef"
"f69f2445df4f9b17ad2b417be66c3710"),
SHEX("bd334f1d6e45f25ff712a214571fa5cc"
"974104846d0ad3ad7734ecb3ecee4eef"
"ef7afd2270e2e60adce0ba2face6444e"
"9a4b41ba738d6c72fb16691603c18e0e"));
/* F.1.5 ECB-AES256-Encrypt */
test_cipher(&nettle_aes256,
HL("603deb1015ca71be2b73aef0857d7781"
"1f352c073b6108d72d9810a30914dff4"),
HL("6bc1bee22e409f96e93d7e117393172a"
"ae2d8a571e03ac9c9eb76fac45af8e51"
"30c81c46a35ce411e5fbc1191a0a52ef"
"f69f2445df4f9b17ad2b417be66c3710"),
H("f3eed1bdb5d2a03c064b5a7e3db181f8"
"591ccb10d410ed26dc5ba74a31362870"
"b6ed21b99ca6f4f9f153e7b1beafed1d"
"23304b7a39f9f3ff067d8d8f9e24ecc7"));
SHEX("603deb1015ca71be2b73aef0857d7781"
"1f352c073b6108d72d9810a30914dff4"),
SHEX("6bc1bee22e409f96e93d7e117393172a"
"ae2d8a571e03ac9c9eb76fac45af8e51"
"30c81c46a35ce411e5fbc1191a0a52ef"
"f69f2445df4f9b17ad2b417be66c3710"),
SHEX("f3eed1bdb5d2a03c064b5a7e3db181f8"
"591ccb10d410ed26dc5ba74a31362870"
"b6ed21b99ca6f4f9f153e7b1beafed1d"
"23304b7a39f9f3ff067d8d8f9e24ecc7"));
/* Test aes_invert_key with src != dst */
test_invert(HL("0001020305060708 0A0B0C0D0F101112"),
HL("506812A45F08C889 B97F5980038B8359"),
H("D8F532538289EF7D 06B506A4FD5BE9C9"));
test_invert(HL("0001020305060708 0A0B0C0D0F101112"
"14151617191A1B1C"),
HL("2D33EEF2C0430A8A 9EBF45E809C40BB6"),
H("DFF4945E0336DF4C 1C56BC700EFF837F"));
test_invert(HL("0001020305060708 0A0B0C0D0F101112"
"14151617191A1B1C 1E1F202123242526"),
HL("834EADFCCAC7E1B30664B1ABA44815AB"),
H("1946DABF6A03A2A2 C3D0B05080AED6FC"));
SUCCESS();
test_invert(SHEX("0001020305060708 0A0B0C0D0F101112"),
SHEX("506812A45F08C889 B97F5980038B8359"),
SHEX("D8F532538289EF7D 06B506A4FD5BE9C9"));
test_invert(SHEX("0001020305060708 0A0B0C0D0F101112"
"14151617191A1B1C"),
SHEX("2D33EEF2C0430A8A 9EBF45E809C40BB6"),
SHEX("DFF4945E0336DF4C 1C56BC700EFF837F"));
test_invert(SHEX("0001020305060708 0A0B0C0D0F101112"
"14151617191A1B1C 1E1F202123242526"),
SHEX("834EADFCCAC7E1B30664B1ABA44815AB"),
SHEX("1946DABF6A03A2A2 C3D0B05080AED6FC"));
}
/* Internal state for the first test case:
......
#include "testutils.h"
#include "arcfour.h"
int
void
test_main(void)
{
test_cipher_stream(&nettle_arcfour128,
HL("01234567 89ABCDEF 00000000 00000000"),
HL("01234567 89ABCDEF"),
H("69723659 1B5242B1"));
SHEX("01234567 89ABCDEF 00000000 00000000"),
SHEX("01234567 89ABCDEF"),
SHEX("69723659 1B5242B1"));
/* 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
where the ordering of loads and stores matter. */
test_cipher_stream(&nettle_arcfour128,
HL("aaaaaaaa bbbbbbbb cccccccc dddddddd"),
HL("00000000 00000000 00000000 00000000"
"00000000 00000000 00000000 00000000"
"00000000 00000000 00000000 00000000"
"00000000 00000000 00000000 00000000"
SHEX("aaaaaaaa bbbbbbbb cccccccc dddddddd"),
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"
"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"
"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"
"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"
"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"
"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"
"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"
"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"),
H("a2b35dc7 bf95ae1e 1c432d15 f4fb8c1c"
"f264e1d0 bd090831 6caa7d17 5401ae67"
"3cfbd140 fd3dee42 1012d674 2fb69fa3"
"6522631e bb3d4703 535de1ce 4a81ddce"
"00000000 00000000 00000000 00000000"
"00000000 00000000 00000000 00000000"
"00000000 00000000 00000000 00000000"
"00000000 00000000 00000000 00000000"),
SHEX("a2b35dc7 bf95ae1e 1c432d15 f4fb8c1c"
"f264e1d0 bd090831 6caa7d17 5401ae67"
"3cfbd140 fd3dee42 1012d674 2fb69fa3"
"6522631e bb3d4703 535de1ce 4a81ddce"
"5780cfe0 b5fc9fae ebe14c96 26451bd9"
"992f2204 119cbe37 cbdc453c 7afa08c7"
"1380ccf8 48f81e53 a535cdfb 96c64faa"
"c3f759d0 fa1ff920 008d95cf 39d52324"
"5780cfe0 b5fc9fae ebe14c96 26451bd9"
"992f2204 119cbe37 cbdc453c 7afa08c7"
"1380ccf8 48f81e53 a535cdfb 96c64faa"
"c3f759d0 fa1ff920 008d95cf 39d52324"
"d0aac3f9 749b22e2 6a065145 06fb249d"
"ffb8e05e cb0381fe 5346a04a 63dac61c"
"10b6683e 3ab427de d4c6bc60 6366545e"
"77d0e121 96037717 a745d49e e72a70aa"
"d0aac3f9 749b22e2 6a065145 06fb249d"
"ffb8e05e cb0381fe 5346a04a 63dac61c"
"10b6683e 3ab427de d4c6bc60 6366545e"
"77d0e121 96037717 a745d49e e72a70aa"
"a50a612d 879b0580 fd4a89ae 3ee49871"
"2cf6c98d a62dfbc7 d7b2d901 2c3aaf27"
"42b7e089 ef2466ac 450b440c 138daa1a"
"cf9ebef6 f66a7a64 2677b213 06640130"
"a50a612d 879b0580 fd4a89ae 3ee49871"
"2cf6c98d a62dfbc7 d7b2d901 2c3aaf27"
"42b7e089 ef2466ac 450b440c 138daa1a"
"cf9ebef6 f66a7a64 2677b213 06640130"
"de6651df 0065180d 4db366ba 9c377712"
"53d21cac 82ed72a4 c6c4d81e 4375fea3"
"1f935909 95322c83 13c64d8e 829c93a6"
"d540a1b3 20f41541 96800888 1a7afc9b"
"de6651df 0065180d 4db366ba 9c377712"
"53d21cac 82ed72a4 c6c4d81e 4375fea3"
"1f935909 95322c83 13c64d8e 829c93a6"
"d540a1b3 20f41541 96800888 1a7afc9b"
"e39e89fc 3ac78be5 cdbbf774 33c36863"
"da2a3b1b d06e54a9 aa4b7edd 70b34941"
"b886f7db f36c3def f9fc4c80 7ce55ea5"
"98a7257b f68a9e1d caf4bfd6 43bd9853"
"e39e89fc 3ac78be5 cdbbf774 33c36863"
"da2a3b1b d06e54a9 aa4b7edd 70b34941"
"b886f7db f36c3def f9fc4c80 7ce55ea5"
"98a7257b f68a9e1d caf4bfd6 43bd9853"
"c966629d 54e34221 6e140780 d48c69bb"
"5e77e886 86f2ebcb 807732d5 d29bc384"
"a4ca1c31 c7c1b5b9 85dbfcf1 8d845905"
"a0ff487a b4a3f252 a75caebf 857ba48b"
"c966629d 54e34221 6e140780 d48c69bb"
"5e77e886 86f2ebcb 807732d5 d29bc384"
"a4ca1c31 c7c1b5b9 85dbfcf1 8d845905"
"a0ff487a b4a3f252 a75caebf 857ba48b"
"613e3067 92cada3e 0e07f599 2f4794f3"
"af01f15a 491732fb 22aa09a3 d2e1e408"
"fe94bdb4 993c68b1 1bb79eb1 bb7ec446"
"760ef7bf 2caa8713 479760e5 a6e143cd"));
SUCCESS();
"613e3067 92cada3e 0e07f599 2f4794f3"
"af01f15a 491732fb 22aa09a3 d2e1e408"
"fe94bdb4 993c68b1 1bb79eb1 bb7ec446"
"760ef7bf 2caa8713 479760e5 a6e143cd"));
}
......@@ -25,91 +25,91 @@
/* For tests with obscure values of ebk. */
static void
test_arctwo(unsigned ekb,
unsigned key_length,
const uint8_t *key,
unsigned length,
const uint8_t *cleartext,
const uint8_t *ciphertext)
const struct tstring *key,
const struct tstring *cleartext,
const struct tstring *ciphertext)
{
struct arctwo_ctx ctx;
uint8_t *data = xalloc(length);
uint8_t *data;
unsigned length;
arctwo_set_key_ekb(&ctx, key_length, key, ekb);
arctwo_encrypt(&ctx, length, data, cleartext);
ASSERT (cleartext->length == ciphertext->length);
length = cleartext->length;
data = xalloc(length);
if (!MEMEQ(length, data, ciphertext))
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);
if (!MEMEQ(length, data, cleartext))
FAIL();
ASSERT(MEMEQ(length, data, cleartext->data));
free(data);
}
int
void
test_main(void)
{
/* Test vectors from Peter Gutmann's paper. */
test_cipher(&nettle_arctwo_gutmann128,
HL("00000000 00000000 00000000 00000000"),
HL("00000000 00000000"),
H ("1c198a83 8df028b7"));
SHEX("00000000 00000000 00000000 00000000"),
SHEX("00000000 00000000"),
SHEX("1c198a83 8df028b7"));
test_cipher(&nettle_arctwo_gutmann128,
HL("00010203 04050607 08090a0b 0c0d0e0f"),
HL("00000000 00000000"),
H ("50dc0162 bd757f31"));
SHEX("00010203 04050607 08090a0b 0c0d0e0f"),
SHEX("00000000 00000000"),
SHEX("50dc0162 bd757f31"));
/* This one was checked against libmcrypt's RFC2268. */
test_cipher(&nettle_arctwo_gutmann128,
HL("30000000 00000000 00000000 00000000"),
HL("10000000 00000000"),
H ("8fd10389 336bf95e"));
SHEX("30000000 00000000 00000000 00000000"),
SHEX("10000000 00000000"),
SHEX("8fd10389 336bf95e"));
/* Test vectors from RFC 2268. */
test_cipher(&nettle_arctwo64,
HL("ffffffff ffffffff"),
HL("ffffffff ffffffff"),
H ("278b27e4 2e2f0d49"));
SHEX("ffffffff ffffffff"),
SHEX("ffffffff ffffffff"),
SHEX("278b27e4 2e2f0d49"));
test_cipher(&nettle_arctwo64,
HL("30000000 00000000"),
HL("10000000 00000001"),
H ("30649edf 9be7d2c2"));
SHEX("30000000 00000000"),
SHEX("10000000 00000001"),
SHEX("30649edf 9be7d2c2"));
test_cipher(&nettle_arctwo128,
HL("88bca90e 90875a7f 0f79c384 627bafb2"),
HL("00000000 00000000"),
H ("2269552a b0f85ca6"));
SHEX("88bca90e 90875a7f 0f79c384 627bafb2"),
SHEX("00000000 00000000"),
SHEX("2269552a b0f85ca6"));
/* More obscure tests from RFC 2286 */
test_arctwo(63,
HL("00000000 00000000"),
HL("00000000 00000000"),
H ("ebb773f9 93278eff"));
SHEX("00000000 00000000"),
SHEX("00000000 00000000"),
SHEX("ebb773f9 93278eff"));
test_arctwo(64,
HL("88"),
HL("00000000 00000000"),
H ("61a8a244 adacccf0"));
SHEX("88"),
SHEX("00000000 00000000"),
SHEX("61a8a244 adacccf0"));
test_arctwo(64,
HL("88bca90e 90875a"),
HL("00000000 00000000"),
H ("6ccf4308 974c267f"));
SHEX("88bca90e 90875a"),
SHEX("00000000 00000000"),
SHEX("6ccf4308 974c267f"));
test_arctwo(64,
HL("88bca90e 90875a7f 0f79c384 627bafb2"),
HL("00000000 00000000"),
H ("1a807d27 2bbe5db1"));
SHEX("88bca90e 90875a7f 0f79c384 627bafb2"),
SHEX("00000000 00000000"),
SHEX("1a807d27 2bbe5db1"));
test_arctwo(129,
HL("88bca90e 90875a7f 0f79c384 627bafb2"
"16f80a6f 85920584 c42fceb0 be255daf 1e"),
HL("00000000 00000000"),
H ("5b78d3a4 3dfff1f1"));
SUCCESS ();
SHEX("88bca90e 90875a7f 0f79c384 627bafb2"
"16f80a6f 85920584 c42fceb0 be255daf 1e"),
SHEX("00000000 00000000"),
SHEX("5b78d3a4 3dfff1f1"));
}
#include "testutils.h"
#include "base16.h"
int
void
test_main(void)
{
ASSERT(BASE16_ENCODE_LENGTH(0) == 0);
......@@ -21,7 +21,5 @@ test_main(void)
test_armor(&nettle_base16, 4, "Hell", "48656c6c");
test_armor(&nettle_base16, 5, "Hello", "48656c6c6f");
test_armor(&nettle_base16, 6, "Hello", "48656c6c6f00");
SUCCESS();
}
#include "testutils.h"
#include "base64.h"
int
void
test_main(void)
{
ASSERT(BASE64_ENCODE_LENGTH(0) == 0); /* At most 4 bits */
......@@ -45,6 +45,4 @@ test_main(void)
ASSERT(MEMEQ(9, buffer, "HelloG8=x"));
}
SUCCESS();
}
......@@ -11,27 +11,24 @@
#include "bignum.h"
static void
test_bignum(const char *hex, unsigned length, const uint8_t *base256)
test_bignum(const char *hex, const struct tstring *base256)
{
mpz_t a;
mpz_t b;
uint8_t *buf;
mpz_init_set_str(a, hex, 16);
nettle_mpz_init_set_str_256_s(b, length, base256);
nettle_mpz_init_set_str_256_s(b, base256->length, base256->data);
if (mpz_cmp(a, b))
FAIL();
ASSERT(mpz_cmp(a, b) == 0);
buf = xalloc(length + 1);
memset(buf, 17, length + 1);
buf = xalloc(base256->length + 1);
memset(buf, 17, base256->length + 1);
nettle_mpz_get_str_256(length, buf, a);
if (!MEMEQ(length, buf, base256))
FAIL();
nettle_mpz_get_str_256(base256->length, buf, a);
ASSERT(MEMEQ(base256->length, buf, base256->data));
if (buf[length] != 17)
FAIL();
ASSERT(buf[base256->length] == 17);
mpz_clear(a); mpz_clear(b);
free(buf);
......@@ -49,7 +46,7 @@ test_size(long x, unsigned size)
#endif /* HAVE_LIBGMP */
int
void
test_main(void)
{
#if HAVE_LIBGMP
......@@ -78,19 +75,18 @@ test_main(void)
test_size(- 0x8000, 2); /* 8000 */
test_size(- 0x8001, 3); /* ff7fff */
test_bignum("0", HL("00"));
test_bignum("010203040506", HL("010203040506"));
test_bignum("80010203040506", HL("0080010203040506"));
test_bignum( "-1", HL( "ff"));