提交 7e31164a 编写于 作者: B Bodo Möller

ASN1 for binary curves

Submitted by: Nils Larsch
上级 ad55f581
......@@ -412,13 +412,32 @@ int ECPKParameters_print(BIO *bp, const EC_GROUP *x, int off)
if (BIO_write(bp, str, off) <= 0)
goto err;
}
/* print the 'short name' of the field type */
if (BIO_printf(bp, "Field Type: %s\n", OBJ_nid2sn(tmp_nid))
<= 0)
goto err;
if (is_char_two)
{
/* print the 'short name' of the base type OID */
int basis_type = EC_GROUP_get_basis_type(x, NULL,
NULL, NULL);
if (basis_type == 0)
goto err;
if (off)
{
if (off > 128) off=128;
memset(str,' ',off);
if (BIO_write(bp, str, off) <= 0)
goto err;
}
if (BIO_printf(bp, "Basis Type: %s\n",
OBJ_nid2sn(basis_type)) <= 0)
goto err;
/* print the polynomial */
if ((p != NULL) && !print(bp, "Polynomial:", p, buffer,
off))
goto err;
......@@ -565,6 +584,13 @@ static int print(BIO *bp, const char *number, BIGNUM *num, unsigned char *buf,
if (BIO_write(bp,str,off) <= 0) return(0);
}
if (BN_is_zero(num))
{
if (BIO_printf(bp, "%s 0\n", number) <= 0)
return 0;
return 1;
}
if (BN_num_bytes(num) <= BN_BYTES)
{
if (BIO_printf(bp,"%s %s%lu (%s0x%lx)\n",number,neg,
......
......@@ -191,6 +191,14 @@ const char *EC_GROUP_get0_comment(int nid);
* with the given index i from the internal curve list */
int ec_group_index2nid(int i);
/* EC_GROUP_get_basis_type() returns the NID of the basis type
* used to represent the field elements (in case of a pentanomial or trinomial
* basis the coefficient are returned in the k? arguments) */
int EC_GROUP_get_basis_type(const EC_GROUP *, unsigned int *k1,
unsigned int *k2, unsigned int *k3);
/* EC_POINT functions */
EC_POINT *EC_POINT_new(const EC_GROUP *);
void EC_POINT_free(EC_POINT *);
......
此差异已折叠。
......@@ -537,6 +537,45 @@ void EC_GROUP_clear_free_extra_data(EC_GROUP *group)
}
int EC_GROUP_get_basis_type(const EC_GROUP *group, unsigned int *k1,
unsigned int *k2, unsigned int *k3)
{
int i = 0;
if (group == NULL)
return 0;
if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) !=
NID_X9_62_characteristic_two_field)
/* everything else is currently not supported */
return 0;
while (group->poly[i] != 0)
i++;
if (i == 4)
{
if (k1)
*k1 = group->poly[3];
if (k2)
*k2 = group->poly[2];
if (k3)
*k3 = group->poly[1];
return NID_X9_62_ppBasis;
}
else if (i == 2)
{
if (k1)
*k1 = group->poly[1];
return NID_X9_62_tpBasis;
}
else
/* everything else is currently not supported */
return 0;
}
/* functions for EC_POINT objects */
EC_POINT *EC_POINT_new(const EC_GROUP *group)
......
......@@ -3005,3 +3005,5 @@ ENGINE_set_default_ECDH 3438 EXIST::FUNCTION:
ENGINE_register_ECDH 3439 EXIST::FUNCTION:
EC_GROUP_get0_comment 3440 EXIST::FUNCTION:EC
ec_group_index2nid 3441 EXIST::FUNCTION:EC
EC_GROUP_get_basis_type 3442 EXIST::FUNCTION:EC
X509_REQ_print_ex 3443 EXIST::FUNCTION:BIO
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册