]>
git.ipfire.org Git - thirdparty/openssl.git/blob - crypto/objects/obj_xref.c
d7794028911cb5e7de0abd2d960a7fe6b97a5da1
2 * Copyright 2006-2018 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
10 #include <openssl/objects.h>
12 #include "internal/nelem.h"
13 #include <openssl/err.h>
15 static STACK_OF(nid_triple
) *sig_app
, *sigx_app
;
17 static int sig_cmp(const nid_triple
*a
, const nid_triple
*b
)
19 return a
->sign_id
- b
->sign_id
;
22 DECLARE_OBJ_BSEARCH_CMP_FN(nid_triple
, nid_triple
, sig
);
23 IMPLEMENT_OBJ_BSEARCH_CMP_FN(nid_triple
, nid_triple
, sig
);
25 static int sig_sk_cmp(const nid_triple
*const *a
, const nid_triple
*const *b
)
27 return (*a
)->sign_id
- (*b
)->sign_id
;
30 DECLARE_OBJ_BSEARCH_CMP_FN(const nid_triple
*, const nid_triple
*, sigx
);
32 static int sigx_cmp(const nid_triple
*const *a
, const nid_triple
*const *b
)
35 ret
= (*a
)->hash_id
- (*b
)->hash_id
;
38 return (*a
)->pkey_id
- (*b
)->pkey_id
;
41 IMPLEMENT_OBJ_BSEARCH_CMP_FN(const nid_triple
*, const nid_triple
*, sigx
);
43 int OBJ_find_sigid_algs(int signid
, int *pdig_nid
, int *ppkey_nid
)
46 const nid_triple
*rv
= NULL
;
49 if (sig_app
!= NULL
) {
50 int idx
= sk_nid_triple_find(sig_app
, &tmp
);
51 rv
= sk_nid_triple_value(sig_app
, idx
);
53 #ifndef OBJ_XREF_TEST2
55 rv
= OBJ_bsearch_sig(&tmp
, sigoid_srt
, OSSL_NELEM(sigoid_srt
));
61 *pdig_nid
= rv
->hash_id
;
63 *ppkey_nid
= rv
->pkey_id
;
67 int OBJ_find_sigid_by_algs(int *psignid
, int dig_nid
, int pkey_nid
)
70 const nid_triple
*t
= &tmp
;
71 const nid_triple
**rv
= NULL
;
73 tmp
.hash_id
= dig_nid
;
74 tmp
.pkey_id
= pkey_nid
;
77 int idx
= sk_nid_triple_find(sigx_app
, &tmp
);
79 t
= sk_nid_triple_value(sigx_app
, idx
);
83 #ifndef OBJ_XREF_TEST2
85 rv
= OBJ_bsearch_sigx(&t
, sigoid_srt_xref
, OSSL_NELEM(sigoid_srt_xref
));
91 *psignid
= (*rv
)->sign_id
;
95 int OBJ_add_sigid(int signid
, int dig_id
, int pkey_id
)
99 sig_app
= sk_nid_triple_new(sig_sk_cmp
);
102 if (sigx_app
== NULL
)
103 sigx_app
= sk_nid_triple_new(sigx_cmp
);
104 if (sigx_app
== NULL
)
106 if ((ntr
= OPENSSL_malloc(sizeof(*ntr
))) == NULL
) {
107 OBJerr(OBJ_F_OBJ_ADD_SIGID
, ERR_R_MALLOC_FAILURE
);
110 ntr
->sign_id
= signid
;
111 ntr
->hash_id
= dig_id
;
112 ntr
->pkey_id
= pkey_id
;
114 if (!sk_nid_triple_push(sig_app
, ntr
)) {
119 if (!sk_nid_triple_push(sigx_app
, ntr
))
122 sk_nid_triple_sort(sig_app
);
123 sk_nid_triple_sort(sigx_app
);
128 static void sid_free(nid_triple
*tt
)
133 void OBJ_sigid_free(void)
135 sk_nid_triple_pop_free(sig_app
, sid_free
);
137 sk_nid_triple_free(sigx_app
);