[PATCH v6 13/28] public_key: move common functions to public key helper