/* * sendBMPToGIMP * * Take the captured data and send it across * to GIMP. */ static void sendBMPToGimp(HBITMAP hBMP, HDC hDC, RECT rect) { int width, height; int imageType, layerType; gint32 image_id; gint32 layer_id; GimpPixelRgn pixel_rgn; GimpDrawable *drawable; /* Our width and height */ width = (rect.right - rect.left); height = (rect.bottom - rect.top); /* Check that we got the memory */ if (!capBytes) { g_message (_("No data captured")); return; } /* Flip the red and blue bytes */ flipRedAndBlueBytes(width, height); /* Set up the image and layer types */ imageType = GIMP_RGB; layerType = GIMP_RGB_IMAGE; /* Create the GIMP image and layers */ image_id = gimp_image_new(width, height, imageType); layer_id = gimp_layer_new(image_id, _("Background"), ROUND4(width), height, layerType, 100, GIMP_NORMAL_MODE); gimp_image_insert_layer(image_id, layer_id, -1, 0); /* Get our drawable */ drawable = gimp_drawable_get(layer_id); gimp_tile_cache_size(ROUND4(width) * gimp_tile_height() * 3); /* Initialize a pixel region for writing to the image */ gimp_pixel_rgn_init(&pixel_rgn, drawable, 0, 0, ROUND4(width), height, TRUE, FALSE); gimp_pixel_rgn_set_rect(&pixel_rgn, (guchar *) capBytes, 0, 0, ROUND4(width), height); /* HB: update data BEFORE size change */ gimp_drawable_flush(drawable); /* Now resize the layer down to the correct size if necessary. */ if (width != ROUND4(width)) { gimp_layer_resize (layer_id, width, height, 0, 0); gimp_image_resize (image_id, width, height, 0, 0); } /* Finish up */ gimp_drawable_detach(drawable); gimp_display_new (image_id); return; }
/* * vDecode4bpp - decode an uncompressed 4 bits per pixel image */ static void vDecode4bpp(FILE *pFile, UCHAR *pucData, const imagedata_type *pImg) { int iX, iY, iByteWidth, iOffset, iTmp, iHalfWidth, iPadding; UCHAR ucTmp; DBG_MSG("vDecode4bpp"); fail(pFile == NULL); fail(pucData == NULL); fail(pImg == NULL); fail(pImg->iColorsUsed < 1 || pImg->iColorsUsed > 16); iByteWidth = iGetByteWidth(pImg); iHalfWidth = (pImg->iWidth + 1) / 2; iPadding = ROUND4(iHalfWidth) - iHalfWidth; for (iY = pImg->iHeight - 1; iY >= 0; iY--) { for (iX = 0; iX < iHalfWidth; iX++) { iTmp = iNextByte(pFile); if (iTmp == EOF) { return; } /* Reverse the nibble order */ ucTmp = (iTmp & 0xf0) >> 4; ucTmp |= (iTmp & 0x0f) << 4; iOffset = iY * iByteWidth + iX; *(pucData + iOffset) = ucTmp; } (void)tSkipBytes(pFile, iPadding); } } /* end of vDecode4bpp */
void *malloc(size_t size) { t_mdata last; t_mdata mem_node; size_t aligned_size; last = NULL; aligned_size = ROUND4(size); if (!g_beg) { if (!(mem_node = get_more_heap(NULL, aligned_size))) return (NULL); g_beg = mem_node; } else { last = g_beg; if (!(mem_node = find_space(&last, aligned_size))) { if (!(mem_node = get_more_heap(last, aligned_size))) return (NULL); } else node_resizing(mem_node, aligned_size); } return (size <= 0 ? NULL : mem_node->d_beg); }
/* * vDecode8bpp - decode an uncompressed 8 bits per pixel image */ static void vDecode8bpp(FILE *pInFile, FILE *pOutFile, const imagedata_type *pImg) { size_t tPadding; int iX, iY, iByte; DBG_MSG("vDecode8bpp"); fail(pInFile == NULL); fail(pOutFile == NULL); fail(pImg == NULL); fail(pImg->iColorsUsed < 1 || pImg->iColorsUsed > 256); DBG_DEC(pImg->iWidth); DBG_DEC(pImg->iHeight); tPadding = (size_t)(ROUND4(pImg->iWidth) - pImg->iWidth); for (iY = 0; iY < pImg->iHeight; iY++) { for (iX = 0; iX < pImg->iWidth; iX++) { iByte = iNextByte(pInFile); if (iByte == EOF) { vASCII85EncodeByte(pOutFile, EOF); return; } vASCII85EncodeByte(pOutFile, iByte); } (void)tSkipBytes(pInFile, tPadding); } vASCII85EncodeByte(pOutFile, EOF); } /* end of vDecode8bpp */
BOOL ElfLoader::load() { Elf_Phdr *ph; vaddr_t kv; int i; _load_segment_start(); for (i = 0, ph = _ph; i < _eh.e_phnum; i++, ph++) { if (ph->p_type == PT_LOAD) { size_t filesz = ph->p_filesz; size_t memsz = ph->p_memsz; kv = ph->p_vaddr; off_t fileofs = ph->p_offset; DPRINTF((TEXT("seg[%d] vaddr 0x%08x file size 0x%x mem size 0x%x\n"), i, kv, filesz, memsz)); _load_segment(kv, memsz, fileofs, filesz); kv += ROUND4(memsz); } } load_symbol_block(kv); // tag chain still opening return _load_success(); }
static inline struct auth_body* auth_body_cloner(char* new_buf, char *org_buf, struct auth_body *auth, char **p) { struct auth_body* new_auth; new_auth = (struct auth_body*)(*p); memcpy(new_auth , auth , sizeof(struct auth_body)); (*p) += ROUND4(sizeof(struct auth_body)); /* authorized field must be cloned elsewhere */ new_auth->digest.username.whole.s = translate_pointer(new_buf, org_buf, auth->digest.username.whole.s); new_auth->digest.username.user.s = translate_pointer(new_buf, org_buf, auth->digest.username.user.s); new_auth->digest.username.domain.s = translate_pointer(new_buf, org_buf, auth->digest.username.domain.s); new_auth->digest.realm.s = translate_pointer(new_buf, org_buf, auth->digest.realm.s); new_auth->digest.nonce.s = translate_pointer(new_buf, org_buf, auth->digest.nonce.s); new_auth->digest.uri.s = translate_pointer(new_buf, org_buf, auth->digest.uri.s); new_auth->digest.response.s = translate_pointer(new_buf, org_buf, auth->digest.response.s); new_auth->digest.alg.alg_str.s = translate_pointer(new_buf, org_buf, auth->digest.alg.alg_str.s); new_auth->digest.cnonce.s = translate_pointer(new_buf, org_buf, auth->digest.cnonce.s); new_auth->digest.opaque.s = translate_pointer(new_buf, org_buf, auth->digest.opaque.s); new_auth->digest.qop.qop_str.s = translate_pointer(new_buf, org_buf, auth->digest.qop.qop_str.s); new_auth->digest.nc.s = translate_pointer(new_buf, org_buf, auth->digest.nc.s); return new_auth; }
/* * vDecode8bpp - decode an uncompressed 8 bits per pixel image */ static void vDecode8bpp(FILE *pFile, UCHAR *pucData, const imagedata_type *pImg) { int iX, iY, iByteWidth, iOffset, iIndex, iPadding; DBG_MSG("vDecode8bpp"); fail(pFile == NULL); fail(pucData == NULL); fail(pImg == NULL); fail(pImg->iColorsUsed < 1 || pImg->iColorsUsed > 256); iByteWidth = iGetByteWidth(pImg); iPadding = ROUND4(pImg->iWidth) - pImg->iWidth; for (iY = pImg->iHeight - 1; iY >= 0; iY--) { for (iX = 0; iX < pImg->iWidth; iX++) { iIndex = iNextByte(pFile); if (iIndex == EOF) { return; } iOffset = iY * iByteWidth + iX; *(pucData + iOffset) = iReduceColor( pImg->aucPalette[iIndex][0], pImg->aucPalette[iIndex][1], pImg->aucPalette[iIndex][2]); } (void)tSkipBytes(pFile, iPadding); } } /* end of vDecode8bpp */
/* * primDoWindowCapture * * The primitive window capture functionality. Accepts * the two device contexts and the rectangle to be * captured. */ static HBITMAP primDoWindowCapture(HDC hdcWindow, HDC hdcCompat, RECT rect) { HBITMAP hbmCopy; HGDIOBJ oldObject; BITMAPINFO bmi; int width = (rect.right - rect.left); int height = (rect.bottom - rect.top); /* Create the bitmap info header */ bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bmi.bmiHeader.biWidth = ROUND4(width); bmi.bmiHeader.biHeight = -height; bmi.bmiHeader.biPlanes = 1; bmi.bmiHeader.biBitCount = 24; bmi.bmiHeader.biCompression = BI_RGB; bmi.bmiHeader.biSizeImage = 0; bmi.bmiHeader.biXPelsPerMeter = bmi.bmiHeader.biYPelsPerMeter = 0; bmi.bmiHeader.biClrUsed = 0; bmi.bmiHeader.biClrImportant = 0; /* Create the bitmap storage space */ hbmCopy = CreateDIBSection(hdcCompat, (BITMAPINFO *) &bmi, DIB_RGB_COLORS, &capBytes, NULL, 0); if (!hbmCopy) { formatWindowsError(buffer, sizeof buffer); g_error("Error creating DIB section: %s", buffer); return NULL; } /* Select the bitmap into the compatible DC. */ oldObject = SelectObject(hdcCompat, hbmCopy); if (!oldObject) { formatWindowsError(buffer, sizeof buffer); g_error("Error selecting object: %s", buffer); return NULL; } /* Copy the data from the application to the bitmap. Even if we did * round up the width, BitBlt only the actual data. */ if (!BitBlt(hdcCompat, 0,0, width, height, hdcWindow, 0,0, SRCCOPY)) { formatWindowsError(buffer, sizeof buffer); g_error("Error copying bitmap: %s", buffer); return NULL; } /* Restore the original object */ SelectObject(hdcCompat, oldObject); return hbmCopy; }
void smap_txeof(void *arg) { struct smap_softc *sc = arg; struct ifnet *ifp = &sc->ethercom.ec_if; struct smap_desc *d; int i; FUNC_ENTER(); /* clear the timeout timer. */ ifp->if_timer = 0; /* garbage collect */ for (i = sc->tx_done_index;; i = (i + 1) & 0x3f) { u_int16_t stat; d = &sc->tx_desc[i]; stat = d->stat; if (stat & SMAP_TXDESC_READY) { /* all descriptor processed. */ break; } else if (stat & 0x7fff) { if (stat & (SMAP_TXDESC_ECOLL | SMAP_TXDESC_LCOLL | SMAP_TXDESC_MCOLL | SMAP_TXDESC_SCOLL)) ifp->if_collisions++; else ifp->if_oerrors++; } else { ifp->if_opackets++; } if (sc->tx_desc_cnt == 0) break; sc->tx_buf_freesize += ROUND4(d->sz); sc->tx_desc_cnt--; d->sz = 0; d->ptr = 0; d->stat = 0; _wbflush(); } sc->tx_done_index = i; /* OK to start transmit */ ifp->if_flags &= ~IFF_OACTIVE; FUNC_EXIT(); }
/* * vDecode24bpp - decode an uncompressed 24 bits per pixel image */ static void vDecode24bpp(FILE *pInFile, FILE *pOutFile, const imagedata_type *pImg) { size_t tPadding; int iX, iY, iBlue, iGreen, iRed, iTripleWidth; DBG_MSG("vDecode24bpp"); fail(pInFile == NULL); fail(pOutFile == NULL); fail(pImg == NULL); fail(!pImg->bColorImage); DBG_DEC(pImg->iWidth); DBG_DEC(pImg->iHeight); iTripleWidth = pImg->iWidth * 3; tPadding = (size_t)(ROUND4(iTripleWidth) - iTripleWidth); for (iY = 0; iY < pImg->iHeight; iY++) { for (iX = 0; iX < pImg->iWidth; iX++) { /* Change from BGR order to RGB order */ iBlue = iNextByte(pInFile); if (iBlue == EOF) { vASCII85EncodeByte(pOutFile, EOF); return; } iGreen = iNextByte(pInFile); if (iGreen == EOF) { vASCII85EncodeByte(pOutFile, EOF); return; } iRed = iNextByte(pInFile); if (iRed == EOF) { vASCII85EncodeByte(pOutFile, EOF); return; } vASCII85EncodeByte(pOutFile, iRed); vASCII85EncodeByte(pOutFile, iGreen); vASCII85EncodeByte(pOutFile, iBlue); } (void)tSkipBytes(pInFile, tPadding); } vASCII85EncodeByte(pOutFile, EOF); } /* end of vDecode24bpp */
/* * vDecode4bpp - decode an uncompressed 4 bits per pixel image */ static void vDecode4bpp(FILE *pInFile, FILE *pOutFile, const imagedata_type *pImg) { size_t tPadding; int iX, iY, iN, iByte, iTmp, iHalfWidth, iUse; DBG_MSG("vDecode4bpp"); fail(pInFile == NULL); fail(pOutFile == NULL); fail(pImg == NULL); fail(pImg->iColorsUsed < 1 || pImg->iColorsUsed > 16); DBG_DEC(pImg->iWidth); DBG_DEC(pImg->iHeight); iHalfWidth = (pImg->iWidth + 1) / 2; tPadding = (size_t)(ROUND4(iHalfWidth) - iHalfWidth); for (iY = 0; iY < pImg->iHeight; iY++) { for (iX = 0; iX < iHalfWidth; iX++) { iByte = iNextByte(pInFile); if (iByte == EOF) { vASCII85EncodeByte(pOutFile, EOF); return; } if (iX == iHalfWidth - 1 && odd(pImg->iWidth)) { iUse = 1; } else { iUse = 2; } for (iN = 0; iN < iUse; iN++) { if (odd(iN)) { iTmp = iByte & 0x0f; } else { iTmp = (iByte & 0xf0) / 16; } vASCII85EncodeByte(pOutFile, iTmp); } } (void)tSkipBytes(pInFile, tPadding); } vASCII85EncodeByte(pOutFile, EOF); } /* end of vDecode4bpp */
/* * flipRedAndBlueBytes * * Microsoft has chosen to provide us a very nice (not!) * interface for retrieving bitmap bits. DIBSections have * RGB information as BGR instead. So, we have to swap * the silly red and blue bytes before sending to the * GIMP. */ static void flipRedAndBlueBytes(int width, int height) { int i, j; guchar *bufp; guchar temp; j = 0; while (j < height) { i = width; bufp = capBytes + j*ROUND4(width)*3; while (i--) { temp = bufp[2]; bufp[2] = bufp[0]; bufp[0] = temp; bufp += 3; } j++; } }
/* * vDecode1bpp - decode an uncompressed 1 bit per pixel image */ static void vDecode1bpp(FILE *pFile, UCHAR *pucData, const imagedata_type *pImg) { int iX, iY, iByteWidth, iOffset, iTmp, iEighthWidth, iPadding; UCHAR ucTmp; DBG_MSG("vDecode1bpp"); fail(pFile == NULL); fail(pucData == NULL); fail(pImg == NULL); fail(pImg->iColorsUsed < 1 || pImg->iColorsUsed > 2); iByteWidth = iGetByteWidth(pImg); iEighthWidth = (pImg->iWidth + 7) / 8; iPadding = ROUND4(iEighthWidth) - iEighthWidth; for (iY = pImg->iHeight - 1; iY >= 0; iY--) { for (iX = 0; iX < iEighthWidth; iX++) { iTmp = iNextByte(pFile); if (iTmp == EOF) { return; } /* Reverse the bit order */ ucTmp = (iTmp & BIT(0)) ? (UCHAR)BIT(7) : 0; ucTmp |= (iTmp & BIT(1)) ? (UCHAR)BIT(6) : 0; ucTmp |= (iTmp & BIT(2)) ? (UCHAR)BIT(5) : 0; ucTmp |= (iTmp & BIT(3)) ? (UCHAR)BIT(4) : 0; ucTmp |= (iTmp & BIT(4)) ? (UCHAR)BIT(3) : 0; ucTmp |= (iTmp & BIT(5)) ? (UCHAR)BIT(2) : 0; ucTmp |= (iTmp & BIT(6)) ? (UCHAR)BIT(1) : 0; ucTmp |= (iTmp & BIT(7)) ? (UCHAR)BIT(0) : 0; iOffset = iY * iByteWidth + iX; *(pucData + iOffset) = ucTmp; } (void)tSkipBytes(pFile, iPadding); } } /* end of vDecode1bpp */
/* * vDecode24bpp - decode an uncompressed 24 bits per pixel image */ static void vDecode24bpp(FILE *pFile, UCHAR *pucData, const imagedata_type *pImg) { int iX, iY, iTripleWidth, iByteWidth, iOffset, iPadding; int iRed, iGreen, iBlue; DBG_MSG("vDecode24bpp"); fail(pFile == NULL); fail(pucData == NULL); fail(pImg == NULL); iByteWidth = iGetByteWidth(pImg); iTripleWidth = pImg->iWidth * 3; iPadding = ROUND4(iTripleWidth) - iTripleWidth; for (iY = pImg->iHeight - 1; iY >= 0; iY--) { for (iX = 0; iX < pImg->iWidth; iX++) { iBlue = iNextByte(pFile); if (iBlue == EOF) { return; } iGreen = iNextByte(pFile); if (iGreen == EOF) { return; } iRed = iNextByte(pFile); if (iRed == EOF) { return; } iOffset = iY * iByteWidth + iX; *(pucData + iOffset) = iReduceColor(iRed, iGreen, iBlue); } (void)tSkipBytes(pFile, iPadding); } } /* end of vDecode24bpp */
void ElfLoader::load_symbol_block(vaddr_t kv) { size_t sz; if (!_sym_blk.enable) return; DPRINTF((TEXT("ksyms\n"))); // load header _load_memory(kv, _sym_blk.header_size, _sym_blk.header); kv += _sym_blk.header_size; // load symbol table sz = _sym_blk.shsym->sh_size; _load_segment(kv, sz, _sym_blk.symoff, sz); kv += ROUND4(sz); // load string table sz = _sym_blk.shstr->sh_size; _load_segment(kv, sz, _sym_blk.stroff, sz); }
void smap_rxeof(void *arg) { struct smap_softc *sc = arg; struct smap_desc *d; struct ifnet *ifp = &sc->ethercom.ec_if; struct mbuf *m; u_int16_t r16, stat; u_int32_t *p; int i, j, sz, rxsz, cnt; FUNC_ENTER(); i = sc->rx_done_index; for (cnt = 0;; cnt++, i = (i + 1) & 0x3f) { m = NULL; d = &sc->rx_desc[i]; stat = d->stat; if ((stat & SMAP_RXDESC_EMPTY) != 0) { break; } else if (stat & 0x7fff) { ifp->if_ierrors++; goto next_packet; } sz = d->sz; rxsz = ROUND4(sz); KDASSERT(sz >= ETHER_ADDR_LEN * 2 + ETHER_TYPE_LEN); KDASSERT(sz <= ETHER_MAX_LEN); /* load data from FIFO */ _reg_write_2(SMAP_RXFIFO_PTR_REG16, d->ptr & 0x3ffc); p = sc->rx_buf; for (j = 0; j < rxsz; j += sizeof(u_int32_t)) { *p++ = _reg_read_4(SMAP_RXFIFO_DATA_REG); } /* put to mbuf */ MGETHDR(m, M_DONTWAIT, MT_DATA); if (m == NULL) { printf("%s: unable to allocate Rx mbuf\n", DEVNAME); ifp->if_ierrors++; goto next_packet; } if (sz > (MHLEN - 2)) { MCLGET(m, M_DONTWAIT); if ((m->m_flags & M_EXT) == 0) { printf("%s: unable to allocate Rx cluster\n", DEVNAME); m_freem(m); m = NULL; ifp->if_ierrors++; goto next_packet; } } m->m_data += 2; /* for alignment */ m->m_pkthdr.rcvif = ifp; m->m_pkthdr.len = m->m_len = sz; memcpy(mtod(m, void *), (void *)sc->rx_buf, sz); next_packet: ifp->if_ipackets++; _reg_write_1(SMAP_RXFIFO_FRAME_DEC_REG8, 1); /* free descriptor */ d->sz = 0; d->ptr = 0; d->stat = SMAP_RXDESC_EMPTY; _wbflush(); if (m != NULL) { if (ifp->if_bpf) bpf_mtap(ifp->if_bpf, m); (*ifp->if_input)(ifp, m); } } sc->rx_done_index = i; r16 = _reg_read_2(SPD_INTR_ENABLE_REG16); if (((r16 & SPD_INTR_RXDNV) == 0) && cnt > 0) { r16 |= SPD_INTR_RXDNV; _reg_write_2(SPD_INTR_ENABLE_REG16, r16); } FUNC_EXIT(); }
void md5_context_hash(struct MD5_CONTEXT *c, const unsigned char blk[MD5_BLOCK_SIZE]) { MD5_WORD x[16]; unsigned i, j; MD5_WORD A, B, C, D; MD5_WORD zz; for (i=j=0; i<16; i++) { MD5_WORD w=(MD5_WORD)blk[j++]; w |= (MD5_WORD)blk[j++] << 8; w |= (MD5_WORD)blk[j++] << 16; w |= (MD5_WORD)blk[j++] << 24; x[i]= w; } #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)))) A=c->A; B=c->B; C=c->C; D=c->D; #define ROUND1(a,b,c,d,k,s,i) \ { zz=(a + F(b,c,d) + x[k] + T[i]); a=b+MD5_ROL(zz,s); } ROUND1(A,B,C,D,0,7,0); ROUND1(D,A,B,C,1,12,1); ROUND1(C,D,A,B,2,17,2); ROUND1(B,C,D,A,3,22,3); ROUND1(A,B,C,D,4,7,4); ROUND1(D,A,B,C,5,12,5); ROUND1(C,D,A,B,6,17,6); ROUND1(B,C,D,A,7,22,7); ROUND1(A,B,C,D,8,7,8); ROUND1(D,A,B,C,9,12,9); ROUND1(C,D,A,B,10,17,10); ROUND1(B,C,D,A,11,22,11); ROUND1(A,B,C,D,12,7,12); ROUND1(D,A,B,C,13,12,13); ROUND1(C,D,A,B,14,17,14); ROUND1(B,C,D,A,15,22,15); #define ROUND2(a,b,c,d,k,s,i) \ { zz=(a + G(b,c,d) + x[k] + T[i]); a = b + MD5_ROL(zz,s); } ROUND2(A,B,C,D,1,5,16); ROUND2(D,A,B,C,6,9,17); ROUND2(C,D,A,B,11,14,18); ROUND2(B,C,D,A,0,20,19); ROUND2(A,B,C,D,5,5,20); ROUND2(D,A,B,C,10,9,21); ROUND2(C,D,A,B,15,14,22); ROUND2(B,C,D,A,4,20,23); ROUND2(A,B,C,D,9,5,24); ROUND2(D,A,B,C,14,9,25); ROUND2(C,D,A,B,3,14,26); ROUND2(B,C,D,A,8,20,27); ROUND2(A,B,C,D,13,5,28); ROUND2(D,A,B,C,2,9,29); ROUND2(C,D,A,B,7,14,30); ROUND2(B,C,D,A,12,20,31); #define ROUND3(a,b,c,d,k,s,i) \ { zz=(a + H(b,c,d) + x[k] + T[i]); a = b + MD5_ROL(zz,s); } ROUND3(A,B,C,D,5,4,32); ROUND3(D,A,B,C,8,11,33); ROUND3(C,D,A,B,11,16,34); ROUND3(B,C,D,A,14,23,35); ROUND3(A,B,C,D,1,4,36); ROUND3(D,A,B,C,4,11,37); ROUND3(C,D,A,B,7,16,38); ROUND3(B,C,D,A,10,23,39); ROUND3(A,B,C,D,13,4,40); ROUND3(D,A,B,C,0,11,41); ROUND3(C,D,A,B,3,16,42); ROUND3(B,C,D,A,6,23,43); ROUND3(A,B,C,D,9,4,44); ROUND3(D,A,B,C,12,11,45); ROUND3(C,D,A,B,15,16,46); ROUND3(B,C,D,A,2,23,47); #define ROUND4(a,b,c,d,k,s,i) \ { zz=(a + I(b,c,d) + x[k] + T[i]); a = b + MD5_ROL(zz,s); } ROUND4(A,B,C,D,0,6,48); ROUND4(D,A,B,C,7,10,49); ROUND4(C,D,A,B,14,15,50); ROUND4(B,C,D,A,5,21,51); ROUND4(A,B,C,D,12,6,52); ROUND4(D,A,B,C,3,10,53); ROUND4(C,D,A,B,10,15,54); ROUND4(B,C,D,A,1,21,55); ROUND4(A,B,C,D,8,6,56); ROUND4(D,A,B,C,15,10,57); ROUND4(C,D,A,B,6,15,58); ROUND4(B,C,D,A,13,21,59); ROUND4(A,B,C,D,4,6,60); ROUND4(D,A,B,C,11,10,61); ROUND4(C,D,A,B,2,15,62); ROUND4(B,C,D,A,9,21,63); c->A += A; c->B += B; c->C += C; c->D += D; }
/* ======================================================================== Routine Description: MD5 computation for one block (512 bits) Arguments: pMD5_CTX Pointer to Md5_CTX_STRUC Return Value: None Note: T[i] := floor(abs(sin(i + 1)) * (2 pow 32)), i is number of round ======================================================================== */ VOID RT_MD5_Hash ( IN MD5_CTX_STRUC *pMD5_CTX) { UINT32 X_i; UINT32 X[16]; UINT32 a,b,c,d; /* Prepare the message schedule, {X_i} */ NdisMoveMemory(X, pMD5_CTX->Block, MD5_BLOCK_SIZE); for (X_i = 0; X_i < 16; X_i++) X[X_i] = cpu2le32(X[X_i]); /* Endian Swap */ /* End of for */ /* MD5 hash computation */ /* Initialize the working variables */ a = pMD5_CTX->HashValue[0]; b = pMD5_CTX->HashValue[1]; c = pMD5_CTX->HashValue[2]; d = pMD5_CTX->HashValue[3]; /* * Round 1 * Let [abcd k s i] denote the operation * a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s) */ ROUND1(a, b, c, d, X[ 0], 7, 0xd76aa478); /* 1 */ ROUND1(d, a, b, c, X[ 1], 12, 0xe8c7b756); /* 2 */ ROUND1(c, d, a, b, X[ 2], 17, 0x242070db); /* 3 */ ROUND1(b, c, d, a, X[ 3], 22, 0xc1bdceee); /* 4 */ ROUND1(a, b, c, d, X[ 4], 7, 0xf57c0faf); /* 5 */ ROUND1(d, a, b, c, X[ 5], 12, 0x4787c62a); /* 6 */ ROUND1(c, d, a, b, X[ 6], 17, 0xa8304613); /* 7 */ ROUND1(b, c, d, a, X[ 7], 22, 0xfd469501); /* 8 */ ROUND1(a, b, c, d, X[ 8], 7, 0x698098d8); /* 9 */ ROUND1(d, a, b, c, X[ 9], 12, 0x8b44f7af); /* 10 */ ROUND1(c, d, a, b, X[10], 17, 0xffff5bb1); /* 11 */ ROUND1(b, c, d, a, X[11], 22, 0x895cd7be); /* 12 */ ROUND1(a, b, c, d, X[12], 7, 0x6b901122); /* 13 */ ROUND1(d, a, b, c, X[13], 12, 0xfd987193); /* 14 */ ROUND1(c, d, a, b, X[14], 17, 0xa679438e); /* 15 */ ROUND1(b, c, d, a, X[15], 22, 0x49b40821); /* 16 */ /* * Round 2 * Let [abcd k s i] denote the operation * a = b + ((a + G(b,c,d) + X[k] + T[i]) <<< s) */ ROUND2(a, b, c, d, X[ 1], 5, 0xf61e2562); /* 17 */ ROUND2(d, a, b, c, X[ 6], 9, 0xc040b340); /* 18 */ ROUND2(c, d, a, b, X[11], 14, 0x265e5a51); /* 19 */ ROUND2(b, c, d, a, X[ 0], 20, 0xe9b6c7aa); /* 20 */ ROUND2(a, b, c, d, X[ 5], 5, 0xd62f105d); /* 21 */ ROUND2(d, a, b, c, X[10], 9, 0x2441453); /* 22 */ ROUND2(c, d, a, b, X[15], 14, 0xd8a1e681); /* 23 */ ROUND2(b, c, d, a, X[ 4], 20, 0xe7d3fbc8); /* 24 */ ROUND2(a, b, c, d, X[ 9], 5, 0x21e1cde6); /* 25 */ ROUND2(d, a, b, c, X[14], 9, 0xc33707d6); /* 26 */ ROUND2(c, d, a, b, X[ 3], 14, 0xf4d50d87); /* 27 */ ROUND2(b, c, d, a, X[ 8], 20, 0x455a14ed); /* 28 */ ROUND2(a, b, c, d, X[13], 5, 0xa9e3e905); /* 29 */ ROUND2(d, a, b, c, X[ 2], 9, 0xfcefa3f8); /* 30 */ ROUND2(c, d, a, b, X[ 7], 14, 0x676f02d9); /* 31 */ ROUND2(b, c, d, a, X[12], 20, 0x8d2a4c8a); /* 32 */ /* * Round 3 * Let [abcd k s t] denote the operation * a = b + ((a + H(b,c,d) + X[k] + T[i]) <<< s) */ ROUND3(a, b, c, d, X[ 5], 4, 0xfffa3942); /* 33 */ ROUND3(d, a, b, c, X[ 8], 11, 0x8771f681); /* 34 */ ROUND3(c, d, a, b, X[11], 16, 0x6d9d6122); /* 35 */ ROUND3(b, c, d, a, X[14], 23, 0xfde5380c); /* 36 */ ROUND3(a, b, c, d, X[ 1], 4, 0xa4beea44); /* 37 */ ROUND3(d, a, b, c, X[ 4], 11, 0x4bdecfa9); /* 38 */ ROUND3(c, d, a, b, X[ 7], 16, 0xf6bb4b60); /* 39 */ ROUND3(b, c, d, a, X[10], 23, 0xbebfbc70); /* 40 */ ROUND3(a, b, c, d, X[13], 4, 0x289b7ec6); /* 41 */ ROUND3(d, a, b, c, X[ 0], 11, 0xeaa127fa); /* 42 */ ROUND3(c, d, a, b, X[ 3], 16, 0xd4ef3085); /* 43 */ ROUND3(b, c, d, a, X[ 6], 23, 0x4881d05); /* 44 */ ROUND3(a, b, c, d, X[ 9], 4, 0xd9d4d039); /* 45 */ ROUND3(d, a, b, c, X[12], 11, 0xe6db99e5); /* 46 */ ROUND3(c, d, a, b, X[15], 16, 0x1fa27cf8); /* 47 */ ROUND3(b, c, d, a, X[ 2], 23, 0xc4ac5665); /* 48 */ /* * Round 4 * Let [abcd k s t] denote the operation * a = b + ((a + I(b,c,d) + X[k] + T[i]) <<< s) */ ROUND4(a, b, c, d, X[ 0], 6, 0xf4292244); /* 49 */ ROUND4(d, a, b, c, X[ 7], 10, 0x432aff97); /* 50 */ ROUND4(c, d, a, b, X[14], 15, 0xab9423a7); /* 51 */ ROUND4(b, c, d, a, X[ 5], 21, 0xfc93a039); /* 52 */ ROUND4(a, b, c, d, X[12], 6, 0x655b59c3); /* 53 */ ROUND4(d, a, b, c, X[ 3], 10, 0x8f0ccc92); /* 54 */ ROUND4(c, d, a, b, X[10], 15, 0xffeff47d); /* 55 */ ROUND4(b, c, d, a, X[ 1], 21, 0x85845dd1); /* 56 */ ROUND4(a, b, c, d, X[ 8], 6, 0x6fa87e4f); /* 57 */ ROUND4(d, a, b, c, X[15], 10, 0xfe2ce6e0); /* 58 */ ROUND4(c, d, a, b, X[ 6], 15, 0xa3014314); /* 59 */ ROUND4(b, c, d, a, X[13], 21, 0x4e0811a1); /* 60 */ ROUND4(a, b, c, d, X[ 4], 6, 0xf7537e82); /* 61 */ ROUND4(d, a, b, c, X[11], 10, 0xbd3af235); /* 62 */ ROUND4(c, d, a, b, X[ 2], 15, 0x2ad7d2bb); /* 63 */ ROUND4(b, c, d, a, X[ 9], 21, 0xeb86d391); /* 64 */ /* Compute the i^th intermediate hash value H^(i) */ pMD5_CTX->HashValue[0] += a; pMD5_CTX->HashValue[1] += b; pMD5_CTX->HashValue[2] += c; pMD5_CTX->HashValue[3] += d; NdisZeroMemory(pMD5_CTX->Block, MD5_BLOCK_SIZE); pMD5_CTX->BlockLen = 0; } /* End of RT_MD5_Hash */
static inline struct via_body* via_body_cloner( char* new_buf, char *org_buf, struct via_body *param_org_via, char **p) { struct via_body *new_via; struct via_body *first_via, *last_via; struct via_body *org_via; first_via = last_via = 0; org_via = param_org_via; do { /* clones the via_body structure */ new_via = (struct via_body*)(*p); memcpy( new_via , org_via , sizeof( struct via_body) ); (*p) += ROUND4(sizeof( struct via_body )); /* hdr (str type) */ new_via->hdr.s=translate_pointer(new_buf,org_buf,org_via->hdr.s); /* name (str type) */ new_via->name.s=translate_pointer(new_buf,org_buf,org_via->name.s); /* version (str type) */ new_via->version.s= translate_pointer(new_buf,org_buf,org_via->version.s); /* transport (str type) */ new_via->transport.s= translate_pointer(new_buf,org_buf,org_via->transport.s); /* host (str type) */ new_via->host.s=translate_pointer(new_buf,org_buf,org_via->host.s); /* port_str (str type) */ new_via->port_str.s= translate_pointer(new_buf,org_buf,org_via->port_str.s); /* params (str type) */ new_via->params.s=translate_pointer(new_buf,org_buf,org_via->params.s); /* transaction id */ new_via->tid.s= translate_pointer(new_buf, org_buf, org_via->tid.s); /* comment (str type) */ new_via->comment.s= translate_pointer(new_buf,org_buf,org_via->comment.s); if ( org_via->param_lst ) { struct via_param *vp, *new_vp, *last_new_vp; for( vp=org_via->param_lst, last_new_vp=0 ; vp ; vp=vp->next ) { new_vp = (struct via_param*)(*p); memcpy( new_vp , vp , sizeof(struct via_param)); (*p) += ROUND4(sizeof(struct via_param)); new_vp->name.s=translate_pointer(new_buf,org_buf,vp->name.s); new_vp->value.s=translate_pointer(new_buf,org_buf,vp->value.s); new_vp->start=translate_pointer(new_buf,org_buf,vp->start); /* "translate" the shortcuts */ switch(new_vp->type){ case PARAM_BRANCH: new_via->branch = new_vp; break; case PARAM_RECEIVED: new_via->received = new_vp; break; case PARAM_RPORT: new_via->rport = new_vp; break; case PARAM_I: new_via->i = new_vp; break; case PARAM_ALIAS: new_via->alias = new_vp; break; #ifdef USE_COMP case PARAM_COMP: new_via->comp = new_vp; break; #endif } if (last_new_vp) last_new_vp->next = new_vp; else new_via->param_lst = new_vp; last_new_vp = new_vp; last_new_vp->next = NULL; } new_via->last_param = new_vp; }/*end if via has params */ if (last_via) last_via->next = new_via; else first_via = new_via; last_via = new_via; org_via = org_via->next; }while(org_via); return first_via; }
/* * vDecode1bpp - decode an uncompressed 1 bit per pixel image */ static void vDecode1bpp(FILE *pInFile, FILE *pOutFile, const imagedata_type *pImg) { size_t tPadding; int iX, iY, iN, iByte, iTmp, iEighthWidth, iUse; DBG_MSG("vDecode1bpp"); fail(pOutFile == NULL); fail(pImg == NULL); fail(pImg->iColorsUsed < 1 || pImg->iColorsUsed > 2); DBG_DEC(pImg->iWidth); DBG_DEC(pImg->iHeight); iEighthWidth = (pImg->iWidth + 7) / 8; tPadding = (size_t)(ROUND4(iEighthWidth) - iEighthWidth); for (iY = 0; iY < pImg->iHeight; iY++) { for (iX = 0; iX < iEighthWidth; iX++) { iByte = iNextByte(pInFile); if (iByte == EOF) { vASCII85EncodeByte(pOutFile, EOF); return; } if (iX == iEighthWidth - 1 && pImg->iWidth % 8 != 0) { iUse = pImg->iWidth % 8; } else { iUse = 8; } for (iN = 0; iN < iUse; iN++) { switch (iN) { case 0: iTmp = (iByte & 0x80) / 128; break; case 1: iTmp = (iByte & 0x40) / 64; break; case 2: iTmp = (iByte & 0x20) / 32; break; case 3: iTmp = (iByte & 0x10) / 16; break; case 4: iTmp = (iByte & 0x08) / 8; break; case 5: iTmp = (iByte & 0x04) / 4; break; case 6: iTmp = (iByte & 0x02) / 2; break; case 7: iTmp = (iByte & 0x01); break; default: iTmp = 0; break; } vASCII85EncodeByte(pOutFile, iTmp); } } (void)tSkipBytes(pInFile, tPadding); } vASCII85EncodeByte(pOutFile, EOF); } /* end of vDecode1bpp */
// // Prepare ELF headers for symbol table. // // ELF header // section header // shstrtab // symtab // strtab // size_t ElfLoader::symbol_block_size() { size_t shstrsize = ROUND4(_sh[_eh.e_shstrndx].sh_size); size_t shtab_sz = _eh.e_shentsize * _eh.e_shnum; off_t shstrtab_offset = sizeof(Elf_Ehdr) + shtab_sz; int i; memset(&_sym_blk, 0, sizeof(_sym_blk)); _sym_blk.enable = FALSE; _sym_blk.header_size = sizeof(Elf_Ehdr) + shtab_sz + shstrsize; // inquire string and symbol table size _sym_blk.header = static_cast<char *>(malloc(_sym_blk.header_size)); if (_sym_blk.header == NULL) { MessageBox(HPC_MENU._root->_window, TEXT("Can't determine symbol block size."), TEXT("WARNING"), MB_ICONWARNING | MB_OK); UpdateWindow(HPC_MENU._root->_window); return (0); } // set pointer for symbol block Elf_Ehdr *eh = reinterpret_cast<Elf_Ehdr *>(_sym_blk.header); Elf_Shdr *sh = reinterpret_cast<Elf_Shdr *> (_sym_blk.header + sizeof(Elf_Ehdr)); char *shstrtab = _sym_blk.header + shstrtab_offset; // initialize headers memset(_sym_blk.header, 0, _sym_blk.header_size); memcpy(eh, &_eh, sizeof(Elf_Ehdr)); eh->e_phoff = 0; eh->e_phnum = 0; eh->e_entry = 0; // XXX NetBSD kernel check this member. see machdep.c eh->e_shoff = sizeof(Elf_Ehdr); memcpy(sh, _sh, shtab_sz); // inquire symbol/string table information _file->read(shstrtab, shstrsize, _sh[_eh.e_shstrndx].sh_offset); for (i = 0; i < _eh.e_shnum; i++, sh++) { if (strcmp(".strtab", shstrtab + sh->sh_name) == 0) { _sym_blk.shstr = sh; _sym_blk.stroff = sh->sh_offset; } else if (strcmp(".symtab", shstrtab + sh->sh_name) == 0) { _sym_blk.shsym = sh; _sym_blk.symoff = sh->sh_offset; } sh->sh_offset = (i == _eh.e_shstrndx) ? shstrtab_offset : 0; } if (_sym_blk.shstr == NULL || _sym_blk.shsym == NULL) { if (HPC_PREFERENCE.safety_message) { MessageBox(HPC_MENU._root->_window, TEXT("No symbol and/or string table in binary.\n(not fatal)"), TEXT("Information"), MB_ICONINFORMATION | MB_OK); UpdateWindow(HPC_MENU._root->_window); } free(_sym_blk.header); _sym_blk.header = NULL; return (0); } // set Section Headers for symbol/string table _sym_blk.shsym->sh_offset = shstrtab_offset + shstrsize; _sym_blk.shstr->sh_offset = shstrtab_offset + shstrsize + ROUND4(_sym_blk.shsym->sh_size); _sym_blk.enable = TRUE; DPRINTF((TEXT("+[ksyms: header 0x%x, symtab 0x%x, strtab 0x%x"), _sym_blk.header_size, _sym_blk.shsym->sh_size, _sym_blk.shstr->sh_size)); // return total amount of symbol block return (_sym_blk.header_size + ROUND4(_sym_blk.shsym->sh_size) + _sym_blk.shstr->sh_size); }
void smap_start(struct ifnet *ifp) { struct smap_softc *sc = ifp->if_softc; struct smap_desc *d; struct mbuf *m0, *m; u_int8_t *p, *q; u_int32_t *r; int i, sz, pktsz; u_int16_t fifop; u_int16_t r16; KDASSERT(ifp->if_flags & IFF_RUNNING); FUNC_ENTER(); while (1) { IFQ_POLL(&ifp->if_snd, m0); if (m0 == NULL) goto end; pktsz = m0->m_pkthdr.len; KDASSERT(pktsz <= ETHER_MAX_LEN - ETHER_CRC_LEN); sz = ROUND4(pktsz); if (sz > sc->tx_buf_freesize || sc->tx_desc_cnt >= SMAP_DESC_MAX || emac3_tx_done() != 0) { ifp->if_flags |= IFF_OACTIVE; goto end; } IFQ_DEQUEUE(&ifp->if_snd, m0); KDASSERT(m0 != NULL); if (ifp->if_bpf) bpf_mtap(ifp->if_bpf, m0); p = (u_int8_t *)sc->tx_buf; q = p + sz; /* copy to temporary buffer area */ for (m = m0; m != 0; m = m->m_next) { memcpy(p, mtod(m, void *), m->m_len); p += m->m_len; } m_freem(m0); /* zero padding area */ for (; p < q; p++) *p = 0; /* put to FIFO */ fifop = sc->tx_fifo_ptr; KDASSERT((fifop & 3) == 0); _reg_write_2(SMAP_TXFIFO_PTR_REG16, fifop); sc->tx_fifo_ptr = (fifop + sz) & 0xfff; r = sc->tx_buf; for (i = 0; i < sz; i += sizeof(u_int32_t)) *(volatile u_int32_t *)SMAP_TXFIFO_DATA_REG = *r++; _wbflush(); /* put FIFO to EMAC3 */ d = &sc->tx_desc[sc->tx_start_index]; KDASSERT((d->stat & SMAP_TXDESC_READY) == 0); d->sz = pktsz; d->ptr = fifop + SMAP_TXBUF_BASE; d->stat = SMAP_TXDESC_READY | SMAP_TXDESC_GENFCS | SMAP_TXDESC_GENPAD; _wbflush(); sc->tx_buf_freesize -= sz; sc->tx_desc_cnt++; sc->tx_start_index = (sc->tx_start_index + 1) & 0x3f; _reg_write_1(SMAP_TXFIFO_FRAME_INC_REG8, 1); emac3_tx_kick(); r16 = _reg_read_2(SPD_INTR_ENABLE_REG16); if ((r16 & SPD_INTR_TXDNV) == 0) { r16 |= SPD_INTR_TXDNV; _reg_write_2(SPD_INTR_ENABLE_REG16, r16); } } end: /* set watchdog timer */ ifp->if_timer = 5; FUNC_EXIT(); }
ECode CCallbackParcel::WriteValue( /* [in] */ PVoid value, /* [in] */ Int32 type, /* [in] */ Int32 size) { ECode ec; Int32 used, len; if (mElemCount >= mTypeBufCapacity) { ec = GrowTypeBuffer(); if (FAILED(ec)) return ec; } if (mElemPtr - mElemBuf + 4 > mElemBufCapacity) { ec = GrowElemBuffer(); if (FAILED(ec)) return ec; } mElemTypes[mElemCount] = (Byte)type; switch(type) { case Type_Byte: case Type_Boolean: *(Int32*)(mElemPtr) = *((Byte*)value); mElemPtr += 4; break; case Type_Int16: *(Int32*)(mElemPtr) = *((Int16*)value); mElemPtr += 4; break; case Type_Char32: case Type_Int32: case Type_Float: *(Int32*)(mElemPtr) = *(Int32*)value; mElemPtr += 4; break; case Type_Int64: case Type_Double: if (mElemPtr - mElemBuf + 4 + 4 > mElemBufCapacity) { ec = GrowElemBuffer(); if (FAILED(ec)) return ec; } #if defined(_arm) && defined(__GNUC__) && (__GNUC__ >= 4) mElemPtr = (Byte*)ROUND8((Int32)mElemPtr); #endif *(Int32*)(mElemPtr) = (Int32)(*((Int64*)value) & 0xffffffff); *(Int32*)(mElemPtr + 4) = (Int32)((*((Int64*)value) >> 32) & 0xffffffff); mElemPtr += 8; break; case Type_String: { String* p = new String(); *p = *(String*)value; *(String**)mElemPtr = p; mElemPtr += 4; break; } case Type_InterfacePtr: *(IInterface**)mElemPtr = *(IInterface**)value; if ((*(IInterface**)mElemPtr) != NULL) { (*(IInterface**)mElemPtr)->AddRef(); } mElemPtr += 4; break; case Type_Struct: if (mDataPtr - mDataBuf + ROUND4(size) + 4 > mDataBufCapacity) { ec = GrowDataBuffer(ROUND4(size) + 4); if (FAILED(ec)) return ec; } *(Int32*)mDataPtr = size; mDataPtr += 4; *(Byte**)(mElemPtr) = mDataPtr; mElemPtr += 4; memcpy(mDataPtr, value, size); mDataPtr += ROUND4(size); break; case Type_EMuid: if (mDataPtr - mDataBuf + ROUND4(size) > mDataBufCapacity) { ec = GrowDataBuffer(ROUND4(size)); if (FAILED(ec)) return ec; } *(EMuid**)(mElemPtr) = (EMuid*)mDataPtr; mElemPtr += 4; memcpy(mDataPtr, value, size); mDataPtr += size; break; case Type_EGuid: if (mDataPtr - mDataBuf + ROUND4(size) > mDataBufCapacity) { ec = GrowDataBuffer(ROUND4(size)); if (FAILED(ec)) return ec; } *(EGuid**)(mElemPtr) = (EGuid*)mDataPtr; mElemPtr += 4; memcpy(mDataPtr, value, sizeof(EGuid)); ((EGuid*)mDataPtr)->mUunm = (char*)(mDataPtr + sizeof(EGuid)); strcpy(((EGuid*)mDataPtr)->mUunm, ((EGuid*)value)->mUunm); mDataPtr += ROUND4(size); break; case Type_ArrayOf: if (value == NULL) { *(Byte**)(mElemPtr) = NULL; mElemPtr += 4; } else { if (mDataPtr - mDataBuf + ROUND4(size + 4) + 4 > mDataBufCapacity) { ec = GrowDataBuffer(ROUND4(size + 4) + 4); if (FAILED(ec)) return ec; } *(Int32*)mDataPtr = size; mDataPtr += 4; *(Byte**)(mElemPtr) = mDataPtr; mElemPtr += 4; memcpy(mDataPtr, value, sizeof(CarQuintet)); mDataPtr += ROUND4(sizeof(CarQuintet)); (*(CarQuintet**)(mElemPtr - 4))->mBuf = (PVoid)(mDataPtr); memcpy(mDataPtr, ((CarQuintet*)value)->mBuf, size - sizeof(CarQuintet)); mDataPtr += ROUND4(size - sizeof(CarQuintet)); } break; case Type_ArrayOfString: used = ((ArrayOf<String>*)value)->GetLength(); if (mDataPtr - mDataBuf + ROUND4(size) + 4 > mDataBufCapacity) { ec = GrowDataBuffer(ROUND4(size) + 4); if (FAILED(ec)) return ec; } *(Int32*)mDataPtr = size; mDataPtr += 4; *(Byte**)(mElemPtr) = mDataPtr; mElemPtr += 4; memcpy(mDataPtr, value, sizeof(CarQuintet)); mDataPtr += ROUND4(sizeof(CarQuintet)); (*(CarQuintet**)(mElemPtr - 4))->mBuf = (PVoid)(mDataPtr); mDataPtr += ROUND4(((CarQuintet*)value)->mSize); for(Int32 i = 0; i < used; i++) { (**(ArrayOf<String>**)(mElemPtr - 4))[i] = (const char*)mDataPtr; if ((*(ArrayOf<String>*)value)[i]) { len = (strlen((*(ArrayOf<String>*)value)[i]) + 1); memcpy((void*)(const char*)(**(ArrayOf<String>**)(mElemPtr - 4))[i], (*(ArrayOf<String>*)value)[i], len); mDataPtr += ROUND4(len); } else (**(ArrayOf<String>**)(mElemPtr - 4))[i] = NULL; } break; default: assert(0); break; } mElemCount += 1; return NOERROR; }
static void md5_calc(const uint8_t *b64, md5_ctxt * ctxt) { uint32_t A = ctxt->md5_sta; uint32_t B = ctxt->md5_stb; uint32_t C = ctxt->md5_stc; uint32_t D = ctxt->md5_std; #if (BYTE_ORDER == LITTLE_ENDIAN) const uint32_t *X = (const uint32_t *)b64; #elif (BYTE_ORDER == BIG_ENDIAN) uint32_t X[16]; #endif if (BYTE_ORDER == BIG_ENDIAN) { /* 4 byte words */ /* what a brute force but fast! */ uint8_t *y = (uint8_t *)X; y[ 0] = b64[ 3]; y[ 1] = b64[ 2]; y[ 2] = b64[ 1]; y[ 3] = b64[ 0]; y[ 4] = b64[ 7]; y[ 5] = b64[ 6]; y[ 6] = b64[ 5]; y[ 7] = b64[ 4]; y[ 8] = b64[11]; y[ 9] = b64[10]; y[10] = b64[ 9]; y[11] = b64[ 8]; y[12] = b64[15]; y[13] = b64[14]; y[14] = b64[13]; y[15] = b64[12]; y[16] = b64[19]; y[17] = b64[18]; y[18] = b64[17]; y[19] = b64[16]; y[20] = b64[23]; y[21] = b64[22]; y[22] = b64[21]; y[23] = b64[20]; y[24] = b64[27]; y[25] = b64[26]; y[26] = b64[25]; y[27] = b64[24]; y[28] = b64[31]; y[29] = b64[30]; y[30] = b64[29]; y[31] = b64[28]; y[32] = b64[35]; y[33] = b64[34]; y[34] = b64[33]; y[35] = b64[32]; y[36] = b64[39]; y[37] = b64[38]; y[38] = b64[37]; y[39] = b64[36]; y[40] = b64[43]; y[41] = b64[42]; y[42] = b64[41]; y[43] = b64[40]; y[44] = b64[47]; y[45] = b64[46]; y[46] = b64[45]; y[47] = b64[44]; y[48] = b64[51]; y[49] = b64[50]; y[50] = b64[49]; y[51] = b64[48]; y[52] = b64[55]; y[53] = b64[54]; y[54] = b64[53]; y[55] = b64[52]; y[56] = b64[59]; y[57] = b64[58]; y[58] = b64[57]; y[59] = b64[56]; y[60] = b64[63]; y[61] = b64[62]; y[62] = b64[61]; y[63] = b64[60]; } ROUND1(A, B, C, D, 0, Sa, 1); ROUND1(D, A, B, C, 1, Sb, 2); ROUND1(C, D, A, B, 2, Sc, 3); ROUND1(B, C, D, A, 3, Sd, 4); ROUND1(A, B, C, D, 4, Sa, 5); ROUND1(D, A, B, C, 5, Sb, 6); ROUND1(C, D, A, B, 6, Sc, 7); ROUND1(B, C, D, A, 7, Sd, 8); ROUND1(A, B, C, D, 8, Sa, 9); ROUND1(D, A, B, C, 9, Sb, 10); ROUND1(C, D, A, B, 10, Sc, 11); ROUND1(B, C, D, A, 11, Sd, 12); ROUND1(A, B, C, D, 12, Sa, 13); ROUND1(D, A, B, C, 13, Sb, 14); ROUND1(C, D, A, B, 14, Sc, 15); ROUND1(B, C, D, A, 15, Sd, 16); ROUND2(A, B, C, D, 1, Se, 17); ROUND2(D, A, B, C, 6, Sf, 18); ROUND2(C, D, A, B, 11, Sg, 19); ROUND2(B, C, D, A, 0, Sh, 20); ROUND2(A, B, C, D, 5, Se, 21); ROUND2(D, A, B, C, 10, Sf, 22); ROUND2(C, D, A, B, 15, Sg, 23); ROUND2(B, C, D, A, 4, Sh, 24); ROUND2(A, B, C, D, 9, Se, 25); ROUND2(D, A, B, C, 14, Sf, 26); ROUND2(C, D, A, B, 3, Sg, 27); ROUND2(B, C, D, A, 8, Sh, 28); ROUND2(A, B, C, D, 13, Se, 29); ROUND2(D, A, B, C, 2, Sf, 30); ROUND2(C, D, A, B, 7, Sg, 31); ROUND2(B, C, D, A, 12, Sh, 32); ROUND3(A, B, C, D, 5, Si, 33); ROUND3(D, A, B, C, 8, Sj, 34); ROUND3(C, D, A, B, 11, Sk, 35); ROUND3(B, C, D, A, 14, Sl, 36); ROUND3(A, B, C, D, 1, Si, 37); ROUND3(D, A, B, C, 4, Sj, 38); ROUND3(C, D, A, B, 7, Sk, 39); ROUND3(B, C, D, A, 10, Sl, 40); ROUND3(A, B, C, D, 13, Si, 41); ROUND3(D, A, B, C, 0, Sj, 42); ROUND3(C, D, A, B, 3, Sk, 43); ROUND3(B, C, D, A, 6, Sl, 44); ROUND3(A, B, C, D, 9, Si, 45); ROUND3(D, A, B, C, 12, Sj, 46); ROUND3(C, D, A, B, 15, Sk, 47); ROUND3(B, C, D, A, 2, Sl, 48); ROUND4(A, B, C, D, 0, Sm, 49); ROUND4(D, A, B, C, 7, Sn, 50); ROUND4(C, D, A, B, 14, So, 51); ROUND4(B, C, D, A, 5, Sp, 52); ROUND4(A, B, C, D, 12, Sm, 53); ROUND4(D, A, B, C, 3, Sn, 54); ROUND4(C, D, A, B, 10, So, 55); ROUND4(B, C, D, A, 1, Sp, 56); ROUND4(A, B, C, D, 8, Sm, 57); ROUND4(D, A, B, C, 15, Sn, 58); ROUND4(C, D, A, B, 6, So, 59); ROUND4(B, C, D, A, 13, Sp, 60); ROUND4(A, B, C, D, 4, Sm, 61); ROUND4(D, A, B, C, 11, Sn, 62); ROUND4(C, D, A, B, 2, So, 63); ROUND4(B, C, D, A, 9, Sp, 64); ctxt->md5_sta += A; ctxt->md5_stb += B; ctxt->md5_stc += C; ctxt->md5_std += D; }
static void SHA1_block(SHA1_CTX *ctx) /* Update the SHA-1 hash from a fresh 64 bytes of data. */ { static DWORDC sha1_round1 = 0x5A827999u; static DWORDC sha1_round2 = 0x6ED9EBA1u; static DWORDC sha1_round3 = 0x8F1BBCDCu; static DWORDC sha1_round4 = 0xCA62C1D6u; DWORD a = ctx->partial_hash[0], b = ctx->partial_hash[1]; DWORD c = ctx->partial_hash[2], d = ctx->partial_hash[3]; DWORD e = ctx->partial_hash[4]; DWORD msg80[80]; int i; BOOL OK = TRUE; for (i = 0; i != 16; i++) { // Copy to local array, zero original // Extend length to 80 DWORDC datval = ctx->awaiting_data[i]; ctx->awaiting_data[i] = 0; msg80[i] = datval; } for (i = 16; i != 80; i += 2) { DWORDC temp1 = msg80[i-3] ^ msg80[i-8] ^ msg80[i-14] ^ msg80[i-16]; DWORDC temp2 = msg80[i-2] ^ msg80[i-7] ^ msg80[i-13] ^ msg80[i-15]; msg80[i ] = ROTATE32L(temp1, 1); msg80[i+1] = ROTATE32L(temp2, 1); } #define ROUND1(B, C, D) ((D ^ (B & (C ^ D))) + sha1_round1) // Equivalent to (B & C) | (~B & D). // (check cases B = 0 and B = 1) #define ROUND2(B, C, D) ((B ^ C ^ D) + sha1_round2) #define ROUND3(B, C, D) ((C & (B | D) | (B & D)) + sha1_round3) #define ROUND4(B, C, D) ((B ^ C ^ D) + sha1_round4) // Round 1 for (i = 0; i != 20; i += 5) { e += ROTATE32L(a, 5) + ROUND1(b, c, d) + msg80[i]; b = ROTATE32L(b, 30); d += ROTATE32L(e, 5) + ROUND1(a, b, c) + msg80[i+1]; a = ROTATE32L(a, 30); c += ROTATE32L(d, 5) + ROUND1(e, a, b) + msg80[i+2]; e = ROTATE32L(e, 30); b += ROTATE32L(c, 5) + ROUND1(d, e, a) + msg80[i+3]; d = ROTATE32L(d, 30); a += ROTATE32L(b, 5) + ROUND1(c, d, e) + msg80[i+4]; c = ROTATE32L(c, 30); #if 0 printf("i = %ld %08lx %08lx %08lx %08lx %08lx\n", i, a, b, c, d, e); #endif } // for i // Round 2 for (i = 20; i != 40; i += 5) { e += ROTATE32L(a, 5) + ROUND2(b, c, d) + msg80[i]; b = ROTATE32L(b, 30); d += ROTATE32L(e, 5) + ROUND2(a, b, c) + msg80[i+1]; a = ROTATE32L(a, 30); c += ROTATE32L(d, 5) + ROUND2(e, a, b) + msg80[i+2]; e = ROTATE32L(e, 30); b += ROTATE32L(c, 5) + ROUND2(d, e, a) + msg80[i+3]; d = ROTATE32L(d, 30); a += ROTATE32L(b, 5) + ROUND2(c, d, e) + msg80[i+4]; c = ROTATE32L(c, 30); } // for i // Round 3 for (i = 40; i != 60; i += 5) { e += ROTATE32L(a, 5) + ROUND3(b, c, d) + msg80[i]; b = ROTATE32L(b, 30); d += ROTATE32L(e, 5) + ROUND3(a, b, c) + msg80[i+1]; a = ROTATE32L(a, 30); c += ROTATE32L(d, 5) + ROUND3(e, a, b) + msg80[i+2]; e = ROTATE32L(e, 30); b += ROTATE32L(c, 5) + ROUND3(d, e, a) + msg80[i+3]; d = ROTATE32L(d, 30); a += ROTATE32L(b, 5) + ROUND3(c, d, e) + msg80[i+4]; c = ROTATE32L(c, 30); } // for i // Round 4 for (i = 60; i != 80; i += 5) { e += ROTATE32L(a, 5) + ROUND4(b, c, d) + msg80[i]; b = ROTATE32L(b, 30); d += ROTATE32L(e, 5) + ROUND4(a, b, c) + msg80[i+1]; a = ROTATE32L(a, 30); c += ROTATE32L(d, 5) + ROUND4(e, a, b) + msg80[i+2]; e = ROTATE32L(e, 30); b += ROTATE32L(c, 5) + ROUND4(d, e, a) + msg80[i+3]; d = ROTATE32L(d, 30); a += ROTATE32L(b, 5) + ROUND4(c, d, e) + msg80[i+4]; c = ROTATE32L(c, 30); } // for i #undef ROUND1 #undef ROUND2 #undef ROUND3 #undef ROUND4 ctx->partial_hash[0] += a; ctx->partial_hash[1] += b; ctx->partial_hash[2] += c; ctx->partial_hash[3] += d; ctx->partial_hash[4] += e; #if 0 for (i = 0; i != 16; i++) { printf("%8lx ", msg16[i]); if ((i & 7) == 7) printf("\n"); } printf("a, b, c, d, e = %08lx %08lx %08lx %08lx %08lx\n", a, b, c, d, e); printf("Partial hash = %08lx %08lx %08lx %08lx %08lx\n", (long)ctx->partial_hash[0], (long)ctx->partial_hash[1], (long)ctx->partial_hash[2], (long)ctx->partial_hash[3], (long)ctx->partial_hash[4]); #endif } // end SHA1_block