Search for resonances and quantum black holes using dijet mass spectra in proton-proton collisions at sqrt(s) = 8 TeV