indutny / elliptic

Fast Elliptic Curve Cryptography in plain javascript
1.71k stars 398 forks source link

Extending to new curve #172

Open GuthL opened 5 years ago

GuthL commented 5 years ago

Hi, I want to extend the lib to a new Twisted Edwards curve and I'm having a hard time understanding what the difference parameters refer to. What prime is referring to? Why is c set to 1 altough ed25519 cofactor is 3? At last, should I assume that n is the subgroup order?

defineCurve('ed25519', {
  type: 'edwards',
  prime: 'p25519',
  p: '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed',
  a: '-1',
  c: '1',
  // -121665 * (121666^(-1)) (mod P)
  d: '52036cee2b6ffe73 8cc740797779e898 00700a4d4141d8ab 75eb4dca135978a3',
  n: '1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed',
  hash: hash.sha256,
  gRed: false,
  g: [
    '216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a',

    // 4/5
    '6666666666666666666666666666666666666666666666666666666666666658'
  ]
});

Thanks a lot

GuthL commented 5 years ago

So, I discover that prime is a feature of BN.js.

var red = BN.red(primeName);
Where primeName is either of these Mersenne Primes:
'k256'
'p224'
'p192'
'p25519'