https://tools.ietf.org/html/rfc5034 This could be implemented using libgsasl (my preference), or cyrus-sasl.