コード例 #1
0
// 第二轮运算函数
void gg(unsigned long md5_x,unsigned long s,unsigned long ac)
{
	if(s==S11||s==S21||s==S31||s==S41)
	{
		md5_a+=g(md5_b,md5_c,md5_d)+md5_x+ac;
		md5_a=ROTATE_LEFT(md5_a,s);
		md5_a+=md5_b;
	}
	if(s==S12||s==S22||s==S32||s==S42)
	{
		md5_d+=g(md5_a,md5_b,md5_c)+md5_x+ac;
		md5_d=ROTATE_LEFT(md5_d,s);
		md5_d+=md5_a;
	}        
	if(s==S13||s==S23||s==S33||s==S43)
	{
		md5_c+=g(md5_d,md5_a,md5_b)+md5_x+ac;
		md5_c=ROTATE_LEFT(md5_c,s);
		md5_c+=md5_d;
	}        
	if(s==S14||s==S24||s==S34||s==S44)
	{
		md5_b+=g(md5_c,md5_d,md5_a)+md5_x+ac;
		md5_b=ROTATE_LEFT(md5_b,s);
		md5_b+=md5_c;
	}
}
コード例 #2
0
ファイル: rbtree.c プロジェクト: amohtasham/rstm
/* =============================================================================
 * fixAfterInsertion
 * =============================================================================
 */
static void
fixAfterInsertion (rbtree_t* s, node_t* x)
{
    STF(x, c, RED);
    while (x != NULL && x != LDNODE(s, root)) {
        node_t* xp = LDNODE(x, p);
        if (LDF(xp, c) != RED) {
            break;
        }
        /* TODO: cache g = ppx = PARENT_OF(PARENT_OF(x)) */
        if (PARENT_OF(x) == LEFT_OF(PARENT_OF(PARENT_OF(x)))) {
            node_t*  y = RIGHT_OF(PARENT_OF(PARENT_OF(x)));
            if (COLOR_OF(y) == RED) {
                SET_COLOR(PARENT_OF(x), BLACK);
                SET_COLOR(y, BLACK);
                SET_COLOR(PARENT_OF(PARENT_OF(x)), RED);
                x = PARENT_OF(PARENT_OF(x));
            } else {
                if (x == RIGHT_OF(PARENT_OF(x))) {
                    x = PARENT_OF(x);
                    ROTATE_LEFT(s, x);
                }
                SET_COLOR(PARENT_OF(x), BLACK);
                SET_COLOR(PARENT_OF(PARENT_OF(x)), RED);
                if (PARENT_OF(PARENT_OF(x)) != NULL) {
                    ROTATE_RIGHT(s, PARENT_OF(PARENT_OF(x)));
                }
            }
        } else {
            node_t* y = LEFT_OF(PARENT_OF(PARENT_OF(x)));
            if (COLOR_OF(y) == RED) {
                SET_COLOR(PARENT_OF(x), BLACK);
                SET_COLOR(y, BLACK);
                SET_COLOR(PARENT_OF(PARENT_OF(x)), RED);
                x = PARENT_OF(PARENT_OF(x));
            } else {
                if (x == LEFT_OF(PARENT_OF(x))) {
                    x = PARENT_OF(x);
                    ROTATE_RIGHT(s, x);
                }
                SET_COLOR(PARENT_OF(x),  BLACK);
                SET_COLOR(PARENT_OF(PARENT_OF(x)), RED);
                if (PARENT_OF(PARENT_OF(x)) != NULL) {
                    ROTATE_LEFT(s, PARENT_OF(PARENT_OF(x)));
                }
            }
        }
    }
    node_t* ro = LDNODE(s, root);
    if (LDF(ro, c) != BLACK) {
        STF(ro, c, BLACK);
    }
}
コード例 #3
0
ファイル: md5.c プロジェクト: BernardXiong/loongson1-pmon
static void
md5_transform (const unsigned char block[64])
{
  int i, j;
  UINT4 a,b,c,d,tmp;
  const UINT4 *x = (UINT4 *) block;

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

  /* Round 1 */
  for (i = 0; i < 16; i++)
    {
      tmp = a + F (b, c, d) + le32_to_cpu (x[i]) + T[i];
      tmp = ROTATE_LEFT (tmp, s1[i & 3]);
      tmp += b;
      a = d; d = c; c = b; b = tmp;
    }
  /* Round 2 */
  for (i = 0, j = 1; i < 16; i++, j += 5)
    {
      tmp = a + G (b, c, d) + le32_to_cpu (x[j & 15]) + T[i+16];
      tmp = ROTATE_LEFT (tmp, s2[i & 3]);
      tmp += b;
      a = d; d = c; c = b; b = tmp;
    }
  /* Round 3 */
  for (i = 0, j = 5; i < 16; i++, j += 3)
    {
      tmp = a + H (b, c, d) + le32_to_cpu (x[j & 15]) + T[i+32];
      tmp = ROTATE_LEFT (tmp, s3[i & 3]);
      tmp += b;
      a = d; d = c; c = b; b = tmp;
    }
  /* Round 4 */
  for (i = 0, j = 0; i < 16; i++, j += 7)
    {
      tmp = a + I (b, c, d) + le32_to_cpu (x[j & 15]) + T[i+48];
      tmp = ROTATE_LEFT (tmp, s4[i & 3]);
      tmp += b;
      a = d; d = c; c = b; b = tmp;
    }

  state[0] += a;
  state[1] += b;
  state[2] += c;
  state[3] += d;
}
コード例 #4
0
ファイル: scm.cpp プロジェクト: jjf28/lawine
DWORD DScm::CalcVerifyHash(CONST VCODE *vcode, VCPTR vdata, UINT vdata_size)
{
	DAssert(vcode && vdata && vdata_size);

	UINT op_num = DCount(vcode->op);
	DWORD hash = 0UL;
	BUFCPTR ptr = static_cast<BUFCPTR>(vdata);

	vdata_size >>= 2;

	for (UINT i = 0; i < vdata_size; i++, ptr += 4) {
		for (UINT j = 0; j < op_num; j++) {
			switch (vcode->op[j]) {
			case 0x00:
				hash ^= *reinterpret_cast<CONST DWORD *>(ptr);
				break;
			case 0x01:
				hash += *reinterpret_cast<CONST DWORD *>(ptr);
				break;
			case 0x02:
				hash -= *reinterpret_cast<CONST DWORD *>(ptr);
				break;
			case 0x03:
			case 0x04:
			case 0x05:
				hash ^= vcode->code[ptr[0]];
				hash ^= vcode->code[ptr[1]];
				hash ^= vcode->code[ptr[2]];
				hash ^= vcode->code[ptr[3]];
				break;
			case 0x06:
				hash = ROTATE_LEFT(hash, ptr[0]);
				hash = ROTATE_LEFT(hash, ptr[1]);
				hash = ROTATE_LEFT(hash, ptr[2]);
				hash = ROTATE_LEFT(hash, ptr[3]);
				break;
			case 0x07:
				hash = ROTATE_RIGHT(hash, ptr[0]);
				hash = ROTATE_RIGHT(hash, ptr[1]);
				hash = ROTATE_RIGHT(hash, ptr[2]);
				hash = ROTATE_RIGHT(hash, ptr[3]);
				break;
			default:
				break;
			}
		}
	}

	return hash;
}
コード例 #5
0
ファイル: md5.c プロジェクト: 12019/tiaozhanbei
	uint32 II(uint32 a, uint32 b, uint32 c, uint32 d, uint32 x, uint32 s, uint32 ac)
	{
		a += I (b, c, d) + x + (uint32)(ac);
		a = ROTATE_LEFT (a, s);
		a += b;
		return a;
	}
