Ejemplo n.º 1
0
int point_decompress(struct affine_point *p, const gcry_mpi_t x, int yflag, 
		     const struct domain_params *dp)
{
  gcry_mpi_t h, y;
  int res;
  h = gcry_mpi_snew(0);
  y = gcry_mpi_snew(0);
  gcry_mpi_mulm(h, x, x, dp->m);
  gcry_mpi_addm(h, h, dp->a, dp->m);
  gcry_mpi_mulm(h, h, x, dp->m);
  gcry_mpi_addm(h, h, dp->b, dp->m);
  if ((res = mod_root(y, h, dp->m)))
    if ((res = (gcry_mpi_cmp_ui(y, 0) || ! yflag))) {
      p->x = gcry_mpi_snew(0);
      p->y = gcry_mpi_snew(0);
      gcry_mpi_set(p->x, x);
      if (gcry_mpi_test_bit(y, 0) == yflag)
	gcry_mpi_set(p->y, y);
      else
	gcry_mpi_sub(p->y, dp->m, y);
      assert(point_on_curve(p, dp));
    }
  gcry_mpi_release(h);
  gcry_mpi_release(y);
  return res;
}
Ejemplo n.º 2
0
/* Algorithm 4.26 in the "Guide to Elliptic Curve Cryptography"               */
int embedded_key_validation(const struct affine_point *p,
			    const struct domain_params *dp)
{
  if (gcry_mpi_cmp_ui(p->x, 0) < 0 || gcry_mpi_cmp(p->x, dp->m) >= 0 ||
      gcry_mpi_cmp_ui(p->y, 0) < 0 || gcry_mpi_cmp(p->y, dp->m) >= 0)
    return 0;
  return ! point_is_zero(p) && point_on_curve(p, dp);
}
Ejemplo n.º 3
0
struct affine_point pointmul(const struct affine_point *p,
			     const gcry_mpi_t exp, 
			     const struct domain_params *dp)
{
  struct affine_point r = point_new();
  int n = gcry_mpi_get_nbits(exp);
  while (n) {
    point_double(&r, dp);
    if (gcry_mpi_test_bit(exp, --n))
      point_add(&r, p, dp);
  }
  assert(point_on_curve(&r, dp));
  return r;
}
Ejemplo n.º 4
0
struct affine_point pointmul(const struct affine_point *p,
			     const gcry_mpi_t exp, 
			     const struct domain_params *dp)
{
  struct jacobian_point r = jacobian_new();
  struct affine_point R;
  int n = gcry_mpi_get_nbits(exp);
  while (n) {
    jacobian_double(&r, dp);
    if (gcry_mpi_test_bit(exp, --n))
      jacobian_affine_point_add(&r, p, dp);
  }
  R = jacobian_to_affine(&r, dp);
  jacobian_release(&r);
  assert(point_on_curve(&R, dp));
  return R;
}
Ejemplo n.º 5
0
void CatmulRom::timestep()
{
    QVector3D p0, p1;
    if (size() < 4) return;
    if (m_animation_step == 0 && m_animation_vertex == 1)
    {
        p0 = points[m_animation_vertex];
    }
    else
        p0 = m_anim_p0;

    if (m_animation_vertex >= size() - 2)
    {
        m_animation_vertex = 1;
        m_animation_step = 0;
        p0 = points[m_animation_vertex];
    }
    else
    {
        if (m_animation_step >= SAMPLES)
        {
            m_animation_step = 0;

            m_animation_vertex++;
        }
        else
        {
            m_animation_step++;
        }
    }

    p1 = point_on_curve(points[m_animation_vertex - 1], points[m_animation_vertex ],
            points[m_animation_vertex + 1], points[m_animation_vertex + 2],
            (1.0f/SAMPLES) * m_animation_step);
    m_cube.set_orientation(calculate_frame(p0, p1));

    m_cube.set_position(p1);
    p0 = p1;
    m_anim_p0 = p0;
}
Ejemplo n.º 6
0
void CatmulRom::draw()
{

    double scale = 1;
    double scale2 = 1;
//     double scale2 = 1 * cos(90) + 2;
    if (size() < 2) return;

    int i, n;
    QVector3D p0, p1, prev;
    QMatrix3x3 cur_frame, prev_frame;
    // Draw curve
    if (size() >= 4 && m_draw_curve)
    {

        p0 = points[1];
        prev = p0;
        prev_frame = calculate_frame(p0, prev);
        for (n = 1; n < size() -2 ; n++)
        {
            for (i = 0; i < SAMPLES; i++)
            {
                scale2 = cos(((double)360 / size() -2 ) * n + i) + 2;
                glColor3f(m_curve_color.x(), m_curve_color.y(), m_curve_color.z());

                p1 = point_on_curve(points[n - 1],
                        points[n], points[n + 1],
                        points[n + 2], (1.0f/SAMPLES) * i);
                cur_frame = calculate_frame(p0, p1);
                if (m_shape.size() > 2 && m_draw_solid) draw_cross_section(p0, cur_frame,
                                                           prev, prev_frame,
                                                           scale, scale2);
                else DrawLib::drawLine(p0, p1);
                m_cube.draw();
                prev = p0; p0 = p1; prev_frame = cur_frame; scale = scale2;
            }
        }
    }
}
Ejemplo n.º 7
0
void CatmulRom::draw()
{
    if (n_points < 2) return;
    int i, n;
    int count = n_points - 1;

    QVector3D p0, p1;

    // Draw lines
    if (count >= 0 && show_lines)
    {
        QVector3D q0, q1;
        p0 = points[0];
        glColor3f(line_color.x(), line_color.y(), line_color.z());
        for (i = 0; i <= count; i++)
        {
            if (count < 1) break;
            q1 = points[i];

            DrawLib::drawLine(q0, q1);
            q0 = q1;
        }
    }

    if (n_points >= 4 && draw_curve)
    {
        glColor3f(curve_color.x(), curve_color.y(), curve_color.z());
        p0 = points[1];
        for (n = 1; n < this->size() - 2; n++)
        {
            for (i = 0; i < SAMPLES; i++)
            {
                p1 = point_on_curve(points[n - 1], points[n], points[n + 1], points[n + 2], (1.0f/SAMPLES) * i);
                DrawLib::drawLine(p0, p1);
                p0 = p1;
            }
        }
    }
}
Ejemplo n.º 8
0
void squash_sheet(
  tectonic_sheet *ts,
  float lower_cutoff,
  float new_min,
  float upper_cutoff,
  float new_max
) {
  size_t i, j, idx;
  size_t pw, ph;
  float old_min, old_max;
  vector *p;
  float interp;
  curve lcurve, ucurve;
  vector bzr;

  pw = sheet_pwidth(ts);
  ph = sheet_pwidth(ts);

  old_min = sheet_min_z(ts);
  old_max = sheet_max_z(ts);

  // set up the lower and upper interpolation curves:
  lcurve.from.x = 0;
  lcurve.from.y = lower_cutoff;
  lcurve.from.z = 0;
  lcurve.go_towards.x = 0.5; // TODO: Be smarter here!
  lcurve.go_towards.y = new_min;
  lcurve.go_towards.z = 0;
  vcopy_as(&(lcurve.come_from), &(lcurve.go_towards));
  lcurve.to.x = 1.0;
  lcurve.to.y = new_min;
  lcurve.to.z = 0;

  ucurve.from.x = 0;
  ucurve.from.y = upper_cutoff;
  ucurve.from.z = 0;
  ucurve.go_towards.x = 0.5; // TODO: Be smarter here!
  ucurve.go_towards.y = new_max;
  ucurve.go_towards.z = 0;
  vcopy_as(&(ucurve.come_from), &(ucurve.go_towards));
  ucurve.to.x = 1.0;
  ucurve.to.y = new_max;
  ucurve.to.z = 0;

  // Only pass: squash lower and upper z values:
  for (i = 0; i < pw; ++i) {
    for (j = 0; j < ph; ++j) {
      idx = sheet_pidx(ts, i, j);
      p = &(ts->points[idx]);

      if (p->z < lower_cutoff) {
        interp = (lower_cutoff - p->z) / (lower_cutoff - old_min);
        point_on_curve(&lcurve, interp, &bzr);
        p->z = bzr.y;
      } else if (p->z > upper_cutoff) {
        interp = (p->z - upper_cutoff) / (old_max - upper_cutoff);
        point_on_curve(&ucurve, interp, &bzr);
        p->z = bzr.y;
      }
    }
  }
}