/* This function hash a formatted string with MD5 and format the result as ascii characters.  */
static int md5_printf(char *md, const char *fmt,...)
/* This function hash a formatted string with MD5 and format the result as ascii characters.  */
static int md5_printf(char *md, const char *fmt,...)
{
    unsigned char *buf;
    unsigned char digest[MD5_MAX_LEN];
    int len, i;
    struct MD5Context md5_ctx;
    va_list ap;
    va_start(ap, fmt);
    len = vasprintf((char **)&buf, fmt, ap);
    if (buf == NULL) {
        return ESP_FAIL;
    }
    MD5Init(&md5_ctx);
    MD5Update(&md5_ctx, buf, len);
    MD5Final(digest, &md5_ctx);
    for (i = 0; i < 16; ++i) {
        sprintf(&md[i * 2], "%02x", (unsigned int)digest[i]);
    }
    va_end(ap);
    free(buf);
    return MD5_MAX_LEN;
}