Example #1
0
 def test_correctness_for_primes(self):
   for prime in prime_sieve.SIEVE:
     self.assertEqual(integer.uint_to_bytes(prime), _alt_integer.uint_to_bytes_naive(prime),
                      "Boom %d" % prime)
     self.assertEqual(_alt_integer.uint_to_bytes_array_based(prime),
                      _alt_integer.uint_to_bytes_naive(prime),
                      "Boom %d" % prime)
     self.assertEqual(_alt_integer.uint_to_bytes_pycrypto(prime),
                      _alt_integer.uint_to_bytes_naive(prime),
                      "Boom %d" % prime)
Example #2
0
 def test_correctness_for_primes(self):
   for prime in SIEVE:
     self.assertEqual(uint_to_bytes(prime), uint_to_bytes_naive(prime),
                      "Boom %d" % prime)
     self.assertEqual(uint_to_bytes_array_based(prime),
                      uint_to_bytes_naive(prime),
                      "Boom %d" % prime)
     self.assertEqual(uint_to_bytes_pycrypto(prime),
                      uint_to_bytes_naive(prime),
                      "Boom %d" % prime)
Example #3
0
  def test_zero(self):
    self.assertEqual(uint_to_bytes(0), b('\x00'))
    self.assertEqual(uint_to_bytes(0, 4), b('\x00') * 4)
    self.assertEqual(uint_to_bytes(0, 7), b('\x00') * 7)
    self.assertEqual(uint_to_bytes(0, chunk_size=1), b('\x00'))
    self.assertEqual(uint_to_bytes(0, chunk_size=4), b('\x00') * 4)
    self.assertEqual(uint_to_bytes(0, chunk_size=7), b('\x00') * 7)

    self.assertEqual(uint_to_bytes_naive(0), b('\x00'))
    self.assertEqual(uint_to_bytes_naive(0, 4), b('\x00') * 4)
    self.assertEqual(uint_to_bytes_naive(0, 7), b('\x00') * 7)

    self.assertEqual(uint_to_bytes_simple(0), b('\x00'))
Example #4
0
  def test_zero(self):
    self.assertEqual(integer.uint_to_bytes(0), b("\x00"))
    self.assertEqual(integer.uint_to_bytes(0, 4), b("\x00") * 4)
    self.assertEqual(integer.uint_to_bytes(0, 7), b("\x00") * 7)
    self.assertEqual(integer.uint_to_bytes(0, chunk_size=1), b("\x00"))
    self.assertEqual(integer.uint_to_bytes(0, chunk_size=4), b("\x00") * 4)
    self.assertEqual(integer.uint_to_bytes(0, chunk_size=7), b("\x00") * 7)

    self.assertEqual(_alt_integer.uint_to_bytes_naive(0), b("\x00"))
    self.assertEqual(_alt_integer.uint_to_bytes_naive(0, 4), b("\x00") * 4)
    self.assertEqual(_alt_integer.uint_to_bytes_naive(0, 7), b("\x00") * 7)

    self.assertEqual(_alt_integer.uint_to_bytes_simple(0), b("\x00"))
Example #5
0
  def test_correctness(self):
    self.assertEqual(uint_to_bytes(0xeeeeffff),
                     b('\xee\xee\xff\xff'))
    self.assertEqual(uint_to_bytes(0xeeeeff),
                     b('\xee\xee\xff'))

    self.assertEqual(uint_to_bytes_naive(0xeeeeffff),
                     b('\xee\xee\xff\xff'))
    self.assertEqual(uint_to_bytes_naive(0xeeeeff),
                     b('\xee\xee\xff'))

    self.assertEqual(uint_to_bytes_simple(0xeeeeffff),
                     b('\xee\xee\xff\xff'))
    self.assertEqual(uint_to_bytes_simple(0xeeeeff),
                     b('\xee\xee\xff'))
