diff options
Diffstat (limited to 'crypto/ecdsa/ecs_asn1.c')
-rw-r--r-- | crypto/ecdsa/ecs_asn1.c | 321 |
1 files changed, 0 insertions, 321 deletions
diff --git a/crypto/ecdsa/ecs_asn1.c b/crypto/ecdsa/ecs_asn1.c index 048fa88de9..e9e1c2b51e 100644 --- a/crypto/ecdsa/ecs_asn1.c +++ b/crypto/ecdsa/ecs_asn1.c @@ -65,324 +65,3 @@ ASN1_SEQUENCE(ECDSA_SIG) = { DECLARE_ASN1_FUNCTIONS_const(ECDSA_SIG) DECLARE_ASN1_ENCODE_FUNCTIONS_const(ECDSA_SIG, ECDSA_SIG) IMPLEMENT_ASN1_FUNCTIONS_const(ECDSA_SIG) - -int i2d_ECDSAParameters(ECDSA *a, unsigned char **out) - { - if (a == NULL) - { - ECDSAerr(ECDSA_F_I2D_ECDSAPARAMETERS, - ERR_R_PASSED_NULL_PARAMETER); - return 0; - } - return i2d_ECPKParameters(a->group, out); - } - -ECDSA *d2i_ECDSAParameters(ECDSA **a, const unsigned char **in, long len) - { - EC_GROUP *group; - ECDSA *ret; - - if (in == NULL || *in == NULL) - { - ECDSAerr(ECDSA_F_D2I_ECDSAPARAMETERS, - ERR_R_PASSED_NULL_PARAMETER); - return NULL; - } - - group = d2i_ECPKParameters(NULL, in, len); - - if (group == NULL) - { - ECDSAerr(ECDSA_F_D2I_ECDSAPARAMETERS, - ERR_R_EC_LIB); - return NULL; - } - - if (a == NULL || *a == NULL) - { - if ((ret = ECDSA_new()) == NULL) - { - ECDSAerr(ECDSA_F_D2I_ECDSAPARAMETERS, - ERR_R_MALLOC_FAILURE); - return NULL; - } - if (a) - *a = ret; - } - else - ret = *a; - - if (ret->group) - EC_GROUP_clear_free(ret->group); - - ret->group = group; - - return ret; - } - -ECDSA *d2i_ECDSAPrivateKey(ECDSA **a, const unsigned char **in, long len) - { - int ok=0; - ECDSA *ret=NULL; - EC_PRIVATEKEY *priv_key=NULL; - - if ((priv_key = EC_PRIVATEKEY_new()) == NULL) - { - ECDSAerr(ECDSA_F_D2I_ECDSAPRIVATEKEY, ERR_R_MALLOC_FAILURE); - return NULL; - } - - if ((priv_key = d2i_EC_PRIVATEKEY(&priv_key, in, len)) == NULL) - { - ECDSAerr(ECDSA_F_D2I_ECDSAPRIVATEKEY, ERR_R_EC_LIB); - EC_PRIVATEKEY_free(priv_key); - return NULL; - } - - if (a == NULL || *a == NULL) - { - if ((ret = ECDSA_new()) == NULL) - { - ECDSAerr(ECDSA_F_D2I_ECDSAPRIVATEKEY, - ERR_R_MALLOC_FAILURE); - goto err; - } - if (a) - *a = ret; - } - else - ret = *a; - - if (priv_key->parameters) - { - if (ret->group) - EC_GROUP_clear_free(ret->group); - ret->group = EC_ASN1_pkparameters2group(priv_key->parameters); - } - - if (ret->group == NULL) - { - ECDSAerr(ECDSA_F_D2I_ECDSAPRIVATEKEY, ERR_R_EC_LIB); - goto err; - } - - ret->version = priv_key->version; - - if (priv_key->privateKey) - { - ret->priv_key = BN_bin2bn( - M_ASN1_STRING_data(priv_key->privateKey), - M_ASN1_STRING_length(priv_key->privateKey), - ret->priv_key); - if (ret->priv_key == NULL) - { - ECDSAerr(ECDSA_F_D2I_ECDSAPRIVATEKEY, - ERR_R_BN_LIB); - goto err; - } - } - else - { - ECDSAerr(ECDSA_F_D2I_ECDSAPRIVATEKEY, - ECDSA_R_MISSING_PRIVATE_KEY); - goto err; - } - - if (priv_key->publicKey) - { - if (ret->pub_key) - EC_POINT_clear_free(ret->pub_key); - ret->pub_key = EC_POINT_new(ret->group); - if (ret->pub_key == NULL) - { - ECDSAerr(ECDSA_F_D2I_ECDSAPRIVATEKEY, ERR_R_EC_LIB); - goto err; - } - if (!EC_POINT_oct2point(ret->group, ret->pub_key, - M_ASN1_STRING_data(priv_key->publicKey), - M_ASN1_STRING_length(priv_key->publicKey), NULL)) - { - ECDSAerr(ECDSA_F_D2I_ECDSAPRIVATEKEY, ERR_R_EC_LIB); - goto err; - } - } - - ok = 1; -err: - if (!ok) - { - if (ret) - ECDSA_free(ret); - ret = NULL; - } - - if (priv_key) - EC_PRIVATEKEY_free(priv_key); - - return(ret); - } - -int i2d_ECDSAPrivateKey(ECDSA *a, unsigned char **out) - { - int ret=0, ok=0; - unsigned char *buffer=NULL; - size_t buf_len=0, tmp_len; - EC_PRIVATEKEY *priv_key=NULL; - - if (a == NULL || a->group == NULL || a->priv_key == NULL) - { - ECDSAerr(ECDSA_F_I2D_ECDSAPRIVATEKEY, - ERR_R_PASSED_NULL_PARAMETER); - goto err; - } - - if ((priv_key = EC_PRIVATEKEY_new()) == NULL) - { - ECDSAerr(ECDSA_F_I2D_ECDSAPRIVATEKEY, - ERR_R_MALLOC_FAILURE); - goto err; - } - - priv_key->version = a->version; - - buf_len = (size_t)BN_num_bytes(a->priv_key); - buffer = OPENSSL_malloc(buf_len); - if (buffer == NULL) - { - ECDSAerr(ECDSA_F_I2D_ECDSAPRIVATEKEY, - ERR_R_MALLOC_FAILURE); - goto err; - } - - if (!BN_bn2bin(a->priv_key, buffer)) - { - ECDSAerr(ECDSA_F_I2D_ECDSAPRIVATEKEY, ERR_R_BN_LIB); - goto err; - } - - if (!M_ASN1_OCTET_STRING_set(priv_key->privateKey, buffer, buf_len)) - { - ECDSAerr(ECDSA_F_I2D_ECDSAPRIVATEKEY, ERR_R_ASN1_LIB); - goto err; - } - - if (!(ECDSA_get_enc_flag(a) & ECDSA_PKEY_NO_PARAMETERS)) - { - if ((priv_key->parameters = EC_ASN1_group2pkparameters( - a->group, priv_key->parameters)) == NULL) - { - ECDSAerr(ECDSA_F_I2D_ECDSAPRIVATEKEY, ERR_R_EC_LIB); - goto err; - } - } - - if (!(ECDSA_get_enc_flag(a) & ECDSA_PKEY_NO_PUBKEY)) - { - priv_key->publicKey = M_ASN1_BIT_STRING_new(); - if (priv_key->publicKey == NULL) - { - ECDSAerr(ECDSA_F_I2D_ECDSAPRIVATEKEY, - ERR_R_MALLOC_FAILURE); - goto err; - } - - tmp_len = EC_POINT_point2oct(a->group, a->pub_key, - ECDSA_get_conversion_form(a), NULL, 0, NULL); - - if (tmp_len > buf_len) - buffer = OPENSSL_realloc(buffer, tmp_len); - if (buffer == NULL) - { - ECDSAerr(ECDSA_F_I2D_ECDSAPRIVATEKEY, - ERR_R_MALLOC_FAILURE); - goto err; - } - - buf_len = tmp_len; - - if (!EC_POINT_point2oct(a->group, a->pub_key, - ECDSA_get_conversion_form(a), buffer, buf_len, NULL)) - { - ECDSAerr(ECDSA_F_I2D_ECDSAPRIVATEKEY, ERR_R_EC_LIB); - goto err; - } - - if (!M_ASN1_BIT_STRING_set(priv_key->publicKey, buffer, - buf_len)) - { - ECDSAerr(ECDSA_F_I2D_ECDSAPRIVATEKEY, ERR_R_ASN1_LIB); - goto err; - } - } - - if ((ret = i2d_EC_PRIVATEKEY(priv_key, out)) == 0) - { - ECDSAerr(ECDSA_F_I2D_ECDSAPRIVATEKEY, ERR_R_EC_LIB); - goto err; - } - ok=1; -err: - if (buffer) - OPENSSL_free(buffer); - if (priv_key) - EC_PRIVATEKEY_free(priv_key); - return(ok?ret:0); - } - - -ECDSA *ECDSAPublicKey_set_octet_string(ECDSA **a, const unsigned char **in, long len) -{ - ECDSA *ret=NULL; - - if (a == NULL || (*a) == NULL || (*a)->group == NULL) - { - /* sorry, but a EC_GROUP-structur is necessary - * to set the public key */ - ECDSAerr(ECDSA_F_D2I_ECDSAPRIVATEKEY, ECDSA_R_MISSING_PARAMETERS); - return 0; - } - ret = *a; - if (ret->pub_key == NULL && (ret->pub_key = EC_POINT_new(ret->group)) == NULL) - { - ECDSAerr(ECDSA_F_D2I_ECDSAPRIVATEKEY, ERR_R_MALLOC_FAILURE); - return 0; - } - if (!EC_POINT_oct2point(ret->group, ret->pub_key, *in, len, NULL)) - { - ECDSAerr(ECDSA_F_D2I_ECDSAPRIVATEKEY, ERR_R_EC_LIB); - return 0; - } - ECDSA_set_conversion_form(ret, (point_conversion_form_t)(*in[0] & ~0x01)); - return ret; -} - -int ECDSAPublicKey_get_octet_string(ECDSA *a, unsigned char **out) -{ - size_t buf_len=0; - - if (a == NULL) - { - ECDSAerr(ECDSA_F_I2D_ECDSAPUBLICKEY, ECDSA_R_MISSING_PARAMETERS); - return 0; - } - buf_len = EC_POINT_point2oct(a->group, a->pub_key, - ECDSA_get_conversion_form(a), NULL, 0, NULL); - if (out == NULL || buf_len == 0) - /* out == NULL => just return the length of the octet string */ - return buf_len; - if (*out == NULL) - if ((*out = OPENSSL_malloc(buf_len)) == NULL) - { - ECDSAerr(ECDSA_F_I2D_ECDSAPUBLICKEY, ERR_R_MALLOC_FAILURE); - return 0; - } - if (!EC_POINT_point2oct(a->group, a->pub_key, ECDSA_get_conversion_form(a), - *out, buf_len, NULL)) - { - ECDSAerr(ECDSA_F_I2D_ECDSAPUBLICKEY, ERR_R_EC_LIB); - OPENSSL_free(*out); - *out = NULL; - return 0; - } - return buf_len; -} |