コード例 #6
0
ファイル: md5.c プロジェクト: boutboutnico/Arduino_HW_lib
	uint32_t II(uint32_t a, uint32_t b, uint32_t c, uint32_t d, uint32_t x, uint32_t s, uint32_t ac)
	{
		a += I (b, c, d) + x + (uint32_t)(ac);
		a = ROTATE_LEFT (a, s);
		a += b;
		return a;
	}
コード例 #7
0
ファイル: io.cpp プロジェクト: russellklenk/md5bench
uint32_t LLCALL_C io_hash_path(char const *path, char const **out_end)
{
    if (path == NULL)
    {
        if (out_end) *out_end = NULL;
        return 0;
    }

    uint32_t    cp   = 0;
    uint32_t    cp2  = 0;
    uint32_t    cp3  = 0;
    uint32_t    hash = 0;
    char const *iter = next_codepoint(path, cp);
    while (cp != 0)
    {
        cp2    = UTF8_TOUPPER(cp);
        cp3    = cp != '\\' ? cp2 : '/';
        hash   = ROTATE_LEFT(hash, 7) + cp3;
        iter   = next_codepoint(iter, cp);
    }
    if (out_end)
    {   
       *out_end = iter + 1;
    }
    return hash;
}
コード例 #8
0
dword II(dword a, dword b, dword c, dword d, dword x, dword s, dword ac) {
	a += I(b, c, d) + x + ac;
	a = ROTATE_LEFT(a, s);
	a += b;

	return a;
}
コード例 #9
0
ファイル: sha1.cpp プロジェクト: max1234/Guilabs
void SHA1::SHA1Transform(__UINT32_TYPE__ state[5], __UINT8_TYPE__ block[64])
{
    __UINT32_TYPE__ a = state[0], b = state[1], c = state[2], d = state[3], e = state[4], temp, x[80];
    Decode (x, block, 64);

    for(int i = 16; i < 80; i++)
    {
        {
            x[i] = x[i - 3] ^ x[i - 8] ^ x[i - 14] ^ x[i - 16];
            x[i] = ROTATE_LEFT(x[i],1);
        }
    }

    for(int i = 0; i < 80; i++)
    {
        if (i < 20)
        {
            temp = F(b,c,d) + K[0];
        }
        else if (i < 40)
        {
            temp = G(b,c,d) + K[1];
        }
        else if (i < 60)
        {
            temp = H(b,c,d) + K[2];
        }
        else
        {
            temp = I(b,c,d) + K[3];
        }

        temp += ROTATE_LEFT(a,5) + x[i] + e;
        e = d;
        d = c;
        c = ROTATE_LEFT(b,30);
        b = a;
        a = temp;
    }

    state[0] += a;
    state[1] += b;
    state[2] += c;
    state[3] += d;
    state[4] += e;

}
コード例 #10
0
ファイル: Cube.cpp プロジェクト: twd2/MagicCube
void Cube::U()
{
    SaveState();
    subCubes[0][2][0] = ROTATE_LEFT(oldSubCubes[0][2][2]);
    subCubes[1][2][0] = ROTATE_LEFT(oldSubCubes[0][2][1]);
    subCubes[2][2][0] = ROTATE_LEFT(oldSubCubes[0][2][0]);
    subCubes[0][2][1] = ROTATE_LEFT(oldSubCubes[1][2][2]);
    subCubes[1][2][1] = ROTATE_LEFT(oldSubCubes[1][2][1]);
    subCubes[2][2][1] = ROTATE_LEFT(oldSubCubes[1][2][0]);
    subCubes[0][2][2] = ROTATE_LEFT(oldSubCubes[2][2][2]);
    subCubes[1][2][2] = ROTATE_LEFT(oldSubCubes[2][2][1]);
    subCubes[2][2][2] = ROTATE_LEFT(oldSubCubes[2][2][0]);
}
コード例 #11
0
ファイル: Cube.cpp プロジェクト: twd2/MagicCube
void Cube::RotateLeft()
{
    U();
    SaveState();
    subCubes[0][1][0] = ROTATE_LEFT(oldSubCubes[0][1][2]);
    subCubes[1][1][0] = ROTATE_LEFT(oldSubCubes[0][1][1]);
    subCubes[2][1][0] = ROTATE_LEFT(oldSubCubes[0][1][0]);
    subCubes[0][1][1] = ROTATE_LEFT(oldSubCubes[1][1][2]);
    subCubes[1][1][1] = ROTATE_LEFT(oldSubCubes[1][1][1]);
    subCubes[2][1][1] = ROTATE_LEFT(oldSubCubes[1][1][0]);
    subCubes[0][1][2] = ROTATE_LEFT(oldSubCubes[2][1][2]);
    subCubes[1][1][2] = ROTATE_LEFT(oldSubCubes[2][1][1]);
    subCubes[2][1][2] = ROTATE_LEFT(oldSubCubes[2][1][0]);
    Di();
}
コード例 #12
0
ファイル: Md5.c プロジェクト: Kohrara/edk
STATIC
VOID
MD5Transform (
  IN MD5_CTX  *Md5Ctx
  )
/*++

Routine Description:

  GC_TODO: Add function description

Arguments:

  Md5Ctx  - GC_TODO: add argument description

Returns:

  GC_TODO: add return values

--*/
{
  UINT32  i;
  UINT32  j;
  UINT32  S[MD5_HASHSIZE >> 2];
  UINT32  *X;
  UINT32  k;
  UINT32  t;

  X = (UINT32 *) Md5Ctx->M;

  //
  // Copy MD5 states to S
  //
  EfiCopyMem (S, Md5Ctx->States, MD5_HASHSIZE);

  t = 0;
  for (i = 0; i < 4; i++) {
    k = MD5_K[i][0];
    for (j = 16; j > 0; j--) {
      SA += (*MD5_F[i]) (SB, SC, SD) + X[k] + MD5_T[t];
      SA  = ROTATE_LEFT (SA, MD5_S[i][j & 3]);
      SA += SB;

      k += MD5_K[i][1];
      k &= 15;

      t++;
    }
  }

  for (i = 0; i < 4; i++) {
    Md5Ctx->States[i] += S[i];
  }
}
コード例 #13
0
ファイル: peer_userhash.c プロジェクト: CoolerVoid/squid
peer *
peerUserHashSelectParent(request_t * request)
{
    int k;
    const char *c;
    peer *p = NULL;
    peer *tp;
    unsigned int user_hash = 0;
    unsigned int combined_hash;
    double score;
    double high_score = 0;
    const char *key = NULL;

    if (request->auth_user_request)
	key = authenticateUserRequestUsername(request->auth_user_request);
    if (!key)
	return NULL;

    /* calculate hash key */
    debug(39, 2) ("peerUserHashSelectParent: Calculating hash for %s\n", key);
    for (c = key; *c != 0; c++)
	user_hash += ROTATE_LEFT(user_hash, 19) + *c;
    /* select peer */
    for (k = 0; k < n_userhash_peers; k++) {
	tp = userhash_peers[k];
	combined_hash = (user_hash ^ tp->userhash.hash);
	combined_hash += combined_hash * 0x62531965;
	combined_hash = ROTATE_LEFT(combined_hash, 21);
	score = combined_hash * tp->userhash.load_multiplier;
	debug(39, 3) ("peerUserHashSelectParent: %s combined_hash %u score %.0f\n",
	    tp->name, combined_hash, score);
	if ((score > high_score) && peerHTTPOkay(tp, request)) {
	    p = tp;
	    high_score = score;
	}
    }
    if (p)
	debug(39, 2) ("peerUserHashSelectParent: selected %s\n", p->name);
    return p;
}
コード例 #14
0
peer *
peerSourceHashSelectParent(request_t * request)
{
    int k;
    const char *c;
    peer *p = NULL;
    peer *tp;
    unsigned int user_hash = 0;
    unsigned int combined_hash;
    double score;
    double high_score = 0;
    char *key = NULL;

    key = inet_ntoa(request->client_addr);

    /* calculate hash key */
    debug(39, 2) ("peerSourceHashSelectParent: Calculating hash for %s\n", key);
    for (c = key; *c != 0; c++)
	user_hash += ROTATE_LEFT(user_hash, 19) + *c;
    /* select peer */
    for (k = 0; k < n_sourcehash_peers; k++) {
	tp = sourcehash_peers[k];
	combined_hash = (user_hash ^ tp->sourcehash.hash);
	combined_hash += combined_hash * 0x62531965;
	combined_hash = ROTATE_LEFT(combined_hash, 21);
	score = combined_hash * tp->sourcehash.load_multiplier;
	debug(39, 3) ("peerSourceHashSelectParent: %s combined_hash %u score %.0f\n",
	    tp->host, combined_hash, score);
	if ((score > high_score) && peerHTTPOkay(tp, request)) {
	    p = tp;
	    high_score = score;
	}
    }
    if (p)
	debug(39, 2) ("peerSourceHashSelectParent: selected %s\n", p->host);
    return p;
}
コード例 #15
0
peer *
carpSelectParent(request_t * request)
{
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> ((sizeof(u_long)*8)-(n))))
    const char *c;
    peer *p = NULL;
    peer *tp;
    unsigned long url_hash = 0;
    unsigned long combined_hash;
    unsigned long high_score = 0;
    const char *url = urlCanonical(request);
    /* calculate url hash */
    debug(39, 2) ("carpSelectParent: CARP Calculating hash for %s\n", url);
    for (c = url; *c != 0; c++)
	url_hash += ROTATE_LEFT(url_hash, 19) + *c;
    /* select peer */
    for (tp = Config.peers; tp; tp = tp->next) {
	if (0.0 == tp->carp.load_factor)
	    continue;
	if (tp->tcp_up != PEER_TCP_MAGIC_COUNT)
	    continue;
	assert(tp->type == PEER_PARENT);
	combined_hash = (url_hash ^ tp->carp.hash);
	combined_hash += combined_hash * 0x62531965;
	combined_hash = ROTATE_LEFT(combined_hash, 21);
	combined_hash = combined_hash * tp->carp.load_multiplier;
	debug(39, 3) ("carpSelectParent: %s combined_hash %d\n",
	    tp->host, combined_hash);
	if ((combined_hash > high_score) && neighborUp(tp)) {
	    p = tp;
	    high_score = combined_hash;
	}
    }
    if (p)
	debug(39, 3) ("carpSelectParent: selected CARP %s\n", p->host);
    return p;
}
コード例 #16
0
ファイル: aes128dec.c プロジェクト: zhangdongyue/AES128cbc
/*Shift one row right*/
static int state_shift_row_right(byte_t * state,int n)
{
	if(n>3 || n<0 || !state) 
		return -1;
	if(n==0) return 0;
	word_t * swt = (word_t*)state;
	word_t sw=*swt;
	if(is_big_endian()){
		*swt=ROTATE_RIGHT(sw,32,n*8); 
	}else{
		*swt=ROTATE_LEFT(sw,32,n*8);
	}		

	return 0;
}
コード例 #17
0
int main()
{
  //unsigned int a;
  //scanf("%x", &a);
  //printf("%d\n", sizeof(a));
  //printf("%x\n", a);
  unsigned int a = 23;
  //printf("%c\n", a);  
  //printf("%08x\n", a);  
  //printf("%08x\n", ROTATE_LEFT (a, 8*sizeof(int), 0));
  //printf("%08x\n", ROTATE_LEFT (a, 8*sizeof(int), 0));
  //printf("%08x\n", ROTATE_LEFT (a, 8*sizeof(int), 0));
  printf("%08x\n", ROTATE_LEFT (a, 8*sizeof(int), 4));
  printf("%08x\n", ROTATE_RIGHT(a, 8*sizeof(int), 4));
  printf("%08x\n", ROTATE_RIGHT(a, 8*sizeof(int), 4));
  printf("%08x\n", ROTATE_RIGHT(a, 8*sizeof(int), 4));
  printf("%08x\n", ROTATE_RIGHT(a, 8*sizeof(int), 4));
  
  return 0;
}
コード例 #18
0
ファイル: Md5.c プロジェクト: AshleyDeSimone/edk2
/**
  Perform the MD5 transform on 64 bytes data segment.

  @param[in, out]  Md5Ctx  It includes the data segment for Md5 transform.
**/
VOID
MD5Transform (
  IN OUT MD5_CTX  *Md5Ctx
  )
{
  UINT32  Index1;
  UINT32  Index2;
  UINT32  MedStates[MD5_HASHSIZE >> 2];
  UINT32  *Data;
  UINT32  IndexD;
  UINT32  IndexT;

  Data = (UINT32 *) Md5Ctx->M;

  //
  // Copy MD5 states to MedStates
  //
  CopyMem (MedStates, Md5Ctx->States, MD5_HASHSIZE);

  IndexT = 0;
  for (Index1 = 0; Index1 < 4; Index1++) {
    IndexD = Md5_Data[Index1][0];
    for (Index2 = 16; Index2 > 0; Index2--) {
      SA += (*Md5_F[Index1]) (SB, SC, SD) + Data[IndexD] + Md5_T[IndexT];
      SA  = ROTATE_LEFT (SA, Md5_S[Index1][Index2 & 3]);
      SA += SB;

      IndexD += Md5_Data[Index1][1];
      IndexD &= 15;

      IndexT++;
    }
  }

  for (Index1 = 0; Index1 < 4; Index1++) {
    Md5Ctx->States[Index1] += MedStates[Index1];
  }
}
コード例 #19
0
ファイル: MD5_std.c プロジェクト: 0x0mar/JohnTheRipper
static MAYBE_INLINE_BODY void MD5_body(MD5_word x[15], MD5_word out[4])
#endif
{
    MD5_word a, b = Cb, c = Cc, d;

    /* Round 1 */
    a = AC1 + x[0];
    ROTATE_LEFT (a, S11);
    a += b;			/* 1 */
    d = (c ^ (a & MASK1)) + x[1] + AC2pCd;
    ROTATE_LEFT (d, S12);
    d += a;			/* 2 */
    c = F(d, a, b) + x[2] + AC3pCc;
    ROTATE_LEFT(c, S13);
    c += d;			/* 3 */
    b = F(c, d, a) + x[3] + AC4pCb;
    ROTATE_LEFT(b, S14);
    b += c;			/* 4 */
    FF (a, b, c, d, x[ 4], S11, AC5);		/* 5 */
    FF (d, a, b, c, x[ 5], S12, AC6);		/* 6 */
    FF (c, d, a, b, x[ 6], S13, AC7);		/* 7 */
    FF (b, c, d, a, x[ 7], S14, AC8);		/* 8 */
    FF (a, b, c, d, x[ 8], S11, AC9);		/* 9 */
    FF (d, a, b, c, x[ 9], S12, AC10);		/* 10 */
    FF (c, d, a, b, x[10], S13, AC11);		/* 11 */
    FF (b, c, d, a, x[11], S14, AC12);		/* 12 */
    FF (a, b, c, d, x[12], S11, AC13);		/* 13 */
    FF (d, a, b, c, x[13], S12, AC14);		/* 14 */
    FF (c, d, a, b, x[14], S13, AC15);		/* 15 */
    b += F (c, d, a) + AC16;
    ROTATE_LEFT (b, S14);
    b += c;			/* 16 */

    /* Round 2 */
    GG (a, b, c, d, x[ 1], S21, AC17);		/* 17 */
    GG (d, a, b, c, x[ 6], S22, AC18);		/* 18 */
    GG (c, d, a, b, x[11], S23, AC19);		/* 19 */
    GG (b, c, d, a, x[ 0], S24, AC20);		/* 20 */
    GG (a, b, c, d, x[ 5], S21, AC21);		/* 21 */
    GG (d, a, b, c, x[10], S22, AC22);		/* 22 */
    c += G (d, a, b) + AC23;
    ROTATE_LEFT (c, S23);
    c += d;			/* 23 */
    GG (b, c, d, a, x[ 4], S24, AC24);		/* 24 */
    GG (a, b, c, d, x[ 9], S21, AC25);		/* 25 */
    GG (d, a, b, c, x[14], S22, AC26);		/* 26 */
    GG (c, d, a, b, x[ 3], S23, AC27);		/* 27 */
    GG (b, c, d, a, x[ 8], S24, AC28);		/* 28 */
    GG (a, b, c, d, x[13], S21, AC29);		/* 29 */
    GG (d, a, b, c, x[ 2], S22, AC30);		/* 30 */
    GG (c, d, a, b, x[ 7], S23, AC31);		/* 31 */
    GG (b, c, d, a, x[12], S24, AC32);		/* 32 */

    /* Round 3 */
    HH (a, b, c, d, x[ 5], S31, AC33);		/* 33 */
    HH (d, a, b, c, x[ 8], S32, AC34);		/* 34 */
    HH (c, d, a, b, x[11], S33, AC35);		/* 35 */
    HH (b, c, d, a, x[14], S34, AC36);		/* 36 */
    HH (a, b, c, d, x[ 1], S31, AC37);		/* 37 */
    HH (d, a, b, c, x[ 4], S32, AC38);		/* 38 */
    HH (c, d, a, b, x[ 7], S33, AC39);		/* 39 */
    HH (b, c, d, a, x[10], S34, AC40);		/* 40 */
    HH (a, b, c, d, x[13], S31, AC41);		/* 41 */
    HH (d, a, b, c, x[ 0], S32, AC42);		/* 42 */
    HH (c, d, a, b, x[ 3], S33, AC43);		/* 43 */
    HH (b, c, d, a, x[ 6], S34, AC44);		/* 44 */
    HH (a, b, c, d, x[ 9], S31, AC45);		/* 45 */
    HH (d, a, b, c, x[12], S32, AC46);		/* 46 */
    c += H (d, a, b) + AC47;
    ROTATE_LEFT (c, S33);
    c += d;			/* 47 */
    HH (b, c, d, a, x[ 2], S34, AC48);		/* 48 */

    /* Round 4 */
    II (a, b, c, d, x[ 0], S41, AC49);		/* 49 */
    II (d, a, b, c, x[ 7], S42, AC50);		/* 50 */
    II (c, d, a, b, x[14], S43, AC51);		/* 51 */
    II (b, c, d, a, x[ 5], S44, AC52);		/* 52 */
    II (a, b, c, d, x[12], S41, AC53);		/* 53 */
    II (d, a, b, c, x[ 3], S42, AC54);		/* 54 */
    II (c, d, a, b, x[10], S43, AC55);		/* 55 */
    II (b, c, d, a, x[ 1], S44, AC56);		/* 56 */
    II (a, b, c, d, x[ 8], S41, AC57);		/* 57 */
    d += I (a, b, c) + AC58;
    ROTATE_LEFT (d, S42);
    d += a;			/* 58 */
    II (c, d, a, b, x[ 6], S43, AC59);		/* 59 */
    II (b, c, d, a, x[13], S44, AC60);		/* 60 */
    II (a, b, c, d, x[ 4], S41, AC61);		/* 61 */
    II (d, a, b, c, x[11], S42, AC62);		/* 62 */
    II (c, d, a, b, x[ 2], S43, AC63);		/* 63 */
    II (b, c, d, a, x[ 9], S44, AC64);		/* 64 */

    out[0] = Ca + a;
    out[1] = Cb + b;
    out[2] = Cc + c;
    out[3] = Cd + d;
}
コード例 #20
0
ファイル: md5calc.c プロジェクト: AxlSckay/Ragnarok-OldTimes
static unsigned int Round(unsigned int a, unsigned int b, unsigned int FGHI,
                     unsigned int k, unsigned int s, unsigned int i)
{
   return b + ROTATE_LEFT(a + FGHI + pX[k] + T[i], s);
}
コード例 #21
0
ファイル: rbtree.c プロジェクト: amohtasham/rstm
/* =============================================================================
 * fixAfterDeletion
 * =============================================================================
 */
