Example #1
0
/** \brief set the IV
 */
void	skey_ciph_t::set_iv(const skey_ciph_iv_t & iv)				const throw()
{
	void *			iv_ptr = (void *)iv.get_iv_ptr();
	gcry_error_t		err;
	// if no iv is required, return now
	if( require_iv() == false )		return;
	// if an iv is required, set it
	if( ciph_type.get_mode() == skey_ciph_mode_t::CTR ){
		err = gcry_cipher_setctr( gcry_cipher_hd, iv_ptr, get_block_len() );
		DBG_ASSERT( !err );
	}else{
		err = gcry_cipher_setiv( gcry_cipher_hd, iv_ptr, get_block_len() );
		DBG_ASSERT( !err );
	}
}
void
mn_non_linear_range_setup_static (GtkRange *range,
				  const MNNonLinearRangeBlock *blocks,
				  int num_blocks)
{
  RangeInfo *info;
  int i;
  int num_values = 0;

  g_return_if_fail(GTK_IS_RANGE(range));
  g_return_if_fail(blocks != NULL);
  g_return_if_fail(num_blocks > 0);

  global_init();

  info = g_new0(RangeInfo, 1);
  info->blocks = blocks;
  info->num_blocks = num_blocks;

  g_object_set_qdata_full(G_OBJECT(range), info_quark, info, g_free);

  for (i = 0; i < num_blocks; i++)
    num_values += get_block_len(&blocks[i]);

  gtk_range_set_range(range, 0, num_values - 1);
}
int
mn_non_linear_range_get_value (GtkRange *range)
{
  RangeInfo *info;
  int raw;
  int offset = 0;
  int i;

  g_return_val_if_fail(GTK_IS_RANGE(range), -1);

  info = get_info(range);

  raw = (int) gtk_range_get_value(range);

  for (i = 0; i < info->num_blocks; i++)
    {
      const MNNonLinearRangeBlock *block = &info->blocks[i];
      int next_offset;

      next_offset = offset + get_block_len(block);

      if (raw >= offset && raw < next_offset)
	return block->min + (raw - offset) * block->step;

      offset = next_offset;
    }

  g_assert_not_reached();
  return -1;
}
Example #4
0
/** \brief return the padding length (ala pkcs5)
 * 
 * - see rfc2898.6.1.1.4
 * - if the mode require padding, the padding is ALWAYS at least 1 byte
 */
size_t	skey_ciph_t::padding_cpu_len(size_t plaintxt_len)	const throw()
{
	// if no padding is required, return 0
	if( require_padding() == false )		return 0;
	// compute and return the padding length
	size_t	block_len	= get_block_len();
	size_t	padding_len	= block_len - (plaintxt_len % block_len);
	// sanity check - because of the current padding encoding, the padding length MUST < 255
	DBG_ASSERT(padding_len < 255);
	// return the length
	return padding_len;
}
static int
value_to_index (RangeInfo *info, int value)
{
  int offset = 0;
  int i;

  /* if smaller than the first value, use the first value */
  if (value < info->blocks[0].min)
    return 0;

  for (i = 0; i < info->num_blocks; i++)
    {
      const MNNonLinearRangeBlock *block = &info->blocks[i];

      if (value >= block->min && value <= block->max)
	{
	  int rounded;
	  int index;
	  int j;

	  /* round the value to the nearest step */
	  rounded = lround((double) value / block->step) * block->step;

	  for (j = block->min, index = 0; j <= block->max; j += block->step, index++)
	    if (j == rounded)
	      return offset + index;

	  g_assert_not_reached();
	}

      offset += get_block_len(block);
    }

  /* block not found: fallback to the maximum value */
  return offset - 1;
}