Look at these slides for reference: https://www.iacr.org/workshops/ches/ches2002/presentations/Tkacik.pdf Should implement this both in software and in hardware.