NRDigestVerifier::NRDigestVerifier(BufferedTransformation &bt) { BERSequenceDecoder seq(bt); p.BERDecode(seq); q.BERDecode(seq); g.BERDecode(seq); y.BERDecode(seq); gpc.Precompute(p, g, ExponentBitLength(), 1); ypc.Precompute(p, y, ExponentBitLength(), 1); }
NRDigestSigner::NRDigestSigner(RandomNumberGenerator &rng, unsigned int pbits) { PrimeAndGenerator pg(1, rng, pbits, 2*DiscreteLogWorkFactor(pbits)); p = pg.Prime(); q = pg.SubPrime(); g = pg.Generator(); x.Randomize(rng, 2, q-2, Integer::ANY); gpc.Precompute(p, g, ExponentBitLength(), 1); y = gpc.Exponentiate(x); ypc.Precompute(p, y, ExponentBitLength(), 1); }
void DH::GenerateKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const { Integer x(rng, ExponentBitLength()); Integer y = gpc.Exponentiate(x); x.Encode(privateKey, PrivateKeyLength()); y.Encode(publicKey, PublicKeyLength()); }
DH::DH(BufferedTransformation &bt) { BERSequenceDecoder seq(bt); p.BERDecode(seq); g.BERDecode(seq); gpc.Precompute(p, g, ExponentBitLength(), 1); }
DH::DH(RandomNumberGenerator &rng, unsigned int pbits) { PrimeAndGenerator pg(1, rng, pbits); p = pg.Prime(); g = pg.Generator(); gpc.Precompute(p, g, ExponentBitLength(), 1); }
ElGamalDecryptor::ElGamalDecryptor(RandomNumberGenerator &rng, const Integer &pIn, const Integer &gIn) { m_p = pIn; m_g = gIn; m_x.Randomize(rng, ExponentBitLength()); m_gpc.SetModulusAndBase(m_p, m_g); m_y = m_gpc.Exponentiate(m_x); m_ypc.SetModulusAndBase(m_p, m_y); }
ElGamalDecryptor::ElGamalDecryptor(RandomNumberGenerator &rng, unsigned int pbits) { PrimeAndGenerator pg(1, rng, pbits); m_p = pg.Prime(); m_g = pg.Generator(); m_x.Randomize(rng, ExponentBitLength()); m_gpc.SetModulusAndBase(m_p, m_g); m_y = m_gpc.Exponentiate(m_x); m_ypc.SetModulusAndBase(m_p, m_y); }
void ElGamalEncryptor::Encrypt(RandomNumberGenerator &rng, const byte *plainText, unsigned int plainTextLength, byte *cipherText) { assert(plainTextLength <= MaxPlainTextLength()); SecByteBlock block(modulusLen-1); rng.GetBlock(block, modulusLen-2-plainTextLength); memcpy(block+modulusLen-2-plainTextLength, plainText, plainTextLength); block[modulusLen-2] = plainTextLength; Integer m(block, modulusLen-1); Integer a,b; RawEncrypt(Integer(rng, ExponentBitLength()), m, a, b); a.Encode(cipherText, modulusLen); b.Encode(cipherText+modulusLen, modulusLen); }
void ElGamalEncryptor::Precompute(unsigned int precomputationStorage) { gpc.Precompute(p, g, ExponentBitLength(), precomputationStorage); ypc.Precompute(p, y, ExponentBitLength(), precomputationStorage); }
ElGamalEncryptor::ElGamalEncryptor(const Integer &p, const Integer &g, const Integer &y) : p(p), g(g), y(y), modulusLen(p.ByteCount()), gpc(p, g, ExponentBitLength(), 1), ypc(p, y, ExponentBitLength(), 1) { }
DH::DH(const Integer &p, const Integer &g) : p(p), g(g), gpc(p, g, ExponentBitLength(), 1) { }
void DH::Precompute(unsigned int precomputationStorage) { gpc.Precompute(p, g, ExponentBitLength(), precomputationStorage); }
void ElGamalEncryptor::Precompute(unsigned int precomputationStorage) { m_gpc.Precompute(ExponentBitLength(), precomputationStorage); m_ypc.Precompute(ExponentBitLength(), precomputationStorage); }
void NRDigestVerifier::Precompute(unsigned int precomputationStorage) { m_gpc.Precompute(ExponentBitLength(), precomputationStorage); m_ypc.Precompute(ExponentBitLength(), precomputationStorage); }
void NRDigestVerifier::Precompute(unsigned int precomputationStorage) { gpc.Precompute(p, g, ExponentBitLength(), precomputationStorage); ypc.Precompute(p, y, ExponentBitLength(), precomputationStorage); }