  We develop a formalism for the identification and accurate estimation of the
strength of structure formation shocks during cosmological smoothed particle
hydrodynamics simulations. Shocks not only play a decisive role for the
thermalization of gas in virialising structures but also for the acceleration
of relativistic cosmic rays (CRs) through diffusive shock acceleration. Our
formalism is applicable both to ordinary non-relativistic thermal gas, and to
plasmas composed of CRs and thermal gas. To this end, we derive an analytical
solution to the one-dimensional Riemann shock tube problem for a composite
plasma of CRs and thermal gas. We apply our methods to study the properties of
structure formation shocks in high-resolution hydrodynamic simulations of the
LCDM model. We find that most of the energy is dissipated in weak internal
shocks with Mach numbers M~2 which are predominantly central flow shocks or
merger shock waves traversing halo centres. Collapsed cosmological structures
are surrounded by external shocks with much higher Mach numbers up to M~1000,
but they play only a minor role in the energy balance of thermalization. We
show that after the epoch of cosmic reionisation the Mach number distribution
is significantly modified by an efficient suppression of strong external shock
waves due to the associated increase of the sound speed of the diffuse gas.
Invoking a model for CR acceleration in shock waves, we find that the average
strength of shock waves responsible for CR energy injection is higher than that
for shocks that dominate the thermalization of the gas. When combined with
radiative dissipation and star formation, our formalism can also be used to
study CR injection by supernova shocks, or to construct models for
shock-induced star formation in the interstellar medium. (abridged)