Example #6
0
  def test_correctness(self):
    self.assertEqual(integer.uint_to_bytes(0xeeeeffff),
                     b("\xee\xee\xff\xff"))
    self.assertEqual(integer.uint_to_bytes(0xeeeeff),
                     b("\xee\xee\xff"))

    self.assertEqual(_alt_integer.uint_to_bytes_naive(0xeeeeffff),
                     b("\xee\xee\xff\xff"))
    self.assertEqual(_alt_integer.uint_to_bytes_naive(0xeeeeff),
                     b("\xee\xee\xff"))

    self.assertEqual(_alt_integer.uint_to_bytes_simple(0xeeeeffff),
                     b("\xee\xee\xff\xff"))
    self.assertEqual(_alt_integer.uint_to_bytes_simple(0xeeeeff),
                     b("\xee\xee\xff"))
Example #7
0
  def test_zero(self):
    self.assertEqual(uint_to_bytes(0, 4), b('\x00') * 4)
    self.assertEqual(uint_to_bytes_array_based(0, 4), b('\x00') * 4)
    self.assertEqual(uint_to_bytes_naive(0, 4), b('\x00') * 4)
    self.assertEqual(uint_to_bytes_naive_array_based(0, 4), b('\x00') * 4)
    self.assertEqual(uint_to_bytes_pycrypto(0, 4), b('\x00') * 4)

    self.assertEqual(uint_to_bytes(0, 7), b('\x00') * 7)
    self.assertEqual(uint_to_bytes_naive(0, 7), b('\x00') * 7)
    self.assertEqual(uint_to_bytes_array_based(0, 7), b('\x00') * 7)
    self.assertEqual(uint_to_bytes_naive_array_based(0, 7), b('\x00') * 7)
    self.assertEqual(uint_to_bytes_pycrypto(0, 7), b('\x00') * 7)

    self.assertEqual(uint_to_bytes(0), b('\x00'))
    self.assertEqual(uint_to_bytes_naive(0), b('\x00'))
    self.assertEqual(uint_to_bytes_array_based(0), b('\x00'))
    self.assertEqual(uint_to_bytes_naive_array_based(0), b('\x00'))
    self.assertEqual(uint_to_bytes_pycrypto(0), b('\x00'))
Example #8
0
  def test_zero(self):
    self.assertEqual(integer.uint_to_bytes(0, 4), b("\x00") * 4)
    self.assertEqual(_alt_integer.uint_to_bytes_array_based(0, 4), b("\x00") * 4)
    self.assertEqual(_alt_integer.uint_to_bytes_naive(0, 4), b("\x00") * 4)
    self.assertEqual(_alt_integer.uint_to_bytes_naive_array_based(0, 4), b("\x00") * 4)
    self.assertEqual(_alt_integer.uint_to_bytes_pycrypto(0, 4), b("\x00") * 4)

    self.assertEqual(integer.uint_to_bytes(0, 7), b("\x00") * 7)
    self.assertEqual(_alt_integer.uint_to_bytes_naive(0, 7), b("\x00") * 7)
    self.assertEqual(_alt_integer.uint_to_bytes_array_based(0, 7), b("\x00") * 7)
    self.assertEqual(_alt_integer.uint_to_bytes_naive_array_based(0, 7), b("\x00") * 7)
    self.assertEqual(_alt_integer.uint_to_bytes_pycrypto(0, 7), b("\x00") * 7)

    self.assertEqual(integer.uint_to_bytes(0), b("\x00"))
    self.assertEqual(_alt_integer.uint_to_bytes_naive(0), b("\x00"))
    self.assertEqual(_alt_integer.uint_to_bytes_array_based(0), b("\x00"))
    self.assertEqual(_alt_integer.uint_to_bytes_naive_array_based(0), b("\x00"))
    self.assertEqual(_alt_integer.uint_to_bytes_pycrypto(0), b("\x00"))
Example #9
0
  def test_accuracy(self):
    self.assertEqual(uint_to_bytes(123456789), b('\x07[\xcd\x15'))
    self.assertEqual(uint_to_bytes_pycrypto(123456789),
                     b('\x07[\xcd\x15'))
    self.assertEqual(uint_to_bytes_array_based(123456789),
                     b('\x07[\xcd\x15'))
    self.assertEqual(uint_to_bytes_naive(123456789), b('\x07[\xcd\x15'))
    self.assertEqual(uint_to_bytes_naive_array_based(123456789),
                     b('\x07[\xcd\x15'))

    self.assertEqual(uint_to_bytes(long_value),
                     expected_bytes)
    self.assertEqual(uint_to_bytes_pycrypto(long_value),
                     expected_bytes)
    self.assertEqual(uint_to_bytes_array_based(long_value),
                     expected_bytes)
    self.assertEqual(uint_to_bytes_naive(long_value),
                     expected_bytes)
    self.assertEqual(uint_to_bytes_naive_array_based(long_value),
                     expected_bytes)
