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 (Tehillim 90) “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 — corresponding to the years of affliction in the wilderness. The work of the Messianic king (restoring David’s kingdom, the Temple, the ingathering, justice, and offerings) is thus read as spanning a period like the forty years of seeing evil in the midbar.
Custom (gezerah shavah / Messianic duration)
The affliction of the wilderness becomes the measure for the length of the Messianic preparatory period: forty years.