private bool _MakeTest(OmgNum testBase) { OmgNum numDec = (new OmgNum(m_tested)).Dec(); OmgNum tested = OmgOp.Pow(testBase, m_initialTested, m_tested); OmgNum iterationsLeft = new OmgNum(m_powerOfTwo); try { if (OmgOp.Equal(tested, OmgNum.GetConst(1)) || OmgOp.Equal(tested, numDec)) { return(true); } while (!iterationsLeft.IsZero()) { iterationsLeft.Dec(); var nwTested = OmgOp.Multiply(tested, tested, m_tested); tested.Release(); tested = nwTested; if (OmgOp.Equal(tested, numDec)) { return(true); } } return(false); } finally { numDec.Release(); tested.Release(); iterationsLeft.Release(); } }
public SignaureKey GenerateSignature(int keyByteLength) { int componentLength = keyByteLength * 8 / 2; OmgNum p = m_primeSource.GeneratePrime(componentLength); OmgNum q = m_primeSource.GeneratePrime(componentLength); OmgNum n = OmgOp.Multiply(p, q); OmgNum carmN = _Carmichael(p.Dec(), q.Dec()); OmgNum e = _SelectRandomExponent(carmN, out OmgNum d); p.Release(); p.Release(); return(new SignaureKey { cert = new SignCertificate { N = n.Copy(), D = d }, secret = new SignSecret() { N = n, E = e } }); }