Commit graph

183 commits

Author SHA1 Message Date
Dag-Erling Smørgrav
d383e7ab62 Misc cleanup after API change. 2017-04-06 19:51:45 +02:00
Dag-Erling Smørgrav
c2f4fa524f Second iteration of the cryb-cipher API.
We now have separate encryption and decryption methods, and can process an arbitrary amount of plaintext or ciphertext per call, rounded down to the block size (if applicable).  For stream ciphers, we also have a keystream method which fills the provided buffer with an arbitrary amount of keystream (once again, rounded down if applicable).
2017-04-06 19:51:45 +02:00
Dag-Erling Smørgrav
8b9a7766da Remove incorrect CRYB_USED annotations. 2017-04-06 19:51:45 +02:00
Dag-Erling Smørgrav
3917a6dfd7 Annotate t_add_test() as printf()-like and fix the fallout. 2017-03-14 15:07:02 +01:00
Dag-Erling Smørgrav
52cf1f9d3c Rename t_verbose*() to t_printv*().
Not only is this a slightly more logical name, but it allows us to expose the verbose flag, previously private to cryb_t_main.c, as the equally logically named t_verbose.
2017-03-14 14:36:52 +01:00
Dag-Erling Smørgrav
9bf06c258c Improve tests for sloppy padding in encoded input. 2017-03-05 17:18:30 +01:00
Dag-Erling Smørgrav
f70dac496f Mechanically bump copyright dates to the date of the latest commit. 2017-02-19 20:07:43 +01:00
Dag-Erling Smørgrav
9414c8b8f1 Disable coverage analysis of the C++ test. 2017-02-19 17:33:42 +01:00
Dag-Erling Smørgrav
01ffa275ad Increase test coverage for cryb_mpi_add_abs(). 2017-02-19 17:29:07 +01:00
Dag-Erling Smørgrav
894cc207b9 Additional tests for cryb_mpi_{add,sub}_abs().
These tests reveal that both functions assume that the target is initially positive zero if it is not identical with one of the operands, and fail in various ways if it is not, or if it is uninitialized.
2017-02-19 17:11:02 +01:00
Dag-Erling Smørgrav
ae7f1e909e Rework t_compare_mpi() to improve diagnostics. 2017-02-19 14:38:24 +01:00
Dag-Erling Smørgrav
912ba9b6ff Add a test that ensures that our headers are compilable in C++. 2017-01-24 15:08:48 +01:00
Dag-Erling Smørgrav
cf28ec163b All our tests are in the test directory. 2017-01-23 11:34:42 +01:00
Dag-Erling Smørgrav
642b34411c Alphabetize. 2016-11-21 14:02:05 +01:00
Dag-Erling Smørgrav
50fbf04eb4 Add version tests for libcryb-oath and libcryb-rand. 2016-11-21 13:52:19 +01:00
Dag-Erling Smørgrav
2d507aaee4 Implement our own assert() and, more importantly, assertf(). 2016-11-14 13:00:51 +01:00
Dag-Erling Smørgrav
856571a06d Implement a soft assert for unit tests.
Unlike assert(3), which uses abort(3), this has no other side effects (before raising SIGABRT) than an fprintf() call.  The test framework will catch the SIGABRT, report that the test case failed, and proceed with the next case.
2016-11-14 13:00:16 +01:00
Dag-Erling Smørgrav
d8e26bc5bb Solve further asprintf() issues by sweeping them under the rug.
All further instances of asprintf() or vasprintf() in our codebase are either in libcryb-test or in individual unit tests, and in all cases, the only consequence of a failed call is that the result will say "no description" instead of either a description of the test or an explanation of how it failed.  Therefore, we can simply ignore the problem and cast the call to void to satisfy gcc.
2016-09-18 22:40:48 +02:00
Dag-Erling Smørgrav
d0236914f7 Add test cases for the new string functions. 2016-09-17 23:32:11 +02:00
Dag-Erling Smørgrav
dc43296a47 Centralize most of .gitignore. 2016-09-17 21:38:54 +02:00
Dag-Erling Smørgrav
9c1988fa17 Add missing third clause to new files. 2016-09-17 16:22:19 +02:00
Dag-Erling Smørgrav
a36c6ba31c Add tests for each library's cryb_foo_version() function.
This may seem stupid, but I've found bugs in the past which would have been caught by unit tests which I didn't write because they seemed stupid.
2016-09-17 16:14:00 +02:00
Dag-Erling Smørgrav
e78c0f811b Remove unneeded #includes. 2016-09-17 16:05:31 +02:00
Dag-Erling Smørgrav
d9b6740247 Implement the full range of BSD endianness conversion functions. 2016-09-15 11:18:01 +02:00
Dag-Erling Smørgrav
e276f2b407 Ensure that we always have off_t and ssize_t in scope.
POSIX requires <stdio.h> and <unistd.h> to define off_t and ssize_t like <sys/types.h> does, but not all platforms respect that.  Play it safe by always including <sys/types.h>.
2016-09-15 10:15:00 +02:00
Dag-Erling Smørgrav
8d7b6439ae Fix signed / unsigned mismatch. 2016-09-05 15:46:29 +02:00
Dag-Erling Smørgrav
401465d8ea Move main() from libcryb-test to the test program.
Instead of having libcryb-test provide main() and assume that the test program defines t_prepare() and t_cleanup(), have libcryb-test provide a t_main() function which the test program calls with pointers to its prepare and cleanup functions.
2016-03-15 14:29:44 +01:00
Dag-Erling Smørgrav
476374323d Vastly improve unit tests for percent-encoding API. 2016-01-10 23:28:04 +01:00
Dag-Erling Smørgrav
f9c8ce7c65 Build system overhaul 2015-12-14 18:08:22 +01:00
Dag-Erling Smørgrav
0995671d43 Don't rely on side effects between sequence points 2015-12-14 17:49:49 +01:00
Dag-Erling Smørgrav
4d7893004c Prepare for moving to Github 2015-12-14 15:55:38 +01:00
Dag-Erling Smørgrav
3e88a08c10 Clean up a bit and add more test cases, including comprehensive tests for
string_append_{cs,string}().
2015-10-13 21:44:37 +00:00
Dag-Erling Smørgrav
4fa82f7c7b Simplify existing tests:
- Set t_malloc_fatal so we don't have to check for allocation failures
  (the driver will catch the SIGABRT).
