powermod: avoid overflows by using widemul [closes #3036]