static char* calculate_private_key(u8* us1, u8* us2, u8* uz1, u8* uz2, u8* un, u8* ur) { mpz_t s1, s2, z1, z2, n, r, k, dA; mpz_init(s1); mpz_init(s2); mpz_init(z1); mpz_init(z2); mpz_init(n); mpz_init(r); mpz_init(k); mpz_init(dA); load_num(s1, us1); load_num(s2, us2); load_num(z1, uz1); load_num(z2, uz2); load_num(n, un); load_num(r, ur); mpz_sub(z2, z1, z2); mpz_sub(s2, s1, s2); mpz_invert(s2, s2, n); mpz_mul(k, z2, s2); mpz_mod(k, k, n); mpz_mul(s2, s1, k); mpz_sub(s2, s2, z1); mpz_invert(r, r, n); mpz_mul(dA, s2, r); mpz_mod(dA, dA, n); // printf("k: %s\n", mpz_get_str(NULL, 16, k)); return mpz_get_str(NULL, 16, dA); }
/* Code for leaf nodes in the expression parse tree: constants, strings, * identifers, and so on. */ static leaf_code(stream, node, need_lval) { if ( node[0] == 'num' || node[0] == 'chr' || node[0] == 'str' ) { if (node[0] == 'num') load_num(stream, node[3]); else if (node[0] == 'chr') load_chr(stream, &node[3]); else if (node[0] == 'str') { auto lc = new_clabel(); defn_str(stream, &node[3], lc); load_str(stream, lc); } } else if ( node[0] == 'id' ) { auto off, is_lval = lookup_sym( &node[3], &off ); auto need_addr = (is_lval == need_lval); if (!off) load_symbol(stream, &node[3], need_addr); else load_local(stream, off, need_addr); } else int_error("Unknown token '%Mc' in parse tree", node[0]); }