cipher_test_cases.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. /*
  2. *
  3. * Copyright (c) 2013-2021, Cisco Systems, Inc.
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. *
  13. * Redistributions in binary form must reproduce the above
  14. * copyright notice, this list of conditions and the following
  15. * disclaimer in the documentation and/or other materials provided
  16. * with the distribution.
  17. *
  18. * Neither the name of the Cisco Systems, Inc. nor the names of its
  19. * contributors may be used to endorse or promote products derived
  20. * from this software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  23. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  24. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  25. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  26. * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  27. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  28. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  29. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  30. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  31. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  32. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  33. * OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. */
  36. #include "cipher_test_cases.h"
  37. #include <stddef.h>
  38. /*
  39. * KAT values for AES self-test. These
  40. * values came from the legacy libsrtp code.
  41. */
  42. /* clang-format off */
  43. static const uint8_t srtp_aes_icm_128_test_case_0_key[SRTP_AES_ICM_128_KEY_LEN_WSALT] = {
  44. 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
  45. 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c,
  46. 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
  47. 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd
  48. };
  49. /* clang-format on */
  50. /* clang-format off */
  51. static uint8_t srtp_aes_icm_128_test_case_0_nonce[16] = {
  52. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  53. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  54. };
  55. /* clang-format on */
  56. /* clang-format off */
  57. static const uint8_t srtp_aes_icm_128_test_case_0_plaintext[32] = {
  58. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  59. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  60. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  61. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  62. };
  63. /* clang-format on */
  64. /* clang-format off */
  65. static const uint8_t srtp_aes_icm_128_test_case_0_ciphertext[32] = {
  66. 0xe0, 0x3e, 0xad, 0x09, 0x35, 0xc9, 0x5e, 0x80,
  67. 0xe1, 0x66, 0xb1, 0x6d, 0xd9, 0x2b, 0x4e, 0xb4,
  68. 0xd2, 0x35, 0x13, 0x16, 0x2b, 0x02, 0xd0, 0xf7,
  69. 0x2a, 0x43, 0xa2, 0xfe, 0x4a, 0x5f, 0x97, 0xab
  70. };
  71. /* clang-format on */
  72. const srtp_cipher_test_case_t srtp_aes_icm_128_test_case_0 = {
  73. SRTP_AES_ICM_128_KEY_LEN_WSALT, /* octets in key */
  74. srtp_aes_icm_128_test_case_0_key, /* key */
  75. srtp_aes_icm_128_test_case_0_nonce, /* packet index */
  76. 32, /* octets in plaintext */
  77. srtp_aes_icm_128_test_case_0_plaintext, /* plaintext */
  78. 32, /* octets in ciphertext */
  79. srtp_aes_icm_128_test_case_0_ciphertext, /* ciphertext */
  80. 0, /* */
  81. NULL, /* */
  82. 0, /* */
  83. NULL /* pointer to next testcase */
  84. };
  85. /*
  86. * KAT values for AES-192-CTR self-test. These
  87. * values came from section 7 of RFC 6188.
  88. */
  89. /* clang-format off */
  90. static const uint8_t srtp_aes_icm_192_test_case_0_key[SRTP_AES_ICM_192_KEY_LEN_WSALT] = {
  91. 0xea, 0xb2, 0x34, 0x76, 0x4e, 0x51, 0x7b, 0x2d,
  92. 0x3d, 0x16, 0x0d, 0x58, 0x7d, 0x8c, 0x86, 0x21,
  93. 0x97, 0x40, 0xf6, 0x5f, 0x99, 0xb6, 0xbc, 0xf7,
  94. 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
  95. 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd
  96. };
  97. /* clang-format on */
  98. /* clang-format off */
  99. static uint8_t srtp_aes_icm_192_test_case_0_nonce[16] = {
  100. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  101. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  102. };
  103. /* clang-format on */
  104. /* clang-format off */
  105. static const uint8_t srtp_aes_icm_192_test_case_0_plaintext[32] = {
  106. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  107. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  108. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  109. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  110. };
  111. /* clang-format on */
  112. /* clang-format off */
  113. static const uint8_t srtp_aes_icm_192_test_case_0_ciphertext[32] = {
  114. 0x35, 0x09, 0x6c, 0xba, 0x46, 0x10, 0x02, 0x8d,
  115. 0xc1, 0xb5, 0x75, 0x03, 0x80, 0x4c, 0xe3, 0x7c,
  116. 0x5d, 0xe9, 0x86, 0x29, 0x1d, 0xcc, 0xe1, 0x61,
  117. 0xd5, 0x16, 0x5e, 0xc4, 0x56, 0x8f, 0x5c, 0x9a
  118. };
  119. /* clang-format on */
  120. const srtp_cipher_test_case_t srtp_aes_icm_192_test_case_0 = {
  121. SRTP_AES_ICM_192_KEY_LEN_WSALT, /* octets in key */
  122. srtp_aes_icm_192_test_case_0_key, /* key */
  123. srtp_aes_icm_192_test_case_0_nonce, /* packet index */
  124. 32, /* octets in plaintext */
  125. srtp_aes_icm_192_test_case_0_plaintext, /* plaintext */
  126. 32, /* octets in ciphertext */
  127. srtp_aes_icm_192_test_case_0_ciphertext, /* ciphertext */
  128. 0, /* */
  129. NULL, /* */
  130. 0, /* */
  131. NULL /* pointer to next testcase */
  132. };
  133. /*
  134. * KAT values for AES-256-CTR self-test. These
  135. * values came from section 7 of RFC 6188.
  136. */
  137. /* clang-format off */
  138. static const uint8_t srtp_aes_icm_256_test_case_0_key[SRTP_AES_ICM_256_KEY_LEN_WSALT] = {
  139. 0x57, 0xf8, 0x2f, 0xe3, 0x61, 0x3f, 0xd1, 0x70,
  140. 0xa8, 0x5e, 0xc9, 0x3c, 0x40, 0xb1, 0xf0, 0x92,
  141. 0x2e, 0xc4, 0xcb, 0x0d, 0xc0, 0x25, 0xb5, 0x82,
  142. 0x72, 0x14, 0x7c, 0xc4, 0x38, 0x94, 0x4a, 0x98,
  143. 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
  144. 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd
  145. };
  146. /* clang-format on */
  147. /* clang-format off */
  148. static uint8_t srtp_aes_icm_256_test_case_0_nonce[16] = {
  149. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  150. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  151. };
  152. /* clang-format on */
  153. /* clang-format off */
  154. static const uint8_t srtp_aes_icm_256_test_case_0_plaintext[32] = {
  155. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  156. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  157. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  158. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  159. };
  160. /* clang-format on */
  161. /* clang-format off */
  162. static const uint8_t srtp_aes_icm_256_test_case_0_ciphertext[32] = {
  163. 0x92, 0xbd, 0xd2, 0x8a, 0x93, 0xc3, 0xf5, 0x25,
  164. 0x11, 0xc6, 0x77, 0xd0, 0x8b, 0x55, 0x15, 0xa4,
  165. 0x9d, 0xa7, 0x1b, 0x23, 0x78, 0xa8, 0x54, 0xf6,
  166. 0x70, 0x50, 0x75, 0x6d, 0xed, 0x16, 0x5b, 0xac
  167. };
  168. /* clang-format on */
  169. const srtp_cipher_test_case_t srtp_aes_icm_256_test_case_0 = {
  170. SRTP_AES_ICM_256_KEY_LEN_WSALT, /* octets in key */
  171. srtp_aes_icm_256_test_case_0_key, /* key */
  172. srtp_aes_icm_256_test_case_0_nonce, /* packet index */
  173. 32, /* octets in plaintext */
  174. srtp_aes_icm_256_test_case_0_plaintext, /* plaintext */
  175. 32, /* octets in ciphertext */
  176. srtp_aes_icm_256_test_case_0_ciphertext, /* ciphertext */
  177. 0, /* */
  178. NULL, /* */
  179. 0, /* */
  180. NULL /* pointer to next testcase */
  181. };
  182. /*
  183. * KAT values for AES self-test. These
  184. * values we're derived from independent test code
  185. * using OpenSSL.
  186. */
  187. /* clang-format off */
  188. static const uint8_t srtp_aes_gcm_128_test_case_0_key[SRTP_AES_GCM_128_KEY_LEN_WSALT] = {
  189. 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
  190. 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08,
  191. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  192. 0x09, 0x0a, 0x0b, 0x0c,
  193. };
  194. /* clang-format on */
  195. /* clang-format off */
  196. static uint8_t srtp_aes_gcm_128_test_case_0_iv[12] = {
  197. 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad,
  198. 0xde, 0xca, 0xf8, 0x88
  199. };
  200. /* clang-format on */
  201. /* clang-format off */
  202. static const uint8_t srtp_aes_gcm_128_test_case_0_plaintext[60] = {
  203. 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5,
  204. 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a,
  205. 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
  206. 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72,
  207. 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53,
  208. 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
  209. 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57,
  210. 0xba, 0x63, 0x7b, 0x39
  211. };
  212. /* clang-format off */
  213. static const uint8_t srtp_aes_gcm_128_test_case_0_aad[20] = {
  214. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  215. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  216. 0xab, 0xad, 0xda, 0xd2
  217. };
  218. /* clang-format on */
  219. /* clang-format off */
  220. static const uint8_t srtp_aes_gcm_128_test_case_0_ciphertext[76] = {
  221. 0x42, 0x83, 0x1e, 0xc2, 0x21, 0x77, 0x74, 0x24,
  222. 0x4b, 0x72, 0x21, 0xb7, 0x84, 0xd0, 0xd4, 0x9c,
  223. 0xe3, 0xaa, 0x21, 0x2f, 0x2c, 0x02, 0xa4, 0xe0,
  224. 0x35, 0xc1, 0x7e, 0x23, 0x29, 0xac, 0xa1, 0x2e,
  225. 0x21, 0xd5, 0x14, 0xb2, 0x54, 0x66, 0x93, 0x1c,
  226. 0x7d, 0x8f, 0x6a, 0x5a, 0xac, 0x84, 0xaa, 0x05,
  227. 0x1b, 0xa3, 0x0b, 0x39, 0x6a, 0x0a, 0xac, 0x97,
  228. 0x3d, 0x58, 0xe0, 0x91,
  229. /* the last 16 bytes are the tag */
  230. 0x5b, 0xc9, 0x4f, 0xbc, 0x32, 0x21, 0xa5, 0xdb,
  231. 0x94, 0xfa, 0xe9, 0x5a, 0xe7, 0x12, 0x1a, 0x47,
  232. };
  233. /* clang-format on */
  234. static const srtp_cipher_test_case_t srtp_aes_gcm_128_test_case_0a = {
  235. SRTP_AES_GCM_128_KEY_LEN_WSALT, /* octets in key */
  236. srtp_aes_gcm_128_test_case_0_key, /* key */
  237. srtp_aes_gcm_128_test_case_0_iv, /* packet index */
  238. 60, /* octets in plaintext */
  239. srtp_aes_gcm_128_test_case_0_plaintext, /* plaintext */
  240. 68, /* octets in ciphertext */
  241. srtp_aes_gcm_128_test_case_0_ciphertext, /* ciphertext + tag */
  242. 20, /* octets in AAD */
  243. srtp_aes_gcm_128_test_case_0_aad, /* AAD */
  244. 8, /* */
  245. NULL /* pointer to next testcase */
  246. };
  247. const srtp_cipher_test_case_t srtp_aes_gcm_128_test_case_0 = {
  248. SRTP_AES_GCM_128_KEY_LEN_WSALT, /* octets in key */
  249. srtp_aes_gcm_128_test_case_0_key, /* key */
  250. srtp_aes_gcm_128_test_case_0_iv, /* packet index */
  251. 60, /* octets in plaintext */
  252. srtp_aes_gcm_128_test_case_0_plaintext, /* plaintext */
  253. 76, /* octets in ciphertext */
  254. srtp_aes_gcm_128_test_case_0_ciphertext, /* ciphertext + tag */
  255. 20, /* octets in AAD */
  256. srtp_aes_gcm_128_test_case_0_aad, /* AAD */
  257. 16, /* */
  258. &srtp_aes_gcm_128_test_case_0a /* pointer to next testcase */
  259. };
  260. /* clang-format off */
  261. static const uint8_t srtp_aes_gcm_256_test_case_0_key[SRTP_AES_GCM_256_KEY_LEN_WSALT] = {
  262. 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
  263. 0xa5, 0x59, 0x09, 0xc5, 0x54, 0x66, 0x93, 0x1c,
  264. 0xaf, 0xf5, 0x26, 0x9a, 0x21, 0xd5, 0x14, 0xb2,
  265. 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08,
  266. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  267. 0x09, 0x0a, 0x0b, 0x0c,
  268. };
  269. /* clang-format on */
  270. /* clang-format off */
  271. static uint8_t srtp_aes_gcm_256_test_case_0_iv[12] = {
  272. 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad,
  273. 0xde, 0xca, 0xf8, 0x88
  274. };
  275. /* clang-format on */
  276. /* clang-format off */
  277. static const uint8_t srtp_aes_gcm_256_test_case_0_plaintext[60] = {
  278. 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5,
  279. 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a,
  280. 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
  281. 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72,
  282. 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53,
  283. 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
  284. 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57,
  285. 0xba, 0x63, 0x7b, 0x39
  286. };
  287. /* clang-format on */
  288. /* clang-format off */
  289. static const uint8_t srtp_aes_gcm_256_test_case_0_aad[20] = {
  290. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  291. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  292. 0xab, 0xad, 0xda, 0xd2
  293. };
  294. /* clang-format on */
  295. /* clang-format off */
  296. static const uint8_t srtp_aes_gcm_256_test_case_0_ciphertext[76] = {
  297. 0x0b, 0x11, 0xcf, 0xaf, 0x68, 0x4d, 0xae, 0x46,
  298. 0xc7, 0x90, 0xb8, 0x8e, 0xb7, 0x6a, 0x76, 0x2a,
  299. 0x94, 0x82, 0xca, 0xab, 0x3e, 0x39, 0xd7, 0x86,
  300. 0x1b, 0xc7, 0x93, 0xed, 0x75, 0x7f, 0x23, 0x5a,
  301. 0xda, 0xfd, 0xd3, 0xe2, 0x0e, 0x80, 0x87, 0xa9,
  302. 0x6d, 0xd7, 0xe2, 0x6a, 0x7d, 0x5f, 0xb4, 0x80,
  303. 0xef, 0xef, 0xc5, 0x29, 0x12, 0xd1, 0xaa, 0x10,
  304. 0x09, 0xc9, 0x86, 0xc1,
  305. /* the last 16 bytes are the tag */
  306. 0x45, 0xbc, 0x03, 0xe6, 0xe1, 0xac, 0x0a, 0x9f,
  307. 0x81, 0xcb, 0x8e, 0x5b, 0x46, 0x65, 0x63, 0x1d,
  308. };
  309. /* clang-format on */
  310. static const srtp_cipher_test_case_t srtp_aes_gcm_256_test_case_0a = {
  311. SRTP_AES_GCM_256_KEY_LEN_WSALT, /* octets in key */
  312. srtp_aes_gcm_256_test_case_0_key, /* key */
  313. srtp_aes_gcm_256_test_case_0_iv, /* packet index */
  314. 60, /* octets in plaintext */
  315. srtp_aes_gcm_256_test_case_0_plaintext, /* plaintext */
  316. 68, /* octets in ciphertext */
  317. srtp_aes_gcm_256_test_case_0_ciphertext, /* ciphertext + tag */
  318. 20, /* octets in AAD */
  319. srtp_aes_gcm_256_test_case_0_aad, /* AAD */
  320. 8, /* */
  321. NULL /* pointer to next testcase */
  322. };
  323. const srtp_cipher_test_case_t srtp_aes_gcm_256_test_case_0 = {
  324. SRTP_AES_GCM_256_KEY_LEN_WSALT, /* octets in key */
  325. srtp_aes_gcm_256_test_case_0_key, /* key */
  326. srtp_aes_gcm_256_test_case_0_iv, /* packet index */
  327. 60, /* octets in plaintext */
  328. srtp_aes_gcm_256_test_case_0_plaintext, /* plaintext */
  329. 76, /* octets in ciphertext */
  330. srtp_aes_gcm_256_test_case_0_ciphertext, /* ciphertext + tag */
  331. 20, /* octets in AAD */
  332. srtp_aes_gcm_256_test_case_0_aad, /* AAD */
  333. 16, /* */
  334. &srtp_aes_gcm_256_test_case_0a /* pointer to next testcase */
  335. };