Skip to content

Commit

Permalink
Add RSABigInteger
Browse files Browse the repository at this point in the history
Add RSABigInteger, to make, using BigInteger, the following RSA operations:
encryption/decryption, and sign/verify
and make this for the bytearrays with arbitrary bytelength.

Two functions allow to do it, now:
	RSABigInteger.EncryptBytes(key, src, byPriv)
	RSABigInteger.DecryptBytes(key, src, byPub)

See changes in differences, and description of this - in comment for this commit.
  • Loading branch information
username1565 authored Nov 28, 2020
1 parent c51dcfd commit 2b2057d
Showing 1 changed file with 2,364 additions and 2 deletions.
Loading

2 comments on commit 2b2057d

@username1565
Copy link
Owner Author

@username1565 username1565 commented on 2b2057d Nov 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add "checkCoPrime" and "genCoPrime" and "BigInteger.from()" functions.
Add "isSafePrime" and "generateSafePrime".
Add "isStrongPrime" and "genStrongPrime" (implementation of Gordon's algorithm, for BigInteger).
Add "Factorize" (implementation of Pollard-rho algorithm, with Richard's Brent optimization), add test for Factorize.
Add "EulerPhi".
	phi(p) = (p-1), when p is a prime,
	phi(1 * p^a) = phi(1) * phi(p^a) = 1 * phi(p^a) = p^a - p^(a-1)
	phi(2 * p^a) = phi(2) * phi(p^a) = 1 * phi(p^a) = p^a - p^(a-1)
	phi(n) = (pf1-1)*(pf2-1)*(pf3-1)*...(pfn-1); where pf1, pf2, pf2, ..., pfn - prime factors of n, as result of factorization n;
Add tests for EulerPhi.
Add "isPrimitiveRoot" and "GetPrimitiveRoot" functions, to generate primitive root g, by module p, or p^a, or 2p^a;
Add "BBSBigInteger" - implementation of Blum-Blum-Shum Random Access PRNG for BigInteger + Usage.
Add "BRAPRNG" - implementation of Bijective-Random-Access-Pseudo-Random-Number-Generator;
Add "BRAPRNG_FindIJ"-function, to find "i" and "j" by known value, and find this indexes, in the square table, if "i", and "j" is unknown, but value is known.

Add RSABigInteger - to process RSA encryption-decryption and sign-verify of bytearrays with arbitrary bytelength,
using functions:
	RSABigInteger.EncryptBytes(key, src, byPriv)
	RSABigInteger.DecryptBytes(key, src, byPub)
Add polyfills for String.repeat, and String.padStart - if this is not supported in old browsers;
Add Usages in comments.

@username1565
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here: 2b2057d#diff-cb1ace1d9097a94a63cc549ba756b5566f4d4653137bc5163b7e62ca1ea6ddd6L1023-L1030

Need to change to this:

    BigInteger.prototype.shiftRight_to_positive = function (n, bitlength) {		//equivalent >>>
        var bitlength = (typeof bitlength === 'undefined') ? 32 : bitlength;	//if undefined - false, else use this bitlength
        var res;
		if(this.isNegative() && (bitlength!==false)){							//negative -> to unsigned:
            var ones = bigInt(1).shiftLeft(bitlength).subtract(bigInt(1));		//bitlength number of one bits.
            var unsigned = ones.xor(this.abs().prev());							//ones XOR (|this|-1)
			res = unsigned.shiftRight((n<0) ? bitlength-(0-n) : n);
        }else{
			res = this.shiftRight((n<0) ? 0-n : n);
		}
		return res;
    }
    SmallInteger.prototype.shiftRight_to_positive = BigInteger.prototype.shiftRight_to_positive;

Or to optimized function.

Issue: peterolson#137

Please sign in to comment.