- Use string_dup_cs() instead of string_new() + string_append_cs().
2015-10-13 20:22:07 +00:00
Dag-Erling Smørgrav
454603d4f1 Add <unistd.h> to more files. FreeBSD's namespace pollution hides these
errors.
2015-10-12 11:45:26 +00:00
Dag-Erling Smørgrav
e6049c1d6a Add string_len() (return length of string) and string_dup_cs() (create a
string from a null-terminated string).  Add test for string_trunc().
2015-10-12 10:23:24 +00:00
Dag-Erling Smørgrav
f8ebdbc14d Move the test framework into its own subdirectory 2015-10-04 07:49:48 +00:00
Dag-Erling Smørgrav
cf02f33af7 Implement the full range of test vectors from RFC 6229. 2015-10-04 07:08:36 +00:00
Dag-Erling Smørgrav
ed9403627f Add more AES test vectors 2015-10-03 15:13:17 +00:00
Dag-Erling Smørgrav
a9e733f0ca Use an enum for encrypt / decrypt + minor cleanup 2015-10-03 14:43:33 +00:00
Dag-Erling Smørgrav
dd18cd2995 Kick off libcryb-cipher with AES (from XySSL) and RC4 (my own). 2015-10-03 14:24:59 +00:00
Dag-Erling Smørgrav
9042130830 Fix ossifrage underflow error in Adler32 unit test 2015-10-03 14:20:07 +00:00
Dag-Erling Smørgrav
17ccbb2f76 rm leftover code from a copypasto 2015-08-28 10:44:30 +00:00
Dag-Erling Smørgrav
0961e4b2e0 Rewrite unit tests for the Fletcher and Adler checksums to exercise
boundary conditions (low and high word overflow).
2015-08-28 08:38:49 +00:00
Dag-Erling Smørgrav
8351719b84 Simplify test cases by a) using C99 VLAs and b) removing error checks for
allocation failures which are either harmless (e.g. failing to allocate
the test description string) or will trigger a segfault which the driver
now catches, allowing subequent test cases to run.
2015-08-19 11:27:48 +00:00
Dag-Erling Smørgrav
cbc2cd1112 If a test case triggers one of a list of signals (including SIGABRT and
SIGSEGV), eat it and fail the test.  Also print a summary in verbose mode.
2015-08-19 11:17:06 +00:00
Dag-Erling Smørgrav
5e1e20c624 Add marginally useful test cases based on t_zero. 2015-08-18 15:21:02 +00:00
Dag-Erling Smørgrav
d670e3e94d Increase the sizeo of t_zero to 4096 bytes. 2015-08-18 15:14:11 +00:00
Dag-Erling Smørgrav
531eeec36b Add a simple implementation of the Adler-32 checksum. 2015-08-18 13:27:06 +00:00
Dag-Erling Smørgrav
20cd7d6012 Add 16-bit endian conversion functions. 2015-08-17 15:37:07 +00:00
Dag-Erling Smørgrav
aa97da3335 Add simple implementations of Fletcher's checksum. 2015-08-17 15:21:47 +00:00
Dag-Erling Smørgrav
dc75f2edd8 Add a memset_s() implementation (cf. C11 / WG14 N1381) 2015-02-15 09:18:18 +00:00
Dag-Erling Smørgrav
cddb6c0e02 Rewrite the zero shortcut tests to avoid dropping a const qualifier. 2014-12-30 20:03:58 +00:00
Dag-Erling Smørgrav
3904e809b2 Add two test cases for shortcut logic used when one operand is zero and
the other is also the target.
2014-12-30 19:57:07 +00:00
Dag-Erling Smørgrav
241f524238 Fix a bogus t_malloc_fail in one of the mpi_add_abs() tests.
Add several subtraction test cases and modify some others to better
exercise the carry logic, which is far more complex for subtraction than
for addition.

