(self, key: int)
| 227 | return hex(public_key)[2:] |
| 228 | |
| 229 | def is_valid_public_key(self, key: int) -> bool: |
| 230 | # check if the other public key is valid based on NIST SP800-56 |
| 231 | return ( |
| 232 | 2 <= key <= self.prime - 2 |
| 233 | and pow(key, (self.prime - 1) // 2, self.prime) == 1 |
| 234 | ) |
| 235 | |
| 236 | def generate_shared_key(self, other_key_str: str) -> str: |
| 237 | other_key = int(other_key_str, base=16) |