I won't claim to know the exact law...
But I believe that the police have the authority to ask you for ID at any time. They may, or may not have the legal right to stop you, I don't know. IT goes back to some old laws covering
vagrancy.
Its not much enforced today, but there are still many places in the country where you can be required to show ID, (showing residence), and be able to prove you are not broke (have some money), or you could be arrested. Those laws are still on the books.
Local cops are most likely to be the ones asking. If you are not someone they usually see in the area, and do something to stand out visually, they might take an interest. I was stopped and asked for ID by a town cop some 30 years ago (ok, maybe not really relevant), just walking down the street to the post office, in a town I had moved into just a couple months before. He asked for ID, which I produced, and in conversation told me about the vagrancy statutes. I admit, I was rather scruffy looking at the time.
If you are carrying openly, in a public place, expect the police to check you out. Its not a violation of our rights, to set their minds at ease. As long as things are polite, and you are not detained, or restrained in any way.
With several officers murdered in recent memory, I, for one, would gladly let them know I'm no threat, just exercising my rights.