The techniques of optimal control are applied to a validated blood circulation model of cardiopulmonary resuscitation (CPR), consisting of a system of seven difference equations. In this system, the non-homogeneous forcing terms are chest and abdominal pressures acting as the 'controls'. We seek to maximize the blood flow, as measured by the pressure difference between the thoracic aorta and the right atrium. By applying optimal control methods, we characterize the optimal waveforms for external chest and abdominal compression during cardiac arrest and CPR in terms of the solutions of the circulation model and of the corresponding adjoint system. Numerical results are given for various scenarios. The optimal waveforms confirm the previously discovered positive effects of active decompression and interposed abdominal compression. These waveforms can be implemented with manual (Lifestick-like) and mechanical (vest-like) devices to achieve levels of blood flow substantially higher than those provided by standard CPR, a technique which, despite its long history, is far from optimal.