示例#1
0
文件: md5step.c 项目: gxliu/MQX_3.8.0
void PPP_MD5_block
   (
      uint_32_ptr context,
            /* [IN/OUT] - the incremental hash */

      register uint_32_ptr block,
            /* [IN] - the 16 word block */

      register const uint_32 _PTR_ ctab
            /* [IN] - the sine function */
   )
{ /* Body */

#define F(x,y,z)  ((y&x)|(z&~x))
#define G(x,y,z)  ((x&z)|(y&~z))
#define H(x,y,z)  (x^y^z)
#define I(x,y,z)  (y^(x|~z))

#define P1(f,k,s) t=a+f(b,c,d)+block[k]+*ctab++; a=rotl(t,s)+b
#define P2(f,k,s) t=d+f(a,b,c)+block[k]+*ctab++; d=rotl(t,s)+a
#define P3(f,k,s) t=c+f(d,a,b)+block[k]+*ctab++; c=rotl(t,s)+d
#define P4(f,k,s) t=b+f(c,d,a)+block[k]+*ctab++; b=rotl(t,s)+c

   register uint_32  a = context[0];
   register uint_32  b = context[1];
   register uint_32  c = context[2];
   register uint_32  d = context[3];
   register uint_32  t;

   P1(F,  0,  7); P2(F,  1, 12); P3(F,  2, 17); P4(F,  3, 22);
   P1(F,  4,  7); P2(F,  5, 12); P3(F,  6, 17); P4(F,  7, 22);
   P1(F,  8,  7); P2(F,  9, 12); P3(F, 10, 17); P4(F, 11, 22);
   P1(F, 12,  7); P2(F, 13, 12); P3(F, 14, 17); P4(F, 15, 22);

   P1(G,  1,  5); P2(G,  6,  9); P3(G, 11, 14); P4(G,  0, 20);
   P1(G,  5,  5); P2(G, 10,  9); P3(G, 15, 14); P4(G,  4, 20);
   P1(G,  9,  5); P2(G, 14,  9); P3(G,  3, 14); P4(G,  8, 20);
   P1(G, 13,  5); P2(G,  2,  9); P3(G,  7, 14); P4(G, 12, 20);

   P1(H,  5,  4); P2(H,  8, 11); P3(H, 11, 16); P4(H, 14, 23);
   P1(H,  1,  4); P2(H,  4, 11); P3(H,  7, 16); P4(H, 10, 23);
   P1(H, 13,  4); P2(H,  0, 11); P3(H,  3, 16); P4(H,  6, 23);
   P1(H,  9,  4); P2(H, 12, 11); P3(H, 15, 16); P4(H,  2, 23);

   P1(I,  0,  6); P2(I,  7, 10); P3(I, 14, 15); P4(I,  5, 21);
   P1(I, 12,  6); P2(I,  3, 10); P3(I, 10, 15); P4(I,  1, 21);
   P1(I,  8,  6); P2(I, 15, 10); P3(I,  6, 15); P4(I, 13, 21);
   P1(I,  4,  6); P2(I, 11, 10); P3(I,  2, 15); P4(I,  9, 21);

   context[0] += a;
   context[1] += b;
   context[2] += c;
   context[3] += d;

   PPP_memzero(block, sizeof(uint_32[16]));

} /* Endbody */
示例#2
0
uint32_t PPPFSM_init
   (
      PPPFSM_CFG_PTR    fsm,
            /* [IN/OUT] - State Machine */
      _ppp_handle       handle,
            /* [IN] - the PPP state structure */
      PPPFSM_CALL_PTR   call_ptr,
            /* [IN] - Protocol-specific call table */
      void             *param
            /* [IN] - Parameter for protocol-specific calls */
   )
{ /* Body */

#if RTCSCFG_ENABLE_IP4


   PPP_memzero(fsm, sizeof(PPPFSM_CFG));
   fsm->HANDLE  = handle;
   fsm->CALL    = call_ptr;
   fsm->PRIVATE = param;
   fsm->STATE   = PPP_STATE_INITIAL;
   fsm->CURID   = RTCS_rand() & 0xFF;

   /* Initialize the mutex */
   if (PPP_mutex_init(&fsm->MUTEX)) {
      return RTCSERR_PPP_INIT_MUTEX_FAILED;
   } /* Endif */

   return PPP_OK;
   
#else   

    return RTCSERR_IP_IS_DISABLED;

#endif /* RTCSCFG_ENABLE_IP4  */

} /* Endbody */
示例#3
0
文件: ppp.c 项目: zhouglu/K60F120M
uint_32 PPP_initialize
   (
      _iopcb_handle       device,
            /* [IN] - I/O stream to use */
      _ppp_handle _PTR_   handle
            /* [OUT] - the PPP state structure */
   )
{ /* Body */

#if RTCSCFG_ENABLE_IP4 

   PPP_CFG_PTR          ppp_ptr;
   uint_32              i, error;

   /* Allocate the state structure */
   ppp_ptr = PPP_memalloc(sizeof(PPP_CFG));
   if (!ppp_ptr) {
      return RTCSERR_PPP_ALLOC_FAILED;
   } /* Endif */

   /* Initialize it */
   PPP_memzero(ppp_ptr, sizeof(PPP_CFG));
   ppp_ptr->LINK_STATE = FALSE;
   ppp_ptr->DEVICE = device;
   for (i = 0; i < PPP_CALL_MAX; i++) {
      ppp_ptr->LCP_CALL[i].CALLBACK = NULL;
      ppp_ptr->LCP_CALL[i].PARAM    = NULL;
   } /* Endfor */
   ppp_ptr->PROT_CALLS = NULL;
   ppp_ptr->RECV_OPTIONS = &PPP_DEFAULT_OPTIONS;
   ppp_ptr->SEND_OPTIONS = &PPP_DEFAULT_OPTIONS;

   /* Initialize the lwsem */
   if (PPP_mutex_init(&ppp_ptr->MUTEX)) {
      return RTCSERR_PPP_INIT_MUTEX_FAILED;
   } /* Endif */

   /* Initialize LCP */
   error = LCP_init(ppp_ptr);
   if (error) {
      PPP_mutex_destroy(&ppp_ptr->MUTEX);
      return error;
   } /* Endif */

   /* Initialize CCP */
   error = CCP_init(ppp_ptr);
   if (error) {
      LCP_destroy(ppp_ptr);
      PPP_mutex_destroy(&ppp_ptr->MUTEX);
      return error;
   } /* Endif */
   CCP_open(ppp_ptr);

   /* Create a pool of message buffers */
   ppp_ptr->MSG_POOL = RTCS_msgpool_create(sizeof(PPP_MESSAGE),
      PPP_MESSAGE_INITCOUNT, PPP_MESSAGE_GROWTH, PPP_MESSAGE_LIMIT);
   if (ppp_ptr->MSG_POOL == MSGPOOL_NULL_POOL_ID) {
      CCP_destroy(ppp_ptr);
      LCP_destroy(ppp_ptr);
      PPP_mutex_destroy(&ppp_ptr->MUTEX);
      return RTCSERR_PPP_CREATE_PKT_POOL_FAILED;
   } /* Endif */

 
   /* Create the Tx Task */
   error = RTCS_task_create("PPP tx", _PPPTASK_priority,
      _PPPTASK_stacksize + 1000,
      PPP_tx_task, ppp_ptr);
   if (error) {
     RTCS_msgpool_destroy(ppp_ptr->MSG_POOL);
      CCP_destroy(ppp_ptr);
      LCP_destroy(ppp_ptr);
     PPP_mutex_destroy(&ppp_ptr->MUTEX);
      return error;
   } /* Endif */

   /* Create the Rx Task        */
   /* Set task ready for run    */
   ppp_ptr->STOP_RX = FALSE; 
   
   error = RTCS_task_create("PPP rx", _PPPTASK_priority,
      _PPPTASK_stacksize + 1000,
      PPP_rx_task, ppp_ptr);
   if (error) {
      RTCS_msgpool_destroy(ppp_ptr->MSG_POOL);
      CCP_destroy(ppp_ptr);
      LCP_destroy(ppp_ptr);
      PPP_mutex_destroy(&ppp_ptr->MUTEX);
      return error;
   } /* Endif */

   /* Return the handle */
   ppp_ptr->VALID = PPP_VALID;
   *handle = ppp_ptr;
   return PPP_OK;

#else

    return RTCSERR_IP_IS_DISABLED;    

#endif /* RTCSCFG_ENABLE_IP4 */

} /* Endbody */