Example #1
0
void blake512_update( state512 *S, const uint8_t *in, uint64_t inlen )
{
  int left = S->buflen;
  int fill = 128 - left;

  /* data left and data received fill a block  */
  if( left && ( inlen >= fill ) )
  {
    tc_memcpy( ( void * ) ( S->buf + left ), ( void * ) in, fill );
    S->t[0] += 1024;

    if ( S->t[0] == 0 ) S->t[1]++;

    blake512_compress( S, S->buf );
    in += fill;
    inlen  -= fill;
    left = 0;
  }

  /* compress blocks of data received */
  while( inlen >= 128 )
  {
    S->t[0] += 1024;

    if ( S->t[0] == 0 ) S->t[1]++;

    blake512_compress( S, in );
    in += 128;
    inlen -= 128;
  }

  /* store any data left */
  if( inlen > 0 )
  {
    tc_memcpy( ( void * ) ( S->buf + left ),   \
            ( void * ) in, ( size_t ) inlen );
    S->buflen = left + ( int )inlen;
  }
  else S->buflen = 0;
}
Example #2
0
void rtsmb_srv_net_set_ip (PFBYTE host_ip, PFBYTE mask_ip)
{
    byte old_broadcast_ip [4];

    /* We want to reset our broadcasting if we are changing subnets.
       So, we save our current broadcast ip. */
    tc_memcpy (old_broadcast_ip, rtsmb_srv_net_get_broadcast_ip (), 4);

    rtsmb_net_set_ip (host_ip, mask_ip);

    /* If they're different, restart broadcasting */
    if (tc_memcmp (old_broadcast_ip, rtsmb_srv_net_get_broadcast_ip (), 4))
    {
        rtsmb_srv_nbns_restart ();
    }
}
Example #3
0
/****************************************************
 * Initialize Socket for Windows
 ****************************************************/
