Hydromagnetic dynamo in the cores of Uranus and Neptune