Add test cases where the target is the same MPI as one or both operands.
2014-12-30 19:48:57 +00:00
Dag-Erling Smørgrav
8d0e24dee7 Remove the "trailing garbage" version of the mpi_cmp() test. It would
be better to systematically pad MPIs used in all tests with garbage.

Greatly expand the number of mpi_cmp() tests to cover all possible
combinations of same or different sign, same or different msb and same
or different magnitude.
2014-12-30 17:00:56 +00:00
Dag-Erling Smørgrav
f18b915b67 Fix the "x = a + b" allocation failure test. Since a and b were
equal, mpi_sub_abs() would return early and the test would never
exercise the mpi_grow() call which is intended to fail.
2014-12-30 16:46:44 +00:00
Dag-Erling Smørgrav
2027ce33e7 Add tests for the off-by-one bug we just fixed in mpi_cmp_abs(). 2014-12-30 16:38:47 +00:00
Dag-Erling Smørgrav
e21452d0c7 Add a few tests for subtraction. They're not particularly well thought
out, because currently subtraction does not work at all, but they work
well enough in the sense that they fail with the current implementation.
2014-12-30 11:19:02 +00:00
Dag-Erling Smørgrav
b6368af502 Re-add $(RT_LIBS) where needed. 2014-12-29 23:56:22 +00:00
Dag-Erling Smørgrav
03867777c6 Add numerous tests, mostly for allocation failures and edge conditions.
Add a t_compare_mpi() predicate which checks that two MPIs have the same
value (but not necessarily the exact same representation).
Clean up and improve existing tests.
2014-12-29 23:54:02 +00:00
Dag-Erling Smørgrav
7b6b493509 Declare t_malloc_fail_after. 2014-12-29 23:49:50 +00:00
Dag-Erling Smørgrav
3ec87c7a8c Introduce t_malloc_fail_after: if non-zero, it serves as a countdown to
setting t_malloc_fail.  Also, enforce t_malloc_fail in realloc(), but not
before checking that the argument was valid.
2014-12-29 23:49:29 +00:00
Dag-Erling Smørgrav
b2ec312d9f Link each test with only the libraries it needs. This avoids rebuilding
every single test whenever any of the libraries changes.
2014-12-29 22:17:02 +00:00
Dag-Erling Smørgrav
85defb9929 Fix a cast that discards a const qualifier. 2014-12-29 15:23:52 +00:00
Dag-Erling Smørgrav
7a09b0638f I had forgotten that t_add_test() is actually a printf()-like variadic
function, which obviates the need for asprintf() in the string comparison
and equality tests.
2014-12-29 14:24:08 +00:00
Dag-Erling Smørgrav
3333bd5709 Add test cases for the static inline functions in <cryb/endian.h>. 2014-12-29 14:20:28 +00:00
Dag-Erling Smørgrav
0dae3b2417 Test string_equal() using the same test cases as for string_compare().
Improve test case descriptions.
2014-12-29 13:36:06 +00:00
Dag-Erling Smørgrav
e20e76a3f7 Recognize "on" and "off". 2014-12-29 13:25:44 +00:00
Dag-Erling Smørgrav
82e32027af Move the decision of whether to check for memory leaks from the malloc()
code to the driver and allow an environment variable to override the
default (on unless coverage is enabled).
2014-12-29 13:24:44 +00:00
Dag-Erling Smørgrav
56eccb99fe Add two utility functions which check if a string contains something that
can be interpreted as either true or false.  Use this instead of a basic
non-NULL test for the CRYB_PERFTEST check.
2014-12-29 13:22:53 +00:00
Dag-Erling Smørgrav
559f6c24f7 Fix off-by-one error in TAP output: the test case number was being
incremented (converted from zero-based to one-based) twice.
2014-12-29 13:03:08 +00:00
Dag-Erling Smørgrav
eb10ce6d05 If the test case changes desc, it *must* point to an allocated buffer
which the driver will free after printing the result.
2014-12-29 12:56:35 +00:00
Dag-Erling Smørgrav
2ad45cfccf Add a string comparison function and a string equality predicate.
Write test cases for the former.
2014-12-29 12:41:39 +00:00
Dag-Erling Smørgrav
eadeeb486c Skip memory leak checks if coverage analysis is enabled. 2014-12-20 01:30:01 +00:00
Dag-Erling Smørgrav
6ed802ddf3 Consistently use #if HAVE_FOO instead of #ifdef HAVE_FOO. The reason is
that AC_CHECK_DECLS([foo]), unlike AC_CHECK_FUNCS([foo]), will always
define HAVE_FOO, so #ifdef HAVE_FOO will always be true even if it is 0.
This commit finally fixes the [bl]e{32,64}{enc,dec} issue on Linux.
2014-12-20 00:38:54 +00:00
Dag-Erling Smørgrav
20dab3e342 Provisionally include strlcmp(), although it is not (currently) used
anywhere.  Opinion is divided as to whether this is useful, or whether
its usefulness is outweighed by its awkwardness.  Still, we have it, so
we may as well commit it.
2014-12-20 00:23:59 +00:00
Dag-Erling Smørgrav
a587a25d45 Ignore free(NULL) instead of treating it the same as free(malloc(0)). 2014-10-30 16:35:54 +00:00
Dag-Erling Smørgrav
1f0fd8d9fe Create an additional test case which always runs after cleanup and checks
for memory leaks.  It may be necessary to make this optional at some point,
but for now, none of our tests leak memory.
2014-10-30 16:31:03 +00:00
Dag-Erling Smørgrav
14c64ec3a5 Improved checks for <sys/ktrace.h>. 2014-10-30 13:07:16 +00:00
Dag-Erling Smørgrav
37973b8705 Use CLOCK_MONOTONIC instead of the non-standard CLOCK_MONOTONIC_PRECISE.
Use librt if required for clock_gettime(2).
2014-10-30 12:56:47 +00:00
Dag-Erling Smørgrav
1b84de1d0f Add <sys/types.h> for size_t / ssize_t which <cryb/wstring.h> uses. 2014-10-30 12:52:00 +00:00
Dag-Erling Smørgrav
97e702145d Add <stdint.h> for the {,u}int*_t types. 2014-10-30 12:51:03 +00:00
Dag-Erling Smørgrav
e9bb48d9c8 Add <sys/types.h> for size_t / ssize_t which <cryb/string.h> uses. 2014-10-30 12:50:09 +00:00
Dag-Erling Smørgrav
1fbf2cf156 It appears that gcc does not accept partial struct initialization. Add
a CRYB_MPI_ZERO macro that expands to an all-zeroes initializer.
2014-10-30 12:46:01 +00:00
Dag-Erling Smørgrav
46beb1adcb Various fixes for Linux and gcc portability. 2014-10-30 12:14:05 +00:00
Dag-Erling Smørgrav
bd69c34a11 Emit jemalloc-compatible trace events if possible. 2014-10-30 12:05:08 +00:00
Dag-Erling Smørgrav
277201a4bb Before we exit, explicitly call t_fcloseall() and make stdout
unbuffered to reduce noise in the malloc() statistics.
2014-10-30 12:04:29 +00:00
Dag-Erling Smørgrav
bf087fd70e Gather memory allocation statistics and print them at the end if verbose. 2014-10-30 11:05:01 +00:00
Dag-Erling Smørgrav
4a4726f9d6 Compare the result of mmap() to MAP_FAILED, not NULL. 2014-10-18 22:01:08 +00:00
Dag-Erling Smørgrav
3be915b8d7 Previous commit was incomplete. Add missing prototypes and a test case. 2014-08-14 18:42:52 +00:00
Dag-Erling Smørgrav
885c586ce9 Add a test function for comparison operators (but no test cases yet).
Consistently destroy MPIs after use.
2014-08-14 18:26:06 +00:00
Dag-Erling Smørgrav
be31515f5e Start of a multiple-precision integer arithmetic library. 2014-08-12 07:30:31 +00:00
Dag-Erling Smørgrav
64a2da2b84 Refactor the malloc() etc code to reduce code duplication.
Introduce a t_malloc_fatal flag that makes unintentional allocation
failures fatal.  This reduces the need for error handling in tests.

Enable that flag in t_main().  Test programs that don't want it can
override it in t_prepare().
2014-08-03 00:58:13 +00:00
Dag-Erling Smørgrav
5875ade2ed Add a pointer comparison function. 2014-08-02 23:54:58 +00:00
Dag-Erling Smørgrav
ce567a72e0 Add a simple malloc() implementation which can be configured to fail
when testing error handling code.
2014-08-02 23:30:07 +00:00
Dag-Erling Smørgrav
3f982ecff7 Improve format strings. 2014-08-02 23:26:58 +00:00
Dag-Erling Smørgrav
25ff8b9664 Print hex strings in groups of eight. 2014-08-02 23:26:20 +00:00
Dag-Erling Smørgrav
33cb3dad6a Remove <stdio.h> from code that doesn't need it. 2014-08-02 23:23:19 +00:00
Dag-Erling Smørgrav
479ffbba4a Remove author and sponsor tags; we'll deal with that some other way.
Remove $Cryb$ tags as it is likely that the code will move to git.
2014-08-01 14:31:07 +00:00
Dag-Erling Smørgrav
cc8109c760 WIP: unit tests for managed strings. 2014-08-01 13:55:01 +00:00