Factor out calculation of derived key