[PATCH v5 12/27] public_key: move common functions to public key helper