def _EXP(n, p): ''' .. note:: See tor-spec Section 5.1.4 for why this is an adequate replacement for checking that none of the EXP() operations produced the point at infinity. :returns: **str** result ''' ret = bindings.crypto_scalarmult(bytes(n), bytes(PublicKey(p))) bad = util.constantStrAllZero(ret) return (ret, bad)
def _scalarMult(self, base): '''Perform base**self._secret_key. Set self.is_bad if the result is all zeros. .. note:: See tor-spec Section 5.1.4 for why this is an adequate replacement for checking that none of the EXP() operations produced the point at infinity. :returns: **str** result ''' # args are: exponent, base ret = bindings.crypto_scalarmult(bytes(self._secret_key), bytes(PublicKey(base))) self.is_bad |= util.constantStrAllZero(ret) return ret
def test_constantStrAllZero_no(self): self.assertFalse( util.constantStrAllZero('\x00' * 37 + '\x01' + '\x00' * 19))
def test_constantStrAllZero_yes(self): self.assertTrue(util.constantStrAllZero('\x00' * 5446))
def test_constantStrAllZero(self, mock_cse): ret = util.constantStrAllZero('\x00') mock_cse.assert_called_once_with('\x00', '\x00') self.assertEqual(ret, 'ret')
def test_constantStrAllZero_no(self): self.assertFalse(util.constantStrAllZero('\x00'*37 + '\x01' + '\x00'*19))
def test_constantStrAllZero_yes(self): self.assertTrue(util.constantStrAllZero('\x00'*5446))