montgomery test implementation