void BitcoinSha256::PrepareData(const void *midstate, const void *data, const void *hash1) { memcpy(m_midstate, midstate, sizeof m_midstate); memcpy(m_w, data, 16*sizeof(uint32_t)); CalcW(m_w, 16); CalcW(m_w, 17); memcpy(m_midstate_after_3, m_midstate, sizeof m_midstate); CalcRounds(m_w, m_midstate, m_midstate_after_3, 18, 0, 3); { uint32_t a = m_midstate_after_3[0], b = m_midstate_after_3[1], c = m_midstate_after_3[2], d = m_midstate_after_3[3], e = m_midstate_after_3[4], f = m_midstate_after_3[5], g = m_midstate_after_3[6], h = m_midstate_after_3[7]; m_preVal4 = h + (Rotr32(e, 6) ^ Rotr32(e, 11) ^ Rotr32(e, 25)) + ((e & f) ^ AndNot(e, g)) + g_sha256_k[3]; m_t1 = (Rotr32(a, 2) ^ Rotr32(a, 13) ^ Rotr32(a, 22)) + ((a & b) ^ (b & c) ^ (a & c)); } memcpy(m_w1, hash1, 16*sizeof(uint32_t)); /*!!! uint32_t bits = 256; *(byte*)&m_w1[8] = 0x80; byte *p = (byte*)&m_w1[63]+3; // swap for LE-processing. Original SHA-2 is BE p[3] = byte(bits >> 24); p[2] = byte(bits >> 16); p[1] = byte(bits >> 8); p[0] = byte(bits); */ }
static int multiUnitReduce( a_state *state, a_reduce_action *raction, a_pro *pro, a_word *reduce_set ) { a_pro *new_pro; /* requirements: (1) state must have a reduction by a unit production (L1 <- r1) on a set of tokens (s) (2) all parents must reduce by an unit production (L2 <- L1) on a set of tokens (t) action: change state to reduce (L2<-r1) instead of (L1<-r1) on t (if s != t, we have to add a new reduce action) */ Assign( reduce_set, raction->follow ); new_pro = analyseParents( state, pro, reduce_set ); if( new_pro != NULL ) { /* parents satisfied all the conditions */ if( Equal( reduce_set, raction->follow ) ) { raction->pro = new_pro; } else { AndNot( raction->follow, reduce_set ); state->redun = addReduceAction( new_pro, reduce_set, state->redun ); } ++changeOccurred; return( 1 ); } return( 0 ); }
static AddError() { a_sym *xsym, *sym; a_pro *xpro, *pro; a_state *x, **s, **t, *AddErrState(); a_shift_action *tx, *ty, *trans; a_reduce_action *rx, *ry, *redun; int i; a_word *defined, *conflict, *rset; short int *at; trans = CALLOC( nsym, a_shift_action ); rx = redun = CALLOC( npro + 1, a_reduce_action ); rset = conflict = AllocSet( npro + 2 ); for( i = 0; i <= npro; ++i ) { (rx++)->follow = rset; rset += GetSetSize( 1 ); } defined = rset; s = CALLOC( nstate, a_state * ); at = CALLOC( nstate, short int ); s = t = CALLOC( nstate + 1, a_state * ); for( x = statelist; x != NULL; x = x->next ) { Mark( *x ); *t++ = x; } restart = AddErrState( &errsym->enter, s, t ); for( x = restart; x != NULL; x = x->next ) { Clear( defined ); Clear( conflict ); xpro = NULL; for( i = 0; i < x->kersize; ++i ) { at[i] = 0; pro = x->name.state[i]->redun->pro; if( pro > xpro ) { xpro = pro; } } redun->pro = errpro; rx = redun + 1; if( x != restart ) while( xpro ) { pro = xpro; xpro = NULL; Clear( rx->follow ); for( i = 0; i < x->kersize; ++i ) { ry = &x->name.state[i]->redun[at[i]]; if( ry->pro == pro ) { Union( rx->follow, ry->follow ); ++(at[i]); ++ry; } if( ry->pro > xpro ) { xpro = ry->pro; } } UnionAnd( conflict, rx->follow, defined ); Union( defined, rx->follow ); rx->pro = pro; ++rx; } xsym = NULL; for( i = 0; i < x->kersize; ++i ) { at[i] = 0; sym = x->name.state[i]->trans->sym; if( sym > xsym ) { xsym = sym; } } tx = trans; while( xsym ) { sym = xsym; xsym = NULL; t = s; for( i = 0; i < x->kersize; ++i ) { ty = &x->name.state[i]->trans[at[i]]; if( ty->sym == sym ) { if( !IsMarked( *ty->state ) ) { Mark( *ty->state ); *t++ = ty->state; } ++(at[i]); ++ty; } if( ty->sym > xsym ) { xsym = ty->sym; } } tx->sym = sym; if( sym->pro != NULL ) { ++nvtrans; } else { if( IsBitSet( defined, sym->id ) ) { SetBit( conflict, sym->id ); while( --t >= s ) { Unmark( **t ); } continue; } else { SetBit( defined, sym->id ); } } tx->state = AddErrState( &errsym->enter, s, t ); ++tx; } x->trans = CALLOC( tx - trans + 1, a_shift_action ); memcpy( x->trans, trans, ((char *) tx) - ((char *) trans) ); if( Empty( conflict ) ) { redun->pro = NULL; i = 0; } else { i = 1; } while( --rx > redun ) { AndNot( rx->follow, conflict ); if( Empty( rx->follow ) ) { rx->pro = NULL; } else { ++i; } } x->redun = CALLOC( i + 1, a_reduce_action ); if( i ) { rset = AllocSet( i ); rx = redun; while( i > 0 ) { if( rx->pro != NULL ) { --i; x->redun[i].pro = rx->pro; x->redun[i].follow = rset; Assign( rset, rx->follow ); rset += GetSetSize( 1 ); } ++rx; } } } FREE( trans ); FREE( redun ); FREE( conflict ); FREE( s ); FREE( at ); }