rgb_color AmTrackDataView::EventColor(uint8 velocity) { if (velocity >= 127) return mEventColor; if (velocity <= 0) return mLowEventColor; rgb_color c; mix_in(mLowEventColor, mEventColor, (float)velocity / 127, c); return c; }
void AmTrackDataView::DrawTrack(const AmTrack* track, BRect clip, BView* view, int32 properties, AmSelectionsI* selections) { AmTime start = mMtc.PixelToTick(clip.left - 2); AmTime end = mMtc.PixelToTick(clip.right + 2); AmNode* n = track->Phrases().HeadNode(); while (n && n->Event() && n->StartTime() <= end) { if (n->EndTime() >= start) { if (n->Event()->Type() == n->Event()->PHRASE_TYPE) { AmPhraseEvent* pe = dynamic_cast<AmPhraseEvent*>( n->Event() ); if (pe && pe->Phrase() ) { mEventColor = pe->Phrase()->Color(AmPhrase::FOREGROUND_C); mix_in(mEventColor, AmPrefs().Color(AM_DATA_BG_C), 0.75, mLowEventColor); DrawPhrase(clip, view, track->Id(), *pe, pe, start, end, properties, selections); } } } n = n->next; } }
int crypto_aead_decrypt( unsigned char *m,unsigned long long *outputmlen, unsigned char *nsec, const unsigned char *c,unsigned long long clen, const unsigned char *ad,unsigned long long adlen, const unsigned char *npub, const unsigned char *k ) { u64 mlen, n, origmlen, start ; const byte *ptr, *origc; byte temp[AES_BYTES], *p ; int i ; assert( m != NULL ) ; assert( outputmlen != NULL ) ; assert( c != NULL ) ; assert( ad != NULL ) ; assert( npub != NULL ) ; assert( k != NULL ) ; if( clen < AUTH_BYTES) return -1; /* where auth data should be */ mlen = clen - AUTH_BYTES ; ptr = c + mlen ; *outputmlen = mlen; setup(mlen, adlen, npub, k) ; do_additional( ad, adlen ) ; origc = c; origmlen = mlen; #ifdef TESTING printf("decrypt: total %llu text %llu ad %llu\n", clen, mlen, adlen ) ; printf("decrypt: ciphertext starts with %08xu\n", ((u32 *) origc)[0] ) ; printf("decrypt: starting authentication check %08x\n", ((u32 *) ptr)[0] ) ; #endif /* authenticate */ start = mlen ; while( (mlen > 0) && (mlen <= start) ) { n = (u64) ((mlen >= AES_BYTES) ? AES_BYTES : mlen) ; addmul( (byte *) accum, c, n, (byte *) H) ; c += n; mlen -= n; } if( mlen > start ) { #ifdef TESTING printf("decrypt: mlen out of bounds\n" ) ; #endif return -2 ; } #ifdef TESTING printf("decrypt: auth before finalisation %08x %08x\n", accum[0], accum[1] ) ; #endif mix_in(finalblock) ; xor_128( accum, I ) ; /* see if we have a match */ if( memcmp((void *) accum, (void *) ptr, AUTH_BYTES) != 0) { #ifdef TESTING printf("decrypt: auth failed, result here %08x\n", accum[0] ) ; #endif return -3; } #ifdef TESTING printf("decrypt: auth matched, going to decrypt\n" ) ; printf("decrypt: 1st ciphertext word %08x\n", *((u32 *) c) ) ; #endif /* reset things start encryption with correct ChaCha state */ c = origc; mlen = origmlen; setup(mlen, adlen, npub, k) ; /* decrypt, simpler than encryption no authentication to do */ start = mlen ; while( (mlen > 0) && (mlen <= start) ) { n = (u64) ((mlen >= AES_BYTES)? AES_BYTES : mlen) ; white_aes( temp ) ; for( i = 0, p = temp ; i < n ; i++, c++, m++, p++ ) *m = *c ^ *p ; mlen -= n; } if( mlen > start ) { #ifdef TESTING printf("decrypt: mlen out of bounds\n" ) ; #endif return -2 ; } #ifdef TESTING printf("decrypt: reached end, showing first words\n" ) ; printf("plaintext %08x ciphertext %08x auth %08x\n",*((u32 *) m), *((u32 *) c), accum[0] ) ; #endif memset( temp, 0, AES_BYTES ) ; cleanup() ; return 0; }
/* declarations for this and decrypt copied from Bernstein's example AES-GCM code to be sure they match test framework */ int crypto_aead_encrypt( unsigned char *c,unsigned long long *clen, const unsigned char *m, unsigned long long mlen, const unsigned char *ad,unsigned long long adlen, const unsigned char *nsec, const unsigned char *npub, const unsigned char *k ) { u64 n, start ; byte temp[AES_BYTES] ; byte *p, *q, *ptr ; int i ; #ifdef TESTING byte *origm, *origc ; assert( c != NULL ) ; /* are framework declarations compatible with mine? */ assert( sizeof(long long) == sizeof( u64) ) ; printf("encrypt: plaintext %llu ad %llu\n", mlen, adlen ) ; origm = m ; origc = c ; #endif /* Bernstein's example aes-gcm code sets *clen I copy that, assuming the interface needs it */ *clen = mlen+AUTH_BYTES ; /* address for authentication data */ ptr = c + mlen ; /* key schedule */ setup( mlen, (u64) adlen, npub, k) ; /* data authenticated but not encrypted */ do_additional( ad, (u64) adlen ) ; /* encryption mlen is unsigned so always > = 0 use start for an error check */ start = mlen ; while( (mlen != 0) && (mlen <= start) ) { n = (u64) ((mlen >= AES_BYTES)? AES_BYTES : mlen) ; white_aes( temp ) ; for( i = 0, p = temp, q = c ; i < n ; i++, q++, m++, p++ ) *q = *m ^ *p ; addmul( (byte *) accum, c, n, (byte *) H) ; mlen -= n; c += n ; } if( mlen > start ) { #ifdef TESTING printf("encrypt: mlen out of bounds\n" ) ; #endif return -2 ; } #ifdef TESTING printf("encrypt: auth before finalisation %08x %08x\n", accum[0], accum[1] ) ; #endif /* finish authentication */ mix_in(finalblock) ; xor_128( accum, I ) ; memcpy( ptr, (void *) accum, AES_BYTES ) ; #ifdef TESTING printf("encrypt: reached end, showing first words\n" ) ; printf("plaintext %08x ciphertext %08x auth %08x\n", *((u32 *) origm), *((u32 *) origc), accum[0] ) ; #endif memset( temp, 0, AES_BYTES ) ; cleanup() ; return 0 ; }