Yes, it's legal, provided that the barrel is not less than 18" in length. (I normally advise going for 18½", so as to leave room for error if the crown is damaged and the barrel needs to be re-crowned.) One normally measures barrel length to include the chamber. Close the action, drop a wooden dowel down the barrel, and make a mark on the dowel at the end of the barrel. Withdraw the dowel, measure the distance between the "breech end" of the dowel and your end-of-barrel mark, and the result is the length of the barrel.