ta/wallet_ta.c
/**
  * Serialise an elliptic curve point in a manner which is Bitcoin-compatible.
  * This means using the serialisation rules in:
  * "SEC 1: Elliptic Curve Cryptography" by Certicom research, obtained
  * 15-August-2011 from: http://www.secg.org/collateral/sec1_final.pdf
  * sections 2.3.2 ("OctetString-to-BitString Conversion") and
  * 2.3.3 ("EllipticCurvePoint-to-OctetString Conversion").
  * The document basically says that integers should be represented big-endian
  * and that a prefix byte should be perpended to indicate that the public key
  * is compressed or not.
  * \param out Where the serialised point will be written to. This must be a
  *            byte array with space for at least #ECDSA_MAX_SERIALISE_SIZE
  *            bytes.
  * \param point The elliptic point curve to serialise.
  * \param do_compress Whether to apply point compression - this will reduce
  *                    the size of public keys and hence transactions.
  *                    As of 2014, all Bitcoin clients out there are able to
  *                    decompress points, so it should be safe to always
  *                    compress points.
  * \return The number of bytes written to out.
  */
Serialise an elliptic curve point in a manner which is Bitcoin-compatible.
Serialise an elliptic curve point in a manner which is Bitcoin - compatible .
static uint8_t ecdsa_serialise_internal(uint8_t *out, const PointAffine *point, const bool do_compress)
{
	PointAffine temp;
	TEE_MemMove((PointAffine*)&temp, (PointAffine*)point, (uint32_t)sizeof(temp)); 
	if (temp.is_point_at_infinity)
	{
		out[0] = 0x00;
		return 1;
	}
	else if (!do_compress)
	{
		out[0] = 0x04;
		swap_endian256_internal(temp.x);
		swap_endian256_internal(temp.y);
		TEE_MemMove((uint8_t*)&(out[1]), (uint8_t*)(temp.x), 32);
		TEE_MemMove((uint8_t*)&(out[33]), (uint8_t*)(temp.y), 32);
		return 65;
	}
	else
	{
		if ((temp.y[0] & 1) != 0)
			out[0] = 0x03; 
		else
			out[0] = 0x02; 
		swap_endian256_internal(temp.x);
		TEE_MemMove((uint8_t*)&(out[1]), (uint8_t*)(temp.x), 32);
		return 33;
	}
}
static uint8_t ecdsa_serialise_internal ( uint8_t * out , const PointAffine * point , const bool do_compress ) { PointAffine temp ; TEE_MemMove ( ( PointAffine * ) & temp , ( PointAffine * ) point , ( uint32_t ) sizeof ( temp ) ) ; if ( temp . is_point_at_infinity ) { out [ 0 ] = 0x00 ; return 1 ; } else if ( ! do_compress ) { out [ 0 ] = 0x04 ; swap_endian256_internal ( temp . x ) ; swap_endian256_internal ( temp . y ) ; TEE_MemMove ( ( uint8_t * ) & ( out [ 1 ] ) , ( uint8_t * ) ( temp . x ) , 32 ) ; TEE_MemMove ( ( uint8_t * ) & ( out [ 33 ] ) , ( uint8_t * ) ( temp . y ) , 32 ) ; return 65 ; } else { if ( ( temp . y [ 0 ] & 1 ) != 0 ) out [ 0 ] = 0x03 ; else out [ 0 ] = 0x02 ; swap_endian256_internal ( temp . x ) ; TEE_MemMove ( ( uint8_t * ) & ( out [ 1 ] ) , ( uint8_t * ) ( temp . x ) , 32 ) ; return 33 ; } }
Serialise an elliptic curve point in a manner which is Bitcoin-compatible.
Serialise an elliptic curve point in a manner which is Bitcoin - compatible .
/* Need temp for endian reversing */ /* Special case for point at infinity. */ /* Uncompressed point. */ /* Compressed point. */ /* is odd */ /* is not odd */