Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ECDSA-56
- Parameters are, according to The Elliptic Curve Digital Signature Algorithm
- (D. Johnson and A. Menezes, Univ. of Waterloo, 1999):
- a = 0x2982
- b = 0x3408
- p = 0xAEBF94CEE3E707
- xG = 0x7A3E808599A525
- xQ = 0x9F70A02013BC9B
- Q = d * G, d being the private key.
- n = 0xAEBF94D5C6AA71 not prime.
- n = 0x11 * 0x35 * 0xDD0F5 * 0x397FAE9
- Discrete logarithm can be computed fastly using Pohlig-Hellman:
- d = 0x9D3F1E3CDDA5E5
- ocde_ecc parameters ec2n
- a: 0163F35A5137C2CE3EA6ED8667190B0BC43ECD69977702709B
- b: 00C9BB9E8927D4D64C377E2AB2856A5B16E3EFB7F61D4316AE
- n: 010000000000000000000000015AAB561B005413CCD4EE99D5
- p: 02000000000000000000000000000000000000000000008001
- x: 00D9B67D192E0367C803F39E1A7E82CA14A651350AAE617E8F
- y: 01CE94335607C304AC29E7DEFBD9CA01F596F927224CDECF6C
- the public ec2n point:
- 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
- reversing for both
- 25 2F 04 D6 35 5C A5 F5 1A 60 A5 46 06 F5 B5 2B 5C F9 F6 B5 9B EB 51 32
- reversed_public_ec2n_point:
- 018D63CB4836C236AE33328BDE9A79948562160D67DA729E9F ;Qax
- 3251EB9BB5F6F95C2BB5F50646A5601AF5A55C35D6042F25 ; Qay
- */
- #include "all.h"
- #include "miracl.h"
- DWORD WINAPI GenererSerial(HWND hwnd)
- {
- int i=0;
- int m193=193;
- int a14=14;
- int a15=15;
- int b13=13;
- int c13=13;
- miracl *mip;
- big a, b, p, n, x, d, k, r, s, h,y,y_1,one;
- epoint *G;
- TCHAR name[MAX_NAME];
- TCHAR serial[MAX_SERIAL];
- TCHAR temp[60];
- TCHAR temp7[660];
- TCHAR decoded[660];
- BYTE digest[20] = {}
- sha sh;
- if(GetDlgItemText(hwnd,IDC_NAME,name,MAX_NAME)<MIN_NAME)
- {
- SetDlgItemText(hwnd, IDC_SERIAL,"your name is too short");
- }
- else
- {
- RtlZeroMemory(temp,60);
- lstrcat(temp,hardcode);
- lstrcat(temp,name);
- lstrcpy(name,temp);
- RtlZeroMemory(temp,60);
- mip = mirsys(50, 0);
- G = epoint_init();
- memset(serial,0,MAX_SERIAL);
- mip->IOBASE = 16;
- a = mirvar(0);
- b = mirvar(0);
- p = mirvar(0);
- n = mirvar(0);
- y = mirvar(0);
- one = mirvar(0);
- x = mirvar(0);
- d = mirvar(0);
- k = mirvar(0);
- r = mirvar(0);
- s = mirvar(0);
- h = mirvar(0);
- y_1 = mirvar(0);
- cinstr(y_1, "01CE94335607C304AC29E7DEFBD9CA01F596F927224CDECF6C");
- cinstr(x, "00D9B67D192E0367C803F39E1A7E82CA14A651350AAE617E8F");
- cinstr(p, "AEBF94CEE3E707");
- cinstr(n, "010000000000000000000000015AAB561B005413CCD4EE99D5");
- cinstr(d, "5445414D584FDA8E91");//gerada
- cinstr(a, "0163F35A5137C2CE3EA6ED8667190B0BC43ECD69977702709B");
- cinstr(b, "00C9BB9E8927D4D64C377E2AB2856A5B16E3EFB7F61D4316AE");
- cinstr(one,"1");
- //ecurve_init(a, b, p, MR_AFFINE);
- //2^193 + 2^14 + 2^13 + 2^13 + 2^0 for pentominal
- ecurve2_init(m193,a15,NULL,NULL,a,b,FALSE,MR_AFFINE);
- epoint2_set(x, y_1, 0, G);
- /*1. Check that QA is not equal to O and its coordinates are otherwise valid
- 2. Check that QA lies on the curve
- 3. check that nQA=0
- After that bob follows these steps:
- 1. verify that r and s are integers in [1,n-1]. if not signature is invalid
- 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.
- 3. calculate w=s^-1 mod n
- 4. calculate u1=zw(mod n) and u2=rw(mod n)
- 5. calculate (x1,y1)=u1G+u2QA
- 6. the signature is valid if r=x1 mod n.
- */
- bytes_to_big(16, digest, h);
- ecurve2_mult(k, G, G);
- epoint2_get(G, r, r);
- powmod(r,one,n,r);
- xgcd(k, n, k, k, k);
- shs_init(&sh);
- i = 0;
- while (name[i] != 0)
- {
- shs_process(&sh, name[i]);
- i++;
- }
- shs_hash(&sh, digest);
- bytes_to_big(20, digest, h);
- mad(d, r, h, n, n, s);
- mad(k, s, s, n, n, s);
- RtlZeroMemory(decoded,660);
- RtlZeroMemory(serial,MAX_SERIAL);
- __asm {
- mov eax, dword ptr ds:[r];
- mov eax, dword ptr ds:[eax]
- imul eax, 4
- cmp eax, 0
- jz avoid
- xor ecx, ecx
- xor edx, edx
- dec ecx
- push esi
- search:
- inc ecx
- mov ebx, eax
- sub ebx, ecx
- mov esi, dword ptr ds:[r]
- mov dl, byte ptr ds:[esi+4*3+ebx-1]
- cmp dl, 0
- jz search
- pop esi
- mov eax, dword ptr ds:[r];
- mov eax, dword ptr ds:[eax];
- imul eax, 4
- sub eax, ecx//r length
- mov ecx, eax
- mov edx, 25
- sub edx, eax //number of zeros to add
- lea eax, serial
- add eax, edx
- push edi
- push esi
- xor esi, esi
- dec esi
- makeling:
- inc esi
- mov ebx, ecx
- sub ebx, esi
- mov edi, dword ptr ds:[r]
- mov dl, byte ptr ds:[edi+4*3+ebx-1]
- mov byte ptr ds:[eax+esi],dl
- cmp esi, ecx
- jnz makeling
- pop esi
- pop edi
- avoid:
- }
- //cotstr(r, serial);
- //cotstr(s, temp);
- //strcat(serial+25, temp);
- __asm {
- mov eax, dword ptr ds:[s];
- mov eax, dword ptr ds:[eax]
- imul eax, 4
- cmp eax, 0
- jz avoidre
- xor ecx, ecx
- xor edx, edx
- dec ecx
- push esi
- searchre:
- inc ecx
- mov ebx, eax
- sub ebx, ecx
- mov esi, dword ptr ds:[s]
- mov dl, byte ptr ds:[esi+4*3+ebx-1]
- cmp dl, 0
- jz searchre
- pop esi
- mov eax, dword ptr ds:[s];
- mov eax, dword ptr ds:[eax];
- imul eax, 4
- sub eax, ecx//r length
- mov ecx, eax
- mov edx, 25
- sub edx, eax //number of zeros to add
- lea eax, serial
- add eax, 25
- add eax, edx
- push edi
- push esi
- xor esi, esi
- dec esi
- makelingre:
- inc esi
- mov ebx, ecx
- sub ebx, esi
- mov edi, dword ptr ds:[s]
- mov dl, byte ptr ds:[edi+4*3+ebx-1]
- mov byte ptr ds:[eax+esi],dl
- cmp esi, ecx
- jnz makelingre
- pop esi
- pop edi
- avoidre:
- }
- __asm {
- //D599EED4 CC135400 1B56AB5A 01000000 00000000 00000000 01000000
- XOR EAX,EAX
- XOR EBX,EBX
- XOR ECX,ECX
- decode:
- mov al, byte ptr ds:[serial+ecx]
- inc al
- and al, 0f0h
- sub al, 30h
- movsx eax, al
- shr al, 4
- or al,30h
- mov byte ptr ds:[decoded+ecx*2+1],al
- mov al, byte ptr ds:[serial+ecx]
- inc al
- and al, 0fh
- or al,30h
- mov byte ptr ds:[decoded+ecx*2],al
- inc ecx
- cmp ecx, 50
- jnz decode
- }
- SetDlgItemText(hwnd, IDC_SERIAL,decoded);
- epoint_free(G);
- mirkill(a);
- mirkill(b);
- mirkill(p);
- mirkill(y_1);
- mirkill(n);
- mirkill(x);
- mirkill(d);
- mirkill(one);
- mirkill(k);
- mirkill(r);
- mirkill(s);
- mirkill(y);
- mirkill(h);
- mirexit();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement