Here is optimized signing function with all necessary checks for valid signature generation:
char private_key[] = "8..."; <-- fill with valid key
char prime1[] = "AEBF94CEE3E707";
char prime2[] = "AEBF94D5C6AA71";
char curve_a[] = "2982";
char curve_b[] = "3408";
char point1[] = "7A3E808599A525";
char point2[] = "28BE7FAFD2A052";
void ecssign(char *serial, char *options, char *lic1, char *lic2)
{
mirsys(800, 16)->IOBASE = 16;
sha sha1;
shs_init(&sha1);
char *ptr = serial;
while(*ptr) shs_process(&sha1, *ptr++);
ptr = options;
while(*ptr) shs_process(&sha1, *ptr++);
char h[20];
shs_hash(&sha1, h);
big hash = mirvar(0);
bytes_to_big(20, h, hash);
big a = mirvar(0); instr(a, curve_a);
big b = mirvar(0); instr(b, curve_b);
big p = mirvar(0); instr(p, prime1);
big q = mirvar(0); instr(q, prime2);
big Gx = mirvar(0); instr(Gx, point1);
big Gy = mirvar(0); instr(Gy, point2);
big d = mirvar(0); instr(d, private_key);
big k = mirvar(0);
big r = mirvar(0);
big s = mirvar(0);
big k1 = mirvar(0);
big zero = mirvar(0);
big f1 = mirvar(17);
big f2 = mirvar(53);
big f3 = mirvar(905461);
big f4 = mirvar(60291817);
epoint *G = epoint_init();
epoint *kG = epoint_init();
ecurve_init(a, b, p, MR_PROJECTIVE);
epoint_set(Gx, Gy, 0, G);
for(;;)
{
incr(k, 1, k);
if(divisible(k, f1) || divisible(k, f2) || divisible(k, f3) || divisible(k, f4))
continue;
ecurve_mult(k, G, kG);
epoint_get(kG, r, r);
divide(r, q, q);
if(mr_compare(r, zero) == 0)
continue;
xgcd(k, q, k1, k1, k1);
mad(d, r, hash, q, q, s);
mad(s, k1, k1, q, q, s);
if(!divisible(s, f1) && !divisible(s, f2) && !divisible(s, f3) && !divisible(s, f4))
break;
}
cotstr(r, lic1);
cotstr(s, lic2);
}