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