-1

I was trying to understand calculation of EC public key for given secret key. Following this question I was found a well explained answer, but (as often happens) something goes wrong. According to previous answer and this document I use following Perl script to perform calculation:

#!/usr/bin/perl

use strict;
use warnings;

use Math::BigInt;

my $d_hex = "18E14A7B6A307F426A94F8114701E7C8E774E7F9A47E2C2035DB29A206321725";
my $d_num = Math::BigInt->new("0x$d_hex");

my $g_hex = "0479BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8";
my $g_num = Math::BigInt->new("0x$g_hex");

my $q_num = $d_num->copy()->bmul($g_num);
my $q_hex = $q_num->as_hex();

# Expect: 0x0450863ad64a87ae8a2fe83c1af1a8403cb53f53e486d8511dad8a04887e5b23522cd470243453a299fa9e77237716103abc11a1df38855ed6f2ee187e9c582ba6
# Result: 0x479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798611c24f290d443a7c839f40d5512f071e48c9c424b038039d222fa320142ebdd

print "$q_hex\n";

Here is expected result means a result of calculation using code written in C from previously founded answer. As you can see, results is different. What I am doing wrong?

Community
  • 1
  • 1
Kechup
  • 115
  • 2
  • 9

2 Answers2

1

I'm not used to Perl but i cannot see you initializing or using a cyclic group. Elliptic curve operations and asymmetric crypto in general are (mostly) always performed in a cyclic group

Paul Bastian
  • 2,597
  • 11
  • 26
  • Thank you, I was found a nice library written in PHP where I found how to deal with it. I will post right answer there when I am done. – Kechup Aug 24 '15 at 11:52
1

So, I found a PHP library that can generate addresses from private key, and wrote an example code in Perl that based on this PHP code. It weird, but works is some cases. Anyway, this is enough for me to understand about how it works.

Kechup
  • 115
  • 2
  • 9