Ejemplo n.º 1
0
def _generate_new(privkey=None):
    pk, sk = pysodium.crypto_sign_keypair()
    save_privkey(binascii.b2a_hex(sk))

    save_pubkey(binascii.b2a_hex(pk))

    address = binascii.b2a_hex(pysodium.crypto_generichash_blake2b_salt_personal(pk, key = "ZibbitZibbit")[12:])
    save_address(address)
Ejemplo n.º 2
0
 def generate(self,msg=MSG,ctx=None,salt=None,keysize=KEYSIZE,noncesize=NONCESIZE):
   # pysodium silently computes the hash of an empty string if input is not bytes, so check for
   # and catch that.
   if isinstance(ctx, (str,)):
     ctx = ctx.encode('utf-8')
   if isinstance(salt, (str,)):
     salt = salt.encode('utf-8')
   if (ctx is None or not isinstance(ctx,(bytes,bytearray))):
     ctx = self.__ctx
   if (salt is None or not isinstance(salt,(bytes,bytearray))):
     salt = self.__salt
   if (not isinstance(msg,(bytes,bytearray))):
     raise KafkaCryptoGeneratorError("Message is not bytes!")
   keynonce = pysodium.crypto_generichash_blake2b_salt_personal(msg,key=self.__secret,salt=salt,personal=ctx,outlen=keysize+noncesize)
   self.__salt = (int.from_bytes(self.__salt, byteorder='little', signed=False)+1).to_bytes(self.SALTSIZE, byteorder='little', signed=False)
   return (keynonce[0:keysize], keynonce[-noncesize:])
Ejemplo n.º 3
0
    def test_crypto_blake2b(self):
        message   = binascii.unhexlify(b'54686520717569636b2062726f776e20666f78206a756d7073206f76657220746865206c617a7920646f67')
        key       = binascii.unhexlify(b'000102030405060708090a0b0c0d0e0f')

        # Test vectors generated from the blake2b reference implementation
        self.assertEqual(pysodium.crypto_generichash_blake2b_salt_personal(message, key      = key),      binascii.unhexlify(b'0f44eda51dba98442425d486b89962647c1a6e0e8b98a93e7090bf849a5156da'))
        self.assertEqual(pysodium.crypto_generichash_blake2b_salt_personal(message, personal = key),      binascii.unhexlify(b'8c68aecca4b50e91aebaf8c53bde15b68c01b13d571a772fcb8b432affa52a7c'))
        self.assertEqual(pysodium.crypto_generichash_blake2b_salt_personal(message, salt     = key),      binascii.unhexlify(b'43b7feaa91019d0d5b492357fb923211af827d6126af28ccc1874e70bc2177f8'))
        self.assertEqual(pysodium.crypto_generichash_blake2b_salt_personal(message, personal = key[0:8]), binascii.unhexlify(b'31353589b3f179cda74387fbe1deca94f004661f05cde2295a16c0a8d8ead79b'))
        self.assertEqual(pysodium.crypto_generichash_blake2b_salt_personal(message, salt     = key[0:8]), binascii.unhexlify(b'11c29bf7b91b8500a463f27e215dc83afdb71ed5e959f0847e339769c4835fc7'))
        self.assertEqual(pysodium.crypto_generichash_blake2b_salt_personal(message, personal = key, key = key), binascii.unhexlify(b'5a0b3db4bf2dab71485211447fc2014391228cc6c1acd2f3031050a9a32ca407'))
Ejemplo n.º 4
0
    def test_crypto_blake2b(self):
        message   = binascii.unhexlify(b'54686520717569636b2062726f776e20666f78206a756d7073206f76657220746865206c617a7920646f67')
        key       = binascii.unhexlify(b'000102030405060708090a0b0c0d0e0f')

        # Test vectors generated from the blake2b reference implementation
        self.assertEqual(pysodium.crypto_generichash_blake2b_salt_personal(message, key      = key),      binascii.unhexlify(b'0f44eda51dba98442425d486b89962647c1a6e0e8b98a93e7090bf849a5156da'))
        self.assertEqual(pysodium.crypto_generichash_blake2b_salt_personal(message, personal = key),      binascii.unhexlify(b'8c68aecca4b50e91aebaf8c53bde15b68c01b13d571a772fcb8b432affa52a7c'))
        self.assertEqual(pysodium.crypto_generichash_blake2b_salt_personal(message, salt     = key),      binascii.unhexlify(b'43b7feaa91019d0d5b492357fb923211af827d6126af28ccc1874e70bc2177f8'))
        self.assertEqual(pysodium.crypto_generichash_blake2b_salt_personal(message, personal = key[0:8]), binascii.unhexlify(b'31353589b3f179cda74387fbe1deca94f004661f05cde2295a16c0a8d8ead79b'))
        self.assertEqual(pysodium.crypto_generichash_blake2b_salt_personal(message, salt     = key[0:8]), binascii.unhexlify(b'11c29bf7b91b8500a463f27e215dc83afdb71ed5e959f0847e339769c4835fc7'))
        self.assertEqual(pysodium.crypto_generichash_blake2b_salt_personal(message, personal = key, key = key), binascii.unhexlify(b'5a0b3db4bf2dab71485211447fc2014391228cc6c1acd2f3031050a9a32ca407'))
Ejemplo n.º 5
0
def main():
    if len(sys.argv) == 2:
        path = sys.argv[1]
    else:
        path = os.path.join(sys.argv[1], "node" + sys.argv[2])
    dump_path = os.path.join(path, "privkey")
    pk, sk = pysodium.crypto_sign_keypair()
    f = open(dump_path, "w")
    f.write(binascii.b2a_hex(sk))
    f.close()
    auth_path = os.path.join(sys.argv[1], "authorities")
    authority = binascii.b2a_hex(
        pysodium.crypto_generichash_blake2b_salt_personal(
            pk, key="CryptapeCryptape")[12:])
    auth_file = open(auth_path, "a")
    auth_file.write("0x" + authority + "\n")
    auth_file.close()
Ejemplo n.º 6
0
def _blake2b(seed):
    hashed = pysodium.crypto_generichash_blake2b_salt_personal(
        seed, key="ZibbitZibbit")
    return hashed