提交 2b3aeffb 编写于 作者: B Bodo Möller

fix 'ecdsaparam -C' output

Submitted by: Nils Larsch
上级 2c2f9e2c
......@@ -470,39 +470,30 @@ bad:
}
printf("\n\t};\n\n");
/* FIXME:
* the generated code does not make much sense
*
* TODO:
* use EC_GROUP_new_curve_GFp instead of using EC_GFp_mont_method directly
*/
printf("ECDSA *get_ecdsa%d()\n\t{\n",bits_p);
printf("\tint ok=1;\n");
printf("ECDSA *get_ecdsa%d(void)\n\t{\n",bits_p);
printf("\tECDSA *ecdsa=NULL;\n");
printf("\tEC_POINT *point=NULL;\n");
printf("\tBIGNUM *tmp_1=NULL,*tmp_2=NULL,*tmp_3=NULL;\n");
printf("\tBN_CTX *ctx=NULL;\n\n");
printf("\tecdsa=ECDSA_new();\n");
printf("\ttmp_1=BN_new();\n");
printf("\ttmp_2=BN_new();\n");
printf("\ttmp_3=BN_new();\n");
printf("\tctx=BN_CTX_new();\n");
printf("\tif (!ecdsa || !tmp_1 || !tmp_2 || !tmp_3 || !ctx) ok=0;\n");
printf("\tif (ok && !ecdsa->group=EC_GROUP_new(EC_GFp_mont_method())) == NULL) ok=0;");
printf("\tif (ok && !BN_bin2bn(ecdsa%d_p,sizeof(ecdsa%d_p),tmp_1)) ok=0;\n", bits_p, bits_p);
printf("\tif (ok && !BN_bin2bn(ecdsa%d_a,sizeof(ecdsa%d_a),tmp_2)) ok=0;\n", bits_p, bits_p);
printf("\tif (ok && !BN_bin2bn(ecdsa%d_b,sizeof(ecdsa%d_b),tmp_3)) ok=0;\n", bits_p, bits_p);
printf("\tif (ok && !EC_GROUP_set_curve_GFp(ecdsa->group,tmp_1,tmp_2,tmp_3,ctx)) ok=0;\n");
printf("\tif (ok && !BN_bin2bn(ecdsa%d_x,sizeof(ecdsa%d_p),tmp_1)) ok=0;\n", bits_p, bits_p);
printf("\tif (ok && !BN_bin2bn(ecdsa%d_y,sizeof(ecdsa%d_a),tmp_2)) ok=0;\n", bits_p, bits_p);
printf("\tif (ok && (point = EC_POINT_new(ecdsa->group)) == NULL) ok=0;\n");
printf("\tif (ok && !EC_POINT_set_affine_coordinates_GFp(ecdsa->group,point,tmp_1,tmp_2,ctx)) ok=0:\n");
printf("\tif (ok && !BN_bin2bn(ecdsa%d_o,sizeof(ecdsa%d_b),tmp_1)) ok=0;\n", bits_p, bits_p);
printf("\tif (ok && !BN_bin2bn(ecdsa%d_c,sizeof(ecdsa%d_b),tmp_2)) ok=0;\n", bits_p, bits_p);
printf("\tif (ok && !EC_GROUP_set_generator(ecdsa->group,point,tmp_1,tmp_2)) ok=0;\n");
printf("\tif ((ecdsa->group == NULL) || (ecdsa->pub_key == NULL) || (ecdsa->priv_key == NULL))\n");
printf("\t\t{ ECDSA_free(ecdsa); return(NULL); }\n");
printf("\tBIGNUM *tmp_1=NULL,*tmp_2=NULL,*tmp_3=NULL;\n\n");
printf("\tif ((ecdsa=ECDSA_new()) == NULL)\n");
printf("\t\treturn(NULL);\n");
printf("\t/* first : generate EC_GROUP-structure */\n");
printf("\ttmp_1 = BN_bin2bn(ecdsa%d_p, sizeof(ecdsa%d_p), NULL);\n", bits_p, bits_p);
printf("\ttmp_2 = BN_bin2bn(ecdsa%d_a, sizeof(ecdsa%d_a), NULL);\n", bits_p, bits_p);
printf("\ttmp_3 = BN_bin2bn(ecdsa%d_b, sizeof(ecdsa%d_b), NULL);\n", bits_p, bits_p);
printf("\tecdsa->group = EC_GROUP_new_curve_GFp(tmp_1, tmp_2, tmp_3, NULL);\n");
printf("\t/* second : set coordinates of the generating point */\n");
printf("\tBN_bin2bn(ecdsa%d_x, sizeof(ecdsa%d_x), tmp_1);\n", bits_p, bits_p);
printf("\tBN_bin2bn(ecdsa%d_y, sizeof(ecdsa%d_y), tmp_2);\n", bits_p, bits_p);
printf("\tif ((point = EC_POINT_new(ecdsa->group)) == NULL)\n");
printf("\t{\n\t\tECDSA_free(ecdsa); BN_free(tmp_1); BN_free(tmp_2); BN_free(tmp_3);\n");
printf("\t\treturn(NULL);\n\t}\n");
printf("\tEC_POINT_set_affine_coordinates_GFp(ecdsa->group, point, tmp_1, tmp_2, NULL);\n");
printf("\t/* and finally : insert the generating point and its order in the EC_GROUP-structure */\n");
printf("\tBN_bin2bn(ecdsa%d_o, sizeof(ecdsa%d_o), tmp_1);\n", bits_p, bits_p);
printf("\tBN_bin2bn(ecdsa%d_c, sizeof(ecdsa%d_c), tmp_2);\n", bits_p, bits_p);
printf("\tEC_GROUP_set_generator(ecdsa->group, point, tmp_1, tmp_2);\n");
printf("\tBN_free(tmp_1); BN_free(tmp_2); BN_free(tmp_3);\n");
printf("\tEC_POINT_free(point);\n");
printf("\treturn(ecdsa);\n\t}\n");
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册