You cannot castle through check Casp, and your king must not pass
through a square that is controlled by opponents piece while castling
and no piece involved in the castle can have moved previously, even if
it has returned to the original square.
The biggest area of confusion re castling is whether or not your rook
can pass through a square controlled by an opponents piece when
castling. (This phenomenon often comes up during queen side
castles) Or can you castle when the rook in question is being attacked.
The answer to both of these is: yes you can.