Shem, Ham, and Japheth. Surely Japheth was the eldest? [Shem, however, is written] first because he was [more] righteous [than the others]; also because he was born circumcised, the Holy One, blessed be He, set His name particularly upon him; [other reasons for his priority are that] Abraham was to arise from him, he was the minister in the High Priesthood, and because the Temple would be built on his territory.
(Gen. Rab. 26.3; trans. Freedman)
The passage tries to explain Shem's priority given Japheth being elderly--I should wonder, however, given that Ham is the most accursed in the story, why his name comes second and not last? The reasons for Shem's priority: more righteous, he's pre-cut (and, therefore, God set His name on him), Abraham's ancestor, a high priest, and his future territory would have the temple. Two of these deal with covenant (pre-circumcised and Abraham), and three the temple/cult (Name, high priest, and temple). I say the name is related to the temple because of Deuteronomy, wherein the future temple is where God will cause his Name to dwell, and the fact that the Name--the tetragrammaton--was inscribed on the headdress of the high priest. To have God's name set on you is to represent God on earth to the people. He receives this name, however, because he comes pre-circumcised; thus, the covenantal and temple issues are causally connected. What does it mean, however, to be pre-circumcised, especially at this moment before circumcision was given to Abraham as a sign of the covenant? My guess would be chosen-ness; to be born circumcised pre-circumcision is to be especially chosen (chosen for God and chosen as God's representative). I don't know if the Rabbis speculated on angelic phalli, but if they thought of them in terms of Jubilees (a big if), this would make Shem like one of the angels.