MD5 digest compatibility tests, small fixes and refactoring

Tests and fixes from last week, moved from jboss-sasl.