The paper reports the results on first-principles investigation of energy band spectrum and optical properties of bulk and nanoporous silicon. We present the evolution of energy band-gap, refractive indices and extinction coefficients going from the bulk Si of cubic symmetry to porous Si with periodically ordered square-shaped pores of 7.34, 11.26 and 15.40 Å width. We consider two natural processes observed in practice, the hydroxylation of Si pores (introduction of OH groups into pores) and the penetration of water molecules into Si pores, as well as their impact on the electronic spectrum and optical properties of Si superstructures. The penetration of OH groups into the pores of the smallest 7.34 Å width causes a disintegration of hydroxyl groups and forms non-bonded protons which might be a reason for proton conductivity of porous Si. The porosity of silicon increases the extinction coefficient, k, in the visible range of the spectrum. The water structuring in pores of various diameters is analysed in detail. By using the bond valence sum approach we demonstrate that the types and geometry of most of hydrogen bonds created within the pores manifest a structural evolution from distorted hydrogen bonds inherent to small pores (∼7 Å) to typical hydrogen bonds observed by us in larger pores (∼15 Å) which are consistent with those observed in a wide database of inorganic crystals.