Exemplo n.º 1
0
 def test_sign(self):
     random = np.random.RandomState(seed=1)
     for i in range(10):
         length = random.randint(1, 4096)
         secret_key = bytes(random.randint(0, 256, 32, dtype=np.uint8))
         msg = bytes(random.randint(0, 256, length, dtype=np.uint8))
         public_key = monocypher.public_key_compute(secret_key)
         sig = monocypher.signature_sign(secret_key, msg)
         self.assertTrue(monocypher.signature_check(sig, public_key, msg))
         self.assertFalse(monocypher.signature_check(sig, public_key, msg + b'0'))
         sig2 = sig[:10] + bytes([sig[10] + 1]) + sig[11:]
         self.assertFalse(monocypher.signature_check(sig2, public_key, msg))
Exemplo n.º 2
0
 def test_sign(self):
     random = np.random.RandomState(seed=1)
     for i in range(10):
         length = random.randint(1, 4096)
         secret_key = bytes(random.randint(0, 256, 32, dtype=np.uint8))
         msg = bytes(random.randint(0, 256, length, dtype=np.uint8))
         public_key = monocypher.compute_signing_public_key(secret_key)
         sig = monocypher.signature_sign(secret_key, msg)
         self.assertTrue(monocypher.signature_check(sig, public_key, msg))
         self.assertFalse(
             monocypher.signature_check(sig, public_key, msg + b'0'))
         sig2 = sig[:10] + bytes([sig[10] + 1]) + sig[11:]
         self.assertFalse(monocypher.signature_check(sig2, public_key, msg))
Exemplo n.º 3
0
 def append_encrypted(self,
                      tag,
                      data,
                      signing_key,
                      encryption_key,
                      nonce,
                      associated_data=None,
                      compress=None):
     flags = 0
     if bool(compress):
         flags, data = _maybe_compress(data)
     flags |= FLAG_ENCRYPT
     signature = monocypher.signature_sign(signing_key, data)
     mac, data = monocypher.lock(encryption_key, nonce, data,
                                 associated_data)
     log.info('signature = %r', binascii.hexlify(signature))
     log.info('mac       = %r', binascii.hexlify(mac))
     pos = self._append(tag, flags, data)
     self._append(TAG_ENCRYPTION, 0, mac + signature)
     return pos
Exemplo n.º 4
0
 def signature_end(self):
     s = monocypher.signature_sign(self._signature['key'],
                                   self._signature['data'])
     self.append(TAG_SIGNATURE_END, s)