Direct quotes from the link provided by Pat.
Entire engines can be replacement parts. As with any other replacement part, the engine must be identical to the original. If the replacement block or engine is obtained without emissions equipment, all the equipment from the original engine must be installed on the replacement block.
If the engine is not identical to the original then it is not a replacement part, instead it is considered an engine change.
Engine changes are a modification that must meet certain requirements to be legal (please see "Engine Changes").
"Engine Changes "
Engine changes are legal as long as the following requirements are met to ensure that the change does not increase pollution from the vehicle:
The engine must be the same year or newer than the vehicle.
The engine must be from the same type of vehicle (passenger car, light-duty truck, heavy-duty truck, etc.) based on gross vehicle weight.
If the vehicle is a California certified vehicle then the engine must also be a California certified engine.
All emissions control equipment must remain on the installed engine.
Vehicles converted to 100% electric drive, with all power supplied by on-board batteries are considered in compliance with the engine change requirements. All fuel system components must be removed prior to inspection. For additional information contact the ARB helpline at (800) 242-4450
After an engine change, vehicles must first be inspected by a state referee station. The vehicle will be inspected to ensure that all the equipment required is in place, and vehicle will be emissions tested subject to the specifications of the installed engine.
Seems to me a K swap would be legit. Time for me to do some shopping