summaryrefslogtreecommitdiff
path: root/lib/libcrypto/dsa
diff options
context:
space:
mode:
authorBob Beck <beck@cvs.openbsd.org>2014-04-17 13:37:51 +0000
committerBob Beck <beck@cvs.openbsd.org>2014-04-17 13:37:51 +0000
commit798a6f0972ce4f8ea25aa987dc43e626dc6d4087 (patch)
tree557371c7b1514332c466ec6233d3e6af96c88520 /lib/libcrypto/dsa
parenteea79ffdb77e3dd4cdbd3f98ed1b44d9522496fa (diff)
Change library to use intrinsic memory allocation functions instead of
OPENSSL_foo wrappers. This changes: OPENSSL_malloc->malloc OPENSSL_free->free OPENSSL_relloc->realloc OPENSSL_freeFunc->free
Diffstat (limited to 'lib/libcrypto/dsa')
-rw-r--r--lib/libcrypto/dsa/dsa_ameth.c55
-rw-r--r--lib/libcrypto/dsa/dsa_asn1.c2
-rw-r--r--lib/libcrypto/dsa/dsa_lib.c10
-rw-r--r--lib/libcrypto/dsa/dsa_pmeth.c11
-rw-r--r--lib/libcrypto/dsa/dsa_sign.c4
5 files changed, 66 insertions, 16 deletions
diff --git a/lib/libcrypto/dsa/dsa_ameth.c b/lib/libcrypto/dsa/dsa_ameth.c
index 6413aae46e2..e9c549802d6 100644
--- a/lib/libcrypto/dsa/dsa_ameth.c
+++ b/lib/libcrypto/dsa/dsa_ameth.c
@@ -176,7 +176,7 @@ static int dsa_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey)
err:
if (penc)
- OPENSSL_free(penc);
+ free(penc);
if (pval)
ASN1_STRING_free(pval);
@@ -344,7 +344,7 @@ static int dsa_priv_encode(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pkey)
err:
if (dp != NULL)
- OPENSSL_free(dp);
+ free(dp);
if (params != NULL)
ASN1_STRING_free(params);
if (prkey != NULL)
@@ -459,7 +459,7 @@ static int do_dsa_print(BIO *bp, const DSA *x, int off, int ptype)
update_buflen(priv_key, &buf_len);
update_buflen(pub_key, &buf_len);
- m=(unsigned char *)OPENSSL_malloc(buf_len+10);
+ m=(unsigned char *)malloc(buf_len+10);
if (m == NULL)
{
DSAerr(DSA_F_DO_DSA_PRINT,ERR_R_MALLOC_FAILURE);
@@ -483,7 +483,7 @@ static int do_dsa_print(BIO *bp, const DSA *x, int off, int ptype)
if (!ASN1_bn_print(bp,"G: ",x->g,m,off)) goto err;
ret=1;
err:
- if (m != NULL) OPENSSL_free(m);
+ if (m != NULL) free(m);
return(ret);
}
@@ -542,6 +542,52 @@ static int old_dsa_priv_encode(const EVP_PKEY *pkey, unsigned char **pder)
return i2d_DSAPrivateKey(pkey->pkey.dsa, pder);
}
+static int dsa_sig_print(BIO *bp, const X509_ALGOR *sigalg,
+ const ASN1_STRING *sig,
+ int indent, ASN1_PCTX *pctx)
+ {
+ DSA_SIG *dsa_sig;
+ const unsigned char *p;
+ if (!sig)
+ {
+ if (BIO_puts(bp, "\n") <= 0)
+ return 0;
+ else
+ return 1;
+ }
+ p = sig->data;
+ dsa_sig = d2i_DSA_SIG(NULL, &p, sig->length);
+ if (dsa_sig)
+ {
+ int rv = 0;
+ size_t buf_len = 0;
+ unsigned char *m=NULL;
+ update_buflen(dsa_sig->r, &buf_len);
+ update_buflen(dsa_sig->s, &buf_len);
+ m = malloc(buf_len+10);
+ if (m == NULL)
+ {
+ DSAerr(DSA_F_DSA_SIG_PRINT,ERR_R_MALLOC_FAILURE);
+ goto err;
+ }
+
+ if (BIO_write(bp, "\n", 1) != 1)
+ goto err;
+
+ if (!ASN1_bn_print(bp,"r: ",dsa_sig->r,m,indent))
+ goto err;
+ if (!ASN1_bn_print(bp,"s: ",dsa_sig->s,m,indent))
+ goto err;
+ rv = 1;
+ err:
+ if (m)
+ free(m);
+ DSA_SIG_free(dsa_sig);
+ return rv;
+ }
+ return X509_signature_dump(bp, sig, indent);
+ }
+
static int dsa_pkey_ctrl(EVP_PKEY *pkey, int op, long arg1, void *arg2)
{
switch (op)
@@ -647,6 +693,7 @@ const EVP_PKEY_ASN1_METHOD dsa_asn1_meths[] =
dsa_copy_parameters,
dsa_cmp_parameters,
dsa_param_print,
+ dsa_sig_print,
int_dsa_free,
dsa_pkey_ctrl,
diff --git a/lib/libcrypto/dsa/dsa_asn1.c b/lib/libcrypto/dsa/dsa_asn1.c
index 19528dcd7ac..f8a918d72cb 100644
--- a/lib/libcrypto/dsa/dsa_asn1.c
+++ b/lib/libcrypto/dsa/dsa_asn1.c
@@ -69,7 +69,7 @@ static int sig_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
{
if(operation == ASN1_OP_NEW_PRE) {
DSA_SIG *sig;
- sig = OPENSSL_malloc(sizeof(DSA_SIG));
+ sig = malloc(sizeof(DSA_SIG));
if (!sig)
{
DSAerr(DSA_F_SIG_CB, ERR_R_MALLOC_FAILURE);
diff --git a/lib/libcrypto/dsa/dsa_lib.c b/lib/libcrypto/dsa/dsa_lib.c
index 897c0859682..27a4c666183 100644
--- a/lib/libcrypto/dsa/dsa_lib.c
+++ b/lib/libcrypto/dsa/dsa_lib.c
@@ -116,7 +116,7 @@ DSA *DSA_new_method(ENGINE *engine)
{
DSA *ret;
- ret=(DSA *)OPENSSL_malloc(sizeof(DSA));
+ ret=(DSA *)malloc(sizeof(DSA));
if (ret == NULL)
{
DSAerr(DSA_F_DSA_NEW_METHOD,ERR_R_MALLOC_FAILURE);
@@ -129,7 +129,7 @@ DSA *DSA_new_method(ENGINE *engine)
if (!ENGINE_init(engine))
{
DSAerr(DSA_F_DSA_NEW_METHOD, ERR_R_ENGINE_LIB);
- OPENSSL_free(ret);
+ free(ret);
return NULL;
}
ret->engine = engine;
@@ -144,7 +144,7 @@ DSA *DSA_new_method(ENGINE *engine)
DSAerr(DSA_F_DSA_NEW_METHOD,
ERR_R_ENGINE_LIB);
ENGINE_finish(ret->engine);
- OPENSSL_free(ret);
+ free(ret);
return NULL;
}
}
@@ -174,7 +174,7 @@ DSA *DSA_new_method(ENGINE *engine)
ENGINE_finish(ret->engine);
#endif
CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DSA, ret, &ret->ex_data);
- OPENSSL_free(ret);
+ free(ret);
ret=NULL;
}
@@ -216,7 +216,7 @@ void DSA_free(DSA *r)
if (r->priv_key != NULL) BN_clear_free(r->priv_key);
if (r->kinv != NULL) BN_clear_free(r->kinv);
if (r->r != NULL) BN_clear_free(r->r);
- OPENSSL_free(r);
+ free(r);
}
int DSA_up_ref(DSA *r)
diff --git a/lib/libcrypto/dsa/dsa_pmeth.c b/lib/libcrypto/dsa/dsa_pmeth.c
index 4ce91e20c64..7076bf7b676 100644
--- a/lib/libcrypto/dsa/dsa_pmeth.c
+++ b/lib/libcrypto/dsa/dsa_pmeth.c
@@ -81,7 +81,7 @@ typedef struct
static int pkey_dsa_init(EVP_PKEY_CTX *ctx)
{
DSA_PKEY_CTX *dctx;
- dctx = OPENSSL_malloc(sizeof(DSA_PKEY_CTX));
+ dctx = malloc(sizeof(DSA_PKEY_CTX));
if (!dctx)
return 0;
dctx->nbits = 1024;
@@ -114,7 +114,7 @@ static void pkey_dsa_cleanup(EVP_PKEY_CTX *ctx)
{
DSA_PKEY_CTX *dctx = ctx->data;
if (dctx)
- OPENSSL_free(dctx);
+ free(dctx);
}
static int pkey_dsa_sign(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
@@ -187,8 +187,11 @@ static int pkey_dsa_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
case EVP_PKEY_CTRL_MD:
if (EVP_MD_type((const EVP_MD *)p2) != NID_sha1 &&
EVP_MD_type((const EVP_MD *)p2) != NID_dsa &&
+ EVP_MD_type((const EVP_MD *)p2) != NID_dsaWithSHA &&
EVP_MD_type((const EVP_MD *)p2) != NID_sha224 &&
- EVP_MD_type((const EVP_MD *)p2) != NID_sha256)
+ EVP_MD_type((const EVP_MD *)p2) != NID_sha256 &&
+ EVP_MD_type((const EVP_MD *)p2) != NID_sha384 &&
+ EVP_MD_type((const EVP_MD *)p2) != NID_sha512)
{
DSAerr(DSA_F_PKEY_DSA_CTRL, DSA_R_INVALID_DIGEST_TYPE);
return 0;
@@ -252,7 +255,7 @@ static int pkey_dsa_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
if (!dsa)
return 0;
ret = dsa_builtin_paramgen(dsa, dctx->nbits, dctx->qbits, dctx->pmd,
- NULL, 0, NULL, NULL, pcb);
+ NULL, 0, NULL, NULL, NULL, pcb);
if (ret)
EVP_PKEY_assign_DSA(pkey, dsa);
else
diff --git a/lib/libcrypto/dsa/dsa_sign.c b/lib/libcrypto/dsa/dsa_sign.c
index e02365a8b13..5f48d6b622f 100644
--- a/lib/libcrypto/dsa/dsa_sign.c
+++ b/lib/libcrypto/dsa/dsa_sign.c
@@ -76,7 +76,7 @@ int DSA_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)
DSA_SIG *DSA_SIG_new(void)
{
DSA_SIG *sig;
- sig = OPENSSL_malloc(sizeof(DSA_SIG));
+ sig = malloc(sizeof(DSA_SIG));
if (!sig)
return NULL;
sig->r = NULL;
@@ -92,7 +92,7 @@ void DSA_SIG_free(DSA_SIG *sig)
BN_free(sig->r);
if (sig->s)
BN_free(sig->s);
- OPENSSL_free(sig);
+ free(sig);
}
}