des.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058
  1. /*
  2. * FIPS-46-3 compliant Triple-DES implementation
  3. *
  4. * Copyright The Mbed TLS Contributors
  5. * SPDX-License-Identifier: Apache-2.0
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  8. * not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. */
  19. /*
  20. * DES, on which TDES is based, was originally designed by Horst Feistel
  21. * at IBM in 1974, and was adopted as a standard by NIST (formerly NBS).
  22. *
  23. * http://csrc.nist.gov/publications/fips/fips46-3/fips46-3.pdf
  24. */
  25. #include "common.h"
  26. #if defined(MBEDTLS_DES_C)
  27. #include "mbedtls/des.h"
  28. #include "mbedtls/platform_util.h"
  29. #include <string.h>
  30. #if defined(MBEDTLS_SELF_TEST)
  31. #if defined(MBEDTLS_PLATFORM_C)
  32. #include "mbedtls/platform.h"
  33. #else
  34. #include <stdio.h>
  35. #define mbedtls_printf printf
  36. #endif /* MBEDTLS_PLATFORM_C */
  37. #endif /* MBEDTLS_SELF_TEST */
  38. #if !defined(MBEDTLS_DES_ALT)
  39. /*
  40. * 32-bit integer manipulation macros (big endian)
  41. */
  42. #ifndef GET_UINT32_BE
  43. #define GET_UINT32_BE(n,b,i) \
  44. { \
  45. (n) = ( (uint32_t) (b)[(i) ] << 24 ) \
  46. | ( (uint32_t) (b)[(i) + 1] << 16 ) \
  47. | ( (uint32_t) (b)[(i) + 2] << 8 ) \
  48. | ( (uint32_t) (b)[(i) + 3] ); \
  49. }
  50. #endif
  51. #ifndef PUT_UINT32_BE
  52. #define PUT_UINT32_BE(n,b,i) \
  53. { \
  54. (b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
  55. (b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
  56. (b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
  57. (b)[(i) + 3] = (unsigned char) ( (n) ); \
  58. }
  59. #endif
  60. /*
  61. * Expanded DES S-boxes
  62. */
  63. static const uint32_t SB1[64] =
  64. {
  65. 0x01010400, 0x00000000, 0x00010000, 0x01010404,
  66. 0x01010004, 0x00010404, 0x00000004, 0x00010000,
  67. 0x00000400, 0x01010400, 0x01010404, 0x00000400,
  68. 0x01000404, 0x01010004, 0x01000000, 0x00000004,
  69. 0x00000404, 0x01000400, 0x01000400, 0x00010400,
  70. 0x00010400, 0x01010000, 0x01010000, 0x01000404,
  71. 0x00010004, 0x01000004, 0x01000004, 0x00010004,
  72. 0x00000000, 0x00000404, 0x00010404, 0x01000000,
  73. 0x00010000, 0x01010404, 0x00000004, 0x01010000,
  74. 0x01010400, 0x01000000, 0x01000000, 0x00000400,
  75. 0x01010004, 0x00010000, 0x00010400, 0x01000004,
  76. 0x00000400, 0x00000004, 0x01000404, 0x00010404,
  77. 0x01010404, 0x00010004, 0x01010000, 0x01000404,
  78. 0x01000004, 0x00000404, 0x00010404, 0x01010400,
  79. 0x00000404, 0x01000400, 0x01000400, 0x00000000,
  80. 0x00010004, 0x00010400, 0x00000000, 0x01010004
  81. };
  82. static const uint32_t SB2[64] =
  83. {
  84. 0x80108020, 0x80008000, 0x00008000, 0x00108020,
  85. 0x00100000, 0x00000020, 0x80100020, 0x80008020,
  86. 0x80000020, 0x80108020, 0x80108000, 0x80000000,
  87. 0x80008000, 0x00100000, 0x00000020, 0x80100020,
  88. 0x00108000, 0x00100020, 0x80008020, 0x00000000,
  89. 0x80000000, 0x00008000, 0x00108020, 0x80100000,
  90. 0x00100020, 0x80000020, 0x00000000, 0x00108000,
  91. 0x00008020, 0x80108000, 0x80100000, 0x00008020,
  92. 0x00000000, 0x00108020, 0x80100020, 0x00100000,
  93. 0x80008020, 0x80100000, 0x80108000, 0x00008000,
  94. 0x80100000, 0x80008000, 0x00000020, 0x80108020,
  95. 0x00108020, 0x00000020, 0x00008000, 0x80000000,
  96. 0x00008020, 0x80108000, 0x00100000, 0x80000020,
  97. 0x00100020, 0x80008020, 0x80000020, 0x00100020,
  98. 0x00108000, 0x00000000, 0x80008000, 0x00008020,
  99. 0x80000000, 0x80100020, 0x80108020, 0x00108000
  100. };
  101. static const uint32_t SB3[64] =
  102. {
  103. 0x00000208, 0x08020200, 0x00000000, 0x08020008,
  104. 0x08000200, 0x00000000, 0x00020208, 0x08000200,
  105. 0x00020008, 0x08000008, 0x08000008, 0x00020000,
  106. 0x08020208, 0x00020008, 0x08020000, 0x00000208,
  107. 0x08000000, 0x00000008, 0x08020200, 0x00000200,
  108. 0x00020200, 0x08020000, 0x08020008, 0x00020208,
  109. 0x08000208, 0x00020200, 0x00020000, 0x08000208,
  110. 0x00000008, 0x08020208, 0x00000200, 0x08000000,
  111. 0x08020200, 0x08000000, 0x00020008, 0x00000208,
  112. 0x00020000, 0x08020200, 0x08000200, 0x00000000,
  113. 0x00000200, 0x00020008, 0x08020208, 0x08000200,
  114. 0x08000008, 0x00000200, 0x00000000, 0x08020008,
  115. 0x08000208, 0x00020000, 0x08000000, 0x08020208,
  116. 0x00000008, 0x00020208, 0x00020200, 0x08000008,
  117. 0x08020000, 0x08000208, 0x00000208, 0x08020000,
  118. 0x00020208, 0x00000008, 0x08020008, 0x00020200
  119. };
  120. static const uint32_t SB4[64] =
  121. {
  122. 0x00802001, 0x00002081, 0x00002081, 0x00000080,
  123. 0x00802080, 0x00800081, 0x00800001, 0x00002001,
  124. 0x00000000, 0x00802000, 0x00802000, 0x00802081,
  125. 0x00000081, 0x00000000, 0x00800080, 0x00800001,
  126. 0x00000001, 0x00002000, 0x00800000, 0x00802001,
  127. 0x00000080, 0x00800000, 0x00002001, 0x00002080,
  128. 0x00800081, 0x00000001, 0x00002080, 0x00800080,
  129. 0x00002000, 0x00802080, 0x00802081, 0x00000081,
  130. 0x00800080, 0x00800001, 0x00802000, 0x00802081,
  131. 0x00000081, 0x00000000, 0x00000000, 0x00802000,
  132. 0x00002080, 0x00800080, 0x00800081, 0x00000001,
  133. 0x00802001, 0x00002081, 0x00002081, 0x00000080,
  134. 0x00802081, 0x00000081, 0x00000001, 0x00002000,
  135. 0x00800001, 0x00002001, 0x00802080, 0x00800081,
  136. 0x00002001, 0x00002080, 0x00800000, 0x00802001,
  137. 0x00000080, 0x00800000, 0x00002000, 0x00802080
  138. };
  139. static const uint32_t SB5[64] =
  140. {
  141. 0x00000100, 0x02080100, 0x02080000, 0x42000100,
  142. 0x00080000, 0x00000100, 0x40000000, 0x02080000,
  143. 0x40080100, 0x00080000, 0x02000100, 0x40080100,
  144. 0x42000100, 0x42080000, 0x00080100, 0x40000000,
  145. 0x02000000, 0x40080000, 0x40080000, 0x00000000,
  146. 0x40000100, 0x42080100, 0x42080100, 0x02000100,
  147. 0x42080000, 0x40000100, 0x00000000, 0x42000000,
  148. 0x02080100, 0x02000000, 0x42000000, 0x00080100,
  149. 0x00080000, 0x42000100, 0x00000100, 0x02000000,
  150. 0x40000000, 0x02080000, 0x42000100, 0x40080100,
  151. 0x02000100, 0x40000000, 0x42080000, 0x02080100,
  152. 0x40080100, 0x00000100, 0x02000000, 0x42080000,
  153. 0x42080100, 0x00080100, 0x42000000, 0x42080100,
  154. 0x02080000, 0x00000000, 0x40080000, 0x42000000,
  155. 0x00080100, 0x02000100, 0x40000100, 0x00080000,
  156. 0x00000000, 0x40080000, 0x02080100, 0x40000100
  157. };
  158. static const uint32_t SB6[64] =
  159. {
  160. 0x20000010, 0x20400000, 0x00004000, 0x20404010,
  161. 0x20400000, 0x00000010, 0x20404010, 0x00400000,
  162. 0x20004000, 0x00404010, 0x00400000, 0x20000010,
  163. 0x00400010, 0x20004000, 0x20000000, 0x00004010,
  164. 0x00000000, 0x00400010, 0x20004010, 0x00004000,
  165. 0x00404000, 0x20004010, 0x00000010, 0x20400010,
  166. 0x20400010, 0x00000000, 0x00404010, 0x20404000,
  167. 0x00004010, 0x00404000, 0x20404000, 0x20000000,
  168. 0x20004000, 0x00000010, 0x20400010, 0x00404000,
  169. 0x20404010, 0x00400000, 0x00004010, 0x20000010,
  170. 0x00400000, 0x20004000, 0x20000000, 0x00004010,
  171. 0x20000010, 0x20404010, 0x00404000, 0x20400000,
  172. 0x00404010, 0x20404000, 0x00000000, 0x20400010,
  173. 0x00000010, 0x00004000, 0x20400000, 0x00404010,
  174. 0x00004000, 0x00400010, 0x20004010, 0x00000000,
  175. 0x20404000, 0x20000000, 0x00400010, 0x20004010
  176. };
  177. static const uint32_t SB7[64] =
  178. {
  179. 0x00200000, 0x04200002, 0x04000802, 0x00000000,
  180. 0x00000800, 0x04000802, 0x00200802, 0x04200800,
  181. 0x04200802, 0x00200000, 0x00000000, 0x04000002,
  182. 0x00000002, 0x04000000, 0x04200002, 0x00000802,
  183. 0x04000800, 0x00200802, 0x00200002, 0x04000800,
  184. 0x04000002, 0x04200000, 0x04200800, 0x00200002,
  185. 0x04200000, 0x00000800, 0x00000802, 0x04200802,
  186. 0x00200800, 0x00000002, 0x04000000, 0x00200800,
  187. 0x04000000, 0x00200800, 0x00200000, 0x04000802,
  188. 0x04000802, 0x04200002, 0x04200002, 0x00000002,
  189. 0x00200002, 0x04000000, 0x04000800, 0x00200000,
  190. 0x04200800, 0x00000802, 0x00200802, 0x04200800,
  191. 0x00000802, 0x04000002, 0x04200802, 0x04200000,
  192. 0x00200800, 0x00000000, 0x00000002, 0x04200802,
  193. 0x00000000, 0x00200802, 0x04200000, 0x00000800,
  194. 0x04000002, 0x04000800, 0x00000800, 0x00200002
  195. };
  196. static const uint32_t SB8[64] =
  197. {
  198. 0x10001040, 0x00001000, 0x00040000, 0x10041040,
  199. 0x10000000, 0x10001040, 0x00000040, 0x10000000,
  200. 0x00040040, 0x10040000, 0x10041040, 0x00041000,
  201. 0x10041000, 0x00041040, 0x00001000, 0x00000040,
  202. 0x10040000, 0x10000040, 0x10001000, 0x00001040,
  203. 0x00041000, 0x00040040, 0x10040040, 0x10041000,
  204. 0x00001040, 0x00000000, 0x00000000, 0x10040040,
  205. 0x10000040, 0x10001000, 0x00041040, 0x00040000,
  206. 0x00041040, 0x00040000, 0x10041000, 0x00001000,
  207. 0x00000040, 0x10040040, 0x00001000, 0x00041040,
  208. 0x10001000, 0x00000040, 0x10000040, 0x10040000,
  209. 0x10040040, 0x10000000, 0x00040000, 0x10001040,
  210. 0x00000000, 0x10041040, 0x00040040, 0x10000040,
  211. 0x10040000, 0x10001000, 0x10001040, 0x00000000,
  212. 0x10041040, 0x00041000, 0x00041000, 0x00001040,
  213. 0x00001040, 0x00040040, 0x10000000, 0x10041000
  214. };
  215. /*
  216. * PC1: left and right halves bit-swap
  217. */
  218. static const uint32_t LHs[16] =
  219. {
  220. 0x00000000, 0x00000001, 0x00000100, 0x00000101,
  221. 0x00010000, 0x00010001, 0x00010100, 0x00010101,
  222. 0x01000000, 0x01000001, 0x01000100, 0x01000101,
  223. 0x01010000, 0x01010001, 0x01010100, 0x01010101
  224. };
  225. static const uint32_t RHs[16] =
  226. {
  227. 0x00000000, 0x01000000, 0x00010000, 0x01010000,
  228. 0x00000100, 0x01000100, 0x00010100, 0x01010100,
  229. 0x00000001, 0x01000001, 0x00010001, 0x01010001,
  230. 0x00000101, 0x01000101, 0x00010101, 0x01010101,
  231. };
  232. /*
  233. * Initial Permutation macro
  234. */
  235. #define DES_IP(X,Y) \
  236. do \
  237. { \
  238. T = (((X) >> 4) ^ (Y)) & 0x0F0F0F0F; (Y) ^= T; (X) ^= (T << 4); \
  239. T = (((X) >> 16) ^ (Y)) & 0x0000FFFF; (Y) ^= T; (X) ^= (T << 16); \
  240. T = (((Y) >> 2) ^ (X)) & 0x33333333; (X) ^= T; (Y) ^= (T << 2); \
  241. T = (((Y) >> 8) ^ (X)) & 0x00FF00FF; (X) ^= T; (Y) ^= (T << 8); \
  242. (Y) = (((Y) << 1) | ((Y) >> 31)) & 0xFFFFFFFF; \
  243. T = ((X) ^ (Y)) & 0xAAAAAAAA; (Y) ^= T; (X) ^= T; \
  244. (X) = (((X) << 1) | ((X) >> 31)) & 0xFFFFFFFF; \
  245. } while( 0 )
  246. /*
  247. * Final Permutation macro
  248. */
  249. #define DES_FP(X,Y) \
  250. do \
  251. { \
  252. (X) = (((X) << 31) | ((X) >> 1)) & 0xFFFFFFFF; \
  253. T = ((X) ^ (Y)) & 0xAAAAAAAA; (X) ^= T; (Y) ^= T; \
  254. (Y) = (((Y) << 31) | ((Y) >> 1)) & 0xFFFFFFFF; \
  255. T = (((Y) >> 8) ^ (X)) & 0x00FF00FF; (X) ^= T; (Y) ^= (T << 8); \
  256. T = (((Y) >> 2) ^ (X)) & 0x33333333; (X) ^= T; (Y) ^= (T << 2); \
  257. T = (((X) >> 16) ^ (Y)) & 0x0000FFFF; (Y) ^= T; (X) ^= (T << 16); \
  258. T = (((X) >> 4) ^ (Y)) & 0x0F0F0F0F; (Y) ^= T; (X) ^= (T << 4); \
  259. } while( 0 )
  260. /*
  261. * DES round macro
  262. */
  263. #define DES_ROUND(X,Y) \
  264. do \
  265. { \
  266. T = *SK++ ^ (X); \
  267. (Y) ^= SB8[ (T ) & 0x3F ] ^ \
  268. SB6[ (T >> 8) & 0x3F ] ^ \
  269. SB4[ (T >> 16) & 0x3F ] ^ \
  270. SB2[ (T >> 24) & 0x3F ]; \
  271. \
  272. T = *SK++ ^ (((X) << 28) | ((X) >> 4)); \
  273. (Y) ^= SB7[ (T ) & 0x3F ] ^ \
  274. SB5[ (T >> 8) & 0x3F ] ^ \
  275. SB3[ (T >> 16) & 0x3F ] ^ \
  276. SB1[ (T >> 24) & 0x3F ]; \
  277. } while( 0 )
  278. #define SWAP(a,b) \
  279. do \
  280. { \
  281. uint32_t t = (a); (a) = (b); (b) = t; t = 0; \
  282. } while( 0 )
  283. void mbedtls_des_init( mbedtls_des_context *ctx )
  284. {
  285. memset( ctx, 0, sizeof( mbedtls_des_context ) );
  286. }
  287. void mbedtls_des_free( mbedtls_des_context *ctx )
  288. {
  289. if( ctx == NULL )
  290. return;
  291. mbedtls_platform_zeroize( ctx, sizeof( mbedtls_des_context ) );
  292. }
  293. void mbedtls_des3_init( mbedtls_des3_context *ctx )
  294. {
  295. memset( ctx, 0, sizeof( mbedtls_des3_context ) );
  296. }
  297. void mbedtls_des3_free( mbedtls_des3_context *ctx )
  298. {
  299. if( ctx == NULL )
  300. return;
  301. mbedtls_platform_zeroize( ctx, sizeof( mbedtls_des3_context ) );
  302. }
  303. static const unsigned char odd_parity_table[128] = { 1, 2, 4, 7, 8,
  304. 11, 13, 14, 16, 19, 21, 22, 25, 26, 28, 31, 32, 35, 37, 38, 41, 42, 44,
  305. 47, 49, 50, 52, 55, 56, 59, 61, 62, 64, 67, 69, 70, 73, 74, 76, 79, 81,
  306. 82, 84, 87, 88, 91, 93, 94, 97, 98, 100, 103, 104, 107, 109, 110, 112,
  307. 115, 117, 118, 121, 122, 124, 127, 128, 131, 133, 134, 137, 138, 140,
  308. 143, 145, 146, 148, 151, 152, 155, 157, 158, 161, 162, 164, 167, 168,
  309. 171, 173, 174, 176, 179, 181, 182, 185, 186, 188, 191, 193, 194, 196,
  310. 199, 200, 203, 205, 206, 208, 211, 213, 214, 217, 218, 220, 223, 224,
  311. 227, 229, 230, 233, 234, 236, 239, 241, 242, 244, 247, 248, 251, 253,
  312. 254 };
  313. void mbedtls_des_key_set_parity( unsigned char key[MBEDTLS_DES_KEY_SIZE] )
  314. {
  315. int i;
  316. for( i = 0; i < MBEDTLS_DES_KEY_SIZE; i++ )
  317. key[i] = odd_parity_table[key[i] / 2];
  318. }
  319. /*
  320. * Check the given key's parity, returns 1 on failure, 0 on SUCCESS
  321. */
  322. int mbedtls_des_key_check_key_parity( const unsigned char key[MBEDTLS_DES_KEY_SIZE] )
  323. {
  324. int i;
  325. for( i = 0; i < MBEDTLS_DES_KEY_SIZE; i++ )
  326. if( key[i] != odd_parity_table[key[i] / 2] )
  327. return( 1 );
  328. return( 0 );
  329. }
  330. /*
  331. * Table of weak and semi-weak keys
  332. *
  333. * Source: http://en.wikipedia.org/wiki/Weak_key
  334. *
  335. * Weak:
  336. * Alternating ones + zeros (0x0101010101010101)
  337. * Alternating 'F' + 'E' (0xFEFEFEFEFEFEFEFE)
  338. * '0xE0E0E0E0F1F1F1F1'
  339. * '0x1F1F1F1F0E0E0E0E'
  340. *
  341. * Semi-weak:
  342. * 0x011F011F010E010E and 0x1F011F010E010E01
  343. * 0x01E001E001F101F1 and 0xE001E001F101F101
  344. * 0x01FE01FE01FE01FE and 0xFE01FE01FE01FE01
  345. * 0x1FE01FE00EF10EF1 and 0xE01FE01FF10EF10E
  346. * 0x1FFE1FFE0EFE0EFE and 0xFE1FFE1FFE0EFE0E
  347. * 0xE0FEE0FEF1FEF1FE and 0xFEE0FEE0FEF1FEF1
  348. *
  349. */
  350. #define WEAK_KEY_COUNT 16
  351. static const unsigned char weak_key_table[WEAK_KEY_COUNT][MBEDTLS_DES_KEY_SIZE] =
  352. {
  353. { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
  354. { 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE },
  355. { 0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E },
  356. { 0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1 },
  357. { 0x01, 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E },
  358. { 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E, 0x01 },
  359. { 0x01, 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1 },
  360. { 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1, 0x01 },
  361. { 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE },
  362. { 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01 },
  363. { 0x1F, 0xE0, 0x1F, 0xE0, 0x0E, 0xF1, 0x0E, 0xF1 },
  364. { 0xE0, 0x1F, 0xE0, 0x1F, 0xF1, 0x0E, 0xF1, 0x0E },
  365. { 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E, 0xFE },
  366. { 0xFE, 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E },
  367. { 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE },
  368. { 0xFE, 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1 }
  369. };
  370. int mbedtls_des_key_check_weak( const unsigned char key[MBEDTLS_DES_KEY_SIZE] )
  371. {
  372. int i;
  373. for( i = 0; i < WEAK_KEY_COUNT; i++ )
  374. if( memcmp( weak_key_table[i], key, MBEDTLS_DES_KEY_SIZE) == 0 )
  375. return( 1 );
  376. return( 0 );
  377. }
  378. #if !defined(MBEDTLS_DES_SETKEY_ALT)
  379. void mbedtls_des_setkey( uint32_t SK[32], const unsigned char key[MBEDTLS_DES_KEY_SIZE] )
  380. {
  381. int i;
  382. uint32_t X, Y, T;
  383. GET_UINT32_BE( X, key, 0 );
  384. GET_UINT32_BE( Y, key, 4 );
  385. /*
  386. * Permuted Choice 1
  387. */
  388. T = ((Y >> 4) ^ X) & 0x0F0F0F0F; X ^= T; Y ^= (T << 4);
  389. T = ((Y ) ^ X) & 0x10101010; X ^= T; Y ^= (T );
  390. X = (LHs[ (X ) & 0xF] << 3) | (LHs[ (X >> 8) & 0xF ] << 2)
  391. | (LHs[ (X >> 16) & 0xF] << 1) | (LHs[ (X >> 24) & 0xF ] )
  392. | (LHs[ (X >> 5) & 0xF] << 7) | (LHs[ (X >> 13) & 0xF ] << 6)
  393. | (LHs[ (X >> 21) & 0xF] << 5) | (LHs[ (X >> 29) & 0xF ] << 4);
  394. Y = (RHs[ (Y >> 1) & 0xF] << 3) | (RHs[ (Y >> 9) & 0xF ] << 2)
  395. | (RHs[ (Y >> 17) & 0xF] << 1) | (RHs[ (Y >> 25) & 0xF ] )
  396. | (RHs[ (Y >> 4) & 0xF] << 7) | (RHs[ (Y >> 12) & 0xF ] << 6)
  397. | (RHs[ (Y >> 20) & 0xF] << 5) | (RHs[ (Y >> 28) & 0xF ] << 4);
  398. X &= 0x0FFFFFFF;
  399. Y &= 0x0FFFFFFF;
  400. /*
  401. * calculate subkeys
  402. */
  403. for( i = 0; i < 16; i++ )
  404. {
  405. if( i < 2 || i == 8 || i == 15 )
  406. {
  407. X = ((X << 1) | (X >> 27)) & 0x0FFFFFFF;
  408. Y = ((Y << 1) | (Y >> 27)) & 0x0FFFFFFF;
  409. }
  410. else
  411. {
  412. X = ((X << 2) | (X >> 26)) & 0x0FFFFFFF;
  413. Y = ((Y << 2) | (Y >> 26)) & 0x0FFFFFFF;
  414. }
  415. *SK++ = ((X << 4) & 0x24000000) | ((X << 28) & 0x10000000)
  416. | ((X << 14) & 0x08000000) | ((X << 18) & 0x02080000)
  417. | ((X << 6) & 0x01000000) | ((X << 9) & 0x00200000)
  418. | ((X >> 1) & 0x00100000) | ((X << 10) & 0x00040000)
  419. | ((X << 2) & 0x00020000) | ((X >> 10) & 0x00010000)
  420. | ((Y >> 13) & 0x00002000) | ((Y >> 4) & 0x00001000)
  421. | ((Y << 6) & 0x00000800) | ((Y >> 1) & 0x00000400)
  422. | ((Y >> 14) & 0x00000200) | ((Y ) & 0x00000100)
  423. | ((Y >> 5) & 0x00000020) | ((Y >> 10) & 0x00000010)
  424. | ((Y >> 3) & 0x00000008) | ((Y >> 18) & 0x00000004)
  425. | ((Y >> 26) & 0x00000002) | ((Y >> 24) & 0x00000001);
  426. *SK++ = ((X << 15) & 0x20000000) | ((X << 17) & 0x10000000)
  427. | ((X << 10) & 0x08000000) | ((X << 22) & 0x04000000)
  428. | ((X >> 2) & 0x02000000) | ((X << 1) & 0x01000000)
  429. | ((X << 16) & 0x00200000) | ((X << 11) & 0x00100000)
  430. | ((X << 3) & 0x00080000) | ((X >> 6) & 0x00040000)
  431. | ((X << 15) & 0x00020000) | ((X >> 4) & 0x00010000)
  432. | ((Y >> 2) & 0x00002000) | ((Y << 8) & 0x00001000)
  433. | ((Y >> 14) & 0x00000808) | ((Y >> 9) & 0x00000400)
  434. | ((Y ) & 0x00000200) | ((Y << 7) & 0x00000100)
  435. | ((Y >> 7) & 0x00000020) | ((Y >> 3) & 0x00000011)
  436. | ((Y << 2) & 0x00000004) | ((Y >> 21) & 0x00000002);
  437. }
  438. }
  439. #endif /* !MBEDTLS_DES_SETKEY_ALT */
  440. /*
  441. * DES key schedule (56-bit, encryption)
  442. */
  443. int mbedtls_des_setkey_enc( mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE] )
  444. {
  445. mbedtls_des_setkey( ctx->sk, key );
  446. return( 0 );
  447. }
  448. /*
  449. * DES key schedule (56-bit, decryption)
  450. */
  451. int mbedtls_des_setkey_dec( mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE] )
  452. {
  453. int i;
  454. mbedtls_des_setkey( ctx->sk, key );
  455. for( i = 0; i < 16; i += 2 )
  456. {
  457. SWAP( ctx->sk[i ], ctx->sk[30 - i] );
  458. SWAP( ctx->sk[i + 1], ctx->sk[31 - i] );
  459. }
  460. return( 0 );
  461. }
  462. static void des3_set2key( uint32_t esk[96],
  463. uint32_t dsk[96],
  464. const unsigned char key[MBEDTLS_DES_KEY_SIZE*2] )
  465. {
  466. int i;
  467. mbedtls_des_setkey( esk, key );
  468. mbedtls_des_setkey( dsk + 32, key + 8 );
  469. for( i = 0; i < 32; i += 2 )
  470. {
  471. dsk[i ] = esk[30 - i];
  472. dsk[i + 1] = esk[31 - i];
  473. esk[i + 32] = dsk[62 - i];
  474. esk[i + 33] = dsk[63 - i];
  475. esk[i + 64] = esk[i ];
  476. esk[i + 65] = esk[i + 1];
  477. dsk[i + 64] = dsk[i ];
  478. dsk[i + 65] = dsk[i + 1];
  479. }
  480. }
  481. /*
  482. * Triple-DES key schedule (112-bit, encryption)
  483. */
  484. int mbedtls_des3_set2key_enc( mbedtls_des3_context *ctx,
  485. const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2] )
  486. {
  487. uint32_t sk[96];
  488. des3_set2key( ctx->sk, sk, key );
  489. mbedtls_platform_zeroize( sk, sizeof( sk ) );
  490. return( 0 );
  491. }
  492. /*
  493. * Triple-DES key schedule (112-bit, decryption)
  494. */
  495. int mbedtls_des3_set2key_dec( mbedtls_des3_context *ctx,
  496. const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2] )
  497. {
  498. uint32_t sk[96];
  499. des3_set2key( sk, ctx->sk, key );
  500. mbedtls_platform_zeroize( sk, sizeof( sk ) );
  501. return( 0 );
  502. }
  503. static void des3_set3key( uint32_t esk[96],
  504. uint32_t dsk[96],
  505. const unsigned char key[24] )
  506. {
  507. int i;
  508. mbedtls_des_setkey( esk, key );
  509. mbedtls_des_setkey( dsk + 32, key + 8 );
  510. mbedtls_des_setkey( esk + 64, key + 16 );
  511. for( i = 0; i < 32; i += 2 )
  512. {
  513. dsk[i ] = esk[94 - i];
  514. dsk[i + 1] = esk[95 - i];
  515. esk[i + 32] = dsk[62 - i];
  516. esk[i + 33] = dsk[63 - i];
  517. dsk[i + 64] = esk[30 - i];
  518. dsk[i + 65] = esk[31 - i];
  519. }
  520. }
  521. /*
  522. * Triple-DES key schedule (168-bit, encryption)
  523. */
  524. int mbedtls_des3_set3key_enc( mbedtls_des3_context *ctx,
  525. const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3] )
  526. {
  527. uint32_t sk[96];
  528. des3_set3key( ctx->sk, sk, key );
  529. mbedtls_platform_zeroize( sk, sizeof( sk ) );
  530. return( 0 );
  531. }
  532. /*
  533. * Triple-DES key schedule (168-bit, decryption)
  534. */
  535. int mbedtls_des3_set3key_dec( mbedtls_des3_context *ctx,
  536. const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3] )
  537. {
  538. uint32_t sk[96];
  539. des3_set3key( sk, ctx->sk, key );
  540. mbedtls_platform_zeroize( sk, sizeof( sk ) );
  541. return( 0 );
  542. }
  543. /*
  544. * DES-ECB block encryption/decryption
  545. */
  546. #if !defined(MBEDTLS_DES_CRYPT_ECB_ALT)
  547. int mbedtls_des_crypt_ecb( mbedtls_des_context *ctx,
  548. const unsigned char input[8],
  549. unsigned char output[8] )
  550. {
  551. int i;
  552. uint32_t X, Y, T, *SK;
  553. SK = ctx->sk;
  554. GET_UINT32_BE( X, input, 0 );
  555. GET_UINT32_BE( Y, input, 4 );
  556. DES_IP( X, Y );
  557. for( i = 0; i < 8; i++ )
  558. {
  559. DES_ROUND( Y, X );
  560. DES_ROUND( X, Y );
  561. }
  562. DES_FP( Y, X );
  563. PUT_UINT32_BE( Y, output, 0 );
  564. PUT_UINT32_BE( X, output, 4 );
  565. return( 0 );
  566. }
  567. #endif /* !MBEDTLS_DES_CRYPT_ECB_ALT */
  568. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  569. /*
  570. * DES-CBC buffer encryption/decryption
  571. */
  572. int mbedtls_des_crypt_cbc( mbedtls_des_context *ctx,
  573. int mode,
  574. size_t length,
  575. unsigned char iv[8],
  576. const unsigned char *input,
  577. unsigned char *output )
  578. {
  579. int i;
  580. unsigned char temp[8];
  581. if( length % 8 )
  582. return( MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH );
  583. if( mode == MBEDTLS_DES_ENCRYPT )
  584. {
  585. while( length > 0 )
  586. {
  587. for( i = 0; i < 8; i++ )
  588. output[i] = (unsigned char)( input[i] ^ iv[i] );
  589. mbedtls_des_crypt_ecb( ctx, output, output );
  590. memcpy( iv, output, 8 );
  591. input += 8;
  592. output += 8;
  593. length -= 8;
  594. }
  595. }
  596. else /* MBEDTLS_DES_DECRYPT */
  597. {
  598. while( length > 0 )
  599. {
  600. memcpy( temp, input, 8 );
  601. mbedtls_des_crypt_ecb( ctx, input, output );
  602. for( i = 0; i < 8; i++ )
  603. output[i] = (unsigned char)( output[i] ^ iv[i] );
  604. memcpy( iv, temp, 8 );
  605. input += 8;
  606. output += 8;
  607. length -= 8;
  608. }
  609. }
  610. return( 0 );
  611. }
  612. #endif /* MBEDTLS_CIPHER_MODE_CBC */
  613. /*
  614. * 3DES-ECB block encryption/decryption
  615. */
  616. #if !defined(MBEDTLS_DES3_CRYPT_ECB_ALT)
  617. int mbedtls_des3_crypt_ecb( mbedtls_des3_context *ctx,
  618. const unsigned char input[8],
  619. unsigned char output[8] )
  620. {
  621. int i;
  622. uint32_t X, Y, T, *SK;
  623. SK = ctx->sk;
  624. GET_UINT32_BE( X, input, 0 );
  625. GET_UINT32_BE( Y, input, 4 );
  626. DES_IP( X, Y );
  627. for( i = 0; i < 8; i++ )
  628. {
  629. DES_ROUND( Y, X );
  630. DES_ROUND( X, Y );
  631. }
  632. for( i = 0; i < 8; i++ )
  633. {
  634. DES_ROUND( X, Y );
  635. DES_ROUND( Y, X );
  636. }
  637. for( i = 0; i < 8; i++ )
  638. {
  639. DES_ROUND( Y, X );
  640. DES_ROUND( X, Y );
  641. }
  642. DES_FP( Y, X );
  643. PUT_UINT32_BE( Y, output, 0 );
  644. PUT_UINT32_BE( X, output, 4 );
  645. return( 0 );
  646. }
  647. #endif /* !MBEDTLS_DES3_CRYPT_ECB_ALT */
  648. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  649. /*
  650. * 3DES-CBC buffer encryption/decryption
  651. */
  652. int mbedtls_des3_crypt_cbc( mbedtls_des3_context *ctx,
  653. int mode,
  654. size_t length,
  655. unsigned char iv[8],
  656. const unsigned char *input,
  657. unsigned char *output )
  658. {
  659. int i;
  660. unsigned char temp[8];
  661. if( length % 8 )
  662. return( MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH );
  663. if( mode == MBEDTLS_DES_ENCRYPT )
  664. {
  665. while( length > 0 )
  666. {
  667. for( i = 0; i < 8; i++ )
  668. output[i] = (unsigned char)( input[i] ^ iv[i] );
  669. mbedtls_des3_crypt_ecb( ctx, output, output );
  670. memcpy( iv, output, 8 );
  671. input += 8;
  672. output += 8;
  673. length -= 8;
  674. }
  675. }
  676. else /* MBEDTLS_DES_DECRYPT */
  677. {
  678. while( length > 0 )
  679. {
  680. memcpy( temp, input, 8 );
  681. mbedtls_des3_crypt_ecb( ctx, input, output );
  682. for( i = 0; i < 8; i++ )
  683. output[i] = (unsigned char)( output[i] ^ iv[i] );
  684. memcpy( iv, temp, 8 );
  685. input += 8;
  686. output += 8;
  687. length -= 8;
  688. }
  689. }
  690. return( 0 );
  691. }
  692. #endif /* MBEDTLS_CIPHER_MODE_CBC */
  693. #endif /* !MBEDTLS_DES_ALT */
  694. #if defined(MBEDTLS_SELF_TEST)
  695. /*
  696. * DES and 3DES test vectors from:
  697. *
  698. * http://csrc.nist.gov/groups/STM/cavp/documents/des/tripledes-vectors.zip
  699. */
  700. static const unsigned char des3_test_keys[24] =
  701. {
  702. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  703. 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01,
  704. 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01, 0x23
  705. };
  706. static const unsigned char des3_test_buf[8] =
  707. {
  708. 0x4E, 0x6F, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74
  709. };
  710. static const unsigned char des3_test_ecb_dec[3][8] =
  711. {
  712. { 0x37, 0x2B, 0x98, 0xBF, 0x52, 0x65, 0xB0, 0x59 },
  713. { 0xC2, 0x10, 0x19, 0x9C, 0x38, 0x5A, 0x65, 0xA1 },
  714. { 0xA2, 0x70, 0x56, 0x68, 0x69, 0xE5, 0x15, 0x1D }
  715. };
  716. static const unsigned char des3_test_ecb_enc[3][8] =
  717. {
  718. { 0x1C, 0xD5, 0x97, 0xEA, 0x84, 0x26, 0x73, 0xFB },
  719. { 0xB3, 0x92, 0x4D, 0xF3, 0xC5, 0xB5, 0x42, 0x93 },
  720. { 0xDA, 0x37, 0x64, 0x41, 0xBA, 0x6F, 0x62, 0x6F }
  721. };
  722. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  723. static const unsigned char des3_test_iv[8] =
  724. {
  725. 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF,
  726. };
  727. static const unsigned char des3_test_cbc_dec[3][8] =
  728. {
  729. { 0x58, 0xD9, 0x48, 0xEF, 0x85, 0x14, 0x65, 0x9A },
  730. { 0x5F, 0xC8, 0x78, 0xD4, 0xD7, 0x92, 0xD9, 0x54 },
  731. { 0x25, 0xF9, 0x75, 0x85, 0xA8, 0x1E, 0x48, 0xBF }
  732. };
  733. static const unsigned char des3_test_cbc_enc[3][8] =
  734. {
  735. { 0x91, 0x1C, 0x6D, 0xCF, 0x48, 0xA7, 0xC3, 0x4D },
  736. { 0x60, 0x1A, 0x76, 0x8F, 0xA1, 0xF9, 0x66, 0xF1 },
  737. { 0xA1, 0x50, 0x0F, 0x99, 0xB2, 0xCD, 0x64, 0x76 }
  738. };
  739. #endif /* MBEDTLS_CIPHER_MODE_CBC */
  740. /*
  741. * Checkup routine
  742. */
  743. int mbedtls_des_self_test( int verbose )
  744. {
  745. int i, j, u, v, ret = 0;
  746. mbedtls_des_context ctx;
  747. mbedtls_des3_context ctx3;
  748. unsigned char buf[8];
  749. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  750. unsigned char prv[8];
  751. unsigned char iv[8];
  752. #endif
  753. mbedtls_des_init( &ctx );
  754. mbedtls_des3_init( &ctx3 );
  755. /*
  756. * ECB mode
  757. */
  758. for( i = 0; i < 6; i++ )
  759. {
  760. u = i >> 1;
  761. v = i & 1;
  762. if( verbose != 0 )
  763. mbedtls_printf( " DES%c-ECB-%3d (%s): ",
  764. ( u == 0 ) ? ' ' : '3', 56 + u * 56,
  765. ( v == MBEDTLS_DES_DECRYPT ) ? "dec" : "enc" );
  766. memcpy( buf, des3_test_buf, 8 );
  767. switch( i )
  768. {
  769. case 0:
  770. mbedtls_des_setkey_dec( &ctx, des3_test_keys );
  771. break;
  772. case 1:
  773. mbedtls_des_setkey_enc( &ctx, des3_test_keys );
  774. break;
  775. case 2:
  776. mbedtls_des3_set2key_dec( &ctx3, des3_test_keys );
  777. break;
  778. case 3:
  779. mbedtls_des3_set2key_enc( &ctx3, des3_test_keys );
  780. break;
  781. case 4:
  782. mbedtls_des3_set3key_dec( &ctx3, des3_test_keys );
  783. break;
  784. case 5:
  785. mbedtls_des3_set3key_enc( &ctx3, des3_test_keys );
  786. break;
  787. default:
  788. return( 1 );
  789. }
  790. for( j = 0; j < 100; j++ )
  791. {
  792. if( u == 0 )
  793. mbedtls_des_crypt_ecb( &ctx, buf, buf );
  794. else
  795. mbedtls_des3_crypt_ecb( &ctx3, buf, buf );
  796. }
  797. if( ( v == MBEDTLS_DES_DECRYPT &&
  798. memcmp( buf, des3_test_ecb_dec[u], 8 ) != 0 ) ||
  799. ( v != MBEDTLS_DES_DECRYPT &&
  800. memcmp( buf, des3_test_ecb_enc[u], 8 ) != 0 ) )
  801. {
  802. if( verbose != 0 )
  803. mbedtls_printf( "failed\n" );
  804. ret = 1;
  805. goto exit;
  806. }
  807. if( verbose != 0 )
  808. mbedtls_printf( "passed\n" );
  809. }
  810. if( verbose != 0 )
  811. mbedtls_printf( "\n" );
  812. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  813. /*
  814. * CBC mode
  815. */
  816. for( i = 0; i < 6; i++ )
  817. {
  818. u = i >> 1;
  819. v = i & 1;
  820. if( verbose != 0 )
  821. mbedtls_printf( " DES%c-CBC-%3d (%s): ",
  822. ( u == 0 ) ? ' ' : '3', 56 + u * 56,
  823. ( v == MBEDTLS_DES_DECRYPT ) ? "dec" : "enc" );
  824. memcpy( iv, des3_test_iv, 8 );
  825. memcpy( prv, des3_test_iv, 8 );
  826. memcpy( buf, des3_test_buf, 8 );
  827. switch( i )
  828. {
  829. case 0:
  830. mbedtls_des_setkey_dec( &ctx, des3_test_keys );
  831. break;
  832. case 1:
  833. mbedtls_des_setkey_enc( &ctx, des3_test_keys );
  834. break;
  835. case 2:
  836. mbedtls_des3_set2key_dec( &ctx3, des3_test_keys );
  837. break;
  838. case 3:
  839. mbedtls_des3_set2key_enc( &ctx3, des3_test_keys );
  840. break;
  841. case 4:
  842. mbedtls_des3_set3key_dec( &ctx3, des3_test_keys );
  843. break;
  844. case 5:
  845. mbedtls_des3_set3key_enc( &ctx3, des3_test_keys );
  846. break;
  847. default:
  848. return( 1 );
  849. }
  850. if( v == MBEDTLS_DES_DECRYPT )
  851. {
  852. for( j = 0; j < 100; j++ )
  853. {
  854. if( u == 0 )
  855. mbedtls_des_crypt_cbc( &ctx, v, 8, iv, buf, buf );
  856. else
  857. mbedtls_des3_crypt_cbc( &ctx3, v, 8, iv, buf, buf );
  858. }
  859. }
  860. else
  861. {
  862. for( j = 0; j < 100; j++ )
  863. {
  864. unsigned char tmp[8];
  865. if( u == 0 )
  866. mbedtls_des_crypt_cbc( &ctx, v, 8, iv, buf, buf );
  867. else
  868. mbedtls_des3_crypt_cbc( &ctx3, v, 8, iv, buf, buf );
  869. memcpy( tmp, prv, 8 );
  870. memcpy( prv, buf, 8 );
  871. memcpy( buf, tmp, 8 );
  872. }
  873. memcpy( buf, prv, 8 );
  874. }
  875. if( ( v == MBEDTLS_DES_DECRYPT &&
  876. memcmp( buf, des3_test_cbc_dec[u], 8 ) != 0 ) ||
  877. ( v != MBEDTLS_DES_DECRYPT &&
  878. memcmp( buf, des3_test_cbc_enc[u], 8 ) != 0 ) )
  879. {
  880. if( verbose != 0 )
  881. mbedtls_printf( "failed\n" );
  882. ret = 1;
  883. goto exit;
  884. }
  885. if( verbose != 0 )
  886. mbedtls_printf( "passed\n" );
  887. }
  888. #endif /* MBEDTLS_CIPHER_MODE_CBC */
  889. if( verbose != 0 )
  890. mbedtls_printf( "\n" );
  891. exit:
  892. mbedtls_des_free( &ctx );
  893. mbedtls_des3_free( &ctx3 );
  894. return( ret );
  895. }
  896. #endif /* MBEDTLS_SELF_TEST */
  897. #endif /* MBEDTLS_DES_C */