Example #1
0
static void sig_out(BIO* b)
{
    BIO_OK_CTX *ctx;
    EVP_MD_CTX *md;

    ctx=(BIO_OK_CTX *)b->ptr;
    md=&ctx->md;

    if(ctx->buf_len+ 2* md->digest->md_size > OK_BLOCK_SIZE) return;

    EVP_DigestInit_ex(md, md->digest, NULL);
    /* FIXME: there's absolutely no guarantee this makes any sense at all,
     * particularly now EVP_MD_CTX has been restructured.
     */
    RAND_pseudo_bytes((unsigned char*)md->md_data, md->digest->md_size);
    TINYCLR_SSL_MEMCPY(&(ctx->buf[ctx->buf_len]), md->md_data, md->digest->md_size);
    longswap(&(ctx->buf[ctx->buf_len]), md->digest->md_size);
    ctx->buf_len+= md->digest->md_size;

    EVP_DigestUpdate(md, WELLKNOWN, TINYCLR_SSL_STRLEN(WELLKNOWN));
    EVP_DigestFinal_ex(md, &(ctx->buf[ctx->buf_len]), NULL);
    ctx->buf_len+= md->digest->md_size;
    ctx->blockout= 1;
    ctx->sigio= 0;
}
Example #2
0
static int sig_out(BIO *b)
{
    BIO_OK_CTX *ctx;
    EVP_MD_CTX *md;

    ctx = b->ptr;
    md = &ctx->md;

    if (ctx->buf_len + 2 * md->digest->md_size > OK_BLOCK_SIZE)
        return 1;

    if (!EVP_DigestInit_ex(md, md->digest, NULL))
        goto berr;
    /*
     * FIXME: there's absolutely no guarantee this makes any sense at all,
     * particularly now EVP_MD_CTX has been restructured.
     */
    if (RAND_pseudo_bytes(md->md_data, md->digest->md_size) < 0)
        goto berr;
    memcpy(&(ctx->buf[ctx->buf_len]), md->md_data, md->digest->md_size);
    longswap(&(ctx->buf[ctx->buf_len]), md->digest->md_size);
    ctx->buf_len += md->digest->md_size;

    if (!EVP_DigestUpdate(md, WELLKNOWN, strlen(WELLKNOWN)))
        goto berr;
    if (!EVP_DigestFinal_ex(md, &(ctx->buf[ctx->buf_len]), NULL))
        goto berr;
    ctx->buf_len += md->digest->md_size;
    ctx->blockout = 1;
    ctx->sigio = 0;
    return 1;
 berr:
    BIO_clear_retry_flags(b);
    return 0;
}
Example #3
0
static void sig_in(BIO *b)
{
    BIO_OK_CTX *ctx;
    EVP_MD_CTX *md;
    unsigned char tmp[EVP_MAX_MD_SIZE];
    int ret = 0;

    ctx = b->ptr;
    md = &ctx->md;

    if ((int)(ctx->buf_len - ctx->buf_off) < 2 * md->digest->md_size)
        return;

    EVP_DigestInit_ex(md, md->digest, NULL);
    memcpy(md->md_data, &(ctx->buf[ctx->buf_off]), md->digest->md_size);
    longswap(md->md_data, md->digest->md_size);
    ctx->buf_off += md->digest->md_size;

    EVP_DigestUpdate(md, WELLKNOWN, strlen(WELLKNOWN));
    EVP_DigestFinal_ex(md, tmp, NULL);
    ret = memcmp(&(ctx->buf[ctx->buf_off]), tmp, md->digest->md_size) == 0;
    ctx->buf_off += md->digest->md_size;
    if (ret == 1) {
        ctx->sigio = 0;
        if (ctx->buf_len != ctx->buf_off) {
            memmove(ctx->buf, &(ctx->buf[ctx->buf_off]),
                    ctx->buf_len - ctx->buf_off);
        }
        ctx->buf_len -= ctx->buf_off;
        ctx->buf_off = 0;
    } else {
        ctx->cont = 0;
    }
}
Example #4
0
STATUS  IGMP_Initialize(DV_DEVICE_ENTRY *device)
{
    uint32      all_hosts_group = 0xE0000001; /* IP address 224.0.0.1 */

    /* Join the all hosts group on this device. Note that IP_Add_Multi will not
       report the membership in the all hosts group, and a report should not be
       sent here.  RFC 1112 specifies that membership in the all hosts group is
       never reported.
    */
    if (IP_Add_Multi(longswap(all_hosts_group), device) != NU_NULL)
        return NU_SUCCESS;
    else
        return NU_INVAL;

} /* IGMP_Initialize */
Example #5
0
static int sig_in(BIO *b)
{
    BIO_OK_CTX *ctx;
    EVP_MD_CTX *md;
    unsigned char tmp[EVP_MAX_MD_SIZE];
    int ret = 0;
    const EVP_MD *digest;
    int md_size;
    void *md_data;

    ctx = BIO_get_data(b);
    md = ctx->md;
    digest = EVP_MD_CTX_md(md);
    md_size = EVP_MD_size(digest);
    md_data = EVP_MD_CTX_md_data(md);

    if ((int)(ctx->buf_len - ctx->buf_off) < 2 * md_size)
        return 1;

    if (!EVP_DigestInit_ex(md, digest, NULL))
        goto berr;
    memcpy(md_data, &(ctx->buf[ctx->buf_off]), md_size);
    longswap(md_data, md_size);
    ctx->buf_off += md_size;

    if (!EVP_DigestUpdate(md, WELLKNOWN, strlen(WELLKNOWN)))
        goto berr;
    if (!EVP_DigestFinal_ex(md, tmp, NULL))
        goto berr;
    ret = memcmp(&(ctx->buf[ctx->buf_off]), tmp, md_size) == 0;
    ctx->buf_off += md_size;
    if (ret == 1) {
        ctx->sigio = 0;
        if (ctx->buf_len != ctx->buf_off) {
            memmove(ctx->buf, &(ctx->buf[ctx->buf_off]),
                    ctx->buf_len - ctx->buf_off);
        }
        ctx->buf_len -= ctx->buf_off;
        ctx->buf_off = 0;
    } else {
        ctx->cont = 0;
    }
    return 1;
 berr:
    BIO_clear_retry_flags(b);
    return 0;
}
Example #6
0
static int sig_in(BIO *b)
{
    BIO_OK_CTX *ctx;
    EVP_MD_CTX *md;
    unsigned char tmp[EVP_MAX_MD_SIZE];
    int ret = 0;

    ctx = b->ptr;
    md = &ctx->md;

    if ((int)(ctx->buf_len - ctx->buf_off) < 2 * md->digest->md_size)
        return 1;

    if (!EVP_DigestInit_ex(md, md->digest, NULL))
        goto berr;
    sgx_memcpy(md->md_data, &(ctx->buf[ctx->buf_off]), md->digest->md_size);
    longswap(md->md_data, md->digest->md_size);
    ctx->buf_off += md->digest->md_size;

    if (!EVP_DigestUpdate(md, WELLKNOWN, sgx_strlen(WELLKNOWN)))
        goto berr;
    if (!EVP_DigestFinal_ex(md, tmp, NULL))
        goto berr;
    ret = sgx_memcmp(&(ctx->buf[ctx->buf_off]), tmp, md->digest->md_size) == 0;
    ctx->buf_off += md->digest->md_size;
    if (ret == 1) {
        ctx->sigio = 0;
        if (ctx->buf_len != ctx->buf_off) {
            sgx_memmove(ctx->buf, &(ctx->buf[ctx->buf_off]),
                    ctx->buf_len - ctx->buf_off);
        }
        ctx->buf_len -= ctx->buf_off;
        ctx->buf_off = 0;
    } else {
        ctx->cont = 0;
    }
    return 1;
 berr:
    BIO_clear_retry_flags(b);
    return 0;
}
Example #7
0
VOID IGMP_Join(IP_MULTI *ipm)
{

	/* Membership in the all hosts group is not reported. It is assumed that all
       level 2 conforming multicasts hosts are members of this group. */
    /* NOTE: When loop back of multicast packets is supported, membership should 
       not be reported in that case either. The interface should be checked here.
    */
    if (ipm->ipm_addr == longswap(IGMP_ALL_HOSTS_GROUP))
    {
        ipm->ipm_timer = 0;
    }
    else
    {
        /* Send a report of the membership.*/
        IGMP_Send(ipm);

        /* Set up timer event to send the report again just in case something 
           goes wrong with the first report. */
        ipm->ipm_timer = IGMP_Random_Delay(ipm);
    }

} /* IGMP_Join */
Example #8
0
static void sig_in(BIO* b)
{
    BIO_OK_CTX *ctx;
    EVP_MD_CTX *md;
    unsigned char tmp[EVP_MAX_MD_SIZE];
    int ret= 0;

    ctx=(BIO_OK_CTX *)b->ptr;
    md=&ctx->md;

    if((int)(ctx->buf_len-ctx->buf_off) < 2*md->digest->md_size) return;

    EVP_DigestInit_ex(md, md->digest, NULL);
    TINYCLR_SSL_MEMCPY(md->md_data, &(ctx->buf[ctx->buf_off]), md->digest->md_size);
    longswap(md->md_data, md->digest->md_size);
    ctx->buf_off+= md->digest->md_size;

    EVP_DigestUpdate(md, WELLKNOWN, TINYCLR_SSL_STRLEN(WELLKNOWN));
    EVP_DigestFinal_ex(md, tmp, NULL);
    ret= TINYCLR_SSL_MEMCMP(&(ctx->buf[ctx->buf_off]), tmp, md->digest->md_size) == 0;
    ctx->buf_off+= md->digest->md_size;
    if(ret == 1)
    {
        ctx->sigio= 0;
        if(ctx->buf_len != ctx->buf_off)
        {
            TINYCLR_SSL_MEMMOVE(ctx->buf, &(ctx->buf[ctx->buf_off]), ctx->buf_len- ctx->buf_off);
        }
        ctx->buf_len-= ctx->buf_off;
        ctx->buf_off= 0;
    }
    else
    {
        ctx->cont= 0;
    }
}
Example #9
0
boolean unmergehandles (Handle hmerged, Handle *hfirst, Handle *hsecond) {

    /*
    split up a handle created by mergehandle.

    3/12/91 dmb: rewrote so that we own hmerged; caller no longer diposes it.
    this allows us to reuse the handle to greatly reduce memory requirements.
    we could further optimize by reusing hmerged for the larger handle instead
    of always hsecond.

    also, avoid locking handles when we're trying to allocate potentially
    large chunks of memory.

    2.1b3 dmb: newly-created handle is always ok as temporary memory
    */

    register Handle h1 = nil, h2 = nil;
    register Handle h = hmerged;
    long ix;
    long sizefirsthandle, sizesecondhandle;

    *hfirst = *hsecond = nil; /*default return values*/

    moveleft (*h, &sizefirsthandle, sizeof (long));

#ifdef PACKFLIPPED
    longswap (sizefirsthandle);
#endif

    ix = sizeof (long);

    if (sizefirsthandle == 0)
        h1 = nil;

    else {
        h1 = getnewhandle (sizefirsthandle, true);

        if (h1 == nil)
            goto error;

        moveleft (*h + ix, *h1, sizefirsthandle);
    }

    ix += sizefirsthandle;

    sizesecondhandle = gethandlesize (h) - sizefirsthandle - sizeof (long);

    if (sizesecondhandle == 0) {

        h2 = nil;

        disposehandle (h);
    }
    else {

        h2 = h; /*second handle can safely re-use merged handle*/

        moveleft (*h2 + ix, *h2, sizesecondhandle);

        sethandlesize (h2, sizesecondhandle);
    }

    *hfirst = h1; /*return handles to caller*/

    *hsecond = h2;

    return (true);

error:

    disposehandle (h);

    disposehandle (h1);

    disposehandle (h2);

    memoryerror ();

    return (false);
} /*unmergehandles*/
Example #10
0
STATUS IGMP_Interpret(NET_BUFFER *buf_ptr, INT hlen)
{
    INT         igmp_len;
    IGMP_LAYER  *igmp;
    IPLAYER     *ip;
    uint16      cksum;
    IP_MULTI    *ipm;

    igmp_len = buf_ptr->mem_total_data_len;

    if (igmp_len != sizeof (IGMP_LAYER))
    {
        MEM_Buffer_Chain_Free (&MEM_Buffer_List, &MEM_Buffer_Freelist);
        return -1;
    }

    igmp = (IGMP_LAYER *)buf_ptr->data_ptr;
    ip = (IPLAYER *)(buf_ptr->data_ptr - hlen);

    cksum = igmp->igmp_cksum;
    igmp->igmp_cksum = 0;

    if ( cksum != IP_Checklen ((int8 *)igmp, sizeof(IGMP_LAYER)) )
    {
        MEM_Buffer_Chain_Free (&MEM_Buffer_List, &MEM_Buffer_Freelist);
        return -1;
    }

    switch (igmp->igmp_type)
    {
    
    case IGMP_HOST_MEMBERSHIP_QUERY :
        
        /* All queries should be addressed to the all hosts group. */
        if (*(uint32 *)ip->ipdest != longswap(IGMP_ALL_HOSTS_GROUP))
        {
            MEM_Buffer_Chain_Free (&MEM_Buffer_List, &MEM_Buffer_Freelist);
            return -1;
        }

        /* Step through all of the multicast groups that the receive interface 
           is a member of. */
        for ( ipm = buf_ptr->mem_buf_device->dev_addr.dev_multiaddrs;
              ipm != NU_NULL;
              ipm = ipm->ipm_next)
        {
            /* Don't send a report if for the all hosts group or if a timer is 
               already set up. */
            if ( (ipm->ipm_device == buf_ptr->mem_buf_device) &&
                 (ipm->ipm_timer == 0) &&
                 (ipm->ipm_addr != longswap(IGMP_ALL_HOSTS_GROUP)) )
            {
                ipm->ipm_timer = IGMP_Random_Delay(ipm);
            }

        }
        break;

    case IGMP_HOST_MEMBERSHIP_REPORT :
        
        /* Make sure the multicast group is valid. */
        if ( !IP_MULTICAST_ADDR(longswap(igmp->igmp_group)) ||
             (igmp->igmp_group != *(uint32 *)ip->ipdest ) )
        {
            MEM_Buffer_Chain_Free (&MEM_Buffer_List, &MEM_Buffer_Freelist);
            return -1;
        }

        /* See if the receive interface is a member of the group. */
        ipm = IP_Lookup_Multi(igmp->igmp_group, &buf_ptr->mem_buf_device->dev_addr);

        /* If the interface is a member of the group and a report timer 
           currently exists, clear the timer. */
        if (ipm && ipm->ipm_timer)
        {
            ipm->ipm_timer = 0;
            UTL_Timerunset (EV_IGMP_REPORT, (uint32)ipm, 1);
        }
        break;

    default :

        MEM_Buffer_Chain_Free (&MEM_Buffer_List, &MEM_Buffer_Freelist);
        break;
    }

    /* Free the buffer. */
    MEM_Buffer_Chain_Free (&MEM_Buffer_List, &MEM_Buffer_Freelist);

    return (NU_SUCCESS);

} /* IGMP_Interpret */
Example #11
0
void *ConvertWAVCFURL(CFURLRef theURL, size_t *sndSize, int *loopStart, int *loopEnd, short *sampleSize, unsigned int *rate, bool *stereo)
{
	PCMWavePtr	WAVERsrc = NULL;
	long		fSize = 0;
	CFReadStreamRef fRef = CFReadStreamCreateWithFile(kCFAllocatorDefault, theURL);
	CFReadStreamOpen(fRef);
	CFStreamStatus theStat = CFReadStreamGetStatus(fRef);
	while (theStat != kCFStreamStatusOpen && theStat != kCFStreamStatusError) {
		theStat = CFReadStreamGetStatus(fRef);
	}
	if (theStat == kCFStreamStatusError) {
		CFReadStreamClose(fRef);
		CFRelease(fRef);
		return NULL;
	}
	
	*stereo = false;
	
	if (fRef != NULL) {
		fSize = URLGetFileSize(theURL);
		if (!(WAVERsrc = (PCMWavePtr)malloc(fSize))) {
			CFReadStreamClose(fRef);
			CFRelease(fRef);
			return NULL;
		}
		
		if (CFReadStreamRead(fRef, (UInt8*)WAVERsrc, fSize) != fSize) {
			free(WAVERsrc);
			CFReadStreamClose(fRef);
			CFRelease(fRef);
			return NULL;
		}
		
		if (memcmp(WAVERsrc->ckid, "RIFF", 4) == 0) {
			WAVERsrc->cksize = longswap(WAVERsrc->cksize);
			
			if (memcmp(WAVERsrc->fccType, "WAVE", 4) == 0) {
				WAVERsrc->dwDataOffset = longswap(WAVERsrc->dwDataOffset);
				
				if (memcmp(WAVERsrc->fmtType, "fmt ", 4) == 0) {
					WAVERsrc->wFormatTag		= shrtswap(WAVERsrc->wFormatTag);
					WAVERsrc->nCannels			= shrtswap(WAVERsrc->nCannels);
					WAVERsrc->nSamplesPerSec	= longswap(WAVERsrc->nSamplesPerSec);
					WAVERsrc->nSamplesPerSec	= CFSwapInt32BigToHost(WAVERsrc->nSamplesPerSec) << 16; //FIXME: is this right for LE machines?
					WAVERsrc->nAvgBytesPerSec	= longswap(WAVERsrc->nAvgBytesPerSec);
					WAVERsrc->nBlockAlign		= shrtswap(WAVERsrc->nBlockAlign);
					WAVERsrc->wBitsPerSample	= shrtswap(WAVERsrc->wBitsPerSample);
					WAVERsrc->dataSize			= longswap(WAVERsrc->dataSize);
					
					*loopStart	= 0;
					*loopEnd 	= 0;
					*sampleSize = WAVERsrc->wBitsPerSample;
					*rate		= WAVERsrc->nSamplesPerSec;
					
					if (WAVERsrc->nCannels == 2)
						*stereo = true;
					else
						*stereo = false;
					
					if (WAVERsrc->wFormatTag != 1) {
						free(WAVERsrc);
						CFReadStreamClose(fRef);
						CFRelease(fRef);
						return NULL;
					}
				} else {
					free(WAVERsrc);
					CFReadStreamClose(fRef);
					CFRelease(fRef);
					return NULL;
				}
			} else {
				free(WAVERsrc);
				CFReadStreamClose(fRef);
				CFRelease(fRef);
				return NULL;
			}
		} else {
			free(WAVERsrc);
			CFReadStreamClose(fRef);
			CFRelease(fRef);
			return NULL;
		}
		CFReadStreamClose(fRef);
		CFRelease(fRef);
	}
	
	{
#if __BIG_ENDIAN__
		unsigned short *tt;
#endif
		
		*sndSize = WAVERsrc->dataSize;
		memmove(WAVERsrc, WAVERsrc->theData, *sndSize);
		WAVERsrc = realloc(WAVERsrc, *sndSize);
		
		switch (*sampleSize) {
			case 8:
				MADConvertInstrument((Byte*)WAVERsrc, *sndSize);
				break;
				
			case 16:
#if __BIG_ENDIAN__
				tt = (unsigned short*)WAVERsrc;
				dispatch_apply((*sndSize) / 2, dispatch_get_global_queue(0, 0), ^(size_t i) {
					tt[i] = shrtswap(tt[i]);
				});
#endif
				break;
		}