ecc_test.c 129 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269
  1. /* LibTomCrypt, modular cryptographic library -- Tom St Denis */
  2. /* SPDX-License-Identifier: Unlicense */
  3. #include <tomcrypt_test.h>
  4. #if defined(LTC_MECC)
  5. const unsigned char ltc_ecc_long_pri_test_key[] = { /* private + long public, explicit curve params */
  6. 0x30, 0x82, 0x01, 0x13, 0x02, 0x01, 0x01, 0x04, 0x20, 0x0c, 0xf1, 0xad, 0x2f, 0x03, 0xf7, 0x91,
  7. 0x1b, 0xba, 0x03, 0xcf, 0x23, 0x37, 0xc8, 0xf2, 0xf7, 0x36, 0xce, 0x65, 0xf1, 0x84, 0x2d, 0x7d,
  8. 0x9f, 0x5f, 0x9e, 0x21, 0xd9, 0x5e, 0x49, 0xbd, 0x23, 0xa0, 0x81, 0xa5, 0x30, 0x81, 0xa2, 0x02,
  9. 0x01, 0x01, 0x30, 0x2c, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x01, 0x01, 0x02, 0x21, 0x00,
  10. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  11. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xfc, 0x2f,
  12. 0x30, 0x06, 0x04, 0x01, 0x00, 0x04, 0x01, 0x07, 0x04, 0x41, 0x04, 0x79, 0xbe, 0x66, 0x7e, 0xf9,
  13. 0xdc, 0xbb, 0xac, 0x55, 0xa0, 0x62, 0x95, 0xce, 0x87, 0x0b, 0x07, 0x02, 0x9b, 0xfc, 0xdb, 0x2d,
  14. 0xce, 0x28, 0xd9, 0x59, 0xf2, 0x81, 0x5b, 0x16, 0xf8, 0x17, 0x98, 0x48, 0x3a, 0xda, 0x77, 0x26,
  15. 0xa3, 0xc4, 0x65, 0x5d, 0xa4, 0xfb, 0xfc, 0x0e, 0x11, 0x08, 0xa8, 0xfd, 0x17, 0xb4, 0x48, 0xa6,
  16. 0x85, 0x54, 0x19, 0x9c, 0x47, 0xd0, 0x8f, 0xfb, 0x10, 0xd4, 0xb8, 0x02, 0x21, 0x00, 0xff, 0xff,
  17. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xba, 0xae,
  18. 0xdc, 0xe6, 0xaf, 0x48, 0xa0, 0x3b, 0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36, 0x41, 0x41, 0x02, 0x01,
  19. 0x01, 0xa1, 0x44, 0x03, 0x42, 0x00, 0x04, 0x2a, 0xf9, 0x0b, 0xda, 0xbe, 0x71, 0x66, 0x9e, 0xd1,
  20. 0xcf, 0x12, 0xd0, 0x24, 0xaf, 0xba, 0xb6, 0x7f, 0xfb, 0x96, 0x27, 0x3e, 0x2f, 0xbd, 0x1e, 0xd5,
  21. 0xf9, 0x8d, 0x6c, 0x73, 0x9d, 0xc5, 0x16, 0x91, 0xbd, 0xb2, 0xb9, 0x1b, 0x40, 0x10, 0x5a, 0xb7,
  22. 0x6c, 0x6e, 0x32, 0x5b, 0xf7, 0x63, 0x62, 0x94, 0x24, 0x24, 0xdb, 0xec, 0x3f, 0x8b, 0xe5, 0x6e,
  23. 0x4b, 0x64, 0x37, 0x31, 0x24, 0x79, 0x4d
  24. };
  25. const unsigned long ltc_ecc_long_pri_test_key_sz = sizeof(ltc_ecc_long_pri_test_key);
  26. static unsigned int sizes[] = {
  27. #ifdef LTC_ECC_SECP112R1
  28. 14,
  29. #endif
  30. #ifdef LTC_ECC_SECP128R1
  31. 16,
  32. #endif
  33. #ifdef LTC_ECC_SECP160R1
  34. 20,
  35. #endif
  36. #ifdef LTC_ECC_SECP192R1
  37. 24,
  38. #endif
  39. #ifdef LTC_ECC_SECP224R1
  40. 28,
  41. #endif
  42. #ifdef LTC_ECC_SECP256R1
  43. 32,
  44. #endif
  45. #ifdef LTC_ECC_SECP384R1
  46. 48,
  47. #endif
  48. #ifdef LTC_ECC_SECP512R1
  49. 66
  50. #endif
  51. };
  52. static const char* curvenames[] = {
  53. #ifdef LTC_ECC_SECP112R1
  54. "SECP112R1", "ECC-112",
  55. "secp112r1", /* name is case-insensitive */
  56. "S E C-P-1_1_2r1", /* should pass fuzzy matching */
  57. #endif
  58. #ifdef LTC_ECC_SECP112R2
  59. "SECP112R2",
  60. #endif
  61. #ifdef LTC_ECC_SECP128R1
  62. "SECP128R1", "ECC-128",
  63. #endif
  64. #ifdef LTC_ECC_SECP128R2
  65. "SECP128R2",
  66. #endif
  67. #ifdef LTC_ECC_SECP160R1
  68. "SECP160R1", "ECC-160",
  69. #endif
  70. #ifdef LTC_ECC_SECP160R2
  71. "SECP160R2",
  72. #endif
  73. #ifdef LTC_ECC_SECP160K1
  74. "SECP160K1",
  75. #endif
  76. #ifdef LTC_ECC_BRAINPOOLP160R1
  77. "BRAINPOOLP160R1",
  78. #endif
  79. #ifdef LTC_ECC_SECP192R1
  80. "SECP192R1", "NISTP192", "PRIME192V1", "ECC-192", "P-192",
  81. #endif
  82. #ifdef LTC_ECC_PRIME192V2
  83. "PRIME192V2",
  84. #endif
  85. #ifdef LTC_ECC_PRIME192V3
  86. "PRIME192V3",
  87. #endif
  88. #ifdef LTC_ECC_SECP192K1
  89. "SECP192K1",
  90. #endif
  91. #ifdef LTC_ECC_BRAINPOOLP192R1
  92. "BRAINPOOLP192R1",
  93. #endif
  94. #ifdef LTC_ECC_SECP224R1
  95. "SECP224R1", "NISTP224", "ECC-224", "P-224",
  96. #endif
  97. #ifdef LTC_ECC_SECP224K1
  98. "SECP224K1",
  99. #endif
  100. #ifdef LTC_ECC_BRAINPOOLP224R1
  101. "BRAINPOOLP224R1",
  102. #endif
  103. #ifdef LTC_ECC_PRIME239V1
  104. "PRIME239V1",
  105. #endif
  106. #ifdef LTC_ECC_PRIME239V2
  107. "PRIME239V2",
  108. #endif
  109. #ifdef LTC_ECC_PRIME239V3
  110. "PRIME239V3",
  111. #endif
  112. #ifdef LTC_ECC_SECP256R1
  113. "SECP256R1", "NISTP256", "PRIME256V1", "ECC-256", "P-256",
  114. #endif
  115. #ifdef LTC_ECC_SECP256K1
  116. "SECP256K1",
  117. #endif
  118. #ifdef LTC_ECC_BRAINPOOLP256R1
  119. "BRAINPOOLP256R1",
  120. #endif
  121. #ifdef LTC_ECC_BRAINPOOLP320R1
  122. "BRAINPOOLP320R1",
  123. #endif
  124. #ifdef LTC_ECC_SECP384R1
  125. "SECP384R1", "NISTP384", "ECC-384", "P-384",
  126. #endif
  127. #ifdef LTC_ECC_BRAINPOOLP384R1
  128. "BRAINPOOLP384R1",
  129. #endif
  130. #ifdef LTC_ECC_BRAINPOOLP512R1
  131. "BRAINPOOLP512R1",
  132. #endif
  133. #ifdef LTC_ECC_SECP521R1
  134. "SECP521R1", "NISTP521", "ECC-521", "P-521",
  135. #endif
  136. };
  137. #ifdef LTC_ECC_SHAMIR
  138. static int s_ecc_test_shamir(void)
  139. {
  140. void *a, *modulus, *mp, *kA, *kB, *rA, *rB;
  141. void *mu, *ma;
  142. ecc_point *G, *A, *B, *C1, *C2;
  143. int x, y, z;
  144. unsigned char buf[ECC_BUF_SIZE];
  145. DO(ltc_mp_init_multi(&kA, &kB, &rA, &rB, &modulus, &a, &mu, &ma, LTC_NULL));
  146. LTC_ARGCHK((G = ltc_ecc_new_point()) != NULL);
  147. LTC_ARGCHK((A = ltc_ecc_new_point()) != NULL);
  148. LTC_ARGCHK((B = ltc_ecc_new_point()) != NULL);
  149. LTC_ARGCHK((C1 = ltc_ecc_new_point()) != NULL);
  150. LTC_ARGCHK((C2 = ltc_ecc_new_point()) != NULL);
  151. for (x = 0; x < (int)LTC_ARRAY_SIZE(sizes); x++) {
  152. /* get the base point */
  153. for (z = 0; ltc_ecc_curves[z].prime != NULL; z++) {
  154. DO(ltc_mp_read_radix(modulus, ltc_ecc_curves[z].prime, 16));
  155. if (sizes[x] <= ltc_mp_unsigned_bin_size(modulus)) break;
  156. }
  157. LTC_ARGCHK(ltc_ecc_curves[z].prime != NULL);
  158. /* load it */
  159. DO(ltc_mp_read_radix(G->x, ltc_ecc_curves[z].Gx, 16));
  160. DO(ltc_mp_read_radix(G->y, ltc_ecc_curves[z].Gy, 16));
  161. DO(ltc_mp_set(G->z, 1));
  162. DO(ltc_mp_read_radix(a, ltc_ecc_curves[z].A, 16));
  163. DO(ltc_mp_montgomery_setup(modulus, &mp));
  164. DO(ltc_mp_montgomery_normalization(mu, modulus));
  165. DO(ltc_mp_mulmod(a, mu, modulus, ma));
  166. /* do 100 random tests */
  167. for (y = 0; y < 100; y++) {
  168. /* pick a random r1, r2 */
  169. ENSURE(yarrow_read(buf, sizes[x], &yarrow_prng) == sizes[x]);
  170. DO(ltc_mp_read_unsigned_bin(rA, buf, sizes[x]));
  171. ENSURE(yarrow_read(buf, sizes[x], &yarrow_prng) == sizes[x]);
  172. DO(ltc_mp_read_unsigned_bin(rB, buf, sizes[x]));
  173. /* compute rA * G = A */
  174. DO(ltc_mp.ecc_ptmul(rA, G, A, a, modulus, 1));
  175. /* compute rB * G = B */
  176. DO(ltc_mp.ecc_ptmul(rB, G, B, a, modulus, 1));
  177. /* pick a random kA, kB */
  178. ENSURE(yarrow_read(buf, sizes[x], &yarrow_prng) == sizes[x]);
  179. DO(ltc_mp_read_unsigned_bin(kA, buf, sizes[x]));
  180. ENSURE(yarrow_read(buf, sizes[x], &yarrow_prng) == sizes[x]);
  181. DO(ltc_mp_read_unsigned_bin(kB, buf, sizes[x]));
  182. /* now, compute kA*A + kB*B = C1 using the older method */
  183. DO(ltc_mp.ecc_ptmul(kA, A, C1, a, modulus, 0));
  184. DO(ltc_mp.ecc_ptmul(kB, B, C2, a, modulus, 0));
  185. DO(ltc_mp.ecc_ptadd(C1, C2, C1, a, modulus, mp));
  186. DO(ltc_mp.ecc_map(C1, modulus, mp));
  187. /* now compute using mul2add */
  188. DO(ltc_mp.ecc_mul2add(A, kA, B, kB, C2, ma, modulus));
  189. /* is they the sames? */
  190. if ((ltc_mp_cmp(C1->x, C2->x) != LTC_MP_EQ) || (ltc_mp_cmp(C1->y, C2->y) != LTC_MP_EQ) || (ltc_mp_cmp(C1->z, C2->z) != LTC_MP_EQ)) {
  191. fprintf(stderr, "ECC failed shamir test: size=%d, testno=%d\n", sizes[x], y);
  192. return 1;
  193. }
  194. }
  195. ltc_mp_montgomery_free(mp);
  196. }
  197. ltc_ecc_del_point(C2);
  198. ltc_ecc_del_point(C1);
  199. ltc_ecc_del_point(B);
  200. ltc_ecc_del_point(A);
  201. ltc_ecc_del_point(G);
  202. ltc_mp_deinit_multi(kA, kB, rA, rB, modulus, a, mu, ma, LTC_NULL);
  203. return 0;
  204. }
  205. #endif
  206. /* https://github.com/libtom/libtomcrypt/issues/630 */
  207. static int s_ecc_issue630(void)
  208. {
  209. unsigned char protected_buffer[30], protected_buffer_copy[30];
  210. unsigned long keylen = 0;
  211. ecc_key key;
  212. int low, high;
  213. ecc_sizes(&low, &high);
  214. DO(ecc_make_key (&yarrow_prng, find_prng ("yarrow"), high, &key));
  215. if (yarrow_read(protected_buffer, sizeof(protected_buffer), &yarrow_prng) != sizeof(protected_buffer)) {
  216. return CRYPT_ERROR_READPRNG;
  217. }
  218. XMEMCPY(protected_buffer_copy, protected_buffer, sizeof(protected_buffer));
  219. COMPARE_TESTVECTOR(protected_buffer, sizeof(protected_buffer), protected_buffer_copy, sizeof(protected_buffer), "Ensure copy is equal", 0);
  220. keylen = 10;
  221. SHOULD_FAIL(ecc_get_key(&protected_buffer[10], &keylen, PK_PRIVATE, &key));
  222. COMPARE_TESTVECTOR(protected_buffer, 10, protected_buffer_copy, 10, "Start canary", 1);
  223. COMPARE_TESTVECTOR(&protected_buffer[20], 10, &protected_buffer[20], 10, "End canary", 2);
  224. ecc_free(&key);
  225. return 0;
  226. }
  227. /* https://github.com/libtom/libtomcrypt/issues/108 */
  228. static int s_ecc_issue108(void)
  229. {
  230. void *a, *modulus, *order;
  231. ecc_point *Q, *Result;
  232. int err;
  233. const ltc_ecc_curve* dp;
  234. /* init */
  235. if ((err = ltc_mp_init_multi(&modulus, &order, &a, LTC_NULL)) != CRYPT_OK) { return err; }
  236. Q = ltc_ecc_new_point();
  237. Result = ltc_ecc_new_point();
  238. /* ECC-224 AKA SECP224R1 */
  239. if ((err = ecc_find_curve("SECP224R1", &dp)) != CRYPT_OK) { goto done; }
  240. /* read A */
  241. if ((err = ltc_mp_read_radix(a, dp->A, 16)) != CRYPT_OK) { goto done; }
  242. /* read modulus */
  243. if ((err = ltc_mp_read_radix(modulus, dp->prime, 16)) != CRYPT_OK) { goto done; }
  244. /* read order */
  245. if ((err = ltc_mp_read_radix(order, dp->order, 16)) != CRYPT_OK) { goto done; }
  246. /* read Q */
  247. if ((err = ltc_mp_read_radix(Q->x, "EA3745501BBC6A70BBFDD8AEEDB18CF5073C6DC9AA7CBB5915170D60", 16)) != CRYPT_OK) { goto done; }
  248. if ((err = ltc_mp_read_radix(Q->y, "6C9CB8E68AABFEC989CAC5E2326E0448B7E69C3E56039BA21A44FDAC", 16)) != CRYPT_OK) { goto done; }
  249. ltc_mp_set(Q->z, 1);
  250. /* calculate nQ */
  251. if ((err = ltc_mp.ecc_ptmul(order, Q, Result, a, modulus, 1)) != CRYPT_OK) { goto done; }
  252. done:
  253. ltc_ecc_del_point(Result);
  254. ltc_ecc_del_point(Q);
  255. ltc_mp_deinit_multi(modulus, order, a, LTC_NULL);
  256. return err;
  257. }
  258. /* https://github.com/libtom/libtomcrypt/issues/443 */
  259. /* https://github.com/libtom/libtomcrypt/issues/447 */
  260. static int s_ecc_issue443_447(void)
  261. {
  262. const ltc_ecc_curve* cu;
  263. ecc_key key;
  264. int err, stat = 0;
  265. unsigned char hash[64];
  266. unsigned long hashlen;
  267. const unsigned char msg[] = { 0x54,0x65,0x73,0x74 };
  268. /* msg+pub1+sig1 test vector is from wycheproof - ecdsa_webcrypto_test (incorrect size of signature) */
  269. const unsigned char pub1[] = {
  270. 0x04,
  271. 0x4a,0x03,0xef,0x9f,0x92,0xeb,0x26,0x8c,0xaf,0xa6,0x01,0x07,0x24,0x89,0xa5,0x63,
  272. 0x80,0xfa,0x0d,0xc4,0x31,0x71,0xd7,0x71,0x28,0x13,0xb3,0xa1,0x9a,0x1e,0xb5,0xe5,
  273. 0x3e,0x21,0x3e,0x28,0xa6,0x08,0xce,0x9a,0x2f,0x4a,0x17,0xfd,0x83,0x0c,0x66,0x54,
  274. 0x01,0x8a,0x79,0xb3,0xe0,0x26,0x3d,0x91,0xa8,0xba,0x90,0x62,0x2d,0xf6,0xf2,0xf0
  275. };
  276. const unsigned char sig1[] = { 0x05, 0x01 };
  277. /* msg+pub2+sig2 test vector is from wycheproof - ecdsa_webcrypto_test (incorrect size of signature) */
  278. const unsigned char pub2[] = {
  279. 0x04,
  280. 0x00,0x5f,0x50,0x59,0x30,0x83,0x49,0xf9,0xeb,0xbb,0x4d,0x1c,0x55,0xc0,0xaf,0xcc,0xf6,0x21,0x62,0xec,0x1d,0xd1,
  281. 0x2e,0xf3,0xed,0x90,0x66,0x56,0x92,0x4f,0xfd,0x99,0xca,0xb9,0xf0,0x6b,0x0e,0xb2,0x18,0xcf,0xf0,0x78,0xa4,0x67,
  282. 0x7a,0x5c,0xe1,0xcc,0x07,0x65,0x2b,0xc9,0x76,0xae,0xfc,0x73,0x2c,0x28,0xf6,0x7e,0xf0,0x78,0xa4,0x34,0xe9,0x99,
  283. 0x00,0xa5,0xd1,0x4d,0xf3,0x10,0x63,0x0d,0x76,0xec,0x03,0xcb,0x6f,0x9b,0x95,0xbf,0x1a,0x22,0x43,0x81,0x05,0xc8,
  284. 0x8c,0xd9,0xfd,0x3d,0xac,0x80,0xf8,0x57,0xad,0xd3,0x82,0x71,0xd8,0xba,0x90,0x16,0x84,0xb2,0x6d,0x43,0x6d,0x4a,
  285. 0x85,0x9a,0xd4,0xcd,0xa5,0xe9,0x67,0x7b,0x73,0xca,0xb3,0xf3,0xe5,0xe4,0x1a,0x3d,0x79,0x96,0x60,0x72,0x79,0xab
  286. };
  287. const unsigned char sig2[] = { 0x01, 0x01 };
  288. hashlen = sizeof(hash);
  289. DO(hash_memory(find_hash("sha256"), msg, sizeof(msg), hash, &hashlen));
  290. DO(ecc_find_curve("secp256r1", &cu));
  291. DO(ecc_set_curve(cu, &key));
  292. DO(ecc_set_key(pub1, sizeof(pub1), PK_PUBLIC, &key));
  293. err = ecc_verify_hash_rfc7518_internal(sig1, sizeof(sig1), hash, hashlen, &stat, &key); /* should fail */
  294. ecc_free(&key);
  295. if (err != CRYPT_INVALID_PACKET) return CRYPT_FAIL_TESTVECTOR;
  296. hashlen = sizeof(hash);
  297. DO(hash_memory(find_hash("sha512"), msg, sizeof(msg), hash, &hashlen));
  298. DO(ecc_find_curve("secp521r1", &cu));
  299. DO(ecc_set_curve(cu, &key));
  300. DO(ecc_set_key(pub2, sizeof(pub2), PK_PUBLIC, &key));
  301. err = ecc_verify_hash_rfc7518_internal(sig2, sizeof(sig2), hash, hashlen, &stat, &key); /* should fail */
  302. ecc_free(&key);
  303. if (err != CRYPT_INVALID_PACKET) return CRYPT_FAIL_TESTVECTOR;
  304. return CRYPT_OK;
  305. }
  306. /* https://github.com/libtom/libtomcrypt/issues/446 */
  307. static int s_ecc_issue446(void)
  308. {
  309. const ltc_ecc_curve* cu;
  310. ecc_key key1, key2, key3, key4;
  311. int stat = 0;
  312. unsigned char hash[64];
  313. unsigned long hashlen;
  314. const unsigned char msg1[] = { 0x31,0x32,0x33,0x34,0x30,0x30 };
  315. const unsigned char msg2[] = { 0x36,0x39,0x38,0x31,0x39 };
  316. const unsigned char msg3[] = { 0x4d,0x73,0x67 };
  317. const unsigned char msg4[] = { 0x54,0x65,0x73,0x74 };
  318. const unsigned char pub1[] = {
  319. 0x04, /* secp256r1 */
  320. 0x29,0x27,0xb1,0x05,0x12,0xba,0xe3,0xed,0xdc,0xfe,0x46,0x78,0x28,0x12,0x8b,0xad,
  321. 0x29,0x03,0x26,0x99,0x19,0xf7,0x08,0x60,0x69,0xc8,0xc4,0xdf,0x6c,0x73,0x28,0x38,
  322. 0xc7,0x78,0x79,0x64,0xea,0xac,0x00,0xe5,0x92,0x1f,0xb1,0x49,0x8a,0x60,0xf4,0x60,
  323. 0x67,0x66,0xb3,0xd9,0x68,0x50,0x01,0x55,0x8d,0x1a,0x97,0x4e,0x73,0x41,0x51,0x3e
  324. };
  325. const unsigned char pub2[] = {
  326. 0x04, /* secp224r1 */
  327. 0x53,0x88,0x35,0x38,0xd8,0x66,0x09,0x21,0x7a,0x4d,0x9c,0x27,0x99,0x2e,
  328. 0x2b,0xd7,0x04,0xa4,0xbb,0x12,0xfb,0x91,0x25,0x3c,0xd4,0xf4,0x96,0xfa,
  329. 0x00,0xb3,0x2f,0x3a,0x2d,0x15,0x3a,0x52,0xbb,0x57,0x76,0x50,0xcd,0xf1,
  330. 0xb7,0x3a,0x34,0x05,0x35,0xc7,0xe7,0x3d,0xeb,0x59,0x9a,0xa9,0x50,0x88
  331. };
  332. const unsigned char pub3[] = {
  333. 0x04, /* brainpoolP256r1 */
  334. 0x30,0x29,0x1b,0xca,0x4e,0xb9,0x3c,0x41,0x99,0x1d,0xae,0xc0,0xfd,0x2e,0x87,0xc2,
  335. 0x77,0x8d,0x95,0x8d,0x9a,0x8e,0x2f,0xa4,0xe6,0xd3,0x83,0x5d,0x48,0x5b,0xc2,0x3e,
  336. 0x42,0x17,0xf6,0x84,0xcf,0xdd,0x83,0x6d,0x7c,0xf6,0x09,0x9a,0x34,0xc6,0x82,0x61,
  337. 0xe5,0xa0,0x94,0xad,0xb5,0xb3,0xe4,0xa9,0x26,0x2f,0xf5,0x95,0x7c,0x1b,0x1b,0xa8
  338. };
  339. const unsigned char pub4[] = {
  340. 0x04, /* brainpoolP256t1 */
  341. 0x44,0x24,0xf0,0x9e,0x4f,0x86,0x92,0x31,0xe4,0x7b,0x1e,0x34,0x26,0xec,0x26,0x9e,
  342. 0x5b,0xef,0x19,0xec,0x64,0xcc,0x96,0xda,0x5b,0x2e,0xfd,0xd2,0x11,0x6b,0x83,0xf0,
  343. 0x7a,0x86,0x3d,0x25,0x74,0x3b,0xb2,0x60,0xa6,0x38,0xde,0x64,0x97,0x96,0xc6,0x76,
  344. 0xe1,0x38,0x05,0x86,0x5c,0x8b,0xb9,0xda,0xc3,0x8e,0x16,0xfa,0xe5,0x4b,0x0c,0xef
  345. };
  346. /* msg1+pub1+sig1 test vector is from wycheproof/ecdsa_test VALID */
  347. const unsigned char sig1[] = {
  348. 0x30,0x45,0x02,0x20,0x2b,0xa3,0xa8,0xbe,0x6b,0x94,0xd5,0xec,0x80,0xa6,0xd9,0xd1,0x19,0x0a,
  349. 0x43,0x6e,0xff,0xe5,0x0d,0x85,0xa1,0xee,0xe8,0x59,0xb8,0xcc,0x6a,0xf9,0xbd,0x5c,0x2e,0x18,
  350. 0x02,0x21,0x00,0xb3,0x29,0xf4,0x79,0xa2,0xbb,0xd0,0xa5,0xc3,0x84,0xee,0x14,0x93,0xb1,0xf5,
  351. 0x18,0x6a,0x87,0x13,0x9c,0xac,0x5d,0xf4,0x08,0x7c,0x13,0x4b,0x49,0x15,0x68,0x47,0xdb
  352. };
  353. /* msg1+pub1+sig2 test vector is from wycheproof/ecdsa_test INVALID (changing tag value of sequence) */
  354. const unsigned char sig2[] = {
  355. 0x31,0x45,0x02,0x20,0x2b,0xa3,0xa8,0xbe,0x6b,0x94,0xd5,0xec,0x80,0xa6,0xd9,0xd1,0x19,0x0a,
  356. 0x43,0x6e,0xff,0xe5,0x0d,0x85,0xa1,0xee,0xe8,0x59,0xb8,0xcc,0x6a,0xf9,0xbd,0x5c,0x2e,0x18,
  357. 0x02,0x21,0x00,0xb3,0x29,0xf4,0x79,0xa2,0xbb,0xd0,0xa5,0xc3,0x84,0xee,0x14,0x93,0xb1,0xf5,
  358. 0x18,0x6a,0x87,0x13,0x9c,0xac,0x5d,0xf4,0x08,0x7c,0x13,0x4b,0x49,0x15,0x68,0x47,0xdb
  359. };
  360. /* msg2+pub1+sig3 test vector is from wycheproof/ecdsa_test VALID (Edge case for Shamir multiplication) */
  361. const unsigned char sig3[] = {
  362. 0x30,0x44,0x02,0x20,0x64,0xa1,0xaa,0xb5,0x00,0x0d,0x0e,0x80,0x4f,0x3e,0x2f,0xc0,0x2b,0xde,
  363. 0xe9,0xbe,0x8f,0xf3,0x12,0x33,0x4e,0x2b,0xa1,0x6d,0x11,0x54,0x7c,0x97,0x71,0x1c,0x89,0x8e,
  364. 0x02,0x20,0x6a,0xf0,0x15,0x97,0x1c,0xc3,0x0b,0xe6,0xd1,0xa2,0x06,0xd4,0xe0,0x13,0xe0,0x99,
  365. 0x77,0x72,0xa2,0xf9,0x1d,0x73,0x28,0x6f,0xfd,0x68,0x3b,0x9b,0xb2,0xcf,0x4f,0x1b
  366. };
  367. /* msg1+pub1+sig4 test vector is from wycheproof/ecdsa_test INVALID (long form encoding of length) */
  368. const unsigned char sig4[] = {
  369. 0x30,0x81,0x45,0x02,0x20,0x2b,0xa3,0xa8,0xbe,0x6b,0x94,0xd5,0xec,0x80,0xa6,0xd9,0xd1,0x19,
  370. 0x0a,0x43,0x6e,0xff,0xe5,0x0d,0x85,0xa1,0xee,0xe8,0x59,0xb8,0xcc,0x6a,0xf9,0xbd,0x5c,0x2e,
  371. 0x18,0x02,0x21,0x00,0xb3,0x29,0xf4,0x79,0xa2,0xbb,0xd0,0xa5,0xc3,0x84,0xee,0x14,0x93,0xb1,
  372. 0xf5,0x18,0x6a,0x87,0x13,0x9c,0xac,0x5d,0xf4,0x08,0x7c,0x13,0x4b,0x49,0x15,0x68,0x47,0xdb
  373. };
  374. /* msg1+pub1+sig5 test vector is from wycheproof/ecdsa_test INVALID (length contains leading 0) */
  375. const unsigned char sig5[] = {
  376. 0x30,0x82,0x00,0x45,0x02,0x20,0x2b,0xa3,0xa8,0xbe,0x6b,0x94,0xd5,0xec,0x80,0xa6,0xd9,0xd1,
  377. 0x19,0x0a,0x43,0x6e,0xff,0xe5,0x0d,0x85,0xa1,0xee,0xe8,0x59,0xb8,0xcc,0x6a,0xf9,0xbd,0x5c,
  378. 0x2e,0x18,0x02,0x21,0x00,0xb3,0x29,0xf4,0x79,0xa2,0xbb,0xd0,0xa5,0xc3,0x84,0xee,0x14,0x93,
  379. 0xb1,0xf5,0x18,0x6a,0x87,0x13,0x9c,0xac,0x5d,0xf4,0x08,0x7c,0x13,0x4b,0x49,0x15,0x68,0x47,0xdb
  380. };
  381. /* msg3+pub2+sig6 test vector is from wycheproof/ecdsa_test VALID (extreme value for k and edgecase s) */
  382. const unsigned char sig6[] = {
  383. 0x30,0x3c,0x02,0x1c,0x70,0x6a,0x46,0xdc,0x76,0xdc,0xb7,0x67,0x98,0xe6,0x0e,0x6d,0x89,0x47,0x47,0x88,0xd1,
  384. 0x6d,0xc1,0x80,0x32,0xd2,0x68,0xfd,0x1a,0x70,0x4f,0xa6,0x02,0x1c,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
  385. 0x55,0x55,0x55,0x55,0x55,0x55,0x07,0x8b,0xa0,0x3d,0xa5,0x6a,0x06,0x9f,0x0d,0xc1,0xc9,0x74,0x0e,0x14
  386. };
  387. /* msg4+pub3+sig7 test vector is from wycheproof/ecdsa_test VALID (extreme value for k) */
  388. const unsigned char sig7[] = {
  389. 0x30,0x44,0x02,0x20,0x74,0x3c,0xf1,0xb8,0xb5,0xcd,0x4f,0x2e,0xb5,0x5f,0x8a,0xa3,0x69,0x59,
  390. 0x3a,0xc4,0x36,0xef,0x04,0x41,0x66,0x69,0x9e,0x37,0xd5,0x1a,0x14,0xc2,0xce,0x13,0xea,0x0e,
  391. 0x02,0x20,0x77,0x47,0x2d,0x9a,0x28,0xb4,0xec,0xe7,0x1c,0xf4,0x13,0xa6,0x8e,0xac,0x0e,0xb4,
  392. 0x23,0xa1,0x6f,0xb4,0x62,0xb1,0xf4,0x87,0x06,0xfe,0xd4,0x8c,0xa4,0x37,0xbd,0x2d
  393. };
  394. /* msg4+pub4+sig8 test vector is from wycheproof/ecdsa_test VALID (extreme value for k and s^-1) */
  395. const unsigned char sig8[] = {
  396. 0x30,0x45,0x02,0x21,0x00,0x83,0x38,0x42,0x7c,0x7c,0xf4,0xd1,0x1c,0xb9,0x81,0xd9,0xb1,0x87,
  397. 0x93,0xe3,0x77,0x9c,0x49,0x4c,0x50,0x2c,0x75,0xbd,0x73,0x9e,0x57,0x8d,0xe2,0xa7,0x00,0x57,
  398. 0x8d,0x02,0x20,0x30,0x90,0xf4,0x87,0xe5,0x1f,0x9e,0x35,0xc8,0xaf,0x70,0xbb,0x9a,0xb7,0xdf,
  399. 0x45,0x03,0x7e,0x23,0x0a,0x33,0xd2,0xc1,0xfd,0x96,0xe4,0x04,0x25,0x4f,0xcb,0x86,0x79
  400. };
  401. DO(ecc_find_curve("secp256r1", &cu));
  402. DO(ecc_set_curve(cu, &key1));
  403. DO(ecc_set_key(pub1, sizeof(pub1), PK_PUBLIC, &key1));
  404. DO(ecc_find_curve("secp224r1", &cu));
  405. DO(ecc_set_curve(cu, &key2));
  406. DO(ecc_set_key(pub2, sizeof(pub2), PK_PUBLIC, &key2));
  407. DO(ecc_find_curve("brainpoolP256r1", &cu));
  408. DO(ecc_set_curve(cu, &key3));
  409. DO(ecc_set_key(pub3, sizeof(pub3), PK_PUBLIC, &key3));
  410. DO(ecc_find_curve("brainpoolP256t1", &cu));
  411. DO(ecc_set_curve(cu, &key4));
  412. DO(ecc_set_key(pub4, sizeof(pub4), PK_PUBLIC, &key4));
  413. hashlen = sizeof(hash);
  414. DO(hash_memory(find_hash("sha256"), msg2, sizeof(msg2), hash, &hashlen));
  415. DO(ecc_verify_hash(sig3, sizeof(sig3), hash, hashlen, &stat, &key1));
  416. if (stat != 1) {
  417. fflush(stdout);
  418. fprintf(stderr, "XXX-TODO should be valid - wycheproof / Edge case for Shamir multiplication\n");
  419. /* return CRYPT_FAIL_TESTVECTOR; / * expected result: VALID */
  420. }
  421. exit(0);
  422. hashlen = sizeof(hash);
  423. DO(hash_memory(find_hash("sha256"), msg1, sizeof(msg1), hash, &hashlen));
  424. DO(ecc_verify_hash(sig1, sizeof(sig1), hash, hashlen, &stat, &key1));
  425. ENSUREX(stat == 1, "sig1 - wycheproof / Valid");
  426. SHOULD_FAIL(ecc_verify_hash(sig2, sizeof(sig2), hash, hashlen, &stat, &key1));
  427. ENSUREX(stat == 0, "sig2 - wycheproof / changing tag value of sequence");
  428. SHOULD_FAIL(ecc_verify_hash(sig4, sizeof(sig4), hash, hashlen, &stat, &key1));
  429. ENSUREX(stat == 0, "sig4 - wycheproof / long form encoding of length");
  430. SHOULD_FAIL(ecc_verify_hash(sig5, sizeof(sig5), hash, hashlen, &stat, &key1));
  431. ENSUREX(stat == 0, "sig5 - wycheproof / length contains leading 0");
  432. hashlen = sizeof(hash);
  433. DO(hash_memory(find_hash("sha224"), msg3, sizeof(msg3), hash, &hashlen));
  434. DO(ecc_verify_hash(sig6, sizeof(sig6), hash, hashlen, &stat, &key2));
  435. if (stat != 1) {
  436. fprintf(stderr, "XXX-TODO should be valid - wycheproof / extreme value for k and edgecase s\n");
  437. /* return CRYPT_FAIL_TESTVECTOR; / * expected result: VALID */
  438. }
  439. hashlen = sizeof(hash);
  440. DO(hash_memory(find_hash("sha256"), msg4, sizeof(msg4), hash, &hashlen));
  441. DO(ecc_verify_hash(sig7, sizeof(sig7), hash, hashlen, &stat, &key3));
  442. if (stat != 1) {
  443. fprintf(stderr, "XXX-TODO should be valid - wycheproof / extreme value for k\n");
  444. /* return CRYPT_FAIL_TESTVECTOR; / * expected result: VALID */
  445. }
  446. DO(ecc_verify_hash(sig8, sizeof(sig8), hash, hashlen, &stat, &key4));
  447. if (stat != 1) {
  448. fprintf(stderr, "XXX-TODO should be valid - wycheproof / extreme value for k and s^-1\n");
  449. /* return CRYPT_FAIL_TESTVECTOR; / * expected result: VALID */
  450. }
  451. ecc_free(&key1);
  452. ecc_free(&key2);
  453. ecc_free(&key3);
  454. ecc_free(&key4);
  455. return CRYPT_OK;
  456. }
  457. static int s_ecc_test_mp(void)
  458. {
  459. void *a, *modulus, *order;
  460. ecc_point *G, *GG;
  461. int i, err, primality;
  462. char buf[4096];
  463. DO(ltc_mp_init_multi(&modulus, &order, &a, LTC_NULL));
  464. G = ltc_ecc_new_point();
  465. GG = ltc_ecc_new_point();
  466. if (G == NULL || GG == NULL) {
  467. ltc_mp_deinit_multi(modulus, order, LTC_NULL);
  468. ltc_ecc_del_point(G);
  469. ltc_ecc_del_point(GG);
  470. return CRYPT_MEM;
  471. }
  472. err = CRYPT_OK;
  473. for (i = 0; ltc_ecc_curves[i].prime != NULL; i++) {
  474. DO(ltc_mp_read_radix(a, ltc_ecc_curves[i].A, 16));
  475. DO(ltc_mp_read_radix(modulus, ltc_ecc_curves[i].prime, 16));
  476. DO(ltc_mp_read_radix(order, ltc_ecc_curves[i].order, 16));
  477. /* is prime actually prime? */
  478. DO(ltc_mp_prime_is_prime(modulus, 8, &primality));
  479. if (primality == 0) {
  480. err = CRYPT_FAIL_TESTVECTOR;
  481. ltc_mp_tohex(modulus, buf);
  482. printf("Modulus failed prime check: %s\n", buf);
  483. }
  484. /* is order prime ? */
  485. DO(ltc_mp_prime_is_prime(order, 8, &primality));
  486. if (primality == 0) {
  487. err = CRYPT_FAIL_TESTVECTOR;
  488. ltc_mp_tohex(order, buf);
  489. printf("Order failed prime check: %s\n", buf);
  490. }
  491. DO(ltc_mp_read_radix(G->x, ltc_ecc_curves[i].Gx, 16));
  492. DO(ltc_mp_read_radix(G->y, ltc_ecc_curves[i].Gy, 16));
  493. ltc_mp_set(G->z, 1);
  494. /* then we should have G == (order + 1)G */
  495. DO(ltc_mp_add_d(order, 1, order));
  496. DO(ltc_mp.ecc_ptmul(order, G, GG, a, modulus, 1));
  497. if (ltc_mp_cmp(G->x, GG->x) != LTC_MP_EQ || ltc_mp_cmp(G->y, GG->y) != LTC_MP_EQ) {
  498. err = CRYPT_FAIL_TESTVECTOR;
  499. }
  500. if (err != CRYPT_OK) {
  501. goto done;
  502. }
  503. }
  504. err = CRYPT_OK;
  505. done:
  506. ltc_ecc_del_point(GG);
  507. ltc_ecc_del_point(G);
  508. ltc_mp_deinit_multi(order, modulus, a, LTC_NULL);
  509. return err;
  510. }
  511. static int s_ecc_old_api(void)
  512. {
  513. unsigned char buf[4][4096], ch;
  514. unsigned long x, y, z, s;
  515. int stat, stat2;
  516. ecc_key usera, userb, pubKey, privKey;
  517. ltc_ecc_sig_opts sig_opts = {
  518. .prng = &yarrow_prng,
  519. .wprng = find_prng ("yarrow")
  520. };
  521. int low, high;
  522. ecc_sizes(&low, &high);
  523. if (low < 14 || high < 14 || low > 100 || high > 100 || high < low) return CRYPT_FAIL_TESTVECTOR;
  524. for (s = 0; s < LTC_ARRAY_SIZE(sizes); s++) {
  525. /* make up two keys */
  526. DO(ecc_make_key (&yarrow_prng, find_prng ("yarrow"), sizes[s], &usera));
  527. DO(ecc_make_key (&yarrow_prng, find_prng ("yarrow"), sizes[s], &userb));
  528. if (ecc_get_size(&usera) != (int)sizes[s]) return CRYPT_FAIL_TESTVECTOR;
  529. if (ecc_get_size(&userb) != (int)sizes[s]) return CRYPT_FAIL_TESTVECTOR;
  530. /* make the shared secret */
  531. x = sizeof(buf[0]);
  532. DO(ecc_shared_secret (&usera, &userb, buf[0], &x));
  533. y = sizeof(buf[1]);
  534. DO(ecc_shared_secret (&userb, &usera, buf[1], &y));
  535. COMPARE_TESTVECTOR(buf[0], x, buf[1], y, "ecc Shared keys", s);
  536. /* now export userb */
  537. y = sizeof(buf[0]);
  538. DO(ecc_export (buf[1], &y, PK_PUBLIC, &userb));
  539. ecc_free (&userb);
  540. /* import and make the shared secret again */
  541. DO(ecc_import (buf[1], y, &userb));
  542. z = sizeof(buf[0]);
  543. DO(ecc_shared_secret (&usera, &userb, buf[2], &z));
  544. if (z != x) {
  545. fprintf(stderr, "failed. Size don't match?");
  546. return 1;
  547. }
  548. if (memcmp (buf[0], buf[2], x)) {
  549. fprintf(stderr, "Failed. Contents didn't match.");
  550. return 1;
  551. }
  552. /* export with ANSI X9.63 */
  553. y = sizeof(buf[1]);
  554. DO(ecc_ansi_x963_export(&userb, buf[1], &y));
  555. ecc_free (&userb);
  556. /* now import the ANSI key */
  557. DO(ecc_ansi_x963_import(buf[1], y, &userb));
  558. /* shared secret */
  559. z = sizeof(buf[0]);
  560. DO(ecc_shared_secret (&usera, &userb, buf[2], &z));
  561. if (z != x) {
  562. fprintf(stderr, "failed. Size don't match?");
  563. return 1;
  564. }
  565. if (memcmp (buf[0], buf[2], x)) {
  566. fprintf(stderr, "Failed. Contents didn't match.");
  567. return 1;
  568. }
  569. ecc_free (&usera);
  570. ecc_free (&userb);
  571. /* test encrypt_key */
  572. DO(ecc_make_key (&yarrow_prng, find_prng ("yarrow"), sizes[s], &usera));
  573. /* export key */
  574. x = sizeof(buf[0]);
  575. DO(ecc_export(buf[0], &x, PK_PUBLIC, &usera));
  576. DO(ecc_import(buf[0], x, &pubKey));
  577. x = sizeof(buf[0]);
  578. DO(ecc_export(buf[0], &x, PK_PRIVATE, &usera));
  579. DO(ecc_import(buf[0], x, &privKey));
  580. for (ch = 0; ch < 32; ch++) {
  581. buf[0][ch] = ch;
  582. }
  583. y = sizeof (buf[1]);
  584. DO(ecc_encrypt_key (buf[0], 32, buf[1], &y, &yarrow_prng, find_prng ("yarrow"), find_hash ("sha256"), &pubKey));
  585. zeromem (buf[0], sizeof (buf[0]));
  586. x = sizeof (buf[0]);
  587. DO(ecc_decrypt_key (buf[1], y, buf[0], &x, &privKey));
  588. if (x != 32) {
  589. fprintf(stderr, "Failed (length)");
  590. return 1;
  591. }
  592. for (ch = 0; ch < 32; ch++) {
  593. if (buf[0][ch] != ch) {
  594. fprintf(stderr, "Failed (contents)");
  595. return 1;
  596. }
  597. }
  598. /* test sign_hash */
  599. for (ch = 0; ch < 16; ch++) {
  600. buf[0][ch] = ch;
  601. }
  602. x = sizeof (buf[1]);
  603. DO(ecc_sign_hash_v2(buf[0], 16, buf[1], &x, &sig_opts, &privKey));
  604. DO(ecc_verify_hash_v2(buf[1], x, buf[0], 16, &sig_opts, &stat, &pubKey));
  605. buf[0][0] ^= 1;
  606. DO(ecc_verify_hash_v2(buf[1], x, buf[0], 16, &sig_opts, &stat2, &privKey));
  607. if (!(stat == 1 && stat2 == 0)) {
  608. fprintf(stderr, "ecc_verify_hash failed %d, %d, ", stat, stat2);
  609. return 1;
  610. }
  611. /* test sign_hash_rfc7518 */
  612. for (ch = 0; ch < 16; ch++) {
  613. buf[0][ch] = ch;
  614. }
  615. x = sizeof (buf[1]);
  616. DO(ecc_sign_hash_v2(buf[0], 16, buf[1], &x, &sig_opts, &privKey));
  617. DO(ecc_verify_hash_v2(buf[1], x, buf[0], 16, &sig_opts, &stat, &pubKey));
  618. buf[0][0] ^= 1;
  619. DO(ecc_verify_hash_v2(buf[1], x, buf[0], 16, &sig_opts, &stat2, &privKey));
  620. if (!(stat == 1 && stat2 == 0)) {
  621. fprintf(stderr, "ecc_verify_hash_rfc7518 failed %d, %d, ", stat, stat2);
  622. return 1;
  623. }
  624. ecc_free (&usera);
  625. ecc_free (&pubKey);
  626. ecc_free (&privKey);
  627. }
  628. return CRYPT_OK;
  629. }
  630. int ecc_key_cmp(const int should_type, const ecc_key *should, const ecc_key *is)
  631. {
  632. if (should_type != is->type) return CRYPT_ERROR;
  633. if (should_type == PK_PRIVATE) {
  634. if (ltc_mp_cmp(should->k, is->k) != LTC_MP_EQ) return CRYPT_ERROR;
  635. }
  636. if (ltc_mp_cmp(should->dp.prime, is->dp.prime) != LTC_MP_EQ) return CRYPT_ERROR;
  637. if (ltc_mp_cmp(should->dp.A, is->dp.A) != LTC_MP_EQ) return CRYPT_ERROR;
  638. if (ltc_mp_cmp(should->dp.B, is->dp.B) != LTC_MP_EQ) return CRYPT_ERROR;
  639. if (ltc_mp_cmp(should->dp.order, is->dp.order) != LTC_MP_EQ) return CRYPT_ERROR;
  640. if (ltc_mp_cmp(should->dp.base.x, is->dp.base.x) != LTC_MP_EQ) return CRYPT_ERROR;
  641. if (ltc_mp_cmp(should->dp.base.y, is->dp.base.y) != LTC_MP_EQ) return CRYPT_ERROR;
  642. if (ltc_mp_cmp(should->pubkey.x, is->pubkey.x) != LTC_MP_EQ) return CRYPT_ERROR;
  643. if (ltc_mp_cmp(should->pubkey.y, is->pubkey.y) != LTC_MP_EQ) return CRYPT_ERROR;
  644. if (should->dp.size != is->dp.size) return CRYPT_ERROR;
  645. if (should->dp.cofactor != is->dp.cofactor) return CRYPT_ERROR;
  646. return CRYPT_OK;
  647. }
  648. static int s_ecc_new_api(void)
  649. {
  650. int i, stat;
  651. const ltc_ecc_curve* dp;
  652. ecc_key key, privkey, pubkey;
  653. unsigned char buf[1000];
  654. unsigned long len, j;
  655. #ifdef LTC_ECC_SHAMIR
  656. unsigned long k;
  657. #endif
  658. unsigned char data16[MAXBLOCKSIZE];
  659. unsigned long len16;
  660. const ecc_signature_type sig_algs[] = {
  661. #ifdef LTC_DER
  662. LTC_ECCSIG_ANSIX962,
  663. #endif
  664. LTC_ECCSIG_RFC7518,
  665. LTC_ECCSIG_ETH27,
  666. #ifdef LTC_SSH
  667. LTC_ECCSIG_RFC5656,
  668. #endif
  669. };
  670. ltc_ecc_sig_opts sig_opts = {
  671. .type = LTC_ECCSIG_ANSIX962,
  672. .prng = &yarrow_prng,
  673. .wprng = find_prng ("yarrow")
  674. };
  675. XMEMSET(data16, 0xd1, sizeof(data16));
  676. for (i = 0; i < (int)LTC_ARRAY_SIZE(curvenames); i++) {
  677. DO(ecc_find_curve(curvenames[i], &dp));
  678. /* make new key */
  679. DO(ecc_make_key_ex(&yarrow_prng, find_prng ("yarrow"), &key, dp));
  680. len = sizeof(buf);
  681. DO(ecc_export(buf, &len, PK_PRIVATE, &key));
  682. DO(ecc_import_ex(buf, len, &privkey, dp));
  683. ecc_free(&privkey);
  684. len = sizeof(buf);
  685. DO(ecc_export(buf, &len, PK_PUBLIC, &key));
  686. DO(ecc_import_ex(buf, len, &pubkey, dp));
  687. ecc_free(&pubkey);
  688. len = sizeof(buf);
  689. DO(ecc_ansi_x963_export(&key, buf, &len));
  690. ecc_free(&key);
  691. DO(ecc_ansi_x963_import_ex(buf, len, &pubkey, dp));
  692. ecc_free(&pubkey);
  693. /* generate new key */
  694. DO(ecc_set_curve(dp, &key));
  695. DO(ecc_generate_key(&yarrow_prng, find_prng ("yarrow"), &key));
  696. len = sizeof(buf);
  697. DO(ecc_get_key(buf, &len, PK_PRIVATE, &key));
  698. ecc_free(&key);
  699. /* load exported private key */
  700. DO(ecc_set_curve(dp, &privkey));
  701. DO(ecc_set_key(buf, len, PK_PRIVATE, &privkey));
  702. if (strcmp(ltc_mp.name, "TomsFastMath") != 0) {
  703. /* XXX-FIXME: TFM does not support sqrtmod_prime */
  704. /* export compressed public key */
  705. len = sizeof(buf);
  706. DO(ecc_get_key(buf, &len, PK_PUBLIC|PK_COMPRESSED, &privkey));
  707. if (len != 1 + (unsigned)ecc_get_size(&privkey)) return CRYPT_FAIL_TESTVECTOR;
  708. /* load exported public+compressed key */
  709. DO(ecc_set_curve(dp, &pubkey));
  710. DO(ecc_set_key(buf, len, PK_PUBLIC, &pubkey));
  711. ecc_free(&pubkey);
  712. }
  713. /* export long public key */
  714. len = sizeof(buf);
  715. DO(ecc_get_key(buf, &len, PK_PUBLIC, &privkey));
  716. if (len != 1 + 2 * (unsigned)ecc_get_size(&privkey)) return CRYPT_FAIL_TESTVECTOR;
  717. /* load exported public key */
  718. DO(ecc_set_curve(dp, &pubkey));
  719. DO(ecc_set_key(buf, len, PK_PUBLIC, &pubkey));
  720. for (j = 0; j < LTC_ARRAY_SIZE(sig_algs); ++j) {
  721. /* test signature */
  722. if (sig_algs[j] == LTC_ECCSIG_ETH27 && XSTRCMP(dp->OID, "1.3.132.0.10"))
  723. continue;
  724. len = sizeof(buf);
  725. sig_opts.type = sig_algs[j];
  726. DO(ecc_sign_hash_v2(data16, privkey.dp.size, buf, &len, &sig_opts, &privkey));
  727. stat = 0;
  728. DO(ecc_verify_hash_v2(buf, len, data16, privkey.dp.size, &sig_opts, &stat, &pubkey));
  729. if (stat != 1) return CRYPT_FAIL_TESTVECTOR;
  730. #ifdef LTC_ECC_SHAMIR
  731. if (strcmp(ltc_mp.name, "TomsFastMath") != 0) {
  732. /* XXX-FIXME: TFM does not support sqrtmod_prime */
  733. int found = 0, recid;
  734. ecc_key reckey;
  735. /* test recovery */
  736. sig_opts.recid = &recid;
  737. len = sizeof(buf);
  738. DO(ecc_sign_hash_v2(data16, privkey.dp.size, buf, &len, &sig_opts, &privkey));
  739. DO(ecc_set_curve(dp, &reckey));
  740. for (k = 0; k < 2*(1+privkey.dp.cofactor); k++) {
  741. recid = k;
  742. stat = ecc_recover_key(buf, len, data16, privkey.dp.size, &sig_opts, &reckey);
  743. if (stat != CRYPT_OK) continue; /* last two will almost always fail, only possible if x<(prime mod order) */
  744. stat = ecc_key_cmp(PK_PUBLIC, &pubkey, &reckey);
  745. if (stat == CRYPT_OK) found++;
  746. }
  747. sig_opts.recid = NULL;
  748. if (found != 1) return CRYPT_FAIL_TESTVECTOR; /* unique match */
  749. ecc_free(&reckey);
  750. }
  751. #endif
  752. }
  753. /* test encryption */
  754. len = sizeof(buf);
  755. DO(ecc_encrypt_key(data16, 16, buf, &len, &yarrow_prng, find_prng("yarrow"), find_hash("sha256"), &pubkey));
  756. zeromem(data16, 16);
  757. len16 = 16;
  758. DO(ecc_decrypt_key(buf, len, data16, &len16, &privkey));
  759. if ((int)len16 != 16) return CRYPT_FAIL_TESTVECTOR;
  760. for (j = 0; (int)j < 16; j++) if (data16[j] != 0xd1) return CRYPT_FAIL_TESTVECTOR;
  761. /* cleanup */
  762. ecc_free(&privkey);
  763. ecc_free(&pubkey);
  764. }
  765. return CRYPT_OK;
  766. }
  767. static int s_ecc_rfc6979(void)
  768. {
  769. const struct {
  770. const char *curve, *x, *Ux, *Uy;
  771. struct {
  772. const char *k, *r, *s;
  773. } signatures[11];
  774. } tests[] = {
  775. {
  776. "P-192",
  777. "6FAB034934E4C0FC9AE67F5B5659A9D7D1FEFD187EE09FD4",
  778. "AC2C77F529F91689FEA0EA5EFEC7F210D8EEA0B9E047ED56",
  779. "3BC723E57670BD4887EBC732C523063D0A7C957BC97C1C43",
  780. {
  781. {
  782. "37D7CA00D2C7B0E5E412AC03BD44BA837FDD5B28CD3B0021",
  783. "98C6BD12B23EAF5E2A2045132086BE3EB8EBD62ABF6698FF",
  784. "57A22B07DEA9530F8DE9471B1DC6624472E8E2844BC25B64",
  785. },
  786. {
  787. "4381526B3FC1E7128F202E194505592F01D5FF4C5AF015D8",
  788. "A1F00DAD97AEEC91C95585F36200C65F3C01812AA60378F5",
  789. "E07EC1304C7C6C9DEBBE980B9692668F81D4DE7922A0F97A",
  790. },
  791. {
  792. "32B1B6D7D42A05CB449065727A84804FB1A3E34D8F261496",
  793. "4B0B8CE98A92866A2820E20AA6B75B56382E0F9BFD5ECB55",
  794. "CCDB006926EA9565CBADC840829D8C384E06DE1F1E381B85",
  795. },
  796. {
  797. "4730005C4FCB01834C063A7B6760096DBE284B8252EF4311",
  798. "DA63BF0B9ABCF948FBB1E9167F136145F7A20426DCC287D5",
  799. "C3AA2C960972BD7A2003A57E1C4C77F0578F8AE95E31EC5E",
  800. },
  801. {
  802. "A2AC7AB055E4F20692D49209544C203A7D1F2C0BFBC75DB1",
  803. "4D60C5AB1996BD848343B31C00850205E2EA6922DAC2E4B8",
  804. "3F6E837448F027A1BF4B34E796E32A811CBB4050908D8F67",
  805. },
  806. {
  807. "D9CF9C3D3297D3260773A1DA7418DB5537AB8DD93DE7FA25",
  808. "0F2141A0EBBC44D2E1AF90A50EBCFCE5E197B3B7D4DE036D",
  809. "EB18BC9E1F3D7387500CB99CF5F7C157070A8961E38700B7",
  810. },
  811. {
  812. "F5DC805F76EF851800700CCE82E7B98D8911B7D510059FBE",
  813. "6945A1C1D1B2206B8145548F633BB61CEF04891BAF26ED34",
  814. "B7FB7FDFC339C0B9BD61A9F5A8EAF9BE58FC5CBA2CB15293",
  815. },
  816. {
  817. "5C4CE89CF56D9E7C77C8585339B006B97B5F0680B4306C6C",
  818. "3A718BD8B4926C3B52EE6BBE67EF79B18CB6EB62B1AD97AE",
  819. "5662E6848A4A19B1F1AE2F72ACD4B8BBE50F1EAC65D9124F",
  820. },
  821. {
  822. "5AFEFB5D3393261B828DB6C91FBC68C230727B030C975693",
  823. "B234B60B4DB75A733E19280A7A6034BD6B1EE88AF5332367",
  824. "7994090B2D59BB782BE57E74A44C9A1C700413F8ABEFE77A",
  825. },
  826. {
  827. "0758753A5254759C7CFBAD2E2D9B0792EEE44136C9480527",
  828. "FE4F4AE86A58B6507946715934FE2D8FF9D95B6B098FE739",
  829. "74CF5605C98FBA0E1EF34D4B5A1577A7DCF59457CAE52290",
  830. },
  831. {
  832. NULL, NULL, NULL
  833. }
  834. }
  835. },
  836. {
  837. "P-224",
  838. "F220266E1105BFE3083E03EC7A3A654651F45E37167E88600BF257C1",
  839. "CF08DA5AD719E42707FA431292DEA11244D64FC51610D94B130D6C",
  840. "EEAB6F3DEBE455E3DBF85416F7030CBD94F34F2D6F232C69F3C1385A",
  841. {
  842. {
  843. "7EEFADD91110D8DE6C2C470831387C50D3357F7F4D477054B8B426BC",
  844. "22226F9D40A96E19C4A301CE5B74B115303C0F3A4FD30FC257FB57AC",
  845. "66D1CDD83E3AF75605DD6E2FEFF196D30AA7ED7A2EDF7AF475403D69",
  846. },
  847. {
  848. "C1D1F2F10881088301880506805FEB4825FE09ACB6816C36991AA06D",
  849. "1CDFE6662DDE1E4A1EC4CDEDF6A1F5A2FB7FBD9145C12113E6ABFD3E",
  850. "A6694FD7718A21053F225D3F46197CA699D45006C06F871808F43EBC",
  851. },
  852. {
  853. "AD3029E0278F80643DE33917CE6908C70A8FF50A411F06E41DEDFCDC",
  854. "61AA3DA010E8E8406C656BC477A7A7189895E7E840CDFE8FF42307BA",
  855. "BC814050DAB5D23770879494F9E0A680DC1AF7161991BDE692B10101",
  856. },
  857. {
  858. "52B40F5A9D3D13040F494E83D3906C6079F29981035C7BD51E5CAC40",
  859. "0B115E5E36F0F9EC81F1325A5952878D745E19D7BB3EABFABA77E953",
  860. "830F34CCDFE826CCFDC81EB4129772E20E122348A2BBD889A1B1AF1D",
  861. },
  862. {
  863. "9DB103FFEDEDF9CFDBA05184F925400C1653B8501BAB89CEA0FBEC14",
  864. "074BD1D979D5F32BF958DDC61E4FB4872ADCAFEB2256497CDAC30397",
  865. "A4CECA196C3D5A1FF31027B33185DC8EE43F288B21AB342E5D8EB084",
  866. },
  867. {
  868. "2519178F82C3F0E4F87ED5883A4E114E5B7A6E374043D8EFD329C253",
  869. "DEAA646EC2AF2EA8AD53ED66B2E2DDAA49A12EFD8356561451F3E21C",
  870. "95987796F6CF2062AB8135271DE56AE55366C045F6D9593F53787BD2",
  871. },
  872. {
  873. "DF8B38D40DCA3E077D0AC520BF56B6D565134D9B5F2EAE0D34900524",
  874. "C441CE8E261DED634E4CF84910E4C5D1D22C5CF3B732BB204DBEF019",
  875. "902F42847A63BDC5F6046ADA114953120F99442D76510150F372A3F4",
  876. },
  877. {
  878. "FF86F57924DA248D6E44E8154EB69F0AE2AEBAEE9931D0B5A969F904",
  879. "AD04DDE87B84747A243A631EA47A1BA6D1FAA059149AD2440DE6FBA6",
  880. "178D49B1AE90E3D8B629BE3DB5683915F4E8C99FDF6E666CF37ADCFD",
  881. },
  882. {
  883. "7046742B839478C1B5BD31DB2E862AD868E1A45C863585B5F22BDC2D",
  884. "389B92682E399B26518A95506B52C03BC9379A9DADF3391A21FB0EA4",
  885. "414A718ED3249FF6DBC5B50C27F71F01F070944DA22AB1F78F559AAB",
  886. },
  887. {
  888. "E39C2AA4EA6BE2306C72126D40ED77BF9739BB4D6EF2BBB1DCB6169D",
  889. "049F050477C5ADD858CAC56208394B5A55BAEBBE887FDF765047C17C",
  890. "077EB13E7005929CEFA3CD0403C7CDCC077ADF4E44F3C41B2F60ECFF",
  891. },
  892. {
  893. NULL, NULL, NULL
  894. }
  895. }
  896. },
  897. {
  898. "P-256",
  899. "C9AFA9D845BA75166B5C215767B1D6934E50C3DB36E89B127B8A622B120F6721",
  900. "60FED4BA255A9D31C961EB74C6356D68C049B8923B61FA6CE669622E60F29FB6",
  901. "7903FE1008B8BC99A41AE9E95628BC64F2F1B20C2D7E9F5177A3C294D4462299",
  902. {
  903. {
  904. "882905F1227FD620FBF2ABF21244F0BA83D0DC3A9103DBBEE43A1FB858109DB4",
  905. "61340C88C3AAEBEB4F6D667F672CA9759A6CCAA9FA8811313039EE4A35471D32",
  906. "6D7F147DAC089441BB2E2FE8F7A3FA264B9C475098FDCF6E00D7C996E1B8B7EB",
  907. },
  908. {
  909. "103F90EE9DC52E5E7FB5132B7033C63066D194321491862059967C715985D473",
  910. "53B2FFF5D1752B2C689DF257C04C40A587FABABB3F6FC2702F1343AF7CA9AA3F",
  911. "B9AFB64FDC03DC1A131C7D2386D11E349F070AA432A4ACC918BEA988BF75C74C",
  912. },
  913. {
  914. "A6E3C57DD01ABE90086538398355DD4C3B17AA873382B0F24D6129493D8AAD60",
  915. "EFD48B2AACB6A8FD1140DD9CD45E81D69D2C877B56AAF991C34D0EA84EAF3716",
  916. "F7CB1C942D657C41D436C7A1B6E29F65F3E900DBB9AFF4064DC4AB2F843ACDA8",
  917. },
  918. {
  919. "09F634B188CEFD98E7EC88B1AA9852D734D0BC272F7D2A47DECC6EBEB375AAD4",
  920. "0EAFEA039B20E9B42309FB1D89E213057CBF973DC0CFC8F129EDDDC800EF7719",
  921. "4861F0491E6998B9455193E34E7B0D284DDD7149A74B95B9261F13ABDE940954",
  922. },
  923. {
  924. "5FA81C63109BADB88C1F367B47DA606DA28CAD69AA22C4FE6AD7DF73A7173AA5",
  925. "8496A60B5E9B47C825488827E0495B0E3FA109EC4568FD3F8D1097678EB97F00",
  926. "2362AB1ADBE2B8ADF9CB9EDAB740EA6049C028114F2460F96554F61FAE3302FE",
  927. },
  928. {
  929. "8C9520267C55D6B980DF741E56B4ADEE114D84FBFA2E62137954164028632A2E",
  930. "0CBCC86FD6ABD1D99E703E1EC50069EE5C0B4BA4B9AC60E409E8EC5910D81A89",
  931. "01B9D7B73DFAA60D5651EC4591A0136F87653E0FD780C3B1BC872FFDEAE479B1",
  932. },
  933. {
  934. "669F4426F2688B8BE0DB3A6BD1989BDAEFFF84B649EEB84F3DD26080F667FAA7",
  935. "C37EDB6F0AE79D47C3C27E962FA269BB4F441770357E114EE511F662EC34A692",
  936. "C820053A05791E521FCAAD6042D40AEA1D6B1A540138558F47D0719800E18F2D",
  937. },
  938. {
  939. "D16B6AE827F17175E040871A1C7EC3500192C4C92677336EC2537ACAEE0008E0",
  940. "F1ABB023518351CD71D881567B1EA663ED3EFCF6C5132B354F28D3B0B7D38367",
  941. "019F4113742A2B14BD25926B49C649155F267E60D3814B4C0CC84250E46F0083",
  942. },
  943. {
  944. "16AEFFA357260B04B1DD199693960740066C1A8F3E8EDD79070AA914D361B3B8",
  945. "83910E8B48BB0C74244EBDF7F07A1C5413D61472BD941EF3920E623FBCCEBEB6",
  946. "8DDBEC54CF8CD5874883841D712142A56A8D0F218F5003CB0296B6B509619F2C",
  947. },
  948. {
  949. "6915D11632ACA3C40D5D51C08DAF9C555933819548784480E93499000D9F0B7F",
  950. "461D93F31B6540894788FD206C07CFA0CC35F46FA3C91816FFF1040AD1581A04",
  951. "39AF9F15DE0DB8D97E72719C74820D304CE5226E32DEDAE67519E840D1194E55",
  952. },
  953. {
  954. NULL, NULL, NULL
  955. }
  956. }
  957. },
  958. {
  959. "P-384",
  960. "6B9D3DAD2E1B8C1C05B19875B6659F4DE23C3B667BF297BA9AA47740787137D896D5724E4C70A825F872C9EA60D2EDF5",
  961. "EC3A4E415B4E19A4568618029F427FA5DA9A8BC4AE92E02E06AAE5286B300C64DEF8F0EA9055866064A254515480BC13",
  962. "8015D9B72D7D57244EA8EF9AC0C621896708A59367F9DFB9F54CA84B3F1C9DB1288B231C3AE0D4FE7344FD2533264720",
  963. {
  964. {
  965. "4471EF7518BB2C7C20F62EAE1C387AD0C5E8E470995DB4ACF694466E6AB096630F29E5938D25106C3C340045A2DB01A7",
  966. "EC748D839243D6FBEF4FC5C4859A7DFFD7F3ABDDF72014540C16D73309834FA37B9BA002899F6FDA3A4A9386790D4EB2",
  967. "A3BCFA947BEEF4732BF247AC17F71676CB31A847B9FF0CBC9C9ED4C1A5B3FACF26F49CA031D4857570CCB5CA4424A443",
  968. },
  969. {
  970. "A4E4D2F0E729EB786B31FC20AD5D849E304450E0AE8E3E341134A5C1AFA03CAB8083EE4E3C45B06A5899EA56C51B5879",
  971. "42356E76B55A6D9B4631C865445DBE54E056D3B3431766D0509244793C3F9366450F76EE3DE43F5A125333A6BE060122",
  972. "9DA0C81787064021E78DF658F2FBB0B042BF304665DB721F077A4298B095E4834C082C03D83028EFBF93A3C23940CA8D",
  973. },
  974. {
  975. "180AE9F9AEC5438A44BC159A1FCB277C7BE54FA20E7CF404B490650A8ACC414E375572342863C899F9F2EDF9747A9B60",
  976. "21B13D1E013C7FA1392D03C5F99AF8B30C570C6F98D4EA8E354B63A21D3DAA33BDE1E888E63355D92FA2B3C36D8FB2CD",
  977. "F3AA443FB107745BF4BD77CB3891674632068A10CA67E3D45DB2266FA7D1FEEBEFDC63ECCD1AC42EC0CB8668A4FA0AB0",
  978. },
  979. {
  980. "94ED910D1A099DAD3254E9242AE85ABDE4BA15168EAF0CA87A555FD56D10FBCA2907E3E83BA95368623B8C4686915CF9",
  981. "94EDBB92A5ECB8AAD4736E56C691916B3F88140666CE9FA73D64C4EA95AD133C81A648152E44ACF96E36DD1E80FABE46",
  982. "99EF4AEB15F178CEA1FE40DB2603138F130E740A19624526203B6351D0A3A94FA329C145786E679E7B82C71A38628AC8",
  983. },
  984. {
  985. "92FC3C7183A883E24216D1141F1A8976C5B0DD797DFA597E3D7B32198BD35331A4E966532593A52980D0E3AAA5E10EC3",
  986. "ED0959D5880AB2D869AE7F6C2915C6D60F96507F9CB3E047C0046861DA4A799CFE30F35CC900056D7C99CD7882433709",
  987. "512C8CCEEE3890A84058CE1E22DBC2198F42323CE8ACA9135329F03C068E5112DC7CC3EF3446DEFCEB01A45C2667FDD5",
  988. },
  989. {
  990. "66CC2C8F4D303FC962E5FF6A27BD79F84EC812DDAE58CF5243B64A4AD8094D47EC3727F3A3C186C15054492E30698497",
  991. "4BC35D3A50EF4E30576F58CD96CE6BF638025EE624004A1F7789A8B8E43D0678ACD9D29876DAF46638645F7F404B11C7",
  992. "D5A6326C494ED3FF614703878961C0FDE7B2C278F9A65FD8C4B7186201A2991695BA1C84541327E966FA7B50F7382282",
  993. },
  994. {
  995. "18FA39DB95AA5F561F30FA3591DC59C0FA3653A80DAFFA0B48D1A4C6DFCBFF6E3D33BE4DC5EB8886A8ECD093F2935726",
  996. "E8C9D0B6EA72A0E7837FEA1D14A1A9557F29FAA45D3E7EE888FC5BF954B5E62464A9A817C47FF78B8C11066B24080E72",
  997. "07041D4A7A0379AC7232FF72E6F77B6DDB8F09B16CCE0EC3286B2BD43FA8C6141C53EA5ABEF0D8231077A04540A96B66",
  998. },
  999. {
  1000. "0CFAC37587532347DC3389FDC98286BBA8C73807285B184C83E62E26C401C0FAA48DD070BA79921A3457ABFF2D630AD7",
  1001. "6D6DEFAC9AB64DABAFE36C6BF510352A4CC27001263638E5B16D9BB51D451559F918EEDAF2293BE5B475CC8F0188636B",
  1002. "2D46F3BECBCC523D5F1A1256BF0C9B024D879BA9E838144C8BA6BAEB4B53B47D51AB373F9845C0514EEFB14024787265",
  1003. },
  1004. {
  1005. "015EE46A5BF88773ED9123A5AB0807962D193719503C527B031B4C2D225092ADA71F4A459BC0DA98ADB95837DB8312EA",
  1006. "8203B63D3C853E8D77227FB377BCF7B7B772E97892A80F36AB775D509D7A5FEB0542A7F0812998DA8F1DD3CA3CF023DB",
  1007. "DDD0760448D42D8A43AF45AF836FCE4DE8BE06B485E9B61B827C2F13173923E06A739F040649A667BF3B828246BAA5A5",
  1008. },
  1009. {
  1010. "3780C4F67CB15518B6ACAE34C9F83568D2E12E47DEAB6C50A4E4EE5319D1E8CE0E2CC8A136036DC4B9C00E6888F66B6C",
  1011. "A0D5D090C9980FAF3C2CE57B7AE951D31977DD11C775D314AF55F76C676447D06FB6495CD21B4B6E340FC236584FB277",
  1012. "976984E59B4C77B0E8E4460DCA3D9F20E07B9BB1F63BEEFAF576F6B2E8B224634A2092CD3792E0159AD9CEE37659C736",
  1013. },
  1014. {
  1015. NULL, NULL, NULL
  1016. }
  1017. }
  1018. },
  1019. {
  1020. "P-521",
  1021. "00FAD06DAA62BA3B25D2FB40133DA757205DE67F5BB0018FEE8C86E1B68C7E75CAA896EB32F1F47C70855836A6D16FCC1466F6D8FBEC67DB89EC0C08B0E996B83538",
  1022. "1894550D0785932E00EAA23B694F213F8C3121F86DC97A04E5A7167DB4E5BCD371123D46E45DB6B5D5370A7F20FB633155D38FFA16D2BD761DCAC474B9A2F5023A4",
  1023. "493101C962CD4D2FDDF782285E64584139C2F91B47F87FF82354D6630F746A28A0DB25741B5B34A828008B22ACC23F924FAAFBD4D33F81EA66956DFEAA2BFDFCF5",
  1024. {
  1025. {
  1026. "89C071B419E1C2820962321787258469511958E80582E95D8378E0C2CCDB3CB42BEDE42F50E3FA3C71F5A76724281D31D9C89F0F91FC1BE4918DB1C03A5838D0F9",
  1027. "00343B6EC45728975EA5CBA6659BBB6062A5FF89EEA58BE3C80B619F322C87910FE092F7D45BB0F8EEE01ED3F20BABEC079D202AE677B243AB40B5431D497C55D75D",
  1028. "00E7B0E675A9B24413D448B8CC119D2BF7B2D2DF032741C096634D6D65D0DBE3D5694625FB9E8104D3B842C1B0E2D0B98BEA19341E8676AEF66AE4EBA3D5475D5D16",
  1029. },
  1030. {
  1031. "0121415EC2CD7726330A61F7F3FA5DE14BE9436019C4DB8CB4041F3B54CF31BE0493EE3F427FB906393D895A19C9523F3A1D54BB8702BD4AA9C99DAB2597B92113F3",
  1032. "01776331CFCDF927D666E032E00CF776187BC9FDD8E69D0DABB4109FFE1B5E2A30715F4CC923A4A5E94D2503E9ACFED92857B7F31D7152E0F8C00C15FF3D87E2ED2E",
  1033. "0050CB5265417FE2320BBB5A122B8E1A32BD699089851128E360E620A30C7E17BA41A666AF126CE100E5799B153B60528D5300D08489CA9178FB610A2006C254B41F",
  1034. },
  1035. {
  1036. "EDF38AFCAAECAB4383358B34D67C9F2216C8382AAEA44A3DAD5FDC9C32575761793FEF24EB0FC276DFC4F6E3EC476752F043CF01415387470BCBD8678ED2C7E1A0",
  1037. "01511BB4D675114FE266FC4372B87682BAECC01D3CC62CF2303C92B3526012659D16876E25C7C1E57648F23B73564D67F61C6F14D527D54972810421E7D87589E1A7",
  1038. "004A171143A83163D6DF460AAF61522695F207A58B95C0644D87E52AA1A347916E4F7A72930B1BC06DBE22CE3F58264AFD23704CBB63B29B931F7DE6C9D949A7ECFC",
  1039. },
  1040. {
  1041. "01546A108BC23A15D6F21872F7DED661FA8431DDBD922D0DCDB77CC878C8553FFAD064C95A920A750AC9137E527390D2D92F153E66196966EA554D9ADFCB109C4211",
  1042. "01EA842A0E17D2DE4F92C15315C63DDF72685C18195C2BB95E572B9C5136CA4B4B576AD712A52BE9730627D16054BA40CC0B8D3FF035B12AE75168397F5D50C67451",
  1043. "01F21A3CEE066E1961025FB048BD5FE2B7924D0CD797BABE0A83B66F1E35EEAF5FDE143FA85DC394A7DEE766523393784484BDF3E00114A1C857CDE1AA203DB65D61",
  1044. },
  1045. {
  1046. "01DAE2EA071F8110DC26882D4D5EAE0621A3256FC8847FB9022E2B7D28E6F10198B1574FDD03A9053C08A1854A168AA5A57470EC97DD5CE090124EF52A2F7ECBFFD3",
  1047. "00C328FAFCBD79DD77850370C46325D987CB525569FB63C5D3BC53950E6D4C5F174E25A1EE9017B5D450606ADD152B534931D7D4E8455CC91F9B15BF05EC36E377FA",
  1048. "00617CCE7CF5064806C467F678D3B4080D6F1CC50AF26CA209417308281B68AF282623EAA63E5B5C0723D8B8C37FF0777B1A20F8CCB1DCCC43997F1EE0E44DA4A67A",
  1049. },
  1050. {
  1051. "00BB9F2BF4FE1038CCF4DABD7139A56F6FD8BB1386561BD3C6A4FC818B20DF5DDBA80795A947107A1AB9D12DAA615B1ADE4F7A9DC05E8E6311150F47F5C57CE8B222",
  1052. "013BAD9F29ABE20DE37EBEB823C252CA0F63361284015A3BF430A46AAA80B87B0693F0694BD88AFE4E661FC33B094CD3B7963BED5A727ED8BD6A3A202ABE009D0367",
  1053. "01E9BB81FF7944CA409AD138DBBEE228E1AFCC0C890FC78EC8604639CB0DBDC90F717A99EAD9D272855D00162EE9527567DD6A92CBD629805C0445282BBC916797FF",
  1054. },
  1055. {
  1056. "0040D09FCF3C8A5F62CF4FB223CBBB2B9937F6B0577C27020A99602C25A01136987E452988781484EDBBCF1C47E554E7FC901BC3085E5206D9F619CFF07E73D6F706",
  1057. "01C7ED902E123E6815546065A2C4AF977B22AA8EADDB68B2C1110E7EA44D42086BFE4A34B67DDC0E17E96536E358219B23A706C6A6E16BA77B65E1C595D43CAE17FB",
  1058. "0177336676304FCB343CE028B38E7B4FBA76C1C1B277DA18CAD2A8478B2A9A9F5BEC0F3BA04F35DB3E4263569EC6AADE8C92746E4C82F8299AE1B8F1739F8FD519A4",
  1059. },
  1060. {
  1061. "001DE74955EFAABC4C4F17F8E84D881D1310B5392D7700275F82F145C61E843841AF09035BF7A6210F5A431A6A9E81C9323354A9E69135D44EBD2FCAA7731B909258",
  1062. "000E871C4A14F993C6C7369501900C4BC1E9C7B0B4BA44E04868B30B41D8071042EB28C4C250411D0CE08CD197E4188EA4876F279F90B3D8D74A3C76E6F1E4656AA8",
  1063. "00CD52DBAA33B063C3A6CD8058A1FB0A46A4754B034FCC644766CA14DA8CA5CA9FDE00E88C1AD60CCBA759025299079D7A427EC3CC5B619BFBC828E7769BCD694E86",
  1064. },
  1065. {
  1066. "01F1FC4A349A7DA9A9E116BFDD055DC08E78252FF8E23AC276AC88B1770AE0B5DCEB1ED14A4916B769A523CE1E90BA22846AF11DF8B300C38818F713DADD85DE0C88",
  1067. "014BEE21A18B6D8B3C93FAB08D43E739707953244FDBE924FA926D76669E7AC8C89DF62ED8975C2D8397A65A49DCC09F6B0AC62272741924D479354D74FF6075578C",
  1068. "0133330865C067A0EAF72362A65E2D7BC4E461E8C8995C3B6226A21BD1AA78F0ED94FE536A0DCA35534F0CD1510C41525D163FE9D74D134881E35141ED5E8E95B979",
  1069. },
  1070. {
  1071. "016200813020EC986863BEDFC1B121F605C1215645018AEA1A7B215A564DE9EB1B38A67AA1128B80CE391C4FB71187654AAA3431027BFC7F395766CA988C964DC56D",
  1072. "013E99020ABF5CEE7525D16B69B229652AB6BDF2AFFCAEF38773B4B7D08725F10CDB93482FDCC54EDCEE91ECA4166B2A7C6265EF0CE2BD7051B7CEF945BABD47EE6D",
  1073. "01FBD0013C674AA79CB39849527916CE301C66EA7CE8B80682786AD60F98F7E78A19CA69EFF5C57400E3B3A0AD66CE0978214D13BAF4E9AC60752F7B155E2DE4DCE3",
  1074. },
  1075. {
  1076. NULL, NULL, NULL
  1077. }
  1078. }
  1079. },
  1080. {
  1081. NULL
  1082. }
  1083. };
  1084. const void *inputs[] = {
  1085. "sample",
  1086. "test"
  1087. };
  1088. const char hashes[][7] = {
  1089. "sha1",
  1090. "sha224",
  1091. "sha256",
  1092. "sha384",
  1093. "sha512"
  1094. };
  1095. const ltc_ecc_curve* dp;
  1096. ecc_key key;
  1097. unsigned char pk[MAXBLOCKSIZE], hash[MAXBLOCKSIZE], sig[512], should[512];
  1098. char name[128], tmp[MAXBLOCKSIZE];
  1099. unsigned int t, s, i, h;
  1100. unsigned long pklen, hashlen, curvelen, inputlen, siglen, shouldlen, shouldlen2;
  1101. ltc_ecc_sig_opts sig_opts = {
  1102. .type = LTC_ECCSIG_RFC7518,
  1103. .prng = &yarrow_prng,
  1104. .wprng = find_prng ("yarrow")
  1105. };
  1106. for (t = 0; tests[t].curve; ++t) {
  1107. curvelen = XSTRLEN(tests[t].curve);
  1108. XMEMCPY(name, tests[t].curve, curvelen);
  1109. name[curvelen++] = '-';
  1110. DOX(ecc_find_curve(tests[t].curve, &dp), tests[t].curve);
  1111. pklen = sizeof(pk);
  1112. DOX(base16_decode(tests[t].x, XSTRLEN(tests[t].x), pk, &pklen), tests[t].curve);
  1113. DOX(ecc_set_curve(dp, &key), tests[t].curve);
  1114. DOX(ecc_set_key(pk, pklen, PK_PRIVATE, &key), tests[t].curve);
  1115. name[curvelen] = 'U';
  1116. name[curvelen + 1] = 'x';
  1117. name[curvelen + 2] = '\0';
  1118. ltc_mp.write_radix(key.pubkey.x, tmp, 16);
  1119. COMPARE_TESTVECTOR(tmp, XSTRLEN(tmp), tests[t].Ux, XSTRLEN(tests[t].Ux), name, t * 1000);
  1120. name[curvelen + 1] = 'y';
  1121. ltc_mp.write_radix(key.pubkey.y, tmp, 16);
  1122. COMPARE_TESTVECTOR(tmp, XSTRLEN(tmp), tests[t].Uy, XSTRLEN(tests[t].Uy), name, t * 1000);
  1123. i = h = 0;
  1124. for (s = 0; tests[t].signatures[s].k; ++s) {
  1125. if (h == 0) {
  1126. inputlen = XSTRLEN(inputs[i]);
  1127. XMEMCPY(&name[curvelen], inputs[i], inputlen);
  1128. name[curvelen + inputlen++] = '-';
  1129. }
  1130. XMEMCPY(&name[curvelen + inputlen], hashes[h], 7);
  1131. hashlen = sizeof(hash);
  1132. DOX(hash_memory(find_hash(hashes[h]), inputs[i], XSTRLEN(inputs[i]), hash, &hashlen), name);
  1133. sig_opts.rfc6979_hash_alg = hashes[h];
  1134. siglen = sizeof(sig);
  1135. DOX(ecc_sign_hash_v2(hash, hashlen, sig, &siglen, &sig_opts, &key), name);
  1136. XMEMSET(should, 0, sizeof(should));
  1137. shouldlen = sizeof(should);
  1138. DOX(base16_decode(tests[t].signatures[s].r, XSTRLEN(tests[t].signatures[s].r), should, &shouldlen), name);
  1139. shouldlen2 = sizeof(should) - shouldlen;
  1140. DOX(base16_decode(tests[t].signatures[s].s, XSTRLEN(tests[t].signatures[s].s), should + shouldlen, &shouldlen2), name);
  1141. COMPARE_TESTVECTOR(sig, siglen, should, shouldlen + shouldlen2, name, (t * 1000 | s * 100 | i * 10 | h));
  1142. h++;
  1143. if (h == 5) {
  1144. h = 0;
  1145. i++;
  1146. }
  1147. }
  1148. ecc_free(&key);
  1149. }
  1150. return CRYPT_OK;
  1151. }
  1152. static int password_get(void **p, unsigned long *l, void *u)
  1153. {
  1154. LTC_UNUSED_PARAM(u);
  1155. *p = strdup("secret");
  1156. *l = 6;
  1157. return 0;
  1158. }
  1159. static int s_ecc_import_export(void) {
  1160. const ltc_ecc_curve *cu;
  1161. ecc_key key, pri, pub;
  1162. unsigned char out[300];
  1163. unsigned long outlen;
  1164. /* the following test keys were generated by:
  1165. # no password
  1166. openssl ecparam -name secp256k1 -genkey -out main-key.pem
  1167. openssl ec -in main-key.pem -param_enc explicit -out long_pri.der -outform DER
  1168. openssl ec -in main-key.pem -param_enc explicit -conv_form compressed -out long_pric.der -outform DER
  1169. openssl ec -in main-key.pem -param_enc explicit -pubout -out long_pub.der -outform DER
  1170. openssl ec -in main-key.pem -param_enc explicit -pubout -conv_form compressed -out long_pubc.der -outform DER
  1171. openssl ec -in main-key.pem -param_enc named_curve -out short_pri.der -outform DER
  1172. openssl ec -in main-key.pem -param_enc named_curve -conv_form compressed -out short_pric.der -outform DER
  1173. openssl ec -in main-key.pem -param_enc named_curve -pubout -out short_pub.der -outform DER
  1174. openssl ec -in main-key.pem -param_enc named_curve -pubout -conv_form compressed -out short_pubc.der -outform DER
  1175. # X.509 EC certificates
  1176. openssl req -new -x509 -keyform der -key long_pri.der -sha512 -subj '/CN=Test Cert EC' -out x509_cert_long.der -outform der -days 365000
  1177. openssl req -new -x509 -keyform der -key long_pric.der -sha512 -subj '/CN=Test Cert EC' -out x509_cert_longc.der -outform der -days 365000
  1178. openssl req -new -x509 -keyform der -key short_pri.der -sha512 -subj '/CN=Test Cert EC' -out x509_cert_short.der -outform der -days 365000
  1179. openssl req -new -x509 -keyform der -key short_pric.der -sha512 -subj '/CN=Test Cert EC' -out x509_cert_shortc.der -outform der -days 365000
  1180. # pkcs8 without password
  1181. openssl pkcs8 -topk8 -inform DER -outform DER -nocrypt -in long_pri.der -out long_pri_pkcs8.der
  1182. openssl pkcs8 -topk8 -inform DER -outform DER -nocrypt -in long_pric.der -out long_pric_pkcs8.der
  1183. openssl pkcs8 -topk8 -inform DER -outform DER -nocrypt -in short_pri.der -out short_pri_pkcs8.der
  1184. openssl pkcs8 -topk8 -inform DER -outform DER -nocrypt -in short_pric.der -out short_pric_pkcs8.der
  1185. # password protected - PBES1
  1186. openssl pkcs8 -topk8 -inform DER -outform DER -passout pass:secret -in long_pri.der -v1 PBE-MD2-DES -out long_pri_pkcs8_pbe_md2_des.der
  1187. openssl pkcs8 -topk8 -inform DER -outform DER -passout pass:secret -in long_pri.der -v1 PBE-MD2-RC2-64 -out long_pri_pkcs8_pbe_md2_rc2_64.der
  1188. openssl pkcs8 -topk8 -inform DER -outform DER -passout pass:secret -in ltc_ecc_long_pri_test_key.der -v1 PBE-MD5-DES -out long_pri_pkcs8_pbe_md5_des.der
  1189. openssl pkcs8 -topk8 -inform DER -outform DER -passout pass:secret -in ltc_ecc_long_pri_test_key.der -v1 PBE-SHA1-RC2-64 -out long_pri_pkcs8_pbe_sha1_rc2_64.der
  1190. openssl pkcs8 -topk8 -inform DER -outform DER -passout pass:secret -in ltc_ecc_long_pri_test_key.der -v1 PBE-MD5-RC2-64 -out long_pri_pkcs8_pbe_md5_rc2_64.der
  1191. openssl pkcs8 -topk8 -inform DER -outform DER -passout pass:secret -in ltc_ecc_long_pri_test_key.der -v1 PBE-SHA1-DES -out long_pri_pkcs8_pbe_sha1_des.der
  1192. # password protected - PBES2
  1193. openssl pkcs8 -topk8 -inform DER -outform DER -passout pass:secret -in ltc_ecc_long_pri_test_key.der -v2 rc2 -out long_pri_pkcs8_pbkdf2_rc2_cbc.der
  1194. openssl pkcs8 -topk8 -inform DER -outform DER -passout pass:secret -in ltc_ecc_long_pri_test_key.der -v2 des -out long_pri_pkcs8_pbkdf2_des_cbc.der
  1195. openssl pkcs8 -topk8 -inform DER -outform DER -passout pass:secret -in ltc_ecc_long_pri_test_key.der -v2 des3 -out long_pri_pkcs8_pbkdf2_des_ede3_cbc.der
  1196. openssl pkcs8 -topk8 -inform DER -outform DER -passout pass:secret -in ltc_ecc_long_pri_test_key.der -v2 des3 -v2prf hmacWithSHA224 -out long_pri_pkcs8_pbkdf2_sha224_des_ede3_cbc.der
  1197. openssl pkcs8 -topk8 -inform DER -outform DER -passout pass:secret -in ltc_ecc_long_pri_test_key.der -v2 des3 -v2prf hmacWithSHA256 -out long_pri_pkcs8_pbkdf2_sha256_des_ede3_cbc.der
  1198. openssl pkcs8 -topk8 -inform DER -outform DER -passout pass:secret -in ltc_ecc_long_pri_test_key.der -v2 des3 -v2prf hmacWithSHA384 -out long_pri_pkcs8_pbkdf2_sha384_des_ede3_cbc.der
  1199. openssl pkcs8 -topk8 -inform DER -outform DER -passout pass:secret -in ltc_ecc_long_pri_test_key.der -v2 des3 -v2prf hmacWithSHA512 -out long_pri_pkcs8_pbkdf2_sha512_des_ede3_cbc.der
  1200. */
  1201. /* static const unsigned char ltc_ecc_long_pri_test_key[] defined globally */
  1202. static const unsigned char long_pri_pkcs8[] = { /* private + long public, explicit curve params, PKCS8 */
  1203. 0x30, 0x82, 0x01, 0x23, 0x02, 0x01, 0x00, 0x30, 0x81, 0xae, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce,
  1204. 0x3d, 0x02, 0x01, 0x30, 0x81, 0xa2, 0x02, 0x01, 0x01, 0x30, 0x2c, 0x06, 0x07, 0x2a, 0x86, 0x48,
  1205. 0xce, 0x3d, 0x01, 0x01, 0x02, 0x21, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  1206. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  1207. 0xff, 0xff, 0xfe, 0xff, 0xff, 0xfc, 0x2f, 0x30, 0x06, 0x04, 0x01, 0x00, 0x04, 0x01, 0x07, 0x04,
  1208. 0x41, 0x04, 0x79, 0xbe, 0x66, 0x7e, 0xf9, 0xdc, 0xbb, 0xac, 0x55, 0xa0, 0x62, 0x95, 0xce, 0x87,
  1209. 0x0b, 0x07, 0x02, 0x9b, 0xfc, 0xdb, 0x2d, 0xce, 0x28, 0xd9, 0x59, 0xf2, 0x81, 0x5b, 0x16, 0xf8,
  1210. 0x17, 0x98, 0x48, 0x3a, 0xda, 0x77, 0x26, 0xa3, 0xc4, 0x65, 0x5d, 0xa4, 0xfb, 0xfc, 0x0e, 0x11,
  1211. 0x08, 0xa8, 0xfd, 0x17, 0xb4, 0x48, 0xa6, 0x85, 0x54, 0x19, 0x9c, 0x47, 0xd0, 0x8f, 0xfb, 0x10,
  1212. 0xd4, 0xb8, 0x02, 0x21, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  1213. 0xff, 0xff, 0xff, 0xff, 0xfe, 0xba, 0xae, 0xdc, 0xe6, 0xaf, 0x48, 0xa0, 0x3b, 0xbf, 0xd2, 0x5e,
  1214. 0x8c, 0xd0, 0x36, 0x41, 0x41, 0x02, 0x01, 0x01, 0x04, 0x6d, 0x30, 0x6b, 0x02, 0x01, 0x01, 0x04,
  1215. 0x20, 0x0c, 0xf1, 0xad, 0x2f, 0x03, 0xf7, 0x91, 0x1b, 0xba, 0x03, 0xcf, 0x23, 0x37, 0xc8, 0xf2,
  1216. 0xf7, 0x36, 0xce, 0x65, 0xf1, 0x84, 0x2d, 0x7d, 0x9f, 0x5f, 0x9e, 0x21, 0xd9, 0x5e, 0x49, 0xbd,
  1217. 0x23, 0xa1, 0x44, 0x03, 0x42, 0x00, 0x04, 0x2a, 0xf9, 0x0b, 0xda, 0xbe, 0x71, 0x66, 0x9e, 0xd1,
  1218. 0xcf, 0x12, 0xd0, 0x24, 0xaf, 0xba, 0xb6, 0x7f, 0xfb, 0x96, 0x27, 0x3e, 0x2f, 0xbd, 0x1e, 0xd5,
  1219. 0xf9, 0x8d, 0x6c, 0x73, 0x9d, 0xc5, 0x16, 0x91, 0xbd, 0xb2, 0xb9, 0x1b, 0x40, 0x10, 0x5a, 0xb7,
  1220. 0x6c, 0x6e, 0x32, 0x5b, 0xf7, 0x63, 0x62, 0x94, 0x24, 0x24, 0xdb, 0xec, 0x3f, 0x8b, 0xe5, 0x6e,
  1221. 0x4b, 0x64, 0x37, 0x31, 0x24, 0x79, 0x4d
  1222. };
  1223. #if defined(LTC_MD2) && defined(LTC_DES)
  1224. static const unsigned char long_pri_pkcs8_pbe_md2_des[] = {
  1225. 0x30, 0x82, 0x01, 0x49, 0x30, 0x1b, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x05,
  1226. 0x01, 0x30, 0x0e, 0x04, 0x08, 0xd8, 0x1c, 0x80, 0xac, 0xd9, 0xfa, 0x9d, 0xbc, 0x02, 0x02, 0x08,
  1227. 0x00, 0x04, 0x82, 0x01, 0x28, 0xe1, 0xd5, 0xa8, 0x9a, 0xa8, 0x23, 0x85, 0x53, 0x18, 0xb3, 0x96,
  1228. 0x67, 0x8d, 0x45, 0x72, 0xf8, 0x69, 0xc4, 0xb1, 0x01, 0x3e, 0x04, 0xf7, 0xf7, 0x5d, 0x07, 0xad,
  1229. 0xec, 0x8e, 0xd6, 0x23, 0x00, 0xe7, 0x59, 0xb0, 0x98, 0xbb, 0xdb, 0x85, 0xdb, 0x59, 0x4d, 0xb5,
  1230. 0x53, 0xb3, 0x32, 0x50, 0x66, 0x75, 0xc4, 0x69, 0x05, 0x07, 0xee, 0xd4, 0xd8, 0x33, 0xcd, 0x4c,
  1231. 0x94, 0xad, 0x82, 0xc7, 0x89, 0x53, 0x65, 0x9f, 0x55, 0x44, 0x95, 0x20, 0xe8, 0x4a, 0xc2, 0xef,
  1232. 0x41, 0xf2, 0x9d, 0xf8, 0x3d, 0x16, 0x8a, 0x6a, 0x4e, 0x85, 0x90, 0xa7, 0xf9, 0xf8, 0xac, 0x16,
  1233. 0x76, 0xf2, 0x29, 0x4b, 0x93, 0xec, 0xd8, 0x17, 0x3f, 0x89, 0x84, 0x79, 0x75, 0x90, 0x5f, 0xc3,
  1234. 0xf2, 0xb8, 0x1a, 0x0a, 0x25, 0xf4, 0xe2, 0x59, 0xe0, 0xea, 0xa6, 0x57, 0xc4, 0x9c, 0xce, 0xfd,
  1235. 0xa8, 0xbc, 0xf6, 0x0d, 0x3a, 0x47, 0x14, 0x9d, 0x6a, 0x92, 0x77, 0xe4, 0xcb, 0x88, 0x6e, 0xfa,
  1236. 0x19, 0xa4, 0x3d, 0x58, 0xdb, 0x5f, 0xc7, 0xad, 0x91, 0x64, 0xb0, 0x1f, 0xe2, 0x66, 0xc5, 0x5a,
  1237. 0x28, 0x21, 0xb0, 0xc1, 0xc8, 0x73, 0x55, 0xd8, 0x43, 0x66, 0x6a, 0x5c, 0xcd, 0xb0, 0x89, 0x60,
  1238. 0x59, 0x31, 0xe0, 0x2f, 0x20, 0x3b, 0x83, 0xdf, 0x27, 0xcf, 0x33, 0xcc, 0xb9, 0xb6, 0xe0, 0xec,
  1239. 0x8b, 0x94, 0x4b, 0xc4, 0x1c, 0x25, 0xba, 0x97, 0x6c, 0x83, 0x22, 0x8c, 0xca, 0x9d, 0xc6, 0xaa,
  1240. 0x74, 0x3f, 0x46, 0xdc, 0xba, 0x7a, 0x36, 0x04, 0xa7, 0xc8, 0x65, 0xb4, 0xf7, 0x14, 0x53, 0x8c,
  1241. 0xff, 0x4d, 0x19, 0xc1, 0xdb, 0xa4, 0xcc, 0x52, 0xc2, 0xd9, 0x38, 0x16, 0x8f, 0xd8, 0x6e, 0x55,
  1242. 0x41, 0xa8, 0xe0, 0x15, 0xd6, 0x2d, 0xa4, 0x37, 0x9f, 0xcc, 0x42, 0x3c, 0xcb, 0xcc, 0x92, 0x04,
  1243. 0xc8, 0xcf, 0xbc, 0x60, 0xfb, 0x45, 0xff, 0x62, 0x74, 0xa1, 0xe9, 0xba, 0x1e, 0x5d, 0x44, 0x6f,
  1244. 0x0e, 0xac, 0xdf, 0xde, 0xb1, 0xbb, 0x47, 0x5e, 0x0c, 0x88, 0x0a, 0x85, 0x0b, 0xa8, 0x9e, 0xcb,
  1245. 0x32, 0x99, 0x8d, 0xb1, 0xdd, 0x12, 0x08, 0xeb, 0x7e, 0x45, 0x70, 0x12, 0xe3
  1246. };
  1247. #endif
  1248. #if defined(LTC_MD2) && defined(LTC_RC2)
  1249. static const unsigned char long_pri_pkcs8_pbe_md2_rc2_64[] = {
  1250. 0x30, 0x82, 0x01, 0x49, 0x30, 0x1b, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x05,
  1251. 0x04, 0x30, 0x0e, 0x04, 0x08, 0xa2, 0x28, 0xb7, 0x2a, 0x08, 0x1c, 0x4a, 0xc4, 0x02, 0x02, 0x08,
  1252. 0x00, 0x04, 0x82, 0x01, 0x28, 0x78, 0x12, 0x02, 0x58, 0x9b, 0xea, 0x77, 0xba, 0x84, 0x20, 0x96,
  1253. 0x63, 0xf0, 0xf3, 0x38, 0x0b, 0x98, 0x53, 0x63, 0x8d, 0xa4, 0x5a, 0xa0, 0xa9, 0x21, 0x93, 0xd0,
  1254. 0x56, 0xc9, 0xd2, 0x67, 0xb2, 0x5e, 0xb5, 0x9f, 0x15, 0x8c, 0x3c, 0x9a, 0xaf, 0x9c, 0xe5, 0x8b,
  1255. 0xe6, 0x61, 0xac, 0xa4, 0x26, 0x75, 0x96, 0xea, 0x73, 0xaf, 0xd6, 0xb7, 0x4c, 0x66, 0x33, 0x98,
  1256. 0x9e, 0x0b, 0xf8, 0xe6, 0x9c, 0xfd, 0x83, 0x0f, 0x55, 0x86, 0x9f, 0xa9, 0xf0, 0x23, 0xcb, 0x80,
  1257. 0xe5, 0x32, 0x50, 0xea, 0x5b, 0x7d, 0xe2, 0x69, 0xc4, 0x6b, 0x61, 0xb2, 0xb8, 0x81, 0xe9, 0x05,
  1258. 0xcb, 0x76, 0xae, 0xa5, 0x37, 0x0f, 0x3c, 0xe6, 0xde, 0x24, 0x6a, 0x9c, 0xf2, 0x0a, 0x28, 0x6a,
  1259. 0xc9, 0xec, 0xef, 0xd7, 0xda, 0xcc, 0xf4, 0x3b, 0x74, 0x36, 0xc5, 0xaf, 0x53, 0xd8, 0xf4, 0x30,
  1260. 0x0b, 0xd4, 0xb6, 0x36, 0xdc, 0x90, 0x4f, 0x83, 0x44, 0x79, 0xea, 0xc9, 0xb7, 0xb2, 0xd0, 0x03,
  1261. 0xa6, 0x63, 0x7e, 0x1d, 0xa8, 0x4e, 0x93, 0x16, 0x7a, 0x4f, 0xd2, 0x8b, 0xd6, 0x78, 0x7d, 0x48,
  1262. 0x41, 0x7c, 0xba, 0xc3, 0x64, 0x6f, 0x11, 0x22, 0x6d, 0x40, 0xb8, 0xc9, 0x03, 0x7a, 0x2c, 0xdf,
  1263. 0x76, 0x78, 0x4f, 0x5f, 0x50, 0x03, 0x7a, 0xaf, 0x78, 0x91, 0xbb, 0x2a, 0xe6, 0x5e, 0x0f, 0xf5,
  1264. 0x60, 0x9e, 0x8a, 0x2f, 0xdb, 0x9e, 0x57, 0xbe, 0xf6, 0x0f, 0x76, 0x6e, 0x44, 0x91, 0x7b, 0x36,
  1265. 0x88, 0x9c, 0xf9, 0xbe, 0x13, 0x3e, 0x6b, 0x85, 0x62, 0xda, 0x1f, 0xf9, 0x73, 0x98, 0x8a, 0x0d,
  1266. 0xdf, 0x11, 0x74, 0x18, 0xe1, 0x1c, 0xd1, 0x3f, 0x02, 0x43, 0xd4, 0x46, 0xe3, 0x8a, 0x3b, 0x6c,
  1267. 0x7f, 0x81, 0xb4, 0xc3, 0x85, 0x4f, 0x89, 0x67, 0x26, 0x5a, 0x08, 0x35, 0x31, 0xd3, 0x15, 0xbb,
  1268. 0xcc, 0x7d, 0x7b, 0x99, 0x41, 0xdb, 0x43, 0xa0, 0x83, 0x84, 0x74, 0x6c, 0x0a, 0x80, 0x46, 0xdc,
  1269. 0xc8, 0x88, 0x87, 0x01, 0x21, 0x19, 0xd4, 0x1e, 0xf4, 0x09, 0x0e, 0x18, 0x31, 0x91, 0x37, 0x35,
  1270. 0x1d, 0x07, 0xaf, 0x87, 0x92, 0x3d, 0xf8, 0xee, 0x6f, 0x87, 0x7b, 0x52, 0x3d
  1271. };
  1272. #endif
  1273. #if defined(LTC_MD5) && defined(LTC_DES)
  1274. static const unsigned char long_pri_pkcs8_pbe_md5_des[] = {
  1275. 0x30, 0x82, 0x01, 0x49, 0x30, 0x1b, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x05,
  1276. 0x03, 0x30, 0x0e, 0x04, 0x08, 0x33, 0xe7, 0xd9, 0xf1, 0x35, 0xd9, 0x74, 0x83, 0x02, 0x02, 0x08,
  1277. 0x00, 0x04, 0x82, 0x01, 0x28, 0x2f, 0x77, 0x7c, 0x48, 0xc9, 0x43, 0x6d, 0xdb, 0xd0, 0x1a, 0xef,
  1278. 0xfb, 0x29, 0x5e, 0x53, 0xa3, 0x52, 0x28, 0x27, 0x76, 0xc2, 0x01, 0x76, 0x5a, 0xea, 0x98, 0xe6,
  1279. 0x72, 0xdf, 0x06, 0xa2, 0xf5, 0xd0, 0x7b, 0x74, 0xe4, 0x6b, 0x98, 0xa6, 0xb5, 0xe1, 0x02, 0xf7,
  1280. 0xab, 0x2c, 0xf1, 0xeb, 0xf4, 0xec, 0xa6, 0xba, 0xd3, 0xd5, 0xb2, 0x26, 0x83, 0xeb, 0xff, 0xc9,
  1281. 0xf8, 0x7b, 0xbf, 0xab, 0xdc, 0xe5, 0xe4, 0x91, 0xd5, 0x48, 0xba, 0x49, 0xcb, 0xc5, 0xf1, 0x71,
  1282. 0x48, 0x1e, 0x96, 0x7c, 0x10, 0xe4, 0xa9, 0x35, 0xa7, 0xe6, 0x82, 0x97, 0x6f, 0xe4, 0x64, 0xd4,
  1283. 0x53, 0xa9, 0xf1, 0x1b, 0x6c, 0x31, 0xa1, 0xc7, 0x12, 0x46, 0x45, 0x6f, 0x45, 0xb2, 0x09, 0x3a,
  1284. 0xfe, 0x35, 0x4e, 0xbf, 0x7d, 0xf8, 0xcf, 0x94, 0x78, 0x0c, 0x78, 0xfb, 0xce, 0xc1, 0x30, 0xcd,
  1285. 0x6d, 0x6b, 0x08, 0x5e, 0xf6, 0xf5, 0x97, 0xff, 0x5e, 0x63, 0x44, 0x36, 0xa5, 0x71, 0x04, 0xe5,
  1286. 0x2d, 0xd9, 0xe3, 0x41, 0x91, 0x09, 0x1e, 0xa3, 0x30, 0xff, 0x12, 0x2a, 0x7a, 0xe1, 0x8f, 0x9c,
  1287. 0x38, 0x13, 0x3d, 0xc3, 0xbb, 0x68, 0xfa, 0xc0, 0xc6, 0x35, 0x77, 0xed, 0xe8, 0x73, 0xca, 0xc3,
  1288. 0x87, 0x62, 0xa9, 0x0e, 0xef, 0xcf, 0x73, 0x3c, 0xb3, 0xa0, 0x1b, 0xb5, 0x5d, 0x72, 0x89, 0x82,
  1289. 0xd4, 0xf6, 0x37, 0x0b, 0x57, 0x8f, 0x48, 0xd4, 0xf1, 0x10, 0xa1, 0xe5, 0x25, 0x90, 0xeb, 0xde,
  1290. 0x8d, 0x2a, 0x9d, 0xfb, 0x7c, 0x0d, 0xdc, 0x38, 0x45, 0x9e, 0xa0, 0x05, 0x98, 0x4e, 0x72, 0x9f,
  1291. 0x3d, 0xde, 0xc7, 0x00, 0xf9, 0xaf, 0xdc, 0x67, 0x47, 0x73, 0xf7, 0xcf, 0x63, 0x80, 0xe3, 0x05,
  1292. 0xb3, 0xda, 0x9f, 0x4b, 0x27, 0xd3, 0x14, 0xc9, 0x62, 0xd5, 0x09, 0xde, 0x4d, 0xe7, 0x21, 0x67,
  1293. 0xfa, 0x10, 0x34, 0x18, 0xbf, 0xde, 0xf7, 0x95, 0x25, 0x6d, 0xba, 0xe4, 0x10, 0xf0, 0x9d, 0x05,
  1294. 0x7b, 0xe4, 0xb5, 0xc0, 0x21, 0xb3, 0x7d, 0xcd, 0x1d, 0x80, 0xd0, 0x10, 0xd4, 0xdb, 0x9f, 0x06,
  1295. 0xd5, 0x86, 0xea, 0x62, 0x96, 0xb7, 0x31, 0x73, 0xde, 0x25, 0xd0, 0xbb, 0xb2
  1296. };
  1297. #endif
  1298. #if defined(LTC_MD5) && defined(LTC_RC2)
  1299. static const unsigned char long_pri_pkcs8_pbe_md5_rc2_64[] = {
  1300. 0x30, 0x82, 0x01, 0x49, 0x30, 0x1b, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x05,
  1301. 0x06, 0x30, 0x0e, 0x04, 0x08, 0x95, 0x82, 0x6d, 0x08, 0xe4, 0x7e, 0xae, 0x5f, 0x02, 0x02, 0x08,
  1302. 0x00, 0x04, 0x82, 0x01, 0x28, 0x93, 0x2c, 0xd8, 0x27, 0xed, 0x13, 0xe1, 0x31, 0xef, 0x7c, 0x44,
  1303. 0x9c, 0xce, 0x85, 0x17, 0x38, 0x5a, 0xe3, 0xd8, 0xe9, 0xfd, 0x1e, 0x81, 0xae, 0x9c, 0xd7, 0x8b,
  1304. 0x11, 0x4e, 0x92, 0x08, 0x3a, 0x97, 0x2c, 0x4f, 0x9a, 0xb7, 0x10, 0xda, 0x6a, 0x06, 0x9e, 0xe2,
  1305. 0xb6, 0x41, 0xf8, 0xb3, 0xd4, 0x42, 0xcc, 0x67, 0xe8, 0x25, 0x76, 0x9a, 0xc2, 0x66, 0x1a, 0x94,
  1306. 0x19, 0x0c, 0xe1, 0x43, 0x27, 0x27, 0x1e, 0xad, 0xfb, 0xce, 0xb7, 0x96, 0xfb, 0x5d, 0x6d, 0xf3,
  1307. 0xe1, 0x73, 0xc5, 0x1c, 0xa0, 0xbe, 0x94, 0x2c, 0xe7, 0x1c, 0x04, 0xa9, 0xfe, 0xdf, 0x15, 0x79,
  1308. 0x0c, 0x5e, 0xf8, 0xe2, 0xb9, 0x4a, 0xa0, 0xc5, 0x89, 0x2c, 0xf8, 0x1d, 0x5f, 0xcc, 0xf0, 0xb6,
  1309. 0xe8, 0x31, 0xeb, 0xe5, 0xb4, 0x9d, 0x2a, 0xa8, 0x8d, 0xff, 0x69, 0xf7, 0x83, 0x65, 0xbb, 0xa2,
  1310. 0xdd, 0xcd, 0x97, 0x41, 0x6e, 0xfa, 0xb6, 0xe1, 0x76, 0x7e, 0xa3, 0x24, 0x9b, 0x23, 0x58, 0x0e,
  1311. 0xeb, 0x08, 0x00, 0x96, 0x53, 0xae, 0x6c, 0xb9, 0xaa, 0x5c, 0x9a, 0xf8, 0xee, 0xcd, 0xfd, 0xe5,
  1312. 0xc5, 0x40, 0x62, 0x58, 0x6d, 0xf0, 0x10, 0xd5, 0x85, 0xeb, 0xed, 0x8a, 0x75, 0xe9, 0x8c, 0x2b,
  1313. 0xe7, 0x39, 0xaf, 0xb1, 0x15, 0xdb, 0x4f, 0xe3, 0xa5, 0x24, 0x1d, 0xd2, 0xae, 0x82, 0x88, 0x1a,
  1314. 0x37, 0x4c, 0x6b, 0x30, 0x9d, 0x6f, 0x93, 0x9c, 0x87, 0x99, 0xd1, 0x1c, 0x93, 0x0c, 0xbb, 0xf9,
  1315. 0x70, 0x36, 0x28, 0x56, 0x68, 0x27, 0x2f, 0x1e, 0xf1, 0x86, 0x0a, 0x23, 0x04, 0xe6, 0x72, 0x1f,
  1316. 0x1b, 0x71, 0x45, 0x0b, 0xe7, 0x74, 0x45, 0x8e, 0x7f, 0x94, 0xbc, 0xcd, 0x6c, 0xf8, 0xf3, 0xed,
  1317. 0x44, 0x02, 0x4d, 0x0a, 0xdd, 0xe9, 0xe4, 0x46, 0x31, 0x94, 0x28, 0x9b, 0x5f, 0x05, 0x37, 0xf4,
  1318. 0x05, 0x9c, 0xa3, 0x9c, 0xdf, 0xb7, 0xfb, 0xab, 0xe0, 0x07, 0x26, 0x40, 0x79, 0x12, 0x9a, 0x78,
  1319. 0xf6, 0xb6, 0x30, 0x3d, 0x4e, 0x16, 0x2e, 0x39, 0x96, 0x98, 0x2a, 0x8c, 0xa7, 0xdb, 0xa0, 0x4a,
  1320. 0x3f, 0x42, 0x30, 0xd3, 0x5d, 0xd0, 0x26, 0xd0, 0xc5, 0xd5, 0xa4, 0x10, 0x10
  1321. };
  1322. #endif
  1323. #if defined(LTC_SHA1) && defined(LTC_DES)
  1324. static const unsigned char long_pri_pkcs8_pbe_sha1_des[] = {
  1325. 0x30, 0x82, 0x01, 0x49, 0x30, 0x1b, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x05,
  1326. 0x0a, 0x30, 0x0e, 0x04, 0x08, 0x7c, 0x01, 0xae, 0xc9, 0x05, 0x43, 0x40, 0x70, 0x02, 0x02, 0x08,
  1327. 0x00, 0x04, 0x82, 0x01, 0x28, 0xff, 0x96, 0x47, 0x56, 0x02, 0xd5, 0xd3, 0x2a, 0xf0, 0x44, 0x47,
  1328. 0x7e, 0x74, 0x28, 0x62, 0x3f, 0x2b, 0xd4, 0xa9, 0xcc, 0x2c, 0xb7, 0x03, 0xc7, 0xa6, 0x39, 0xde,
  1329. 0xc1, 0x46, 0xf1, 0xcd, 0x53, 0xb8, 0x76, 0xcd, 0xb8, 0xfd, 0xe8, 0x96, 0x1d, 0x52, 0xc5, 0xc2,
  1330. 0x33, 0x2c, 0x2e, 0x4a, 0xe1, 0x83, 0x2e, 0x8a, 0x3a, 0x73, 0xfe, 0x50, 0x70, 0xcf, 0x2a, 0x29,
  1331. 0xd5, 0x8a, 0x77, 0x96, 0xa3, 0x29, 0x7e, 0xfa, 0x74, 0xde, 0x78, 0x31, 0xd6, 0x78, 0x0a, 0x4f,
  1332. 0x67, 0x8e, 0x26, 0xc9, 0x64, 0xf3, 0xde, 0xda, 0x5d, 0x15, 0xc2, 0x6b, 0x22, 0x25, 0x9e, 0x98,
  1333. 0x41, 0x71, 0x4c, 0x09, 0x56, 0x90, 0x44, 0x7d, 0x16, 0xab, 0x7e, 0xd3, 0x75, 0x54, 0xbd, 0x88,
  1334. 0x85, 0x4a, 0x01, 0xf4, 0x17, 0x19, 0xe2, 0x43, 0x5f, 0x31, 0xf9, 0x0b, 0x78, 0xd3, 0xb6, 0xc8,
  1335. 0xa0, 0x29, 0x65, 0x86, 0xbc, 0x4b, 0xcb, 0xe2, 0xe8, 0xe7, 0x06, 0xe2, 0x27, 0xa3, 0x6a, 0xdc,
  1336. 0x9f, 0x42, 0x40, 0xc4, 0x38, 0x49, 0x3b, 0x15, 0x28, 0x82, 0x9f, 0xa0, 0x2d, 0x42, 0x30, 0xa9,
  1337. 0x28, 0x84, 0x41, 0x2b, 0xa3, 0xfb, 0xf1, 0x74, 0xa1, 0xfa, 0xff, 0x9d, 0xb6, 0x7e, 0x9b, 0x9f,
  1338. 0xfa, 0xbd, 0x00, 0x17, 0x17, 0xa6, 0xb5, 0x2a, 0x1f, 0x6b, 0x55, 0x6c, 0xd4, 0x4b, 0xbe, 0xbb,
  1339. 0xa5, 0xa7, 0x9f, 0x0c, 0x90, 0x04, 0x91, 0x09, 0x4d, 0x82, 0xe1, 0x67, 0x21, 0x96, 0x3a, 0x3b,
  1340. 0xcf, 0x7f, 0xe9, 0xb9, 0xcc, 0x56, 0xd8, 0xc7, 0xe4, 0x98, 0x30, 0x11, 0x8f, 0xfd, 0xe5, 0xbc,
  1341. 0x5e, 0xc4, 0x60, 0xe9, 0xd4, 0xc6, 0xf2, 0x60, 0xf3, 0xcd, 0x36, 0xa4, 0xe4, 0x6c, 0xfe, 0xbf,
  1342. 0xab, 0xd5, 0x2f, 0x12, 0xf4, 0xa2, 0xf0, 0xeb, 0x10, 0xd9, 0x74, 0xef, 0x7c, 0x37, 0x8d, 0xdd,
  1343. 0xc1, 0xaa, 0x84, 0xf6, 0xf1, 0xb6, 0x5b, 0x43, 0x51, 0x06, 0x78, 0xae, 0x8e, 0x9d, 0xc5, 0xc9,
  1344. 0x26, 0xdc, 0x05, 0xa3, 0x00, 0xfa, 0x4a, 0x27, 0x5f, 0x19, 0xf3, 0x88, 0x2e, 0x01, 0xb8, 0xe7,
  1345. 0x23, 0x37, 0x77, 0xa1, 0xbb, 0xb0, 0x66, 0xe2, 0xba, 0x10, 0x50, 0x06, 0x65
  1346. };
  1347. #endif
  1348. #if defined(LTC_SHA1) && defined(LTC_RC2)
  1349. static const unsigned char long_pri_pkcs8_pbe_sha1_rc2_64[] = {
  1350. 0x30, 0x82, 0x01, 0x49, 0x30, 0x1b, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x05,
  1351. 0x0b, 0x30, 0x0e, 0x04, 0x08, 0x64, 0x3c, 0xdb, 0x86, 0xd9, 0xa0, 0xae, 0x3e, 0x02, 0x02, 0x08,
  1352. 0x00, 0x04, 0x82, 0x01, 0x28, 0x78, 0x85, 0x55, 0x7f, 0x37, 0xb8, 0xf7, 0xff, 0x94, 0x94, 0xf3,
  1353. 0xf2, 0x21, 0x05, 0x6d, 0x75, 0xca, 0x03, 0x1c, 0xa3, 0x9f, 0x47, 0x41, 0x14, 0x57, 0xdd, 0x63,
  1354. 0x71, 0x6c, 0xc2, 0x51, 0x14, 0x4a, 0x0d, 0x63, 0x12, 0xa8, 0x27, 0xf6, 0x3c, 0xb7, 0x47, 0x6d,
  1355. 0xa0, 0x72, 0xfe, 0x60, 0x9f, 0x1c, 0xc8, 0xe4, 0xe5, 0xfe, 0x68, 0x9d, 0x85, 0x0f, 0x8e, 0x52,
  1356. 0x2e, 0x30, 0xd5, 0x81, 0xd8, 0xc9, 0x05, 0x14, 0x1b, 0x1b, 0xf3, 0xbc, 0x95, 0x6d, 0x5d, 0x94,
  1357. 0x71, 0xff, 0xa8, 0xfe, 0xa7, 0x34, 0xff, 0x30, 0xbe, 0x8e, 0xe4, 0x65, 0x6b, 0xd0, 0xa2, 0x43,
  1358. 0x42, 0x14, 0x63, 0x36, 0x6f, 0x5d, 0x79, 0x56, 0x1b, 0x23, 0xd6, 0xdf, 0x39, 0x75, 0x48, 0x07,
  1359. 0xa2, 0x5f, 0x8d, 0x11, 0x7c, 0x95, 0x48, 0x18, 0x2d, 0xdd, 0x92, 0x14, 0x4f, 0xfd, 0x45, 0x7e,
  1360. 0x60, 0x68, 0xde, 0x47, 0x04, 0x0d, 0x0a, 0xa6, 0x3a, 0x30, 0xcb, 0x29, 0xc7, 0x9e, 0x27, 0xc3,
  1361. 0x2d, 0x49, 0xbd, 0x1e, 0xc5, 0xc9, 0xd8, 0xd2, 0x22, 0x72, 0xe2, 0xd0, 0x8e, 0x03, 0xe8, 0x84,
  1362. 0xfd, 0x7e, 0xb8, 0x8a, 0xd7, 0x70, 0x6d, 0x0b, 0xec, 0x67, 0xd0, 0xb3, 0x08, 0x9a, 0x31, 0x32,
  1363. 0x43, 0x1f, 0xa3, 0xd1, 0x6b, 0x3a, 0x63, 0xbc, 0xca, 0x25, 0x1e, 0x55, 0xd7, 0x21, 0x68, 0x77,
  1364. 0xfa, 0x41, 0x70, 0xdc, 0x3a, 0xfb, 0x05, 0x19, 0xd8, 0x8a, 0xe3, 0xe7, 0xfc, 0xf1, 0xc1, 0x0d,
  1365. 0xd4, 0x9e, 0x64, 0xd0, 0x91, 0xa5, 0x4d, 0x7b, 0x8b, 0xd9, 0xee, 0xa7, 0x6b, 0x2b, 0x0f, 0xd9,
  1366. 0xcf, 0xb3, 0xb4, 0x5b, 0x4e, 0xcc, 0xac, 0x53, 0xe5, 0xd3, 0xdd, 0x73, 0x40, 0xa5, 0x35, 0x71,
  1367. 0xeb, 0xca, 0xa7, 0xc0, 0xae, 0x70, 0xdf, 0x14, 0x83, 0xbe, 0xd8, 0x37, 0xfa, 0x8b, 0x14, 0xdb,
  1368. 0x0c, 0x4e, 0x98, 0xc7, 0xe6, 0x40, 0x38, 0x94, 0x69, 0xd4, 0xd4, 0xa9, 0xb5, 0x3f, 0xec, 0xac,
  1369. 0x14, 0x59, 0x46, 0xb5, 0x98, 0xb0, 0x99, 0x89, 0xea, 0xf5, 0x43, 0xb4, 0x47, 0xa9, 0xb1, 0xf2,
  1370. 0x03, 0x2a, 0xaf, 0xd5, 0x5d, 0x81, 0xae, 0x3b, 0xb4, 0x52, 0x11, 0x85, 0xcb
  1371. };
  1372. #endif
  1373. #if defined(LTC_DES)
  1374. static const unsigned char long_pri_pkcs8_pbkdf2_des_cbc[] = {
  1375. 0x30, 0x82, 0x01, 0x6b, 0x30, 0x3d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x05,
  1376. 0x0d, 0x30, 0x30, 0x30, 0x1b, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x05, 0x0c,
  1377. 0x30, 0x0e, 0x04, 0x08, 0xda, 0x6b, 0x0a, 0x58, 0x7e, 0xd2, 0x9d, 0x38, 0x02, 0x02, 0x08, 0x00,
  1378. 0x30, 0x11, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x07, 0x04, 0x08, 0xcc, 0x5c, 0x19, 0x7c, 0xa6,
  1379. 0x0d, 0x01, 0x4b, 0x04, 0x82, 0x01, 0x28, 0x02, 0x9d, 0xec, 0xa4, 0xe1, 0x42, 0xc4, 0xdb, 0x18,
  1380. 0x32, 0x26, 0x96, 0x8b, 0x87, 0x1a, 0xb7, 0x66, 0x8e, 0xfd, 0x23, 0x1e, 0x1e, 0x20, 0x18, 0xcd,
  1381. 0x81, 0x1b, 0x67, 0x86, 0x78, 0xae, 0xb3, 0x70, 0x81, 0xf9, 0x6a, 0x26, 0x4e, 0x31, 0x64, 0xf8,
  1382. 0x7e, 0xbf, 0xf3, 0xd3, 0xea, 0x7c, 0xda, 0x5d, 0x4d, 0xb7, 0xe2, 0xda, 0x9a, 0x80, 0x94, 0xd1,
  1383. 0x65, 0x5f, 0x57, 0x17, 0xbc, 0xac, 0xd3, 0xb4, 0x94, 0xdc, 0xd0, 0x34, 0xe9, 0xed, 0x57, 0x97,
  1384. 0x53, 0xe9, 0x24, 0x21, 0xac, 0x2b, 0xd1, 0xd9, 0x35, 0x7f, 0xf0, 0x79, 0x14, 0xce, 0x96, 0xe2,
  1385. 0x55, 0xfb, 0xb9, 0x6e, 0xeb, 0xbf, 0xc8, 0xf2, 0x66, 0xc1, 0x42, 0xee, 0x94, 0x22, 0xac, 0x6a,
  1386. 0xe2, 0xf6, 0xba, 0xfc, 0xeb, 0xc1, 0xd0, 0xec, 0x3c, 0x16, 0xa4, 0x36, 0x7a, 0xbf, 0xe9, 0x9d,
  1387. 0x39, 0xd6, 0x32, 0x54, 0x3e, 0x86, 0xcf, 0xe4, 0x32, 0x1c, 0xc5, 0x54, 0x3f, 0x8d, 0x6e, 0xb9,
  1388. 0x6c, 0x3d, 0xd7, 0x68, 0xd7, 0x67, 0xdd, 0x04, 0x0e, 0x8c, 0xfd, 0x62, 0x1a, 0x21, 0xa8, 0xcc,
  1389. 0x67, 0xbd, 0x4f, 0x9b, 0x3c, 0x99, 0xd5, 0xa5, 0x98, 0x12, 0x33, 0x04, 0xcf, 0x1b, 0x58, 0x3f,
  1390. 0xb2, 0x70, 0xfe, 0x92, 0xff, 0x7a, 0x73, 0xf9, 0x37, 0xd5, 0x20, 0x0e, 0x49, 0xed, 0xb3, 0x77,
  1391. 0x73, 0x0f, 0x3e, 0xf8, 0x15, 0xc1, 0xfc, 0x28, 0x47, 0x10, 0xe8, 0x30, 0xee, 0xa9, 0x96, 0xcf,
  1392. 0x39, 0xb6, 0x83, 0xe2, 0x84, 0x1d, 0x0e, 0x65, 0xb7, 0x02, 0x08, 0xf7, 0x8d, 0xe7, 0xf2, 0xcc,
  1393. 0x52, 0xc2, 0xe6, 0x1d, 0xf6, 0x96, 0x17, 0x3e, 0x3f, 0xd8, 0x70, 0x8d, 0x2c, 0x62, 0x00, 0xf3,
  1394. 0x32, 0xbd, 0x1c, 0x6b, 0x4a, 0x0c, 0xc6, 0x46, 0x61, 0x92, 0x1c, 0x01, 0x11, 0xbc, 0x55, 0xdd,
  1395. 0x82, 0xd1, 0xbf, 0x2e, 0x1e, 0x97, 0xbe, 0xa7, 0x6e, 0x5a, 0xcd, 0xc6, 0x8f, 0x38, 0x24, 0x8f,
  1396. 0xb8, 0x36, 0x3d, 0x06, 0x82, 0x14, 0x5b, 0x1a, 0x84, 0x1e, 0x47, 0x53, 0x3a, 0x12, 0x21, 0x23,
  1397. 0xbe, 0xe4, 0xf4, 0x57, 0xc7, 0x31, 0x45, 0x24, 0x46, 0x94, 0x53, 0x0b, 0x1d, 0xcd, 0x57
  1398. };
  1399. #endif
  1400. #if defined(LTC_DES)
  1401. static const unsigned char long_pri_pkcs8_pbkdf2_des_ede3_cbc[] = {
  1402. 0x30, 0x82, 0x01, 0x6e, 0x30, 0x40, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x05,
  1403. 0x0d, 0x30, 0x33, 0x30, 0x1b, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x05, 0x0c,
  1404. 0x30, 0x0e, 0x04, 0x08, 0x6a, 0x99, 0x55, 0x06, 0x40, 0xd5, 0xe6, 0xc9, 0x02, 0x02, 0x08, 0x00,
  1405. 0x30, 0x14, 0x06, 0x08, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x03, 0x07, 0x04, 0x08, 0x7f, 0xf2,
  1406. 0xa7, 0xa3, 0x2c, 0xbb, 0x8e, 0x78, 0x04, 0x82, 0x01, 0x28, 0x55, 0x4d, 0xcb, 0xab, 0xb8, 0x6e,
  1407. 0xcf, 0x00, 0xd2, 0xe8, 0x1e, 0x0e, 0xe1, 0x8f, 0x51, 0x8e, 0x32, 0x68, 0xaf, 0x44, 0xa6, 0xf2,
  1408. 0x9e, 0x11, 0xd7, 0x0f, 0xa7, 0xd5, 0x74, 0x77, 0xbc, 0x6b, 0x53, 0x40, 0x70, 0xb6, 0x02, 0xdb,
  1409. 0xa6, 0x2e, 0xc7, 0x20, 0x15, 0x78, 0x91, 0xcc, 0x5b, 0xa7, 0x15, 0x58, 0x65, 0xeb, 0xc7, 0x6f,
  1410. 0xb8, 0x14, 0xc9, 0x5f, 0x89, 0x58, 0xe2, 0xab, 0x69, 0x17, 0xe2, 0xe7, 0xe0, 0xa4, 0x59, 0xb7,
  1411. 0x6a, 0xc2, 0xe5, 0xba, 0x03, 0x0e, 0xcc, 0x0a, 0xb1, 0xf0, 0x69, 0xb2, 0x90, 0xac, 0x30, 0x79,
  1412. 0xd4, 0xa3, 0x90, 0xa2, 0x60, 0x37, 0x7d, 0xf8, 0xd9, 0x49, 0xa3, 0x0b, 0x6d, 0xd9, 0x98, 0x9e,
  1413. 0xb0, 0x6a, 0xad, 0x97, 0x08, 0xf1, 0xfd, 0xec, 0xf8, 0xa7, 0x3c, 0xf6, 0x48, 0x81, 0x5b, 0x6d,
  1414. 0x19, 0xcc, 0xed, 0x49, 0x94, 0x05, 0x6e, 0xa4, 0x9b, 0x58, 0xdd, 0xaf, 0xd7, 0x3d, 0x12, 0xe6,
  1415. 0xf4, 0x12, 0x46, 0xd9, 0x82, 0xde, 0xb7, 0xc4, 0xeb, 0x1c, 0x3a, 0xef, 0x93, 0x82, 0x3d, 0xf8,
  1416. 0x55, 0x88, 0xe5, 0x54, 0xd6, 0x74, 0x1c, 0x20, 0xbd, 0x40, 0x65, 0x99, 0x19, 0x5f, 0x25, 0x62,
  1417. 0x35, 0x6d, 0x32, 0x64, 0xd7, 0xa1, 0x45, 0xa8, 0xc4, 0x8d, 0xe0, 0x6d, 0x14, 0x85, 0x84, 0x75,
  1418. 0x62, 0x0f, 0xb0, 0xe9, 0xb1, 0xca, 0x31, 0x97, 0x22, 0x41, 0xb3, 0xf5, 0xdf, 0x5c, 0xbf, 0x3f,
  1419. 0x4f, 0x01, 0xf8, 0xe7, 0xbc, 0xdc, 0xb2, 0x9a, 0x7d, 0x0c, 0x96, 0x38, 0x48, 0x7a, 0x1b, 0x89,
  1420. 0x2b, 0xab, 0xa6, 0xbd, 0xee, 0x7a, 0xf8, 0x85, 0x82, 0x80, 0x8c, 0x3b, 0x05, 0x3c, 0x40, 0x69,
  1421. 0x97, 0x0a, 0x4c, 0x45, 0xae, 0x38, 0x22, 0xc5, 0x95, 0xf2, 0x4f, 0x0c, 0xd5, 0x54, 0x23, 0x92,
  1422. 0x9b, 0x06, 0x81, 0xca, 0xa5, 0x1e, 0x91, 0x7e, 0x2b, 0x85, 0xb4, 0xd4, 0xeb, 0xb6, 0xee, 0x22,
  1423. 0x10, 0x72, 0xaf, 0x9e, 0x6d, 0xcc, 0x16, 0x24, 0x01, 0x44, 0x48, 0xaa, 0xc9, 0xf8, 0x38, 0x72,
  1424. 0x7a, 0x35, 0x94, 0x20, 0x58, 0xa2, 0x1c, 0x81, 0xaf, 0x47, 0x3b, 0xb8, 0x23, 0xbb, 0x71, 0x09,
  1425. 0xbf, 0x93
  1426. };
  1427. #endif
  1428. #if defined(LTC_RC2)
  1429. static const unsigned char long_pri_pkcs8_pbkdf2_rc2_cbc[] = {
  1430. 0x30, 0x82, 0x01, 0x76, 0x30, 0x48, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x05,
  1431. 0x0d, 0x30, 0x3b, 0x30, 0x1e, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x05, 0x0c,
  1432. 0x30, 0x11, 0x04, 0x08, 0xbf, 0xef, 0x1a, 0x42, 0x5d, 0xc3, 0x6b, 0x0f, 0x02, 0x02, 0x08, 0x00,
  1433. 0x02, 0x01, 0x10, 0x30, 0x19, 0x06, 0x08, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x03, 0x02, 0x30,
  1434. 0x0d, 0x02, 0x01, 0x3a, 0x04, 0x08, 0xfe, 0xf2, 0x09, 0x0c, 0xa4, 0xd0, 0xe6, 0x83, 0x04, 0x82,
  1435. 0x01, 0x28, 0x61, 0x18, 0x73, 0xb7, 0x9d, 0x58, 0xc8, 0x4a, 0xf4, 0x24, 0xec, 0xb4, 0xe6, 0x24,
  1436. 0xa7, 0xf0, 0x1e, 0xea, 0xc3, 0x57, 0x44, 0xb7, 0x5a, 0x77, 0xe5, 0x3c, 0x1c, 0x6a, 0x6b, 0x70,
  1437. 0x6e, 0x64, 0x35, 0xa5, 0x5d, 0x32, 0xe3, 0xce, 0xe8, 0x79, 0xa4, 0x7f, 0x2b, 0xfc, 0xcb, 0x07,
  1438. 0x62, 0xcd, 0xc9, 0x15, 0x30, 0xdf, 0x69, 0xae, 0xe8, 0xb4, 0x83, 0xec, 0x2a, 0xaf, 0xb3, 0x29,
  1439. 0x92, 0x77, 0xf3, 0x31, 0x4d, 0x5f, 0xcb, 0xea, 0xa2, 0x4d, 0xfb, 0xa1, 0x68, 0xbe, 0x00, 0x01,
  1440. 0x6d, 0x3f, 0xc6, 0xc1, 0x13, 0xee, 0xb0, 0x5a, 0x52, 0xce, 0xdc, 0x12, 0xf8, 0x42, 0x22, 0x2f,
  1441. 0x57, 0x2e, 0x54, 0xac, 0x48, 0x31, 0x4d, 0x3c, 0xa1, 0x97, 0x5e, 0x17, 0x74, 0x88, 0x9b, 0x31,
  1442. 0x91, 0x69, 0x00, 0x00, 0x15, 0x2c, 0xc2, 0xac, 0x70, 0x84, 0x9c, 0x7e, 0x5d, 0xc9, 0xee, 0x06,
  1443. 0xcc, 0x38, 0x9d, 0x7d, 0xea, 0x71, 0xc3, 0x4f, 0x99, 0x08, 0xde, 0xb0, 0x1b, 0x3b, 0x2a, 0xbd,
  1444. 0x7e, 0x01, 0x3b, 0x5e, 0xe5, 0xc2, 0x54, 0xf2, 0x30, 0xe5, 0xa0, 0xf3, 0x69, 0x87, 0x77, 0xed,
  1445. 0xa1, 0x37, 0x76, 0x6a, 0xec, 0xe2, 0x9c, 0x8d, 0x4c, 0xe9, 0xf4, 0xd0, 0xca, 0xb5, 0x8f, 0xd0,
  1446. 0x63, 0x17, 0x41, 0xcb, 0x29, 0x58, 0x4f, 0x2a, 0xd1, 0xe1, 0x03, 0x73, 0x09, 0xcc, 0x93, 0xc6,
  1447. 0xde, 0x1e, 0x34, 0x0f, 0xb3, 0x67, 0xfd, 0x5e, 0x49, 0x16, 0x84, 0x84, 0x6a, 0x8f, 0x55, 0x22,
  1448. 0x0b, 0xe4, 0xd8, 0xee, 0x2e, 0x9f, 0x25, 0x19, 0x89, 0x19, 0xe6, 0x8d, 0x64, 0x31, 0x38, 0x68,
  1449. 0xfa, 0x40, 0x84, 0xca, 0x39, 0xef, 0x1a, 0x4a, 0xe9, 0x04, 0xee, 0xcc, 0x4a, 0xea, 0x19, 0x96,
  1450. 0xa4, 0xcd, 0x62, 0x76, 0xb3, 0xc4, 0x2c, 0x23, 0x75, 0x24, 0xcd, 0x49, 0xe2, 0x17, 0x81, 0x45,
  1451. 0x24, 0x55, 0xeb, 0xe1, 0xb4, 0xeb, 0xda, 0xc5, 0x56, 0xac, 0xfa, 0x30, 0xbd, 0x05, 0xbb, 0x03,
  1452. 0x65, 0x50, 0xdc, 0xbf, 0xdf, 0xff, 0x2a, 0x80, 0x85, 0x6d, 0x6a, 0x5c, 0x93, 0xb8, 0x81, 0xc4,
  1453. 0xca, 0x91, 0x08, 0x7b, 0x8a, 0x9d, 0xe9, 0x2d, 0xfc, 0x3b
  1454. };
  1455. #endif
  1456. #if defined(LTC_SHA224) && defined(LTC_DES)
  1457. static const unsigned char long_pri_pkcs8_pbkdf2_sha224_des_ede3_cbc[] = {
  1458. 0x30, 0x82, 0x01, 0x7c, 0x30, 0x4e, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x05,
  1459. 0x0d, 0x30, 0x41, 0x30, 0x29, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x05, 0x0c,
  1460. 0x30, 0x1c, 0x04, 0x08, 0xb2, 0x82, 0x71, 0xc5, 0xd6, 0x3c, 0x2b, 0x92, 0x02, 0x02, 0x08, 0x00,
  1461. 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x02, 0x08, 0x05, 0x00, 0x30, 0x14,
  1462. 0x06, 0x08, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x03, 0x07, 0x04, 0x08, 0x4a, 0x46, 0x2a, 0xa9,
  1463. 0xd5, 0x9f, 0x79, 0xea, 0x04, 0x82, 0x01, 0x28, 0xc4, 0x27, 0x05, 0xa8, 0x01, 0xa7, 0xc9, 0x0d,
  1464. 0x0e, 0x74, 0x06, 0x4a, 0xb8, 0x07, 0x9f, 0x7b, 0x0f, 0x82, 0xfd, 0x2c, 0xb5, 0x4f, 0x63, 0xed,
  1465. 0xed, 0x86, 0x96, 0x79, 0x08, 0x2d, 0x5f, 0x6d, 0x8c, 0x83, 0xc9, 0xcc, 0xd4, 0x9b, 0x0a, 0x81,
  1466. 0x60, 0x22, 0x09, 0xb9, 0x12, 0xca, 0xf1, 0xad, 0x61, 0x22, 0xf0, 0x6b, 0xdb, 0x52, 0x99, 0xae,
  1467. 0x70, 0x2b, 0x61, 0x63, 0xdc, 0x2f, 0xc1, 0xd3, 0xb5, 0x28, 0xbb, 0xa1, 0xd2, 0xb7, 0xaf, 0xbb,
  1468. 0x86, 0xa1, 0x1b, 0x46, 0x0a, 0xc9, 0xab, 0x44, 0xd2, 0x9c, 0x16, 0x18, 0x8b, 0x4a, 0x92, 0x56,
  1469. 0x5b, 0x50, 0x39, 0x1b, 0x88, 0x50, 0x92, 0x35, 0xb8, 0x85, 0xc3, 0xaa, 0x56, 0x76, 0xde, 0xbf,
  1470. 0x68, 0x91, 0x2e, 0xc8, 0x28, 0x29, 0xd8, 0x71, 0x60, 0xe3, 0xf0, 0x5a, 0x66, 0x85, 0xdd, 0x6b,
  1471. 0x5c, 0xaf, 0xf1, 0x28, 0xf8, 0xdc, 0xa7, 0x8d, 0xc4, 0x9b, 0xcb, 0xb2, 0x99, 0x34, 0x4d, 0x76,
  1472. 0xa0, 0x8b, 0xf2, 0x18, 0x8e, 0x42, 0xe0, 0x79, 0xc3, 0xeb, 0x0f, 0x00, 0xe7, 0xbe, 0x83, 0xdf,
  1473. 0xba, 0xa5, 0xf1, 0x81, 0x05, 0x1c, 0xc9, 0xda, 0xea, 0xe1, 0xc4, 0x38, 0x24, 0x1e, 0xcf, 0xea,
  1474. 0x22, 0x05, 0x75, 0x43, 0xfe, 0xfe, 0x14, 0xf7, 0x6d, 0x41, 0x67, 0xcf, 0xfd, 0x57, 0xa7, 0xfc,
  1475. 0x22, 0x03, 0x14, 0xc1, 0xf6, 0x4d, 0x40, 0x4e, 0xf1, 0xec, 0x72, 0xec, 0x3c, 0xb1, 0x87, 0x44,
  1476. 0xe9, 0x72, 0xc5, 0x8b, 0x48, 0xd9, 0x98, 0x08, 0x55, 0xc5, 0x40, 0x26, 0xf5, 0x8d, 0x73, 0x5e,
  1477. 0x35, 0x98, 0x71, 0x09, 0x98, 0xfa, 0xb7, 0x1c, 0x35, 0xcd, 0xd4, 0xf1, 0x65, 0xb4, 0x59, 0xdb,
  1478. 0x9e, 0x79, 0xe7, 0x21, 0x99, 0xd7, 0x9e, 0x8c, 0x13, 0x77, 0x0c, 0x5e, 0xae, 0x43, 0x82, 0xf1,
  1479. 0x83, 0x79, 0x7d, 0x37, 0x51, 0xde, 0x65, 0x26, 0x1f, 0x8f, 0x81, 0x1c, 0x55, 0x40, 0xec, 0xaf,
  1480. 0x3f, 0x0a, 0x68, 0xd2, 0xc7, 0x59, 0x47, 0xda, 0x78, 0x0c, 0x0e, 0x59, 0x6a, 0x93, 0xcd, 0x05,
  1481. 0x09, 0x51, 0x47, 0xb1, 0x45, 0x3f, 0x67, 0xf8, 0x76, 0x50, 0x76, 0xa3, 0x2d, 0x31, 0x17, 0x73
  1482. };
  1483. #endif
  1484. #if defined(LTC_SHA256) && defined(LTC_DES)
  1485. static const unsigned char long_pri_pkcs8_pbkdf2_sha256_des_ede3_cbc[] = {
  1486. 0x30, 0x82, 0x01, 0x7c, 0x30, 0x4e, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x05,
  1487. 0x0d, 0x30, 0x41, 0x30, 0x29, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x05, 0x0c,
  1488. 0x30, 0x1c, 0x04, 0x08, 0x93, 0x6e, 0x0a, 0x02, 0x8e, 0x72, 0xac, 0x98, 0x02, 0x02, 0x08, 0x00,
  1489. 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x02, 0x09, 0x05, 0x00, 0x30, 0x14,
  1490. 0x06, 0x08, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x03, 0x07, 0x04, 0x08, 0x89, 0xa4, 0xc9, 0xd9,
  1491. 0x82, 0xfa, 0x02, 0x76, 0x04, 0x82, 0x01, 0x28, 0xec, 0xd9, 0xee, 0xbf, 0xfa, 0xe6, 0x51, 0xdb,
  1492. 0x02, 0xcb, 0xf3, 0x2c, 0x55, 0xdb, 0x83, 0x90, 0x5d, 0x9e, 0xf6, 0xbe, 0x10, 0xae, 0x35, 0x8c,
  1493. 0x22, 0x39, 0xfc, 0xf9, 0xd1, 0x23, 0x27, 0x68, 0xd3, 0x15, 0x46, 0xed, 0x5d, 0x15, 0xfb, 0xdf,
  1494. 0x6f, 0xe1, 0x01, 0x1c, 0xed, 0x4c, 0xfc, 0x78, 0x94, 0x47, 0x71, 0x92, 0xbc, 0xa1, 0xa6, 0x06,
  1495. 0x74, 0x22, 0xcc, 0xbb, 0x49, 0x98, 0x43, 0xf1, 0xc2, 0xde, 0x4e, 0xeb, 0x56, 0x0e, 0x03, 0xc1,
  1496. 0xf1, 0xc1, 0x80, 0x4b, 0x70, 0xd0, 0x8f, 0xf3, 0xd8, 0x18, 0x08, 0x41, 0x7a, 0xf9, 0x8b, 0x74,
  1497. 0xe5, 0x28, 0x61, 0x77, 0x2f, 0x84, 0xb3, 0xb3, 0x68, 0xce, 0x19, 0xf0, 0xc6, 0xa9, 0xc1, 0x29,
  1498. 0x96, 0xca, 0x3b, 0xdb, 0x13, 0x99, 0x86, 0xbe, 0x21, 0x0d, 0x00, 0xd7, 0x30, 0x15, 0x74, 0xfb,
  1499. 0x43, 0xf7, 0x14, 0x97, 0x6d, 0xed, 0xeb, 0xe3, 0x4d, 0x67, 0x80, 0x35, 0x03, 0x69, 0x0d, 0xbe,
  1500. 0xf1, 0x99, 0x6b, 0x53, 0xb7, 0xa3, 0xdf, 0xf4, 0xc3, 0xda, 0x20, 0x9b, 0xbf, 0xf9, 0x3f, 0x19,
  1501. 0xae, 0xd5, 0x37, 0x91, 0x36, 0x42, 0xf3, 0x7d, 0xad, 0x40, 0x3c, 0x2a, 0x7f, 0x2d, 0xf1, 0x79,
  1502. 0xee, 0x4c, 0x08, 0x3a, 0xd6, 0x35, 0x9b, 0xc9, 0xff, 0xd8, 0x41, 0x41, 0xd1, 0xc6, 0xa1, 0xba,
  1503. 0x4d, 0xc6, 0xb7, 0x85, 0x05, 0xa1, 0x8e, 0xeb, 0xd1, 0xd2, 0x3a, 0x13, 0xd7, 0xbd, 0xb0, 0x02,
  1504. 0xfe, 0x54, 0xfe, 0xf4, 0xfd, 0x31, 0x0c, 0x42, 0x78, 0xb9, 0x17, 0x90, 0x36, 0x17, 0xb8, 0x1a,
  1505. 0x08, 0xe8, 0x7e, 0x5f, 0xbb, 0x30, 0xc2, 0xec, 0xd5, 0x08, 0xbc, 0xae, 0x2f, 0xe0, 0xca, 0xf2,
  1506. 0x44, 0x2c, 0xa4, 0xb5, 0xec, 0xb9, 0xc2, 0xa3, 0x4a, 0x1a, 0x49, 0xfb, 0x3e, 0x5c, 0xb5, 0xd8,
  1507. 0xb6, 0xf0, 0xbc, 0xa2, 0xda, 0xaa, 0x7a, 0x05, 0x4d, 0x06, 0xc0, 0x4b, 0x8f, 0x59, 0xce, 0x56,
  1508. 0x02, 0x26, 0xb2, 0xa0, 0x5f, 0x74, 0xbb, 0x0b, 0x01, 0x1c, 0xb2, 0x0b, 0x8a, 0x80, 0xa4, 0x5d,
  1509. 0x6e, 0x52, 0x24, 0xd0, 0xbe, 0xf5, 0x8e, 0x9e, 0x9e, 0x02, 0x40, 0x08, 0x99, 0xe0, 0x2c, 0xf9
  1510. };
  1511. #endif
  1512. #if defined(LTC_SHA384) && defined(LTC_DES)
  1513. static const unsigned char long_pri_pkcs8_pbkdf2_sha384_des_ede3_cbc[] = {
  1514. 0x30, 0x82, 0x01, 0x7c, 0x30, 0x4e, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x05,
  1515. 0x0d, 0x30, 0x41, 0x30, 0x29, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x05, 0x0c,
  1516. 0x30, 0x1c, 0x04, 0x08, 0xfd, 0x6c, 0xdf, 0x0b, 0x23, 0xed, 0x71, 0xf7, 0x02, 0x02, 0x08, 0x00,
  1517. 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x02, 0x0a, 0x05, 0x00, 0x30, 0x14,
  1518. 0x06, 0x08, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x03, 0x07, 0x04, 0x08, 0x99, 0xd0, 0x84, 0x7d,
  1519. 0x6d, 0x4e, 0x82, 0xe1, 0x04, 0x82, 0x01, 0x28, 0xac, 0x9a, 0x2c, 0x71, 0xdf, 0x1a, 0x19, 0x38,
  1520. 0xee, 0xc4, 0x9d, 0x7a, 0x27, 0xe0, 0xb9, 0x69, 0x32, 0xed, 0xe7, 0xa1, 0x77, 0x16, 0x60, 0x18,
  1521. 0x7a, 0xf1, 0x47, 0xc1, 0x98, 0x48, 0xa4, 0xff, 0xab, 0x83, 0x1a, 0x7d, 0xe3, 0xdb, 0xcc, 0xf0,
  1522. 0x40, 0x94, 0x3a, 0x6a, 0x3f, 0xf7, 0x88, 0x19, 0x59, 0xf4, 0xd8, 0x1b, 0x87, 0x14, 0x5b, 0x9c,
  1523. 0x1f, 0xc5, 0xaf, 0x80, 0xe8, 0x06, 0xdb, 0xfa, 0x2c, 0xac, 0x61, 0x1c, 0xec, 0xec, 0x99, 0x5e,
  1524. 0x06, 0x6e, 0x68, 0x4c, 0xb0, 0xc8, 0x6f, 0x74, 0x2c, 0x1e, 0x58, 0x2f, 0x49, 0x82, 0xa4, 0x2b,
  1525. 0xb4, 0x4a, 0x2d, 0x77, 0x13, 0x87, 0xed, 0xbd, 0x71, 0x5a, 0x29, 0x29, 0x0c, 0x88, 0x4a, 0xf3,
  1526. 0x76, 0x37, 0x7e, 0x04, 0x3c, 0x45, 0x76, 0x98, 0x22, 0x20, 0x97, 0xef, 0xae, 0x4a, 0xa9, 0x08,
  1527. 0x54, 0xef, 0x43, 0xe0, 0x86, 0x54, 0x72, 0x44, 0xd1, 0x25, 0x9c, 0xb6, 0x7d, 0x88, 0xbd, 0x8f,
  1528. 0xbe, 0xcb, 0xa8, 0x63, 0xfe, 0x66, 0x54, 0xa2, 0xce, 0x77, 0x19, 0x7e, 0xdd, 0xf7, 0x4d, 0xdc,
  1529. 0xb1, 0xf7, 0xbf, 0x3c, 0xb5, 0xd2, 0x30, 0x9d, 0x3c, 0x35, 0x09, 0x37, 0xae, 0xae, 0x0f, 0x0b,
  1530. 0x9d, 0xf5, 0x10, 0xae, 0x56, 0x83, 0x4f, 0xd8, 0xcd, 0xfe, 0xb7, 0xa9, 0x54, 0xf9, 0xb3, 0x89,
  1531. 0xf6, 0x9a, 0x11, 0x60, 0x04, 0x4d, 0x80, 0xaf, 0x74, 0x73, 0x2d, 0xc4, 0x24, 0x23, 0xaa, 0x50,
  1532. 0x4c, 0xf1, 0xd6, 0x2d, 0xc6, 0x74, 0xeb, 0x62, 0x02, 0xda, 0x81, 0x68, 0xc8, 0x68, 0xf0, 0x82,
  1533. 0x71, 0xb2, 0xa5, 0x8e, 0x45, 0x93, 0x29, 0x94, 0x8f, 0xec, 0x11, 0x65, 0xcc, 0xd6, 0x4c, 0x2e,
  1534. 0x0d, 0x4e, 0x45, 0xb4, 0x4e, 0x97, 0x38, 0xd0, 0xc2, 0x61, 0x43, 0x78, 0xa4, 0x08, 0x0a, 0x58,
  1535. 0x3f, 0x66, 0xdb, 0x34, 0x42, 0x17, 0x42, 0x92, 0x04, 0x9a, 0x2d, 0x73, 0xaf, 0x58, 0x38, 0xc8,
  1536. 0x3f, 0x5b, 0x83, 0x95, 0x3d, 0xae, 0xae, 0x60, 0x2b, 0x6d, 0xd9, 0xb4, 0xe3, 0x97, 0x6b, 0x49,
  1537. 0xef, 0xd9, 0x68, 0xbb, 0x8d, 0x3a, 0x7e, 0xcb, 0x57, 0x33, 0xf5, 0x1a, 0x8d, 0xb4, 0x6d, 0xfb
  1538. };
  1539. #endif
  1540. #if defined(LTC_SHA512) && defined(LTC_DES)
  1541. static const unsigned char long_pri_pkcs8_pbkdf2_sha512_des_ede3_cbc[] = {
  1542. 0x30, 0x82, 0x01, 0x7c, 0x30, 0x4e, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x05,
  1543. 0x0d, 0x30, 0x41, 0x30, 0x29, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x05, 0x0c,
  1544. 0x30, 0x1c, 0x04, 0x08, 0xad, 0xb1, 0xe1, 0x21, 0xdc, 0xe5, 0x09, 0xee, 0x02, 0x02, 0x08, 0x00,
  1545. 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x02, 0x0b, 0x05, 0x00, 0x30, 0x14,
  1546. 0x06, 0x08, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x03, 0x07, 0x04, 0x08, 0x1a, 0x8b, 0x81, 0x3b,
  1547. 0x97, 0x7d, 0xfa, 0x51, 0x04, 0x82, 0x01, 0x28, 0x6d, 0x6f, 0x93, 0x77, 0xcb, 0x52, 0x2d, 0x3b,
  1548. 0x82, 0x12, 0x80, 0xce, 0x9e, 0x69, 0x03, 0xe4, 0x64, 0xa1, 0x4b, 0x8e, 0x60, 0x51, 0x4d, 0x08,
  1549. 0xe1, 0x25, 0x5d, 0xe6, 0xed, 0x20, 0x23, 0x4c, 0x4e, 0xa3, 0xe8, 0xab, 0x7a, 0xf8, 0x54, 0x65,
  1550. 0x22, 0x92, 0x0c, 0x45, 0xab, 0x1c, 0xe2, 0x68, 0x4e, 0xf3, 0xa9, 0x61, 0xd6, 0x44, 0x9d, 0x55,
  1551. 0x19, 0xc6, 0xd9, 0x2a, 0x0d, 0x45, 0x7d, 0xca, 0xa4, 0x41, 0xb5, 0x6d, 0xd5, 0x09, 0xf2, 0xb6,
  1552. 0x81, 0x95, 0x64, 0xdb, 0x2b, 0xed, 0x83, 0x6b, 0x44, 0xa6, 0xce, 0x36, 0x8d, 0x23, 0x89, 0xb6,
  1553. 0xf3, 0xb0, 0xe0, 0xcf, 0x57, 0x72, 0xc7, 0x61, 0x3f, 0x29, 0xb9, 0xea, 0xe8, 0x7a, 0xca, 0x43,
  1554. 0x90, 0x79, 0x81, 0x8a, 0xe2, 0x3c, 0xd1, 0xa6, 0xd9, 0x09, 0xd8, 0x7d, 0xd0, 0x90, 0x69, 0x7e,
  1555. 0xdd, 0x40, 0xde, 0xba, 0x11, 0xc6, 0x6f, 0x75, 0xfc, 0xc3, 0x99, 0x43, 0xd2, 0xa4, 0x16, 0x2e,
  1556. 0x95, 0x99, 0x12, 0x77, 0xe8, 0x86, 0x9a, 0xf9, 0x97, 0xf4, 0x43, 0x99, 0x1d, 0x7b, 0xe0, 0x69,
  1557. 0xb0, 0xe9, 0x45, 0xd0, 0x0b, 0xaa, 0xd0, 0xa9, 0x90, 0x85, 0x39, 0xd9, 0xe0, 0xe4, 0xe5, 0xf3,
  1558. 0xcf, 0xb6, 0x60, 0x63, 0x51, 0x0b, 0xd8, 0x3d, 0xa2, 0x0f, 0xf6, 0x53, 0x09, 0x2e, 0x11, 0xc4,
  1559. 0xe6, 0xe3, 0xfa, 0xfb, 0x9f, 0x4d, 0xf4, 0xef, 0xb2, 0xf6, 0x9b, 0xc6, 0xb3, 0x75, 0x66, 0xfd,
  1560. 0x1b, 0x44, 0xba, 0x3c, 0xa8, 0x51, 0xbe, 0x97, 0xf1, 0x54, 0xb5, 0xcc, 0x6f, 0x5f, 0x1d, 0x9b,
  1561. 0xee, 0xed, 0x7a, 0x82, 0xfa, 0x40, 0x39, 0xa7, 0xf5, 0x8e, 0x5e, 0x42, 0xfa, 0x37, 0xcc, 0xe8,
  1562. 0x99, 0x38, 0xc1, 0xab, 0x83, 0xb8, 0x3c, 0x25, 0x17, 0x5f, 0xb7, 0x45, 0x0f, 0xcd, 0xec, 0x2a,
  1563. 0x47, 0x07, 0x02, 0xba, 0x92, 0xc1, 0x79, 0xf1, 0x95, 0xc7, 0x83, 0x46, 0xd7, 0x9e, 0x04, 0x96,
  1564. 0x3c, 0x5d, 0x7e, 0x70, 0xe6, 0x2b, 0x72, 0x70, 0x42, 0x66, 0x17, 0x0e, 0xc3, 0xcf, 0x32, 0x28,
  1565. 0x0c, 0xf9, 0x46, 0x38, 0xb7, 0x64, 0xd6, 0x51, 0xf9, 0xbd, 0x57, 0xf2, 0x7a, 0xcc, 0x02, 0xe3
  1566. };
  1567. #endif
  1568. static const unsigned char long_pric[] = { /* private + compressed public, explicit curve params */
  1569. 0x30, 0x81, 0xd3, 0x02, 0x01, 0x01, 0x04, 0x20, 0x0c, 0xf1, 0xad, 0x2f, 0x03, 0xf7, 0x91, 0x1b,
  1570. 0xba, 0x03, 0xcf, 0x23, 0x37, 0xc8, 0xf2, 0xf7, 0x36, 0xce, 0x65, 0xf1, 0x84, 0x2d, 0x7d, 0x9f,
  1571. 0x5f, 0x9e, 0x21, 0xd9, 0x5e, 0x49, 0xbd, 0x23, 0xa0, 0x81, 0x85, 0x30, 0x81, 0x82, 0x02, 0x01,
  1572. 0x01, 0x30, 0x2c, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x01, 0x01, 0x02, 0x21, 0x00, 0xff,
  1573. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  1574. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xfc, 0x2f, 0x30,
  1575. 0x06, 0x04, 0x01, 0x00, 0x04, 0x01, 0x07, 0x04, 0x21, 0x02, 0x79, 0xbe, 0x66, 0x7e, 0xf9, 0xdc,
  1576. 0xbb, 0xac, 0x55, 0xa0, 0x62, 0x95, 0xce, 0x87, 0x0b, 0x07, 0x02, 0x9b, 0xfc, 0xdb, 0x2d, 0xce,
  1577. 0x28, 0xd9, 0x59, 0xf2, 0x81, 0x5b, 0x16, 0xf8, 0x17, 0x98, 0x02, 0x21, 0x00, 0xff, 0xff, 0xff,
  1578. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xba, 0xae, 0xdc,
  1579. 0xe6, 0xaf, 0x48, 0xa0, 0x3b, 0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36, 0x41, 0x41, 0x02, 0x01, 0x01,
  1580. 0xa1, 0x24, 0x03, 0x22, 0x00, 0x03, 0x2a, 0xf9, 0x0b, 0xda, 0xbe, 0x71, 0x66, 0x9e, 0xd1, 0xcf,
  1581. 0x12, 0xd0, 0x24, 0xaf, 0xba, 0xb6, 0x7f, 0xfb, 0x96, 0x27, 0x3e, 0x2f, 0xbd, 0x1e, 0xd5, 0xf9,
  1582. 0x8d, 0x6c, 0x73, 0x9d, 0xc5, 0x16
  1583. };
  1584. static const unsigned char long_pric_pkcs8[] = { /* private + compressed public, explicit curve params, PKCS8 */
  1585. 0x30, 0x81, 0xe3, 0x02, 0x01, 0x00, 0x30, 0x81, 0x8e, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d,
  1586. 0x02, 0x01, 0x30, 0x81, 0x82, 0x02, 0x01, 0x01, 0x30, 0x2c, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce,
  1587. 0x3d, 0x01, 0x01, 0x02, 0x21, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  1588. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  1589. 0xff, 0xfe, 0xff, 0xff, 0xfc, 0x2f, 0x30, 0x06, 0x04, 0x01, 0x00, 0x04, 0x01, 0x07, 0x04, 0x21,
  1590. 0x02, 0x79, 0xbe, 0x66, 0x7e, 0xf9, 0xdc, 0xbb, 0xac, 0x55, 0xa0, 0x62, 0x95, 0xce, 0x87, 0x0b,
  1591. 0x07, 0x02, 0x9b, 0xfc, 0xdb, 0x2d, 0xce, 0x28, 0xd9, 0x59, 0xf2, 0x81, 0x5b, 0x16, 0xf8, 0x17,
  1592. 0x98, 0x02, 0x21, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  1593. 0xff, 0xff, 0xff, 0xfe, 0xba, 0xae, 0xdc, 0xe6, 0xaf, 0x48, 0xa0, 0x3b, 0xbf, 0xd2, 0x5e, 0x8c,
  1594. 0xd0, 0x36, 0x41, 0x41, 0x02, 0x01, 0x01, 0x04, 0x4d, 0x30, 0x4b, 0x02, 0x01, 0x01, 0x04, 0x20,
  1595. 0x0c, 0xf1, 0xad, 0x2f, 0x03, 0xf7, 0x91, 0x1b, 0xba, 0x03, 0xcf, 0x23, 0x37, 0xc8, 0xf2, 0xf7,
  1596. 0x36, 0xce, 0x65, 0xf1, 0x84, 0x2d, 0x7d, 0x9f, 0x5f, 0x9e, 0x21, 0xd9, 0x5e, 0x49, 0xbd, 0x23,
  1597. 0xa1, 0x24, 0x03, 0x22, 0x00, 0x03, 0x2a, 0xf9, 0x0b, 0xda, 0xbe, 0x71, 0x66, 0x9e, 0xd1, 0xcf,
  1598. 0x12, 0xd0, 0x24, 0xaf, 0xba, 0xb6, 0x7f, 0xfb, 0x96, 0x27, 0x3e, 0x2f, 0xbd, 0x1e, 0xd5, 0xf9,
  1599. 0x8d, 0x6c, 0x73, 0x9d, 0xc5, 0x16
  1600. };
  1601. static const unsigned char long_pub[] = { /* long public, explicit curve params */
  1602. 0x30, 0x81, 0xf5, 0x30, 0x81, 0xae, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x30,
  1603. 0x81, 0xa2, 0x02, 0x01, 0x01, 0x30, 0x2c, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x01, 0x01,
  1604. 0x02, 0x21, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  1605. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff,
  1606. 0xff, 0xfc, 0x2f, 0x30, 0x06, 0x04, 0x01, 0x00, 0x04, 0x01, 0x07, 0x04, 0x41, 0x04, 0x79, 0xbe,
  1607. 0x66, 0x7e, 0xf9, 0xdc, 0xbb, 0xac, 0x55, 0xa0, 0x62, 0x95, 0xce, 0x87, 0x0b, 0x07, 0x02, 0x9b,
  1608. 0xfc, 0xdb, 0x2d, 0xce, 0x28, 0xd9, 0x59, 0xf2, 0x81, 0x5b, 0x16, 0xf8, 0x17, 0x98, 0x48, 0x3a,
  1609. 0xda, 0x77, 0x26, 0xa3, 0xc4, 0x65, 0x5d, 0xa4, 0xfb, 0xfc, 0x0e, 0x11, 0x08, 0xa8, 0xfd, 0x17,
  1610. 0xb4, 0x48, 0xa6, 0x85, 0x54, 0x19, 0x9c, 0x47, 0xd0, 0x8f, 0xfb, 0x10, 0xd4, 0xb8, 0x02, 0x21,
  1611. 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  1612. 0xfe, 0xba, 0xae, 0xdc, 0xe6, 0xaf, 0x48, 0xa0, 0x3b, 0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36, 0x41,
  1613. 0x41, 0x02, 0x01, 0x01, 0x03, 0x42, 0x00, 0x04, 0x2a, 0xf9, 0x0b, 0xda, 0xbe, 0x71, 0x66, 0x9e,
  1614. 0xd1, 0xcf, 0x12, 0xd0, 0x24, 0xaf, 0xba, 0xb6, 0x7f, 0xfb, 0x96, 0x27, 0x3e, 0x2f, 0xbd, 0x1e,
  1615. 0xd5, 0xf9, 0x8d, 0x6c, 0x73, 0x9d, 0xc5, 0x16, 0x91, 0xbd, 0xb2, 0xb9, 0x1b, 0x40, 0x10, 0x5a,
  1616. 0xb7, 0x6c, 0x6e, 0x32, 0x5b, 0xf7, 0x63, 0x62, 0x94, 0x24, 0x24, 0xdb, 0xec, 0x3f, 0x8b, 0xe5,
  1617. 0x6e, 0x4b, 0x64, 0x37, 0x31, 0x24, 0x79, 0x4d
  1618. };
  1619. static const unsigned char long_pubc[] = { /* compressed public, explicit curve params */
  1620. 0x30, 0x81, 0xb5, 0x30, 0x81, 0x8e, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x30,
  1621. 0x81, 0x82, 0x02, 0x01, 0x01, 0x30, 0x2c, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x01, 0x01,
  1622. 0x02, 0x21, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  1623. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff,
  1624. 0xff, 0xfc, 0x2f, 0x30, 0x06, 0x04, 0x01, 0x00, 0x04, 0x01, 0x07, 0x04, 0x21, 0x02, 0x79, 0xbe,
  1625. 0x66, 0x7e, 0xf9, 0xdc, 0xbb, 0xac, 0x55, 0xa0, 0x62, 0x95, 0xce, 0x87, 0x0b, 0x07, 0x02, 0x9b,
  1626. 0xfc, 0xdb, 0x2d, 0xce, 0x28, 0xd9, 0x59, 0xf2, 0x81, 0x5b, 0x16, 0xf8, 0x17, 0x98, 0x02, 0x21,
  1627. 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  1628. 0xfe, 0xba, 0xae, 0xdc, 0xe6, 0xaf, 0x48, 0xa0, 0x3b, 0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36, 0x41,
  1629. 0x41, 0x02, 0x01, 0x01, 0x03, 0x22, 0x00, 0x03, 0x2a, 0xf9, 0x0b, 0xda, 0xbe, 0x71, 0x66, 0x9e,
  1630. 0xd1, 0xcf, 0x12, 0xd0, 0x24, 0xaf, 0xba, 0xb6, 0x7f, 0xfb, 0x96, 0x27, 0x3e, 0x2f, 0xbd, 0x1e,
  1631. 0xd5, 0xf9, 0x8d, 0x6c, 0x73, 0x9d, 0xc5, 0x16
  1632. };
  1633. static const unsigned char short_pri[] = { /* private + long public, curve by OID */
  1634. 0x30, 0x74, 0x02, 0x01, 0x01, 0x04, 0x20, 0x0c, 0xf1, 0xad, 0x2f, 0x03, 0xf7, 0x91, 0x1b, 0xba,
  1635. 0x03, 0xcf, 0x23, 0x37, 0xc8, 0xf2, 0xf7, 0x36, 0xce, 0x65, 0xf1, 0x84, 0x2d, 0x7d, 0x9f, 0x5f,
  1636. 0x9e, 0x21, 0xd9, 0x5e, 0x49, 0xbd, 0x23, 0xa0, 0x07, 0x06, 0x05, 0x2b, 0x81, 0x04, 0x00, 0x0a,
  1637. 0xa1, 0x44, 0x03, 0x42, 0x00, 0x04, 0x2a, 0xf9, 0x0b, 0xda, 0xbe, 0x71, 0x66, 0x9e, 0xd1, 0xcf,
  1638. 0x12, 0xd0, 0x24, 0xaf, 0xba, 0xb6, 0x7f, 0xfb, 0x96, 0x27, 0x3e, 0x2f, 0xbd, 0x1e, 0xd5, 0xf9,
  1639. 0x8d, 0x6c, 0x73, 0x9d, 0xc5, 0x16, 0x91, 0xbd, 0xb2, 0xb9, 0x1b, 0x40, 0x10, 0x5a, 0xb7, 0x6c,
  1640. 0x6e, 0x32, 0x5b, 0xf7, 0x63, 0x62, 0x94, 0x24, 0x24, 0xdb, 0xec, 0x3f, 0x8b, 0xe5, 0x6e, 0x4b,
  1641. 0x64, 0x37, 0x31, 0x24, 0x79, 0x4d
  1642. };
  1643. static const unsigned char short_pri_pkcs8[] = { /* private + long public, curve by OID, PKCS8 */
  1644. 0x30, 0x81, 0x84, 0x02, 0x01, 0x00, 0x30, 0x10, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02,
  1645. 0x01, 0x06, 0x05, 0x2b, 0x81, 0x04, 0x00, 0x0a, 0x04, 0x6d, 0x30, 0x6b, 0x02, 0x01, 0x01, 0x04,
  1646. 0x20, 0x0c, 0xf1, 0xad, 0x2f, 0x03, 0xf7, 0x91, 0x1b, 0xba, 0x03, 0xcf, 0x23, 0x37, 0xc8, 0xf2,
  1647. 0xf7, 0x36, 0xce, 0x65, 0xf1, 0x84, 0x2d, 0x7d, 0x9f, 0x5f, 0x9e, 0x21, 0xd9, 0x5e, 0x49, 0xbd,
  1648. 0x23, 0xa1, 0x44, 0x03, 0x42, 0x00, 0x04, 0x2a, 0xf9, 0x0b, 0xda, 0xbe, 0x71, 0x66, 0x9e, 0xd1,
  1649. 0xcf, 0x12, 0xd0, 0x24, 0xaf, 0xba, 0xb6, 0x7f, 0xfb, 0x96, 0x27, 0x3e, 0x2f, 0xbd, 0x1e, 0xd5,
  1650. 0xf9, 0x8d, 0x6c, 0x73, 0x9d, 0xc5, 0x16, 0x91, 0xbd, 0xb2, 0xb9, 0x1b, 0x40, 0x10, 0x5a, 0xb7,
  1651. 0x6c, 0x6e, 0x32, 0x5b, 0xf7, 0x63, 0x62, 0x94, 0x24, 0x24, 0xdb, 0xec, 0x3f, 0x8b, 0xe5, 0x6e,
  1652. 0x4b, 0x64, 0x37, 0x31, 0x24, 0x79, 0x4d
  1653. };
  1654. static const unsigned char short_pric[] = { /* private + compressed public, curve by OID */
  1655. 0x30, 0x54, 0x02, 0x01, 0x01, 0x04, 0x20, 0x0c, 0xf1, 0xad, 0x2f, 0x03, 0xf7, 0x91, 0x1b, 0xba,
  1656. 0x03, 0xcf, 0x23, 0x37, 0xc8, 0xf2, 0xf7, 0x36, 0xce, 0x65, 0xf1, 0x84, 0x2d, 0x7d, 0x9f, 0x5f,
  1657. 0x9e, 0x21, 0xd9, 0x5e, 0x49, 0xbd, 0x23, 0xa0, 0x07, 0x06, 0x05, 0x2b, 0x81, 0x04, 0x00, 0x0a,
  1658. 0xa1, 0x24, 0x03, 0x22, 0x00, 0x03, 0x2a, 0xf9, 0x0b, 0xda, 0xbe, 0x71, 0x66, 0x9e, 0xd1, 0xcf,
  1659. 0x12, 0xd0, 0x24, 0xaf, 0xba, 0xb6, 0x7f, 0xfb, 0x96, 0x27, 0x3e, 0x2f, 0xbd, 0x1e, 0xd5, 0xf9,
  1660. 0x8d, 0x6c, 0x73, 0x9d, 0xc5, 0x16
  1661. };
  1662. static const unsigned char short_pric_pkcs8[] = { /* private + compressed public, curve by OID, PKCS8 */
  1663. 0x30, 0x64, 0x02, 0x01, 0x00, 0x30, 0x10, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01,
  1664. 0x06, 0x05, 0x2b, 0x81, 0x04, 0x00, 0x0a, 0x04, 0x4d, 0x30, 0x4b, 0x02, 0x01, 0x01, 0x04, 0x20,
  1665. 0x0c, 0xf1, 0xad, 0x2f, 0x03, 0xf7, 0x91, 0x1b, 0xba, 0x03, 0xcf, 0x23, 0x37, 0xc8, 0xf2, 0xf7,
  1666. 0x36, 0xce, 0x65, 0xf1, 0x84, 0x2d, 0x7d, 0x9f, 0x5f, 0x9e, 0x21, 0xd9, 0x5e, 0x49, 0xbd, 0x23,
  1667. 0xa1, 0x24, 0x03, 0x22, 0x00, 0x03, 0x2a, 0xf9, 0x0b, 0xda, 0xbe, 0x71, 0x66, 0x9e, 0xd1, 0xcf,
  1668. 0x12, 0xd0, 0x24, 0xaf, 0xba, 0xb6, 0x7f, 0xfb, 0x96, 0x27, 0x3e, 0x2f, 0xbd, 0x1e, 0xd5, 0xf9,
  1669. 0x8d, 0x6c, 0x73, 0x9d, 0xc5, 0x16
  1670. };
  1671. static const unsigned char short_pub[] = { /* long public, curve by OID */
  1672. 0x30, 0x56, 0x30, 0x10, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x05, 0x2b,
  1673. 0x81, 0x04, 0x00, 0x0a, 0x03, 0x42, 0x00, 0x04, 0x2a, 0xf9, 0x0b, 0xda, 0xbe, 0x71, 0x66, 0x9e,
  1674. 0xd1, 0xcf, 0x12, 0xd0, 0x24, 0xaf, 0xba, 0xb6, 0x7f, 0xfb, 0x96, 0x27, 0x3e, 0x2f, 0xbd, 0x1e,
  1675. 0xd5, 0xf9, 0x8d, 0x6c, 0x73, 0x9d, 0xc5, 0x16, 0x91, 0xbd, 0xb2, 0xb9, 0x1b, 0x40, 0x10, 0x5a,
  1676. 0xb7, 0x6c, 0x6e, 0x32, 0x5b, 0xf7, 0x63, 0x62, 0x94, 0x24, 0x24, 0xdb, 0xec, 0x3f, 0x8b, 0xe5,
  1677. 0x6e, 0x4b, 0x64, 0x37, 0x31, 0x24, 0x79, 0x4d
  1678. };
  1679. static const unsigned char short_pubc[] = { /* compressed public, curve by OID */
  1680. 0x30, 0x36, 0x30, 0x10, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x05, 0x2b,
  1681. 0x81, 0x04, 0x00, 0x0a, 0x03, 0x22, 0x00, 0x03, 0x2a, 0xf9, 0x0b, 0xda, 0xbe, 0x71, 0x66, 0x9e,
  1682. 0xd1, 0xcf, 0x12, 0xd0, 0x24, 0xaf, 0xba, 0xb6, 0x7f, 0xfb, 0x96, 0x27, 0x3e, 0x2f, 0xbd, 0x1e,
  1683. 0xd5, 0xf9, 0x8d, 0x6c, 0x73, 0x9d, 0xc5, 0x16
  1684. };
  1685. static const unsigned char raw_pri[] = { /* raw private key */
  1686. 0x0c, 0xf1, 0xad, 0x2f, 0x03, 0xf7, 0x91, 0x1b, 0xba, 0x03, 0xcf, 0x23, 0x37, 0xc8, 0xf2, 0xf7,
  1687. 0x36, 0xce, 0x65, 0xf1, 0x84, 0x2d, 0x7d, 0x9f, 0x5f, 0x9e, 0x21, 0xd9, 0x5e, 0x49, 0xbd, 0x23
  1688. };
  1689. static const unsigned char raw_pub[] = { /* raw public key - long form */
  1690. 0x04, 0x2a, 0xf9, 0x0b, 0xda, 0xbe, 0x71, 0x66, 0x9e, 0xd1, 0xcf, 0x12, 0xd0, 0x24, 0xaf, 0xba,
  1691. 0xb6, 0x7f, 0xfb, 0x96, 0x27, 0x3e, 0x2f, 0xbd, 0x1e, 0xd5, 0xf9, 0x8d, 0x6c, 0x73, 0x9d, 0xc5,
  1692. 0x16, 0x91, 0xbd, 0xb2, 0xb9, 0x1b, 0x40, 0x10, 0x5a, 0xb7, 0x6c, 0x6e, 0x32, 0x5b, 0xf7, 0x63,
  1693. 0x62, 0x94, 0x24, 0x24, 0xdb, 0xec, 0x3f, 0x8b, 0xe5, 0x6e, 0x4b, 0x64, 0x37, 0x31, 0x24, 0x79,
  1694. 0x4d
  1695. };
  1696. static const unsigned char raw_pubc[] = { /* raw public key - compressed form */
  1697. 0x03, 0x2a, 0xf9, 0x0b, 0xda, 0xbe, 0x71, 0x66, 0x9e, 0xd1, 0xcf, 0x12, 0xd0, 0x24, 0xaf, 0xba,
  1698. 0xb6, 0x7f, 0xfb, 0x96, 0x27, 0x3e, 0x2f, 0xbd, 0x1e, 0xd5, 0xf9, 0x8d, 0x6c, 0x73, 0x9d, 0xc5,
  1699. 0x16
  1700. };
  1701. static const unsigned char x509_cert_long[] = { /* X.509 cert, long pubkey, explicit curve params */
  1702. 0x30, 0x82, 0x02, 0x13, 0x30, 0x82, 0x01, 0xba, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x09, 0x00,
  1703. 0xaf, 0x14, 0xe3, 0x53, 0x36, 0x06, 0x79, 0x34, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce,
  1704. 0x3d, 0x04, 0x03, 0x04, 0x30, 0x17, 0x31, 0x15, 0x30, 0x13, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c,
  1705. 0x0c, 0x54, 0x65, 0x73, 0x74, 0x20, 0x43, 0x65, 0x72, 0x74, 0x20, 0x45, 0x43, 0x30, 0x20, 0x17,
  1706. 0x0d, 0x31, 0x37, 0x31, 0x32, 0x33, 0x30, 0x32, 0x30, 0x33, 0x33, 0x34, 0x31, 0x5a, 0x18, 0x0f,
  1707. 0x33, 0x30, 0x31, 0x37, 0x30, 0x35, 0x30, 0x32, 0x32, 0x30, 0x33, 0x33, 0x34, 0x31, 0x5a, 0x30,
  1708. 0x17, 0x31, 0x15, 0x30, 0x13, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0c, 0x54, 0x65, 0x73, 0x74,
  1709. 0x20, 0x43, 0x65, 0x72, 0x74, 0x20, 0x45, 0x43, 0x30, 0x81, 0xf5, 0x30, 0x81, 0xae, 0x06, 0x07,
  1710. 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x30, 0x81, 0xa2, 0x02, 0x01, 0x01, 0x30, 0x2c, 0x06,
  1711. 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x01, 0x01, 0x02, 0x21, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff,
  1712. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  1713. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xfc, 0x2f, 0x30, 0x06, 0x04, 0x01, 0x00,
  1714. 0x04, 0x01, 0x07, 0x04, 0x41, 0x04, 0x79, 0xbe, 0x66, 0x7e, 0xf9, 0xdc, 0xbb, 0xac, 0x55, 0xa0,
  1715. 0x62, 0x95, 0xce, 0x87, 0x0b, 0x07, 0x02, 0x9b, 0xfc, 0xdb, 0x2d, 0xce, 0x28, 0xd9, 0x59, 0xf2,
  1716. 0x81, 0x5b, 0x16, 0xf8, 0x17, 0x98, 0x48, 0x3a, 0xda, 0x77, 0x26, 0xa3, 0xc4, 0x65, 0x5d, 0xa4,
  1717. 0xfb, 0xfc, 0x0e, 0x11, 0x08, 0xa8, 0xfd, 0x17, 0xb4, 0x48, 0xa6, 0x85, 0x54, 0x19, 0x9c, 0x47,
  1718. 0xd0, 0x8f, 0xfb, 0x10, 0xd4, 0xb8, 0x02, 0x21, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  1719. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xba, 0xae, 0xdc, 0xe6, 0xaf, 0x48, 0xa0,
  1720. 0x3b, 0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36, 0x41, 0x41, 0x02, 0x01, 0x01, 0x03, 0x42, 0x00, 0x04,
  1721. 0x2a, 0xf9, 0x0b, 0xda, 0xbe, 0x71, 0x66, 0x9e, 0xd1, 0xcf, 0x12, 0xd0, 0x24, 0xaf, 0xba, 0xb6,
  1722. 0x7f, 0xfb, 0x96, 0x27, 0x3e, 0x2f, 0xbd, 0x1e, 0xd5, 0xf9, 0x8d, 0x6c, 0x73, 0x9d, 0xc5, 0x16,
  1723. 0x91, 0xbd, 0xb2, 0xb9, 0x1b, 0x40, 0x10, 0x5a, 0xb7, 0x6c, 0x6e, 0x32, 0x5b, 0xf7, 0x63, 0x62,
  1724. 0x94, 0x24, 0x24, 0xdb, 0xec, 0x3f, 0x8b, 0xe5, 0x6e, 0x4b, 0x64, 0x37, 0x31, 0x24, 0x79, 0x4d,
  1725. 0xa3, 0x50, 0x30, 0x4e, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x66,
  1726. 0xc9, 0x90, 0x3c, 0x8a, 0x81, 0xa3, 0x1c, 0x20, 0x61, 0xd2, 0xf3, 0xf5, 0xae, 0xa8, 0x85, 0x70,
  1727. 0xf9, 0x1f, 0x2c, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14,
  1728. 0x66, 0xc9, 0x90, 0x3c, 0x8a, 0x81, 0xa3, 0x1c, 0x20, 0x61, 0xd2, 0xf3, 0xf5, 0xae, 0xa8, 0x85,
  1729. 0x70, 0xf9, 0x1f, 0x2c, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x05, 0x30, 0x03, 0x01,
  1730. 0x01, 0xff, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x04, 0x03, 0x47,
  1731. 0x00, 0x30, 0x44, 0x02, 0x1f, 0x2a, 0x62, 0x64, 0x05, 0x67, 0xb0, 0x2c, 0xa0, 0xa3, 0xb8, 0x61,
  1732. 0x4e, 0x87, 0x06, 0x69, 0xf2, 0xda, 0x78, 0xd6, 0x0e, 0x8d, 0x9b, 0xf1, 0x43, 0x5f, 0xf6, 0x40,
  1733. 0x9d, 0x9d, 0xbd, 0xce, 0x02, 0x21, 0x00, 0xe9, 0x6f, 0x79, 0xb4, 0x4a, 0x00, 0xf7, 0xfa, 0x81,
  1734. 0x25, 0x29, 0xec, 0x79, 0xb2, 0xfa, 0x86, 0xf8, 0x84, 0xd1, 0x78, 0xe7, 0xf8, 0xfd, 0x76, 0x2d,
  1735. 0x4f, 0xfe, 0x02, 0x72, 0xba, 0x6c, 0xca
  1736. };
  1737. static const unsigned char x509_cert_longc[] = { /* X.509 cert, compressed pubkey, explicit curve params */
  1738. 0x30, 0x82, 0x01, 0xd3, 0x30, 0x82, 0x01, 0x7a, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x09, 0x00,
  1739. 0x90, 0x5b, 0x48, 0x32, 0x37, 0x4b, 0x72, 0x54, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce,
  1740. 0x3d, 0x04, 0x03, 0x04, 0x30, 0x17, 0x31, 0x15, 0x30, 0x13, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c,
  1741. 0x0c, 0x54, 0x65, 0x73, 0x74, 0x20, 0x43, 0x65, 0x72, 0x74, 0x20, 0x45, 0x43, 0x30, 0x20, 0x17,
  1742. 0x0d, 0x31, 0x37, 0x31, 0x32, 0x33, 0x30, 0x32, 0x30, 0x33, 0x33, 0x34, 0x31, 0x5a, 0x18, 0x0f,
  1743. 0x33, 0x30, 0x31, 0x37, 0x30, 0x35, 0x30, 0x32, 0x32, 0x30, 0x33, 0x33, 0x34, 0x31, 0x5a, 0x30,
  1744. 0x17, 0x31, 0x15, 0x30, 0x13, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0c, 0x54, 0x65, 0x73, 0x74,
  1745. 0x20, 0x43, 0x65, 0x72, 0x74, 0x20, 0x45, 0x43, 0x30, 0x81, 0xb5, 0x30, 0x81, 0x8e, 0x06, 0x07,
  1746. 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x30, 0x81, 0x82, 0x02, 0x01, 0x01, 0x30, 0x2c, 0x06,
  1747. 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x01, 0x01, 0x02, 0x21, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff,
  1748. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  1749. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xfc, 0x2f, 0x30, 0x06, 0x04, 0x01, 0x00,
  1750. 0x04, 0x01, 0x07, 0x04, 0x21, 0x02, 0x79, 0xbe, 0x66, 0x7e, 0xf9, 0xdc, 0xbb, 0xac, 0x55, 0xa0,
  1751. 0x62, 0x95, 0xce, 0x87, 0x0b, 0x07, 0x02, 0x9b, 0xfc, 0xdb, 0x2d, 0xce, 0x28, 0xd9, 0x59, 0xf2,
  1752. 0x81, 0x5b, 0x16, 0xf8, 0x17, 0x98, 0x02, 0x21, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  1753. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xba, 0xae, 0xdc, 0xe6, 0xaf, 0x48, 0xa0,
  1754. 0x3b, 0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36, 0x41, 0x41, 0x02, 0x01, 0x01, 0x03, 0x22, 0x00, 0x03,
  1755. 0x2a, 0xf9, 0x0b, 0xda, 0xbe, 0x71, 0x66, 0x9e, 0xd1, 0xcf, 0x12, 0xd0, 0x24, 0xaf, 0xba, 0xb6,
  1756. 0x7f, 0xfb, 0x96, 0x27, 0x3e, 0x2f, 0xbd, 0x1e, 0xd5, 0xf9, 0x8d, 0x6c, 0x73, 0x9d, 0xc5, 0x16,
  1757. 0xa3, 0x50, 0x30, 0x4e, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0xca,
  1758. 0x2a, 0xa1, 0x12, 0x97, 0x96, 0x2c, 0x85, 0xd3, 0x1f, 0xb1, 0x34, 0x7c, 0x26, 0xe9, 0xd6, 0x49,
  1759. 0x9f, 0x98, 0xcf, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14,
  1760. 0xca, 0x2a, 0xa1, 0x12, 0x97, 0x96, 0x2c, 0x85, 0xd3, 0x1f, 0xb1, 0x34, 0x7c, 0x26, 0xe9, 0xd6,
  1761. 0x49, 0x9f, 0x98, 0xcf, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x05, 0x30, 0x03, 0x01,
  1762. 0x01, 0xff, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x04, 0x03, 0x47,
  1763. 0x00, 0x30, 0x44, 0x02, 0x20, 0x24, 0x7a, 0xc1, 0xb4, 0x7d, 0x1c, 0x3c, 0x23, 0xc6, 0xad, 0xea,
  1764. 0x04, 0x27, 0x27, 0x65, 0xb8, 0x72, 0x93, 0x46, 0xc9, 0xe9, 0x60, 0x8f, 0xca, 0x96, 0x30, 0x60,
  1765. 0xb3, 0x22, 0xf7, 0x3b, 0x01, 0x02, 0x20, 0x48, 0x30, 0x2a, 0x58, 0x18, 0x46, 0xdb, 0x50, 0x3e,
  1766. 0xad, 0xc3, 0xca, 0xcd, 0x6d, 0x83, 0xd4, 0xc3, 0xc4, 0xa4, 0x8f, 0x37, 0xc3, 0x1d, 0x83, 0x3c,
  1767. 0xd3, 0x1f, 0x8f, 0x38, 0x29, 0x75, 0x2c
  1768. };
  1769. static const unsigned char x509_cert_short[] = { /* X.509 cert, long pubkey, curve by OID */
  1770. 0x30, 0x82, 0x01, 0x74, 0x30, 0x82, 0x01, 0x1a, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x09, 0x00,
  1771. 0xbd, 0x81, 0x04, 0x29, 0x43, 0x12, 0x79, 0xce, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce,
  1772. 0x3d, 0x04, 0x03, 0x04, 0x30, 0x17, 0x31, 0x15, 0x30, 0x13, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c,
  1773. 0x0c, 0x54, 0x65, 0x73, 0x74, 0x20, 0x43, 0x65, 0x72, 0x74, 0x20, 0x45, 0x43, 0x30, 0x20, 0x17,
  1774. 0x0d, 0x31, 0x37, 0x31, 0x32, 0x33, 0x30, 0x32, 0x30, 0x33, 0x33, 0x34, 0x31, 0x5a, 0x18, 0x0f,
  1775. 0x33, 0x30, 0x31, 0x37, 0x30, 0x35, 0x30, 0x32, 0x32, 0x30, 0x33, 0x33, 0x34, 0x31, 0x5a, 0x30,
  1776. 0x17, 0x31, 0x15, 0x30, 0x13, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0c, 0x54, 0x65, 0x73, 0x74,
  1777. 0x20, 0x43, 0x65, 0x72, 0x74, 0x20, 0x45, 0x43, 0x30, 0x56, 0x30, 0x10, 0x06, 0x07, 0x2a, 0x86,
  1778. 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x05, 0x2b, 0x81, 0x04, 0x00, 0x0a, 0x03, 0x42, 0x00, 0x04,
  1779. 0x2a, 0xf9, 0x0b, 0xda, 0xbe, 0x71, 0x66, 0x9e, 0xd1, 0xcf, 0x12, 0xd0, 0x24, 0xaf, 0xba, 0xb6,
  1780. 0x7f, 0xfb, 0x96, 0x27, 0x3e, 0x2f, 0xbd, 0x1e, 0xd5, 0xf9, 0x8d, 0x6c, 0x73, 0x9d, 0xc5, 0x16,
  1781. 0x91, 0xbd, 0xb2, 0xb9, 0x1b, 0x40, 0x10, 0x5a, 0xb7, 0x6c, 0x6e, 0x32, 0x5b, 0xf7, 0x63, 0x62,
  1782. 0x94, 0x24, 0x24, 0xdb, 0xec, 0x3f, 0x8b, 0xe5, 0x6e, 0x4b, 0x64, 0x37, 0x31, 0x24, 0x79, 0x4d,
  1783. 0xa3, 0x50, 0x30, 0x4e, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x66,
  1784. 0xc9, 0x90, 0x3c, 0x8a, 0x81, 0xa3, 0x1c, 0x20, 0x61, 0xd2, 0xf3, 0xf5, 0xae, 0xa8, 0x85, 0x70,
  1785. 0xf9, 0x1f, 0x2c, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14,
  1786. 0x66, 0xc9, 0x90, 0x3c, 0x8a, 0x81, 0xa3, 0x1c, 0x20, 0x61, 0xd2, 0xf3, 0xf5, 0xae, 0xa8, 0x85,
  1787. 0x70, 0xf9, 0x1f, 0x2c, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x05, 0x30, 0x03, 0x01,
  1788. 0x01, 0xff, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x04, 0x03, 0x48,
  1789. 0x00, 0x30, 0x45, 0x02, 0x21, 0x00, 0x9b, 0x4e, 0xb2, 0x6a, 0xcc, 0xfa, 0x02, 0x69, 0x22, 0x6a,
  1790. 0x32, 0x9c, 0x0c, 0xaa, 0x4c, 0xdf, 0xbb, 0x9b, 0x22, 0xfb, 0xd6, 0xec, 0x5d, 0xf9, 0x87, 0x82,
  1791. 0xeb, 0x37, 0xb8, 0x32, 0x7c, 0xd6, 0x02, 0x20, 0x50, 0x8b, 0x9f, 0xc1, 0xa8, 0x4a, 0xff, 0x49,
  1792. 0x0d, 0x7e, 0x04, 0x2d, 0x93, 0x3e, 0xdb, 0x30, 0xbc, 0x93, 0xd1, 0x16, 0x1d, 0x99, 0xbd, 0x3f,
  1793. 0xfa, 0x2a, 0x6d, 0xe0, 0x2a, 0x83, 0x55, 0x5d
  1794. };
  1795. static const unsigned char x509_cert_shortc[] = { /* X.509 cert, compressed pubkey, curve by OID */
  1796. 0x30, 0x82, 0x01, 0x54, 0x30, 0x81, 0xfa, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x09, 0x00, 0x85,
  1797. 0x45, 0x77, 0x75, 0x02, 0x95, 0xf7, 0x06, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d,
  1798. 0x04, 0x03, 0x04, 0x30, 0x17, 0x31, 0x15, 0x30, 0x13, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0c,
  1799. 0x54, 0x65, 0x73, 0x74, 0x20, 0x43, 0x65, 0x72, 0x74, 0x20, 0x45, 0x43, 0x30, 0x20, 0x17, 0x0d,
  1800. 0x31, 0x37, 0x31, 0x32, 0x33, 0x30, 0x32, 0x30, 0x33, 0x33, 0x34, 0x31, 0x5a, 0x18, 0x0f, 0x33,
  1801. 0x30, 0x31, 0x37, 0x30, 0x35, 0x30, 0x32, 0x32, 0x30, 0x33, 0x33, 0x34, 0x31, 0x5a, 0x30, 0x17,
  1802. 0x31, 0x15, 0x30, 0x13, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0c, 0x54, 0x65, 0x73, 0x74, 0x20,
  1803. 0x43, 0x65, 0x72, 0x74, 0x20, 0x45, 0x43, 0x30, 0x36, 0x30, 0x10, 0x06, 0x07, 0x2a, 0x86, 0x48,
  1804. 0xce, 0x3d, 0x02, 0x01, 0x06, 0x05, 0x2b, 0x81, 0x04, 0x00, 0x0a, 0x03, 0x22, 0x00, 0x03, 0x2a,
  1805. 0xf9, 0x0b, 0xda, 0xbe, 0x71, 0x66, 0x9e, 0xd1, 0xcf, 0x12, 0xd0, 0x24, 0xaf, 0xba, 0xb6, 0x7f,
  1806. 0xfb, 0x96, 0x27, 0x3e, 0x2f, 0xbd, 0x1e, 0xd5, 0xf9, 0x8d, 0x6c, 0x73, 0x9d, 0xc5, 0x16, 0xa3,
  1807. 0x50, 0x30, 0x4e, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0xca, 0x2a,
  1808. 0xa1, 0x12, 0x97, 0x96, 0x2c, 0x85, 0xd3, 0x1f, 0xb1, 0x34, 0x7c, 0x26, 0xe9, 0xd6, 0x49, 0x9f,
  1809. 0x98, 0xcf, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0xca,
  1810. 0x2a, 0xa1, 0x12, 0x97, 0x96, 0x2c, 0x85, 0xd3, 0x1f, 0xb1, 0x34, 0x7c, 0x26, 0xe9, 0xd6, 0x49,
  1811. 0x9f, 0x98, 0xcf, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x05, 0x30, 0x03, 0x01, 0x01,
  1812. 0xff, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x04, 0x03, 0x49, 0x00,
  1813. 0x30, 0x46, 0x02, 0x21, 0x00, 0xa4, 0xf9, 0x41, 0x2b, 0x4b, 0x56, 0xa5, 0xd4, 0x8c, 0xdf, 0xb0,
  1814. 0x14, 0xe3, 0xe7, 0xed, 0xcc, 0xc4, 0x46, 0x42, 0x04, 0xec, 0x15, 0x9f, 0xe1, 0xb2, 0x00, 0x07,
  1815. 0x8c, 0xc1, 0xf9, 0x25, 0xed, 0x02, 0x21, 0x00, 0x81, 0xd8, 0xc4, 0x3a, 0x9f, 0xdf, 0xc1, 0x70,
  1816. 0x9d, 0x7b, 0x70, 0x3e, 0xf5, 0x7d, 0xa4, 0xfd, 0x3c, 0xc6, 0x49, 0x93, 0xd3, 0x5b, 0xef, 0xc9,
  1817. 0xae, 0x97, 0xaf, 0x64, 0x64, 0xf9, 0x69, 0xd8
  1818. };
  1819. password_ctx pw_ctx = { .callback = password_get };
  1820. if (ltc_mp.sqrtmod_prime == NULL) return CRYPT_NOP; /* we need compressed points which requires sqrtmod_prime */
  1821. DO(ecc_import_openssl(short_pub, sizeof(short_pub), &pub));
  1822. DO(ecc_import_openssl(short_pri, sizeof(short_pri), &pri));
  1823. DO(ecc_find_curve("SECP256K1", &cu));
  1824. /* import - raw keys */
  1825. DO(ecc_set_curve(cu, &key));
  1826. DO(ecc_set_key(raw_pri, sizeof(raw_pri), PK_PRIVATE, &key));
  1827. DO(ecc_key_cmp(PK_PRIVATE, &pri, &key));
  1828. ecc_free(&key);
  1829. DO(ecc_set_curve(cu, &key));
  1830. DO(ecc_set_key(raw_pub, sizeof(raw_pub), PK_PUBLIC, &key));
  1831. DO(ecc_key_cmp(PK_PUBLIC, &pub, &key));
  1832. ecc_free(&key);
  1833. DO(ecc_set_curve(cu, &key));
  1834. DO(ecc_set_key(raw_pubc, sizeof(raw_pubc), PK_PUBLIC, &key));
  1835. DO(ecc_key_cmp(PK_PUBLIC, &pub, &key));
  1836. ecc_free(&key);
  1837. /* import - openssl compatible DER format */
  1838. DO(ecc_import_openssl(ltc_ecc_long_pri_test_key, sizeof(ltc_ecc_long_pri_test_key), &key));
  1839. DO(ecc_key_cmp(PK_PRIVATE, &pri, &key));
  1840. ecc_free(&key);
  1841. DO(ecc_import_openssl(long_pric, sizeof(long_pric), &key));
  1842. DO(ecc_key_cmp(PK_PRIVATE, &pri, &key));
  1843. ecc_free(&key);
  1844. DO(ecc_import_openssl(long_pub, sizeof(long_pub), &key));
  1845. DO(ecc_key_cmp(PK_PUBLIC, &pub, &key));
  1846. ecc_free(&key);
  1847. DO(ecc_import_openssl(long_pubc, sizeof(long_pubc), &key));
  1848. DO(ecc_key_cmp(PK_PUBLIC, &pub, &key));
  1849. ecc_free(&key);
  1850. DO(ecc_import_openssl(short_pri, sizeof(short_pri), &key));
  1851. DO(ecc_key_cmp(PK_PRIVATE, &pri, &key));
  1852. ecc_free(&key);
  1853. DO(ecc_import_openssl(short_pric, sizeof(short_pric), &key));
  1854. DO(ecc_key_cmp(PK_PRIVATE, &pri, &key));
  1855. ecc_free(&key);
  1856. DO(ecc_import_openssl(short_pub, sizeof(short_pub), &key));
  1857. DO(ecc_key_cmp(PK_PUBLIC, &pub, &key));
  1858. ecc_free(&key);
  1859. DO(ecc_import_openssl(short_pubc, sizeof(short_pubc), &key));
  1860. DO(ecc_key_cmp(PK_PUBLIC, &pub, &key));
  1861. ecc_free(&key);
  1862. /* import - private PKCS8 format - no password */
  1863. DO(ecc_import_pkcs8(long_pri_pkcs8, sizeof(long_pri_pkcs8), NULL, &key));
  1864. DO(ecc_key_cmp(PK_PRIVATE, &pri, &key));
  1865. ecc_free(&key);
  1866. DO(ecc_import_pkcs8(long_pric_pkcs8, sizeof(long_pric_pkcs8), NULL, &key));
  1867. DO(ecc_key_cmp(PK_PRIVATE, &pri, &key));
  1868. ecc_free(&key);
  1869. DO(ecc_import_pkcs8(short_pri_pkcs8, sizeof(short_pri_pkcs8), NULL, &key));
  1870. DO(ecc_key_cmp(PK_PRIVATE, &pri, &key));
  1871. ecc_free(&key);
  1872. DO(ecc_import_pkcs8(short_pric_pkcs8, sizeof(short_pric_pkcs8), NULL, &key));
  1873. DO(ecc_key_cmp(PK_PRIVATE, &pri, &key));
  1874. ecc_free(&key);
  1875. /* import - private PKCS8 format - password protected (PBES1 algorithms) */
  1876. #ifdef LTC_MD2
  1877. DO(ecc_import_pkcs8(long_pri_pkcs8_pbe_md2_des, sizeof(long_pri_pkcs8_pbe_md2_des), &pw_ctx, &key));
  1878. DO(ecc_key_cmp(PK_PRIVATE, &pri, &key));
  1879. ecc_free(&key);
  1880. #endif
  1881. #ifdef LTC_MD5
  1882. DO(ecc_import_pkcs8(long_pri_pkcs8_pbe_md5_des, sizeof(long_pri_pkcs8_pbe_md5_des), &pw_ctx, &key));
  1883. DO(ecc_key_cmp(PK_PRIVATE, &pri, &key));
  1884. ecc_free(&key);
  1885. #endif
  1886. #ifdef LTC_SHA1
  1887. DO(ecc_import_pkcs8(long_pri_pkcs8_pbe_sha1_des, sizeof(long_pri_pkcs8_pbe_sha1_des), &pw_ctx, &key));
  1888. DO(ecc_key_cmp(PK_PRIVATE, &pri, &key));
  1889. ecc_free(&key);
  1890. #endif
  1891. #if defined(LTC_RC2) && defined(LTC_MD2)
  1892. DO(ecc_import_pkcs8(long_pri_pkcs8_pbe_md2_rc2_64, sizeof(long_pri_pkcs8_pbe_md2_rc2_64), &pw_ctx, &key));
  1893. DO(ecc_key_cmp(PK_PRIVATE, &pri, &key));
  1894. ecc_free(&key);
  1895. #endif
  1896. #if defined(LTC_RC2) && defined(LTC_MD5)
  1897. DO(ecc_import_pkcs8(long_pri_pkcs8_pbe_md5_rc2_64, sizeof(long_pri_pkcs8_pbe_md5_rc2_64), &pw_ctx, &key));
  1898. DO(ecc_key_cmp(PK_PRIVATE, &pri, &key));
  1899. ecc_free(&key);
  1900. #endif
  1901. #if defined(LTC_RC2) && defined(LTC_SHA1)
  1902. DO(ecc_import_pkcs8(long_pri_pkcs8_pbe_sha1_rc2_64, sizeof(long_pri_pkcs8_pbe_sha1_rc2_64), &pw_ctx, &key));
  1903. DO(ecc_key_cmp(PK_PRIVATE, &pri, &key));
  1904. ecc_free(&key);
  1905. #endif
  1906. /* import - private PKCS8 format - password protected (PBES2 algorithms) */
  1907. #if defined(LTC_RC2)
  1908. DO(ecc_import_pkcs8(long_pri_pkcs8_pbkdf2_rc2_cbc, sizeof(long_pri_pkcs8_pbkdf2_rc2_cbc), &pw_ctx, &key));
  1909. DO(ecc_key_cmp(PK_PRIVATE, &pri, &key));
  1910. ecc_free(&key);
  1911. #endif
  1912. #if defined(LTC_DES)
  1913. DO(ecc_import_pkcs8(long_pri_pkcs8_pbkdf2_des_cbc, sizeof(long_pri_pkcs8_pbkdf2_des_cbc), &pw_ctx, &key));
  1914. DO(ecc_key_cmp(PK_PRIVATE, &pri, &key));
  1915. ecc_free(&key);
  1916. #endif
  1917. #if defined(LTC_DES)
  1918. DO(ecc_import_pkcs8(long_pri_pkcs8_pbkdf2_des_ede3_cbc, sizeof(long_pri_pkcs8_pbkdf2_des_ede3_cbc), &pw_ctx, &key));
  1919. DO(ecc_key_cmp(PK_PRIVATE, &pri, &key));
  1920. ecc_free(&key);
  1921. #endif
  1922. #if defined(LTC_SHA224) && defined(LTC_DES)
  1923. DO(ecc_import_pkcs8(long_pri_pkcs8_pbkdf2_sha224_des_ede3_cbc, sizeof(long_pri_pkcs8_pbkdf2_sha224_des_ede3_cbc), &pw_ctx, &key));
  1924. DO(ecc_key_cmp(PK_PRIVATE, &pri, &key));
  1925. ecc_free(&key);
  1926. #endif
  1927. #if defined(LTC_SHA256) && defined(LTC_DES)
  1928. DO(ecc_import_pkcs8(long_pri_pkcs8_pbkdf2_sha256_des_ede3_cbc, sizeof(long_pri_pkcs8_pbkdf2_sha256_des_ede3_cbc), &pw_ctx, &key));
  1929. DO(ecc_key_cmp(PK_PRIVATE, &pri, &key));
  1930. ecc_free(&key);
  1931. #endif
  1932. #if defined(LTC_SHA384) && defined(LTC_DES)
  1933. DO(ecc_import_pkcs8(long_pri_pkcs8_pbkdf2_sha384_des_ede3_cbc, sizeof(long_pri_pkcs8_pbkdf2_sha384_des_ede3_cbc), &pw_ctx, &key));
  1934. DO(ecc_key_cmp(PK_PRIVATE, &pri, &key));
  1935. ecc_free(&key);
  1936. #endif
  1937. #if defined(LTC_SHA512) && defined(LTC_DES)
  1938. DO(ecc_import_pkcs8(long_pri_pkcs8_pbkdf2_sha512_des_ede3_cbc, sizeof(long_pri_pkcs8_pbkdf2_sha512_des_ede3_cbc), &pw_ctx, &key));
  1939. DO(ecc_key_cmp(PK_PRIVATE, &pri, &key));
  1940. ecc_free(&key);
  1941. #endif
  1942. /* import - X.509 EC certificates */
  1943. DO(ecc_import_x509(x509_cert_long, sizeof(x509_cert_long), &key));
  1944. DO(ecc_key_cmp(PK_PUBLIC, &pub, &key));
  1945. ecc_free(&key);
  1946. DO(ecc_import_x509(x509_cert_longc, sizeof(x509_cert_longc), &key));
  1947. DO(ecc_key_cmp(PK_PUBLIC, &pub, &key));
  1948. ecc_free(&key);
  1949. DO(ecc_import_x509(x509_cert_short, sizeof(x509_cert_short), &key));
  1950. DO(ecc_key_cmp(PK_PUBLIC, &pub, &key));
  1951. ecc_free(&key);
  1952. DO(ecc_import_x509(x509_cert_shortc, sizeof(x509_cert_shortc), &key));
  1953. DO(ecc_key_cmp(PK_PUBLIC, &pub, &key));
  1954. ecc_free(&key);
  1955. /* export - openssl compatible DER format */
  1956. outlen = sizeof(out);
  1957. DO(ecc_export_openssl(out, &outlen, PK_PRIVATE, &pri));
  1958. COMPARE_TESTVECTOR(out, outlen, ltc_ecc_long_pri_test_key, sizeof(ltc_ecc_long_pri_test_key), "e-ltc_ecc_long_pri_test_key", 0);
  1959. outlen = sizeof(out);
  1960. DO(ecc_export_openssl(out, &outlen, PK_PRIVATE|PK_COMPRESSED, &pri));
  1961. COMPARE_TESTVECTOR(out, outlen, long_pric, sizeof(long_pric), "e-long_pric", 0);
  1962. outlen = sizeof(out);
  1963. DO(ecc_export_openssl(out, &outlen, PK_PUBLIC, &pub));
  1964. COMPARE_TESTVECTOR(out, outlen, long_pub, sizeof(long_pub), "e-long_pub", 0);
  1965. outlen = sizeof(out);
  1966. DO(ecc_export_openssl(out, &outlen, PK_PUBLIC|PK_COMPRESSED, &pub));
  1967. COMPARE_TESTVECTOR(out, outlen, long_pubc, sizeof(long_pubc), "e-long_pubc", 0);
  1968. outlen = sizeof(out);
  1969. DO(ecc_export_openssl(out, &outlen, PK_PRIVATE|PK_CURVEOID, &pri));
  1970. COMPARE_TESTVECTOR(out, outlen, short_pri, sizeof(short_pri), "e-short_pri", 0);
  1971. outlen = sizeof(out);
  1972. DO(ecc_export_openssl(out, &outlen, PK_PRIVATE|PK_CURVEOID|PK_COMPRESSED, &pri));
  1973. COMPARE_TESTVECTOR(out, outlen, short_pric, sizeof(short_pric), "e-short_pric", 0);
  1974. outlen = sizeof(out);
  1975. DO(ecc_export_openssl(out, &outlen, PK_PUBLIC|PK_CURVEOID, &pub));
  1976. COMPARE_TESTVECTOR(out, outlen, short_pub, sizeof(short_pub), "e-short_pub", 0);
  1977. outlen = sizeof(out);
  1978. DO(ecc_export_openssl(out, &outlen, PK_PUBLIC|PK_CURVEOID|PK_COMPRESSED, &pub));
  1979. COMPARE_TESTVECTOR(out, outlen, short_pubc, sizeof(short_pubc), "e-short_pubc", 0);
  1980. /* export - raw keys */
  1981. outlen = sizeof(out);
  1982. DO(ecc_get_key(out, &outlen, PK_PRIVATE, &pri));
  1983. COMPARE_TESTVECTOR(out, outlen, raw_pri, sizeof(raw_pri), "e-raw_pri", 0);
  1984. outlen = sizeof(out);
  1985. DO(ecc_get_key(out, &outlen, PK_PUBLIC, &pub));
  1986. COMPARE_TESTVECTOR(out, outlen, raw_pub, sizeof(raw_pub), "e-raw_pub", 0);
  1987. outlen = sizeof(out);
  1988. DO(ecc_get_key(out, &outlen, PK_PUBLIC|PK_COMPRESSED, &pub));
  1989. COMPARE_TESTVECTOR(out, outlen, raw_pubc, sizeof(raw_pubc), "e-raw_pubc", 0);
  1990. ecc_free(&pri);
  1991. ecc_free(&pub);
  1992. return CRYPT_OK;
  1993. }
  1994. #ifdef LTC_ECC_SHAMIR
  1995. static int s_ecc_test_ethereum(void)
  1996. {
  1997. #ifdef LTC_ECC_SECP256K1
  1998. int stat;
  1999. const ltc_ecc_curve* dp;
  2000. ecc_key key, reckey;
  2001. unsigned char buf[128];
  2002. unsigned long len;
  2003. unsigned char data16[16] = { 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1 };
  2004. ltc_ecc_sig_opts sig_opts = {
  2005. .type = LTC_ECCSIG_ETH27,
  2006. .prng = &yarrow_prng,
  2007. .wprng = find_prng ("yarrow"),
  2008. };
  2009. DO(ecc_find_curve("SECP256K1", &dp));
  2010. DO(ecc_make_key_ex(&yarrow_prng, find_prng ("yarrow"), &key, dp));
  2011. /* test Ethereum signature */
  2012. len = sizeof(buf);
  2013. DO(ecc_sign_hash_v2(data16, 16, buf, &len, &sig_opts, &key));
  2014. stat = 0;
  2015. DO(ecc_verify_hash_v2(buf, len, data16, 16, &sig_opts, &stat, &key));
  2016. if (stat != 1) return CRYPT_FAIL_TESTVECTOR;
  2017. /* XXX-FIXME: TFM does not support sqrtmod_prime */
  2018. if (strcmp(ltc_mp.name, "TomsFastMath") != 0) {
  2019. DO(ecc_set_curve(dp, &reckey));
  2020. DO(ecc_recover_key(buf, len, data16, 16, &sig_opts, &reckey));
  2021. DO(ecc_key_cmp(PK_PUBLIC, &key, &reckey));
  2022. /* cleanup */
  2023. ecc_free(&reckey);
  2024. }
  2025. /* cleanup */
  2026. ecc_free(&key);
  2027. return CRYPT_OK;
  2028. #else
  2029. return CRYPT_NOP;
  2030. #endif
  2031. }
  2032. static int s_ecc_test_recovery(void)
  2033. {
  2034. int i, recid, stat;
  2035. const ltc_ecc_curve* dp;
  2036. ecc_key key, privkey, pubkey, reckey;
  2037. unsigned char buf[1000];
  2038. unsigned long len;
  2039. unsigned char data16[16] = { 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1 };
  2040. unsigned char eth_hash[] = { /* Keccak-256 hash of "Hello World" */
  2041. 0x59, 0x2f, 0xa7, 0x43, 0x88, 0x9f, 0xc7, 0xf9, 0x2a, 0xc2, 0xa3, 0x7b, 0xb1, 0xf5, 0xba, 0x1d,
  2042. 0xaf, 0x2a, 0x5c, 0x84, 0x74, 0x1c, 0xa0, 0xe0, 0x06, 0x1d, 0x24, 0x3a, 0x2e, 0x67, 0x07, 0xba
  2043. };
  2044. unsigned char eth_pubkey[] = { /* Public part of randomly-generated key pair */
  2045. 0x04,
  2046. 0xc6, 0x99, 0x5f, 0xdc, 0xf4, 0xf2, 0xda, 0x6e, 0x79, 0xe0, 0x47, 0x12, 0xd3, 0xbe, 0x22, 0xe7,
  2047. 0x65, 0xc6, 0xa3, 0x32, 0x89, 0x1b, 0x34, 0xba, 0xc1, 0xb7, 0x01, 0x83, 0xed, 0xdd, 0xf1, 0xcc,
  2048. 0xbf, 0x20, 0xdd, 0xcd, 0x05, 0x4e, 0x49, 0xc8, 0xcb, 0x66, 0x6c, 0xb7, 0x71, 0x2f, 0x7e, 0xc1,
  2049. 0xd6, 0x1a, 0x4a, 0x42, 0x3d, 0xe5, 0xc2, 0x8d, 0x74, 0x03, 0x81, 0xe7, 0xea, 0xc5, 0x3c, 0x10
  2050. };
  2051. unsigned char eth_sig[] = { /* Signature of eth_hash to be verified against eth_pubkey */
  2052. 0xbd, 0x6d, 0xbb, 0xbe, 0x2d, 0xe7, 0x1d, 0x00, 0xae, 0x18, 0x57, 0x12, 0x1d, 0x63, 0xa5, 0x1b,
  2053. 0x0b, 0x42, 0x71, 0xa2, 0x80, 0x49, 0xe0, 0x5c, 0xfa, 0xc8, 0x1a, 0x0d, 0x8a, 0x88, 0x67, 0x56,
  2054. 0xf6, 0x67, 0x1b, 0x41, 0x46, 0x09, 0x4e, 0xd0, 0x44, 0x25, 0x18, 0xfd, 0xf4, 0xcd, 0x62, 0xa3,
  2055. 0xb7, 0x3c, 0x97, 0x55, 0xfa, 0x69, 0xf8, 0xef, 0xe9, 0xcf, 0x12, 0xaf, 0x48, 0x25, 0xe3, 0xe0,
  2056. 0x1b
  2057. };
  2058. ltc_ecc_sig_opts sig_opts = {
  2059. .prng = &yarrow_prng,
  2060. .wprng = find_prng ("yarrow"),
  2061. .recid = &recid
  2062. };
  2063. /* XXX-FIXME: TFM does not support sqrtmod_prime */
  2064. if (strcmp(ltc_mp.name, "TomsFastMath") == 0) return CRYPT_NOP;
  2065. #ifdef LTC_ECC_SECP256K1
  2066. DO(ecc_find_curve("SECP256K1", &dp));
  2067. DO(ecc_set_curve(dp, &pubkey));
  2068. DO(ecc_set_key(eth_pubkey, sizeof(eth_pubkey), PK_PUBLIC, &pubkey));
  2069. DO(ecc_set_curve(dp, &reckey));
  2070. recid = 0;
  2071. sig_opts.type = LTC_ECCSIG_RFC7518;
  2072. DO(ecc_recover_key(eth_sig, sizeof(eth_sig)-1, eth_hash, sizeof(eth_hash), &sig_opts, &reckey));
  2073. DO(ecc_key_cmp(PK_PUBLIC, &pubkey, &reckey));
  2074. ecc_free(&reckey);
  2075. DO(ecc_set_curve(dp, &reckey));
  2076. recid = -1;
  2077. sig_opts.type = LTC_ECCSIG_ETH27;
  2078. DO(ecc_recover_key(eth_sig, sizeof(eth_sig), eth_hash, sizeof(eth_hash), &sig_opts, &reckey));
  2079. DO(ecc_key_cmp(PK_PUBLIC, &pubkey, &reckey));
  2080. ecc_free(&reckey);
  2081. ecc_free(&pubkey);
  2082. #endif
  2083. sig_opts.type = LTC_ECCSIG_RFC7518;
  2084. for (i = 0; i < (int)LTC_ARRAY_SIZE(curvenames); i++) {
  2085. DO(ecc_find_curve(curvenames[i], &dp));
  2086. /* generate new key */
  2087. DO(ecc_set_curve(dp, &key));
  2088. DO(ecc_generate_key(&yarrow_prng, find_prng ("yarrow"), &key));
  2089. /* export private key */
  2090. len = sizeof(buf);
  2091. DO(ecc_get_key(buf, &len, PK_PRIVATE, &key));
  2092. ecc_free(&key);
  2093. /* load exported private key */
  2094. DO(ecc_set_curve(dp, &privkey));
  2095. DO(ecc_set_key(buf, len, PK_PRIVATE, &privkey));
  2096. /* export long public key */
  2097. len = sizeof(buf);
  2098. DO(ecc_get_key(buf, &len, PK_PUBLIC, &privkey));
  2099. if (len != 1 + 2 * (unsigned)ecc_get_size(&privkey)) return CRYPT_FAIL_TESTVECTOR;
  2100. /* load exported public key */
  2101. DO(ecc_set_curve(dp, &pubkey));
  2102. DO(ecc_set_key(buf, len, PK_PUBLIC, &pubkey));
  2103. /* test signature */
  2104. len = sizeof(buf);
  2105. recid = 0;
  2106. DO(ecc_sign_hash_v2(data16, 16, buf, &len, &sig_opts, &privkey));
  2107. /* test verification */
  2108. stat = 0;
  2109. DO(ecc_verify_hash_v2(buf, len, data16, 16, &sig_opts, &stat, &pubkey));
  2110. if (stat != 1) return CRYPT_FAIL_TESTVECTOR;
  2111. /* test recovery */
  2112. DO(ecc_set_curve(dp, &reckey));
  2113. stat = ecc_recover_key(buf, len, data16, 16, &sig_opts, &reckey);
  2114. if (stat != CRYPT_OK) return CRYPT_FAIL_TESTVECTOR;
  2115. DO(ecc_key_cmp(PK_PUBLIC, &pubkey, &reckey));
  2116. /* cleanup */
  2117. ecc_free(&reckey);
  2118. ecc_free(&privkey);
  2119. ecc_free(&pubkey);
  2120. }
  2121. return CRYPT_OK;
  2122. }
  2123. #endif
  2124. int ecc_test(void)
  2125. {
  2126. if (ltc_mp.name == NULL) return CRYPT_NOP;
  2127. DO(s_ecc_issue446());
  2128. DO(s_ecc_rfc6979());
  2129. DO(s_ecc_old_api()); /* up to 1.18 */
  2130. DO(s_ecc_new_api());
  2131. DO(s_ecc_import_export());
  2132. DO(s_ecc_test_mp());
  2133. DO(s_ecc_issue108());
  2134. DO(s_ecc_issue443_447());
  2135. DO(s_ecc_issue630());
  2136. #ifdef LTC_ECC_SHAMIR
  2137. DO(s_ecc_test_shamir());
  2138. DO(s_ecc_test_recovery());
  2139. DO(s_ecc_test_ethereum());
  2140. #endif
  2141. return CRYPT_OK;
  2142. }
  2143. #endif