static void
fixAfterDeletion (rbtree_t* s, node_t* x)
{
    while (x != LDNODE(s,root) && COLOR_OF(x) == BLACK) {
        if (x == LEFT_OF(PARENT_OF(x))) {
            node_t* sib = RIGHT_OF(PARENT_OF(x));
            if (COLOR_OF(sib) == RED) {
                SET_COLOR(sib, BLACK);
                SET_COLOR(PARENT_OF(x), RED);
                ROTATE_LEFT(s, PARENT_OF(x));
                sib = RIGHT_OF(PARENT_OF(x));
            }
            if (COLOR_OF(LEFT_OF(sib)) == BLACK &&
                COLOR_OF(RIGHT_OF(sib)) == BLACK) {
                SET_COLOR(sib, RED);
                x = PARENT_OF(x);
            } else {
                if (COLOR_OF(RIGHT_OF(sib)) == BLACK) {
                    SET_COLOR(LEFT_OF(sib), BLACK);
                    SET_COLOR(sib, RED);
                    ROTATE_RIGHT(s, sib);
                    sib = RIGHT_OF(PARENT_OF(x));
                }
                SET_COLOR(sib, COLOR_OF(PARENT_OF(x)));
                SET_COLOR(PARENT_OF(x), BLACK);
                SET_COLOR(RIGHT_OF(sib), BLACK);
                ROTATE_LEFT(s, PARENT_OF(x));
                /* TODO: consider break ... */
                x = LDNODE(s,root);
            }
        } else { /* symmetric */
            node_t* sib = LEFT_OF(PARENT_OF(x));
            if (COLOR_OF(sib) == RED) {
                SET_COLOR(sib, BLACK);
                SET_COLOR(PARENT_OF(x), RED);
                ROTATE_RIGHT(s, PARENT_OF(x));
                sib = LEFT_OF(PARENT_OF(x));
            }
            if (COLOR_OF(RIGHT_OF(sib)) == BLACK &&
                COLOR_OF(LEFT_OF(sib)) == BLACK) {
                SET_COLOR(sib,  RED);
                x = PARENT_OF(x);
            } else {
                if (COLOR_OF(LEFT_OF(sib)) == BLACK) {
                    SET_COLOR(RIGHT_OF(sib), BLACK);
                    SET_COLOR(sib, RED);
                    ROTATE_LEFT(s, sib);
                    sib = LEFT_OF(PARENT_OF(x));
                }
                SET_COLOR(sib, COLOR_OF(PARENT_OF(x)));
                SET_COLOR(PARENT_OF(x), BLACK);
                SET_COLOR(LEFT_OF(sib), BLACK);
                ROTATE_RIGHT(s, PARENT_OF(x));
                /* TODO: consider break ... */
                x = LDNODE(s, root);
            }
        }
    }

    if (x != NULL && LDF(x,c) != BLACK) {
       STF(x, c, BLACK);
    }
}
コード例 #22
0
ファイル: MD5_std.c プロジェクト: 0x0mar/JohnTheRipper
static MAYBE_INLINE_BODY void MD5_body(MD5_word x0[15], MD5_word x1[15],
                                       MD5_word out0[4], MD5_word out1[4])
