test_aes.c 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244
  1. /* mbedTLS AES test
  2. */
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <stdbool.h>
  6. #include <esp_system.h>
  7. #include "mbedtls/aes.h"
  8. #include "mbedtls/gcm.h"
  9. #include "unity.h"
  10. #include "sdkconfig.h"
  11. #include "esp_timer.h"
  12. #include "esp_heap_caps.h"
  13. #include "test_utils.h"
  14. TEST_CASE("mbedtls CTR stream test", "[aes]")
  15. {
  16. const unsigned SZ = 100;
  17. mbedtls_aes_context ctx;
  18. uint8_t nonce[16];
  19. uint8_t key[16];
  20. uint8_t stream_block[16];
  21. /* Cipher produced via this Python:
  22. import os, binascii
  23. from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
  24. from cryptography.hazmat.backends import default_backend
  25. key = b'\x44' * 16
  26. nonce = b'\xee' * 16
  27. cipher = Cipher(algorithms.AES(key), modes.CTR(nonce), backend=default_backend())
  28. encryptor = cipher.encryptor()
  29. ct = encryptor.update(b'\xaa' * 100) + encryptor.finalize()
  30. ct_arr = ""
  31. for idx, b in enumerate(ct):
  32. if idx % 8 == 0:
  33. ct_arr += '\n'
  34. ct_arr += "0x{}, ".format(binascii.hexlify(b))
  35. print(ct_arr)
  36. */
  37. const uint8_t expected_cipher[] = {
  38. 0xc5, 0x78, 0xa7, 0xb4, 0xf3, 0xb9, 0xcb, 0x8b,
  39. 0x09, 0xe0, 0xd6, 0x89, 0x14, 0x6a, 0x19, 0x09,
  40. 0xde, 0xaf, 0x37, 0x19, 0x32, 0x4d, 0xca, 0xf6,
  41. 0xff, 0x6e, 0xd2, 0x5d, 0x87, 0x51, 0xaa, 0x8c,
  42. 0x1c, 0xe3, 0x3b, 0xbb, 0x18, 0xf5, 0xa0, 0x1b,
  43. 0xdc, 0x29, 0x52, 0x63, 0xf6, 0x5d, 0x49, 0x85,
  44. 0x29, 0xf1, 0xf0, 0x69, 0x8f, 0xa6, 0x9f, 0x38,
  45. 0x5c, 0xdd, 0x26, 0xf8, 0x9d, 0x40, 0xa1, 0xff,
  46. 0x52, 0x46, 0xe1, 0x72, 0x70, 0x39, 0x73, 0xff,
  47. 0xd0, 0x5e, 0xe5, 0x3f, 0xc5, 0xed, 0x5c, 0x18,
  48. 0xa7, 0x84, 0xd8, 0xdf, 0x9d, 0xb5, 0x06, 0xb1,
  49. 0xa7, 0xcf, 0x2e, 0x7a, 0x51, 0xfc, 0x44, 0xc5,
  50. 0xb9, 0x5f, 0x22, 0x47,
  51. };
  52. memset(nonce, 0xEE, 16);
  53. memset(key, 0x44, 16);
  54. // allocate internal memory
  55. uint8_t *chipertext = heap_caps_malloc(SZ, MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL);
  56. uint8_t *plaintext = heap_caps_malloc(SZ, MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL);
  57. uint8_t *decryptedtext = heap_caps_malloc(SZ, MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL);
  58. TEST_ASSERT_NOT_NULL(chipertext);
  59. TEST_ASSERT_NOT_NULL(plaintext);
  60. TEST_ASSERT_NOT_NULL(decryptedtext);
  61. mbedtls_aes_init(&ctx);
  62. mbedtls_aes_setkey_enc(&ctx, key, 128);
  63. memset(plaintext, 0xAA, SZ);
  64. /* Test that all the end results are the same
  65. no matter how many bytes we encrypt each call
  66. */
  67. for (int bytes_to_process = 1; bytes_to_process < SZ; bytes_to_process++) {
  68. memset(nonce, 0xEE, 16);
  69. memset(chipertext, 0x0, SZ);
  70. memset(decryptedtext, 0x0, SZ);
  71. size_t offset = 0;
  72. // Encrypt
  73. for (int idx = 0; idx < SZ; idx = idx + bytes_to_process) {
  74. // Limit length of last call to avoid exceeding buffer size
  75. size_t length = (idx + bytes_to_process > SZ) ? (SZ - idx) : bytes_to_process;
  76. mbedtls_aes_crypt_ctr(&ctx, length, &offset, nonce,
  77. stream_block, plaintext + idx, chipertext + idx );
  78. }
  79. TEST_ASSERT_EQUAL_HEX8_ARRAY(expected_cipher, chipertext, SZ);
  80. // Decrypt
  81. memset(nonce, 0xEE, 16);
  82. offset = 0;
  83. for (int idx = 0; idx < SZ; idx = idx + bytes_to_process) {
  84. // Limit length of last call to avoid exceeding buffer size
  85. size_t length = (idx + bytes_to_process > SZ) ? (SZ - idx) : bytes_to_process;
  86. mbedtls_aes_crypt_ctr(&ctx, length, &offset, nonce,
  87. stream_block, chipertext + idx, decryptedtext + idx );
  88. }
  89. TEST_ASSERT_EQUAL_HEX8_ARRAY(plaintext, decryptedtext, SZ);
  90. }
  91. free(plaintext);
  92. free(chipertext);
  93. free(decryptedtext);
  94. }
  95. TEST_CASE("mbedtls GCM stream test", "[aes]")
  96. {
  97. const unsigned SZ = 100;
  98. mbedtls_gcm_context ctx;
  99. uint8_t nonce[16];
  100. uint8_t key[16];
  101. uint8_t tag[16];
  102. mbedtls_cipher_id_t cipher = MBEDTLS_CIPHER_ID_AES;
  103. /* Cipher produced via this Python:
  104. import os, binascii
  105. from cryptography.hazmat.primitives.ciphers.aead import AESGCM
  106. key = b'\x56' * 16
  107. iv = b'\x89' * 16
  108. data = b'\xab' * 100
  109. aesgcm = AESGCM(key)
  110. ct = aesgcm.encrypt(iv, data, '')
  111. ct_arr = ""
  112. for idx, b in enumerate(ct):
  113. if idx % 8 == 0:
  114. ct_arr += '\n'
  115. ct_arr += "0x{}, ".format(binascii.hexlify(b))
  116. print(ct_arr)
  117. */
  118. const uint8_t expected_cipher[] = {
  119. 0x03, 0x92, 0x13, 0x49, 0x1f, 0x1f, 0x24, 0x41,
  120. 0xe8, 0xeb, 0x89, 0x47, 0x50, 0x0a, 0xce, 0xa3,
  121. 0xc7, 0x1c, 0x10, 0x70, 0xb0, 0x89, 0x82, 0x5e,
  122. 0x0f, 0x4a, 0x23, 0xee, 0xd2, 0xfc, 0xff, 0x45,
  123. 0x61, 0x4c, 0xd1, 0xfb, 0x6d, 0xe2, 0xbe, 0x67,
  124. 0x6f, 0x94, 0x72, 0xa3, 0xe7, 0x04, 0x99, 0xb3,
  125. 0x4a, 0x46, 0xf9, 0x2b, 0xaf, 0xac, 0xa9, 0x0e,
  126. 0x43, 0x7e, 0x8b, 0xc4, 0xbf, 0x49, 0xa4, 0x83,
  127. 0x9c, 0x31, 0x11, 0x1c, 0x09, 0xac, 0x90, 0xdf,
  128. 0x00, 0x34, 0x08, 0xe5, 0x70, 0xa3, 0x7e, 0x4b,
  129. 0x36, 0x48, 0x5a, 0x3f, 0x28, 0xc7, 0x1c, 0xd9,
  130. 0x1b, 0x1b, 0x49, 0x96, 0xe9, 0x7c, 0xea, 0x54,
  131. 0x7c, 0x71, 0x29, 0x0d
  132. };
  133. const uint8_t expected_tag[] = {
  134. 0x35, 0x1c, 0x21, 0xc6, 0xbc, 0x6b, 0x18, 0x52,
  135. 0x90, 0xe1, 0xf2, 0x5b, 0xe1, 0xf6, 0x15, 0xee,
  136. };
  137. memset(nonce, 0x89, 16);
  138. memset(key, 0x56, 16);
  139. // allocate internal memory
  140. uint8_t *chipertext = heap_caps_malloc(SZ, MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL);
  141. uint8_t *plaintext = heap_caps_malloc(SZ, MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL);
  142. uint8_t *decryptedtext = heap_caps_malloc(SZ, MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL);
  143. TEST_ASSERT_NOT_NULL(chipertext);
  144. TEST_ASSERT_NOT_NULL(plaintext);
  145. TEST_ASSERT_NOT_NULL(decryptedtext);
  146. memset(plaintext, 0xAB, SZ);
  147. /* Test that all the end results are the same
  148. no matter how many bytes we encrypt each call
  149. */
  150. for (int bytes_to_process = 16; bytes_to_process < SZ; bytes_to_process = bytes_to_process + 16) {
  151. memset(nonce, 0x89, 16);
  152. memset(chipertext, 0x0, SZ);
  153. memset(decryptedtext, 0x0, SZ);
  154. memset(tag, 0x0, 16);
  155. mbedtls_gcm_init(&ctx);
  156. mbedtls_gcm_setkey(&ctx, cipher, key, 128);
  157. mbedtls_gcm_starts( &ctx, MBEDTLS_AES_ENCRYPT, nonce, sizeof(nonce), NULL, 0 );
  158. // Encrypt
  159. for (int idx = 0; idx < SZ; idx = idx + bytes_to_process) {
  160. // Limit length of last call to avoid exceeding buffer size
  161. size_t length = (idx + bytes_to_process > SZ) ? (SZ - idx) : bytes_to_process;
  162. mbedtls_gcm_update(&ctx, length, plaintext + idx, chipertext + idx );
  163. }
  164. mbedtls_gcm_finish( &ctx, tag, sizeof(tag) );
  165. TEST_ASSERT_EQUAL_HEX8_ARRAY(expected_cipher, chipertext, SZ);
  166. TEST_ASSERT_EQUAL_HEX8_ARRAY(expected_tag, tag, sizeof(tag));
  167. // Decrypt
  168. memset(nonce, 0x89, 16);
  169. mbedtls_gcm_free( &ctx );
  170. mbedtls_gcm_init(&ctx);
  171. mbedtls_gcm_setkey(&ctx, cipher, key, 128);
  172. mbedtls_gcm_starts( &ctx, MBEDTLS_AES_DECRYPT, nonce, sizeof(nonce), NULL, 0 );
  173. for (int idx = 0; idx < SZ; idx = idx + bytes_to_process) {
  174. // Limit length of last call to avoid exceeding buffer size
  175. size_t length = (idx + bytes_to_process > SZ) ? (SZ - idx) : bytes_to_process;
  176. mbedtls_gcm_update(&ctx, length, chipertext + idx, decryptedtext + idx );
  177. }
  178. mbedtls_gcm_finish( &ctx, tag, sizeof(tag) );
  179. TEST_ASSERT_EQUAL_HEX8_ARRAY(plaintext, decryptedtext, SZ);
  180. mbedtls_gcm_free( &ctx );
  181. }
  182. free(plaintext);
  183. free(chipertext);
  184. free(decryptedtext);
  185. }
  186. TEST_CASE("mbedtls OFB stream test", "[aes]")
  187. {
  188. const unsigned SZ = 100;
  189. mbedtls_aes_context ctx;
  190. uint8_t iv[16];
  191. uint8_t key[16];
  192. /* Cipher produced via this Python:
  193. import os, binascii
  194. from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
  195. from cryptography.hazmat.backends import default_backend
  196. key = b'\x44' * 16
  197. iv = b'\xee' * 16
  198. cipher = Cipher(algorithms.AES(key), modes.OFB(iv), backend=default_backend())
  199. encryptor = cipher.encryptor()
  200. ct = encryptor.update(b'\xaa' * 100) + encryptor.finalize()
  201. ct_arr = ""
  202. for idx, b in enumerate(ct):
  203. if idx % 8 == 0:
  204. ct_arr += '\n'
  205. ct_arr += "0x{}, ".format(binascii.hexlify(b))
  206. print(ct_arr)
  207. */
  208. const uint8_t expected_cipher[] = {
  209. 0xc5, 0x78, 0xa7, 0xb4, 0xf3, 0xb9, 0xcb, 0x8b,
  210. 0x09, 0xe0, 0xd6, 0x89, 0x14, 0x6a, 0x19, 0x09,
  211. 0x0a, 0x33, 0x8b, 0xab, 0x82, 0xcb, 0x20, 0x8f,
  212. 0x74, 0x2a, 0x6c, 0xb3, 0xc6, 0xe8, 0x18, 0x89,
  213. 0x09, 0xb6, 0xaf, 0x20, 0xcd, 0xea, 0x74, 0x14,
  214. 0x48, 0x61, 0xe8, 0x4d, 0x50, 0x12, 0x9f, 0x5e,
  215. 0xb8, 0x10, 0x53, 0x3b, 0x74, 0xd9, 0xd0, 0x95,
  216. 0x13, 0xdc, 0x14, 0xcf, 0x0c, 0xa1, 0x90, 0xfd,
  217. 0xa2, 0x58, 0x12, 0xb2, 0x00, 0x2c, 0x5b, 0x7a,
  218. 0x2a, 0x76, 0x80, 0x20, 0x82, 0x39, 0xa2, 0x21,
  219. 0xf8, 0x7a, 0xec, 0xae, 0x82, 0x6a, 0x5c, 0xd3,
  220. 0x04, 0xd9, 0xbd, 0xe4, 0x53, 0xc9, 0xdf, 0x67,
  221. 0xaa, 0x5c, 0xaf, 0xa6,
  222. };
  223. memset(key, 0x44, 16);
  224. // allocate internal memory
  225. uint8_t *chipertext = heap_caps_malloc(SZ, MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL);
  226. uint8_t *plaintext = heap_caps_malloc(SZ, MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL);
  227. uint8_t *decryptedtext = heap_caps_malloc(SZ, MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL);
  228. TEST_ASSERT_NOT_NULL(chipertext);
  229. TEST_ASSERT_NOT_NULL(plaintext);
  230. TEST_ASSERT_NOT_NULL(decryptedtext);
  231. mbedtls_aes_init(&ctx);
  232. mbedtls_aes_setkey_enc(&ctx, key, 128);
  233. memset(plaintext, 0xAA, SZ);
  234. /* Test that all the end results are the same
  235. no matter how many bytes we encrypt each call
  236. */
  237. for (int bytes_to_process = 1; bytes_to_process < SZ; bytes_to_process++) {
  238. // Encrypt
  239. memset(iv, 0xEE, 16);
  240. size_t offset = 0;
  241. for (int idx = 0; idx < SZ; idx = idx + bytes_to_process) {
  242. // Limit length of last call to avoid exceeding buffer size
  243. size_t length = ( (idx + bytes_to_process) > SZ) ? (SZ - idx) : bytes_to_process;
  244. mbedtls_aes_crypt_ofb(&ctx, length, &offset, iv, plaintext + idx, chipertext + idx);
  245. }
  246. TEST_ASSERT_EQUAL_HEX8_ARRAY(expected_cipher, chipertext, SZ);
  247. // Decrypt
  248. memset(iv, 0xEE, 16);
  249. offset = 0;
  250. for (int idx = 0; idx < SZ; idx = idx + bytes_to_process) {
  251. // Limit length of last call to avoid exceeding buffer size
  252. size_t length = (idx + bytes_to_process > SZ) ? (SZ - idx) : bytes_to_process;
  253. mbedtls_aes_crypt_ofb(&ctx, length, &offset, iv, chipertext + idx, decryptedtext + idx);
  254. }
  255. TEST_ASSERT_EQUAL_HEX8_ARRAY(plaintext, decryptedtext, SZ);
  256. }
  257. free(plaintext);
  258. free(chipertext);
  259. free(decryptedtext);
  260. }
  261. TEST_CASE("mbedtls CFB8 stream test", "[aes]")
  262. {
  263. const unsigned SZ = 32;
  264. mbedtls_aes_context ctx;
  265. uint8_t iv[16];
  266. uint8_t key[16];
  267. /* Cipher produced via this Python:
  268. import os, binascii
  269. from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
  270. from cryptography.hazmat.backends import default_backend
  271. key = b'\x44' * 16
  272. iv = b'\xee' * 16
  273. cipher = Cipher(algorithms.AES(key), modes.CFB8(iv), backend=default_backend())
  274. encryptor = cipher.encryptor()
  275. ct = encryptor.update(b'\xaa' * 100) + encryptor.finalize()
  276. ct_arr = ""
  277. for idx, b in enumerate(ct):
  278. if idx % 8 == 0:
  279. ct_arr += '\n'
  280. ct_arr += "0x{}, ".format(binascii.hexlify(b))
  281. print(ct_arr)
  282. */
  283. const uint8_t expected_cipher[] = {
  284. 0xc5, 0x2f, 0xb0, 0x9b, 0x94, 0x9c, 0xa4, 0x5c,
  285. 0x0f, 0x4d, 0xa1, 0x9d, 0xd1, 0x19, 0xfc, 0x04,
  286. 0xe2, 0x7f, 0x04, 0x82, 0x6a, 0xa3, 0x61, 0xbb,
  287. 0x07, 0x6f, 0xac, 0xb9, 0xdf, 0x00, 0xf9, 0xa8,
  288. 0xc4, 0xbe, 0x9d, 0x4d, 0xd9, 0x42, 0x8a, 0x83,
  289. 0x12, 0x8b, 0xeb, 0xd7, 0x88, 0x70, 0x8a, 0xed,
  290. 0x46, 0x81, 0x5b, 0x4c, 0x14, 0x67, 0xe0, 0xfb,
  291. 0xab, 0x34, 0x90, 0x85, 0x24, 0xd2, 0x6b, 0x64,
  292. 0xdf, 0x1d, 0x04, 0xfd, 0x69, 0xf6, 0x30, 0xbe,
  293. 0xa6, 0xac, 0x0b, 0x54, 0x25, 0x24, 0x67, 0xd6,
  294. 0x09, 0xb1, 0x8f, 0x91, 0x63, 0xbd, 0xdf, 0xa1,
  295. 0x8a, 0xa3, 0x2e, 0xeb, 0x15, 0x7d, 0xe5, 0x37,
  296. 0xe5, 0x5a, 0x9f, 0xa5,
  297. };
  298. memset(key, 0x44, 16);
  299. // allocate internal memory
  300. uint8_t *chipertext = heap_caps_malloc(SZ, MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL);
  301. uint8_t *plaintext = heap_caps_malloc(SZ, MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL);
  302. uint8_t *decryptedtext = heap_caps_malloc(SZ, MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL);
  303. TEST_ASSERT_NOT_NULL(chipertext);
  304. TEST_ASSERT_NOT_NULL(plaintext);
  305. TEST_ASSERT_NOT_NULL(decryptedtext);
  306. mbedtls_aes_init(&ctx);
  307. mbedtls_aes_setkey_enc(&ctx, key, 128);
  308. memset(plaintext, 0xAA, SZ);
  309. /* Test that all the end results are the same
  310. no matter how many bytes we encrypt each call
  311. */
  312. for (int bytes_to_process = 1; bytes_to_process < SZ; bytes_to_process++) {
  313. memset(iv, 0xEE, 16);
  314. for (int idx = 0; idx < SZ; idx = idx + bytes_to_process) {
  315. // Limit length of last call to avoid exceeding buffer size
  316. size_t length = ( (idx + bytes_to_process) > SZ) ? (SZ - idx) : bytes_to_process;
  317. mbedtls_aes_crypt_cfb8(&ctx, MBEDTLS_AES_ENCRYPT, length, iv, plaintext + idx, chipertext + idx);
  318. }
  319. TEST_ASSERT_EQUAL_HEX8_ARRAY(expected_cipher, chipertext, SZ);
  320. memset(iv, 0xEE, 16);
  321. for (int idx = 0; idx < SZ; idx = idx + bytes_to_process) {
  322. // Limit length of last call to avoid exceeding buffer size
  323. size_t length = ( (idx + bytes_to_process) > SZ) ? (SZ - idx) : bytes_to_process;
  324. mbedtls_aes_crypt_cfb8(&ctx, MBEDTLS_AES_DECRYPT, length, iv, chipertext + idx, decryptedtext + idx);
  325. }
  326. TEST_ASSERT_EQUAL_HEX8_ARRAY(plaintext, decryptedtext, SZ);
  327. }
  328. free(plaintext);
  329. free(chipertext);
  330. free(decryptedtext);
  331. }
  332. TEST_CASE("mbedtls CFB128 stream test", "[aes]")
  333. {
  334. const unsigned SZ = 32;
  335. mbedtls_aes_context ctx;
  336. uint8_t iv[16];
  337. uint8_t key[16];
  338. /* Cipher produced via this Python:
  339. import os, binascii
  340. from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
  341. from cryptography.hazmat.backends import default_backend
  342. key = b'\x44' * 16
  343. iv = b'\xee' * 16
  344. cipher = Cipher(algorithms.AES(key), modes.CFB(iv), backend=default_backend())
  345. encryptor = cipher.encryptor()
  346. ct = encryptor.update(b'\xaa' * 100) + encryptor.finalize()
  347. ct_arr = ""
  348. for idx, b in enumerate(ct):
  349. if idx % 8 == 0:
  350. ct_arr += '\n'
  351. ct_arr += "0x{}, ".format(binascii.hexlify(b))
  352. print(ct_arr)
  353. */
  354. const uint8_t expected_cipher[] = {
  355. 0xc5, 0x78, 0xa7, 0xb4, 0xf3, 0xb9, 0xcb, 0x8b,
  356. 0x09, 0xe0, 0xd6, 0x89, 0x14, 0x6a, 0x19, 0x09,
  357. 0xf9, 0x08, 0x7e, 0xe1, 0x92, 0x8a, 0x7c, 0xa4,
  358. 0x25, 0xa5, 0xa7, 0x43, 0x24, 0x8d, 0x85, 0x3e,
  359. 0x99, 0x28, 0xeb, 0x36, 0x59, 0x74, 0x69, 0x0e,
  360. 0x09, 0x9f, 0x4e, 0xc0, 0x6d, 0xc3, 0x2b, 0x80,
  361. 0x01, 0xad, 0xa1, 0x0c, 0x99, 0x90, 0x8b, 0x07,
  362. 0xd6, 0x00, 0xf0, 0x32, 0xd7, 0x6b, 0xa1, 0xf1,
  363. 0x4d, 0x14, 0xd0, 0x28, 0xde, 0x64, 0x23, 0x71,
  364. 0xf4, 0x23, 0x61, 0x12, 0x71, 0xbe, 0x03, 0x74,
  365. 0x99, 0x81, 0x9d, 0x65, 0x48, 0xd9, 0xd4, 0x67,
  366. 0xd1, 0x31, 0xe8, 0x44, 0x27, 0x17, 0xd4, 0x2d,
  367. 0x3d, 0x59, 0xf7, 0xd3,
  368. };
  369. memset(key, 0x44, 16);
  370. // allocate internal memory
  371. uint8_t *chipertext = heap_caps_malloc(SZ, MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL);
  372. uint8_t *plaintext = heap_caps_malloc(SZ, MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL);
  373. uint8_t *decryptedtext = heap_caps_malloc(SZ, MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL);
  374. TEST_ASSERT_NOT_NULL(chipertext);
  375. TEST_ASSERT_NOT_NULL(plaintext);
  376. TEST_ASSERT_NOT_NULL(decryptedtext);
  377. mbedtls_aes_init(&ctx);
  378. mbedtls_aes_setkey_enc(&ctx, key, 128);
  379. memset(plaintext, 0xAA, SZ);
  380. /* Test that all the end results are the same
  381. no matter how many bytes we encrypt each call
  382. */
  383. //for (int bytes_to_process = 1; bytes_to_process < SZ; bytes_to_process++) {
  384. int bytes_to_process = 17;
  385. size_t offset = 0;
  386. memset(iv, 0xEE, 16);
  387. for (int idx = 0; idx < SZ; idx = idx + bytes_to_process) {
  388. // Limit length of last call to avoid exceeding buffer size
  389. size_t length = ( (idx + bytes_to_process) > SZ) ? (SZ - idx) : bytes_to_process;
  390. mbedtls_aes_crypt_cfb128(&ctx, MBEDTLS_AES_ENCRYPT, length, &offset, iv, plaintext + idx, chipertext + idx);
  391. }
  392. TEST_ASSERT_EQUAL_HEX8_ARRAY(expected_cipher, chipertext, SZ);
  393. offset = 0;
  394. memset(iv, 0xEE, 16);
  395. for (int idx = 0; idx < SZ; idx = idx + bytes_to_process) {
  396. // Limit length of last call to avoid exceeding buffer size
  397. size_t length = ( (idx + bytes_to_process) > SZ) ? (SZ - idx) : bytes_to_process;
  398. mbedtls_aes_crypt_cfb128(&ctx, MBEDTLS_AES_DECRYPT, length, &offset, iv, chipertext + idx, decryptedtext + idx);
  399. }
  400. TEST_ASSERT_EQUAL_HEX8_ARRAY(plaintext, decryptedtext, SZ);
  401. free(plaintext);
  402. free(chipertext);
  403. free(decryptedtext);
  404. }
  405. /* Cipher produced via this Python:
  406. import os, binascii
  407. from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
  408. from cryptography.hazmat.backends import default_backend
  409. key = b'\x44' * 16
  410. nonce = b'\xee' * 16
  411. cipher = Cipher(algorithms.AES(key), modes.CTR(nonce), backend=default_backend())
  412. encryptor = cipher.encryptor()
  413. ct = encryptor.update(b'\xaa' * 100) + encryptor.finalize()
  414. ct_arr = ""
  415. for idx, b in enumerate(ct):
  416. if idx % 8 == 0:
  417. ct_arr += '\n'
  418. ct_arr += "0x{}, ".format(binascii.hexlify(b))
  419. print(ct_arr)
  420. */
  421. #ifdef CONFIG_SPIRAM_USE_MALLOC
  422. const uint8_t expected_cipher_psram_end[] = {
  423. 0x7e, 0xdf, 0x13, 0xf3, 0x56, 0xef, 0x67, 0x01,
  424. 0xfc, 0x08, 0x49, 0x62, 0xfa, 0xfe, 0x0c, 0x8b,
  425. 0x99, 0x39, 0x09, 0x51, 0x2c, 0x9a, 0xd5, 0x48,
  426. 0x4f, 0x76, 0xa2, 0x19, 0x2c, 0x08, 0x9d, 0x6a,
  427. };
  428. void aes_psram_ctr_test(uint32_t input_buf_caps, uint32_t output_buf_caps)
  429. {
  430. mbedtls_aes_context ctx;
  431. uint8_t nonce[16];
  432. uint8_t key[16];
  433. uint8_t stream_block[16];
  434. size_t SZ = 6000;
  435. size_t ALIGNMENT_SIZE_BYTES = 16;
  436. memset(nonce, 0x2F, 16);
  437. memset(key, 0x1E, 16);
  438. // allocate memory according the requested caps
  439. uint8_t *chipertext = heap_caps_malloc(SZ + ALIGNMENT_SIZE_BYTES, output_buf_caps);
  440. uint8_t *plaintext = heap_caps_malloc(SZ + ALIGNMENT_SIZE_BYTES, input_buf_caps);
  441. uint8_t *decryptedtext = heap_caps_malloc(SZ, MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL);
  442. TEST_ASSERT_NOT_NULL(chipertext);
  443. TEST_ASSERT_NOT_NULL(plaintext);
  444. TEST_ASSERT_NOT_NULL(decryptedtext);
  445. mbedtls_aes_init(&ctx);
  446. mbedtls_aes_setkey_enc(&ctx, key, 128);
  447. memset(plaintext, 0x26, SZ + ALIGNMENT_SIZE_BYTES);
  448. size_t offset;
  449. /* Shift buffers and test for all different misalignments */
  450. for (int i = 0; i < ALIGNMENT_SIZE_BYTES; i++ ) {
  451. // Encrypt with input buffer in external ram
  452. offset = 0;
  453. memset(nonce, 0x2F, 16);
  454. mbedtls_aes_crypt_ctr(&ctx, SZ, &offset, nonce, stream_block, plaintext + i, chipertext + i);
  455. TEST_ASSERT_EQUAL_HEX8_ARRAY(expected_cipher_psram_end, chipertext + i + SZ - 32, 32);
  456. // Decrypt
  457. offset = 0;
  458. memset(nonce, 0x2F, 16);
  459. // Decrypt with input buffer in instruction memory, the crypto DMA can't access this
  460. mbedtls_aes_crypt_ctr(&ctx, SZ, &offset, nonce, stream_block, chipertext + i, decryptedtext);
  461. TEST_ASSERT_EQUAL_HEX8_ARRAY(plaintext, decryptedtext, SZ);
  462. }
  463. free(plaintext);
  464. free(chipertext);
  465. free(decryptedtext);
  466. }
  467. void aes_psram_one_buf_ctr_test(void)
  468. {
  469. mbedtls_aes_context ctx;
  470. uint8_t nonce[16];
  471. uint8_t key[16];
  472. uint8_t stream_block[16];
  473. size_t SZ = 6000;
  474. size_t ALIGNMENT_SIZE_BYTES = 16;
  475. memset(nonce, 0x2F, 16);
  476. memset(key, 0x1E, 16);
  477. // allocate external memory
  478. uint8_t *buf = heap_caps_malloc(SZ + ALIGNMENT_SIZE_BYTES, MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM);
  479. TEST_ASSERT_NOT_NULL(buf);
  480. mbedtls_aes_init(&ctx);
  481. mbedtls_aes_setkey_enc(&ctx, key, 128);
  482. memset(buf, 0x26, SZ + ALIGNMENT_SIZE_BYTES);
  483. size_t offset;
  484. /* Shift buffers and test for all different misalignments */
  485. for (int i = 0; i < ALIGNMENT_SIZE_BYTES; i++ ) {
  486. // Encrypt with input buffer in external ram
  487. offset = 0;
  488. memset(buf, 0x26, SZ + ALIGNMENT_SIZE_BYTES);
  489. memset(nonce, 0x2F, 16);
  490. mbedtls_aes_crypt_ctr(&ctx, SZ, &offset, nonce, stream_block, buf + i, buf + i);
  491. TEST_ASSERT_EQUAL_HEX8_ARRAY(expected_cipher_psram_end, buf + i + SZ - 32, 32);
  492. // Decrypt
  493. offset = 0;
  494. memset(nonce, 0x2F, 16);
  495. // Decrypt with input buffer in instruction memory, the crypto DMA can't access this
  496. mbedtls_aes_crypt_ctr(&ctx, SZ, &offset, nonce, stream_block, buf + i, buf);
  497. TEST_ASSERT_EACH_EQUAL_HEX8(0x26, buf + i, SZ - i);
  498. }
  499. free(buf);
  500. }
  501. const uint8_t long_input[] = {
  502. 0xf7, 0xe6, 0x6b, 0x8d, 0x2e, 0xbf, 0x88, 0xd6,
  503. 0xb0, 0x77, 0xdf, 0x72, 0xbf, 0xa8, 0x0, 0x55,
  504. 0xd5, 0xd1, 0x49, 0xa3, 0x2c, 0xc, 0xfe, 0xdb,
  505. 0x17, 0x37, 0xa4, 0x1d, 0x70, 0x6b, 0x99, 0xf5,
  506. 0x9e, 0x6, 0xad, 0x6c, 0xe0, 0x3b, 0xfa, 0x50,
  507. 0x28, 0xb2, 0x62, 0xf2, 0x99, 0x3a, 0xcc, 0xe4,
  508. 0x86, 0x5f, 0x1, 0xf8, 0x69, 0xd7, 0xf5, 0xb2,
  509. 0x8a, 0x5f, 0x5c, 0x38, 0x9f, 0x8a, 0xb8, 0x8c,
  510. 0xea, 0x6, 0xe1, 0x68, 0xff, 0xaf, 0x5d, 0xd9,
  511. 0x1f, 0xa5, 0x5c, 0x8c, 0x52, 0xa1, 0x5f, 0x45,
  512. 0x55, 0xcb, 0x76, 0x59, 0x8f, 0xfe, 0x36, 0xd0,
  513. 0x85, 0x1f, 0x8, 0x90, 0x6f, 0x62, 0xb1, 0x1a,
  514. 0xde, 0x75, 0xab, 0x90, 0xb7, 0x75, 0xe9, 0xa0,
  515. 0xa9, 0xb0, 0xac, 0x61, 0x5, 0x6d, 0x9a, 0xe3,
  516. 0x3b, 0x43, 0x61, 0x13, 0x8c, 0x3a, 0xa0, 0xaa,
  517. 0x91, 0xea, 0x3e, 0xe1, 0x87, 0x35, 0xff, 0x90,
  518. 0xe2, 0x43, 0xa3, 0x70, 0x57, 0x65, 0x2d, 0xa2,
  519. 0x65, 0xe6, 0xde, 0xb0, 0x52, 0x85, 0x5b, 0xb8,
  520. 0x3, 0x8, 0x63, 0x8b, 0xa1, 0xc2, 0xe1, 0x35,
  521. 0x2e, 0xba, 0xe0, 0x84, 0x56, 0x52, 0x5f, 0x12,
  522. 0xd3, 0x22, 0x8d, 0xa5, 0xbb, 0xe1, 0xd3, 0xfc,
  523. 0x18, 0x1c, 0x90, 0x3b, 0x79, 0xe, 0xab, 0x2d,
  524. 0x5e, 0xb0, 0x7, 0xbb, 0x46, 0x73, 0x1d, 0x35,
  525. 0xd9, 0xc5, 0xa7, 0x87, 0x80, 0xf7, 0xee, 0x29,
  526. 0xb5, 0x17, 0xf3, 0xaf, 0x30, 0xe5, 0x19, 0x50,
  527. 0xf9, 0x5d, 0x2b, 0xc3, 0xc0, 0xda, 0x8f, 0xca,
  528. 0x3c, 0x4d, 0xd5, 0xd7, 0x6c, 0xd2, 0x36, 0xa4,
  529. 0x22, 0x8, 0x66, 0x48, 0x31, 0xb4, 0x3d, 0xc2,
  530. 0xf6, 0x6b, 0xce, 0xf0, 0x12, 0xe4, 0x38, 0x5c,
  531. 0xd8, 0x71, 0xea, 0x30, 0x52, 0xdf, 0x34, 0x62,
  532. 0xdc, 0xb4, 0x30, 0xe, 0x74, 0xc, 0x5, 0x14,
  533. 0xf, 0x47, 0x25, 0x5, 0x72, 0xc9, 0x14, 0x7c,
  534. 0x1f, 0x6e, 0xdb, 0x6f, 0x83, 0x6, 0xa0, 0xb2,
  535. 0x7f, 0x29, 0xe6, 0xb6, 0xe3, 0x11, 0x23, 0x4b,
  536. 0x68, 0x92, 0xa, 0x49, 0xb5, 0x9d, 0x5d, 0x39,
  537. 0x90, 0xff, 0x9, 0xa0, 0xa, 0x69, 0x6b, 0x2,
  538. 0x18, 0xfb, 0xca, 0x5a, 0x91, 0x1a, 0xd9, 0x19,
  539. 0x6b, 0xd4, 0x92, 0xd3, 0xd9, 0x7, 0xce, 0xcb,
  540. 0xc7, 0xf3, 0xa1, 0x33, 0xcd, 0xa9, 0xb1, 0x44,
  541. 0x8c, 0x93, 0xcd, 0xac, 0xc1, 0x44, 0x12, 0x48,
  542. 0x95, 0x3, 0xdf, 0xc, 0x2f, 0xfc, 0x34, 0x8d,
  543. 0x3, 0xde, 0xc1, 0xed, 0xdc, 0xf0, 0xfa, 0xa5,
  544. 0xb2, 0x62, 0xcd, 0xa2, 0xbf, 0xf7, 0x7e, 0x47,
  545. 0xb6, 0xcc, 0xe4, 0xa6, 0x4e, 0x51, 0xc6, 0x34,
  546. 0xee, 0x83, 0x21, 0xb7, 0xc2, 0xe3, 0x13, 0x92,
  547. 0xfc, 0xc9, 0x6, 0x6b, 0x91, 0x76, 0x7b, 0x2e,
  548. 0x1e, 0xa2, 0xe0, 0x17, 0xab, 0x10, 0xfa, 0xac,
  549. 0xd1, 0x2, 0x33, 0xb0, 0xd3, 0x3d, 0xb9, 0xce,
  550. 0xea, 0xe9, 0x93, 0x5c, 0x98, 0x14, 0x0, 0xc6,
  551. 0x2c, 0xa6, 0xdb, 0x1f, 0xdc, 0x76, 0xfb, 0xeb,
  552. 0x9d, 0x55, 0xa6, 0x5f, 0xd5, 0x8e, 0x13, 0x39,
  553. 0x88, 0x58, 0xff, 0xe8, 0xb4, 0x98, 0x9e, 0x4b,
  554. 0xe7, 0x46, 0xdc, 0x7a, 0x68, 0x5b, 0xa8, 0xc2,
  555. 0xe5, 0xa9, 0x50, 0xe2, 0x8, 0x31, 0x6, 0x3e,
  556. 0x8e, 0xaf, 0x80, 0x24, 0x4e, 0xbd, 0x73, 0x6d,
  557. 0xd9, 0x4b, 0xb4, 0x3e, 0x84, 0x5e, 0x31, 0x8e,
  558. 0xf7, 0xa8, 0x9b, 0x5e, 0x2c, 0xd5, 0xe9, 0x7c,
  559. 0xca, 0xca, 0xfa, 0x8e, 0x87, 0xbf, 0xf5, 0xa3,
  560. 0x2f, 0x73, 0x2f, 0xc0, 0x5f, 0x46, 0xf4, 0x2,
  561. 0xfd, 0xd1, 0x23, 0x6f, 0xc2, 0xc1, 0xc0, 0x86,
  562. 0x62, 0x43, 0xc3, 0x44, 0x3b, 0x2c, 0x3d, 0xc2,
  563. 0xd5, 0xe0, 0x2, 0xae, 0x1, 0x5a, 0x9, 0x89,
  564. 0x52, 0x34, 0xdf, 0xb1, 0x6c, 0x2b, 0x85, 0x77,
  565. 0xa5, 0x83, 0xe3, 0xa5, 0x50, 0x13, 0x2f, 0xf3,
  566. 0xa6, 0x83, 0x60, 0x33, 0xba, 0xd5, 0xd2, 0x96,
  567. 0x8a, 0xcd, 0xee, 0xfa, 0x76, 0x2a, 0x63, 0xec,
  568. 0x41, 0x3a, 0xf3, 0xe5, 0x9e, 0x1d, 0x5e, 0x46,
  569. 0x8, 0xd7, 0xe2, 0x3a, 0x25, 0x6f, 0x37, 0x7e,
  570. 0x0, 0x2d, 0x3d, 0x1b, 0x86, 0xf4, 0xbe, 0x0,
  571. 0x3c, 0xda, 0x82, 0x4a, 0xa3, 0x8, 0x2a, 0x38,
  572. 0x95, 0xe, 0x38, 0xf8, 0x18, 0x6c, 0x42, 0x6f,
  573. 0x30, 0x19, 0x8e, 0x22, 0xf6, 0xb7, 0x18, 0xb7,
  574. 0x93, 0xd, 0x54, 0x72, 0x4, 0x64, 0xc1, 0x19,
  575. 0x76, 0x6e, 0xfc, 0x9e, 0xb0, 0x7c, 0x20, 0x37,
  576. 0xb0, 0xcb, 0x82, 0x3a, 0x20, 0x1d, 0x12, 0x44,
  577. 0xbf, 0x44, 0xc4, 0x4d, 0x33, 0x7e, 0x7b, 0xeb,
  578. 0xd8, 0xb8, 0xa1, 0x75, 0x9e, 0x47, 0x99, 0x64,
  579. 0x92, 0xd3, 0x21, 0x1d, 0x72, 0x63, 0xc7, 0xb3,
  580. 0x3d, 0xfc, 0xb9, 0x4, 0x65, 0x18, 0x94, 0xcc,
  581. 0x20, 0xfe, 0x6f, 0x66, 0x36, 0xba, 0x36, 0x2a,
  582. 0x7, 0xf0, 0x5e, 0x8a, 0xf2, 0x7, 0x1e, 0x9e,
  583. 0x47, 0x2a, 0xc3, 0x7d, 0x7a, 0x20, 0x3c, 0x30,
  584. 0x6f, 0xbe, 0x43, 0x5e, 0x71, 0x6f, 0xd, 0xb8,
  585. 0x3d, 0x1d, 0x3e, 0x18, 0x65, 0x62, 0x75, 0xe8,
  586. 0x34, 0xfd, 0x72, 0xbb, 0xd9, 0x3f, 0xf0, 0xa2,
  587. 0x55, 0xee, 0x91, 0x12, 0x88, 0xda, 0x7, 0x3d,
  588. 0x44, 0x88, 0x70, 0x1f, 0xe0, 0xbe, 0x4b, 0x88,
  589. 0xa8, 0x8e, 0x28, 0x7, 0x73, 0xfd, 0x3f, 0xff,
  590. 0x3e, 0xb2, 0xb5, 0xdb, 0x18, 0x48, 0x9e, 0x73,
  591. 0x6e, 0xd7, 0x24, 0xa9, 0x25, 0xdb, 0x4, 0xe0,
  592. 0xe0, 0xf4, 0x45, 0xc0, 0x1b, 0x82, 0xdf, 0x4e,
  593. 0x48, 0x60, 0x85, 0x9c, 0xd8, 0x90, 0x32, 0xca,
  594. 0x4b, 0xf9, 0xb4, 0xb8, 0xe1, 0xfe, 0xd2, 0xe0,
  595. 0xb2, 0xd6, 0xb8, 0x19, 0x38, 0x34, 0x17, 0x8d,
  596. 0x5e, 0xdf, 0xf4, 0xf1, 0xac, 0x2c, 0x88, 0x7f,
  597. 0x54, 0xbc, 0xf1, 0x39, 0xf2, 0xaf, 0x5a, 0xff,
  598. 0xa7, 0x96, 0x0, 0xf0, 0x27, 0x79, 0x27, 0x2e,
  599. 0x9c, 0xf1, 0x4b, 0xa3, 0xad, 0xdc, 0x8a, 0x2c,
  600. 0x9, 0x4c, 0xd3, 0xcd, 0xd0, 0x2d, 0xb1, 0xec,
  601. 0x4d, 0x68, 0x40, 0xb8, 0xc5, 0x5, 0xfa, 0xb2,
  602. 0x61, 0xb8, 0x31, 0x5, 0xea, 0xb8, 0xa3, 0x34,
  603. 0xa8, 0x8b, 0x3, 0x5b, 0x22, 0x93, 0xba, 0x91,
  604. 0x33, 0x3f, 0x8b, 0x5e, 0xed, 0x86, 0x23, 0x95,
  605. 0xbc, 0x9e, 0xdf, 0xa9, 0x8c, 0xca, 0xb9, 0x97,
  606. 0x9b, 0xc5, 0xca, 0xf4, 0xff, 0x4d, 0x62, 0x52,
  607. 0x1c, 0xd3, 0x4c, 0x42, 0xbf, 0x8a, 0x25, 0x47,
  608. 0xc7, 0x9, 0x4e, 0xe0, 0xb1, 0x72, 0x7d, 0x2,
  609. 0x8f, 0xca, 0x4f, 0x4, 0xc8, 0x74, 0x82, 0x8e,
  610. 0x53, 0xfd, 0xa1, 0x37, 0xda, 0x29, 0x5c, 0xa3,
  611. 0x83, 0xe9, 0xa8, 0xd8, 0x25, 0x27, 0xfe, 0xf7,
  612. 0x41, 0xc4, 0xb0, 0xee, 0x1d, 0x89, 0x1c, 0xe7,
  613. 0xef, 0x86, 0x68, 0xd8, 0x87, 0x4c, 0x4f, 0x49,
  614. 0xeb, 0xbc, 0xb3, 0x81, 0xa7, 0xf4, 0xb4, 0x9b,
  615. 0xc1, 0x52, 0x93, 0x7e, 0xdf, 0x75, 0x75, 0xfc,
  616. 0x45, 0xb2, 0x86, 0xa9, 0x50, 0xb5, 0xa3, 0xf7,
  617. 0x61, 0x60, 0xe4, 0x13, 0x99, 0xc0, 0xf8, 0x49,
  618. 0x7b, 0x61, 0x8b, 0xa8, 0xfa, 0x77, 0x0, 0xe4,
  619. 0x6, 0x9a, 0xc5, 0x51, 0xe4, 0xeb, 0xaf, 0x5f,
  620. 0xb9, 0x5c, 0x74, 0xc8, 0xf8, 0x3e, 0x62, 0x26,
  621. 0xe, 0xe5, 0x85, 0xca, 0x49, 0xa0, 0x2f, 0xf7,
  622. 0x7, 0x99, 0x3e, 0x5c, 0xe0, 0x72, 0xfa, 0xd4,
  623. 0x80, 0x2e, 0xd6, 0x40, 0x6, 0xde, 0x5f, 0xc5,
  624. 0xc5, 0x1, 0xd, 0xbf, 0xdb, 0xb6, 0xb3, 0x92,
  625. 0x76, 0xb3, 0x3f, 0x3d, 0x5d, 0x1, 0x23, 0xb8,
  626. 0xa, 0xcb, 0x80, 0x17, 0x31, 0x19, 0xc7, 0x64,
  627. 0x69, 0xf1, 0x99, 0x53, 0xe5, 0xf2, 0x9f, 0x9d,
  628. 0x3c, 0xda, 0xcb, 0xa6, 0x94, 0x94, 0x44, 0xd3,
  629. 0xc6, 0x8b, 0xb5, 0xae, 0x45, 0x25, 0xef, 0x2a,
  630. 0x24, 0x1, 0x3a, 0xf6, 0xf, 0xe, 0xcb, 0x10,
  631. 0xc4, 0xe0, 0xf4, 0x3d, 0xf4, 0xf5, 0xea, 0x9b,
  632. 0xd1, 0x16, 0x1b, 0x62, 0x11, 0x3e, 0x20, 0x3a,
  633. 0x68, 0xc8, 0xf0, 0xe, 0x55, 0xbe, 0x51, 0x4d,
  634. 0xbe, 0x1f, 0x4f, 0xda, 0x84, 0xda, 0xc4, 0x9e,
  635. 0x24, 0xd7, 0x46, 0x82, 0x56, 0x4e, 0x61, 0x63,
  636. 0xda, 0x18, 0xea, 0xc6, 0xc3, 0x21, 0x89, 0x18,
  637. 0xe, 0x87, 0xb7, 0x91, 0xfe, 0x8d, 0xe, 0xac,
  638. 0x75, 0x58, 0xe5, 0x9f, 0x1f, 0x93, 0xa6, 0x49,
  639. 0x24, 0xa2, 0xc6, 0xe8, 0x9d, 0x9c, 0x6d, 0xc1,
  640. 0xf, 0xfc, 0xe3, 0x57, 0xd3, 0xc2, 0x10, 0x91,
  641. 0x9a, 0xa8, 0xaa, 0xd7, 0xf, 0xaa, 0x75, 0x90,
  642. 0x4a, 0x10, 0xef, 0xb6, 0xdd, 0x6c, 0xd5, 0x1a,
  643. 0xe3, 0xbb, 0xe0, 0x64, 0x44, 0xc, 0x59, 0xa1,
  644. 0xef, 0x3, 0x52, 0xac, 0xa4, 0x85, 0x3e, 0x40,
  645. 0xee, 0x5c, 0xef, 0xcf, 0xb1, 0xaa, 0x88, 0xe5,
  646. 0x56, 0xb8, 0xcd, 0x87, 0xc7, 0xc6, 0xd3, 0xb4,
  647. 0x85, 0x8f, 0x2a, 0xc9, 0xcd, 0x8a, 0x8b, 0x25,
  648. 0x12, 0x71, 0x76, 0xc9, 0xaa, 0x62, 0x75, 0x80,
  649. 0x6e, 0xa3, 0xf9, 0xa5, 0xfc, 0x90, 0xac, 0x28,
  650. 0x13, 0x82, 0xbb, 0x5d, 0xa6, 0x93, 0x47, 0xd4,
  651. 0xf, 0x3b, 0x19, 0xf6, 0x81, 0xdb, 0x55, 0xb0,
  652. 0x47, 0x75, 0x63, 0x93, 0xb4, 0xdd, 0xf0, 0xaf,
  653. 0xb7, 0x44, 0xcb, 0x7, 0x7b, 0x35, 0xc5, 0xe4,
  654. 0x45, 0xfe, 0xbb, 0x11, 0x1a, 0x90, 0x96, 0x3a,
  655. 0x7, 0x2a, 0xef, 0x9c, 0xc, 0xae, 0x38, 0x26,
  656. 0xef, 0xc2, 0xc3, 0x53, 0xfa, 0x54, 0xcf, 0x6f,
  657. 0xf7, 0xa, 0xea, 0x19, 0xa8, 0xf, 0xbd, 0xa7,
  658. 0x3f, 0xcd, 0x38, 0x2c, 0xf3, 0x97, 0xfb, 0xdb,
  659. 0xcb, 0xc5, 0x83, 0x80, 0x91, 0x3d, 0xc7, 0x29,
  660. 0x67, 0x16, 0xa5, 0xd1, 0x41, 0xd0, 0xa1, 0x9b,
  661. 0xde, 0x13, 0x83, 0x12, 0x36, 0x75, 0x81, 0x71,
  662. 0x6b, 0xbc, 0x72, 0xcb, 0x37, 0x4, 0x6, 0x7c,
  663. 0x3a, 0x22, 0x2b, 0xa, 0x11, 0xd3, 0x33, 0x8f,
  664. 0x3, 0x54, 0x8e, 0x79, 0xb6, 0x36, 0x93, 0x92,
  665. 0xb8, 0xf, 0x24, 0x4a, 0xd3, 0xd5, 0x27, 0x66,
  666. 0xd1, 0xde, 0xe3, 0xaa, 0x4b, 0x2a, 0xe9, 0x22,
  667. 0x9b, 0xbf, 0x6e, 0x9a, 0xf7, 0xa, 0x2f, 0x24,
  668. 0x13, 0xd5, 0xd5, 0xbb, 0xa3, 0xba, 0x8f, 0xfc,
  669. 0x28, 0xa8, 0xbe, 0xe6, 0x9f, 0xea, 0xed, 0xb1,
  670. 0xba, 0xaf, 0xf, 0x1c, 0x1e, 0x51, 0xf8, 0xd7,
  671. 0x1b, 0xa5, 0xa6, 0x63, 0x40, 0x6e, 0x3f, 0xa2,
  672. 0x57, 0x6f, 0x57, 0xe4, 0x27, 0xc2, 0x3c, 0x33,
  673. 0xc6, 0x9c, 0x24, 0xd0, 0x53, 0xc4, 0xfc, 0xed,
  674. 0x8e, 0x1d, 0xf, 0xc3, 0x86, 0x9, 0x3d, 0x1d,
  675. 0xc2, 0xdb, 0x24, 0x1a, 0x65, 0xf4, 0x30, 0xa5,
  676. 0xc, 0x48, 0x37, 0xc5, 0x53, 0x35, 0x3b, 0xab,
  677. 0xd, 0x96, 0x30, 0xd7, 0x1d, 0x66, 0x18, 0xc2,
  678. 0x47, 0x3a, 0xef, 0xbe, 0x2e, 0xe4, 0x54, 0x9d,
  679. 0xc4, 0xa5, 0xb9, 0xb3, 0x4c, 0x12, 0x73, 0x35,
  680. 0xf0, 0x7, 0xe, 0x36, 0x88, 0xb2, 0x4b, 0x29,
  681. 0xb, 0x4e, 0x84, 0x11, 0xaa, 0x9a, 0x3e, 0xb1,
  682. 0xd7, 0xec, 0xfb, 0x7f, 0x10, 0x70, 0x1f, 0x26,
  683. 0xf0, 0x27, 0x46, 0x5d, 0x4, 0x51, 0x97, 0x29,
  684. 0xb4, 0x66, 0x39, 0x1, 0x82, 0x47, 0xd8, 0x5f,
  685. 0xa9, 0xb3, 0xa1, 0xb8, 0xde, 0x1, 0xe1, 0xc4,
  686. 0x47, 0xc5, 0xe8, 0xe6, 0xbb, 0xc0, 0xb6, 0x41,
  687. 0x55, 0x10, 0x79, 0xa8, 0xd0, 0xd, 0x1, 0x56,
  688. 0x29, 0x6c, 0xa5, 0x96, 0x87, 0x59, 0x4b, 0xd,
  689. 0xc8, 0x3, 0x5, 0xaa, 0xa9, 0x6a, 0xb1, 0x10,
  690. 0xbc, 0x1, 0x68, 0xd3, 0xa5, 0x52, 0x41, 0xe1,
  691. 0x1f, 0x53, 0x7, 0xc6, 0xad, 0xb8, 0xc4, 0xf0,
  692. 0x28, 0xe9, 0x3, 0x3a, 0xee, 0xce, 0x2c, 0xe2,
  693. 0xb0, 0xda, 0x78, 0x3d, 0x37, 0x7, 0x2d, 0x1f,
  694. 0xf1, 0x47, 0x81, 0x4, 0x67, 0x6e, 0xd, 0xa1,
  695. 0x2b, 0x4, 0xe8, 0xd9, 0xf4, 0xaf, 0x35, 0xca,
  696. 0xa5, 0xd1, 0xe3, 0xec, 0xc5, 0x82, 0x50, 0x99,
  697. 0x9a, 0xee, 0xea, 0x53, 0x41, 0x86, 0x97, 0x44,
  698. 0xeb, 0x58, 0x43, 0x47, 0xe7, 0xa0, 0xd3, 0x28,
  699. 0xfc, 0xe7, 0x13, 0x8b, 0x56, 0xe3, 0xdb, 0xa9,
  700. 0xcd, 0x9, 0xc8, 0x7, 0x11, 0xeb, 0xbf, 0xac,
  701. 0x76, 0x72, 0x60, 0xaf, 0x9c, 0xba, 0x8a, 0x64,
  702. 0xfb, 0xf4, 0xab, 0x27, 0x29, 0xe7, 0xec, 0x69,
  703. 0x21, 0xcb, 0x5b, 0x79, 0x56, 0x10, 0xc1, 0x8,
  704. 0xd5, 0x5d, 0x93, 0xb1, 0x70, 0x88, 0xf2, 0x19,
  705. 0x41, 0xc6, 0xc2, 0x84, 0xdd, 0xf0, 0xb3, 0x40,
  706. 0x12, 0x71, 0x24, 0x54, 0xc4, 0x5e, 0xfb, 0x5f,
  707. 0x47, 0x8c, 0xa9, 0x4, 0x5a, 0xd5, 0x61, 0x19,
  708. 0xb5, 0x7f, 0xc9, 0xbd, 0x87, 0xb2, 0xcd, 0x57,
  709. 0x99, 0x50, 0x67, 0x1d, 0xb0, 0x1d, 0x82, 0xdd,
  710. 0xef, 0x32, 0x38, 0xb9, 0xc7, 0x86, 0xb4, 0xd2,
  711. 0xd6, 0xe1, 0x33, 0xb2, 0xdb, 0x5e, 0xc2, 0xa3,
  712. 0x49, 0xa6, 0x5f, 0x79, 0x32, 0x50, 0x41, 0x5b,
  713. 0xd7, 0x87, 0x74, 0xf5, 0xc9, 0x9c, 0x78, 0xb7,
  714. 0xb, 0x1f, 0x72, 0xba, 0xd9, 0x3a, 0x4d, 0x18,
  715. 0x45, 0x1d, 0xad, 0xef, 0xc4, 0xdc, 0x30, 0xe8,
  716. 0x2, 0xb1, 0x7f, 0x6c, 0x8f, 0xaa, 0xd0, 0x40,
  717. 0x17, 0xe, 0x58, 0x93, 0x42, 0x49, 0x63, 0x77,
  718. 0x48, 0x55, 0x90, 0x2f, 0x7c, 0x3b, 0xee, 0x3c,
  719. 0xac, 0xd, 0xd8, 0x72, 0x23, 0xd7, 0xa5, 0x6e,
  720. 0xb0, 0xd2, 0x91, 0x25, 0x60, 0x9a, 0x52, 0xab,
  721. 0xbd, 0x63, 0xce, 0xba, 0xda, 0xb1, 0xd7, 0xc7,
  722. 0x3d, 0x21, 0x4e, 0x9c, 0x5a, 0x1e, 0x8d, 0xf4,
  723. 0xa, 0xdb, 0xd9, 0xf, 0x20, 0x7e, 0xfb, 0xbf,
  724. 0x36, 0x9c, 0x4f, 0xbd, 0xf7, 0xdb, 0x5b, 0xa2,
  725. 0x6, 0xb2, 0x0, 0xe2, 0xa2, 0x9e, 0x4e, 0x19,
  726. 0xd4, 0x69, 0xa9, 0x51, 0x69, 0x8b, 0xf5, 0xe1,
  727. 0xad, 0x89, 0x8, 0xc5, 0x4f, 0xac, 0x1b, 0x7d,
  728. 0xe7, 0xa, 0x9, 0x7d, 0x34, 0xf5, 0x3f, 0x46,
  729. 0x80, 0xb9, 0xb9, 0x45, 0x58, 0xcd, 0x6c, 0xb5,
  730. 0x5f, 0x60, 0xeb, 0x5a, 0xe3, 0xa3, 0x8, 0x5e,
  731. 0xb1, 0xc4, 0x73, 0xc5, 0xa5, 0x67, 0x56, 0xd3,
  732. 0xc6, 0x8a, 0x55, 0x6b, 0xd7, 0xd7, 0xc, 0x20,
  733. 0xe6, 0xc, 0x73, 0x8, 0x2, 0x4b, 0xfb, 0xdd,
  734. 0x4d, 0x4e, 0xa8, 0xb8, 0xd8, 0x4b, 0x53, 0x2f,
  735. 0xc2, 0xfb, 0x5d, 0xa1, 0x6a, 0x16, 0x6b, 0xe,
  736. 0xf1, 0xa1, 0xa5, 0x5b, 0xdf, 0x9c, 0x23, 0xb5,
  737. 0x94, 0x9c, 0xae, 0x7b, 0xbe, 0x42, 0xb5, 0x79,
  738. 0x80, 0xc3, 0x43, 0x41, 0xa4, 0x1b, 0x18, 0xfc,
  739. 0x52, 0xcf, 0x43, 0xc5, 0x80, 0x7b, 0xbd, 0xc1,
  740. 0x20, 0x5e, 0x65, 0xec, 0xc5, 0xfc, 0x3, 0xec,
  741. 0x8f, 0x61, 0x66, 0xf5, 0x15, 0x67, 0xc8, 0xb6,
  742. 0xef, 0x9a, 0xba, 0xb7, 0xcb, 0x2c, 0xac, 0x1b,
  743. 0x50, 0xda, 0xb6, 0x29, 0xa4, 0x37, 0xe9, 0x96,
  744. 0xa0, 0x7, 0x7d, 0x49, 0xa6, 0xce, 0xf3, 0xf0,
  745. 0x19, 0xdf, 0x61, 0xc7, 0xa4, 0x7b, 0x5a, 0xd4,
  746. 0x99, 0xb2, 0x64, 0xe7, 0xd1, 0x6b, 0x7f, 0xe8,
  747. 0xb8, 0xd3, 0x89, 0xee, 0x96, 0xc0, 0xed, 0x5d,
  748. 0x7e, 0x48, 0x2, 0xd2, 0x25, 0xd0, 0x5, 0xef,
  749. 0x93, 0x72, 0x7c, 0x8c, 0xbd, 0x6e, 0x49, 0xd3,
  750. 0x38, 0x46, 0x1c, 0xff, 0x28, 0x4e, 0x1b, 0xad,
  751. 0x39, 0x2f, 0x65, 0x26, 0xe2, 0x70, 0x3d, 0xb8,
  752. 0x7a, 0xd3, 0x38, 0x38, 0xfc, 0x3a, 0x67, 0x78,
  753. 0xdb, 0x9, 0xcb, 0xbf, 0xc9, 0xe1, 0xee, 0x69,
  754. 0x2b, 0xd, 0xb1, 0x79, 0x13, 0xd0, 0xa5, 0x75,
  755. 0x6, 0x8, 0x79, 0xa7, 0x7c, 0xc, 0xe7, 0x1b,
  756. 0x9c, 0x36, 0x64, 0xbe, 0x20, 0x65, 0xa2, 0xd4,
  757. 0xd9, 0xc, 0x68, 0xe, 0x88, 0x2b, 0x93, 0x60,
  758. 0xf1, 0xa5, 0x82, 0xc5, 0x4d, 0x2b, 0x7d, 0x73,
  759. 0xe9, 0x13, 0x8c, 0xc1, 0x8, 0xbd, 0x21, 0x65,
  760. 0x77, 0x2f, 0x34, 0xb1, 0x97, 0x9f, 0xd8, 0x55,
  761. 0xcf, 0x75, 0xc2, 0xf2, 0x41, 0x68, 0xc1, 0x9c,
  762. 0x1c, 0xd7, 0x23, 0xbf, 0x83, 0x2a, 0x9, 0x66,
  763. 0xce, 0x8f, 0xd2, 0x12, 0x79, 0x93, 0xef, 0x8,
  764. 0x9b, 0xeb, 0x2f, 0xc, 0xe4, 0x5b, 0x71, 0x1a,
  765. 0xef, 0x11, 0x65, 0xd8, 0x6d, 0x8c, 0x59, 0x53,
  766. 0x70, 0x1d, 0xb5, 0x81, 0xff, 0xc0, 0x7d, 0x87,
  767. 0xa5, 0x21, 0x5d, 0x9f, 0x63, 0xb2, 0xe7, 0xe9,
  768. 0xd0, 0x49, 0x41, 0xc7, 0x3c, 0xe1, 0x2b, 0xb1,
  769. 0xac, 0x15, 0xcd, 0xb0, 0xa8, 0xdc, 0xae, 0x3b,
  770. 0xef, 0x32, 0x98, 0x8c, 0xc7, 0x40, 0xa6, 0x81,
  771. 0x1, 0xa1, 0x7d, 0x89, 0x46, 0x99, 0x91, 0x24,
  772. 0xce, 0xb2, 0x70, 0x82, 0x92, 0xf3, 0x60, 0x66,
  773. 0x34, 0x6, 0x37, 0xad, 0x5c, 0xed, 0xc3, 0x27,
  774. 0x68, 0x8c, 0x56, 0xe7, 0xf, 0x73, 0x5c, 0x7e,
  775. 0x9e, 0xd0, 0x8c, 0x99, 0x5a, 0xb1, 0x15, 0x98,
  776. 0xbb, 0x79, 0x9f, 0xd1, 0x69, 0xce, 0x76, 0x5,
  777. 0xcb, 0x8e, 0x18, 0xb3, 0x84, 0x65, 0xa9, 0x2,
  778. 0xbc, 0x43, 0x8b, 0x7e, 0xe9, 0xe2, 0xe6, 0x74,
  779. 0x31, 0x8d, 0xe7, 0xa2, 0x42, 0x8f, 0xca, 0x38,
  780. 0x59, 0x85, 0x25, 0x47, 0xd2, 0x86, 0x47, 0x9,
  781. 0xc2, 0x11, 0x2, 0x91, 0xe6, 0xf3, 0x47, 0xc2,
  782. 0x9c, 0x28, 0x2f, 0xbb, 0xac, 0xde, 0x9f, 0xd,
  783. 0xc2, 0x96, 0x4f, 0x43, 0xca, 0x32, 0xed, 0x34,
  784. 0xba, 0xad, 0xef, 0xbe, 0x68, 0xc7, 0xa2, 0x83,
  785. 0xaf, 0xe, 0xd3, 0x72, 0x52, 0xd1, 0x76, 0x3d,
  786. 0x9a, 0x98, 0x39, 0xf4, 0x3e, 0x14, 0x27, 0xff,
  787. 0xb2, 0x37, 0x23, 0xc5, 0x6d, 0x66, 0xef, 0xaa,
  788. 0xfe, 0xe7, 0xe4, 0x86, 0xa1, 0xe, 0x4e, 0x36,
  789. 0x64, 0xb1, 0x67, 0xf, 0x94, 0x6f, 0x77, 0xd5,
  790. 0xec, 0xe2, 0x5e, 0xc8, 0xe3, 0x64, 0x29, 0x92,
  791. 0xd, 0x20, 0x34, 0x9f, 0x19, 0x6e, 0x85, 0xf8,
  792. 0x48, 0x78, 0xb0, 0xf, 0x42, 0xb2, 0x8c, 0xea,
  793. 0xc2, 0x4d, 0xd3, 0x23, 0xb, 0x4d, 0x20, 0x33,
  794. 0xc7, 0x46, 0x0, 0x45, 0x37, 0xc6, 0xcb, 0xd0,
  795. 0xec, 0x11, 0xc6, 0x74, 0x91, 0x7d, 0x6b, 0x54,
  796. 0x56, 0x10, 0x8d, 0xd0, 0xce, 0xe8, 0x57, 0x3b,
  797. 0x83, 0xd8, 0x25, 0x51, 0x79, 0x48, 0xa, 0xa5,
  798. 0xc3, 0xe4, 0x65, 0x33, 0xb2, 0x89, 0xa6, 0x4c,
  799. 0xe8, 0xc8, 0x9e, 0xce, 0xea, 0x2a, 0x55, 0x40,
  800. 0xfc, 0x26, 0x29, 0xd4, 0x2d, 0x7e, 0xe1, 0xb1,
  801. 0x4d, 0x65, 0x1, 0xe9, 0x98, 0xc9, 0xf4, 0x69,
  802. 0x10, 0xd9, 0xa3, 0xf9, 0x34, 0xaf, 0x3c, 0x34,
  803. 0x64, 0x23, 0xde, 0xb8, 0x1c, 0x33, 0x18, 0x74,
  804. 0x67, 0xb4, 0x4a, 0x71, 0xa6, 0x89, 0x2, 0xfe,
  805. 0xf7, 0xf1, 0x32, 0xc7, 0x98, 0xad, 0xe5, 0x10,
  806. 0x98, 0x3c, 0x6c, 0xaf, 0x1f, 0x13, 0x3d, 0xcc,
  807. 0xfc, 0x3b, 0x67, 0x33, 0x34, 0xc9, 0x31, 0xcd,
  808. 0x3f, 0xd, 0x3c, 0x5a, 0xb6, 0xc2, 0x8, 0xea,
  809. 0xe2, 0xae, 0xdd, 0xfc, 0x6f, 0xca, 0xb5, 0x67,
  810. 0x11, 0xce, 0xd5, 0xda, 0x3a, 0x8b, 0x7, 0xf2,
  811. 0xc0, 0x9e, 0x78, 0x18, 0x92, 0x9f, 0x64, 0x26,
  812. 0x9f, 0x66, 0x62, 0x66, 0xa1, 0x7e, 0x3, 0xf5,
  813. 0xb9, 0xe6, 0x74, 0x20, 0x88, 0xb7, 0x7e, 0x62,
  814. 0x7a, 0x33, 0x21, 0x9, 0x9c, 0x91, 0x3b, 0x62,
  815. 0x9, 0x46, 0xd3, 0xd1, 0x1f, 0xc5, 0x3a, 0x8f,
  816. 0x69, 0x27, 0x2c, 0x7b, 0xec, 0xda, 0x79, 0xf1,
  817. 0xc9, 0xe9, 0x98, 0xd0, 0xa, 0xc9, 0xf6, 0x37,
  818. 0x28, 0xf8, 0xfc, 0xe, 0xdc, 0xf, 0xe9, 0x23,
  819. 0xf6, 0x84, 0x25, 0x96, 0x2c, 0x24, 0x14, 0xd7,
  820. 0xe2, 0x5e, 0x1c, 0x56, 0x7f, 0x99, 0x98, 0x62,
  821. 0x76, 0xcc, 0x84, 0x44, 0xd6, 0xb9, 0x47, 0x2b,
  822. 0x52, 0xfb, 0x42, 0x40, 0xf3, 0x63, 0xaf, 0xd4,
  823. 0x10, 0x5, 0xf9, 0x3b, 0xc8, 0x53, 0xa9, 0x45,
  824. 0xa4, 0x50, 0x41, 0x83, 0xe8, 0x4a, 0x9, 0xb6,
  825. 0xf1, 0x77, 0x70, 0xe3, 0x61, 0x30, 0xd8, 0x90,
  826. 0x49, 0x52, 0x4b, 0x4a, 0xf2, 0x66, 0x84, 0xaf,
  827. 0x71, 0x1, 0x40, 0x66, 0xf6, 0x3, 0xc9, 0x23,
  828. 0xb1, 0x1a, 0xc1, 0xb2, 0xf7, 0x35, 0x1a, 0xc9,
  829. 0x3a, 0x75, 0xb1, 0xa7, 0x4, 0xff, 0x69, 0xa,
  830. 0x90, 0x58, 0xd4, 0xf4, 0x16, 0x79, 0xe1, 0xae,
  831. 0x39, 0x9d, 0xbb, 0x32, 0x6b, 0x3, 0xe2, 0xf5,
  832. 0x73, 0x83, 0x7e, 0x3c, 0xf8, 0x29, 0xab, 0xcc,
  833. 0xdc, 0xf0, 0x13, 0xdb, 0x86, 0x28, 0x88, 0x8e,
  834. 0xde, 0x6a, 0x29, 0xf1, 0xea, 0x0, 0x83, 0x97,
  835. 0x1, 0x32, 0x5f, 0xaa, 0x5b, 0x1b, 0xe4, 0x87,
  836. 0xec, 0x90, 0x45, 0xc7, 0xc5, 0x6c, 0x11, 0x83,
  837. 0x95, 0xab, 0xdd, 0x71, 0x69, 0x24, 0xc, 0x5c,
  838. 0xc0, 0xf3, 0xc1, 0xb0, 0x5e, 0x1, 0x5e, 0x4,
  839. 0xa1, 0x6e, 0x6e, 0x7d, 0x3f, 0x6f, 0xbd, 0x5d,
  840. 0x9, 0x8f, 0x23, 0x53, 0x74, 0x4b, 0xa9, 0x53,
  841. 0xd2, 0x10, 0xa1, 0xc0, 0x8e, 0x18, 0xa, 0x2f,
  842. 0x88, 0x8d, 0x4b, 0xf8, 0xc2, 0x3d, 0xeb, 0x34,
  843. 0x23, 0xa, 0x80, 0xc, 0x69, 0x21, 0x3, 0xc1,
  844. 0x6f, 0xbe, 0xdf, 0xf6, 0x2c, 0x27, 0x77, 0xa2,
  845. 0xc5, 0x5c, 0x9, 0x54, 0x5d, 0x4a, 0x4c, 0xb,
  846. 0x6b, 0xb5, 0x88, 0x11, 0x42, 0x62, 0x39, 0x89,
  847. 0x9e, 0x36, 0xd3, 0x91, 0xf6, 0x70, 0x18, 0x35,
  848. 0x79, 0xaf, 0x73, 0xf3, 0x0, 0x75, 0x5a, 0xa3,
  849. 0xce, 0xf1, 0x42, 0x80, 0x19, 0x5e, 0x42, 0x56,
  850. 0x53, 0x85, 0xbb, 0xf4, 0x29, 0xac, 0x84, 0x1d,
  851. 0x97, 0x1, 0x1c, 0xc4, 0x58, 0xcb, 0x33, 0xc4,
  852. 0xdc, 0x1e, 0x59, 0x8f, 0x48, 0xa9, 0x59, 0xfd,
  853. 0xaf, 0xa3, 0x5c, 0x19, 0x17, 0x6b, 0x46, 0x2d,
  854. 0xab, 0x44, 0xa3, 0xcc, 0x1a, 0xaa, 0x23, 0x4e,
  855. 0x58, 0x37, 0x7b, 0x11, 0x14, 0xc2, 0xf1, 0xc9,
  856. 0x58, 0x99, 0xd3, 0x3c, 0xec, 0xb9, 0xbe, 0x17,
  857. 0x3c, 0x8d, 0x1c, 0x87, 0x9d, 0xe1, 0xb9, 0xad,
  858. 0x68, 0x36, 0xd5, 0xfc, 0x24, 0x9b, 0x34, 0x5,
  859. 0x26, 0xac, 0x15, 0x9f, 0xd6, 0x70, 0x74, 0x6c,
  860. 0x72, 0xf, 0x6, 0x6, 0x5a, 0xc, 0xc0, 0x78,
  861. 0x47, 0x8e, 0xcf, 0xf2, 0xce, 0x8, 0xe2, 0xa4,
  862. 0xc6, 0x7d, 0x2d, 0x70, 0x14, 0xe2, 0xc6, 0xfc,
  863. 0x63, 0x7a, 0x42, 0x8c, 0x45, 0xae, 0xe8, 0x3b,
  864. 0x30, 0x48, 0xda, 0x3e, 0x14, 0xb5, 0x8b, 0x10,
  865. 0xae, 0x56, 0xbd, 0x17, 0xdf, 0xcb, 0x63, 0xf5,
  866. 0xb, 0x2b, 0xd7, 0x34, 0x7c, 0x96, 0x43, 0xe9,
  867. 0x17, 0xd4, 0x53, 0x2b, 0x4e, 0xba, 0x61, 0x57,
  868. 0x92, 0xdb, 0xe8, 0x37, 0xf4, 0xa3, 0x59, 0x88,
  869. 0x74, 0xc2, 0x3c, 0x5d, 0x54, 0x30, 0xb9, 0x6,
  870. 0xbe, 0x75, 0x13, 0xe8, 0xf2, 0xe8, 0xcb, 0x45,
  871. 0x73, 0x70, 0xaf, 0x94, 0xe6, 0xc5, 0xb0, 0xdf,
  872. 0xd2, 0xd5, 0x57, 0x97, 0x7c, 0x97, 0xde, 0x55,
  873. 0xaf, 0xbb, 0xed, 0x19, 0x35, 0x17, 0xf4, 0x23,
  874. 0x38, 0x9c, 0xce, 0x37, 0xfe, 0xd8, 0x4e, 0xd8,
  875. 0x99, 0xba, 0x33, 0x22, 0xf2, 0xeb, 0xab, 0x97,
  876. 0xee, 0x9d, 0xab, 0x67, 0x95, 0x35, 0xdf, 0xc8,
  877. 0xb6, 0xa0, 0xf, 0x15, 0x51, 0xa9, 0x76, 0x15,
  878. 0xdd, 0xbd, 0xac, 0x12, 0xce, 0x51, 0xde, 0x68,
  879. 0x15, 0xaf, 0x27, 0xcf, 0xd1, 0xba, 0x7c, 0x17,
  880. 0xef, 0xbf, 0xbb, 0xc0, 0x6e, 0x58, 0x73, 0xf6,
  881. 0x57, 0xe1, 0x8d, 0xb0, 0x9a, 0x5a, 0x9, 0x19,
  882. 0xef, 0xdd, 0x4, 0xe1, 0x76, 0x94, 0x31, 0xd7,
  883. 0x26, 0x9f, 0x9c, 0x27, 0xc4, 0x2b, 0x4b, 0xf6,
  884. 0x3b, 0xa1, 0x8c, 0xf4, 0x21, 0xde, 0x39, 0x14,
  885. 0x5a, 0x54, 0xac, 0x95, 0x2f, 0xa0, 0x60, 0x53,
  886. 0x87, 0x5b, 0x71, 0x92, 0xae, 0xf9, 0x6c, 0x62,
  887. 0x76, 0x7e, 0x91, 0x11, 0xa6, 0xf4, 0xf2, 0xa8,
  888. 0xdf, 0xc1, 0xf6, 0x3a, 0xdb, 0x34, 0x96, 0x9,
  889. 0x71, 0xb4, 0x4, 0xfa, 0xd4, 0x3, 0x46, 0x16,
  890. 0x78, 0x41, 0x42, 0x7d, 0x15, 0x68, 0x63, 0x55,
  891. 0x23, 0x4, 0x46, 0x5d, 0xe1, 0xd8, 0xe7, 0x5f,
  892. 0x55, 0x39, 0xd2, 0x45, 0xb2, 0x0, 0x35, 0xde,
  893. 0xd8, 0x9d, 0xc7, 0x3a, 0x8f, 0x37, 0x7e, 0xe5,
  894. 0x9e, 0xcf, 0xd1, 0x6a, 0x22, 0xe1, 0x51, 0xb2,
  895. 0xe6, 0x99, 0x3e, 0x83, 0xeb, 0x34, 0x9d, 0x34,
  896. 0x7, 0x1c, 0xbe, 0x91, 0x69, 0x9e, 0xaa, 0xcb,
  897. 0x86, 0xd2, 0xb6, 0xed, 0xa5, 0x4, 0xf9, 0x7d,
  898. 0xf8, 0xba, 0x2a, 0x27, 0x38, 0xe1, 0xaa, 0x22,
  899. 0x94, 0x46, 0x1f, 0x1b, 0xcf, 0xc4, 0x78, 0x88,
  900. 0x3d, 0x50, 0x83, 0x30, 0x61, 0x87, 0xb6, 0x38,
  901. 0x5b, 0x4f, 0x5a, 0x3, 0x2d, 0x5d, 0xa6, 0x33,
  902. 0x38, 0xe7, 0x8b, 0x60, 0x1, 0x8e, 0xde, 0x69,
  903. 0x8e, 0x4d, 0x60, 0x24, 0x3b, 0x47, 0x4b, 0x56,
  904. 0xea, 0xf9, 0xc8, 0xfa, 0x2d, 0x65, 0x7b, 0xad,
  905. 0xee, 0xe4, 0x91, 0x20, 0x6f, 0x64, 0x6e, 0x81,
  906. 0x69, 0xda, 0xf5, 0x3c, 0x3d, 0xff, 0x4c, 0xe9,
  907. 0x9b, 0x4d, 0xa8, 0x67, 0x9e, 0x67, 0x7f, 0x84,
  908. 0xdb, 0x7a, 0xb7, 0x24, 0x32, 0xa0, 0x80, 0x16,
  909. 0x55, 0x2d, 0x1d, 0xc1, 0x3a, 0x19, 0xd3, 0x17,
  910. 0x74, 0x8e, 0x2a, 0x5c, 0xf6, 0x71, 0xf7, 0x25,
  911. 0x3a, 0x54, 0x28, 0xef, 0x50, 0x78, 0x14, 0x5,
  912. 0x49, 0x8a, 0xbb, 0x71, 0xb2, 0xed, 0xa2, 0x5b,
  913. 0xff, 0x2, 0xe, 0xd8, 0x1a, 0x8b, 0x3c, 0xcc,
  914. 0x58, 0x27, 0x71, 0x2d, 0xb, 0x11, 0x9f, 0x6,
  915. 0xc3, 0xfd, 0x37, 0x19, 0xdb, 0xec, 0xa5, 0x4b,
  916. 0x93, 0x81, 0xb6, 0xff, 0xd4, 0xf5, 0x7b, 0xf5,
  917. 0x49, 0x5b, 0x95, 0x9, 0xa4, 0xca, 0xa5, 0x33,
  918. 0x9a, 0xfc, 0x97, 0xec, 0x7b, 0xb, 0xb9, 0x2e,
  919. 0x3b, 0x9d, 0x52, 0xc2, 0xa2, 0x9, 0xc8, 0xbf,
  920. 0x39, 0x16, 0xce, 0x42, 0x3, 0x4b, 0xe3, 0xfc,
  921. 0xfd, 0xc, 0x37, 0x96, 0x10, 0x36, 0xad, 0x44,
  922. 0xda, 0xc5, 0x58, 0x3e, 0x78, 0x52, 0xa1, 0x65,
  923. 0xed, 0x89, 0xe7, 0xea, 0xbf, 0xa8, 0x6a, 0xf2,
  924. 0xa7, 0x8e, 0x9d, 0x1, 0x25, 0x83, 0x57, 0x5f,
  925. 0x51, 0xe6, 0xe1, 0xa4, 0x4f, 0xf6, 0x81, 0xd7,
  926. 0xe6, 0x98, 0x29, 0x98, 0x58, 0xfe, 0xda, 0x45,
  927. 0xab, 0x38, 0x6, 0x91, 0x97, 0xb7, 0xa3, 0x4f,
  928. 0x93, 0x8d, 0x8a, 0x8b, 0x5, 0xe9, 0x5, 0x98,
  929. 0x3b, 0xc4, 0xb7, 0xe1, 0x68, 0x58, 0xa0, 0x3b,
  930. 0x99, 0xea, 0x8a, 0xa9, 0xfb, 0x55, 0xe2, 0xc7,
  931. 0x1d, 0x87, 0x3, 0x40, 0x24, 0x13, 0x28, 0x6a,
  932. 0x34, 0x8a, 0xff, 0x62, 0x91, 0xb8, 0x7d, 0x28,
  933. 0x1a, 0xd2, 0xfc, 0x4e, 0xa3, 0xda, 0x66, 0x69,
  934. 0x15, 0xc0, 0xda, 0x15, 0x3e, 0x67, 0x12, 0x95,
  935. 0x6, 0x1b, 0xf4, 0x60, 0xe4, 0x39, 0x82, 0xe9,
  936. 0x2e, 0xbe, 0xab, 0x8c, 0x2c, 0x6e, 0xd6, 0x40,
  937. 0x91, 0xc0, 0x68, 0xf7, 0xa2, 0x41, 0xd0, 0xa8,
  938. 0x7, 0xab, 0x13, 0x34, 0x16, 0xf4, 0x73, 0x4f,
  939. 0x1d, 0x21, 0x1a, 0x7d, 0xad, 0x43, 0x12, 0xf,
  940. 0xb7, 0xfe, 0xa3, 0x81, 0xe9, 0xb5, 0x2d, 0xd3,
  941. 0xa, 0x29, 0xb5, 0x32, 0xcb, 0x49, 0x6f, 0x1,
  942. 0x90, 0x45, 0x62, 0xca, 0x1b, 0x66, 0x39, 0x88,
  943. 0x1c, 0xee, 0x30, 0xa8, 0xb5, 0x37, 0xd0, 0xfa,
  944. 0x46, 0x52, 0x16, 0x30, 0x17, 0xcf, 0x88, 0xd0,
  945. 0x4, 0x5d, 0xde, 0x5e, 0x4f, 0xe7, 0xa9, 0xbf,
  946. 0x3c, 0x29, 0x3a, 0x63, 0x67, 0x23, 0xb3, 0x7c,
  947. 0x51, 0x17, 0xfe, 0x8d, 0xdb, 0xc8, 0x8d, 0x70,
  948. 0xe9, 0x6f, 0x56, 0xe5, 0x44, 0xb2, 0x94, 0xeb,
  949. 0x47, 0xca, 0x3a, 0xdc, 0xe3, 0x33, 0x87, 0x9c,
  950. 0xe8, 0x89, 0x4b, 0x41, 0xb8, 0xb3, 0x69, 0xb0,
  951. 0x7f, 0xc8, 0xc7, 0x74, 0xf5, 0xcb, 0x20, 0xad,
  952. 0xea, 0xbb, 0x3d, 0x11, 0xc6, 0xc0, 0xd2, 0x88,
  953. 0x8b, 0x16, 0xee, 0x62, 0x5a, 0x4d, 0x32, 0xe7,
  954. 0x48, 0xae, 0xab, 0x5e, 0xc2, 0x83, 0xc4, 0xfc,
  955. 0xd1, 0xb9, 0x71, 0xf2, 0x9, 0x7f, 0xdc, 0xbc,
  956. 0x28, 0x74, 0xa0, 0x37, 0xa9, 0x5b, 0x6c, 0x7c,
  957. 0x9b, 0x61, 0x94, 0x88, 0xf7, 0x40, 0x84, 0x75,
  958. 0xa5, 0x50, 0xab, 0xb0, 0x92, 0x66, 0x10, 0x66,
  959. 0xf6, 0xec, 0x6b, 0x5e, 0x31, 0x9b, 0xc4, 0xfa,
  960. 0x95, 0x8b, 0xe7, 0xd4, 0xba, 0x81, 0xd2, 0x85,
  961. 0x30, 0x4, 0x8b, 0x3d, 0xfa, 0x8a, 0x8f, 0x9b,
  962. 0x54, 0x6a, 0x4d, 0x35, 0xa2, 0xe9, 0x58, 0x95,
  963. 0xe3, 0xd1, 0x71, 0xcd, 0x3a, 0x54, 0xae, 0xd9,
  964. 0x5c, 0x83, 0xd, 0x15, 0x64, 0x66, 0xee, 0x39,
  965. 0xa1, 0x85, 0xe2, 0x28, 0xf5, 0x66, 0x5f, 0xec,
  966. 0x39, 0x70, 0x96, 0x2c, 0x72, 0x9e, 0x57, 0xfd,
  967. 0x57, 0x27, 0xb7, 0xda, 0x79, 0x39, 0xd8, 0x3b,
  968. 0x2e, 0xa3, 0xb0, 0xde, 0xbf, 0x60, 0xb6, 0x42,
  969. 0x78, 0x9d, 0x8f, 0xe8, 0x1c, 0x7c, 0x45, 0x72,
  970. 0x3, 0xc4, 0xd5, 0x81, 0xf6, 0xe6, 0x9, 0x29,
  971. 0x1e, 0xcd, 0xf3, 0xe, 0xd6, 0x65, 0xee, 0x6d,
  972. 0x90, 0x17, 0x95, 0x20, 0x54, 0xf1, 0xd, 0x2f,
  973. 0xa0, 0xac, 0xe3, 0x4b, 0xfc, 0xa4, 0xdc, 0xab,
  974. 0x9d, 0x9e, 0x32, 0x63, 0x72, 0xd1, 0xb4, 0xef,
  975. 0xf1, 0x83, 0xa7, 0xd7, 0x2b, 0x1a, 0x9a, 0x9e,
  976. 0xfa, 0x1e, 0xb, 0x2b, 0xdc, 0x7b, 0x87, 0x96,
  977. 0xf, 0xdb, 0x75, 0xb9, 0x6, 0x2b, 0xd3, 0x95,
  978. 0xc5, 0xb3, 0x9, 0x53, 0x94, 0x54, 0x1f, 0xd0,
  979. 0x75, 0x5a, 0x36, 0x6a, 0x7c, 0x82, 0xdb, 0xb1,
  980. 0xa2, 0x17, 0xbc, 0xeb, 0x1f, 0xfa, 0x34, 0x3d,
  981. 0xee, 0x68, 0xee, 0x93, 0x33, 0xfb, 0xcb, 0xd2,
  982. 0xa3, 0xd1, 0x24, 0x5e, 0xf4, 0x9, 0xbe, 0x5a,
  983. 0x68, 0x9e, 0x3e, 0xd4, 0x81, 0xcd, 0xa3, 0x1e,
  984. 0x2, 0x13, 0xb4, 0x79, 0x94, 0xc9, 0xb2, 0xde,
  985. 0x56, 0xf1, 0x7b, 0x2f, 0xe2, 0x56, 0xe1, 0x10,
  986. 0xf4, 0x73, 0x2d, 0xc9, 0xca, 0x4d, 0x5f, 0x11,
  987. 0x9e, 0xd6, 0x3c, 0x73, 0x12, 0x57, 0xe9, 0x14,
  988. 0xe0, 0x8d, 0xdd, 0x4b, 0x8a, 0xbb, 0xb3, 0x78,
  989. 0xbe, 0x16, 0x94, 0x93, 0x51, 0x33, 0x7a, 0xa5,
  990. 0x41, 0x14, 0x60, 0x82, 0x94, 0x67, 0x70, 0xea,
  991. 0xe6, 0x3, 0x7f, 0xc5, 0xa0, 0x20, 0x15, 0x88,
  992. 0x53, 0xe3, 0x7e, 0x16, 0x52, 0xe4, 0xca, 0xa0,
  993. 0x6f, 0xb9, 0x68, 0x4e, 0x30, 0xb9, 0x8c, 0xe6,
  994. 0x9c, 0x5e, 0xc2, 0x93, 0xf9, 0xe1, 0x41, 0x4b,
  995. 0x18, 0x42, 0x6f, 0x8f, 0x96, 0x3d, 0x2b, 0x28,
  996. 0xd5, 0x53, 0x62, 0xdd, 0x6b, 0xd0, 0xf8, 0x2e,
  997. 0xa6, 0x97, 0xe5, 0x87, 0xc5, 0xf6, 0x96, 0x7b,
  998. 0xc4, 0x3e, 0x84, 0xc9, 0xf6, 0x34, 0x63, 0x46,
  999. 0xe1, 0x10, 0xa5, 0x91, 0x6b, 0xff, 0x10, 0x3f,
  1000. 0x50, 0x2e, 0xd7, 0x39, 0x12, 0x7a, 0x15, 0x85,
  1001. 0xed, 0x99, 0xdb, 0x9b, 0x99, 0x6b, 0xfa, 0xfa,
  1002. 0x93, 0x7, 0x44, 0xbe, 0xbe, 0x60, 0x23, 0xc1,
  1003. 0xec, 0x5c, 0xf6, 0x93, 0x38, 0xf9, 0x89, 0x0,
  1004. 0xc5, 0x5f, 0x5b, 0xe2, 0x9d, 0x2b, 0xea, 0x6b,
  1005. 0x2e, 0xee, 0xb7, 0x4a, 0x4e, 0x8d, 0xd0, 0x35,
  1006. 0xe9, 0xc1, 0x5, 0x2b, 0x83, 0xb7, 0x72, 0x25,
  1007. 0xbb, 0xbe, 0xe8, 0x15, 0xf4, 0x74, 0x69, 0x69,
  1008. 0x67, 0x8c, 0x5c, 0x31, 0x79, 0x78, 0x2e, 0x43,
  1009. 0x83, 0xd1, 0xdd, 0x9, 0xc3, 0xa1, 0x0, 0x13,
  1010. 0x31, 0x4b, 0x86, 0xce, 0xee, 0xd7, 0xec, 0xb1,
  1011. 0x2c, 0x38, 0x46, 0x68, 0x62, 0xd9, 0x84, 0xdb,
  1012. 0x24, 0x62, 0x82, 0xc, 0x12, 0xb7, 0x4f, 0x86,
  1013. 0x54, 0x18, 0xc6, 0xd7, 0x94, 0x8b, 0xf2, 0x4c,
  1014. 0x17, 0x98, 0xaa, 0xe0,
  1015. };
  1016. const uint8_t expected_cipher_long_input_end[] = {
  1017. 0x05, 0x95, 0x58, 0x7b, 0xb4, 0x60, 0x15,
  1018. 0x32, 0x9f, 0x38, 0xcc, 0x98, 0x1b, 0xbe, 0x10, 0xa5, 0x06, 0x67, 0xae, 0x38,
  1019. 0xbd, 0x7d, 0xb5, 0xcd, 0x58, 0x32, 0xdd, 0x9e,
  1020. 0x6a, 0xde, 0xe3, 0x53,
  1021. };
  1022. void aes_icache_ctr_test(uint32_t output_buf_caps)
  1023. {
  1024. mbedtls_aes_context ctx;
  1025. uint8_t nonce[16];
  1026. uint8_t key[16];
  1027. uint8_t stream_block[16];
  1028. size_t SZ = sizeof(long_input);
  1029. memset(nonce, 0x2F, 16);
  1030. memset(key, 0x1E, 16);
  1031. // allocate internal memory
  1032. uint8_t *chipertext = heap_caps_malloc(SZ, output_buf_caps);
  1033. uint8_t *decryptedtext = heap_caps_malloc(SZ, MALLOC_CAP_8BIT | MALLOC_CAP_DMA);
  1034. TEST_ASSERT_NOT_NULL(chipertext);
  1035. TEST_ASSERT_NOT_NULL(decryptedtext);
  1036. mbedtls_aes_init(&ctx);
  1037. mbedtls_aes_setkey_enc(&ctx, key, 128);
  1038. size_t offset;
  1039. // Encrypt with input buffer in external ram
  1040. offset = 0;
  1041. memset(nonce, 0x2F, 16);
  1042. mbedtls_aes_crypt_ctr(&ctx, SZ, &offset, nonce, stream_block, long_input, chipertext);
  1043. TEST_ASSERT_EQUAL_HEX8_ARRAY(expected_cipher_long_input_end, chipertext + SZ - 32, 32);
  1044. // Decrypt
  1045. offset = 0;
  1046. memset(nonce, 0x2F, 16);
  1047. // Decrypt with input buffer in instruction memory, the crypto DMA can't access this
  1048. mbedtls_aes_crypt_ctr(&ctx, SZ, &offset, nonce, stream_block, chipertext, decryptedtext);
  1049. TEST_ASSERT_EQUAL_HEX8_ARRAY(long_input, decryptedtext, SZ);
  1050. free(chipertext);
  1051. free(decryptedtext);
  1052. }
  1053. /* Tests how crypto DMA handles data in external memory */
  1054. TEST_CASE("mbedtls AES PSRAM tests", "[aes]")
  1055. {
  1056. aes_psram_ctr_test(MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL, MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM);
  1057. aes_psram_ctr_test(MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM, MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL);
  1058. aes_psram_ctr_test(MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM, MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM);
  1059. aes_psram_one_buf_ctr_test();
  1060. }
  1061. /* Tests how crypto DMA handles data from iCache */
  1062. TEST_CASE("mbedtls AES iCache tests", "[aes]")
  1063. {
  1064. aes_icache_ctr_test(MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM);
  1065. aes_icache_ctr_test(MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL);
  1066. }
  1067. #endif // CONFIG_SPIRAM_USE_MALLOC
  1068. TEST_CASE("mbedtls AES GCM self-tests", "[aes]")
  1069. {
  1070. TEST_ASSERT_FALSE_MESSAGE(mbedtls_gcm_self_test(1), "AES GCM self-test should pass.");
  1071. }
  1072. TEST_CASE("mbedtls AES GCM crypt-and-tag", "[aes]")
  1073. {
  1074. const unsigned CALL_SZ = 32 * 1024;
  1075. mbedtls_gcm_context ctx;
  1076. unsigned char tag_buf[16];
  1077. mbedtls_cipher_id_t cipher = MBEDTLS_CIPHER_ID_AES;
  1078. uint8_t iv[16];
  1079. uint8_t key[16];
  1080. memset(iv, 0xEE, 16);
  1081. memset(key, 0x44, 16);
  1082. // allocate internal memory
  1083. uint8_t *buf = heap_caps_malloc(CALL_SZ, MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL);
  1084. TEST_ASSERT_NOT_NULL(buf);
  1085. uint8_t aad[16];
  1086. memset(aad, 0x22, 16);
  1087. mbedtls_gcm_init(&ctx);
  1088. mbedtls_gcm_setkey( &ctx, cipher, key, 128);
  1089. memset(buf, 0xAA, CALL_SZ);
  1090. mbedtls_gcm_crypt_and_tag(&ctx, MBEDTLS_AES_ENCRYPT, CALL_SZ, iv, sizeof(iv), aad, sizeof(aad), buf, buf, 16, tag_buf);
  1091. /* Sanity check: make sure the last ciphertext block matches
  1092. what we expect to see.
  1093. Last block and tag produced via this Python:
  1094. import os, binascii
  1095. from cryptography.hazmat.primitives.ciphers.aead import AESGCM
  1096. key = b'\x44' * 16
  1097. iv = b'\xEE' * 16
  1098. data = b'\xAA' * 100
  1099. aad = b'\x22 * 16
  1100. aesgcm = AESGCM(key)
  1101. ct = aesgcm.encrypt(iv, data, aad)
  1102. */
  1103. const uint8_t expected_last_block[] = {
  1104. 0x7d, 0x3d, 0x16, 0x84, 0xd0, 0xb4, 0x38, 0x30,
  1105. 0xd1, 0x24, 0x6f, 0x7e, 0x9a, 0x9c, 0x81, 0x58,
  1106. };
  1107. const uint8_t expected_tag[] = {
  1108. 0x7e, 0x16, 0x04, 0x07, 0x4b, 0x7e, 0x6b, 0xf7,
  1109. 0x5d, 0xce, 0x9e, 0x7d, 0x3f, 0x85, 0xc5, 0xa5,
  1110. };
  1111. TEST_ASSERT_EQUAL_HEX8_ARRAY(expected_last_block, buf + CALL_SZ - 16, 16);
  1112. TEST_ASSERT_EQUAL_HEX8_ARRAY(expected_tag, tag_buf, 16);
  1113. memset(iv, 0xEE, 16);
  1114. TEST_ASSERT_EQUAL(mbedtls_gcm_auth_decrypt(&ctx, CALL_SZ, iv, sizeof(iv), aad, sizeof(aad), expected_tag, sizeof(expected_tag), buf, buf), 0);
  1115. TEST_ASSERT_EACH_EQUAL_HEX8(0xAA, buf, CALL_SZ);
  1116. free(buf);
  1117. }