using constant time implementation made by CodesInChaos

unfortunately it is unsafe code