Example #10
0
 def test_correctness_against_base_implementation(self):
   # Slow test.
   values = [
     1 << 512,
     1 << 8192,
     1 << 77,
     ]
   for value in values:
     self.assertEqual(uint_to_bytes(value),
                      uint_to_bytes_naive(value),
                      "Boom %d" % value)
Example #11
0
  def test_accuracy(self):
    self.assertEqual(integer.uint_to_bytes(123456789), b("\x07[\xcd\x15"))
    self.assertEqual(_alt_integer.uint_to_bytes_pycrypto(123456789),
                     b("\x07[\xcd\x15"))
    self.assertEqual(_alt_integer.uint_to_bytes_array_based(123456789),
                     b("\x07[\xcd\x15"))
    self.assertEqual(_alt_integer.uint_to_bytes_naive(123456789), b("\x07[\xcd\x15"))
    self.assertEqual(_alt_integer.uint_to_bytes_naive_array_based(123456789),
                     b("\x07[\xcd\x15"))

    self.assertEqual(integer.uint_to_bytes(LONG_VALUE),
                     EXPECTED_BYTES)
    self.assertEqual(_alt_integer.uint_to_bytes_pycrypto(LONG_VALUE),
                     EXPECTED_BYTES)
    self.assertEqual(_alt_integer.uint_to_bytes_array_based(LONG_VALUE),
                     EXPECTED_BYTES)
    self.assertEqual(_alt_integer.uint_to_bytes_naive(LONG_VALUE),
                     EXPECTED_BYTES)
    self.assertEqual(_alt_integer.uint_to_bytes_naive_array_based(LONG_VALUE),
                     EXPECTED_BYTES)
Example #12
0
 def test_correctness_against_base_implementation(self):
   # Slow test.
   values = [
     1 << 512,
     1 << 8192,
     1 << 77,
     ]
   for value in values:
     self.assertEqual(integer.uint_to_bytes(value),
                      _alt_integer.uint_to_bytes_naive(value),
                      "Boom %d" % value)
Example #13
0
  def test_chunk_size(self):
    self.assertEqual(uint_to_bytes(long_value,
                                   long_value_blocksize),
                     expected_blocksize_bytes)
    self.assertEqual(uint_to_bytes_pycrypto(long_value,
                                            long_value_blocksize),
                     expected_blocksize_bytes)
    self.assertEqual(uint_to_bytes_array_based(long_value,
                                               long_value_blocksize),
                     expected_blocksize_bytes)
    self.assertEqual(uint_to_bytes_naive(long_value,
                                         long_value_blocksize),
                     expected_blocksize_bytes)
    self.assertEqual(uint_to_bytes_naive_array_based(long_value,
                                                     long_value_blocksize),
                     expected_blocksize_bytes)

    self.assertEqual(uint_to_bytes(123456789, 6),
                     b('\x00\x00\x07[\xcd\x15'))
    self.assertEqual(uint_to_bytes(123456789, 7),
                     b('\x00\x00\x00\x07[\xcd\x15'))

    self.assertEqual(uint_to_bytes_pycrypto(123456789, 6),
                     b('\x00\x00\x07[\xcd\x15'))
    self.assertEqual(uint_to_bytes_pycrypto(123456789, 7),
                     b('\x00\x00\x00\x07[\xcd\x15'))

    self.assertEqual(uint_to_bytes_array_based(123456789, 6),
                     b('\x00\x00\x07[\xcd\x15'))
    self.assertEqual(uint_to_bytes_array_based(123456789, 7),
                     b('\x00\x00\x00\x07[\xcd\x15'))

    self.assertEqual(uint_to_bytes_naive(123456789, 6),
                     b('\x00\x00\x07[\xcd\x15'))
    self.assertEqual(uint_to_bytes_naive(123456789, 7),
                     b('\x00\x00\x00\x07[\xcd\x15'))

    self.assertEqual(uint_to_bytes_naive_array_based(123456789, 6),
                     b('\x00\x00\x07[\xcd\x15'))
    self.assertEqual(uint_to_bytes_naive_array_based(123456789, 7),
                     b('\x00\x00\x00\x07[\xcd\x15'))
Example #14
0
  def test_chunk_size(self):
    self.assertEqual(integer.uint_to_bytes(LONG_VALUE,
                                   LONG_VALUE_BLOCKSIZE),
                     EXPECTED_BLOCKSIZE_BYTES)
    self.assertEqual(_alt_integer.uint_to_bytes_pycrypto(LONG_VALUE,
                                            LONG_VALUE_BLOCKSIZE),
                     EXPECTED_BLOCKSIZE_BYTES)
    self.assertEqual(_alt_integer.uint_to_bytes_array_based(LONG_VALUE,
                                               LONG_VALUE_BLOCKSIZE),
                     EXPECTED_BLOCKSIZE_BYTES)
    self.assertEqual(_alt_integer.uint_to_bytes_naive(LONG_VALUE,
                                         LONG_VALUE_BLOCKSIZE),
                     EXPECTED_BLOCKSIZE_BYTES)
    self.assertEqual(_alt_integer.uint_to_bytes_naive_array_based(LONG_VALUE,
                                                     LONG_VALUE_BLOCKSIZE),
                     EXPECTED_BLOCKSIZE_BYTES)

    self.assertEqual(integer.uint_to_bytes(123456789, 6),
                     b("\x00\x00\x07[\xcd\x15"))
    self.assertEqual(integer.uint_to_bytes(123456789, 7),
                     b("\x00\x00\x00\x07[\xcd\x15"))

    self.assertEqual(_alt_integer.uint_to_bytes_pycrypto(123456789, 6),
                     b("\x00\x00\x07[\xcd\x15"))
    self.assertEqual(_alt_integer.uint_to_bytes_pycrypto(123456789, 7),
                     b("\x00\x00\x00\x07[\xcd\x15"))

    self.assertEqual(_alt_integer.uint_to_bytes_array_based(123456789, 6),
                     b("\x00\x00\x07[\xcd\x15"))
    self.assertEqual(_alt_integer.uint_to_bytes_array_based(123456789, 7),
                     b("\x00\x00\x00\x07[\xcd\x15"))

    self.assertEqual(_alt_integer.uint_to_bytes_naive(123456789, 6),
                     b("\x00\x00\x07[\xcd\x15"))
    self.assertEqual(_alt_integer.uint_to_bytes_naive(123456789, 7),
                     b("\x00\x00\x00\x07[\xcd\x15"))

    self.assertEqual(_alt_integer.uint_to_bytes_naive_array_based(123456789, 6),
                     b("\x00\x00\x07[\xcd\x15"))
    self.assertEqual(_alt_integer.uint_to_bytes_naive_array_based(123456789, 7),
                     b("\x00\x00\x00\x07[\xcd\x15"))
 def test_correctness_against_base_implementation(self):
   # Slow test.
   values = [
     1 << 512,
     1 << 8192,
     1 << 77,
     ]
   for value in values:
     self.assertEqual(integer.uint_to_bytes(value), _alt_integer.uint_to_bytes_naive(value),
                      "Boom %d" % value)
     self.assertEqual(_alt_integer.uint_to_bytes_array_based(value),
                      _alt_integer.uint_to_bytes_naive(value),
                      "Boom %d" % value)
     self.assertEqual(integer.uint_to_bytes(value),
                      _alt_integer.uint_to_bytes_naive_array_based(value),
                      "Boom %d" % value)
     self.assertEqual(_alt_integer.uint_to_bytes_pycrypto(value),
                      _alt_integer.uint_to_bytes_naive(value),
                      "Boom %d" % value)
     self.assertEqual(integer.bytes_to_uint(integer.uint_to_bytes(value)),
                      value,
                      "Boom %d" % value)
Example #16
0
 def test_correctness_for_primes(self):
   for prime in SIEVE:
     self.assertEqual(uint_to_bytes(prime),
                      uint_to_bytes_naive(prime),
                      "Boom %d" % prime)