make more function params const &
This commit is contained in:
parent
3a4b761e2a
commit
1b6be03572
2 changed files with 4 additions and 4 deletions
|
@ -29,7 +29,7 @@ class DHSetup {
|
||||||
return primes;
|
return primes;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool checkGenerator(T a) {
|
bool checkGenerator(const T &a) {
|
||||||
uint64_t p = a.characteristic() - 1;
|
uint64_t p = a.characteristic() - 1;
|
||||||
for (uint64_t q : sieve_of_eratosthenes(std::sqrt(p))) {
|
for (uint64_t q : sieve_of_eratosthenes(std::sqrt(p))) {
|
||||||
if (p % q == 0 && a * (p / q) == 1) {
|
if (p % q == 0 && a * (p / q) == 1) {
|
||||||
|
|
|
@ -27,18 +27,18 @@ public:
|
||||||
return this->dh.power(dh.getGenerator(), this->secret);
|
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);
|
this->key = this->dh.power(a, this->secret);
|
||||||
}
|
}
|
||||||
|
|
||||||
T encrypt(T m) const {
|
T encrypt(const T &m) const {
|
||||||
if (this->key == T(0)) {
|
if (this->key == T(0)) {
|
||||||
throw std::logic_error("key must be set before encrypting");
|
throw std::logic_error("key must be set before encrypting");
|
||||||
}
|
}
|
||||||
return m * this->key;
|
return m * this->key;
|
||||||
}
|
}
|
||||||
|
|
||||||
T decrypt(T c) const {
|
T decrypt(const T &c) const {
|
||||||
if (this->key == T(0)) {
|
if (this->key == T(0)) {
|
||||||
throw std::logic_error("key must be set before decrypting");
|
throw std::logic_error("key must be set before decrypting");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue