Let's say I have a position where white is to move, and I need white's legal moves. Is there any way where it is not necessary to generate black's legal moves? You only need black's moves for white's king moves, and it would greatly improve efficiency if you could somehow use black's moves from last turn instead of generating all of black's legal moves?
Yes and no.
In many board positions it is possible, but you will need to check a number of additional moves to verify if a King move is legal. You could essentially treat each square that the king could move to like a Queen and a Knight and then see if any enemy pieces can be found on those squares. Then you could check what kind of piece it is to determine if that move would put the King in check. That would prevent you from needing to generate legal moves for the opponent, however that might be very tricky for things like en passant.