2020#include <stdio.h>
2121#include <string.h>
2222
23+ int ssl3_num_ciphers (void );
24+ const SSL_CIPHER * ssl3_get_cipher (unsigned int u );
25+
2326int ssl_parse_ciphersuites (STACK_OF (SSL_CIPHER ) * * out_ciphers , const char * str );
2427
2528static inline int
@@ -32,6 +35,38 @@ ssl_aes_is_accelerated(void)
3235#endif
3336}
3437
38+ static int
39+ check_cipher_order (void )
40+ {
41+ unsigned long id , prev_id = 0 ;
42+ const SSL_CIPHER * cipher ;
43+ int num_ciphers ;
44+ int i ;
45+
46+ num_ciphers = ssl3_num_ciphers ();
47+
48+ for (i = 1 ; i <= num_ciphers ; i ++ ) {
49+ /*
50+ * For some reason, ssl3_get_cipher() returns ciphers in
51+ * reverse order.
52+ */
53+ if ((cipher = ssl3_get_cipher (num_ciphers - i )) == NULL ) {
54+ fprintf (stderr , "FAIL: ssl3_get_cipher(%d) returned "
55+ "NULL\n" , i );
56+ return 1 ;
57+ }
58+ if ((id = SSL_CIPHER_get_id (cipher )) <= prev_id ) {
59+ fprintf (stderr , "FAIL: ssl3_ciphers is not sorted by "
60+ "id - cipher %d (%lx) <= cipher %d (%lx)\n" ,
61+ i , id , i - 1 , prev_id );
62+ return 1 ;
63+ }
64+ prev_id = id ;
65+ }
66+
67+ return 0 ;
68+ }
69+
3570static int
3671cipher_find_test (void )
3772{
@@ -484,6 +519,8 @@ main(int argc, char **argv)
484519{
485520int failed = 0 ;
486521
522+ failed |= check_cipher_order ();
523+
487524failed |= cipher_find_test ();
488525failed |= cipher_get_by_value_tests ();
489526
0 commit comments