Browse Source

bug: should mod bn addition

when adding two private keys to get a new private key, you should mod the
result with N so that it is always less than N.
patch-2
Ryan X. Charles 11 years ago
parent
commit
f11ed4d20b
  1. 3
      lib/expmt/stealth.js
  2. 5
      test/test.stealth.js

3
lib/expmt/stealth.js

@ -1,6 +1,7 @@
var Key = require('../key');
var Privkey = require('../privkey');
var Pubkey = require('../pubkey');
var Point = require('../point');
var Hash = require('../hash');
var KDF = require('../kdf');
var base58check = require('../base58check');
@ -76,7 +77,7 @@ Stealth.prototype.getReceivePubkeyAsSender = function(senderKey) {
Stealth.prototype.getReceiveKey = function(senderPubkey) {
var sharedKey = this.getSharedKeyAsReceiver(senderPubkey);
var privkey = Privkey(this.payloadKey.privkey.bn.add(sharedKey.privkey.bn));
var privkey = Privkey(this.payloadKey.privkey.bn.add(sharedKey.privkey.bn).mod(Point.getN()));
var key = Key(privkey);
key.privkey2pubkey();

5
test/test.stealth.js

@ -141,6 +141,11 @@ describe('Stealth', function() {
key.pubkey.toString().should.equal(pubkey.toString());
});
it('should return private key with length 32 or less', function() {
var key = stealth.getReceiveKey(senderKey.pubkey);
key.privkey.bn.toBuffer().length.should.be.below(33);
});
});
describe('#isForMe', function() {

Loading…
Cancel
Save