Commit Graph
11188 Commits
Author SHA1 Message Date
Martin Willi bbfe7a80b1 string: Move string related utility functions to separate files 2015-04-16 14:49:19 +02:00
Martin Willi 03cf888277 byteorder: Move byte order related functions to separate header file 2015-04-16 14:49:19 +02:00
Martin Willi 95726f7617 types: Use generic type definitions to separate header file 2015-04-16 14:49:19 +02:00
Martin Willi 717313c542 atomics: Move atomics/recounting support to separate files 2015-04-16 14:49:19 +02:00
Martin Willi 31a171f5c4 unit-tests: Further increase the test vector testing timeout
Some build bots running make check seem to have longer for the DH testing.
2015-04-16 10:15:13 +02:00
Martin Willi 7d1ffe013d test-vectors: Define test vector symbols as extern
We don't actually define a vector, but only prototype the test vector
implemented in a different file. GCC uses the correct symbol during testing,
but clang correctly complains about duplicated symbols during linking.
2015-04-16 09:38:14 +02:00
Tobias Brunner d1e7b31e80 Fix years in some copyright statements 2015-04-16 09:21:00 +02:00
Martin Willi 23947b2a4f aesni: Fix doxygen groups 2015-04-15 17:29:56 +02:00
Martin Willi 22458c18ff kernel-netlink: Don't mangle verbosity during test initialization
We now properly manage thread verbosity in the test framework, and don't need
to silence thread spawning messages.
2015-04-15 14:38:44 +02:00
Martin Willi 432d712048 unit-tests: Set test verbosity just after test suite loading
We see any plugin startup messages during suite configuration, where
initialization is called once to query plugin features. No need to be verbose
and show these messages once again in the first test.
2015-04-15 14:38:43 +02:00
Martin Willi 80469c2168 crypto-factory: Remove obsolete transform testing functions 2015-04-15 14:38:43 +02:00
Martin Willi e507c48e8d unit-tests: Use progressive testing of transforms with test vectors
This allows us to show which transform from which plugin failed. Also, we use
the new cleanup handler functionality that allows proper deinitialization on
failure or timeout.
2015-04-15 14:38:43 +02:00
Martin Willi 1d55e0756a transform: Add a getter for the enum_names for a specific transform type 2015-04-15 14:38:43 +02:00
Martin Willi de1c492a0f enum-names: Fail gracefully when passing a NULL value as enum names 2015-04-15 14:38:43 +02:00
Martin Willi e03fb1fb26 crypto-factory: Add enumerator method to support individual transform testing 2015-04-15 14:38:43 +02:00
Martin Willi 30003bc51a unit-tests: Invoke all registered thread cleanup handlers on test failure
If a test fails in a timeout or a test failure, longjmp() is used to restore
the thread context and handle test failure. However, there might be unreleased
resources, namely locks, which prevent the library to clean up properly after
finishing the test.

By using thread cleanup handlers, we can release any test subject internal or
test specific external resources on test failure. We do so by calling all
registered cleanup handlers.
2015-04-15 14:38:43 +02:00
Martin Willi d36b30803e thread: Add a function to pop and call all registered cleanup handlers 2015-04-15 14:38:43 +02:00
Martin Willi ef33f8e85d thread: Don't acquire lock for thread_cleanup_push/pop
This is called only by the thread for its own thread_t, and does not need
synchronization.
2015-04-15 14:38:42 +02:00
Martin Willi 13a5a906e9 gcrypt: Explicitly initialize RNG backend to allocate static data
The libgcrypt RNG implementation uses static buffer allocation which it does
not free. There is no symbol we can catch in leak-detective, hence we explicitly
initialize the RNG during the whitelisted gcrypt_plugin_create() function.
2015-04-15 14:38:42 +02:00
Martin Willi d72817491d leak-detective: Whitelist gcrypt_plugin_create()
gcry_check_version() does not free statically allocated resources. However,
we can't whitelist it in some versions, as it is not a resolvable symbol name.
Instead, whitelist our own plugin constructor function.
2015-04-15 14:38:42 +02:00
Martin Willi 162252aca9 unit-tests: Add a TESTS_PLUGINS environment variable
This is often more convenient than specifying plugins in a configuration file.
2015-04-15 14:38:42 +02:00
Martin Willi 26c215e818 unit-tests: Use a larger timeout for test vector testing
As we test DH calculations this now takes more time. If multiple DH backends
are enabled, we likely hit the default test timeout.
2015-04-15 14:38:42 +02:00
Martin Willi 41421b85a9 gcrypt: Support setting private value and testing of DH backend 2015-04-15 14:38:42 +02:00
Martin Willi 0778c027a7 openssl: Support setting ECDH private values 2015-04-15 14:38:42 +02:00
Martin Willi e77ca5c79d openssl: Support setting private Diffie-Hellman values 2015-04-15 14:38:42 +02:00
Martin Willi 1a522d327e gmp: Support setting Diffie-Hellman private values 2015-04-15 14:38:41 +02:00
Martin Willi b8f576a803 test-vectors: Add DH vectors for Brainpool groups 2015-04-15 14:38:41 +02:00
Martin Willi 8b070b1b36 test-vectors: Add DH vectors for ECDH groups 2015-04-15 14:38:41 +02:00
Martin Willi 57f1ef220c test-vectors: Add DH vectors for subgroup MODP groups 2015-04-15 14:38:41 +02:00
Martin Willi e62906524c test-vectors: Add DH vectors for normal MODP groups 2015-04-15 14:38:39 +02:00
Martin Willi 79955b2b99 test-vectors: Support testing DH groups 2015-04-15 14:37:38 +02:00
Martin Willi a94955e88a crypto-tester: Support testing DH groups using DH test vectors 2015-04-15 14:37:38 +02:00
Martin Willi 3941545fb9 diffie-hellman: Introduce an optional setter for the private value
This allows us to work with deterministic values for testing purposes.
2015-04-15 14:37:38 +02:00
Martin Willi 37794878cc aesni: Avoid loading AES/GHASH round keys into local variables
The performance impact is not measurable, as the compiler loads these variables
in xmm registers in unrolled loops anyway.

