2
0

seed.c 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848
  1. /*
  2. * Copyright (c) 2007 KISA(Korea Information Security Agency). All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Neither the name of author nor the names of its contributors may
  10. * be used to endorse or promote products derived from this software
  11. * without specific prior written permission.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  14. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  15. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  16. * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
  17. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  18. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  19. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  20. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  21. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  22. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  23. * SUCH DAMAGE.
  24. *
  25. */
  26. #ifndef OPENSSL_NO_SEED
  27. # include <stdio.h>
  28. # include <stdlib.h>
  29. # include <string.h>
  30. # ifdef WIN32
  31. # include <memory.h>
  32. # endif
  33. # include <openssl/seed.h>
  34. # include "seed_locl.h"
  35. static seed_word SS[4][256] = { {
  36. 0x2989a1a8, 0x05858184, 0x16c6d2d4,
  37. 0x13c3d3d0, 0x14445054, 0x1d0d111c,
  38. 0x2c8ca0ac, 0x25052124,
  39. 0x1d4d515c, 0x03434340, 0x18081018,
  40. 0x1e0e121c, 0x11415150, 0x3cccf0fc,
  41. 0x0acac2c8, 0x23436360,
  42. 0x28082028, 0x04444044, 0x20002020,
  43. 0x1d8d919c, 0x20c0e0e0, 0x22c2e2e0,
  44. 0x08c8c0c8, 0x17071314,
  45. 0x2585a1a4, 0x0f8f838c, 0x03030300,
  46. 0x3b4b7378, 0x3b8bb3b8, 0x13031310,
  47. 0x12c2d2d0, 0x2ecee2ec,
  48. 0x30407070, 0x0c8c808c, 0x3f0f333c,
  49. 0x2888a0a8, 0x32023230, 0x1dcdd1dc,
  50. 0x36c6f2f4, 0x34447074,
  51. 0x2ccce0ec, 0x15859194, 0x0b0b0308,
  52. 0x17475354, 0x1c4c505c, 0x1b4b5358,
  53. 0x3d8db1bc, 0x01010100,
  54. 0x24042024, 0x1c0c101c, 0x33437370,
  55. 0x18889098, 0x10001010, 0x0cccc0cc,
  56. 0x32c2f2f0, 0x19c9d1d8,
  57. 0x2c0c202c, 0x27c7e3e4, 0x32427270,
  58. 0x03838380, 0x1b8b9398, 0x11c1d1d0,
  59. 0x06868284, 0x09c9c1c8,
  60. 0x20406060, 0x10405050, 0x2383a3a0,
  61. 0x2bcbe3e8, 0x0d0d010c, 0x3686b2b4,
  62. 0x1e8e929c, 0x0f4f434c,
  63. 0x3787b3b4, 0x1a4a5258, 0x06c6c2c4,
  64. 0x38487078, 0x2686a2a4, 0x12021210,
  65. 0x2f8fa3ac, 0x15c5d1d4,
  66. 0x21416160, 0x03c3c3c0, 0x3484b0b4,
  67. 0x01414140, 0x12425250, 0x3d4d717c,
  68. 0x0d8d818c, 0x08080008,
  69. 0x1f0f131c, 0x19899198, 0x00000000,
  70. 0x19091118, 0x04040004, 0x13435350,
  71. 0x37c7f3f4, 0x21c1e1e0,
  72. 0x3dcdf1fc, 0x36467274, 0x2f0f232c,
  73. 0x27072324, 0x3080b0b0, 0x0b8b8388,
  74. 0x0e0e020c, 0x2b8ba3a8,
  75. 0x2282a2a0, 0x2e4e626c, 0x13839390,
  76. 0x0d4d414c, 0x29496168, 0x3c4c707c,
  77. 0x09090108, 0x0a0a0208,
  78. 0x3f8fb3bc, 0x2fcfe3ec, 0x33c3f3f0,
  79. 0x05c5c1c4, 0x07878384, 0x14041014,
  80. 0x3ecef2fc, 0x24446064,
  81. 0x1eced2dc, 0x2e0e222c, 0x0b4b4348,
  82. 0x1a0a1218, 0x06060204, 0x21012120,
  83. 0x2b4b6368, 0x26466264,
  84. 0x02020200, 0x35c5f1f4, 0x12829290,
  85. 0x0a8a8288, 0x0c0c000c, 0x3383b3b0,
  86. 0x3e4e727c, 0x10c0d0d0,
  87. 0x3a4a7278, 0x07474344, 0x16869294,
  88. 0x25c5e1e4, 0x26062224, 0x00808080,
  89. 0x2d8da1ac, 0x1fcfd3dc,
  90. 0x2181a1a0, 0x30003030, 0x37073334,
  91. 0x2e8ea2ac, 0x36063234, 0x15051114,
  92. 0x22022220, 0x38083038,
  93. 0x34c4f0f4, 0x2787a3a4, 0x05454144,
  94. 0x0c4c404c, 0x01818180, 0x29c9e1e8,
  95. 0x04848084, 0x17879394,
  96. 0x35053134, 0x0bcbc3c8, 0x0ecec2cc,
  97. 0x3c0c303c, 0x31417170, 0x11011110,
  98. 0x07c7c3c4, 0x09898188,
  99. 0x35457174, 0x3bcbf3f8, 0x1acad2d8,
  100. 0x38c8f0f8, 0x14849094, 0x19495158,
  101. 0x02828280, 0x04c4c0c4,
  102. 0x3fcff3fc, 0x09494148, 0x39093138,
  103. 0x27476364, 0x00c0c0c0, 0x0fcfc3cc,
  104. 0x17c7d3d4, 0x3888b0b8,
  105. 0x0f0f030c, 0x0e8e828c, 0x02424240,
  106. 0x23032320, 0x11819190, 0x2c4c606c,
  107. 0x1bcbd3d8, 0x2484a0a4,
  108. 0x34043034, 0x31c1f1f0, 0x08484048,
  109. 0x02c2c2c0, 0x2f4f636c, 0x3d0d313c,
  110. 0x2d0d212c, 0x00404040,
  111. 0x3e8eb2bc, 0x3e0e323c, 0x3c8cb0bc,
  112. 0x01c1c1c0, 0x2a8aa2a8, 0x3a8ab2b8,
  113. 0x0e4e424c, 0x15455154,
  114. 0x3b0b3338, 0x1cccd0dc, 0x28486068,
  115. 0x3f4f737c, 0x1c8c909c, 0x18c8d0d8,
  116. 0x0a4a4248, 0x16465254,
  117. 0x37477374, 0x2080a0a0, 0x2dcde1ec,
  118. 0x06464244, 0x3585b1b4, 0x2b0b2328,
  119. 0x25456164, 0x3acaf2f8,
  120. 0x23c3e3e0, 0x3989b1b8, 0x3181b1b0,
  121. 0x1f8f939c, 0x1e4e525c, 0x39c9f1f8,
  122. 0x26c6e2e4, 0x3282b2b0,
  123. 0x31013130, 0x2acae2e8, 0x2d4d616c,
  124. 0x1f4f535c, 0x24c4e0e4, 0x30c0f0f0,
  125. 0x0dcdc1cc, 0x08888088,
  126. 0x16061214, 0x3a0a3238, 0x18485058,
  127. 0x14c4d0d4, 0x22426260, 0x29092128,
  128. 0x07070304, 0x33033330,
  129. 0x28c8e0e8, 0x1b0b1318, 0x05050104,
  130. 0x39497178, 0x10809090, 0x2a4a6268,
  131. 0x2a0a2228, 0x1a8a9298}, {
  132. 0x38380830,
  133. 0xe828c8e0,
  134. 0x2c2d0d21,
  135. 0xa42686a2,
  136. 0xcc0fcfc3,
  137. 0xdc1eced2,
  138. 0xb03383b3,
  139. 0xb83888b0,
  140. 0xac2f8fa3,
  141. 0x60204060,
  142. 0x54154551,
  143. 0xc407c7c3,
  144. 0x44044440,
  145. 0x6c2f4f63,
  146. 0x682b4b63,
  147. 0x581b4b53,
  148. 0xc003c3c3,
  149. 0x60224262,
  150. 0x30330333,
  151. 0xb43585b1,
  152. 0x28290921,
  153. 0xa02080a0,
  154. 0xe022c2e2,
  155. 0xa42787a3,
  156. 0xd013c3d3,
  157. 0x90118191,
  158. 0x10110111,
  159. 0x04060602,
  160. 0x1c1c0c10,
  161. 0xbc3c8cb0,
  162. 0x34360632,
  163. 0x480b4b43,
  164. 0xec2fcfe3,
  165. 0x88088880,
  166. 0x6c2c4c60,
  167. 0xa82888a0,
  168. 0x14170713,
  169. 0xc404c4c0,
  170. 0x14160612,
  171. 0xf434c4f0,
  172. 0xc002c2c2,
  173. 0x44054541,
  174. 0xe021c1e1,
  175. 0xd416c6d2,
  176. 0x3c3f0f33,
  177. 0x3c3d0d31,
  178. 0x8c0e8e82,
  179. 0x98188890,
  180. 0x28280820,
  181. 0x4c0e4e42,
  182. 0xf436c6f2,
  183. 0x3c3e0e32,
  184. 0xa42585a1,
  185. 0xf839c9f1,
  186. 0x0c0d0d01,
  187. 0xdc1fcfd3,
  188. 0xd818c8d0,
  189. 0x282b0b23,
  190. 0x64264662,
  191. 0x783a4a72,
  192. 0x24270723,
  193. 0x2c2f0f23,
  194. 0xf031c1f1,
  195. 0x70324272,
  196. 0x40024242,
  197. 0xd414c4d0,
  198. 0x40014141,
  199. 0xc000c0c0,
  200. 0x70334373,
  201. 0x64274763,
  202. 0xac2c8ca0,
  203. 0x880b8b83,
  204. 0xf437c7f3,
  205. 0xac2d8da1,
  206. 0x80008080,
  207. 0x1c1f0f13,
  208. 0xc80acac2,
  209. 0x2c2c0c20,
  210. 0xa82a8aa2,
  211. 0x34340430,
  212. 0xd012c2d2,
  213. 0x080b0b03,
  214. 0xec2ecee2,
  215. 0xe829c9e1,
  216. 0x5c1d4d51,
  217. 0x94148490,
  218. 0x18180810,
  219. 0xf838c8f0,
  220. 0x54174753,
  221. 0xac2e8ea2,
  222. 0x08080800,
  223. 0xc405c5c1,
  224. 0x10130313,
  225. 0xcc0dcdc1,
  226. 0x84068682,
  227. 0xb83989b1,
  228. 0xfc3fcff3,
  229. 0x7c3d4d71,
  230. 0xc001c1c1,
  231. 0x30310131,
  232. 0xf435c5f1,
  233. 0x880a8a82,
  234. 0x682a4a62,
  235. 0xb03181b1,
  236. 0xd011c1d1,
  237. 0x20200020,
  238. 0xd417c7d3,
  239. 0x00020202,
  240. 0x20220222,
  241. 0x04040400,
  242. 0x68284860,
  243. 0x70314171,
  244. 0x04070703,
  245. 0xd81bcbd3,
  246. 0x9c1d8d91,
  247. 0x98198991,
  248. 0x60214161,
  249. 0xbc3e8eb2,
  250. 0xe426c6e2,
  251. 0x58194951,
  252. 0xdc1dcdd1,
  253. 0x50114151,
  254. 0x90108090,
  255. 0xdc1cccd0,
  256. 0x981a8a92,
  257. 0xa02383a3,
  258. 0xa82b8ba3,
  259. 0xd010c0d0,
  260. 0x80018181,
  261. 0x0c0f0f03,
  262. 0x44074743,
  263. 0x181a0a12,
  264. 0xe023c3e3,
  265. 0xec2ccce0,
  266. 0x8c0d8d81,
  267. 0xbc3f8fb3,
  268. 0x94168692,
  269. 0x783b4b73,
  270. 0x5c1c4c50,
  271. 0xa02282a2,
  272. 0xa02181a1,
  273. 0x60234363,
  274. 0x20230323,
  275. 0x4c0d4d41,
  276. 0xc808c8c0,
  277. 0x9c1e8e92,
  278. 0x9c1c8c90,
  279. 0x383a0a32,
  280. 0x0c0c0c00,
  281. 0x2c2e0e22,
  282. 0xb83a8ab2,
  283. 0x6c2e4e62,
  284. 0x9c1f8f93,
  285. 0x581a4a52,
  286. 0xf032c2f2,
  287. 0x90128292,
  288. 0xf033c3f3,
  289. 0x48094941,
  290. 0x78384870,
  291. 0xcc0cccc0,
  292. 0x14150511,
  293. 0xf83bcbf3,
  294. 0x70304070,
  295. 0x74354571,
  296. 0x7c3f4f73,
  297. 0x34350531,
  298. 0x10100010,
  299. 0x00030303,
  300. 0x64244460,
  301. 0x6c2d4d61,
  302. 0xc406c6c2,
  303. 0x74344470,
  304. 0xd415c5d1,
  305. 0xb43484b0,
  306. 0xe82acae2,
  307. 0x08090901,
  308. 0x74364672,
  309. 0x18190911,
  310. 0xfc3ecef2,
  311. 0x40004040,
  312. 0x10120212,
  313. 0xe020c0e0,
  314. 0xbc3d8db1,
  315. 0x04050501,
  316. 0xf83acaf2,
  317. 0x00010101,
  318. 0xf030c0f0,
  319. 0x282a0a22,
  320. 0x5c1e4e52,
  321. 0xa82989a1,
  322. 0x54164652,
  323. 0x40034343,
  324. 0x84058581,
  325. 0x14140410,
  326. 0x88098981,
  327. 0x981b8b93,
  328. 0xb03080b0,
  329. 0xe425c5e1,
  330. 0x48084840,
  331. 0x78394971,
  332. 0x94178793,
  333. 0xfc3cccf0,
  334. 0x1c1e0e12,
  335. 0x80028282,
  336. 0x20210121,
  337. 0x8c0c8c80,
  338. 0x181b0b13,
  339. 0x5c1f4f53,
  340. 0x74374773,
  341. 0x54144450,
  342. 0xb03282b2,
  343. 0x1c1d0d11,
  344. 0x24250521,
  345. 0x4c0f4f43,
  346. 0x00000000,
  347. 0x44064642,
  348. 0xec2dcde1,
  349. 0x58184850,
  350. 0x50124252,
  351. 0xe82bcbe3,
  352. 0x7c3e4e72,
  353. 0xd81acad2,
  354. 0xc809c9c1,
  355. 0xfc3dcdf1,
  356. 0x30300030,
  357. 0x94158591,
  358. 0x64254561,
  359. 0x3c3c0c30,
  360. 0xb43686b2,
  361. 0xe424c4e0,
  362. 0xb83b8bb3,
  363. 0x7c3c4c70,
  364. 0x0c0e0e02,
  365. 0x50104050,
  366. 0x38390931,
  367. 0x24260622,
  368. 0x30320232,
  369. 0x84048480,
  370. 0x68294961,
  371. 0x90138393,
  372. 0x34370733,
  373. 0xe427c7e3,
  374. 0x24240420,
  375. 0xa42484a0,
  376. 0xc80bcbc3,
  377. 0x50134353,
  378. 0x080a0a02,
  379. 0x84078783,
  380. 0xd819c9d1,
  381. 0x4c0c4c40,
  382. 0x80038383,
  383. 0x8c0f8f83,
  384. 0xcc0ecec2,
  385. 0x383b0b33,
  386. 0x480a4a42,
  387. 0xb43787b3}, {
  388. 0xa1a82989,
  389. 0x81840585,
  390. 0xd2d416c6,
  391. 0xd3d013c3,
  392. 0x50541444,
  393. 0x111c1d0d,
  394. 0xa0ac2c8c,
  395. 0x21242505,
  396. 0x515c1d4d,
  397. 0x43400343,
  398. 0x10181808,
  399. 0x121c1e0e,
  400. 0x51501141,
  401. 0xf0fc3ccc,
  402. 0xc2c80aca,
  403. 0x63602343,
  404. 0x20282808,
  405. 0x40440444,
  406. 0x20202000,
  407. 0x919c1d8d,
  408. 0xe0e020c0,
  409. 0xe2e022c2,
  410. 0xc0c808c8,
  411. 0x13141707,
  412. 0xa1a42585,
  413. 0x838c0f8f,
  414. 0x03000303,
  415. 0x73783b4b,
  416. 0xb3b83b8b,
  417. 0x13101303,
  418. 0xd2d012c2,
  419. 0xe2ec2ece,
  420. 0x70703040,
  421. 0x808c0c8c,
  422. 0x333c3f0f,
  423. 0xa0a82888,
  424. 0x32303202,
  425. 0xd1dc1dcd,
  426. 0xf2f436c6,
  427. 0x70743444,
  428. 0xe0ec2ccc,
  429. 0x91941585,
  430. 0x03080b0b,
  431. 0x53541747,
  432. 0x505c1c4c,
  433. 0x53581b4b,
  434. 0xb1bc3d8d,
  435. 0x01000101,
  436. 0x20242404,
  437. 0x101c1c0c,
  438. 0x73703343,
  439. 0x90981888,
  440. 0x10101000,
  441. 0xc0cc0ccc,
  442. 0xf2f032c2,
  443. 0xd1d819c9,
  444. 0x202c2c0c,
  445. 0xe3e427c7,
  446. 0x72703242,
  447. 0x83800383,
  448. 0x93981b8b,
  449. 0xd1d011c1,
  450. 0x82840686,
  451. 0xc1c809c9,
  452. 0x60602040,
  453. 0x50501040,
  454. 0xa3a02383,
  455. 0xe3e82bcb,
  456. 0x010c0d0d,
  457. 0xb2b43686,
  458. 0x929c1e8e,
  459. 0x434c0f4f,
  460. 0xb3b43787,
  461. 0x52581a4a,
  462. 0xc2c406c6,
  463. 0x70783848,
  464. 0xa2a42686,
  465. 0x12101202,
  466. 0xa3ac2f8f,
  467. 0xd1d415c5,
  468. 0x61602141,
  469. 0xc3c003c3,
  470. 0xb0b43484,
  471. 0x41400141,
  472. 0x52501242,
  473. 0x717c3d4d,
  474. 0x818c0d8d,
  475. 0x00080808,
  476. 0x131c1f0f,
  477. 0x91981989,
  478. 0x00000000,
  479. 0x11181909,
  480. 0x00040404,
  481. 0x53501343,
  482. 0xf3f437c7,
  483. 0xe1e021c1,
  484. 0xf1fc3dcd,
  485. 0x72743646,
  486. 0x232c2f0f,
  487. 0x23242707,
  488. 0xb0b03080,
  489. 0x83880b8b,
  490. 0x020c0e0e,
  491. 0xa3a82b8b,
  492. 0xa2a02282,
  493. 0x626c2e4e,
  494. 0x93901383,
  495. 0x414c0d4d,
  496. 0x61682949,
  497. 0x707c3c4c,
  498. 0x01080909,
  499. 0x02080a0a,
  500. 0xb3bc3f8f,
  501. 0xe3ec2fcf,
  502. 0xf3f033c3,
  503. 0xc1c405c5,
  504. 0x83840787,
  505. 0x10141404,
  506. 0xf2fc3ece,
  507. 0x60642444,
  508. 0xd2dc1ece,
  509. 0x222c2e0e,
  510. 0x43480b4b,
  511. 0x12181a0a,
  512. 0x02040606,
  513. 0x21202101,
  514. 0x63682b4b,
  515. 0x62642646,
  516. 0x02000202,
  517. 0xf1f435c5,
  518. 0x92901282,
  519. 0x82880a8a,
  520. 0x000c0c0c,
  521. 0xb3b03383,
  522. 0x727c3e4e,
  523. 0xd0d010c0,
  524. 0x72783a4a,
  525. 0x43440747,
  526. 0x92941686,
  527. 0xe1e425c5,
  528. 0x22242606,
  529. 0x80800080,
  530. 0xa1ac2d8d,
  531. 0xd3dc1fcf,
  532. 0xa1a02181,
  533. 0x30303000,
  534. 0x33343707,
  535. 0xa2ac2e8e,
  536. 0x32343606,
  537. 0x11141505,
  538. 0x22202202,
  539. 0x30383808,
  540. 0xf0f434c4,
  541. 0xa3a42787,
  542. 0x41440545,
  543. 0x404c0c4c,
  544. 0x81800181,
  545. 0xe1e829c9,
  546. 0x80840484,
  547. 0x93941787,
  548. 0x31343505,
  549. 0xc3c80bcb,
  550. 0xc2cc0ece,
  551. 0x303c3c0c,
  552. 0x71703141,
  553. 0x11101101,
  554. 0xc3c407c7,
  555. 0x81880989,
  556. 0x71743545,
  557. 0xf3f83bcb,
  558. 0xd2d81aca,
  559. 0xf0f838c8,
  560. 0x90941484,
  561. 0x51581949,
  562. 0x82800282,
  563. 0xc0c404c4,
  564. 0xf3fc3fcf,
  565. 0x41480949,
  566. 0x31383909,
  567. 0x63642747,
  568. 0xc0c000c0,
  569. 0xc3cc0fcf,
  570. 0xd3d417c7,
  571. 0xb0b83888,
  572. 0x030c0f0f,
  573. 0x828c0e8e,
  574. 0x42400242,
  575. 0x23202303,
  576. 0x91901181,
  577. 0x606c2c4c,
  578. 0xd3d81bcb,
  579. 0xa0a42484,
  580. 0x30343404,
  581. 0xf1f031c1,
  582. 0x40480848,
  583. 0xc2c002c2,
  584. 0x636c2f4f,
  585. 0x313c3d0d,
  586. 0x212c2d0d,
  587. 0x40400040,
  588. 0xb2bc3e8e,
  589. 0x323c3e0e,
  590. 0xb0bc3c8c,
  591. 0xc1c001c1,
  592. 0xa2a82a8a,
  593. 0xb2b83a8a,
  594. 0x424c0e4e,
  595. 0x51541545,
  596. 0x33383b0b,
  597. 0xd0dc1ccc,
  598. 0x60682848,
  599. 0x737c3f4f,
  600. 0x909c1c8c,
  601. 0xd0d818c8,
  602. 0x42480a4a,
  603. 0x52541646,
  604. 0x73743747,
  605. 0xa0a02080,
  606. 0xe1ec2dcd,
  607. 0x42440646,
  608. 0xb1b43585,
  609. 0x23282b0b,
  610. 0x61642545,
  611. 0xf2f83aca,
  612. 0xe3e023c3,
  613. 0xb1b83989,
  614. 0xb1b03181,
  615. 0x939c1f8f,
  616. 0x525c1e4e,
  617. 0xf1f839c9,
  618. 0xe2e426c6,
  619. 0xb2b03282,
  620. 0x31303101,
  621. 0xe2e82aca,
  622. 0x616c2d4d,
  623. 0x535c1f4f,
  624. 0xe0e424c4,
  625. 0xf0f030c0,
  626. 0xc1cc0dcd,
  627. 0x80880888,
  628. 0x12141606,
  629. 0x32383a0a,
  630. 0x50581848,
  631. 0xd0d414c4,
  632. 0x62602242,
  633. 0x21282909,
  634. 0x03040707,
  635. 0x33303303,
  636. 0xe0e828c8,
  637. 0x13181b0b,
  638. 0x01040505,
  639. 0x71783949,
  640. 0x90901080,
  641. 0x62682a4a,
  642. 0x22282a0a,
  643. 0x92981a8a},
  644. {
  645. 0x08303838, 0xc8e0e828, 0x0d212c2d, 0x86a2a426, 0xcfc3cc0f, 0xced2dc1e,
  646. 0x83b3b033, 0x88b0b838,
  647. 0x8fa3ac2f, 0x40606020, 0x45515415, 0xc7c3c407, 0x44404404, 0x4f636c2f,
  648. 0x4b63682b, 0x4b53581b,
  649. 0xc3c3c003, 0x42626022, 0x03333033, 0x85b1b435, 0x09212829, 0x80a0a020,
  650. 0xc2e2e022, 0x87a3a427,
  651. 0xc3d3d013, 0x81919011, 0x01111011, 0x06020406, 0x0c101c1c, 0x8cb0bc3c,
  652. 0x06323436, 0x4b43480b,
  653. 0xcfe3ec2f, 0x88808808, 0x4c606c2c, 0x88a0a828, 0x07131417, 0xc4c0c404,
  654. 0x06121416, 0xc4f0f434,
  655. 0xc2c2c002, 0x45414405, 0xc1e1e021, 0xc6d2d416, 0x0f333c3f, 0x0d313c3d,
  656. 0x8e828c0e, 0x88909818,
  657. 0x08202828, 0x4e424c0e, 0xc6f2f436, 0x0e323c3e, 0x85a1a425, 0xc9f1f839,
  658. 0x0d010c0d, 0xcfd3dc1f,
  659. 0xc8d0d818, 0x0b23282b, 0x46626426, 0x4a72783a, 0x07232427, 0x0f232c2f,
  660. 0xc1f1f031, 0x42727032,
  661. 0x42424002, 0xc4d0d414, 0x41414001, 0xc0c0c000, 0x43737033, 0x47636427,
  662. 0x8ca0ac2c, 0x8b83880b,
  663. 0xc7f3f437, 0x8da1ac2d, 0x80808000, 0x0f131c1f, 0xcac2c80a, 0x0c202c2c,
  664. 0x8aa2a82a, 0x04303434,
  665. 0xc2d2d012, 0x0b03080b, 0xcee2ec2e, 0xc9e1e829, 0x4d515c1d, 0x84909414,
  666. 0x08101818, 0xc8f0f838,
  667. 0x47535417, 0x8ea2ac2e, 0x08000808, 0xc5c1c405, 0x03131013, 0xcdc1cc0d,
  668. 0x86828406, 0x89b1b839,
  669. 0xcff3fc3f, 0x4d717c3d, 0xc1c1c001, 0x01313031, 0xc5f1f435, 0x8a82880a,
  670. 0x4a62682a, 0x81b1b031,
  671. 0xc1d1d011, 0x00202020, 0xc7d3d417, 0x02020002, 0x02222022, 0x04000404,
  672. 0x48606828, 0x41717031,
  673. 0x07030407, 0xcbd3d81b, 0x8d919c1d, 0x89919819, 0x41616021, 0x8eb2bc3e,
  674. 0xc6e2e426, 0x49515819,
  675. 0xcdd1dc1d, 0x41515011, 0x80909010, 0xccd0dc1c, 0x8a92981a, 0x83a3a023,
  676. 0x8ba3a82b, 0xc0d0d010,
  677. 0x81818001, 0x0f030c0f, 0x47434407, 0x0a12181a, 0xc3e3e023, 0xcce0ec2c,
  678. 0x8d818c0d, 0x8fb3bc3f,
  679. 0x86929416, 0x4b73783b, 0x4c505c1c, 0x82a2a022, 0x81a1a021, 0x43636023,
  680. 0x03232023, 0x4d414c0d,
  681. 0xc8c0c808, 0x8e929c1e, 0x8c909c1c, 0x0a32383a, 0x0c000c0c, 0x0e222c2e,
  682. 0x8ab2b83a, 0x4e626c2e,
  683. 0x8f939c1f, 0x4a52581a, 0xc2f2f032, 0x82929012, 0xc3f3f033, 0x49414809,
  684. 0x48707838, 0xccc0cc0c,
  685. 0x05111415, 0xcbf3f83b, 0x40707030, 0x45717435, 0x4f737c3f, 0x05313435,
  686. 0x00101010, 0x03030003,
  687. 0x44606424, 0x4d616c2d, 0xc6c2c406, 0x44707434, 0xc5d1d415, 0x84b0b434,
  688. 0xcae2e82a, 0x09010809,
  689. 0x46727436, 0x09111819, 0xcef2fc3e, 0x40404000, 0x02121012, 0xc0e0e020,
  690. 0x8db1bc3d, 0x05010405,
  691. 0xcaf2f83a, 0x01010001, 0xc0f0f030, 0x0a22282a, 0x4e525c1e, 0x89a1a829,
  692. 0x46525416, 0x43434003,
  693. 0x85818405, 0x04101414, 0x89818809, 0x8b93981b, 0x80b0b030, 0xc5e1e425,
  694. 0x48404808, 0x49717839,
  695. 0x87939417, 0xccf0fc3c, 0x0e121c1e, 0x82828002, 0x01212021, 0x8c808c0c,
  696. 0x0b13181b, 0x4f535c1f,
  697. 0x47737437, 0x44505414, 0x82b2b032, 0x0d111c1d, 0x05212425, 0x4f434c0f,
  698. 0x00000000, 0x46424406,
  699. 0xcde1ec2d, 0x48505818, 0x42525012, 0xcbe3e82b, 0x4e727c3e, 0xcad2d81a,
  700. 0xc9c1c809, 0xcdf1fc3d,
  701. 0x00303030, 0x85919415, 0x45616425, 0x0c303c3c, 0x86b2b436, 0xc4e0e424,
  702. 0x8bb3b83b, 0x4c707c3c,
  703. 0x0e020c0e, 0x40505010, 0x09313839, 0x06222426, 0x02323032, 0x84808404,
  704. 0x49616829, 0x83939013,
  705. 0x07333437, 0xc7e3e427, 0x04202424, 0x84a0a424, 0xcbc3c80b, 0x43535013,
  706. 0x0a02080a, 0x87838407,
  707. 0xc9d1d819, 0x4c404c0c, 0x83838003, 0x8f838c0f, 0xcec2cc0e, 0x0b33383b,
  708. 0x4a42480a, 0x87b3b437}
  709. };
  710. /* key schedule constants - golden ratio */
  711. # define KC0 0x9e3779b9
  712. # define KC1 0x3c6ef373
  713. # define KC2 0x78dde6e6
  714. # define KC3 0xf1bbcdcc
  715. # define KC4 0xe3779b99
  716. # define KC5 0xc6ef3733
  717. # define KC6 0x8dde6e67
  718. # define KC7 0x1bbcdccf
  719. # define KC8 0x3779b99e
  720. # define KC9 0x6ef3733c
  721. # define KC10 0xdde6e678
  722. # define KC11 0xbbcdccf1
  723. # define KC12 0x779b99e3
  724. # define KC13 0xef3733c6
  725. # define KC14 0xde6e678d
  726. # define KC15 0xbcdccf1b
  727. void SEED_set_key(const unsigned char rawkey[SEED_KEY_LENGTH],
  728. SEED_KEY_SCHEDULE *ks)
  729. {
  730. seed_word x1, x2, x3, x4;
  731. seed_word t0, t1;
  732. char2word(rawkey, x1);
  733. char2word(rawkey + 4, x2);
  734. char2word(rawkey + 8, x3);
  735. char2word(rawkey + 12, x4);
  736. t0 = (x1 + x3 - KC0) & 0xffffffff;
  737. t1 = (x2 - x4 + KC0) & 0xffffffff;
  738. KEYUPDATE_TEMP(t0, t1, &ks->data[0]);
  739. KEYSCHEDULE_UPDATE1(t0, t1, x1, x2, x3, x4, KC1);
  740. KEYUPDATE_TEMP(t0, t1, &ks->data[2]);
  741. KEYSCHEDULE_UPDATE0(t0, t1, x1, x2, x3, x4, KC2);
  742. KEYUPDATE_TEMP(t0, t1, &ks->data[4]);
  743. KEYSCHEDULE_UPDATE1(t0, t1, x1, x2, x3, x4, KC3);
  744. KEYUPDATE_TEMP(t0, t1, &ks->data[6]);
  745. KEYSCHEDULE_UPDATE0(t0, t1, x1, x2, x3, x4, KC4);
  746. KEYUPDATE_TEMP(t0, t1, &ks->data[8]);
  747. KEYSCHEDULE_UPDATE1(t0, t1, x1, x2, x3, x4, KC5);
  748. KEYUPDATE_TEMP(t0, t1, &ks->data[10]);
  749. KEYSCHEDULE_UPDATE0(t0, t1, x1, x2, x3, x4, KC6);
  750. KEYUPDATE_TEMP(t0, t1, &ks->data[12]);
  751. KEYSCHEDULE_UPDATE1(t0, t1, x1, x2, x3, x4, KC7);
  752. KEYUPDATE_TEMP(t0, t1, &ks->data[14]);
  753. KEYSCHEDULE_UPDATE0(t0, t1, x1, x2, x3, x4, KC8);
  754. KEYUPDATE_TEMP(t0, t1, &ks->data[16]);
  755. KEYSCHEDULE_UPDATE1(t0, t1, x1, x2, x3, x4, KC9);
  756. KEYUPDATE_TEMP(t0, t1, &ks->data[18]);
  757. KEYSCHEDULE_UPDATE0(t0, t1, x1, x2, x3, x4, KC10);
  758. KEYUPDATE_TEMP(t0, t1, &ks->data[20]);
  759. KEYSCHEDULE_UPDATE1(t0, t1, x1, x2, x3, x4, KC11);
  760. KEYUPDATE_TEMP(t0, t1, &ks->data[22]);
  761. KEYSCHEDULE_UPDATE0(t0, t1, x1, x2, x3, x4, KC12);
  762. KEYUPDATE_TEMP(t0, t1, &ks->data[24]);
  763. KEYSCHEDULE_UPDATE1(t0, t1, x1, x2, x3, x4, KC13);
  764. KEYUPDATE_TEMP(t0, t1, &ks->data[26]);
  765. KEYSCHEDULE_UPDATE0(t0, t1, x1, x2, x3, x4, KC14);
  766. KEYUPDATE_TEMP(t0, t1, &ks->data[28]);
  767. KEYSCHEDULE_UPDATE1(t0, t1, x1, x2, x3, x4, KC15);
  768. KEYUPDATE_TEMP(t0, t1, &ks->data[30]);
  769. }
  770. void SEED_encrypt(const unsigned char s[SEED_BLOCK_SIZE],
  771. unsigned char d[SEED_BLOCK_SIZE],
  772. const SEED_KEY_SCHEDULE *ks)
  773. {
  774. seed_word x1, x2, x3, x4;
  775. seed_word t0, t1;
  776. char2word(s, x1);
  777. char2word(s + 4, x2);
  778. char2word(s + 8, x3);
  779. char2word(s + 12, x4);
  780. E_SEED(t0, t1, x1, x2, x3, x4, 0);
  781. E_SEED(t0, t1, x3, x4, x1, x2, 2);
  782. E_SEED(t0, t1, x1, x2, x3, x4, 4);
  783. E_SEED(t0, t1, x3, x4, x1, x2, 6);
  784. E_SEED(t0, t1, x1, x2, x3, x4, 8);
  785. E_SEED(t0, t1, x3, x4, x1, x2, 10);
  786. E_SEED(t0, t1, x1, x2, x3, x4, 12);
  787. E_SEED(t0, t1, x3, x4, x1, x2, 14);
  788. E_SEED(t0, t1, x1, x2, x3, x4, 16);
  789. E_SEED(t0, t1, x3, x4, x1, x2, 18);
  790. E_SEED(t0, t1, x1, x2, x3, x4, 20);
  791. E_SEED(t0, t1, x3, x4, x1, x2, 22);
  792. E_SEED(t0, t1, x1, x2, x3, x4, 24);
  793. E_SEED(t0, t1, x3, x4, x1, x2, 26);
  794. E_SEED(t0, t1, x1, x2, x3, x4, 28);
  795. E_SEED(t0, t1, x3, x4, x1, x2, 30);
  796. word2char(x3, d);
  797. word2char(x4, d + 4);
  798. word2char(x1, d + 8);
  799. word2char(x2, d + 12);
  800. }
  801. void SEED_decrypt(const unsigned char s[SEED_BLOCK_SIZE],
  802. unsigned char d[SEED_BLOCK_SIZE],
  803. const SEED_KEY_SCHEDULE *ks)
  804. {
  805. seed_word x1, x2, x3, x4;
  806. seed_word t0, t1;
  807. char2word(s, x1);
  808. char2word(s + 4, x2);
  809. char2word(s + 8, x3);
  810. char2word(s + 12, x4);
  811. E_SEED(t0, t1, x1, x2, x3, x4, 30);
  812. E_SEED(t0, t1, x3, x4, x1, x2, 28);
  813. E_SEED(t0, t1, x1, x2, x3, x4, 26);
  814. E_SEED(t0, t1, x3, x4, x1, x2, 24);
  815. E_SEED(t0, t1, x1, x2, x3, x4, 22);
  816. E_SEED(t0, t1, x3, x4, x1, x2, 20);
  817. E_SEED(t0, t1, x1, x2, x3, x4, 18);
  818. E_SEED(t0, t1, x3, x4, x1, x2, 16);
  819. E_SEED(t0, t1, x1, x2, x3, x4, 14);
  820. E_SEED(t0, t1, x3, x4, x1, x2, 12);
  821. E_SEED(t0, t1, x1, x2, x3, x4, 10);
  822. E_SEED(t0, t1, x3, x4, x1, x2, 8);
  823. E_SEED(t0, t1, x1, x2, x3, x4, 6);
  824. E_SEED(t0, t1, x3, x4, x1, x2, 4);
  825. E_SEED(t0, t1, x1, x2, x3, x4, 2);
  826. E_SEED(t0, t1, x3, x4, x1, x2, 0);
  827. word2char(x3, d);
  828. word2char(x4, d + 4);
  829. word2char(x1, d + 8);
  830. word2char(x2, d + 12);
  831. }
  832. #endif /* OPENSSL_NO_SEED */