Improve build system (including some compiler/linker flags from libsodium and Debian Hardening). Fix tests.