We study in detail the mechanism of baryon and lepton asymmetry generation in the framework of the νMSM (an extension of the Standard Model by three singlet fermions with masses smaller than the electroweak scale). We elucidate the issue of CP-violation in the model and define the phase relevant for baryogenesis. We clarify the question of quantum-mechanical coherence, essential for the lepton asymmetry generation in singlet fermion oscillations and compute the relevant damping rates. The range of masses and couplings of singlet leptons which can lead to successful baryogenesis is determined. The conditions which ensure survival of primordial (existing above the electroweak temperatures) asymmetries in different leptonic numbers are analysed. We address the question whether CP-violating reactions with lepton number non-conservation can produce leptonic asymmetry below the sphaleron freeze-out temperature. This asymmetry, if created, leads to resonant production of dark matter sterile neutrinos. We show that the requirement that a significant lepton asymmetry be produced puts stringent constraints on the properties of a pair of nearly degenerate singlet fermions, which can be tested in accelerator experiments. In this region of parameters the νMSM provides a common mechanism for production of baryonic matter and dark matter in the universe. We analyse different fine-tunings of the model and discuss possible symmetries of the νMSM Lagrangian that can lead to them.