Specification and Analysis of Security Protocols by Rewriting