The generation of hard X-rays and relativistic protons observed during solar flares