int SOCK_Init (void)
{
    int result;
    char hostname[100];
    struct hostent *he;
    byte ip [4];

    result = WSAStartup (WINSOCK_VER, &wsa_data);

    if (result)
    {
        PRINTF (("init: Winsock start up failed\n"));
        return -1;
    }

    result = gethostname (hostname, 100);

    if (result)
    {
        PRINTF (("init: Winsock start up failed\n"));
        return -1;
    }

    he = gethostbyname (hostname);

    if (!he)
    {
        PRINTF (("init: Winsock start up failed\n"));
        return -1;
    }

    /* just use the first one   */
    tc_memcpy (ip, he->h_addr_list[0], 4);

    rtsmb_srv_init (ip, NULL, NULL, NULL);
    rtsmb_cli_init (ip, NULL);

    return 0;
}
Example #4
0
/*---------------------------------------------------------------------------*/
int rtp_queue_get (RTPMessageQueue *queue, void *message)
{
	if (rtp_sig_semaphore_wait(queue->sem) < 0)
	{
		return (-1);
	}
	
	if (rtp_sig_mutex_claim(queue->lock) < 0)
	{
		return (-1);
	}
	
	if (queue->first != queue->last)
	{
		tc_memcpy((char *) message, &queue->messages[queue->first * queue->msgSize], queue->msgSize);
		
		queue->first = (queue->first + 1) % queue->queueSize;
	}
	
	rtp_sig_mutex_release(queue->lock);

	return (0);
}
Example #5
0
/*---------------------------------------------------------------------------*/
int rtp_queue_put (RTPMessageQueue *queue, void *message)
{
	if (rtp_sig_mutex_claim(queue->lock) < 0)
	{
		return (-1);
	}
	
	/* make sure the queue is not full */
	if ((queue->last + 1) % queue->queueSize == queue->first)
	{
		rtp_sig_mutex_release(queue->lock);	
		return (-1);
	}
		
	tc_memcpy(&queue->messages[queue->last * queue->msgSize], (char *) message, queue->msgSize);

	queue->last = (queue->last + 1) % queue->queueSize;
		
	rtp_sig_semaphore_signal(queue->sem);
	rtp_sig_mutex_release(queue->lock);
	
	return (0);
}
Example #6
0
int crypto_core_salsa(
	unsigned char *out,
	const unsigned char *in,
	const unsigned char *k,
	const unsigned char *c,
	unsigned int rounds)
{
	tc_memcpy(out +  0, c +  0, 4);

	tc_memcpy(out +  4, k  +  0, 4);
	tc_memcpy(out +  8, k  +  4, 4);
	tc_memcpy(out + 12, k  +  8, 4);
	tc_memcpy(out + 16, k  + 12, 4);

	tc_memcpy(out + 20, c  +  4, 4);

	tc_memcpy(out + 24, in +  0, 4);
	tc_memcpy(out + 28, in +  4, 4);
	tc_memcpy(out + 32, in +  8, 4);
	tc_memcpy(out + 36, in + 12, 4);

	tc_memcpy(out + 40, c  +  8, 4);

	tc_memcpy(out + 44, k  + 16, 4);
	tc_memcpy(out + 48, k  + 20, 4);
	tc_memcpy(out + 52, k  + 24, 4);
	tc_memcpy(out + 56, k  + 28, 4);

	tc_memcpy(out + 60, c  + 12, 4);

	crypto_core_salsa_rounds(out, rounds);

	return 0;
}
Example #7
0
/*---------------------------------------------------------------------------*/
HTTP_INT32 _HTTP_RealmPrintAuthorization (
		HTTPAuthenticationRealm *realm,
		const HTTP_CHAR* method,
		const HTTP_CHAR* path,
		HTTP_INT32 (*writeFn) (
				void* requestStream,
				const HTTP_CHAR* data,
				HTTP_INT32 len
			),
		void* requestStream
	)
{
	switch (realm->scheme)
	{
		case HTTP_AUTHENTICATION_BASIC:
			if (realm->userName[0])
			{
				HTTP_INT32 len = 0;
				char auth[HTTP_CFG_MAX_USERNAME_LEN + HTTP_CFG_MAX_PASSWORD_LEN];
				char encoded[((HTTP_CFG_MAX_USERNAME_LEN + HTTP_CFG_MAX_PASSWORD_LEN) * 4 + 2) /3];

				len =  sizeof(HTTP_CLIENT_BASIC_STR) / sizeof(HTTP_CHAR) - sizeof(HTTP_CHAR);
				writeFn(requestStream, HTTP_CLIENT_BASIC_STR, len);
				writeFn(requestStream, " ", 1);

				tc_strcpy(auth, realm->userName);
				tc_strcat(auth, ":");
				tc_strcat(auth, realm->password);

				len = _HTTP_Base64Encode(encoded, (HTTP_UINT8*) auth, (HTTP_INT32) tc_strlen(auth));

				writeFn(requestStream, encoded, len);

				return (len);
			}
			break;

		case HTTP_AUTHENTICATION_DIGEST:
			if (realm->userName[0])
			{
				HTTP_INT32 len = 0;
				HTTP_MD5_CTX md5Ctx;
				HTTP_CHAR hashA1[32];
				HTTP_CHAR hashA2[32];
				HTTP_CHAR finalHash[33];

				/* according to RFC 2617,
				      credentials = "Digest" digest-response

				   where
				      digest-response = "username=\"" + <user-name> +
					                    "\", realm=\"" + <realm-name> +
										"\", nonce=\"" + <server-nonce> +
										"\", uri=\"" + <path> +
										"\", response=\"" +
										   (qop == auth || qop == auth-int)?
										      KD(H(A1), <nonce> + ":" + <nonce-count> + ":" + <cnonce> + ":" + <qop> + ":" + H(A2)) :
											  KD(H(A1), <nonce> + ":" + H(A2))

				      A1 = <user-name> + ":" + <realm-name> + ":" + <password>

					  A2 = <method (GET,POST,etc)> + ":" + <path>

					  H(X) = MD5(X), as a 32-character HEX string

					  KD(I,J) = H(I + ":" + J);
				*/

				len = 17 /*Digest username="******", realm="*/ +
				      tc_strlen(realm->realmName) + 10 /*", nonce="*/ +
					  tc_strlen(realm->param.digest.serverNonce) + 8 /*", uri="*/ +
					  tc_strlen(path) + 13 /*", response="*/ + 32 /* MD5 hash */ + 1;

				writeFn(requestStream, "Digest username=\"", 17);
				writeFn(requestStream, realm->userName, tc_strlen(realm->userName));
				writeFn(requestStream, "\", realm=\"", 10);
				writeFn(requestStream, realm->realmName, tc_strlen(realm->realmName));
				writeFn(requestStream, "\", nonce=\"", 10);
				writeFn(requestStream, realm->param.digest.serverNonce, tc_strlen(realm->param.digest.serverNonce));
				writeFn(requestStream, "\", uri=\"", 8);
				writeFn(requestStream, path, tc_strlen(path));
				writeFn(requestStream, "\", response=\"", 13);

				/*-----------------------------------------------------*/
				/* find H(A1)                                          */
				/* if (algorithm == MD5) */
				HTTP_MD5_Init(&md5Ctx);
				HTTP_MD5_Update(&md5Ctx, realm->userName, tc_strlen(realm->userName)); /* TBD!!! - what if HTTP_CHAR is not ASCII 8bit ? */
				HTTP_MD5_Update(&md5Ctx, ":", 1);
				HTTP_MD5_Update(&md5Ctx, realm->realmName, tc_strlen(realm->realmName));
				HTTP_MD5_Update(&md5Ctx, ":", 1);
				HTTP_MD5_Update(&md5Ctx, realm->password, tc_strlen(realm->password));
				HTTP_MD5_Final(&md5Ctx);

     			if (realm->param.digest.hashAlgorithm == HTTP_ALGORITHM_MD5_SESS)
				{
					HTTP_UINT8 HA1[16];

					tc_memcpy(HA1, md5Ctx.digest, 16);

					HTTP_MD5_Init(&md5Ctx);
					HTTP_MD5_Update(&md5Ctx, HA1, 16);
					HTTP_MD5_Update(&md5Ctx, ":", 1);
					HTTP_MD5_Update(&md5Ctx, realm->param.digest.serverNonce, tc_strlen(realm->param.digest.serverNonce));
					HTTP_MD5_Update(&md5Ctx, ":", 1);
					HTTP_MD5_Update(&md5Ctx, realm->param.digest.clientNonce, tc_strlen(realm->param.digest.clientNonce));
					HTTP_MD5_Final(&md5Ctx);
				}

				_HTTP_HashToHex(hashA1, md5Ctx.digest, 16);

				/*-----------------------------------------------------*/
				/* find H(A2)                                          */
				/* if (QOP == auth || QOP == none) */
				HTTP_MD5_Init(&md5Ctx);
				HTTP_MD5_Update(&md5Ctx, method, tc_strlen(method));
				HTTP_MD5_Update(&md5Ctx, ":", 1);
				HTTP_MD5_Update(&md5Ctx, path, tc_strlen(path));

				if (realm->param.digest.qop == HTTP_QOP_AUTH_INT)
				{
					HTTP_MD5_Update(&md5Ctx, ":", 1);
					/* What is HEntity!?!? */
					/*HTTP_MD5_Update(&md5Ctx, HEntity, HASHHEXLEN);*/
				}

				HTTP_MD5_Final(&md5Ctx);
				_HTTP_HashToHex(hashA2, md5Ctx.digest, 16);

				HTTP_MD5_Init(&md5Ctx);
				HTTP_MD5_Update(&md5Ctx, hashA1, 32);
				HTTP_MD5_Update(&md5Ctx, ":", 1);
				HTTP_MD5_Update(&md5Ctx, realm->param.digest.serverNonce, tc_strlen(realm->param.digest.serverNonce));
				HTTP_MD5_Update(&md5Ctx, ":", 1);

				if (realm->param.digest.qop == HTTP_QOP_AUTH ||
					realm->param.digest.qop == HTTP_QOP_AUTH_INT)
				{
					HTTP_CHAR nonceCountStr[8];

					_HTTP_UINT32ToHex(nonceCountStr, realm->param.digest.nonceCount);

					HTTP_MD5_Update(&md5Ctx, nonceCountStr, 8);
					HTTP_MD5_Update(&md5Ctx, ":", 1);
					HTTP_MD5_Update(&md5Ctx, realm->param.digest.clientNonce, tc_strlen(realm->param.digest.clientNonce));
					HTTP_MD5_Update(&md5Ctx, ":", 1);
					HTTP_MD5_Update(&md5Ctx, httpAuthQoPNames[realm->param.digest.qop], tc_strlen(httpAuthQoPNames[realm->param.digest.qop]));
					HTTP_MD5_Update(&md5Ctx, ":", 1);
				}

				HTTP_MD5_Update(&md5Ctx, hashA2, 32);
				HTTP_MD5_Final(&md5Ctx);

				_HTTP_HashToHex(finalHash, md5Ctx.digest, 16);
				finalHash[32] = '\"';

				writeFn(requestStream, finalHash, 33);

				return (len);
			}
			break;

		default:
			break;
	}

	return (0);
}