MD5 digest compatibility tests, small fixes and refactoring

Tests and fixes from last week, moved from my wildfly-sasl repository.