#endif
{
    MD5_word a0, b0 = Cb, c0 = Cc, d0;
    MD5_word a1, b1, c1, d1;
    MD5_word u, v;

    /* Round 1 */
    a0 = (u = AC1) + x0[0];
    ROTATE_LEFT (a0, S11);
    a0 += b0;		/* 1 */
    a1 = u + x1[0];
    ROTATE_LEFT (a1, S11);
    a1 += b0;		/* 1 */
    d0 = (c0 ^ (a0 & (u = MASK1))) + x0[1] + (v = AC2pCd);
    ROTATE_LEFT (d0, S12);
    d0 += a0;		/* 2 */
    d1 = (c0 ^ (a1 & u)) + x1[1] + v;
    ROTATE_LEFT (d1, S12);
    d1 += a1;		/* 2 */
    c0 = F(d0, a0, b0) + x0[2] + (u = AC3pCc);
    ROTATE_LEFT(c0, S13);
    c0 += d0;			/* 3 */
    c1 = F(d1, a1, b0) + x1[2] + u;
    ROTATE_LEFT(c1, S13);
    c1 += d1;			/* 3 */
    b0 = F(c0, d0, a0) + x0[3] + (u = AC4pCb);
    ROTATE_LEFT(b0, S14);
    b0 += c0;			/* 4 */
    b1 = F(c1, d1, a1) + x1[3] + u;
    ROTATE_LEFT(b1, S14);
    b1 += c1;			/* 4 */
    FF (a0, b0, c0, d0, x0[ 4], S11, (u = AC5));	/* 5 */
    FF (a1, b1, c1, d1, x1[ 4], S11, u);		/* 5 */
    FF (d0, a0, b0, c0, x0[ 5], S12, (u = AC6));	/* 6 */
    FF (d1, a1, b1, c1, x1[ 5], S12, u);		/* 6 */
    FF (c0, d0, a0, b0, x0[ 6], S13, (u = AC7));	/* 7 */
    FF (c1, d1, a1, b1, x1[ 6], S13, u);		/* 7 */
    FF (b0, c0, d0, a0, x0[ 7], S14, (u = AC8));	/* 8 */
    FF (b1, c1, d1, a1, x1[ 7], S14, u);		/* 8 */
    FF (a0, b0, c0, d0, x0[ 8], S11, (u = AC9));	/* 9 */
    FF (a1, b1, c1, d1, x1[ 8], S11, u);		/* 9 */
    FF (d0, a0, b0, c0, x0[ 9], S12, (u = AC10));	/* 10 */
    FF (d1, a1, b1, c1, x1[ 9], S12, u);		/* 10 */
    FF (c0, d0, a0, b0, x0[10], S13, (u = AC11));	/* 11 */
    FF (c1, d1, a1, b1, x1[10], S13, u);		/* 11 */
    FF (b0, c0, d0, a0, x0[11], S14, (u = AC12));	/* 12 */
    FF (b1, c1, d1, a1, x1[11], S14, u);		/* 12 */
    FF (a0, b0, c0, d0, x0[12], S11, (u = AC13));	/* 13 */
    FF (a1, b1, c1, d1, x1[12], S11, u);		/* 13 */
    FF (d0, a0, b0, c0, x0[13], S12, (u = AC14));	/* 14 */
    FF (d1, a1, b1, c1, x1[13], S12, u);		/* 14 */
    FF (c0, d0, a0, b0, x0[14], S13, (u = AC15));	/* 15 */
    FF (c1, d1, a1, b1, x1[14], S13, u);		/* 15 */
    b0 += F (c0, d0, a0) + (u = AC16);
    ROTATE_LEFT (b0, S14);
    b0 += c0;		/* 16 */
    b1 += F (c1, d1, a1) + u;
    ROTATE_LEFT (b1, S14);
    b1 += c1;		/* 16 */

    /* Round 2 */
    GG (a0, b0, c0, d0, x0[ 1], S21, (u = AC17));	/* 17 */
    GG (a1, b1, c1, d1, x1[ 1], S21, u);		/* 17 */
    GG (d0, a0, b0, c0, x0[ 6], S22, (u = AC18));	/* 18 */
    GG (d1, a1, b1, c1, x1[ 6], S22, u);		/* 18 */
    GG (c0, d0, a0, b0, x0[11], S23, (u = AC19));	/* 19 */
    GG (c1, d1, a1, b1, x1[11], S23, u);		/* 19 */
    GG (b0, c0, d0, a0, x0[ 0], S24, (u = AC20));	/* 20 */
    GG (b1, c1, d1, a1, x1[ 0], S24, u);		/* 20 */
    GG (a0, b0, c0, d0, x0[ 5], S21, (u = AC21));	/* 21 */
    GG (a1, b1, c1, d1, x1[ 5], S21, u);		/* 21 */
    GG (d0, a0, b0, c0, x0[10], S22, (u = AC22));	/* 22 */
    GG (d1, a1, b1, c1, x1[10], S22, u);		/* 22 */
    c0 += G (d0, a0, b0) + (u = AC23);
    ROTATE_LEFT (c0, S23);
    c0 += d0;		/* 23 */
    c1 += G (d1, a1, b1) + u;
    ROTATE_LEFT (c1, S23);
    c1 += d1;		/* 23 */
    GG (b0, c0, d0, a0, x0[ 4], S24, (u = AC24));	/* 24 */
    GG (b1, c1, d1, a1, x1[ 4], S24, u);		/* 24 */
    GG (a0, b0, c0, d0, x0[ 9], S21, (u = AC25));	/* 25 */
    GG (a1, b1, c1, d1, x1[ 9], S21, u);		/* 25 */
    GG (d0, a0, b0, c0, x0[14], S22, (u = AC26));	/* 26 */
    GG (d1, a1, b1, c1, x1[14], S22, u);		/* 26 */
    GG (c0, d0, a0, b0, x0[ 3], S23, (u = AC27));	/* 27 */
    GG (c1, d1, a1, b1, x1[ 3], S23, u);		/* 27 */
    GG (b0, c0, d0, a0, x0[ 8], S24, (u = AC28));	/* 28 */
    GG (b1, c1, d1, a1, x1[ 8], S24, u);		/* 28 */
    GG (a0, b0, c0, d0, x0[13], S21, (u = AC29));	/* 29 */
    GG (a1, b1, c1, d1, x1[13], S21, u);		/* 29 */
    GG (d0, a0, b0, c0, x0[ 2], S22, (u = AC30));	/* 30 */
    GG (d1, a1, b1, c1, x1[ 2], S22, u);		/* 30 */
    GG (c0, d0, a0, b0, x0[ 7], S23, (u = AC31));	/* 31 */
    GG (c1, d1, a1, b1, x1[ 7], S23, u);		/* 31 */
    GG (b0, c0, d0, a0, x0[12], S24, (u = AC32));	/* 32 */
    GG (b1, c1, d1, a1, x1[12], S24, u);		/* 32 */

    /* Round 3 */
    HH (a0, b0, c0, d0, x0[ 5], S31, (u = AC33));	/* 33 */
    HH (a1, b1, c1, d1, x1[ 5], S31, u);		/* 33 */
    HH (d0, a0, b0, c0, x0[ 8], S32, (u = AC34));	/* 34 */
    HH (d1, a1, b1, c1, x1[ 8], S32, u);		/* 34 */
    HH (c0, d0, a0, b0, x0[11], S33, (u = AC35));	/* 35 */
    HH (c1, d1, a1, b1, x1[11], S33, u);		/* 35 */
    HH (b0, c0, d0, a0, x0[14], S34, (u = AC36));	/* 36 */
    HH (b1, c1, d1, a1, x1[14], S34, u);		/* 36 */
    HH (a0, b0, c0, d0, x0[ 1], S31, (u = AC37));	/* 37 */
    HH (a1, b1, c1, d1, x1[ 1], S31, u);		/* 37 */
    HH (d0, a0, b0, c0, x0[ 4], S32, (u = AC38));	/* 38 */
    HH (d1, a1, b1, c1, x1[ 4], S32, u);		/* 38 */
    HH (c0, d0, a0, b0, x0[ 7], S33, (u = AC39));	/* 39 */
    HH (c1, d1, a1, b1, x1[ 7], S33, u);		/* 39 */
    HH (b0, c0, d0, a0, x0[10], S34, (u = AC40));	/* 40 */
    HH (b1, c1, d1, a1, x1[10], S34, u);		/* 40 */
    HH (a0, b0, c0, d0, x0[13], S31, (u = AC41));	/* 41 */
    HH (a1, b1, c1, d1, x1[13], S31, u);		/* 41 */
    HH (d0, a0, b0, c0, x0[ 0], S32, (u = AC42));	/* 42 */
    HH (d1, a1, b1, c1, x1[ 0], S32, u);		/* 42 */
    HH (c0, d0, a0, b0, x0[ 3], S33, (u = AC43));	/* 43 */
    HH (c1, d1, a1, b1, x1[ 3], S33, u);		/* 43 */
    HH (b0, c0, d0, a0, x0[ 6], S34, (u = AC44));	/* 44 */
    HH (b1, c1, d1, a1, x1[ 6], S34, u);		/* 44 */
    HH (a0, b0, c0, d0, x0[ 9], S31, (u = AC45));	/* 45 */
    HH (a1, b1, c1, d1, x1[ 9], S31, u);		/* 45 */
    HH (d0, a0, b0, c0, x0[12], S32, (u = AC46));	/* 46 */
    HH (d1, a1, b1, c1, x1[12], S32, u);		/* 46 */
    c0 += H (d0, a0, b0) + (u = AC47);
    ROTATE_LEFT (c0, S33);
    c0 += d0;		/* 47 */
    c1 += H (d1, a1, b1) + u;
    ROTATE_LEFT (c1, S33);
    c1 += d1;		/* 47 */
    HH (b0, c0, d0, a0, x0[ 2], S34, (u = AC48));	/* 48 */
    HH (b1, c1, d1, a1, x1[ 2], S34, u);		/* 48 */

    /* Round 4 */
    II (a0, b0, c0, d0, x0[ 0], S41, (u = AC49));	/* 49 */
    II (a1, b1, c1, d1, x1[ 0], S41, u);		/* 49 */
    II (d0, a0, b0, c0, x0[ 7], S42, (u = AC50));	/* 50 */
    II (d1, a1, b1, c1, x1[ 7], S42, u);		/* 50 */
    II (c0, d0, a0, b0, x0[14], S43, (u = AC51));	/* 51 */
    II (c1, d1, a1, b1, x1[14], S43, u);		/* 51 */
    II (b0, c0, d0, a0, x0[ 5], S44, (u = AC52));	/* 52 */
    II (b1, c1, d1, a1, x1[ 5], S44, u);		/* 52 */
    II (a0, b0, c0, d0, x0[12], S41, (u = AC53));	/* 53 */
    II (a1, b1, c1, d1, x1[12], S41, u);		/* 53 */
    II (d0, a0, b0, c0, x0[ 3], S42, (u = AC54));	/* 54 */
    II (d1, a1, b1, c1, x1[ 3], S42, u);		/* 54 */
    II (c0, d0, a0, b0, x0[10], S43, (u = AC55));	/* 55 */
    II (c1, d1, a1, b1, x1[10], S43, u);		/* 55 */
    II (b0, c0, d0, a0, x0[ 1], S44, (u = AC56));	/* 56 */
    II (b1, c1, d1, a1, x1[ 1], S44, u);		/* 56 */
    II (a0, b0, c0, d0, x0[ 8], S41, (u = AC57));	/* 57 */
    II (a1, b1, c1, d1, x1[ 8], S41, u);		/* 57 */
    d0 += I (a0, b0, c0) + (u = AC58);
    ROTATE_LEFT (d0, S42);
    d0 += a0;		/* 58 */
    d1 += I (a1, b1, c1) + u;
    ROTATE_LEFT (d1, S42);
    d1 += a1;		/* 58 */
    II (c0, d0, a0, b0, x0[ 6], S43, (u = AC59));	/* 59 */
    II (c1, d1, a1, b1, x1[ 6], S43, u);		/* 59 */
    II (b0, c0, d0, a0, x0[13], S44, (u = AC60));	/* 60 */
    II (b1, c1, d1, a1, x1[13], S44, u);		/* 60 */
    II (a0, b0, c0, d0, x0[ 4], S41, (u = AC61));	/* 61 */
    II (a1, b1, c1, d1, x1[ 4], S41, u);		/* 61 */
    II (d0, a0, b0, c0, x0[11], S42, (u = AC62));	/* 62 */
    II (d1, a1, b1, c1, x1[11], S42, u);		/* 62 */
    II (c0, d0, a0, b0, x0[ 2], S43, (u = AC63));	/* 63 */
    II (c1, d1, a1, b1, x1[ 2], S43, u);		/* 63 */
    II (b0, c0, d0, a0, x0[ 9], S44, (u = AC64));	/* 64 */
    II (b1, c1, d1, a1, x1[ 9], S44, u);		/* 64 */

    out1[3] = Cd + d1;

    out0[0] = Ca + a0;
    out0[1] = Cb + b0;
    out0[2] = Cc + c0;
    out0[3] = Cd + d0;

    out1[0] = Ca + a1;
    out1[1] = Cb + b1;
    out1[2] = Cc + c1;
}
コード例 #23
0
ファイル: md5.cpp プロジェクト: zjutchenjm/MD5Encryption
*/
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
#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)))

