How to use the jsbn.ONE function in jsbn

To help you get started, we’ve selected a few jsbn examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hardbyte / paillier.js / index.js View on Github external
}

    console.log("Generating new keypair with " + keysize + " bit length key");

    var p, q, n, g, phi_n, mu;
    var correctLength = false;
    while (!correctLength || p.compareTo(q) == 0){
        p = getprimeover(keysize>>1);
        q = getprimeover(keysize>>1);
        n = p.multiply(q);
        correctLength = n.testBit(keysize -1)
    }
    // simple paillier variant with g=n+1
    g = n.add(bn.ONE);

    phi_n = p.subtract(bn.ONE).multiply(q.subtract(bn.ONE));
    mu = phi_n.modInverse(n);

    var pubKey = exports.publicKey(g, n);

    /**
     * A KeyPair
     * @typedef KeyPair
     * @property {PublicKey} public_key
     * @property {PrivateKey} private_key
     * @property {number} n_length - The key length in bits
     * */
    return {
        public_key: pubKey,
        private_key: exports.privateKey(phi_n, mu, pubKey),
        n_length: keysize
    };
github apache / apex-malhar / front / js / datatorrent / RecordingModel.js View on Github external
// Create the request object
            var reqObject = {
                appId: this.get('appId'),
                operatorId: this.get('operatorId'),
                startTime: this.get('startTime'),
                ports: selected_ports
            };
            offset = new BigInteger(offset+'');
            limit = new BigInteger(limit+'');
            var actualLimit = new BigInteger(limit+'');
            var actualOffset = new BigInteger(offset+'');
            
            if (!windowId){
                
                // check which outer tuples have already been loaded
                for(var i = BigInteger.ZERO; i.compareTo(limit) < 0; i = i.add(BigInteger.ONE)) {
                    var checkIdx = i.add(offset).toString();
                    var tuple = this.tuples.get(checkIdx);
                    if ( tuple === undefined) break;
                    if ( tuple.get('portId') === '' ) break;
                    actualOffset = actualOffset.add(BigInteger.ONE);
                    actualLimit = actualLimit.subtract(BigInteger.ONE);
                }
                reqObject.offset = actualOffset.toString();
                
            } else {
                
                reqObject.startWindow = windowId;
                
            }
            
            reqObject.limit = actualLimit.toString();
github apache / apex-malhar / front / js / app / lib / widgets / TupleViewerWidget / lib / TvModel.js View on Github external
indeces.forEach(function(val){
            // var newIdx = Math.min(self.get("currentTupleCount") - 1, Math.max(val*1 + change, 0));
            var newIdx = currentTotal.subtract(BigInteger.ONE).min((new BigInteger(val+'')).add(change).max(BigInteger.ZERO));
            var next = this.tuples.get(newIdx.toString());
            if (next) {
                var data = {"selected":true};
                if (newIdx == anchor_idx) {
                    data.anchored = true;
                    anchored = true;
                }
                next.set(data);
                last = next;
            }
        }, this);
        if (!anchored && last) {
github apache / apex-malhar / front / js / app / lib / widgets / TupleViewerWidget / lib / TvModel.js View on Github external
while (k >= step) {
                // look for lows
                var jumped = false;
                for (var i=0; i < ranges.length; i++) {
                    var prevRange = ranges[i-1];
                    var range = ranges[i];
                    if (range.low === curWindowId) {
                        if (prevRange === undefined) return;
                        curWindowId = prevRange.high;
                        BI_windowId = new BigInteger(prevRange.high);
                        jumped = true;
                    }
                };
                if (!jumped) {
                    // no jump between ranges made, subtract one
                    BI_windowId = BI_windowId.subtract(BigInteger.ONE);
                    curWindowId = BI_windowId.toString();
                }
                // check if tuples are available for this window
                k--;
            }
            
        }
        else if (step > 0) {
            
            // iterator for moving windows
            var k = 1;
            while (k <= step) {
                // look for lows
                var jumped = false;
                for (var i=0; i < ranges.length; i++) {
                    var nextRange = ranges[i+1];
github apache / apex-malhar / front / js / datatorrent / RecordingModel.js View on Github external
ports: selected_ports
            };
            offset = new BigInteger(offset+'');
            limit = new BigInteger(limit+'');
            var actualLimit = new BigInteger(limit+'');
            var actualOffset = new BigInteger(offset+'');
            
            if (!windowId){
                
                // check which outer tuples have already been loaded
                for(var i = BigInteger.ZERO; i.compareTo(limit) < 0; i = i.add(BigInteger.ONE)) {
                    var checkIdx = i.add(offset).toString();
                    var tuple = this.tuples.get(checkIdx);
                    if ( tuple === undefined) break;
                    if ( tuple.get('portId') === '' ) break;
                    actualOffset = actualOffset.add(BigInteger.ONE);
                    actualLimit = actualLimit.subtract(BigInteger.ONE);
                }
                reqObject.offset = actualOffset.toString();
                
            } else {
                
                reqObject.startWindow = windowId;
                
            }
            
            reqObject.limit = actualLimit.toString();
            
            if (actualLimit.compareTo(BigInteger.ZERO) <= 0) {
                // The limit was zero or less, don't do anything.
                return;
            }
github hardbyte / paillier.js / index.js View on Github external
exports.publicKey = function(g, n){
    g = convertToBN(g);
    n = convertToBN(n);

    /**
     * @lends PublicKey#
     */
    var pk = {
        /** @property {BigInteger} g */
        g:  g,
        /** @property {BigInteger} n */
        n: n,
        nsquare: n.multiply(n),
        /** @property {BigInteger} max_int - The largest number that can be encrypted with this public key. */
        max_int: n.divide(new bn("3", 10)).subtract(bn.ONE)
    };

    // Return an integer number between 1 and n
    function get_random_lt_n(){
        do {
            r = new bn(1 + Math.log(pk.n)/Math.LN2, 1, rng);
            // make sure r <= n
        } while(r.compareTo(pk.n) <= 0);
        return r;
    }

    /**
     * Raw paillier encryption of a positive integer plaintext.
     *
     * You probably want to use {@link encrypt} instead, because
     * it handles signed integers as well as floats.
github hardbyte / paillier.js / test / test_encoded_number.js View on Github external
test("Encode Int Too Large Positive", function (t) {
    t.plan(1);

    /**
     * Since we want to use realistic sized keys (> 512bit)
     * this test can't pass a Javascript Number into encode
     * So we pass in a decimal string.
     * */
    var number = pub.max_int.add(bn.ONE).toString(10);

    t.throws(
        function(){
            phe.EncodedNumber.encode(pub, number);
        }, "ValueError"
    );
});
github apache / apex-malhar / front / js / datatorrent / RecordingModel.js View on Github external
tuples.forEach(function(tuple){
                tuple.idx = idxBR.toString();
                tuple.windowId = windowId;
                retTuples.push(tuple);
                idxBR = idxBR.add(BigInteger.ONE);
            });
        }

jsbn

The jsbn library is a fast, portable implementation of large-number math in pure JavaScript, enabling public-key crypto and other applications on desktop and mobile browsers.

MIT
Latest version published 7 years ago

Package Health Score

67 / 100
Full package analysis