void ecb_md(FILE *outf, f_dctx alg[1], const unsigned long blen, const unsigned long klen) { unsigned long j, k; unsigned char pt[32], ct[64], key[32], dummy; block_clear(pt, blen); // clear initial plaintext and key block_clear(key, klen); block_copy(ct + blen, pt, blen); // copy plaintext into upper half // of double length ciphertext block for(j = 0; j < 400; j++) // 400 Monte Carlo tests { block_out(test_no, &dummy, outf, j); // output test number block_out(key_val, key, outf, klen); // output key block_out(ct_val, pt, outf, blen); // output plaintext f_dec_key(alg, key, klen); // set key for(k = 0; k < 5000; ++k) // 10000 decryptions alternating { // upper and lower blocks in ct do_dec(alg, ct + blen, ct, 1); do_dec(alg, ct, ct + blen, 1); } // compile next key as defined by NIST block_xor(key, ct + 2 * blen - klen, klen); block_out(pt_val, ct + blen, outf, blen); // output ciphertext block_copy(pt, ct + blen, blen); // set ciphertext as next plaintext } }
static inline void apply_motion_generic(RoqContext *ri, int x, int y, int deltax, int deltay, int sz) { int mx, my, cp; mx = x + deltax; my = y + deltay; /* check MV against frame boundaries */ if ((mx < 0) || (mx > ri->width - sz) || (my < 0) || (my > ri->height - sz)) { av_log(ri->avctx, AV_LOG_ERROR, "motion vector out of bounds: MV = (%d, %d), boundaries = (0, 0, %d, %d)\n", mx, my, ri->width, ri->height); return; } if (ri->last_frame->data[0] == NULL) { av_log(ri->avctx, AV_LOG_ERROR, "Invalid decode type. Invalid header?\n"); return; } for(cp = 0; cp < 3; cp++) { int outstride = ri->current_frame->linesize[cp]; int instride = ri->last_frame ->linesize[cp]; block_copy(ri->current_frame->data[cp] + y*outstride + x, ri->last_frame->data[cp] + my*instride + mx, outstride, instride, sz); } }
/** * Inverses mixed columns * @param dt Data */ void AES::inv_mix_sub_columns( uint_8t dt[N_BLOCK] ) { uint_8t st[N_BLOCK]; block_copy(st, dt); dt[ 0] = is_box(gfm_e(st[ 0]) ^ gfm_b(st[ 1]) ^ gfm_d(st[ 2]) ^ gfm_9(st[ 3])); dt[ 5] = is_box(gfm_9(st[ 0]) ^ gfm_e(st[ 1]) ^ gfm_b(st[ 2]) ^ gfm_d(st[ 3])); dt[10] = is_box(gfm_d(st[ 0]) ^ gfm_9(st[ 1]) ^ gfm_e(st[ 2]) ^ gfm_b(st[ 3])); dt[15] = is_box(gfm_b(st[ 0]) ^ gfm_d(st[ 1]) ^ gfm_9(st[ 2]) ^ gfm_e(st[ 3])); dt[ 4] = is_box(gfm_e(st[ 4]) ^ gfm_b(st[ 5]) ^ gfm_d(st[ 6]) ^ gfm_9(st[ 7])); dt[ 9] = is_box(gfm_9(st[ 4]) ^ gfm_e(st[ 5]) ^ gfm_b(st[ 6]) ^ gfm_d(st[ 7])); dt[14] = is_box(gfm_d(st[ 4]) ^ gfm_9(st[ 5]) ^ gfm_e(st[ 6]) ^ gfm_b(st[ 7])); dt[ 3] = is_box(gfm_b(st[ 4]) ^ gfm_d(st[ 5]) ^ gfm_9(st[ 6]) ^ gfm_e(st[ 7])); dt[ 8] = is_box(gfm_e(st[ 8]) ^ gfm_b(st[ 9]) ^ gfm_d(st[10]) ^ gfm_9(st[11])); dt[13] = is_box(gfm_9(st[ 8]) ^ gfm_e(st[ 9]) ^ gfm_b(st[10]) ^ gfm_d(st[11])); dt[ 2] = is_box(gfm_d(st[ 8]) ^ gfm_9(st[ 9]) ^ gfm_e(st[10]) ^ gfm_b(st[11])); dt[ 7] = is_box(gfm_b(st[ 8]) ^ gfm_d(st[ 9]) ^ gfm_9(st[10]) ^ gfm_e(st[11])); dt[12] = is_box(gfm_e(st[12]) ^ gfm_b(st[13]) ^ gfm_d(st[14]) ^ gfm_9(st[15])); dt[ 1] = is_box(gfm_9(st[12]) ^ gfm_e(st[13]) ^ gfm_b(st[14]) ^ gfm_d(st[15])); dt[ 6] = is_box(gfm_d(st[12]) ^ gfm_9(st[13]) ^ gfm_e(st[14]) ^ gfm_b(st[15])); dt[11] = is_box(gfm_b(st[12]) ^ gfm_d(st[13]) ^ gfm_9(st[14]) ^ gfm_e(st[15])); }
/** * Mixes columns * @param dt Data */ void AES::mix_sub_columns( uint_8t dt[N_BLOCK] ) { uint_8t st[N_BLOCK]; block_copy(st, dt); dt[ 0] = gfm2_sb(st[0]) ^ gfm3_sb(st[5]) ^ s_box(st[10]) ^ s_box(st[15]); dt[ 1] = s_box(st[0]) ^ gfm2_sb(st[5]) ^ gfm3_sb(st[10]) ^ s_box(st[15]); dt[ 2] = s_box(st[0]) ^ s_box(st[5]) ^ gfm2_sb(st[10]) ^ gfm3_sb(st[15]); dt[ 3] = gfm3_sb(st[0]) ^ s_box(st[5]) ^ s_box(st[10]) ^ gfm2_sb(st[15]); dt[ 4] = gfm2_sb(st[4]) ^ gfm3_sb(st[9]) ^ s_box(st[14]) ^ s_box(st[3]); dt[ 5] = s_box(st[4]) ^ gfm2_sb(st[9]) ^ gfm3_sb(st[14]) ^ s_box(st[3]); dt[ 6] = s_box(st[4]) ^ s_box(st[9]) ^ gfm2_sb(st[14]) ^ gfm3_sb(st[3]); dt[ 7] = gfm3_sb(st[4]) ^ s_box(st[9]) ^ s_box(st[14]) ^ gfm2_sb(st[3]); dt[ 8] = gfm2_sb(st[8]) ^ gfm3_sb(st[13]) ^ s_box(st[2]) ^ s_box(st[7]); dt[ 9] = s_box(st[8]) ^ gfm2_sb(st[13]) ^ gfm3_sb(st[2]) ^ s_box(st[7]); dt[10] = s_box(st[8]) ^ s_box(st[13]) ^ gfm2_sb(st[2]) ^ gfm3_sb(st[7]); dt[11] = gfm3_sb(st[8]) ^ s_box(st[13]) ^ s_box(st[2]) ^ gfm2_sb(st[7]); dt[12] = gfm2_sb(st[12]) ^ gfm3_sb(st[1]) ^ s_box(st[6]) ^ s_box(st[11]); dt[13] = s_box(st[12]) ^ gfm2_sb(st[1]) ^ gfm3_sb(st[6]) ^ s_box(st[11]); dt[14] = s_box(st[12]) ^ s_box(st[1]) ^ gfm2_sb(st[6]) ^ gfm3_sb(st[11]); dt[15] = gfm3_sb(st[12]) ^ s_box(st[1]) ^ s_box(st[6]) ^ gfm2_sb(st[11]); }
void * block_copy_construct(void *inp) { block * x = (block *) inp; block * y = block_alloc(x->vec->size); block_copy(x, y); return y; }
return_type aes_set_key( const unsigned char key[], length_type keylen, aes_context ctx[1] ) { uint_8t cc, rc, hi; switch( keylen ) { case 16: case 128: keylen = 16; break; case 24: case 192: keylen = 24; break; case 32: case 256: keylen = 32; break; default: ctx->rnd = 0; return (return_type) -1; } block_copy(ctx->ksch, key, keylen); hi = (keylen + 28) << 2; ctx->rnd = (hi >> 4) - 1; for( cc = keylen, rc = 1; cc < hi; cc += 4 ) { uint_8t tt, t0, t1, t2, t3; t0 = ctx->ksch[cc - 4]; t1 = ctx->ksch[cc - 3]; t2 = ctx->ksch[cc - 2]; t3 = ctx->ksch[cc - 1]; if( cc % keylen == 0 ) { tt = t0; t0 = s_box[t1] ^ rc; t1 = s_box[t2]; t2 = s_box[t3]; t3 = s_box[tt]; rc = f2(rc); } else if( keylen > 24 && cc % keylen == 16 ) { t0 = s_box[t0]; t1 = s_box[t1]; t2 = s_box[t2]; t3 = s_box[t3]; } tt = cc - keylen; ctx->ksch[cc + 0] = ctx->ksch[tt + 0] ^ t0; ctx->ksch[cc + 1] = ctx->ksch[tt + 1] ^ t1; ctx->ksch[cc + 2] = ctx->ksch[tt + 2] ^ t2; ctx->ksch[cc + 3] = ctx->ksch[tt + 3] ^ t3; } return 0; }
SHORT quick_paste(void) { /* copy the marked block without */ if (view_block_active()) { /* disturbing current scrap */ my_new_scrap(); block_copy (FALSE); block_paste(FALSE); restore_scrap(); } else block_paste(FALSE); }
bool reallocate_with_copy(OldAllocator &oldAllocator, NewAllocator &newAllocator, block &b, size_t n) noexcept { auto newBlock = newAllocator.allocate(n); if (!newBlock) { return false; } block_copy(b, newBlock); oldAllocator.deallocate(b); b = newBlock; return true; }
static void mesh_prepare_write(mesh_t *mesh) { block_t *blocks, *block, *new_block; if (*mesh->ref == 1) return; (*mesh->ref)--; mesh->ref = calloc(1, sizeof(*mesh->ref)); *mesh->ref = 1; blocks = mesh->blocks; mesh->blocks = NULL; DL_FOREACH(blocks, block) { new_block = block_copy(block); new_block->id = block->id; DL_APPEND(mesh->blocks, new_block); }
int code_one(struct zint_symbol *symbol, unsigned char source[], int length) { int size = 1, i, j, data_blocks; char datagrid[136][120]; int row, col; int sub_version = 0; if((symbol->option_2 < 0) || (symbol->option_2 > 10)) { strcpy(symbol->errtxt, "Invalid symbol size"); return ERROR_INVALID_OPTION; } if(symbol->option_2 == 9) { /* Version S */ int codewords; short int elreg[112]; unsigned int data[15], ecc[15]; int stream[30]; int block_width; if(length > 18) { strcpy(symbol->errtxt, "Input data too long"); return ERROR_TOO_LONG; } if(is_sane(NEON, source, length) == ERROR_INVALID_DATA) { strcpy(symbol->errtxt, "Invalid input data (Version S encodes numeric input only)"); return ERROR_INVALID_DATA; } sub_version = 3; codewords = 12; block_width = 6; /* Version S-30 */ if(length <= 12) { sub_version = 2; codewords = 8; block_width = 4; } /* Version S-20 */ if(length <= 6) { sub_version = 1; codewords = 4; block_width = 2; } /* Version S-10 */ binary_load(elreg, (char *)source, length); hex_dump(elreg); for(i = 0; i < 15; i++) { data[i] = 0; ecc[i] = 0; } for(i = 0; i < codewords; i++) { data[codewords - i - 1] += 1 * elreg[(i * 5)]; data[codewords - i - 1] += 2 * elreg[(i * 5) + 1]; data[codewords - i - 1] += 4 * elreg[(i * 5) + 2]; data[codewords - i - 1] += 8 * elreg[(i * 5) + 3]; data[codewords - i - 1] += 16 * elreg[(i * 5) + 4]; } rs_init_gf(0x25); rs_init_code(codewords, 1); rs_encode_long(codewords, data, ecc); rs_free(); for(i = 0; i < codewords; i++) { stream[i] = data[i]; stream[i + codewords] = ecc[codewords - i - 1]; } for(i = 0; i < 136; i++) { for(j = 0; j < 120; j++) { datagrid[i][j] = '0'; } } i = 0; for(row = 0; row < 2; row++) { for(col = 0; col < block_width; col++) { if(stream[i] & 0x10) { datagrid[row * 2][col * 5] = '1'; } if(stream[i] & 0x08) { datagrid[row * 2][(col * 5) + 1] = '1'; } if(stream[i] & 0x04) { datagrid[row * 2][(col * 5) + 2] = '1'; } if(stream[i] & 0x02) { datagrid[(row * 2) + 1][col * 5] = '1'; } if(stream[i] & 0x01) { datagrid[(row * 2) + 1][(col * 5) + 1] = '1'; } if(stream[i + 1] & 0x10) { datagrid[row * 2][(col * 5) + 3] = '1'; } if(stream[i + 1] & 0x08) { datagrid[row * 2][(col * 5) + 4] = '1'; } if(stream[i + 1] & 0x04) { datagrid[(row * 2) + 1][(col * 5) + 2] = '1'; } if(stream[i + 1] & 0x02) { datagrid[(row * 2) + 1][(col * 5) + 3] = '1'; } if(stream[i + 1] & 0x01) { datagrid[(row * 2) + 1][(col * 5) + 4] = '1'; } i += 2; } } size = 9; symbol->rows = 8; symbol->width = 10 * sub_version + 1; } if(symbol->option_2 == 10) { /* Version T */ unsigned int data[40], ecc[25]; unsigned int stream[65]; int data_length; int data_cw, ecc_cw, block_width; for(i = 0; i < 40; i++) { data[i] = 0; } data_length = c1_encode(symbol, source, data, length); if(data_length == 0) { return ERROR_TOO_LONG; } if(data_length > 38) { strcpy(symbol->errtxt, "Input data too long"); return ERROR_TOO_LONG; } size = 10; sub_version = 3; data_cw = 38; ecc_cw = 22; block_width = 12; if(data_length <= 24) { sub_version = 2; data_cw = 24; ecc_cw = 16; block_width = 8; } if(data_length <= 10) { sub_version = 1; data_cw = 10; ecc_cw = 10; block_width = 4; } for(i = data_length; i < data_cw; i++) { data[i] = 129; /* Pad */ } /* Calculate error correction data */ rs_init_gf(0x12d); rs_init_code(ecc_cw, 1); rs_encode_long(data_cw, data, ecc); rs_free(); /* "Stream" combines data and error correction data */ for(i = 0; i < data_cw; i++) { stream[i] = data[i]; } for(i = 0; i < ecc_cw; i++) { stream[data_cw + i] = ecc[ecc_cw - i - 1]; } for(i = 0; i < 136; i++) { for(j = 0; j < 120; j++) { datagrid[i][j] = '0'; } } i = 0; for(row = 0; row < 5; row++) { for(col = 0; col < block_width; col++) { if(stream[i] & 0x80) { datagrid[row * 2][col * 4] = '1'; } if(stream[i] & 0x40) { datagrid[row * 2][(col * 4) + 1] = '1'; } if(stream[i] & 0x20) { datagrid[row * 2][(col * 4) + 2] = '1'; } if(stream[i] & 0x10) { datagrid[row * 2][(col * 4) + 3] = '1'; } if(stream[i] & 0x08) { datagrid[(row * 2) + 1][col * 4] = '1'; } if(stream[i] & 0x04) { datagrid[(row * 2) + 1][(col * 4) + 1] = '1'; } if(stream[i] & 0x02) { datagrid[(row * 2) + 1][(col * 4) + 2] = '1'; } if(stream[i] & 0x01) { datagrid[(row * 2) + 1][(col * 4) + 3] = '1'; } i++; } } symbol->rows = 16; symbol->width = (sub_version * 16) + 1; } if((symbol->option_2 != 9) && (symbol->option_2 != 10)) { /* Version A to H */ unsigned int data[1500], ecc[600]; unsigned int sub_data[190], sub_ecc[75]; unsigned int stream[2100]; int data_length; for(i = 0; i < 1500; i++) { data[i] = 0; } data_length = c1_encode(symbol, source, data, length); if(data_length == 0) { return ERROR_TOO_LONG; } for(i = 7; i >= 0; i--) { if(c1_data_length[i] >= data_length) { size = i + 1; } } if(symbol->option_2 > size) { size = symbol->option_2; } for(i = data_length; i < c1_data_length[size - 1]; i++) { data[i] = 129; /* Pad */ } /* Calculate error correction data */ data_length = c1_data_length[size - 1]; for(i = 0; i < 190; i++) { sub_data[i] = 0; } for(i = 0; i < 75; i++) { sub_ecc[i] = 0; } data_blocks = c1_blocks[size - 1]; rs_init_gf(0x12d); rs_init_code(c1_ecc_blocks[size - 1], 0); for(i = 0; i < data_blocks; i++) { for(j = 0; j < c1_data_blocks[size - 1]; j++) { sub_data[j] = data[j * data_blocks + i]; } rs_encode_long(c1_data_blocks[size - 1], sub_data, sub_ecc); for(j = 0; j < c1_ecc_blocks[size - 1]; j++) { ecc[c1_ecc_length[size - 1] - (j * data_blocks + i) - 1] = sub_ecc[j]; } } rs_free(); /* "Stream" combines data and error correction data */ for(i = 0; i < data_length; i++) { stream[i] = data[i]; } for(i = 0; i < c1_ecc_length[size - 1]; i++) { stream[data_length + i] = ecc[i]; } for(i = 0; i < 136; i++) { for(j = 0; j < 120; j++) { datagrid[i][j] = '0'; } } i = 0; for(row = 0; row < c1_grid_height[size - 1]; row++) { for(col = 0; col < c1_grid_width[size - 1]; col++) { if(stream[i] & 0x80) { datagrid[row * 2][col * 4] = '1'; } if(stream[i] & 0x40) { datagrid[row * 2][(col * 4) + 1] = '1'; } if(stream[i] & 0x20) { datagrid[row * 2][(col * 4) + 2] = '1'; } if(stream[i] & 0x10) { datagrid[row * 2][(col * 4) + 3] = '1'; } if(stream[i] & 0x08) { datagrid[(row * 2) + 1][col * 4] = '1'; } if(stream[i] & 0x04) { datagrid[(row * 2) + 1][(col * 4) + 1] = '1'; } if(stream[i] & 0x02) { datagrid[(row * 2) + 1][(col * 4) + 2] = '1'; } if(stream[i] & 0x01) { datagrid[(row * 2) + 1][(col * 4) + 3] = '1'; } i++; } } /* for(i = 0; i < (c1_grid_height[size - 1] * 2); i++) { for(j = 0; j < (c1_grid_width[size - 1] * 4); j++) { printf("%c", datagrid[i][j]); } printf("\n"); } */ symbol->rows = c1_height[size - 1]; symbol->width = c1_width[size - 1]; } switch(size) { case 1: /* Version A */ central_finder(symbol, 6, 3, 1); vert(symbol, 4, 6, 1); vert(symbol, 12, 5, 0); set_module(symbol, 5, 12); spigot(symbol, 0); spigot(symbol, 15); block_copy(symbol, datagrid, 0, 0, 5, 4, 0, 0); block_copy(symbol, datagrid, 0, 4, 5, 12, 0, 2); block_copy(symbol, datagrid, 5, 0, 5, 12, 6, 0); block_copy(symbol, datagrid, 5, 12, 5, 4, 6, 2); break; case 2: /* Version B */ central_finder(symbol, 8, 4, 1); vert(symbol, 4, 8, 1); vert(symbol, 16, 7, 0); set_module(symbol, 7, 16); spigot(symbol, 0); spigot(symbol, 21); block_copy(symbol, datagrid, 0, 0, 7, 4, 0, 0); block_copy(symbol, datagrid, 0, 4, 7, 16, 0, 2); block_copy(symbol, datagrid, 7, 0, 7, 16, 8, 0); block_copy(symbol, datagrid, 7, 16, 7, 4, 8, 2); break; case 3: /* Version C */ central_finder(symbol, 11, 4, 2); vert(symbol, 4, 11, 1); vert(symbol, 26, 13, 1); vert(symbol, 4, 10, 0); vert(symbol, 26, 10, 0); spigot(symbol, 0); spigot(symbol, 27); block_copy(symbol, datagrid, 0, 0, 10, 4, 0, 0); block_copy(symbol, datagrid, 0, 4, 10, 20, 0, 2); block_copy(symbol, datagrid, 0, 24, 10, 4, 0, 4); block_copy(symbol, datagrid, 10, 0, 10, 4, 8, 0); block_copy(symbol, datagrid, 10, 4, 10, 20, 8, 2); block_copy(symbol, datagrid, 10, 24, 10, 4, 8, 4); break; case 4: /* Version D */ central_finder(symbol, 16, 5, 1); vert(symbol, 4, 16, 1); vert(symbol, 20, 16, 1); vert(symbol, 36, 16, 1); vert(symbol, 4, 15, 0); vert(symbol, 20, 15, 0); vert(symbol, 36, 15, 0); spigot(symbol, 0); spigot(symbol, 12); spigot(symbol, 27); spigot(symbol, 39); block_copy(symbol, datagrid, 0, 0, 15, 4, 0, 0); block_copy(symbol, datagrid, 0, 4, 15, 14, 0, 2); block_copy(symbol, datagrid, 0, 18, 15, 14, 0, 4); block_copy(symbol, datagrid, 0, 32, 15, 4, 0, 6); block_copy(symbol, datagrid, 15, 0, 15, 4, 10, 0); block_copy(symbol, datagrid, 15, 4, 15, 14, 10, 2); block_copy(symbol, datagrid, 15, 18, 15, 14, 10, 4); block_copy(symbol, datagrid, 15, 32, 15, 4, 10, 6); break; case 5: /* Version E */ central_finder(symbol, 22, 5, 2); vert(symbol, 4, 22, 1); vert(symbol, 26, 24, 1); vert(symbol, 48, 22, 1); vert(symbol, 4, 21, 0); vert(symbol, 26, 21, 0); vert(symbol, 48, 21, 0); spigot(symbol, 0); spigot(symbol, 12); spigot(symbol, 39); spigot(symbol, 51); block_copy(symbol, datagrid, 0, 0, 21, 4, 0, 0); block_copy(symbol, datagrid, 0, 4, 21, 20, 0, 2); block_copy(symbol, datagrid, 0, 24, 21, 20, 0, 4); block_copy(symbol, datagrid, 0, 44, 21, 4, 0, 6); block_copy(symbol, datagrid, 21, 0, 21, 4, 10, 0); block_copy(symbol, datagrid, 21, 4, 21, 20, 10, 2); block_copy(symbol, datagrid, 21, 24, 21, 20, 10, 4); block_copy(symbol, datagrid, 21, 44, 21, 4, 10, 6); break; case 6: /* Version F */ central_finder(symbol, 31, 5, 3); vert(symbol, 4, 31, 1); vert(symbol, 26, 35, 1); vert(symbol, 48, 31, 1); vert(symbol, 70, 35, 1); vert(symbol, 4, 30, 0); vert(symbol, 26, 30, 0); vert(symbol, 48, 30, 0); vert(symbol, 70, 30, 0); spigot(symbol, 0); spigot(symbol, 12); spigot(symbol, 24); spigot(symbol, 45); spigot(symbol, 57); spigot(symbol, 69); block_copy(symbol, datagrid, 0, 0, 30, 4, 0, 0); block_copy(symbol, datagrid, 0, 4, 30, 20, 0, 2); block_copy(symbol, datagrid, 0, 24, 30, 20, 0, 4); block_copy(symbol, datagrid, 0, 44, 30, 20, 0, 6); block_copy(symbol, datagrid, 0, 64, 30, 4, 0, 8); block_copy(symbol, datagrid, 30, 0, 30, 4, 10, 0); block_copy(symbol, datagrid, 30, 4, 30, 20, 10, 2); block_copy(symbol, datagrid, 30, 24, 30, 20, 10, 4); block_copy(symbol, datagrid, 30, 44, 30, 20, 10, 6); block_copy(symbol, datagrid, 30, 64, 30, 4, 10, 8); break; case 7: /* Version G */ central_finder(symbol, 47, 6, 2); vert(symbol, 6, 47, 1); vert(symbol, 27, 49, 1); vert(symbol, 48, 47, 1); vert(symbol, 69, 49, 1); vert(symbol, 90, 47, 1); vert(symbol, 6, 46, 0); vert(symbol, 27, 46, 0); vert(symbol, 48, 46, 0); vert(symbol, 69, 46, 0); vert(symbol, 90, 46, 0); spigot(symbol, 0); spigot(symbol, 12); spigot(symbol, 24); spigot(symbol, 36); spigot(symbol, 67); spigot(symbol, 79); spigot(symbol, 91); spigot(symbol, 103); block_copy(symbol, datagrid, 0, 0, 46, 6, 0, 0); block_copy(symbol, datagrid, 0, 6, 46, 19, 0, 2); block_copy(symbol, datagrid, 0, 25, 46, 19, 0, 4); block_copy(symbol, datagrid, 0, 44, 46, 19, 0, 6); block_copy(symbol, datagrid, 0, 63, 46, 19, 0, 8); block_copy(symbol, datagrid, 0, 82, 46, 6, 0, 10); block_copy(symbol, datagrid, 46, 0, 46, 6, 12, 0); block_copy(symbol, datagrid, 46, 6, 46, 19, 12, 2); block_copy(symbol, datagrid, 46, 25, 46, 19, 12, 4); block_copy(symbol, datagrid, 46, 44, 46, 19, 12, 6); block_copy(symbol, datagrid, 46, 63, 46, 19, 12, 8); block_copy(symbol, datagrid, 46, 82, 46, 6, 12, 10); break; case 8: /* Version H */ central_finder(symbol, 69, 6, 3); vert(symbol, 6, 69, 1); vert(symbol, 26, 73, 1); vert(symbol, 46, 69, 1); vert(symbol, 66, 73, 1); vert(symbol, 86, 69, 1); vert(symbol, 106, 73, 1); vert(symbol, 126, 69, 1); vert(symbol, 6, 68, 0); vert(symbol, 26, 68, 0); vert(symbol, 46, 68, 0); vert(symbol, 66, 68, 0); vert(symbol, 86, 68, 0); vert(symbol, 106, 68, 0); vert(symbol, 126, 68, 0); spigot(symbol, 0); spigot(symbol, 12); spigot(symbol, 24); spigot(symbol, 36); spigot(symbol, 48); spigot(symbol, 60); spigot(symbol, 87); spigot(symbol, 99); spigot(symbol, 111); spigot(symbol, 123); spigot(symbol, 135); spigot(symbol, 147); block_copy(symbol, datagrid, 0, 0, 68, 6, 0, 0); block_copy(symbol, datagrid, 0, 6, 68, 18, 0, 2); block_copy(symbol, datagrid, 0, 24, 68, 18, 0, 4); block_copy(symbol, datagrid, 0, 42, 68, 18, 0, 6); block_copy(symbol, datagrid, 0, 60, 68, 18, 0, 8); block_copy(symbol, datagrid, 0, 78, 68, 18, 0, 10); block_copy(symbol, datagrid, 0, 96, 68, 18, 0, 12); block_copy(symbol, datagrid, 0, 114, 68, 6, 0, 14); block_copy(symbol, datagrid, 68, 0, 68, 6, 12, 0); block_copy(symbol, datagrid, 68, 6, 68, 18, 12, 2); block_copy(symbol, datagrid, 68, 24, 68, 18, 12, 4); block_copy(symbol, datagrid, 68, 42, 68, 18, 12, 6); block_copy(symbol, datagrid, 68, 60, 68, 18, 12, 8); block_copy(symbol, datagrid, 68, 78, 68, 18, 12, 10); block_copy(symbol, datagrid, 68, 96, 68, 18, 12, 12); block_copy(symbol, datagrid, 68, 114, 68, 6, 12, 14); break; case 9: /* Version S */ horiz(symbol, 5, 1); horiz(symbol, 7, 1); set_module(symbol, 6, 0); set_module(symbol, 6, symbol->width - 1); unset_module(symbol, 7, 1); unset_module(symbol, 7, symbol->width - 2); switch(sub_version) { case 1: /* Version S-10 */ set_module(symbol, 0, 5); block_copy(symbol, datagrid, 0, 0, 4, 5, 0, 0); block_copy(symbol, datagrid, 0, 5, 4, 5, 0, 1); break; case 2: /* Version S-20 */ set_module(symbol, 0, 10); set_module(symbol, 4, 10); block_copy(symbol, datagrid, 0, 0, 4, 10, 0, 0); block_copy(symbol, datagrid, 0, 10, 4, 10, 0, 1); break; case 3: /* Version S-30 */ set_module(symbol, 0, 15); set_module(symbol, 4, 15); set_module(symbol, 6, 15); block_copy(symbol, datagrid, 0, 0, 4, 15, 0, 0); block_copy(symbol, datagrid, 0, 15, 4, 15, 0, 1); break; } break; case 10: /* Version T */ horiz(symbol, 11, 1); horiz(symbol, 13, 1); horiz(symbol, 15, 1); set_module(symbol, 12, 0); set_module(symbol, 12, symbol->width - 1); set_module(symbol, 14, 0); set_module(symbol, 14, symbol->width - 1); unset_module(symbol, 13, 1); unset_module(symbol, 13, symbol->width - 2); unset_module(symbol, 15, 1); unset_module(symbol, 15, symbol->width - 2); switch(sub_version) { case 1: /* Version T-16 */ set_module(symbol, 0, 8); set_module(symbol, 10, 8); block_copy(symbol, datagrid, 0, 0, 10, 8, 0, 0); block_copy(symbol, datagrid, 0, 8, 10, 8, 0, 1); break; case 2: /* Version T-32 */ set_module(symbol, 0, 16); set_module(symbol, 10, 16); set_module(symbol, 12, 16); block_copy(symbol, datagrid, 0, 0, 10, 16, 0, 0); block_copy(symbol, datagrid, 0, 16, 10, 16, 0, 1); break; case 3: /* Verion T-48 */ set_module(symbol, 0, 24); set_module(symbol, 10, 24); set_module(symbol, 12, 24); set_module(symbol, 14, 24); block_copy(symbol, datagrid, 0, 0, 10, 24, 0, 0); block_copy(symbol, datagrid, 0, 24, 10, 24, 0, 1); break; } break; } for(i = 0; i < symbol->rows; i++) { symbol->row_height[i] = 1; } return 0; }
void ref_test(const char *in_file, const unsigned int it_cnt, enum test_type t_type, AESREF alg) { u4byte i, kl, test_no, cnt, e_cnt; u1byte key[32], pt[16], iv[16], ect[16], act[32]; char str[128], tstr[16]; int ty; IFILE inf; con_string("\nTest file: "); con_string(in_file); con_string("\nStatus: \n"); if(!(inf = open_ifile(inf, in_file))) // reference file for test vectors { // if file is not present con_string("error in running test\n"); return; } cnt = 0; e_cnt = test_no = 0; for(;;) // while there are tests { ty = find_line(inf, str); // input a line if(ty < 0) // until end of file break; switch(ty) // process line type { case 0: kl = get_dec(str + 8); continue; // key length case 1: test_no = get_dec(str + 2); continue; // test number case 2: block_in(iv, str + 3); continue; // init vector case 3: block_in(key, str + 4); continue; // key case 4: block_in(pt, str + 3); // plaintext if(t_type != ecb_md && t_type != cbc_md) continue; break; case 5: block_in(ect, str + 3); // ciphertext if(t_type == ecb_md || t_type == cbc_md) continue; break; } if(serpent_hack) block_reverse(key, kl / 8); alg.set_key(key, kl, both); // set the key if(it_cnt > 100) OUT_DOTS(test_no); if(t_type == ecb_md || t_type == cbc_md) { block_copy(act, ect, 16); // encrypted text to low block if(t_type == cbc_md) // CBC Monte Carlo decryption { block_copy(act + 16, iv, 16); // IV to high block for(i = 0; i < it_cnt; i += 2) // do decryptions two at a time { if(serpent_hack) block_reverse(act, 16); alg.decrypt(act, ect); // decrypt low block if(serpent_hack) { block_reverse(act, 16); block_reverse(ect, 16); } block_xor(act + 16, ect, 16);// xor into high block if(serpent_hack) block_reverse(act + 16, 16); alg.decrypt(act + 16, ect); // decrypt high block if(serpent_hack) { block_reverse(ect, 16); block_reverse(act + 16, 16); } block_xor(act, ect, 16); // xor into low block } } else // ECB Monte Carlo decryption { if(serpent_hack) block_reverse(act, 16); for(i = 0; i < it_cnt; ++i) alg.decrypt(act, act); if(serpent_hack) block_reverse(act, 16); } if(!block_cmp(pt, act, 16)) { con_string("\n\ndecryption error on test "); put_dec(tstr, test_no); con_string(tstr); e_cnt++; } if(t_type == ecb_md) // test encryption if ECB mode { if(serpent_hack) block_reverse(act, 16); for(i = 0; i < it_cnt; ++i) alg.encrypt(act, act); if(serpent_hack) block_reverse(act, 16); if(!block_cmp(ect, act, 16)) { con_string("\n\nencryption error on test "); put_dec(tstr, test_no); con_string(tstr); e_cnt++; } } } else // if(t_type == ecb_me || t_type == cbc_me || ecb_vk || ecb_vt) { if(t_type == cbc_me) // CBC Monte Carlo encryption { block_copy(act, iv, 16); block_copy(act + 16, pt, 16); // copy IV and plaintext for(i = 0; i < it_cnt; i += 2) { block_xor(act + 16, act, 16); // xor low block into high block if(serpent_hack) block_reverse(act + 16, 16); alg.encrypt(act + 16, act + 16); // encrypt high block if(serpent_hack) block_reverse(act + 16, 16); block_xor(act, act + 16, 16); // xor high block into low block if(serpent_hack) block_reverse(act, 16); alg.encrypt(act, act); // encrypt low block if(serpent_hack) block_reverse(act, 16); } } else // ECB Monte Carlo encryption { block_copy(act, pt, 16); if(serpent_hack) block_reverse(act, 16); for(i = 0; i < it_cnt; ++i) alg.encrypt(act, act); if(serpent_hack) block_reverse(act, 16); } if(!block_cmp(ect, act, 16)) { con_string("\n\nencryption error on test "); put_dec(tstr, test_no); con_string(tstr); e_cnt++; } if(t_type != cbc_me) // if ECB mode test decrytpion { if(serpent_hack) block_reverse(act, 16); for(i = 0; i < it_cnt; ++i) alg.decrypt(act, act); if(serpent_hack) block_reverse(act, 16); if(!block_cmp(pt, act, 16)) { con_string("\n\ndecryption error on test "); put_dec(tstr, test_no); con_string(tstr); e_cnt++; } } } } close_ifile(inf); if(e_cnt > 0) // report any errors { put_dec(tstr, e_cnt); con_string("\n"); con_string(tstr); con_string(" errors during test\n"); } else // else report all is well con_string("\nall tests correct\n"); }
/** * Writes all entries except ".class" to the data_file_handle, * writes corresponding central directory records and the end of central * directory record to the directory_file_handle. * Treats .ZIP file format as documented in * ftp://ftp.uu.net/pub/archiving/zip/doc/appnote-970311-iz.zip. * Assumes that the .ZIP file doesn't span across multiple disks. * Assumes that raw_current_entry()->nextCenOffset contains the offset * of the first entry of the central directory (as set in the constructor). * Returns true if completes successfully, false otherwise. */ bool JarFileParser::copy_non_class_entries_to(OsFile_Handle data_file_handle, OsFile_Handle directory_file_handle JVM_TRAPS) { UsingFastOops fast_oops; BufferedFile::Fast jar_buffer = buffered_file(); const char class_suffix[] = {'.','c','l','a','s','s','\0'}; juint locOffset = raw_current_entry()->locOffset; const juint buffer_size = MAX_ENTRY_NAME; DECLARE_STATIC_BUFFER(unsigned char, buffer, buffer_size); unsigned int name_length = 0; juint loc_header_offset = 0; juint cen_header_offset = 0; size_t bytes_to_copy = 0; unsigned int written_entry_count = 0; unsigned int read_entry_count = 0; unsigned int total_entry_count = raw_current_entry()->totalEntryCount; // No OsFile_ routine to get the current position, // so keep this information by ourselves. juint data_file_position = 0; juint directory_file_position = 0; GUARANTEE(buffer_size >= LOCHDRSIZ && buffer_size >= EXTHDRSIZ && buffer_size >= ENDHDRSIZ && buffer_size >= MAX_ENTRY_NAME, "Buffer is too small"); if ((OsFile_seek(data_file_handle, 0L, SEEK_SET) < 0) || (OsFile_seek(directory_file_handle, 0L, SEEK_SET) < 0)) { return false; } for (read_entry_count = 0; read_entry_count < total_entry_count; read_entry_count++) { // Find the next entry in the JAR. bool found = find_entry(NULL JVM_MUST_SUCCEED); if (!found) { return false; } cen_header_offset = raw_current_entry()->nextCenOffset; // If find_entry succeeded, centralHeader contains the central directory // header for the found entry. unsigned char *cenp = (unsigned char *)raw_current_entry()->centralHeader; name_length = CENNAM(cenp); if (name_length >= MAX_ENTRY_NAME) { Throw::error(jarfile_error JVM_THROW_0); } else { jar_buffer().get_bytes(buffer, name_length); if (!JarFileParser::match(class_suffix, (char*)buffer, name_length)) { loc_header_offset = locOffset + CENOFF(cenp); // Update the relative offset of local header // in the central directory entry. // Use little-endian order according to the .ZIP format. Bytes::put_Java_u4(cenp + CENOFF_OFFSET, Bytes::swap_u4(data_file_position)); // Write the central directory entry to the directory file. if (OsFile_write(directory_file_handle, cenp, 1, CENHDRSIZ) != CENHDRSIZ) { return false; } directory_file_position += CENHDRSIZ; // Write the file name to the direcory file. if (OsFile_write(directory_file_handle, buffer, 1, name_length) != name_length) { return false; } directory_file_position += name_length; // Copy the extra field and file comment to the directory file. bytes_to_copy = CENEXT(cenp) + CENCOM(cenp); if (block_copy(&jar_buffer, directory_file_handle, bytes_to_copy) != bytes_to_copy) { return false; } directory_file_position += bytes_to_copy; // Copy the local file header to the data file. if ((jar_buffer().seek(loc_header_offset, SEEK_SET) < 0) || (jar_buffer().get_bytes(buffer, LOCHDRSIZ) != LOCHDRSIZ) || (OsFile_write(data_file_handle, buffer, 1, LOCHDRSIZ) != LOCHDRSIZ)) { return false; } data_file_position += LOCHDRSIZ; { unsigned char *locp = (unsigned char *)buffer; // Copy the file name, extra field and the compressed file data // to the data file. bytes_to_copy = LOCNAM(locp) + LOCEXT(locp) + CENSIZ(cenp); if (block_copy(&jar_buffer, data_file_handle, bytes_to_copy) != bytes_to_copy) { return false; } data_file_position += bytes_to_copy; // Check if the data descriptor exists. if ((LOCFLG(locp) & 8) == 8) { // Copy the data descriptor to the data file. if (jar_buffer().get_bytes(buffer, EXTHDRSIZ) != EXTHDRSIZ) { return false; } // The data descriptor may or may not start with the signature // depending on .ZIP file format revision used. if (GETSIG(buffer) == EXTSIG) { // According to the Info-ZIP Application Note 970311, // the data descriptor starts with the signature. if (OsFile_write(data_file_handle, buffer, 1, EXTHDRSIZ) != EXTHDRSIZ) { return false; } data_file_position += EXTHDRSIZ; } else { // According to the .ZIP format specification version 6.1.0, // the data descriptor doesn't start with the signature. if (OsFile_write(data_file_handle, buffer, 1, EXTHDRSIZ - 4) != EXTHDRSIZ - 4) { return false; } data_file_position += EXTHDRSIZ - 4; } } } written_entry_count++; } } cen_header_offset += CENHDRSIZ + name_length + CENEXT(cenp) + CENCOM(cenp); raw_current_entry()->nextCenOffset = cen_header_offset; } // Now that all central directory entries are processed, // cen_header_offset points to the end of the central directory. if (jar_buffer().seek(cen_header_offset, SEEK_SET) < 0) { return false; } if (jar_buffer().get_bytes(buffer, ENDHDRSIZ) != ENDHDRSIZ) { return false; } { unsigned char *endp = (unsigned char *)buffer; if (GETSIG(endp) != ENDSIG) { return false; } // Update the record to match the new number of entries. // Use little-endian order according to the .ZIP format. Bytes::put_Java_u2(endp + ENDSUB_OFFSET, Bytes::swap_u2(written_entry_count)); Bytes::put_Java_u2(endp + ENDTOT_OFFSET, Bytes::swap_u2(written_entry_count)); // The size of the central directory is exactly // the number of bytes written to the directory_file. Bytes::put_Java_u4(endp + ENDSIZ_OFFSET, Bytes::swap_u4(directory_file_position)); // The offset of the central directory is exactly // the number of bytes written to the data_file. Bytes::put_Java_u4(endp + ENDOFF_OFFSET, Bytes::swap_u4(data_file_position)); if (OsFile_write(directory_file_handle, endp, 1, ENDHDRSIZ) != ENDHDRSIZ) { return false; } if (block_copy(&jar_buffer, directory_file_handle, ENDCOM(endp)) != (size_t)ENDCOM(endp)) { return false; } } return true; }
SHORT block_cut(void) { block_copy(TRUE); }
SHORT block_copy(void) { block_copy(FALSE); }