[lib] remove duplicated code in rsa.c

    - remove duplicated code
    - better code style
Merge pull request #698 from Chilledheart/remove_duplcated_code

[lib] remove duplicated code in rsa.c