static void ssl_cipher_collect_ciphers(const SSL_METHOD *ssl_method,
		int num_of_ciphers, unsigned long mask, CIPHER_ORDER *list,
		CIPHER_ORDER **head_p, CIPHER_ORDER **tail_p)
	{
	int i, list_num;
	SSL_CIPHER *c;

	/*
	 * We have num_of_ciphers descriptions compiled in, depending on the
	 * method selected (SSLv2 and/or SSLv3, TLSv1 etc).
	 * These will later be sorted in a linked list with at most num
	 * entries.
	 */

	/* Get the initial list of ciphers */
	list_num = 0;	/* actual count of ciphers */
	for (i = 0; i < num_of_ciphers; i++)
		{
		c = ssl_method->get_cipher(i);
		/* drop those that use any of that is not available */
		if ((c != NULL) && c->valid && !(c->algorithms & mask))
			{
			list[list_num].cipher = c;
			list[list_num].next = NULL;
			list[list_num].prev = NULL;
			list[list_num].active = 0;
			list_num++;
			/*
			if (!sk_push(ca_list,(char *)c)) goto err;
			*/
			}
		}

	/*
	 * Prepare linked list from list entries
	 */	
	for (i = 1; i < list_num - 1; i++)
		{
		list[i].prev = &(list[i-1]);
		list[i].next = &(list[i+1]);
		}
	if (list_num > 0)
		{
		(*head_p) = &(list[0]);
		(*head_p)->prev = NULL;
		(*head_p)->next = &(list[1]);
		(*tail_p) = &(list[list_num - 1]);
		(*tail_p)->prev = &(list[list_num - 2]);
		(*tail_p)->next = NULL;
		}
	}