refactored signing/verification, algorithm modularized