summaryrefslogtreecommitdiffstats
path: root/crypto/evp
diff options
context:
space:
mode:
authorDr. Stephen Henson <steve@openssl.org>2010-06-26 12:55:01 +0000
committerDr. Stephen Henson <steve@openssl.org>2010-06-26 12:55:01 +0000
commit63e3676e6811874951f222a1fcbe9e2e7751cfbf (patch)
treed1f2836b69f05f953af31261cea407159f1860e7 /crypto/evp
parent1dac2cae6843422768dd5e80b0d6bc910d59058c (diff)
fix so it is safe to repeatedly add PBE algorithms
Diffstat (limited to 'crypto/evp')
-rw-r--r--crypto/evp/evp_pbe.c51
1 files changed, 43 insertions, 8 deletions
diff --git a/crypto/evp/evp_pbe.c b/crypto/evp/evp_pbe.c
index 5e830be65f..278f4858c4 100644
--- a/crypto/evp/evp_pbe.c
+++ b/crypto/evp/evp_pbe.c
@@ -116,17 +116,52 @@ static int pbe_cmp(const char * const *a, const char * const *b)
int EVP_PBE_alg_add(int nid, const EVP_CIPHER *cipher, const EVP_MD *md,
EVP_PBE_KEYGEN *keygen)
{
- EVP_PBE_CTL *pbe_tmp;
- if (!pbe_algs) pbe_algs = sk_new(pbe_cmp);
- if (!(pbe_tmp = (EVP_PBE_CTL*) OPENSSL_malloc (sizeof(EVP_PBE_CTL)))) {
- EVPerr(EVP_F_EVP_PBE_ALG_ADD,ERR_R_MALLOC_FAILURE);
- return 0;
- }
- pbe_tmp->pbe_nid = nid;
+ EVP_PBE_CTL *pbe_tmp, pbelu;
+ int i;
+ if (!pbe_algs)
+ {
+ pbe_algs = sk_new(pbe_cmp);
+ if (!pbe_algs)
+ {
+ EVPerr(EVP_F_EVP_PBE_ALG_ADD,ERR_R_MALLOC_FAILURE);
+ return 0;
+ }
+ }
+ else
+ {
+ /* Check if already present */
+ pbelu.pbe_nid = nid;
+ i = sk_find(pbe_algs, (char *)&pbelu);
+ if (i >= 0)
+ {
+ pbe_tmp = (EVP_PBE_CTL *)sk_value(pbe_algs, i);
+ /* If everything identical leave alone */
+ if (pbe_tmp->cipher == cipher
+ && pbe_tmp->md == md
+ && pbe_tmp->keygen == keygen)
+ return 1;
+ }
+ else
+ pbe_tmp = NULL;
+ }
+
+ if (!pbe_tmp)
+ {
+ pbe_tmp = OPENSSL_malloc (sizeof(EVP_PBE_CTL));
+ if (!pbe_tmp)
+ {
+ EVPerr(EVP_F_EVP_PBE_ALG_ADD,ERR_R_MALLOC_FAILURE);
+ return 0;
+ }
+ /* If adding a new PBE, set nid, append and sort */
+ pbe_tmp->pbe_nid = nid;
+ sk_push (pbe_algs, (char *)pbe_tmp);
+ sk_sort(pbe_algs);
+ }
+
pbe_tmp->cipher = cipher;
pbe_tmp->md = md;
pbe_tmp->keygen = keygen;
- sk_push (pbe_algs, (char *)pbe_tmp);
return 1;
}