static Errcode mask_move_cels(Pframedat *pfd) /* ccb.cel a goes to mask 0 ccb.celb goes to mask non 0 */ { int y; Pixel *bline, *bgetbuf; Rcel *bcel; Coor width; Coor bx, bwidth; Errcode err = Success; width = pfd->dest->width; pfd->aline = pfd->lbuf; pfd->dline = pfd->aline + width; if(ccb.fcelb->flags & FCEL_XFORMED) { err = raster_transform(ccb.fcelb->rc,pfd->dest,&ccb.fcelb->xf, put_celsline, pfd, 0 ); goto OUT; } bline = pfd->dline + width; bcel = ccb.fcelb->rc; bx = bcel->x; bgetbuf = bline; bwidth = width; if(bx) { clear_mem(bline,sizeof(Pixel)*width); if(bx > 0) /* smaller than dest */ { bgetbuf += bx; bx = 0; bwidth = ccb.fcelb->flif.hdr.width; } else /* bigger than dest */ bx = -bx; } for(y = 0; y < pfd->dest->height;++y) { if(y < bcel->y || y >= (bcel->y + bcel->height)) clear_mem(bline,sizeof(Pixel)*width); else pj_get_hseg(bcel,bgetbuf,bx,y - bcel->y,bwidth); if((err = put_celsline(pfd,bline,0,y,width)) < Success) break; } OUT: return(errend_abort_atom(err)); }
static void config_input(void) { int choice; char dev_type; char buf[PATH_SIZE]; USHORT idis[9]; UBYTE modes[IDR_MAX_OPTIONS]; char sbuf[80]; clear_mem(idis,sizeof(idis)); idis[vconfg.dev_type] = QCF_ASTERISK; if(!resource_exists(summa_idriver_name)) idis[1] |= QCF_DISABLED; choice = soft_qchoice(idis, "input_device" ); switch (choice) { default: return; case 0: dev_type = 0; strcpy(buf, mouse_idriver_name); break; case 1: dev_type = 1; strcpy(buf, summa_idriver_name); break; case 2: if(vconfg.dev_type == 2) strcpy(buf,vconfg.idr_name); else buf[0] = 0; if(!req_resource_name(buf,"*.idr", stack_string("idr_scroll", sbuf))) { return; } dev_type = 2; break; case 3: if (!get_serial_port()) return; goto REWRITE; } memcpy(modes,vconfg.idr_modes,sizeof(modes)); if(config_idriver(buf, modes, txtcmp(vconfg.idr_name,buf) == 0, (SHORT)vconfg.comm_port) < Success) { return; } vconfg.dev_type = dev_type; memcpy(vconfg.idr_modes,modes,sizeof(modes)); strcpy(vconfg.idr_name, buf); REWRITE: rewrite_config(); cleanup_idriver(); init_input(); }
void mauINIT() { textattr(atrINIT); cprintf("\nStarting Memory Allocation Unit..."); textattr(atrBORDER); cprintf("\n\tMemory: "); textattr(atrIMPTEXT); cprintf("%ld", mem); textattr(atrBORDER); cprintf(" kB"); // povolenie linky A20 EnableA20(); cprintf("\n\tLink A20 enabled..."); // max. pocet poloziek if (mem < MAX_ITEMS) max_items = mem - 36; else max_items = MAX_ITEMS - 36; // cistenie tabulky pamate clear_mem(); // zaciatok alokovania pamate MemStart = MK_FP(0x3400,0); //(fyzicka adresa) textattr(atrBORDER); cprintf("\n\tFree memory: "); textattr(atrIMPTEXT); cprintf("%ld", coreleft()); textattr(atrBORDER); cputs(" kB"); }
/************************************************* * Simple O(N^2) Multiplication * *************************************************/ void bigint_smul(word z[], const word x[], u32bit x_size, const word y[], u32bit y_size) { const u32bit blocks = y_size - (y_size % 8); clear_mem(z, x_size + y_size); for(u32bit j = 0; j != x_size; j++) { const word x_j = x[j]; word carry = 0; for(u32bit k = 0; k != blocks; k += 8) { bigint_madd(x_j, y[k+0], z[j+k+0], carry, z + (j+k+0), &carry); bigint_madd(x_j, y[k+1], z[j+k+1], carry, z + (j+k+1), &carry); bigint_madd(x_j, y[k+2], z[j+k+2], carry, z + (j+k+2), &carry); bigint_madd(x_j, y[k+3], z[j+k+3], carry, z + (j+k+3), &carry); bigint_madd(x_j, y[k+4], z[j+k+4], carry, z + (j+k+4), &carry); bigint_madd(x_j, y[k+5], z[j+k+5], carry, z + (j+k+5), &carry); bigint_madd(x_j, y[k+6], z[j+k+6], carry, z + (j+k+6), &carry); bigint_madd(x_j, y[k+7], z[j+k+7], carry, z + (j+k+7), &carry); } for(u32bit k = blocks; k != y_size; k++) bigint_madd(x_j, y[k], z[j+k], carry, z + (j+k), &carry); z[j+y_size] = carry; } }
void new_config(void) /* configure numbered item menu */ { USHORT cdis[10]; clear_mem(cdis, sizeof(cdis)); if (vs.dcoor) cdis[3] = QCF_ASTERISK; switch(soft_qchoice(cdis, "configuration")) { case 0: /* set temp path */ config_path(); break; case 1: save_default_settings(); break; case 2: config_input(); break; case 3: vs.dcoor = !vs.dcoor; break; default: break; } }
/** * Attempt a connection to an EGD/PRNGD socket */ int EGD_EntropySource::EGD_Socket::open_socket(const std::string& path) { int fd = ::socket(PF_LOCAL, SOCK_STREAM, 0); if(fd >= 0) { sockaddr_un addr; clear_mem(&addr, 1); addr.sun_family = PF_LOCAL; if(path.length() >= sizeof(addr.sun_path)) throw std::invalid_argument("EGD socket path is too long"); std::strncpy(addr.sun_path, path.c_str(), sizeof(addr.sun_path)); int len = sizeof(addr.sun_family) + std::strlen(addr.sun_path) + 1; if(::connect(fd, reinterpret_cast<struct ::sockaddr*>(&addr), len) < 0) { ::close(fd); fd = -1; } } return fd; }
void sim_init() { /* Create memory and register files */ initialized = 1; mem = init_mem(MEM_SIZE); reg = init_reg(); /* create 5 pipe registers */ pc_state = new_pipe(sizeof(pc_ele), (void *) &bubble_pc); if_id_state = new_pipe(sizeof(if_id_ele), (void *) &bubble_if_id); id_ex_state = new_pipe(sizeof(id_ex_ele), (void *) &bubble_id_ex); ex_mem_state = new_pipe(sizeof(ex_mem_ele), (void *) &bubble_ex_mem); mem_wb_state = new_pipe(sizeof(mem_wb_ele), (void *) &bubble_mem_wb); /* connect them to the pipeline stages */ pc_next = pc_state->next; pc_curr = pc_state->current; if_id_next = if_id_state->next; if_id_curr = if_id_state->current; id_ex_next = id_ex_state->next; id_ex_curr = id_ex_state->current; ex_mem_next = ex_mem_state->next; ex_mem_curr = ex_mem_state->current; mem_wb_next = mem_wb_state->next; mem_wb_curr = mem_wb_state->current; sim_reset(); clear_mem(mem); }
void sim_reset() { if (!initialized) sim_init(); clear_pipes(); clear_mem(reg); minAddr = 0; memCnt = 0; starting_up = 1; cycles = instructions = 0; #ifdef HAS_GUI if (gui_mode) { signal_register_clear(); create_memory_display(minAddr, memCnt); } #endif amux = bmux = MUX_NONE; cc = cc_in = DEFAULT_CC; wb_destE = REG_NONE; wb_valE = 0; wb_destM = REG_NONE; wb_valM = 0; mem_addr = 0; mem_data = 0; mem_write = FALSE; sim_report(); }
/** Frees all memory used to hold the list. O(n) operation. * @param l The list */ void slist_free(struct slist *l) { while(l != NULL) { clear_mem(l); l = l->next; } }
/** Removes @a d from list @a l, if it exists. No action is taken * if @a d does not exist in @a l. O(n) operation. * @param l The list * @param d The data member to be removed. * @return The new list. */ struct slist *slist_remove(struct slist *l, void *d) { struct slist *head = l; struct slist *prev; if(head && head->data == d) { clear_mem(head); return head->next; } while(l && (prev = l, l = l->next) != NULL) { if(l->data == d) { prev->next = l->next; clear_mem(l); } } return head; }
void sim_reset() { if (!initialized) sim_init(); clear_mem(reg); minAddr = 0; memCnt = 0; #ifdef HAS_GUI if (gui_mode) { signal_register_clear(); create_memory_display(minAddr, memCnt); sim_report(); } #endif if (plusmode) { prev_icode = prev_icode_in = I_NOP; prev_ifun = prev_ifun_in = 0; prev_valc = prev_valc_in = 0; prev_valm = prev_valm_in = 0; prev_valp = prev_valp_in = 0; prev_bcond = prev_bcond_in = FALSE; pc = 0; } else { pc_in = 0; } cc = DEFAULT_CC; cc_in = DEFAULT_CC; destE = REG_NONE; destM = REG_NONE; mem_write = FALSE; mem_addr = 0; mem_data = 0; /* Reset intermediate values to clear display */ icode = I_NOP; ifun = 0; instr = HPACK(I_NOP, F_NONE); ra = REG_NONE; rb = REG_NONE; valc = 0; valp = 0; srcA = REG_NONE; srcB = REG_NONE; destE = REG_NONE; destM = REG_NONE; vala = 0; valb = 0; vale = 0; cond = FALSE; bcond = FALSE; valm = 0; sim_report(); }
static void *tget_clear() /* Return an unused sector initialized to all zeroes. */ { void *pt; if ((pt = tget_sector()) != NULL) clear_mem(pt, TRD_SECTOR); return(pt); }
Errcode pj_write_zeros(Jfile file,LONG oset, LONG bytes) { Errcode err; char sbuf[256]; /* static buffer */ char *buf; LONG blocksize; if(bytes <= sizeof(sbuf)) { blocksize = bytes; buf = sbuf; clear_mem(buf,blocksize); } else { if(bytes < 16*1024) blocksize = bytes; else blocksize = 16*1024; if((buf = pj_zalloc(blocksize)) == NULL) { blocksize = sizeof(sbuf); buf = sbuf; clear_mem(sbuf,sizeof(sbuf)); } } while(bytes > 0) { if((err = pj_writeoset(file,buf,oset,blocksize)) < Success) goto error; oset += blocksize; if(bytes < blocksize) blocksize = bytes; else bytes -= blocksize; } err = Success; error: if(buf != &sbuf[0]) pj_free(buf); return(err); }
Errcode create_flxfile(char *path, Flxfile *flx) /* this will always leave file position at end of header and path record */ { extern Errcode pj_i_create(char *path, Flifile *flif); clear_mem(flx,sizeof(*flx)); flx->hdr.type = FLIX_MAGIC; flx->comp_type = pj_fli_comp_ani; return(pj_i_create(path,(Flifile *)flx)); }
void sim_init() { /* Create memory and register files */ initialized = 1; mem = init_mem(MEM_SIZE); reg = init_reg(); sim_reset(); clear_mem(mem); }
void mauDESTROY() { textattr(atrINIT); cprintf("\nFreeing memory..."); clear_mem(); cprintf("\nStopping Memory Allocation Unit..."); textattr(atrBORDER); DisableA20(); cprintf("\n\tLink A20 disabled..."); }
/** * camel_stream_mem_set_byte_array: * @mem: a #CamelStreamMem object * @buffer: a #GByteArray * * Set @buffer to be the backing data to the existing #CamelStreamMem, @mem. * * Note: @mem will not take ownership of @buffer and so will need to * be freed separately from @mem. **/ void camel_stream_mem_set_byte_array (CamelStreamMem *mem, GByteArray *buffer) { if (mem->buffer && mem->owner) { if (mem->secure && mem->buffer->len) clear_mem (mem->buffer->data, mem->buffer->len); g_byte_array_free (mem->buffer, TRUE); } mem->owner = FALSE; mem->buffer = buffer; }
/* * Finish encrypting in CTS mode */ void CTS_Encryption::end_msg() { if(position < BLOCK_SIZE + 1) throw Exception("CTS_Encryption: insufficient data to encrypt"); xor_buf(state, buffer, BLOCK_SIZE); cipher->encrypt(state); SecureVector<byte> cn = state; clear_mem(buffer + position, BUFFER_SIZE - position); encrypt(buffer + BLOCK_SIZE); send(cn, position - BLOCK_SIZE); }
static void camel_stream_mem_finalize (CamelObject *object) { CamelStreamMem *s = CAMEL_STREAM_MEM (object); if (s->buffer && s->owner) { /* TODO: we need our own bytearray type since we don't know the real size of the underlying buffer :-/ */ if (s->secure && s->buffer->len) clear_mem(s->buffer->data, s->buffer->len); g_byte_array_free(s->buffer, TRUE); } }
void aont_package(RandomNumberGenerator& rng, BlockCipher* cipher, const byte input[], size_t input_len, byte output[]) { const size_t BLOCK_SIZE = cipher->block_size(); if(!cipher->valid_keylength(BLOCK_SIZE)) throw Invalid_Argument("AONT::package: Invalid cipher"); // The all-zero string which is used both as the CTR IV and as K0 const std::string all_zeros(BLOCK_SIZE*2, '0'); SymmetricKey package_key(rng, BLOCK_SIZE); Pipe pipe(new StreamCipher_Filter(new CTR_BE(cipher), package_key)); pipe.process_msg(input, input_len); pipe.read(output, pipe.remaining()); // Set K0 (the all zero key) cipher->set_key(SymmetricKey(all_zeros)); SecureVector<byte> buf(BLOCK_SIZE); const size_t blocks = (input_len + BLOCK_SIZE - 1) / BLOCK_SIZE; byte* final_block = output + input_len; clear_mem(final_block, BLOCK_SIZE); // XOR the hash blocks into the final block for(size_t i = 0; i != blocks; ++i) { const size_t left = std::min<size_t>(BLOCK_SIZE, input_len - BLOCK_SIZE * i); zeroise(buf); copy_mem(&buf[0], output + (BLOCK_SIZE * i), left); for(size_t j = 0; j != sizeof(i); ++j) buf[BLOCK_SIZE - 1 - j] ^= get_byte(sizeof(i)-1-j, i); cipher->encrypt(buf); xor_buf(final_block, buf, BLOCK_SIZE); } // XOR the random package key into the final block xor_buf(final_block, package_key.begin(), BLOCK_SIZE); }
void qconv_slide() /***************************************************************************** * Put up slide menu. ****************************************************************************/ { USHORT mdis[8]; short temp; if (cs.slide_frames <= 0) cs.slide_frames = 50; for (;;) { /* set up asterisks */ clear_mem(mdis, sizeof(mdis)); if (cs.slide_complete) mdis[4] |= QCF_ASTERISK; switch (soft_qchoice(mdis, "!%d%d%d", "conv_slide", cs.slidex,cs.slidey,cs.slide_frames)) { case 0: slide_with_mouse(); break; case 1: temp = cs.ifi.cel->width; soft_qreq_number(&cs.slidex, -temp, temp, "conv_slidex"); break; case 2: temp = cs.ifi.cel->height; soft_qreq_number(&cs.slidey, -temp, temp, "conv_slidey"); break; case 3: soft_qreq_number(&cs.slide_frames, 2, 100, "conv_slidef"); if (cs.slide_frames < 1) cs.slide_frames = 1; if (cs.slide_frames > MAXFRAMES) cs.slide_frames = MAXFRAMES; break; case 4: cs.slide_complete = !cs.slide_complete; break; case 5: preview_slide(); break; case 6: render_slide(); break; default: return; } } }
void bigint_mul(word z[], size_t z_size, const word x[], size_t x_size, size_t x_sw, const word y[], size_t y_size, size_t y_sw, word workspace[], size_t ws_size) { clear_mem(z, z_size); if(x_sw == 1) { bigint_linmul3(z, y, y_sw, x[0]); } else if(y_sw == 1) { bigint_linmul3(z, x, x_sw, y[0]); } else if(sized_for_comba_mul<4>(x_sw, x_size, y_sw, y_size, z_size)) { bigint_comba_mul4(z, x, y); } else if(sized_for_comba_mul<6>(x_sw, x_size, y_sw, y_size, z_size)) { bigint_comba_mul6(z, x, y); } else if(sized_for_comba_mul<8>(x_sw, x_size, y_sw, y_size, z_size)) { bigint_comba_mul8(z, x, y); } else if(sized_for_comba_mul<9>(x_sw, x_size, y_sw, y_size, z_size)) { bigint_comba_mul9(z, x, y); } else if(sized_for_comba_mul<16>(x_sw, x_size, y_sw, y_size, z_size)) { bigint_comba_mul16(z, x, y); } else if(x_sw < KARATSUBA_MULTIPLY_THRESHOLD || y_sw < KARATSUBA_MULTIPLY_THRESHOLD || !workspace) { basecase_mul(z, z_size, x, x_sw, y, y_sw); } else { const size_t N = karatsuba_size(z_size, x_size, x_sw, y_size, y_sw); if(N && z_size >= 2*N && ws_size >= 2*N) karatsuba_mul(z, x, y, N, workspace); else basecase_mul(z, z_size, x, x_sw, y, y_sw); } }
/************************************************* * Mark this memory as free, if we own it * *************************************************/ void Pooling_Allocator::Memory_Block::free(void* ptr, u32bit blocks) throw() { clear_mem((byte*)ptr, blocks * BLOCK_SIZE); const u32bit offset = ((byte*)ptr - buffer) / BLOCK_SIZE; if(offset == 0 && blocks == BITMAP_SIZE) bitmap = ~bitmap; else { for(u32bit j = 0; j != blocks; ++j) bitmap &= ~((bitmap_type)1 << (j+offset)); } }
void init_pullwork(Pullwork *pw, Menuhdr *mh) /* initializes a pullwork struct prior to calling pull subroutines * pull menuhdr must be open !! */ { clear_mem(pw,sizeof(*pw)); pw->root = mh; pw->screen = mh->group->screen; pw->port = pw->screen->viscel; /* default port */ if((pw->font = mh->font) == NULL) { extern struct vfont *get_sys_font(); pw->font = pw->screen->mufont; } pw->spwidth = fchar_spacing(pw->font," "); pw->cheight = tallest_char(pw->font); }
static Boolean get_serial_port(void) { int choice; USHORT cdis[9]; clear_mem(cdis, sizeof(cdis)); cdis[(7 & vconfg.comm_port)] |= QCF_ASTERISK; if((choice = soft_qchoice(cdis, "comm_port")) >= Success) { if (!pj_comm_exists(choice)) soft_continu_box("!%d", "no_comm", choice + 1); else vconfg.comm_port = choice; } return(choice); }
/* * Squaring Algorithm Dispatcher */ void bigint_sqr(word z[], size_t z_size, const word x[], size_t x_size, size_t x_sw, word workspace[], size_t ws_size) { clear_mem(z, z_size); BOTAN_ASSERT(z_size/2 >= x_sw, "Output size is sufficient"); if(x_sw == 1) { bigint_linmul3(z, x, x_sw, x[0]); } else if(sized_for_comba_sqr<4>(x_sw, x_size, z_size)) { bigint_comba_sqr4(z, x); } else if(sized_for_comba_sqr<6>(x_sw, x_size, z_size)) { bigint_comba_sqr6(z, x); } else if(sized_for_comba_sqr<8>(x_sw, x_size, z_size)) { bigint_comba_sqr8(z, x); } else if(sized_for_comba_sqr<9>(x_sw, x_size, z_size)) { bigint_comba_sqr9(z, x); } else if(sized_for_comba_sqr<16>(x_sw, x_size, z_size)) { bigint_comba_sqr16(z, x); } else if(x_size < KARATSUBA_SQUARE_THRESHOLD || !workspace) { basecase_sqr(z, z_size, x, x_sw); } else { const size_t N = karatsuba_size(z_size, x_size, x_sw); if(N && z_size >= 2*N && ws_size >= 2*N) karatsuba_sqr(z, x, N, workspace); else basecase_sqr(z, z_size, x, x_sw); } }
static void go_gridreq(Boolean keep_undo) /* put up numbered choice menu for grid certain items are disabled or altered * for overlayed environs that need the undo buffer in sync with the screen */ { int choice; USHORT gdis[6]; SHORT angle; hide_mp(); for (;;) { clear_mem(gdis, sizeof(gdis)); if (vs.use_grid) gdis[0] = QCF_ASTERISK; if(keep_undo) gdis[2] |= QCF_DISABLED; /* no pasting !! */ if ((choice = soft_qchoice(gdis, "grid")) < Success) break; switch (choice) { case 0: /* use grid */ vs.use_grid = !vs.use_grid; break; case 1: /* make grid */ do_qfunc(make_grid,keep_undo); break; case 2: /* paste grid */ uzauto(paste1_grid, NULL); break; case 3: /* see grid */ do_qfunc(see_grid,keep_undo); break; case 4: /* set rot grid */ angle = 0.5 + ((360.0*(FLOAT)vs.rot_grid)/FCEL_TWOPI); if(soft_qreq_number(&angle,0,359,"rot_grid")) vs.rot_grid = 0.5 + (((FLOAT)angle*FCEL_TWOPI)/360.0); break; default: goto OUT; } } OUT: show_mp(); }
static void stream_mem_finalize (GObject *object) { CamelStreamMemPrivate *priv; priv = CAMEL_STREAM_MEM_GET_PRIVATE (object); if (priv->buffer && priv->owner) { /* TODO: we need our own bytearray type since we don't know the real size of the underlying buffer :-/ */ if (priv->secure && priv->buffer->len) clear_mem (priv->buffer->data, priv->buffer->len); g_byte_array_free (priv->buffer, TRUE); } /* Chain up to parent's finalize() method. */ G_OBJECT_CLASS (camel_stream_mem_parent_class)->finalize (object); }
/* * Finalize a hash */ void Streebog::final_result(uint8_t output[]) { m_buffer[m_position++] = 0x01; if(m_position != m_buffer.size()) clear_mem(&m_buffer[m_position], m_buffer.size() - m_position); compress(m_buffer.data()); m_count += (m_position - 1) * 8; zeroise(m_buffer); store_le(m_count, m_buffer.data()); compress(m_buffer.data(), true); compress_64(m_S.data(), true); // FIXME std::memcpy(output, &m_h[8 - output_length() / 8], output_length()); clear(); }
/************************************************* * Multiplication Algorithm Dispatcher * *************************************************/ void bigint_mul(word z[], u32bit z_size, word workspace[], const word x[], u32bit x_size, u32bit x_sw, const word y[], u32bit y_size, u32bit y_sw) { if(x_size <= 8 || y_size <= 8) { handle_small_mul(z, z_size, x, x_size, x_sw, y, y_size, y_sw); return; } const u32bit N = karatsuba_size(z_size, x_size, x_sw, y_size, y_sw); if(N) { clear_mem(workspace, 2*N); karatsuba_mul(z, x, y, N, workspace); } else bigint_simple_mul(z, x, x_sw, y, y_sw); }