Port GMac implementation and tests from bc-java.