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!

  • 2
    210330a31c3caab4087c19fbe770514e5e6b80eda552d1e5f8becabd12c4540e is not a valid Ed25519 curve point, so you'd expect things to break. Only 50% of 256 bit sequences are valid curve points. Where did you get that hex from? – knaccc Apr 18 at 12:12
  • @knaccc Thanks for your reply! I got the hex from PaperWallet.skGen() in MiniNero If my memory serves me right... BTW, how can I verify them? Should I use sc_reduce32() first? – Mooooo Apr 18 at 13:17
  • 2
    skGen creates a secret key, which is a scalar and not a curve point. sc_reduce32 applies to scalars and not curve points. You want to use pkGen to generate a curve point. – knaccc Apr 18 at 19:05
  • @knaccc Thanks you very much! It's very clear. – Mooooo Apr 19 at 14:26
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
| improve this answer | |
  • Very clear! Thank you for your answer!! – Mooooo Apr 19 at 14:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.