ciphername_test.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  1. /*
  2. * Copyright 2017 The OpenSSL Project Authors. All Rights Reserved.
  3. * Copyright 2017 BaishanCloud. All rights reserved.
  4. *
  5. * Licensed under the Apache License 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. * https://www.openssl.org/source/license.html
  9. * or in the file LICENSE in the source distribution.
  10. */
  11. #include <stdio.h>
  12. #include <string.h>
  13. #include <openssl/opensslconf.h>
  14. #include <openssl/err.h>
  15. #include <openssl/e_os2.h>
  16. #include <openssl/ssl.h>
  17. #include <openssl/ssl3.h>
  18. #include <openssl/tls1.h>
  19. #include "internal/nelem.h"
  20. #include "testutil.h"
  21. typedef struct cipher_id_name {
  22. int id;
  23. const char *name;
  24. } CIPHER_ID_NAME;
  25. /* Cipher suites, copied from t1_trce.c */
  26. static CIPHER_ID_NAME cipher_names[] = {
  27. {0x0000, "TLS_NULL_WITH_NULL_NULL"},
  28. {0x0001, "TLS_RSA_WITH_NULL_MD5"},
  29. {0x0002, "TLS_RSA_WITH_NULL_SHA"},
  30. {0x0003, "TLS_RSA_EXPORT_WITH_RC4_40_MD5"},
  31. {0x0004, "TLS_RSA_WITH_RC4_128_MD5"},
  32. {0x0005, "TLS_RSA_WITH_RC4_128_SHA"},
  33. {0x0006, "TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5"},
  34. {0x0007, "TLS_RSA_WITH_IDEA_CBC_SHA"},
  35. {0x0008, "TLS_RSA_EXPORT_WITH_DES40_CBC_SHA"},
  36. {0x0009, "TLS_RSA_WITH_DES_CBC_SHA"},
  37. {0x000A, "TLS_RSA_WITH_3DES_EDE_CBC_SHA"},
  38. {0x000B, "TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA"},
  39. {0x000C, "TLS_DH_DSS_WITH_DES_CBC_SHA"},
  40. {0x000D, "TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA"},
  41. {0x000E, "TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA"},
  42. {0x000F, "TLS_DH_RSA_WITH_DES_CBC_SHA"},
  43. {0x0010, "TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA"},
  44. {0x0011, "TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA"},
  45. {0x0012, "TLS_DHE_DSS_WITH_DES_CBC_SHA"},
  46. {0x0013, "TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA"},
  47. {0x0014, "TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA"},
  48. {0x0015, "TLS_DHE_RSA_WITH_DES_CBC_SHA"},
  49. {0x0016, "TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA"},
  50. {0x0017, "TLS_DH_anon_EXPORT_WITH_RC4_40_MD5"},
  51. {0x0018, "TLS_DH_anon_WITH_RC4_128_MD5"},
  52. {0x0019, "TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA"},
  53. {0x001A, "TLS_DH_anon_WITH_DES_CBC_SHA"},
  54. {0x001B, "TLS_DH_anon_WITH_3DES_EDE_CBC_SHA"},
  55. {0x001D, "SSL_FORTEZZA_KEA_WITH_FORTEZZA_CBC_SHA"},
  56. {0x001E, "SSL_FORTEZZA_KEA_WITH_RC4_128_SHA"},
  57. {0x001F, "TLS_KRB5_WITH_3DES_EDE_CBC_SHA"},
  58. {0x0020, "TLS_KRB5_WITH_RC4_128_SHA"},
  59. {0x0021, "TLS_KRB5_WITH_IDEA_CBC_SHA"},
  60. {0x0022, "TLS_KRB5_WITH_DES_CBC_MD5"},
  61. {0x0023, "TLS_KRB5_WITH_3DES_EDE_CBC_MD5"},
  62. {0x0024, "TLS_KRB5_WITH_RC4_128_MD5"},
  63. {0x0025, "TLS_KRB5_WITH_IDEA_CBC_MD5"},
  64. {0x0026, "TLS_KRB5_EXPORT_WITH_DES_CBC_40_SHA"},
  65. {0x0027, "TLS_KRB5_EXPORT_WITH_RC2_CBC_40_SHA"},
  66. {0x0028, "TLS_KRB5_EXPORT_WITH_RC4_40_SHA"},
  67. {0x0029, "TLS_KRB5_EXPORT_WITH_DES_CBC_40_MD5"},
  68. {0x002A, "TLS_KRB5_EXPORT_WITH_RC2_CBC_40_MD5"},
  69. {0x002B, "TLS_KRB5_EXPORT_WITH_RC4_40_MD5"},
  70. {0x002C, "TLS_PSK_WITH_NULL_SHA"},
  71. {0x002D, "TLS_DHE_PSK_WITH_NULL_SHA"},
  72. {0x002E, "TLS_RSA_PSK_WITH_NULL_SHA"},
  73. {0x002F, "TLS_RSA_WITH_AES_128_CBC_SHA"},
  74. {0x0030, "TLS_DH_DSS_WITH_AES_128_CBC_SHA"},
  75. {0x0031, "TLS_DH_RSA_WITH_AES_128_CBC_SHA"},
  76. {0x0032, "TLS_DHE_DSS_WITH_AES_128_CBC_SHA"},
  77. {0x0033, "TLS_DHE_RSA_WITH_AES_128_CBC_SHA"},
  78. {0x0034, "TLS_DH_anon_WITH_AES_128_CBC_SHA"},
  79. {0x0035, "TLS_RSA_WITH_AES_256_CBC_SHA"},
  80. {0x0036, "TLS_DH_DSS_WITH_AES_256_CBC_SHA"},
  81. {0x0037, "TLS_DH_RSA_WITH_AES_256_CBC_SHA"},
  82. {0x0038, "TLS_DHE_DSS_WITH_AES_256_CBC_SHA"},
  83. {0x0039, "TLS_DHE_RSA_WITH_AES_256_CBC_SHA"},
  84. {0x003A, "TLS_DH_anon_WITH_AES_256_CBC_SHA"},
  85. {0x003B, "TLS_RSA_WITH_NULL_SHA256"},
  86. {0x003C, "TLS_RSA_WITH_AES_128_CBC_SHA256"},
  87. {0x003D, "TLS_RSA_WITH_AES_256_CBC_SHA256"},
  88. {0x003E, "TLS_DH_DSS_WITH_AES_128_CBC_SHA256"},
  89. {0x003F, "TLS_DH_RSA_WITH_AES_128_CBC_SHA256"},
  90. {0x0040, "TLS_DHE_DSS_WITH_AES_128_CBC_SHA256"},
  91. {0x0041, "TLS_RSA_WITH_CAMELLIA_128_CBC_SHA"},
  92. {0x0042, "TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA"},
  93. {0x0043, "TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA"},
  94. {0x0044, "TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA"},
  95. {0x0045, "TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA"},
  96. {0x0046, "TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA"},
  97. {0x0067, "TLS_DHE_RSA_WITH_AES_128_CBC_SHA256"},
  98. {0x0068, "TLS_DH_DSS_WITH_AES_256_CBC_SHA256"},
  99. {0x0069, "TLS_DH_RSA_WITH_AES_256_CBC_SHA256"},
  100. {0x006A, "TLS_DHE_DSS_WITH_AES_256_CBC_SHA256"},
  101. {0x006B, "TLS_DHE_RSA_WITH_AES_256_CBC_SHA256"},
  102. {0x006C, "TLS_DH_anon_WITH_AES_128_CBC_SHA256"},
  103. {0x006D, "TLS_DH_anon_WITH_AES_256_CBC_SHA256"},
  104. {0x0084, "TLS_RSA_WITH_CAMELLIA_256_CBC_SHA"},
  105. {0x0085, "TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA"},
  106. {0x0086, "TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA"},
  107. {0x0087, "TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA"},
  108. {0x0088, "TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA"},
  109. {0x0089, "TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA"},
  110. {0x008A, "TLS_PSK_WITH_RC4_128_SHA"},
  111. {0x008B, "TLS_PSK_WITH_3DES_EDE_CBC_SHA"},
  112. {0x008C, "TLS_PSK_WITH_AES_128_CBC_SHA"},
  113. {0x008D, "TLS_PSK_WITH_AES_256_CBC_SHA"},
  114. {0x008E, "TLS_DHE_PSK_WITH_RC4_128_SHA"},
  115. {0x008F, "TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA"},
  116. {0x0090, "TLS_DHE_PSK_WITH_AES_128_CBC_SHA"},
  117. {0x0091, "TLS_DHE_PSK_WITH_AES_256_CBC_SHA"},
  118. {0x0092, "TLS_RSA_PSK_WITH_RC4_128_SHA"},
  119. {0x0093, "TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA"},
  120. {0x0094, "TLS_RSA_PSK_WITH_AES_128_CBC_SHA"},
  121. {0x0095, "TLS_RSA_PSK_WITH_AES_256_CBC_SHA"},
  122. {0x0096, "TLS_RSA_WITH_SEED_CBC_SHA"},
  123. {0x0097, "TLS_DH_DSS_WITH_SEED_CBC_SHA"},
  124. {0x0098, "TLS_DH_RSA_WITH_SEED_CBC_SHA"},
  125. {0x0099, "TLS_DHE_DSS_WITH_SEED_CBC_SHA"},
  126. {0x009A, "TLS_DHE_RSA_WITH_SEED_CBC_SHA"},
  127. {0x009B, "TLS_DH_anon_WITH_SEED_CBC_SHA"},
  128. {0x009C, "TLS_RSA_WITH_AES_128_GCM_SHA256"},
  129. {0x009D, "TLS_RSA_WITH_AES_256_GCM_SHA384"},
  130. {0x009E, "TLS_DHE_RSA_WITH_AES_128_GCM_SHA256"},
  131. {0x009F, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384"},
  132. {0x00A0, "TLS_DH_RSA_WITH_AES_128_GCM_SHA256"},
  133. {0x00A1, "TLS_DH_RSA_WITH_AES_256_GCM_SHA384"},
  134. {0x00A2, "TLS_DHE_DSS_WITH_AES_128_GCM_SHA256"},
  135. {0x00A3, "TLS_DHE_DSS_WITH_AES_256_GCM_SHA384"},
  136. {0x00A4, "TLS_DH_DSS_WITH_AES_128_GCM_SHA256"},
  137. {0x00A5, "TLS_DH_DSS_WITH_AES_256_GCM_SHA384"},
  138. {0x00A6, "TLS_DH_anon_WITH_AES_128_GCM_SHA256"},
  139. {0x00A7, "TLS_DH_anon_WITH_AES_256_GCM_SHA384"},
  140. {0x00A8, "TLS_PSK_WITH_AES_128_GCM_SHA256"},
  141. {0x00A9, "TLS_PSK_WITH_AES_256_GCM_SHA384"},
  142. {0x00AA, "TLS_DHE_PSK_WITH_AES_128_GCM_SHA256"},
  143. {0x00AB, "TLS_DHE_PSK_WITH_AES_256_GCM_SHA384"},
  144. {0x00AC, "TLS_RSA_PSK_WITH_AES_128_GCM_SHA256"},
  145. {0x00AD, "TLS_RSA_PSK_WITH_AES_256_GCM_SHA384"},
  146. {0x00AE, "TLS_PSK_WITH_AES_128_CBC_SHA256"},
  147. {0x00AF, "TLS_PSK_WITH_AES_256_CBC_SHA384"},
  148. {0x00B0, "TLS_PSK_WITH_NULL_SHA256"},
  149. {0x00B1, "TLS_PSK_WITH_NULL_SHA384"},
  150. {0x00B2, "TLS_DHE_PSK_WITH_AES_128_CBC_SHA256"},
  151. {0x00B3, "TLS_DHE_PSK_WITH_AES_256_CBC_SHA384"},
  152. {0x00B4, "TLS_DHE_PSK_WITH_NULL_SHA256"},
  153. {0x00B5, "TLS_DHE_PSK_WITH_NULL_SHA384"},
  154. {0x00B6, "TLS_RSA_PSK_WITH_AES_128_CBC_SHA256"},
  155. {0x00B7, "TLS_RSA_PSK_WITH_AES_256_CBC_SHA384"},
  156. {0x00B8, "TLS_RSA_PSK_WITH_NULL_SHA256"},
  157. {0x00B9, "TLS_RSA_PSK_WITH_NULL_SHA384"},
  158. {0x00BA, "TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256"},
  159. {0x00BB, "TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA256"},
  160. {0x00BC, "TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA256"},
  161. {0x00BD, "TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256"},
  162. {0x00BE, "TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256"},
  163. {0x00BF, "TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA256"},
  164. {0x00C0, "TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256"},
  165. {0x00C1, "TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA256"},
  166. {0x00C2, "TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA256"},
  167. {0x00C3, "TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256"},
  168. {0x00C4, "TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256"},
  169. {0x00C5, "TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA256"},
  170. {0x00FF, "TLS_EMPTY_RENEGOTIATION_INFO_SCSV"},
  171. {0x5600, "TLS_FALLBACK_SCSV"},
  172. {0xC001, "TLS_ECDH_ECDSA_WITH_NULL_SHA"},
  173. {0xC002, "TLS_ECDH_ECDSA_WITH_RC4_128_SHA"},
  174. {0xC003, "TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA"},
  175. {0xC004, "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA"},
  176. {0xC005, "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA"},
  177. {0xC006, "TLS_ECDHE_ECDSA_WITH_NULL_SHA"},
  178. {0xC007, "TLS_ECDHE_ECDSA_WITH_RC4_128_SHA"},
  179. {0xC008, "TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA"},
  180. {0xC009, "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA"},
  181. {0xC00A, "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA"},
  182. {0xC00B, "TLS_ECDH_RSA_WITH_NULL_SHA"},
  183. {0xC00C, "TLS_ECDH_RSA_WITH_RC4_128_SHA"},
  184. {0xC00D, "TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA"},
  185. {0xC00E, "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA"},
  186. {0xC00F, "TLS_ECDH_RSA_WITH_AES_256_CBC_SHA"},
  187. {0xC010, "TLS_ECDHE_RSA_WITH_NULL_SHA"},
  188. {0xC011, "TLS_ECDHE_RSA_WITH_RC4_128_SHA"},
  189. {0xC012, "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA"},
  190. {0xC013, "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA"},
  191. {0xC014, "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA"},
  192. {0xC015, "TLS_ECDH_anon_WITH_NULL_SHA"},
  193. {0xC016, "TLS_ECDH_anon_WITH_RC4_128_SHA"},
  194. {0xC017, "TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA"},
  195. {0xC018, "TLS_ECDH_anon_WITH_AES_128_CBC_SHA"},
  196. {0xC019, "TLS_ECDH_anon_WITH_AES_256_CBC_SHA"},
  197. {0xC01A, "TLS_SRP_SHA_WITH_3DES_EDE_CBC_SHA"},
  198. {0xC01B, "TLS_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA"},
  199. {0xC01C, "TLS_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA"},
  200. {0xC01D, "TLS_SRP_SHA_WITH_AES_128_CBC_SHA"},
  201. {0xC01E, "TLS_SRP_SHA_RSA_WITH_AES_128_CBC_SHA"},
  202. {0xC01F, "TLS_SRP_SHA_DSS_WITH_AES_128_CBC_SHA"},
  203. {0xC020, "TLS_SRP_SHA_WITH_AES_256_CBC_SHA"},
  204. {0xC021, "TLS_SRP_SHA_RSA_WITH_AES_256_CBC_SHA"},
  205. {0xC022, "TLS_SRP_SHA_DSS_WITH_AES_256_CBC_SHA"},
  206. {0xC023, "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256"},
  207. {0xC024, "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384"},
  208. {0xC025, "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256"},
  209. {0xC026, "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384"},
  210. {0xC027, "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256"},
  211. {0xC028, "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384"},
  212. {0xC029, "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256"},
  213. {0xC02A, "TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384"},
  214. {0xC02B, "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256"},
  215. {0xC02C, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384"},
  216. {0xC02D, "TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256"},
  217. {0xC02E, "TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384"},
  218. {0xC02F, "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"},
  219. {0xC030, "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384"},
  220. {0xC031, "TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256"},
  221. {0xC032, "TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384"},
  222. {0xC033, "TLS_ECDHE_PSK_WITH_RC4_128_SHA"},
  223. {0xC034, "TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA"},
  224. {0xC035, "TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA"},
  225. {0xC036, "TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA"},
  226. {0xC037, "TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256"},
  227. {0xC038, "TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384"},
  228. {0xC039, "TLS_ECDHE_PSK_WITH_NULL_SHA"},
  229. {0xC03A, "TLS_ECDHE_PSK_WITH_NULL_SHA256"},
  230. {0xC03B, "TLS_ECDHE_PSK_WITH_NULL_SHA384"},
  231. {0xC03C, "TLS_RSA_WITH_ARIA_128_CBC_SHA256"},
  232. {0xC03D, "TLS_RSA_WITH_ARIA_256_CBC_SHA384"},
  233. {0xC03E, "TLS_DH_DSS_WITH_ARIA_128_CBC_SHA256"},
  234. {0xC03F, "TLS_DH_DSS_WITH_ARIA_256_CBC_SHA384"},
  235. {0xC040, "TLS_DH_RSA_WITH_ARIA_128_CBC_SHA256"},
  236. {0xC041, "TLS_DH_RSA_WITH_ARIA_256_CBC_SHA384"},
  237. {0xC042, "TLS_DHE_DSS_WITH_ARIA_128_CBC_SHA256"},
  238. {0xC043, "TLS_DHE_DSS_WITH_ARIA_256_CBC_SHA384"},
  239. {0xC044, "TLS_DHE_RSA_WITH_ARIA_128_CBC_SHA256"},
  240. {0xC045, "TLS_DHE_RSA_WITH_ARIA_256_CBC_SHA384"},
  241. {0xC046, "TLS_DH_anon_WITH_ARIA_128_CBC_SHA256"},
  242. {0xC047, "TLS_DH_anon_WITH_ARIA_256_CBC_SHA384"},
  243. {0xC048, "TLS_ECDHE_ECDSA_WITH_ARIA_128_CBC_SHA256"},
  244. {0xC049, "TLS_ECDHE_ECDSA_WITH_ARIA_256_CBC_SHA384"},
  245. {0xC04A, "TLS_ECDH_ECDSA_WITH_ARIA_128_CBC_SHA256"},
  246. {0xC04B, "TLS_ECDH_ECDSA_WITH_ARIA_256_CBC_SHA384"},
  247. {0xC04C, "TLS_ECDHE_RSA_WITH_ARIA_128_CBC_SHA256"},
  248. {0xC04D, "TLS_ECDHE_RSA_WITH_ARIA_256_CBC_SHA384"},
  249. {0xC04E, "TLS_ECDH_RSA_WITH_ARIA_128_CBC_SHA256"},
  250. {0xC04F, "TLS_ECDH_RSA_WITH_ARIA_256_CBC_SHA384"},
  251. {0xC050, "TLS_RSA_WITH_ARIA_128_GCM_SHA256"},
  252. {0xC051, "TLS_RSA_WITH_ARIA_256_GCM_SHA384"},
  253. {0xC052, "TLS_DHE_RSA_WITH_ARIA_128_GCM_SHA256"},
  254. {0xC053, "TLS_DHE_RSA_WITH_ARIA_256_GCM_SHA384"},
  255. {0xC054, "TLS_DH_RSA_WITH_ARIA_128_GCM_SHA256"},
  256. {0xC055, "TLS_DH_RSA_WITH_ARIA_256_GCM_SHA384"},
  257. {0xC056, "TLS_DHE_DSS_WITH_ARIA_128_GCM_SHA256"},
  258. {0xC057, "TLS_DHE_DSS_WITH_ARIA_256_GCM_SHA384"},
  259. {0xC058, "TLS_DH_DSS_WITH_ARIA_128_GCM_SHA256"},
  260. {0xC059, "TLS_DH_DSS_WITH_ARIA_256_GCM_SHA384"},
  261. {0xC05A, "TLS_DH_anon_WITH_ARIA_128_GCM_SHA256"},
  262. {0xC05B, "TLS_DH_anon_WITH_ARIA_256_GCM_SHA384"},
  263. {0xC05C, "TLS_ECDHE_ECDSA_WITH_ARIA_128_GCM_SHA256"},
  264. {0xC05D, "TLS_ECDHE_ECDSA_WITH_ARIA_256_GCM_SHA384"},
  265. {0xC05E, "TLS_ECDH_ECDSA_WITH_ARIA_128_GCM_SHA256"},
  266. {0xC05F, "TLS_ECDH_ECDSA_WITH_ARIA_256_GCM_SHA384"},
  267. {0xC060, "TLS_ECDHE_RSA_WITH_ARIA_128_GCM_SHA256"},
  268. {0xC061, "TLS_ECDHE_RSA_WITH_ARIA_256_GCM_SHA384"},
  269. {0xC062, "TLS_ECDH_RSA_WITH_ARIA_128_GCM_SHA256"},
  270. {0xC063, "TLS_ECDH_RSA_WITH_ARIA_256_GCM_SHA384"},
  271. {0xC064, "TLS_PSK_WITH_ARIA_128_CBC_SHA256"},
  272. {0xC065, "TLS_PSK_WITH_ARIA_256_CBC_SHA384"},
  273. {0xC066, "TLS_DHE_PSK_WITH_ARIA_128_CBC_SHA256"},
  274. {0xC067, "TLS_DHE_PSK_WITH_ARIA_256_CBC_SHA384"},
  275. {0xC068, "TLS_RSA_PSK_WITH_ARIA_128_CBC_SHA256"},
  276. {0xC069, "TLS_RSA_PSK_WITH_ARIA_256_CBC_SHA384"},
  277. {0xC06A, "TLS_PSK_WITH_ARIA_128_GCM_SHA256"},
  278. {0xC06B, "TLS_PSK_WITH_ARIA_256_GCM_SHA384"},
  279. {0xC06C, "TLS_DHE_PSK_WITH_ARIA_128_GCM_SHA256"},
  280. {0xC06D, "TLS_DHE_PSK_WITH_ARIA_256_GCM_SHA384"},
  281. {0xC06E, "TLS_RSA_PSK_WITH_ARIA_128_GCM_SHA256"},
  282. {0xC06F, "TLS_RSA_PSK_WITH_ARIA_256_GCM_SHA384"},
  283. {0xC070, "TLS_ECDHE_PSK_WITH_ARIA_128_CBC_SHA256"},
  284. {0xC071, "TLS_ECDHE_PSK_WITH_ARIA_256_CBC_SHA384"},
  285. {0xC072, "TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256"},
  286. {0xC073, "TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384"},
  287. {0xC074, "TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256"},
  288. {0xC075, "TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384"},
  289. {0xC076, "TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256"},
  290. {0xC077, "TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384"},
  291. {0xC078, "TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256"},
  292. {0xC079, "TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384"},
  293. {0xC07A, "TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256"},
  294. {0xC07B, "TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384"},
  295. {0xC07C, "TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256"},
  296. {0xC07D, "TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384"},
  297. {0xC07E, "TLS_DH_RSA_WITH_CAMELLIA_128_GCM_SHA256"},
  298. {0xC07F, "TLS_DH_RSA_WITH_CAMELLIA_256_GCM_SHA384"},
  299. {0xC080, "TLS_DHE_DSS_WITH_CAMELLIA_128_GCM_SHA256"},
  300. {0xC081, "TLS_DHE_DSS_WITH_CAMELLIA_256_GCM_SHA384"},
  301. {0xC082, "TLS_DH_DSS_WITH_CAMELLIA_128_GCM_SHA256"},
  302. {0xC083, "TLS_DH_DSS_WITH_CAMELLIA_256_GCM_SHA384"},
  303. {0xC084, "TLS_DH_anon_WITH_CAMELLIA_128_GCM_SHA256"},
  304. {0xC085, "TLS_DH_anon_WITH_CAMELLIA_256_GCM_SHA384"},
  305. {0xC086, "TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256"},
  306. {0xC087, "TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384"},
  307. {0xC088, "TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256"},
  308. {0xC089, "TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384"},
  309. {0xC08A, "TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256"},
  310. {0xC08B, "TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384"},
  311. {0xC08C, "TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256"},
  312. {0xC08D, "TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384"},
  313. {0xC08E, "TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256"},
  314. {0xC08F, "TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384"},
  315. {0xC090, "TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256"},
  316. {0xC091, "TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384"},
  317. {0xC092, "TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256"},
  318. {0xC093, "TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384"},
  319. {0xC094, "TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256"},
  320. {0xC095, "TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384"},
  321. {0xC096, "TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256"},
  322. {0xC097, "TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384"},
  323. {0xC098, "TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256"},
  324. {0xC099, "TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384"},
  325. {0xC09A, "TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256"},
  326. {0xC09B, "TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384"},
  327. {0xC09C, "TLS_RSA_WITH_AES_128_CCM"},
  328. {0xC09D, "TLS_RSA_WITH_AES_256_CCM"},
  329. {0xC09E, "TLS_DHE_RSA_WITH_AES_128_CCM"},
  330. {0xC09F, "TLS_DHE_RSA_WITH_AES_256_CCM"},
  331. {0xC0A0, "TLS_RSA_WITH_AES_128_CCM_8"},
  332. {0xC0A1, "TLS_RSA_WITH_AES_256_CCM_8"},
  333. {0xC0A2, "TLS_DHE_RSA_WITH_AES_128_CCM_8"},
  334. {0xC0A3, "TLS_DHE_RSA_WITH_AES_256_CCM_8"},
  335. {0xC0A4, "TLS_PSK_WITH_AES_128_CCM"},
  336. {0xC0A5, "TLS_PSK_WITH_AES_256_CCM"},
  337. {0xC0A6, "TLS_DHE_PSK_WITH_AES_128_CCM"},
  338. {0xC0A7, "TLS_DHE_PSK_WITH_AES_256_CCM"},
  339. {0xC0A8, "TLS_PSK_WITH_AES_128_CCM_8"},
  340. {0xC0A9, "TLS_PSK_WITH_AES_256_CCM_8"},
  341. {0xC0AA, "TLS_PSK_DHE_WITH_AES_128_CCM_8"},
  342. {0xC0AB, "TLS_PSK_DHE_WITH_AES_256_CCM_8"},
  343. {0xC0AC, "TLS_ECDHE_ECDSA_WITH_AES_128_CCM"},
  344. {0xC0AD, "TLS_ECDHE_ECDSA_WITH_AES_256_CCM"},
  345. {0xC0AE, "TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8"},
  346. {0xC0AF, "TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8"},
  347. {0xCCA8, "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256"},
  348. {0xCCA9, "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256"},
  349. {0xCCAA, "TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256"},
  350. {0xCCAB, "TLS_PSK_WITH_CHACHA20_POLY1305_SHA256"},
  351. {0xCCAC, "TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256"},
  352. {0xCCAD, "TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256"},
  353. {0xCCAE, "TLS_RSA_PSK_WITH_CHACHA20_POLY1305_SHA256"},
  354. {0x1301, "TLS_AES_128_GCM_SHA256"},
  355. {0x1302, "TLS_AES_256_GCM_SHA384"},
  356. {0x1303, "TLS_CHACHA20_POLY1305_SHA256"},
  357. {0x1304, "TLS_AES_128_CCM_SHA256"},
  358. {0x1305, "TLS_AES_128_CCM_8_SHA256"},
  359. {0xFEFE, "SSL_RSA_FIPS_WITH_DES_CBC_SHA"},
  360. {0xFEFF, "SSL_RSA_FIPS_WITH_3DES_EDE_CBC_SHA"},
  361. };
  362. static const char *get_std_name_by_id(int id)
  363. {
  364. size_t i;
  365. for (i = 0; i < OSSL_NELEM(cipher_names); i++)
  366. if (cipher_names[i].id == id)
  367. return cipher_names[i].name;
  368. return NULL;
  369. }
  370. static int test_cipher_name(void)
  371. {
  372. SSL_CTX *ctx = NULL;
  373. SSL *ssl = NULL;
  374. const SSL_CIPHER *c;
  375. STACK_OF(SSL_CIPHER) *sk = NULL;
  376. const char *ciphers = "ALL:eNULL", *p, *q, *r;
  377. int i, id = 0, ret = 0;
  378. /* tests for invalid input */
  379. p = SSL_CIPHER_standard_name(NULL);
  380. if (!TEST_str_eq(p, "(NONE)")) {
  381. TEST_info("test_cipher_name(std) failed: NULL input doesn't return \"(NONE)\"\n");
  382. goto err;
  383. }
  384. p = OPENSSL_cipher_name(NULL);
  385. if (!TEST_str_eq(p, "(NONE)")) {
  386. TEST_info("test_cipher_name(ossl) failed: NULL input doesn't return \"(NONE)\"\n");
  387. goto err;
  388. }
  389. p = OPENSSL_cipher_name("This is not a valid cipher");
  390. if (!TEST_str_eq(p, "(NONE)")) {
  391. TEST_info("test_cipher_name(ossl) failed: invalid input doesn't return \"(NONE)\"\n");
  392. goto err;
  393. }
  394. /* tests for valid input */
  395. ctx = SSL_CTX_new(TLS_server_method());
  396. if (ctx == NULL) {
  397. TEST_info("test_cipher_name failed: internal error\n");
  398. goto err;
  399. }
  400. if (!SSL_CTX_set_cipher_list(ctx, ciphers)) {
  401. TEST_info("test_cipher_name failed: internal error\n");
  402. goto err;
  403. }
  404. ssl = SSL_new(ctx);
  405. if (ssl == NULL) {
  406. TEST_info("test_cipher_name failed: internal error\n");
  407. goto err;
  408. }
  409. sk = SSL_get_ciphers(ssl);
  410. if (sk == NULL) {
  411. TEST_info("test_cipher_name failed: internal error\n");
  412. goto err;
  413. }
  414. for (i = 0; i < sk_SSL_CIPHER_num(sk); i++) {
  415. c = sk_SSL_CIPHER_value(sk, i);
  416. id = SSL_CIPHER_get_id(c) & 0xFFFF;
  417. if ((id == 0xFF85) || (id == 0xFF87))
  418. /* skip GOST2012-GOST8912-GOST891 and GOST2012-NULL-GOST12 */
  419. continue;
  420. p = SSL_CIPHER_standard_name(c);
  421. q = get_std_name_by_id(id);
  422. if (!TEST_ptr(p)) {
  423. TEST_info("test_cipher_name failed: expected %s, got NULL, cipher %x\n",
  424. q, id);
  425. goto err;
  426. }
  427. /* check if p is a valid standard name */
  428. if (!TEST_str_eq(p, q)) {
  429. TEST_info("test_cipher_name(std) failed: expected %s, got %s, cipher %x\n",
  430. q, p, id);
  431. goto err;
  432. }
  433. /* test OPENSSL_cipher_name */
  434. q = SSL_CIPHER_get_name(c);
  435. r = OPENSSL_cipher_name(p);
  436. if (!TEST_str_eq(r, q)) {
  437. TEST_info("test_cipher_name(ossl) failed: expected %s, got %s, cipher %x\n",
  438. q, r, id);
  439. goto err;
  440. }
  441. }
  442. ret = 1;
  443. err:
  444. SSL_CTX_free(ctx);
  445. SSL_free(ssl);
  446. return ret;
  447. }
  448. int setup_tests(void)
  449. {
  450. ADD_TEST(test_cipher_name);
  451. return 1;
  452. }