summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/pqueue
diff options
context:
space:
mode:
authordjm <>2010-10-01 22:54:18 +0000
committerdjm <>2010-10-01 22:54:18 +0000
commitf6ca1ae73bb9eabfb510df2cffc2599db98d35a9 (patch)
treedef8296400903465cb96345535c0a56935eb05a4 /src/lib/libcrypto/pqueue
parent0229f29a33371533962d8b0b8264882afac53d70 (diff)
downloadopenbsd-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/Makefile9
-rw-r--r--src/lib/libcrypto/pqueue/pqueue.c43
-rw-r--r--src/lib/libcrypto/pqueue/pqueue.h9
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
23SRC= $(LIBSRC) 23SRC= $(LIBSRC)
24 24
25EXHEADER= pqueue.h pq_compat.h 25EXHEADER= pqueue.h
26HEADER= $(EXHEADER) 26HEADER= $(EXHEADER)
27 27
28ALL= $(GENERAL) $(SRC) $(HEADER) 28ALL= $(GENERAL) $(SRC) $(HEADER)
@@ -33,7 +33,7 @@ top:
33all: lib 33all: lib
34 34
35lib: $(LIBOBJ) 35lib: $(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
79pqueue.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 79pqueue.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
80pqueue.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h 80pqueue.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
81pqueue.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h 81pqueue.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
82pqueue.o: ../../include/openssl/pq_compat.h ../../include/openssl/safestack.h 82pqueue.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
83pqueue.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h 83pqueue.o: ../../include/openssl/symhacks.h ../cryptlib.h pqueue.c pqueue.h
84pqueue.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
70pitem * 70pitem *
71pitem_new(PQ_64BIT priority, void *data) 71pitem_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
166pitem * 167pitem *
167pqueue_find(pqueue_s *pq, PQ_64BIT priority) 168pqueue_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
203void 203void
204pqueue_print(pqueue_s *pq) 204pqueue_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
216pitem * 219pitem *
217pqueue_iterator(pqueue_s *pq) 220pqueue_iterator(pqueue_s *pq)
@@ -234,3 +237,17 @@ pqueue_next(pitem **item)
234 237
235 return ret; 238 return ret;
236 } 239 }
240
241int
242pqueue_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
69typedef struct _pqueue *pqueue; 67typedef struct _pqueue *pqueue;
70 68
71typedef struct _pitem 69typedef 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
78typedef struct _pitem *piterator; 76typedef struct _pitem *piterator;
79 77
80pitem *pitem_new(PQ_64BIT priority, void *data); 78pitem *pitem_new(unsigned char *prio64be, void *data);
81void pitem_free(pitem *item); 79void pitem_free(pitem *item);
82 80
83pqueue pqueue_new(void); 81pqueue pqueue_new(void);
@@ -86,10 +84,11 @@ void pqueue_free(pqueue pq);
86pitem *pqueue_insert(pqueue pq, pitem *item); 84pitem *pqueue_insert(pqueue pq, pitem *item);
87pitem *pqueue_peek(pqueue pq); 85pitem *pqueue_peek(pqueue pq);
88pitem *pqueue_pop(pqueue pq); 86pitem *pqueue_pop(pqueue pq);
89pitem *pqueue_find(pqueue pq, PQ_64BIT priority); 87pitem *pqueue_find(pqueue pq, unsigned char *prio64be);
90pitem *pqueue_iterator(pqueue pq); 88pitem *pqueue_iterator(pqueue pq);
91pitem *pqueue_next(piterator *iter); 89pitem *pqueue_next(piterator *iter);
92 90
93void pqueue_print(pqueue pq); 91void pqueue_print(pqueue pq);
92int pqueue_size(pqueue pq);
94 93
95#endif /* ! HEADER_PQUEUE_H */ 94#endif /* ! HEADER_PQUEUE_H */