package cryptoimport ()// CheckGP checks whether g generates a cyclic subgroup of prime order (p-1)/2, i.e. is a quadratic residue mod p.// Also check that g is 2, 3, 4, 5, 6 or 7.//// This function is needed by some Telegram algorithms(Key generation, SRP 2FA).//// See https://core.telegram.org/mtproto/auth_key.//// See https://core.telegram.org/api/srp.func ( int, *big.Int) error {// Since g is always equal to 2, 3, 4, 5, 6 or 7, // this is easily done using quadratic reciprocity law, yielding a simple condition on p mod 4g -- namely,varboolswitch {case2:// p mod 8 = 7 for g = 2; = checkSubgroup(, 8, 7)case3:// p mod 3 = 2 for g = 3; = checkSubgroup(, 3, 2)case4:// no extra condition for g = 4 = truecase5:// p mod 5 = 1 or 4 for g = 5; = checkSubgroup(, 5, 1, 4)case6:// p mod 24 = 19 or 23 for g = 6; = checkSubgroup(, 24, 19, 23)case7:// and p mod 7 = 3, 5 or 6 for g = 7. = checkSubgroup(, 7, 3, 5, 6)default:returnerrors.Errorf("unexpected g = %d: g should be equal to 2, 3, 4, 5, 6 or 7", ) }if ! {returnerrors.New("g should be a quadratic residue mod p") }returnnil}func ( *big.Int, int64, ...int64) bool { := new(big.Int).Rem(, big.NewInt()).Int64()for , := range {if == {returntrue } }returnfalse}
The pages are generated with Goldsv0.6.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.