Virial masses of galactic haloes from galaxy–galaxy lensing: theoretical modelling and application to Sloan Digital Sky Survey data