However, we avoid loading these sensitive keys onto the stack. This happens for
larger key schedules, where the register count is insufficient. If that key
material is not on the stack, we can avoid to wipe it explicitly after
crypto operations.
2015-04-15 13:44:40 +02:00
Martin Willi 93f0080265 aesni: Align all class instances to 16 byte boundaries
While the required members are aligned in the struct as required, on 32-bit
platforms the allocator aligns the structures itself to 8 bytes only. This
results in non-aligned struct members, and invalid memory accesses.
2015-04-15 13:44:40 +02:00
Martin Willi 0c83225883 utils: Provide aligning variants of INIT/INIT_EXTRA macros 2015-04-15 13:44:40 +02:00
Martin Willi 2b40c9646c unit-tests: Pass stringyfied assertion statement as non-format string argument
If the assertion contains a modulo (%) operation, test_fail_msg() handles
this as printf() format specifier. Pass the assertion string as argument for
an explicit "%s" in the format string, instead.
2015-04-15 13:44:40 +02:00
Martin Willi f206bb7444 utils: Add malloc/free wrappers returning aligned data
While we could use posix_memalign(3), that is not fully portable. Further, it
might be difficult on some platforms to properly catch it in leak-detective,
which results in invalid free()s when releasing such memory.

We instead use a simple wrapper, which allocates larger data, and saves the
padding size in the allocated header. This requires that memory is released
using a dedicated function.

To reduce the risk of invalid free() when working on corrupted data, we fill up
all the padding with the padding length, and verify it during free_align().
2015-04-15 13:44:40 +02:00
Martin Willi edab6c658c aesni: Calculate GHASH for 4 blocks of associated data in parallel
While associated data is usually not that large, in some specific cases
this can bring a significant performance boost.
2015-04-15 11:35:28 +02:00
Martin Willi 0eb593b0bb aesni: Calculate GHASH for 4 blocks of encryption data in parallel
Increases performance by another ~30%.
2015-04-15 11:35:28 +02:00
Martin Willi 58c44cdd00 aesni: Use 4-way parallel en/decryption in GCM
Increases overall performance by ~25%.
2015-04-15 11:35:28 +02:00
Martin Willi 677649cfb5 aesni: Use dedicated key size specific en-/decryption functions in GCM
This gives not much more than ~5% increase in performance, but allows us to
improve further.
2015-04-15 11:35:28 +02:00
Martin Willi 313811b72d aesni: Add a GCM AEAD based on the AES-NI key schedule 2015-04-15 11:35:28 +02:00
Martin Willi 4284660677 aesni: Implement CMAC mode to provide a signer/prf
Compared to the cmac plugin using AESNI-CBC as backend, this improves
performance of AES-CMAC by ~45%.
2015-04-15 11:35:28 +02:00
Martin Willi 9d187f8711 aesni: Implement XCBC mode to provide a signer/prf
Compared to the xcbc plugin using AESNI-CBC as backend, this improves
performance of AES-XCBC by ~45%.
2015-04-15 11:35:28 +02:00
Martin Willi d48642b7eb aesni: Partially use separate code paths for different key sizes in CCM
Due to the serial nature of the CBC mac, this brings only a marginal speedup.
2015-04-15 11:35:28 +02:00
Martin Willi 1ae46dfba2 aesni: Add a CCM AEAD reusing the key schedule 2015-04-15 11:35:27 +02:00
Martin Willi 8488dea2f9 aesni: Use 4-way parallel AES-NI instructions for CTR en/decryption
CTR can be parallelized, and we do so by queueing instructions to the processor
pipeline. While we have enough registers for 128-bit decryption, the register
count is insufficient to hold all variables with larger key sizes. Nonetheless
is 4-way parallelism faster, depending on key size between ~10% and ~25%.
2015-04-15 11:35:27 +02:00
Martin Willi 9e47c1fe77 aesni: Use dedicated round count specific encryption functions in CTR mode
This allows us to unroll loops and hold the key schedule in local (register)
variables. This brings an impressive speedup of ~45%.
2015-04-15 11:35:27 +02:00
Martin Willi 74d43cbde9 aesni: Implement a AES-NI based CTR crypter using the key schedule 2015-04-15 11:35:27 +02:00