Shouldn't this be g**priv_key % p ?