/* ROTATE_LEFT rotates x left n bits.
*/
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))

/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
Rotation is separate from addition to prevent recomputation.
*/
#define FF(a, b, c, d, x, s, ac) { 
(a) += F((b), (c), (d)) + (x)+(UINT4)(ac);
(a) = ROTATE_LEFT((a), (s));
(a) += (b);
}
#define GG(a, b, c, d, x, s, ac) { 
	(a) += G((b), (c), (d)) + (x)+(UINT4)(ac);
	(a) = ROTATE_LEFT((a), (s));
	(a) += (b);
}
#define HH(a, b, c, d, x, s, ac) { 
(a) += H((b), (c), (d)) + (x)+(UINT4)(ac);
(a) = ROTATE_LEFT((a), (s));
(a) += (b);
	}
#define II(a, b, c, d, x, s, ac) { 
(a) += I((b), (c), (d)) + (x)+(UINT4)(ac);
(a) = ROTATE_LEFT((a), (s));
コード例 #24
0
void
peerSourceHashInit(void)
{
    int W = 0;
    int K;
    int k;
    double P_last, X_last, Xn;
    peer *p;
    peer **P;
    char *t;
    /* Clean up */
    for (k = 0; k < n_sourcehash_peers; k++) {
	cbdataUnlock(sourcehash_peers[k]);
    }
    safe_free(sourcehash_peers);
    n_sourcehash_peers = 0;
    /* find out which peers we have */
    for (p = Config.peers; p; p = p->next) {
	if (!p->options.sourcehash)
	    continue;
	assert(p->type == PEER_PARENT);
	if (p->weight == 0)
	    continue;
	n_sourcehash_peers++;
	W += p->weight;
    }
    if (n_sourcehash_peers == 0)
	return;
    sourcehash_peers = xcalloc(n_sourcehash_peers, sizeof(*sourcehash_peers));
    /* Build a list of the found peers and calculate hashes and load factors */
    for (P = sourcehash_peers, p = Config.peers; p; p = p->next) {
	if (!p->options.sourcehash)
	    continue;
	if (p->weight == 0)
	    continue;
	/* calculate this peers hash */
	p->sourcehash.hash = 0;
	for (t = p->host; *t != 0; t++)
	    p->sourcehash.hash += ROTATE_LEFT(p->sourcehash.hash, 19) + (unsigned int) *t;
	p->sourcehash.hash += p->sourcehash.hash * 0x62531965;
	p->sourcehash.hash = ROTATE_LEFT(p->sourcehash.hash, 21);
	/* and load factor */
	p->sourcehash.load_factor = ((double) p->weight) / (double) W;
	if (floor(p->sourcehash.load_factor * 1000.0) == 0.0)
	    p->sourcehash.load_factor = 0.0;
	/* add it to our list of peers */
	*P++ = p;
	cbdataLock(p);
    }
    /* Sort our list on weight */
    qsort(sourcehash_peers, n_sourcehash_peers, sizeof(*sourcehash_peers), peerSortWeight);
    /* Calculate the load factor multipliers X_k
     *
     * X_1 = pow ((K*p_1), (1/K))
     * X_k = ([K-k+1] * [P_k - P_{k-1}])/(X_1 * X_2 * ... * X_{k-1})
     * X_k += pow ((X_{k-1}, {K-k+1})
     * X_k = pow (X_k, {1/(K-k+1)})
     * simplified to have X_1 part of the loop
     */
    K = n_sourcehash_peers;
    P_last = 0.0;		/* Empty P_0 */
    Xn = 1.0;			/* Empty starting point of X_1 * X_2 * ... * X_{x-1} */
    X_last = 0.0;		/* Empty X_0, nullifies the first pow statement */
    for (k = 1; k <= K; k++) {
	double Kk1 = (double) (K - k + 1);
	p = sourcehash_peers[k - 1];
	p->sourcehash.load_multiplier = (Kk1 * (p->sourcehash.load_factor - P_last)) / Xn;
	p->sourcehash.load_multiplier += pow(X_last, Kk1);
	p->sourcehash.load_multiplier = pow(p->sourcehash.load_multiplier, 1.0 / Kk1);
	Xn *= p->sourcehash.load_multiplier;
	X_last = p->sourcehash.load_multiplier;
	P_last = p->sourcehash.load_factor;
    }
}