Fix possible unlock before lock in RSA

Backport of 1385a28 and 4d04cdc

see #257
3 files changed