Beispiel #1
0
/** @brief call the ECC power ladder point-scalar multiply */
msel_status msel_ecc_mul(ecc_ctx_t* ctx)
{
#ifdef USE_SW_ECC

	// Get the scalar value
	make_mp(scalar, ctx->scalar, ECC_SCALAR_LEN);
	make_mp(compressed, ctx->point, ECC_POINT_LEN);

	// The sign of y is the 7th bit of the first byte
	int y_sign = ctx->point[0] & 0x01;
	point_uncompress(&in, compressed, y_sign);

	// Do the multiply
	point_scalar(&out, &in, scalar);

	// Compress the point -- this removes from mont. form
	point_compress(compressed, &y_sign, &out);
	ctx->point[0] &= 0xfe; ctx->point[0] |= y_sign;

	// Load the new point into the buffer
	from_mp(ctx->point, compressed, ECC_POINT_LEN);

    return MSEL_OK;
#else /* USE_SW_ECC */
    return arch_hw_ecc_mul(ctx);
#endif /* USE_SW_ECC */
}
Beispiel #2
0
void compress_to_string(char *buf, enum disp_format df,
			const struct affine_point *P, 
			const struct curve_params *cp)
{
  int outlen = (df == DF_COMPACT) ? cp->pk_len_compact : cp->pk_len_bin;
  if (point_compress(P)) {
    gcry_mpi_t x;
    x = gcry_mpi_snew(0);
    gcry_mpi_add(x, P->x, cp->dp.m);
    serialize_mpi(buf, outlen, df, x);
    gcry_mpi_release(x);
  }
  else
    serialize_mpi(buf, outlen, df, P->x);
}