make more function params const &

This commit is contained in:
jacekpoz 2024-05-10 22:08:48 +02:00
parent 3a4b761e2a
commit 1b6be03572
Signed by: poz
SSH key fingerprint: SHA256:JyLeVWE4bF3tDnFeUpUaJsPsNlJyBldDGV/dIKSLyN8
2 changed files with 4 additions and 4 deletions

View file

@ -29,7 +29,7 @@ class DHSetup {
return primes;
}
bool checkGenerator(T a) {
bool checkGenerator(const T &a) {
uint64_t p = a.characteristic() - 1;
for (uint64_t q : sieve_of_eratosthenes(std::sqrt(p))) {
if (p % q == 0 && a * (p / q) == 1) {

View file

@ -27,18 +27,18 @@ public:
return this->dh.power(dh.getGenerator(), this->secret);
}
void setKey(T a) {
void setKey(const T &a) {
this->key = this->dh.power(a, this->secret);
}
T encrypt(T m) const {
T encrypt(const T &m) const {
if (this->key == T(0)) {
throw std::logic_error("key must be set before encrypting");
}
return m * this->key;
}
T decrypt(T c) const {
T decrypt(const T &c) const {
if (this->key == T(0)) {
throw std::logic_error("key must be set before decrypting");
}