diff options
author | Bodo Möller <bodo@openssl.org> | 2002-05-30 13:16:03 +0000 |
---|---|---|
committer | Bodo Möller <bodo@openssl.org> | 2002-05-30 13:16:03 +0000 |
commit | 6cbe6382944ff47881593935cc5b029f745beeea (patch) | |
tree | ddc38dca2c2eac7380c147e295cc624a8fb278b3 /crypto/asn1/t_pkey.c | |
parent | 07c08ed42cfda6dd5137c5ec2d5915415f7971c9 (diff) | |
download | openssl-6cbe6382944ff47881593935cc5b029f745beeea.tar.gz |
New functions EC_POINT_point2bn(), EC_POINT_bn2point(), EC_POINT_point2hex(), EC_POINT_hex2point()
Submitted by: Nils Larsch
Diffstat (limited to 'crypto/asn1/t_pkey.c')
-rw-r--r-- | crypto/asn1/t_pkey.c | 87 |
1 files changed, 31 insertions, 56 deletions
diff --git a/crypto/asn1/t_pkey.c b/crypto/asn1/t_pkey.c index 1b29fdc4a8..48414449e5 100644 --- a/crypto/asn1/t_pkey.c +++ b/crypto/asn1/t_pkey.c @@ -266,58 +266,36 @@ int ECDSA_print(BIO *bp, const ECDSA *x, int off) reason = ERR_R_EC_LIB; goto err; } - if (!EC_GROUP_get_order(x->group, tmp_6, NULL) || !EC_GROUP_get_cofactor(x->group, tmp_7, NULL)) + if (!EC_GROUP_get_order(x->group, tmp_6, NULL) || + !EC_GROUP_get_cofactor(x->group, tmp_7, NULL)) { reason = ERR_R_EC_LIB; goto err; } - if ((buf_len = EC_POINT_point2oct(x->group, point, ECDSA_get_conversion_form(x), NULL, 0, ctx)) == 0) - { - reason = ECDSA_R_UNEXPECTED_PARAMETER_LENGTH; - goto err; - } - if ((buffer = OPENSSL_malloc(buf_len)) == NULL) - { - reason = ERR_R_MALLOC_FAILURE; - goto err; - } - if (!EC_POINT_point2oct(x->group, point, ECDSA_get_conversion_form(x), - buffer, buf_len, ctx)) goto err; - if ((tmp_4 = BN_bin2bn(buffer, buf_len, NULL)) == NULL) - { - reason = ERR_R_BN_LIB; - goto err; - } - if ((i = EC_POINT_point2oct(x->group, x->pub_key, ECDSA_get_conversion_form(x), NULL, 0, ctx)) == 0) - { - reason = ECDSA_R_UNEXPECTED_PARAMETER_LENGTH; - goto err; - } - if (i > buf_len && (buffer = OPENSSL_realloc(buffer, i)) == NULL) - { - reason = ERR_R_MALLOC_FAILURE; - buf_len = i; - goto err; - } - if (!EC_POINT_point2oct(x->group, x->pub_key, ECDSA_get_conversion_form(x), - buffer, buf_len, ctx)) + if ((tmp_4 = EC_POINT_point2bn(x->group, point, + ECDSA_get_conversion_form(x), tmp_4, ctx)) == NULL) { reason = ERR_R_EC_LIB; goto err; } - if ((tmp_5 = BN_bin2bn(buffer, buf_len, NULL)) == NULL) + if ((tmp_5 = EC_POINT_point2bn(x->group, x->pub_key, + ECDSA_get_conversion_form(x), tmp_5, ctx)) == NULL) { - reason = ERR_R_BN_LIB; + reason = ERR_R_EC_LIB; goto err; } - if (tmp_1 != NULL) - i = BN_num_bytes(tmp_1)*2; - else - i=256; - if ((i + 10) > buf_len && (buffer = OPENSSL_realloc(buffer, i+10)) == NULL) + + buf_len = BN_num_bytes(tmp_1); + if (buf_len < (i = BN_num_bytes(tmp_2))) buf_len = i; + if (buf_len < (i = BN_num_bytes(tmp_3))) buf_len = i; + if (buf_len < (i = BN_num_bytes(tmp_4))) buf_len = i; + if (buf_len < (i = BN_num_bytes(tmp_5))) buf_len = i; + if (buf_len < (i = BN_num_bytes(tmp_6))) buf_len = i; + if (buf_len < (i = BN_num_bytes(tmp_7))) buf_len = i; + buf_len += 10; + if ((buffer = OPENSSL_malloc(buf_len)) == NULL) { reason = ERR_R_MALLOC_FAILURE; - buf_len = i; goto err; } if (off) @@ -552,25 +530,22 @@ int ECDSAParameters_print(BIO *bp, const ECDSA *x) if ((point = EC_GROUP_get0_generator(x->group)) == NULL) goto err; if (!EC_GROUP_get_order(x->group, tmp_5, ctx)) goto err; if (!EC_GROUP_get_cofactor(x->group, tmp_6, ctx)) goto err; - buf_len = EC_POINT_point2oct(x->group, point, ECDSA_get_conversion_form(x), NULL, 0, ctx); - if (!buf_len || (buffer = OPENSSL_malloc(buf_len)) == NULL) - { - reason = ERR_R_MALLOC_FAILURE; - goto err; - } - if (!EC_POINT_point2oct(x->group, point, ECDSA_get_conversion_form(x), buffer, buf_len, ctx)) - { + + if ((tmp_4 = EC_POINT_point2bn(x->group, point, + ECDSA_get_conversion_form(x), NULL, ctx)) == NULL) + { reason = ERR_R_EC_LIB; goto err; - } - if ((tmp_4 = BN_bin2bn(buffer, buf_len, NULL)) == NULL) - { - reason = ERR_R_BN_LIB; - goto err; - } - - i = BN_num_bits(tmp_1) + 10; - if (i > buf_len && (buffer = OPENSSL_realloc(buffer, i)) == NULL) + } + + buf_len = BN_num_bytes(tmp_1); + if (buf_len < (i = BN_num_bytes(tmp_2))) buf_len = i; + if (buf_len < (i = BN_num_bytes(tmp_3))) buf_len = i; + if (buf_len < (i = BN_num_bytes(tmp_4))) buf_len = i; + if (buf_len < (i = BN_num_bytes(tmp_5))) buf_len = i; + if (buf_len < (i = BN_num_bytes(tmp_6))) buf_len = i; + buf_len += 10; + if ((buffer = OPENSSL_malloc(buf_len)) == NULL) { reason=ERR_R_MALLOC_FAILURE; goto err; |