Move hash impl to macro, add sha512