Parashas Eikev · Passuk 8:3
[God] subjected you to the hardship of hunger and then gave you manna to eat, which neither you nor your ancestors had ever known, in order to teach you that a human being does not live on bread alone, but that one may live on anything that GOD decrees.
Torah Temimah points to Sanhedrin 99a.
TT lemma: ויענך.
English: It was taught: R’ Eliezer says: Here it is written “He afflicted you and starved you,” and there “Gladden us according to the days You afflicted us, the years we saw evil.” From here [we learn] that the days of the Messiah are forty years.
Custom (Gezeirah shavah / Messianic duration)
The affliction of the wilderness becomes the measure for the length of the Messianic preparatory period: forty years.