You can fit any EJ engine into the Legacy.
If you do a WRX or STI swap, there is a lot of work involved. You will have to to engine, trans, and rear diff. There is also a TON of wiring that needs to be done. The only other part is you have to use the WRX subframe.
About $10grand for the entire project