/* q*t + r == s [e.g. s/t, q=quotient, r=remainder]. */ static void ccn_divn(cc_size nqs, cc_unit *q, cc_unit *r, const cc_unit *s, size_t nrt, cc_unit *t) { if (ccn_is_zero(nrt, t)) { /* Division by zero is illegal. */ return; } /* If s < t then q = 0, r = s */ if (ccn_cmpn(nqs, s, nrt, t) < 0) { if (r) ccn_setn(nrt, r, CC_MIN(nrt, nqs), s); if (q) ccn_zero(nqs, q); return; } /* s >= t => k >= 0 */ size_t k = ccn_bitlen(nqs, s); size_t l = ccn_bitlen(nrt, t); assert(k >= l); k -= l; cc_unit tr[nqs]; cc_unit tt[nqs]; cc_unit tq[nqs]; ccn_set(nqs, tr, s); ccn_setn(nqs, tt, nrt, t); ccn_shift_left_multi(nqs, tt, tt, k); ccn_zero(nqs, tq); for (;;) { if (ccn_cmp(nqs, tr, tt) >= 0) { ccn_sub(nqs, tr, tr, tt); ccn_set_bit(tq, k, 1); } if (!k) break; --k; ccn_shift_right(nqs, tt, tt, 1); } if (r) { ccn_setn(nrt, r, CC_MIN(nrt, nqs), tr); } if (q) { ccn_set(nqs, q, tq); } }
bool CCControlPotentiometer::isTouchInside(CCTouch * touch) { CCPoint touchLocation = this->getTouchLocation(touch); float distance = this->distanceBetweenPointAndPoint(m_pProgressTimer->getPosition(), touchLocation); return distance < CC_MIN(getContentSize().width / 2, getContentSize().height / 2); }
void ccmode_ctr_crypt(ccctr_ctx *key, size_t nbytes, const void *in, void *out) { const struct ccmode_ecb *ecb = CCMODE_CTR_KEY_ECB(key); const ccecb_ctx *ecb_key = CCMODE_CTR_KEY_ECB_KEY(key); uint8_t *ctr = (uint8_t *)CCMODE_CTR_KEY_CTR(key); uint8_t *pad = (uint8_t *)CCMODE_CTR_KEY_PAD(key); cc_size pad_len = CCMODE_CTR_KEY_PAD_LEN(key); const uint8_t *pt = in; // Counter is 64bit wide for cipher with block size of 64bit or more // This is to match the assembly const size_t counter_size=(CC_MIN(ecb->block_size,(typeof(ecb->block_size))8)); uint8_t *ct = out; while (nbytes) { if (pad_len == ecb->block_size) { ecb->ecb(ecb_key, 1, ctr, pad); pad_len = 0; /* increment the big endian counter */ for (size_t x = ecb->block_size; x-- > (ecb->block_size-counter_size);) { ctr[x] = (ctr[x] + (unsigned char)1) & (unsigned char)255; if (ctr[x] != (unsigned char)0) { break; } } if (nbytes==0) break; } /* TODO: Make sure this works. If pt and ct aren't aligned this might not work right. */ #if 0 if (pad_len == 0 && nbytes >= ecb->block_size) { ccn_xor(ecb->block_size / CCN_UNIT_SIZE, ct, pt, pad); pad_len = ecb->block_size; pt += pad_len; ct += pad_len; nbytes -= pad_len; } #endif do { *ct++ = *pt++ ^ pad[pad_len++]; --nbytes; } while ((nbytes>0)&&(pad_len<ecb->block_size)); } CCMODE_CTR_KEY_PAD_LEN(key) = pad_len; }
float CCControlSlider::valueForLocation(CCPoint location) { float percent = location.x/ m_backgroundSprite->getContentSize().width; return CC_MAX(CC_MIN(m_minimumValue + percent * (m_maximumValue - m_minimumValue), m_maximumAllowedValue), m_minimumAllowedValue); }