From Stateless to Stateful: Generic Authentication and Authenticated Encryption Constructions with Application to TLS