Advertisement
Guest User

Untitled

a guest
Aug 24th, 2010
766
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.05 KB | None | 0 0
  1. /*
  2. ECDSA-56
  3. Parameters are, according to The Elliptic Curve Digital Signature Algorithm
  4. (D. Johnson and A. Menezes, Univ. of Waterloo, 1999):
  5.  
  6. a = 0x2982
  7. b = 0x3408
  8. p = 0xAEBF94CEE3E707
  9. xG = 0x7A3E808599A525
  10. xQ = 0x9F70A02013BC9B
  11. Q = d * G, d being the private key.
  12. n = 0xAEBF94D5C6AA71 not prime.
  13. n = 0x11 * 0x35 * 0xDD0F5 * 0x397FAE9
  14.  
  15. Discrete logarithm can be computed fastly using Pohlig-Hellman:
  16. d = 0x9D3F1E3CDDA5E5
  17.  
  18.  
  19. ocde_ecc parameters ec2n
  20.  
  21. a: 0163F35A5137C2CE3EA6ED8667190B0BC43ECD69977702709B
  22. b: 00C9BB9E8927D4D64C377E2AB2856A5B16E3EFB7F61D4316AE
  23.  
  24. n: 010000000000000000000000015AAB561B005413CCD4EE99D5
  25.  
  26. p: 02000000000000000000000000000000000000000000008001
  27.  
  28. x: 00D9B67D192E0367C803F39E1A7E82CA14A651350AAE617E8F
  29.  
  30. y: 01CE94335607C304AC29E7DEFBD9CA01F596F927224CDECF6C
  31.  
  32. the public ec2n point:
  33.  
  34. 9F 9E 72 DA 67 0D 16 62 85 94 79 9A DE 8B 32 33 AE 36 C2 36 48 CB 63 8D 01 needs
  35. reversing for both
  36.  
  37. 25 2F 04 D6 35 5C A5 F5 1A 60 A5 46 06 F5 B5 2B 5C F9 F6 B5 9B EB 51 32
  38.  
  39. reversed_public_ec2n_point:
  40.  
  41. 018D63CB4836C236AE33328BDE9A79948562160D67DA729E9F ;Qax
  42. 3251EB9BB5F6F95C2BB5F50646A5601AF5A55C35D6042F25 ; Qay
  43.  
  44. */
  45.  
  46. #include "all.h"
  47. #include "miracl.h"
  48.  
  49. DWORD WINAPI GenererSerial(HWND hwnd)
  50. {
  51. int i=0;
  52. int m193=193;
  53. int a14=14;
  54. int a15=15;
  55. int b13=13;
  56. int c13=13;
  57. miracl *mip;
  58. big a, b, p, n, x, d, k, r, s, h,y,y_1,one;
  59. epoint *G;
  60. TCHAR name[MAX_NAME];
  61. TCHAR serial[MAX_SERIAL];
  62. TCHAR temp[60];
  63. TCHAR temp7[660];
  64. TCHAR decoded[660];
  65. BYTE digest[20] = {}
  66. sha sh;
  67.  
  68.  
  69. if(GetDlgItemText(hwnd,IDC_NAME,name,MAX_NAME)<MIN_NAME)
  70. {
  71. SetDlgItemText(hwnd, IDC_SERIAL,"your name is too short");
  72. }
  73.  
  74.  
  75. else
  76. {
  77. RtlZeroMemory(temp,60);
  78. lstrcat(temp,hardcode);
  79. lstrcat(temp,name);
  80. lstrcpy(name,temp);
  81. RtlZeroMemory(temp,60);
  82.  
  83.  
  84.  
  85.  
  86. mip = mirsys(50, 0);
  87.  
  88. G = epoint_init();
  89. memset(serial,0,MAX_SERIAL);
  90. mip->IOBASE = 16;
  91. a = mirvar(0);
  92. b = mirvar(0);
  93. p = mirvar(0);
  94. n = mirvar(0);
  95. y = mirvar(0);
  96. one = mirvar(0);
  97. x = mirvar(0);
  98. d = mirvar(0);
  99. k = mirvar(0);
  100. r = mirvar(0);
  101. s = mirvar(0);
  102. h = mirvar(0);
  103. y_1 = mirvar(0);
  104. cinstr(y_1, "01CE94335607C304AC29E7DEFBD9CA01F596F927224CDECF6C");
  105. cinstr(x, "00D9B67D192E0367C803F39E1A7E82CA14A651350AAE617E8F");
  106. cinstr(p, "AEBF94CEE3E707");
  107. cinstr(n, "010000000000000000000000015AAB561B005413CCD4EE99D5");
  108. cinstr(d, "5445414D584FDA8E91");//gerada
  109. cinstr(a, "0163F35A5137C2CE3EA6ED8667190B0BC43ECD69977702709B");
  110. cinstr(b, "00C9BB9E8927D4D64C377E2AB2856A5B16E3EFB7F61D4316AE");
  111. cinstr(one,"1");
  112. //ecurve_init(a, b, p, MR_AFFINE);
  113. //2^193 + 2^14 + 2^13 + 2^13 + 2^0 for pentominal
  114. ecurve2_init(m193,a15,NULL,NULL,a,b,FALSE,MR_AFFINE);
  115. epoint2_set(x, y_1, 0, G);
  116.  
  117. /*1. Check that QA is not equal to O and its coordinates are otherwise valid
  118.  
  119. 2. Check that QA lies on the curve
  120.  
  121. 3. check that nQA=0
  122.  
  123. After that bob follows these steps:
  124.  
  125. 1. verify that r and s are integers in [1,n-1]. if not signature is invalid
  126.  
  127. 2. calculate e=HASH(M) where hash is the same function used in the signature generation. Let z be the Ln leftmost bits of e.
  128.  
  129. 3. calculate w=s^-1 mod n
  130.  
  131. 4. calculate u1=zw(mod n) and u2=rw(mod n)
  132.  
  133. 5. calculate (x1,y1)=u1G+u2QA
  134.  
  135. 6. the signature is valid if r=x1 mod n.
  136. */
  137.  
  138.  
  139. bytes_to_big(16, digest, h);
  140.  
  141.  
  142. ecurve2_mult(k, G, G);
  143. epoint2_get(G, r, r);
  144. powmod(r,one,n,r);
  145.  
  146. xgcd(k, n, k, k, k);
  147.  
  148. shs_init(&sh);
  149. i = 0;
  150. while (name[i] != 0)
  151. {
  152. shs_process(&sh, name[i]);
  153. i++;
  154. }
  155. shs_hash(&sh, digest);
  156.  
  157. bytes_to_big(20, digest, h);
  158. mad(d, r, h, n, n, s);
  159. mad(k, s, s, n, n, s);
  160.  
  161.  
  162. RtlZeroMemory(decoded,660);
  163. RtlZeroMemory(serial,MAX_SERIAL);
  164.  
  165. __asm {
  166.  
  167. mov eax, dword ptr ds:[r];
  168. mov eax, dword ptr ds:[eax]
  169. imul eax, 4
  170. cmp eax, 0
  171. jz avoid
  172. xor ecx, ecx
  173. xor edx, edx
  174. dec ecx
  175. push esi
  176. search:
  177. inc ecx
  178. mov ebx, eax
  179. sub ebx, ecx
  180. mov esi, dword ptr ds:[r]
  181. mov dl, byte ptr ds:[esi+4*3+ebx-1]
  182. cmp dl, 0
  183. jz search
  184. pop esi
  185. mov eax, dword ptr ds:[r];
  186. mov eax, dword ptr ds:[eax];
  187. imul eax, 4
  188. sub eax, ecx//r length
  189. mov ecx, eax
  190. mov edx, 25
  191. sub edx, eax //number of zeros to add
  192. lea eax, serial
  193. add eax, edx
  194. push edi
  195. push esi
  196. xor esi, esi
  197. dec esi
  198.  
  199. makeling:
  200. inc esi
  201. mov ebx, ecx
  202. sub ebx, esi
  203.  
  204. mov edi, dword ptr ds:[r]
  205. mov dl, byte ptr ds:[edi+4*3+ebx-1]
  206. mov byte ptr ds:[eax+esi],dl
  207. cmp esi, ecx
  208. jnz makeling
  209.  
  210. pop esi
  211. pop edi
  212. avoid:
  213. }
  214. //cotstr(r, serial);
  215. //cotstr(s, temp);
  216. //strcat(serial+25, temp);
  217. __asm {
  218.  
  219. mov eax, dword ptr ds:[s];
  220. mov eax, dword ptr ds:[eax]
  221. imul eax, 4
  222. cmp eax, 0
  223. jz avoidre
  224. xor ecx, ecx
  225. xor edx, edx
  226. dec ecx
  227. push esi
  228. searchre:
  229. inc ecx
  230. mov ebx, eax
  231. sub ebx, ecx
  232. mov esi, dword ptr ds:[s]
  233. mov dl, byte ptr ds:[esi+4*3+ebx-1]
  234. cmp dl, 0
  235. jz searchre
  236. pop esi
  237. mov eax, dword ptr ds:[s];
  238. mov eax, dword ptr ds:[eax];
  239. imul eax, 4
  240. sub eax, ecx//r length
  241. mov ecx, eax
  242. mov edx, 25
  243. sub edx, eax //number of zeros to add
  244. lea eax, serial
  245. add eax, 25
  246. add eax, edx
  247. push edi
  248. push esi
  249. xor esi, esi
  250. dec esi
  251.  
  252. makelingre:
  253. inc esi
  254. mov ebx, ecx
  255. sub ebx, esi
  256.  
  257. mov edi, dword ptr ds:[s]
  258. mov dl, byte ptr ds:[edi+4*3+ebx-1]
  259. mov byte ptr ds:[eax+esi],dl
  260. cmp esi, ecx
  261. jnz makelingre
  262.  
  263. pop esi
  264. pop edi
  265. avoidre:
  266. }
  267.  
  268. __asm {
  269.  
  270. //D599EED4 CC135400 1B56AB5A 01000000 00000000 00000000 01000000
  271.  
  272. XOR EAX,EAX
  273. XOR EBX,EBX
  274. XOR ECX,ECX
  275.  
  276. decode:
  277. mov al, byte ptr ds:[serial+ecx]
  278. inc al
  279. and al, 0f0h
  280. sub al, 30h
  281. movsx eax, al
  282. shr al, 4
  283. or al,30h
  284. mov byte ptr ds:[decoded+ecx*2+1],al
  285. mov al, byte ptr ds:[serial+ecx]
  286. inc al
  287. and al, 0fh
  288. or al,30h
  289. mov byte ptr ds:[decoded+ecx*2],al
  290. inc ecx
  291. cmp ecx, 50
  292. jnz decode
  293.  
  294. }
  295.  
  296.  
  297. SetDlgItemText(hwnd, IDC_SERIAL,decoded);
  298. epoint_free(G);
  299. mirkill(a);
  300. mirkill(b);
  301. mirkill(p);
  302. mirkill(y_1);
  303. mirkill(n);
  304. mirkill(x);
  305. mirkill(d);
  306. mirkill(one);
  307. mirkill(k);
  308. mirkill(r);
  309. mirkill(s);
  310. mirkill(y);
  311. mirkill(h);
  312. mirexit();
  313. }
  314. return 0;
  315. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement