diff options
author | djm <> | 2010-10-01 22:54:18 +0000 |
---|---|---|
committer | djm <> | 2010-10-01 22:54:18 +0000 |
commit | f6ca1ae73bb9eabfb510df2cffc2599db98d35a9 (patch) | |
tree | def8296400903465cb96345535c0a56935eb05a4 /src/lib/libcrypto/pqueue | |
parent | 0229f29a33371533962d8b0b8264882afac53d70 (diff) | |
download | openbsd-f6ca1ae73bb9eabfb510df2cffc2599db98d35a9.tar.gz openbsd-f6ca1ae73bb9eabfb510df2cffc2599db98d35a9.tar.bz2 openbsd-f6ca1ae73bb9eabfb510df2cffc2599db98d35a9.zip |
import OpenSSL-1.0.0a
Diffstat (limited to 'src/lib/libcrypto/pqueue')
-rw-r--r-- | src/lib/libcrypto/pqueue/Makefile | 9 | ||||
-rw-r--r-- | src/lib/libcrypto/pqueue/pqueue.c | 43 | ||||
-rw-r--r-- | src/lib/libcrypto/pqueue/pqueue.h | 9 |
3 files changed, 38 insertions, 23 deletions
diff --git a/src/lib/libcrypto/pqueue/Makefile b/src/lib/libcrypto/pqueue/Makefile index 36bfc349aa..fb36a0c876 100644 --- a/src/lib/libcrypto/pqueue/Makefile +++ b/src/lib/libcrypto/pqueue/Makefile | |||
@@ -22,7 +22,7 @@ LIBOBJ=pqueue.o | |||
22 | 22 | ||
23 | SRC= $(LIBSRC) | 23 | SRC= $(LIBSRC) |
24 | 24 | ||
25 | EXHEADER= pqueue.h pq_compat.h | 25 | EXHEADER= pqueue.h |
26 | HEADER= $(EXHEADER) | 26 | HEADER= $(EXHEADER) |
27 | 27 | ||
28 | ALL= $(GENERAL) $(SRC) $(HEADER) | 28 | ALL= $(GENERAL) $(SRC) $(HEADER) |
@@ -33,7 +33,7 @@ top: | |||
33 | all: lib | 33 | all: lib |
34 | 34 | ||
35 | lib: $(LIBOBJ) | 35 | lib: $(LIBOBJ) |
36 | $(ARX) $(LIB) $(LIBOBJ) | 36 | $(AR) $(LIB) $(LIBOBJ) |
37 | $(RANLIB) $(LIB) || echo Never mind. | 37 | $(RANLIB) $(LIB) || echo Never mind. |
38 | @touch lib | 38 | @touch lib |
39 | 39 | ||
@@ -79,6 +79,5 @@ pqueue.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | |||
79 | pqueue.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | 79 | pqueue.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h |
80 | pqueue.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | 80 | pqueue.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h |
81 | pqueue.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | 81 | pqueue.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h |
82 | pqueue.o: ../../include/openssl/pq_compat.h ../../include/openssl/safestack.h | 82 | pqueue.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h |
83 | pqueue.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | 83 | pqueue.o: ../../include/openssl/symhacks.h ../cryptlib.h pqueue.c pqueue.h |
84 | pqueue.o: ../cryptlib.h pqueue.c pqueue.h | ||
diff --git a/src/lib/libcrypto/pqueue/pqueue.c b/src/lib/libcrypto/pqueue/pqueue.c index 5cc18527f8..99a6fb874d 100644 --- a/src/lib/libcrypto/pqueue/pqueue.c +++ b/src/lib/libcrypto/pqueue/pqueue.c | |||
@@ -68,13 +68,12 @@ typedef struct _pqueue | |||
68 | } pqueue_s; | 68 | } pqueue_s; |
69 | 69 | ||
70 | pitem * | 70 | pitem * |
71 | pitem_new(PQ_64BIT priority, void *data) | 71 | pitem_new(unsigned char *prio64be, void *data) |
72 | { | 72 | { |
73 | pitem *item = (pitem *) OPENSSL_malloc(sizeof(pitem)); | 73 | pitem *item = (pitem *) OPENSSL_malloc(sizeof(pitem)); |
74 | if (item == NULL) return NULL; | 74 | if (item == NULL) return NULL; |
75 | 75 | ||
76 | pq_64bit_init(&(item->priority)); | 76 | memcpy(item->priority,prio64be,sizeof(item->priority)); |
77 | pq_64bit_assign(&item->priority, &priority); | ||
78 | 77 | ||
79 | item->data = data; | 78 | item->data = data; |
80 | item->next = NULL; | 79 | item->next = NULL; |
@@ -87,7 +86,6 @@ pitem_free(pitem *item) | |||
87 | { | 86 | { |
88 | if (item == NULL) return; | 87 | if (item == NULL) return; |
89 | 88 | ||
90 | pq_64bit_free(&(item->priority)); | ||
91 | OPENSSL_free(item); | 89 | OPENSSL_free(item); |
92 | } | 90 | } |
93 | 91 | ||
@@ -124,7 +122,10 @@ pqueue_insert(pqueue_s *pq, pitem *item) | |||
124 | next != NULL; | 122 | next != NULL; |
125 | curr = next, next = next->next) | 123 | curr = next, next = next->next) |
126 | { | 124 | { |
127 | if (pq_64bit_gt(&(next->priority), &(item->priority))) | 125 | /* we can compare 64-bit value in big-endian encoding |
126 | * with memcmp:-) */ | ||
127 | int cmp = memcmp(next->priority, item->priority,8); | ||
128 | if (cmp > 0) /* next > item */ | ||
128 | { | 129 | { |
129 | item->next = next; | 130 | item->next = next; |
130 | 131 | ||
@@ -135,8 +136,8 @@ pqueue_insert(pqueue_s *pq, pitem *item) | |||
135 | 136 | ||
136 | return item; | 137 | return item; |
137 | } | 138 | } |
138 | /* duplicates not allowed */ | 139 | |
139 | if (pq_64bit_eq(&(item->priority), &(next->priority))) | 140 | else if (cmp == 0) /* duplicates not allowed */ |
140 | return NULL; | 141 | return NULL; |
141 | } | 142 | } |
142 | 143 | ||
@@ -164,7 +165,7 @@ pqueue_pop(pqueue_s *pq) | |||
164 | } | 165 | } |
165 | 166 | ||
166 | pitem * | 167 | pitem * |
167 | pqueue_find(pqueue_s *pq, PQ_64BIT priority) | 168 | pqueue_find(pqueue_s *pq, unsigned char *prio64be) |
168 | { | 169 | { |
169 | pitem *next, *prev = NULL; | 170 | pitem *next, *prev = NULL; |
170 | pitem *found = NULL; | 171 | pitem *found = NULL; |
@@ -175,7 +176,7 @@ pqueue_find(pqueue_s *pq, PQ_64BIT priority) | |||
175 | for ( next = pq->items; next->next != NULL; | 176 | for ( next = pq->items; next->next != NULL; |
176 | prev = next, next = next->next) | 177 | prev = next, next = next->next) |
177 | { | 178 | { |
178 | if ( pq_64bit_eq(&(next->priority), &priority)) | 179 | if ( memcmp(next->priority, prio64be,8) == 0) |
179 | { | 180 | { |
180 | found = next; | 181 | found = next; |
181 | break; | 182 | break; |
@@ -183,7 +184,7 @@ pqueue_find(pqueue_s *pq, PQ_64BIT priority) | |||
183 | } | 184 | } |
184 | 185 | ||
185 | /* check the one last node */ | 186 | /* check the one last node */ |
186 | if ( pq_64bit_eq(&(next->priority), &priority)) | 187 | if ( memcmp(next->priority, prio64be,8) ==0) |
187 | found = next; | 188 | found = next; |
188 | 189 | ||
189 | if ( ! found) | 190 | if ( ! found) |
@@ -199,7 +200,6 @@ pqueue_find(pqueue_s *pq, PQ_64BIT priority) | |||
199 | return found; | 200 | return found; |
200 | } | 201 | } |
201 | 202 | ||
202 | #if PQ_64BIT_IS_INTEGER | ||
203 | void | 203 | void |
204 | pqueue_print(pqueue_s *pq) | 204 | pqueue_print(pqueue_s *pq) |
205 | { | 205 | { |
@@ -207,11 +207,14 @@ pqueue_print(pqueue_s *pq) | |||
207 | 207 | ||
208 | while(item != NULL) | 208 | while(item != NULL) |
209 | { | 209 | { |
210 | printf("item\t" PQ_64BIT_PRINT "\n", item->priority); | 210 | printf("item\t%02x%02x%02x%02x%02x%02x%02x%02x\n", |
211 | item->priority[0],item->priority[1], | ||
212 | item->priority[2],item->priority[3], | ||
213 | item->priority[4],item->priority[5], | ||
214 | item->priority[6],item->priority[7]); | ||
211 | item = item->next; | 215 | item = item->next; |
212 | } | 216 | } |
213 | } | 217 | } |
214 | #endif | ||
215 | 218 | ||
216 | pitem * | 219 | pitem * |
217 | pqueue_iterator(pqueue_s *pq) | 220 | pqueue_iterator(pqueue_s *pq) |
@@ -234,3 +237,17 @@ pqueue_next(pitem **item) | |||
234 | 237 | ||
235 | return ret; | 238 | return ret; |
236 | } | 239 | } |
240 | |||
241 | int | ||
242 | pqueue_size(pqueue_s *pq) | ||
243 | { | ||
244 | pitem *item = pq->items; | ||
245 | int count = 0; | ||
246 | |||
247 | while(item != NULL) | ||
248 | { | ||
249 | count++; | ||
250 | item = item->next; | ||
251 | } | ||
252 | return count; | ||
253 | } | ||
diff --git a/src/lib/libcrypto/pqueue/pqueue.h b/src/lib/libcrypto/pqueue/pqueue.h index 02386d130e..87fc9037c8 100644 --- a/src/lib/libcrypto/pqueue/pqueue.h +++ b/src/lib/libcrypto/pqueue/pqueue.h | |||
@@ -64,20 +64,18 @@ | |||
64 | #include <stdlib.h> | 64 | #include <stdlib.h> |
65 | #include <string.h> | 65 | #include <string.h> |
66 | 66 | ||
67 | #include <openssl/pq_compat.h> | ||
68 | |||
69 | typedef struct _pqueue *pqueue; | 67 | typedef struct _pqueue *pqueue; |
70 | 68 | ||
71 | typedef struct _pitem | 69 | typedef struct _pitem |
72 | { | 70 | { |
73 | PQ_64BIT priority; | 71 | unsigned char priority[8]; /* 64-bit value in big-endian encoding */ |
74 | void *data; | 72 | void *data; |
75 | struct _pitem *next; | 73 | struct _pitem *next; |
76 | } pitem; | 74 | } pitem; |
77 | 75 | ||
78 | typedef struct _pitem *piterator; | 76 | typedef struct _pitem *piterator; |
79 | 77 | ||
80 | pitem *pitem_new(PQ_64BIT priority, void *data); | 78 | pitem *pitem_new(unsigned char *prio64be, void *data); |
81 | void pitem_free(pitem *item); | 79 | void pitem_free(pitem *item); |
82 | 80 | ||
83 | pqueue pqueue_new(void); | 81 | pqueue pqueue_new(void); |
@@ -86,10 +84,11 @@ void pqueue_free(pqueue pq); | |||
86 | pitem *pqueue_insert(pqueue pq, pitem *item); | 84 | pitem *pqueue_insert(pqueue pq, pitem *item); |
87 | pitem *pqueue_peek(pqueue pq); | 85 | pitem *pqueue_peek(pqueue pq); |
88 | pitem *pqueue_pop(pqueue pq); | 86 | pitem *pqueue_pop(pqueue pq); |
89 | pitem *pqueue_find(pqueue pq, PQ_64BIT priority); | 87 | pitem *pqueue_find(pqueue pq, unsigned char *prio64be); |
90 | pitem *pqueue_iterator(pqueue pq); | 88 | pitem *pqueue_iterator(pqueue pq); |
91 | pitem *pqueue_next(piterator *iter); | 89 | pitem *pqueue_next(piterator *iter); |
92 | 90 | ||
93 | void pqueue_print(pqueue pq); | 91 | void pqueue_print(pqueue pq); |
92 | int pqueue_size(pqueue pq); | ||
94 | 93 | ||
95 | #endif /* ! HEADER_PQUEUE_H */ | 94 | #endif /* ! HEADER_PQUEUE_H */ |