void prng_init(prng_entropy_fn fun, prng_ctx ctx[1]) { int i; /* clear the buffers and the counter in the context */ memset(ctx, 0, sizeof(prng_ctx)); /* set the pointer to the entropy collection function */ ctx->entropy = fun; /* initialise the random data pool */ update_pool(ctx); /* mix the pool a minimum number of times */ for(i = 0; i < PRNG_MIN_MIX; ++i) prng_mix(ctx->rbuf); /* update the pool to prime the pool output buffer */ update_pool(ctx); }
void prng_rand(unsigned char data[], unsigned int data_len, prng_ctx ctx[1]) { unsigned char *rp = data; unsigned int len, pos = ctx->pos; while(data_len) { /* transfer 'data_len' bytes (or the number of bytes remaining */ /* the pool output buffer if less) into the output */ len = (data_len < PRNG_POOL_SIZE - pos ? data_len : PRNG_POOL_SIZE - pos); memcpy(rp, ctx->obuf + pos, len); rp += len; /* update ouput buffer position pointer */ pos += len; /* update pool output buffer pointer */ data_len -= len; /* update the remaining data count */ /* refresh the random pool if necessary */ if(pos == PRNG_POOL_SIZE) { update_pool(ctx); pos = 0; } } ctx->pos = pos; }
/* * Update a Pool Record in the database. * It is always updated from the Resource record. * * update pool=<pool-name> * updates pool from Pool resource * update media pool=<pool-name> volume=<volume-name> * changes pool info for volume * update slots [scan=...] * updates autochanger slots * update stats [days=...] * updates long term statistics */ int update_cmd(UAContext *ua, const char *cmd) { static const char *kw[] = { NT_("media"), /* 0 */ NT_("volume"), /* 1 */ NT_("pool"), /* 2 */ NT_("slots"), /* 3 */ NT_("slot"), /* 4 */ NT_("jobid"), /* 5 */ NT_("stats"), /* 6 */ NULL}; if (!open_client_db(ua)) { return 1; } switch (find_arg_keyword(ua, kw)) { case 0: case 1: update_volume(ua); return 1; case 2: update_pool(ua); return 1; case 3: case 4: update_slots(ua); return 1; case 5: update_job(ua); return 1; case 6: update_stats(ua); return 1; default: break; } start_prompt(ua, _("Update choice:\n")); add_prompt(ua, _("Volume parameters")); add_prompt(ua, _("Pool from resource")); add_prompt(ua, _("Slots from autochanger")); add_prompt(ua, _("Long term statistics")); switch (do_prompt(ua, _("item"), _("Choose catalog item to update"), NULL, 0)) { case 0: update_volume(ua); break; case 1: update_pool(ua); break; case 2: update_slots(ua); break; case 3: update_stats(ua); break; default: break; } return 1; }