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.
This commit is contained in:
Ryan X. Charles 2014-08-15 15:09:28 -04:00
parent 381481fb7c
commit f11ed4d20b
2 changed files with 7 additions and 1 deletions

View File

@ -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();

View File

@ -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() {