void hls_rand_bytes(void *buf, size_t len)
{
    static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
    static uint64_t counter = 0;

    uint64_t stamp = NTPtime64 ();
    //TRACE();
    while (len > 0)
    {
        uint64_t val;
        
#if defined(HAVE_ANDROID_OS)
        uint8_t hash[16];

        MD5_CTX mdi,mdo;
        MD5_Init(&mdi);
        MD5_Init(&mdo);

        pthread_mutex_lock (&lock);
        if (counter == 0)
            hls_rand_init ();
        val = counter++;
        
        MD5_Update(&mdi, ikey, sizeof (ikey));
        MD5_Update(&mdo, okey, sizeof (okey));
        pthread_mutex_unlock (&lock);

        
        MD5_Update (&mdi, &stamp, sizeof (stamp));
        MD5_Update (&mdi, &val, sizeof (val));
        MD5_Final(hash,&mdi);
        
        MD5_Update(&mdo,hash, 16);
        MD5_Final(hash,&mdo);

        if (len < 16)
        {
            memcpy (buf,hash,len);
            break;
        }

        memcpy (buf,hash, 16);
        len -= 16;
        buf = ((uint8_t *)buf) + 16;  
        //TRACE();        
            
#endif        

    }
}
Exemple #2
0
void vlc_rand_bytes (void *buf, size_t len)
{
    static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
    static uint64_t counter = 0;

    uint64_t stamp = NTPtime64 ();

    while (len > 0)
    {
        uint64_t val;
        struct md5_s mdi, mdo;

        InitMD5 (&mdi);
        InitMD5 (&mdo);

        pthread_mutex_lock (&lock);
        if (counter == 0)
            vlc_rand_init ();
        val = counter++;

        AddMD5 (&mdi, ikey, sizeof (ikey));
        AddMD5 (&mdo, okey, sizeof (okey));
        pthread_mutex_unlock (&lock);

        AddMD5 (&mdi, &stamp, sizeof (stamp));
        AddMD5 (&mdi, &val, sizeof (val));
        EndMD5 (&mdi);
        AddMD5 (&mdo, mdi.p_digest, sizeof (mdi.p_digest));
        EndMD5 (&mdo);

        if (len < sizeof (mdo.p_digest))
        {
            memcpy (buf, mdo.p_digest, len);
            break;
        }

        memcpy (buf, mdo.p_digest, sizeof (mdo.p_digest));
        len -= sizeof (mdo.p_digest);
        buf = ((uint8_t *)buf) + sizeof (mdo.p_digest);
    }
}
Exemple #3
0
static
char *sdp_Start (const char *name, const char *description, const char *url,
                 const char *email, const char *phone,
                 const struct sockaddr *src, size_t srclen,
                 const struct sockaddr *addr, size_t addrlen)
{
    uint64_t now = NTPtime64 ();
    char *sdp;
    char connection[MAXSDPADDRESS], hostname[256],
         sfilter[MAXSDPADDRESS + sizeof ("\r\na=source-filter: incl * ")];
    const char *preurl = "\r\nu=", *premail = "\r\ne=", *prephone = "\r\np=";

    gethostname (hostname, sizeof (hostname));

    if (name == NULL)
        name = "Unnamed";
    if (description == NULL)
        description = "N/A";
    if (url == NULL)
        preurl = url = "";
    if (email == NULL)
        premail = email = "";
    if (phone == NULL)
        prephone = phone = "";

    if (!IsSDPString (name) || !IsSDPString (description)
     || !IsSDPString (url) || !IsSDPString (email) || !IsSDPString (phone)
     || (AddressToSDP (addr, addrlen, connection) == NULL))
        return NULL;

    strcpy (sfilter, "");
    if (srclen > 0)
    {
        char machine[MAXSDPADDRESS];

        if (AddressToSDP (src, srclen, machine) != NULL)
            sprintf (sfilter, "\r\na=source-filter: incl IN IP%c * %s",
                     machine[5], machine + 7);
    }

    if (asprintf (&sdp, "v=0"
                    "\r\no=- %"PRIu64" %"PRIu64" IN IP%c %s"
                    "\r\ns=%s"
                    "\r\ni=%s"
                    "%s%s" // optional URL
                    "%s%s" // optional email
                    "%s%s" // optional phone number
                    "\r\nc=%s"
                        // bandwidth not specified
                    "\r\nt=0 0" // one dummy time span
                        // no repeating
                        // no time zone adjustment (silly idea anyway)
                        // no encryption key (deprecated)
                    "\r\na=tool:"PACKAGE_STRING
                    "\r\na=recvonly"
                    "\r\na=type:broadcast"
                    "\r\na=charset:UTF-8"
                    "%s" // optional source filter
                    "\r\n",
               /* o= */ now, now, connection[5], hostname,
               /* s= */ name,
               /* i= */ description,
               /* u= */ preurl, url,
               /* e= */ premail, email,
               /* p= */ prephone, phone,
               /* c= */ connection,
    /* source-filter */ sfilter) == -1)
        return NULL;
    return sdp;
}