1

I'd like to create LSAG in C and now I need to calculate ciKi as element in L. Then, I try an example with MiniNero like below:

K = "210330a31c3caab4087c19fbe770514e5e6b80eda552d1e5f8becabd12c4540e"
c = "30837c72f9e0034f5669d5b122a200565666f6d31ba9a4c707ebfd0860303988"
print(MiniNero.scalarmultKey(K, c))

And I got the answer:

4581d73d76f00df2724d15bca43b4b9d2fe43132e3357449fd61d8d961e36b33

However, I got a different result with my C version...

from_hex(c, 32, "30837c72f9e0034f5669d5b122a200565666f6d31ba9a4c707ebfd0860303988");
from_hex(K, 32, "210330a31c3caab4087c19fbe770514e5e6b80eda552d1e5f8becabd12c4540e");

scalarmultKey((const unsigned char *) K, (const unsigned char *)c, (unsigned char *)result);

for(i=0; i<32; i++){
    printf("%02x",result[i]);

I got the result:

454c7252631ea5dfd757df7048796fef1b5c235191897791afb84417b82f9c7a

where the content of scalarmultKey is:

void scalarmultKey(const unsigned char *P, const unsigned char *a, unsigned char *aP)
{
    ge_p3 *A = malloc(sizeof(ge_p3));
    ge_p2 *R = malloc(sizeof(ge_p2));

    ge_frombytes_vartime(A, P);
    ge_scalarmult(R, a, A);
    ge_tobytes(aP, R);
}

Is there difference between scalarmultKeys in MiniNero with monero-project's.

Please help on this problem.. Many thanks!

Mooooo
  • 459
  • 2
  • 8

1 Answers1

3

As @knaccc astutely points out, your keys are not valid.

An example with valid test keys, in Python:

p = '644206dabcd3014180f120c0d3da7fc167701a310ca520467199fcefbd7e0109'
P = 'c2f9d63a7dbfb73fc24dae28df2ecf5b3667eff59124511fa6735ac848938cce'
print MiniNero.scalarmultKey(P, p)

Outputs:

af16f921de9efbf28ec744dbe927e7592de8ee4fb1f5c6112e3458b00369a0a4

And in C:

key r,p,P;
hex_to_pod("644206dabcd3014180f120c0d3da7fc167701a310ca520467199fcefbd7e0109", p);
hex_to_pod("c2f9d63a7dbfb73fc24dae28df2ecf5b3667eff59124511fa6735ac848938cce", P);
scalarmultKey(r, P, p);
for(int i=0; i<32; i++)
    printf("%02x", r[i]);

Outputs the same:

af16f921de9efbf28ec744dbe927e7592de8ee4fb1f5c6112e3458b00369a0a4
jtgrassie
  • 19,601
  • 4
  • 17
  • 54