static void sha256_block(sha256_ctx *p) { unsigned i; uint32_t s0, s1; uint32_t a, b, c, d, e, f, g, h; uint32_t t1, t2, maj, ch; for(i = 0; i < 16; i++) p->w[i] = LD32BE(p->in + i * 4); for(i = 16; i < 64; i++) { s0 = ROR32(p->w[i - 15], 7) ^ ROR32(p->w[i - 15], 18) ^ LSR32(p->w[i - 15], 3); s1 = ROR32(p->w[i - 2], 17) ^ ROR32(p->w[i - 2], 19) ^ LSR32(p->w[i - 2], 10); p->w[i] = p->w[i - 16] + s0 + p->w[i - 7] + s1; } a = p->h[0]; b = p->h[1]; c = p->h[2]; d = p->h[3]; e = p->h[4]; f = p->h[5]; g = p->h[6]; h = p->h[7]; for(i = 0; i < 64; i++) { s0 = ROR32(a, 2) ^ ROR32(a, 13) ^ ROR32(a, 22); maj = (a & b) ^ (a & c) ^ (b & c); t2 = s0 + maj; s1 = ROR32(e, 6) ^ ROR32(e, 11) ^ ROR32(e, 25); ch = (e & f) ^ (~e & g); t1 = h + s1 + ch + T_K[i] + p->w[i]; h = g; g = f; f = e; e = d + t1; d = c; c = b; b = a; a = t1 + t2; } p->h[0] += a; p->h[1] += b; p->h[2] += c; p->h[3] += d; p->h[4] += e; p->h[5] += f; p->h[6] += g; p->h[7] += h; //next block p->inlen = 0; }
void AES128::ShiftRows( unsigned char *m ) { register unsigned int * m32 = ( unsigned int * ) m; // m32[0] = ROR32(m32[0], 0); m32[ 1 ] = ROR32( m32[ 1 ], 8 ); m32[ 2 ] = ROR32( m32[ 2 ], 16 ); m32[ 3 ] = ROR32( m32[ 3 ], 24 ); }
void rc6DecryptBlock(Rc6Context *context, const uint8_t *input, uint8_t *output) { uint_t i; uint32_t t; uint32_t u; //Load the 4 working registers with the ciphertext uint32_t a = LOAD32LE(input + 0); uint32_t b = LOAD32LE(input + 4); uint32_t c = LOAD32LE(input + 8); uint32_t d = LOAD32LE(input + 12); //First, update C and A c -= context->s[2 * RC6_NB_ROUNDS + 3]; a -= context->s[2 * RC6_NB_ROUNDS + 2]; //Apply 20 rounds for(i = RC6_NB_ROUNDS; i > 0; i--) { t = d; d = c; c = b; b = a; a = t; u = (d * (2 * d + 1)); u = ROL32(u, 5); t = (b * (2 * b + 1)); t = ROL32(t, 5); c -= context->s[2 * i + 1]; c = ROR32(c, t % 32) ^ u; a -= context->s[2 * i]; a = ROR32(a, u % 32) ^ t; } //Update D and B d -= context->s[1]; b -= context->s[0]; //The resulting value is the plaintext STORE32LE(a, output + 0); STORE32LE(b, output + 4); STORE32LE(c, output + 8); STORE32LE(d, output + 12); }
__inline VOID HwMICBlock( PULONG L, PULONG R ) { *R ^= ROL32(*L, 17); *L += *R; *R ^= ((*L & 0xff00ff00) >> 8) | ((*L & 0x00ff00ff) << 8); *L += *R; *R ^= ROL32(*L, 3); *L += *R; *R ^= ROR32(*L, 2); *L += *R; }
static void s_vAppendByte(BYTE b) { /* Append the byte to our word-sized buffer */ M |= b << (8*nBytesInM); nBytesInM++; /* Process the word if it is full. */ if (nBytesInM >= 4) { L ^= M; R ^= ROL32(L, 17); L += R; R ^= ((L & 0xff00ff00) >> 8) | ((L & 0x00ff00ff) << 8); L += R; R ^= ROL32(L, 3); L += R; R ^= ROR32(L, 2); L += R; /* Clear the buffer */ M = 0; nBytesInM = 0; }
VOID mic_appendByte(PMICHAEL_T pmic,UINT8 b ) { // Append the byte to our word-sized buffer pmic->M |= b << (8*pmic->nBytesInM); pmic->nBytesInM++; // Process the word if it is full. if( pmic->nBytesInM >= 4 ) { pmic->L ^= pmic->M; pmic->R ^= ROL32( pmic->L, 17 ); pmic->L += pmic->R; pmic->R ^= ((pmic->L & 0xff00ff00) >> 8) | ((pmic->L & 0x00ff00ff) << 8); pmic->L += pmic->R; pmic->R ^= ROL32( pmic->L, 3 ); pmic->L += pmic->R; pmic->R ^= ROR32( pmic->L, 2 ); pmic->L += pmic->R; // Clear the buffer pmic->M = 0; pmic->nBytesInM = 0; }
static VOID s_vAppendByte (BYTE b) { M |= b << (8*nBytesInM); nBytesInM++; if( nBytesInM >= 4 ) { L ^= M; R ^= ROL32( L, 17 ); L += R; R ^= ((L & 0xff00ff00) >> 8) | ((L & 0x00ff00ff) << 8); L += R; R ^= ROL32( L, 3 ); L += R; R ^= ROR32( L, 2 ); L += R; M = 0; nBytesInM = 0; }
/* ======================================================================== Routine Description: Calculate the MIC Value. Arguments: pAd Pointer to our adapter uChar Append this uChar Return Value: None IRQL = DISPATCH_LEVEL Note: ======================================================================== */ void RTMPTkipAppendByte(struct rt_tkip_key_info *pTkip, u8 uChar) { /* Append the byte to our word-sized buffer */ pTkip->M |= (uChar << (8 * pTkip->nBytesInM)); pTkip->nBytesInM++; /* Process the word if it is full. */ if (pTkip->nBytesInM >= 4) { pTkip->L ^= pTkip->M; pTkip->R ^= ROL32(pTkip->L, 17); pTkip->L += pTkip->R; pTkip->R ^= ((pTkip->L & 0xff00ff00) >> 8) | ((pTkip-> L & 0x00ff00ff) << 8); pTkip->L += pTkip->R; pTkip->R ^= ROL32(pTkip->L, 3); pTkip->L += pTkip->R; pTkip->R ^= ROR32(pTkip->L, 2); pTkip->L += pTkip->R; /* Clear the buffer */ pTkip->M = 0; pTkip->nBytesInM = 0; }
/* ======================================================================== Routine Description: Calculate the MIC Value. Arguments: pAd Pointer to our adapter uChar Append this uChar Return Value: None IRQL = DISPATCH_LEVEL Note: ======================================================================== */ VOID RTMPTkipAppendByte( IN PTKIP_KEY_INFO pTkip, IN UCHAR uChar) { /* Append the byte to our word-sized buffer */ pTkip->M |= (uChar << (8* pTkip->nBytesInM)); pTkip->nBytesInM++; /* Process the word if it is full. */ if( pTkip->nBytesInM >= 4 ) { pTkip->L ^= pTkip->M; pTkip->R ^= ROL32( pTkip->L, 17 ); pTkip->L += pTkip->R; pTkip->R ^= ((pTkip->L & 0xff00ff00) >> 8) | ((pTkip->L & 0x00ff00ff) << 8); pTkip->L += pTkip->R; pTkip->R ^= ROL32( pTkip->L, 3 ); pTkip->L += pTkip->R; pTkip->R ^= ROR32( pTkip->L, 2 ); pTkip->L += pTkip->R; /* Clear the buffer */ pTkip->M = 0; pTkip->nBytesInM = 0; }
VOID RTMPTkipAppendByte( IN PTKIP_KEY_INFO pTkip, IN UCHAR uChar) { pTkip->M |= (uChar << (8* pTkip->nBytesInM)); pTkip->nBytesInM++; if( pTkip->nBytesInM >= 4 ) { pTkip->L ^= pTkip->M; pTkip->R ^= ROL32( pTkip->L, 17 ); pTkip->L += pTkip->R; pTkip->R ^= ((pTkip->L & 0xff00ff00) >> 8) | ((pTkip->L & 0x00ff00ff) << 8); pTkip->L += pTkip->R; pTkip->R ^= ROL32( pTkip->L, 3 ); pTkip->L += pTkip->R; pTkip->R ^= ROR32( pTkip->L, 2 ); pTkip->L += pTkip->R; pTkip->M = 0; pTkip->nBytesInM = 0; }
__INLINE void invShiftRows(Ipp32u* state) { state[1] = ROR32(state[1], 24); state[2] = ROR32(state[2], 16); state[3] = ROR32(state[3], 8); }