From 833885be8066b9b788acba249dc3e9b65c20a2f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Love=20H=C3=B6rnquist=20=C3=85strand?= Date: Sat, 14 Feb 2009 04:16:10 +0000 Subject: [PATCH] Also select crypto alg based on private key. git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@24684 ec53bebd-3082-4978-b11e-865c3cabbd6b --- lib/hx509/crypto.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/hx509/crypto.c b/lib/hx509/crypto.c index c4dfd083e..87bf55537 100644 --- a/lib/hx509/crypto.c +++ b/lib/hx509/crypto.c @@ -1451,7 +1451,7 @@ find_sig_alg(const heim_oid *oid) } static const AlgorithmIdentifier * -sigalg_for_privatekey(const hx509_private_key pk) +alg_for_privatekey(const hx509_private_key pk, int type) { const heim_oid *keytype = pk->ops->key_oid; unsigned int i; @@ -1464,7 +1464,12 @@ sigalg_for_privatekey(const hx509_private_key pk) if (pk->ops->available && pk->ops->available(pk, sig_algs[i]->sig_alg) == 0) continue; - return sig_algs[i]->sig_alg; + if (type == HX509_SELECT_PUBLIC_SIG) + return sig_algs[i]->sig_alg; + if (type == HX509_SELECT_DIGEST) + return sig_algs[i]->digest_alg; + + return NULL; } return NULL; } @@ -2961,12 +2966,15 @@ hx509_crypto_select(const hx509_context context, if (type == HX509_SELECT_DIGEST) { bits = SIG_DIGEST; - def = _hx509_crypto_default_digest_alg; + if (source) + def = alg_for_privatekey(source, type); + if (def == NULL) + def = _hx509_crypto_default_digest_alg; } else if (type == HX509_SELECT_PUBLIC_SIG) { bits = SIG_PUBLIC_SIG; /* XXX depend on `source“ and `peer“ */ if (source) - def = sigalg_for_privatekey(source); + def = alg_for_privatekey(source, type); if (def == NULL) def = _hx509_crypto_default_sig_alg; } else if (type == HX509_SELECT_SECRET_ENC) {