def test_crypto_secretstream_xchacha20poly1305_pull_multiple(self): if not pysodium.sodium_version_check(1, 0, 15): return key = pysodium.crypto_secretstream_xchacha20poly1305_keygen() state, header = pysodium.crypto_secretstream_xchacha20poly1305_init_push( key) ciphertext = pysodium.crypto_secretstream_xchacha20poly1305_push( state, b"Correct Horse Battery Staple", None, 0) ciphertext2 = pysodium.crypto_secretstream_xchacha20poly1305_push( state, b"howdy", None, pysodium.crypto_secretstream_xchacha20poly1305_TAG_FINAL) # Verify decryption state2 = pysodium.crypto_secretstream_xchacha20poly1305_init_pull( header, key) msg, tag = pysodium.crypto_secretstream_xchacha20poly1305_pull( state2, ciphertext, None) msg2, tag2 = pysodium.crypto_secretstream_xchacha20poly1305_pull( state2, ciphertext2, None) self.assertEqual(msg, b"Correct Horse Battery Staple") self.assertEqual(tag, 0) self.assertEqual(msg2, b"howdy") self.assertEqual( tag2, pysodium.crypto_secretstream_xchacha20poly1305_TAG_FINAL)
def test_crypto_core_ristretto255_scalar_complement(self): if not pysodium.sodium_version_check(1, 0, 18): return x = pysodium.crypto_core_ristretto255_scalar_random() x_ = pysodium.crypto_core_ristretto255_scalar_complement(x) # x + complement(x) = 1 mod L one = pysodium.crypto_core_ristretto255_scalar_add(x,x_) self.assertEqual(one,b'\x01'+b"\x00"*31)
def test_crypto_pwhash_storage(self): if not pysodium.sodium_version_check(1, 0, 9): return pw = "Correct Horse Battery Staple" pstr = pysodium.crypto_pwhash_str( pw, pysodium.crypto_pwhash_OPSLIMIT_INTERACTIVE, pysodium.crypto_pwhash_MEMLIMIT_INTERACTIVE) self.assertTrue(pysodium.crypto_pwhash_str_verify(pstr, pw))
def test_crypto_core_ristretto255_scalar_negate(self): if not pysodium.sodium_version_check(1, 0, 18): return s = pysodium.crypto_core_ristretto255_scalar_random() r = pysodium.crypto_core_ristretto255_scalar_negate(s) # s + neg(s) = 0 mod L s_r = pysodium.crypto_core_ristretto255_scalar_add(s,r) self.assertEqual(s_r,b"\x00"*32)
def test_crypto_secretstream_xchacha20poly1305_rekey(self): if not pysodium.sodium_version_check(1, 0, 15): return key = pysodium.crypto_secretstream_xchacha20poly1305_keygen() state, header = pysodium.crypto_secretstream_xchacha20poly1305_init_push( key) # Encrypt two messages with intermediate re-key ciphertext = pysodium.crypto_secretstream_xchacha20poly1305_push( state, b"Correct Horse Battery Staple", None, 0) pysodium.crypto_secretstream_xchacha20poly1305_rekey(state) ciphertext2 = pysodium.crypto_secretstream_xchacha20poly1305_push( state, b"howdy", None, pysodium.crypto_secretstream_xchacha20poly1305_TAG_FINAL) # Verify by decrypting them state2 = pysodium.crypto_secretstream_xchacha20poly1305_init_pull( header, key) msg, tag = pysodium.crypto_secretstream_xchacha20poly1305_pull( state2, ciphertext, None) pysodium.crypto_secretstream_xchacha20poly1305_rekey(state2) msg2, tag2 = pysodium.crypto_secretstream_xchacha20poly1305_pull( state2, ciphertext2, None) self.assertEqual(msg, b"Correct Horse Battery Staple") self.assertEqual(tag, 0) self.assertEqual(msg2, b"howdy") self.assertEqual( tag2, pysodium.crypto_secretstream_xchacha20poly1305_TAG_FINAL)
def test_crypto_secretstream_xchacha20poly1305_pull_corrupted(self): if not pysodium.sodium_version_check(1, 0, 15): return key = pysodium.crypto_secretstream_xchacha20poly1305_keygen() state, header = pysodium.crypto_secretstream_xchacha20poly1305_init_push( key) ad = 'additional data' ciphertext = pysodium.crypto_secretstream_xchacha20poly1305_push( state, b"Correct Horse Battery Staple", ad, 0) # Verify error is raised if cypher text is changed state2 = pysodium.crypto_secretstream_xchacha20poly1305_init_pull( header, key) self.assertRaises(ValueError, pysodium.crypto_secretstream_xchacha20poly1305_pull, state2, ciphertext + 'this is a corruption'.encode(), ad) # Verify error is raised if additional data is changed ad2 = 'this is not the same' state2 = pysodium.crypto_secretstream_xchacha20poly1305_init_pull( header, key) self.assertRaises(ValueError, pysodium.crypto_secretstream_xchacha20poly1305_pull, state2, ciphertext, ad2)
def test_crypto_secretstream_xchacha20poly1305_init_pull(self): if not pysodium.sodium_version_check(1, 0, 15): return key = pysodium.crypto_secretstream_xchacha20poly1305_keygen() state, header = pysodium.crypto_secretstream_xchacha20poly1305_init_push( key) state2 = pysodium.crypto_secretstream_xchacha20poly1305_init_pull( header, key)
def test_crypto_secretstream_xchacha20poly1305_push(self): if not pysodium.sodium_version_check(1, 0, 15): return key = pysodium.crypto_secretstream_xchacha20poly1305_keygen() state, header = pysodium.crypto_secretstream_xchacha20poly1305_init_push( key) ciphertext = pysodium.crypto_secretstream_xchacha20poly1305_push( state, b"howdy", None, 0)
def test_crypto_core_ristretto255_scalar_invert(self): if not pysodium.sodium_version_check(1, 0, 18): return s = pysodium.crypto_core_ristretto255_scalar_random() r = pysodium.crypto_core_ristretto255_scalar_invert(s) p = pysodium.crypto_scalarmult_ristretto255_base(pysodium.crypto_core_ristretto255_scalar_random()) q = pysodium.crypto_scalarmult_ristretto255(s, p) p_ = pysodium.crypto_scalarmult_ristretto255(r, q) self.assertEqual(p,p_)
def test_crypto_core_ristretto255_add_sub(self): if not pysodium.sodium_version_check(1, 0, 18): return p = pysodium.crypto_core_ristretto255_random() q = pysodium.crypto_core_ristretto255_random() p_q = pysodium.crypto_core_ristretto255_add(p, q) r = pysodium.crypto_core_ristretto255_sub(p_q,q) self.assertEqual(p,r)
def test_crypto_scalarmult_ristretto255(self): if not pysodium.sodium_version_check(1, 0, 18): return n = pysodium.crypto_scalarmult_ristretto255_base( pysodium.crypto_core_ristretto255_scalar_random()) p = pysodium.crypto_scalarmult_ristretto255_base( pysodium.crypto_core_ristretto255_scalar_random()) r = pysodium.crypto_scalarmult_ristretto255(n, p) pysodium.crypto_core_ristretto255_is_valid_point(r)
def test_crypto_secretstream_xchacha20poly1305_pull_changed_ad(self): if not pysodium.sodium_version_check(1, 0, 15): return key = pysodium.crypto_secretstream_xchacha20poly1305_keygen() state, header = pysodium.crypto_secretstream_xchacha20poly1305_init_push(key) ciphertext = pysodium.crypto_secretstream_xchacha20poly1305_push(state, b"howdy", b"some data", pysodium.crypto_secretstream_xchacha20poly1305_TAG_FINAL) state2 = pysodium.crypto_secretstream_xchacha20poly1305_init_pull(header, key) self.assertRaises(ValueError, pysodium.crypto_secretstream_xchacha20poly1305_pull, state2, ciphertext, b"different data")
def test_aead_xchacha20poly1305_ietf(self): if not pysodium.sodium_version_check(1, 0, 12): return key = binascii.unhexlify(b"4290bcb154173531f314af57f3be3b5006da371ece272afa1b5dbdd1100a1007") input_ = binascii.unhexlify(b"86d09974840bded2a5ca") nonce = binascii.unhexlify(b"cd7cf67be39c794acd7cf67bcd7cf67be39c794acd7cf67b") for ad in [binascii.unhexlify(b"87e229d4500845a079c0"), None]: output = pysodium.crypto_aead_xchacha20poly1305_ietf_encrypt(input_, ad, nonce, key) output = pysodium.crypto_aead_xchacha20poly1305_ietf_decrypt(output, ad, nonce, key) self.assertEqual(output, input_)
def test_aead_chacha20poly1305_ietf(self): if not pysodium.sodium_version_check(1, 0, 4): return key = binascii.unhexlify(b"4290bcb154173531f314af57f3be3b5006da371ece272afa1b5dbdd1100a1007") input_ = binascii.unhexlify(b"86d09974840bded2a5ca") nonce = binascii.unhexlify(b"cd7cf67be39c794a") ad = binascii.unhexlify(b"87e229d4500845a079c0") output = pysodium.crypto_aead_chacha20poly1305_ietf_encrypt(input_, ad, nonce, key) output = pysodium.crypto_aead_chacha20poly1305_ietf_decrypt(output, ad, nonce, key) self.assertEqual(output, input_)
def test_crypto_kx(self): if not pysodium.sodium_version_check(1, 0, 12): return client_pk, client_sk = pysodium.crypto_kx_keypair() server_pk, server_sk = pysodium.crypto_kx_keypair() crx, ctx = pysodium.crypto_kx_client_session_keys(client_pk, client_sk, server_pk) srx, stx = pysodium.crypto_kx_server_session_keys(server_pk, server_sk, client_pk) self.assertEqual(crx, stx) self.assertEqual(ctx, srx)
def test_crypto_secretstream_xchacha20poly1305_pull_incorrect_key(self): if not pysodium.sodium_version_check(1, 0, 15): return key = pysodium.crypto_secretstream_xchacha20poly1305_keygen() state, header = pysodium.crypto_secretstream_xchacha20poly1305_init_push(key) ciphertext = pysodium.crypto_secretstream_xchacha20poly1305_push(state, b"howdy", None, pysodium.crypto_secretstream_xchacha20poly1305_TAG_FINAL) bad_key = pysodium.crypto_secretstream_xchacha20poly1305_keygen() state2 = pysodium.crypto_secretstream_xchacha20poly1305_init_pull(header, bad_key) self.assertRaises(ValueError, pysodium.crypto_secretstream_xchacha20poly1305_pull, state2, ciphertext, None)
def test_crypto_core_ristretto255_scalar_add_sub(self): if not pysodium.sodium_version_check(1, 0, 18): return x = pysodium.crypto_core_ristretto255_scalar_random() y = pysodium.crypto_core_ristretto255_scalar_random() x_y = pysodium.crypto_core_ristretto255_scalar_add(x,y) r = pysodium.crypto_core_ristretto255_scalar_sub(x_y,y) p1 = pysodium.crypto_scalarmult_ristretto255_base(x) p2 = pysodium.crypto_scalarmult_ristretto255_base(r) self.assertEqual(p1,p2)
def test_crypto_core_ristretto255_scalar_mul(self): if not pysodium.sodium_version_check(1, 0, 18): return two = b'\x02' + b'\x00' * 31 four_mul = pysodium.crypto_core_ristretto255_scalar_mul(two,two) four_add = pysodium.crypto_core_ristretto255_scalar_add(two,two) self.assertEqual(four_mul,four_add) x = pysodium.crypto_core_ristretto255_scalar_random() one = b'\x01' + b'\x00' * 31 r = pysodium.crypto_core_ristretto255_scalar_mul(x,one) self.assertEqual(x,r)
def test_aead_chacha20poly1305_detached(self): if not pysodium.sodium_version_check(1, 0, 9): return key = binascii.unhexlify(b"4290bcb154173531f314af57f3be3b5006da371ece272afa1b5dbdd1100a1007") input_ = binascii.unhexlify(b"86d09974840bded2a5ca") nonce = binascii.unhexlify(b"cd7cf67be39c794a") ad = binascii.unhexlify(b"87e229d4500845a079c0") output, mac = pysodium.crypto_aead_chacha20poly1305_encrypt_detached(input_, ad, nonce, key) self.assertEqual(binascii.unhexlify(b"e3e446f7ede9a19b62a4"), output) self.assertEqual(binascii.unhexlify(b"677dabf4e3d24b876bb284753896e1d6"), mac) output = pysodium.crypto_aead_chacha20poly1305_decrypt_detached(output, mac, ad, nonce, key) self.assertEqual(output, input_)
def test_crypto_pwhash(self): if not pysodium.sodium_version_check(1, 0, 9): return pw = "Correct Horse Battery Staple" salt = binascii.unhexlify(b'0f58b94c7a369fd8a9a7083e4cd75266') out = pysodium.crypto_pwhash( pysodium.crypto_auth_KEYBYTES, pw, salt, pysodium.crypto_pwhash_OPSLIMIT_INTERACTIVE, pysodium.crypto_pwhash_MEMLIMIT_INTERACTIVE) self.assertEqual( binascii.hexlify(out), b'79db3095517c7358449d84ee3b2f81f0e9907fbd4e0bae4e0bcc6c79821427dc' )
def test_crypto_secretstream_xchacha20poly1305_pull(self): if not pysodium.sodium_version_check(1, 0, 15): return key = pysodium.crypto_secretstream_xchacha20poly1305_keygen() state, header = pysodium.crypto_secretstream_xchacha20poly1305_init_push(key) ciphertext = pysodium.crypto_secretstream_xchacha20poly1305_push(state, b"howdy", None, pysodium.crypto_secretstream_xchacha20poly1305_TAG_FINAL) state2 = pysodium.crypto_secretstream_xchacha20poly1305_init_pull(header, key) msg, tag = pysodium.crypto_secretstream_xchacha20poly1305_pull(state2, ciphertext, None) self.assertEqual(msg, b"howdy") self.assertEqual(tag, pysodium.crypto_secretstream_xchacha20poly1305_TAG_FINAL)
def test_crypto_core_ristretto255_is_valid_point(self): if not pysodium.sodium_version_check(1, 0, 18): return invalid = binascii.unhexlify( b"ecffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f" ) self.assertEqual( False, pysodium.crypto_core_ristretto255_is_valid_point(invalid)) invalid = binascii.unhexlify( b"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f" ) self.assertEqual( False, pysodium.crypto_core_ristretto255_is_valid_point(invalid))
def test_crypto_secretstream_xchacha20poly1305_out_of_order_messeges(self): if not pysodium.sodium_version_check(1, 0, 15): return key = pysodium.crypto_secretstream_xchacha20poly1305_keygen() state, header = pysodium.crypto_secretstream_xchacha20poly1305_init_push(key) ciphertext = pysodium.crypto_secretstream_xchacha20poly1305_push(state, b"Correct Horse Battery Staple", None, 0) ciphertext2 = pysodium.crypto_secretstream_xchacha20poly1305_push(state, b"howdy", None, pysodium.crypto_secretstream_xchacha20poly1305_TAG_FINAL) # Decrypting the second message first should fail state2 = pysodium.crypto_secretstream_xchacha20poly1305_init_pull(header, key) self.assertRaises(ValueError, pysodium.crypto_secretstream_xchacha20poly1305_pull, state2, ciphertext2, None)
def test_aead_chacha20poly1305_ietf_detached(self): if not pysodium.sodium_version_check(1, 0, 9): return key = binascii.unhexlify(b"4290bcb154173531f314af57f3be3b5006da371ece272afa1b5dbdd1100a1007") input_ = binascii.unhexlify(b"86d09974840bded2a5ca") nonce = binascii.unhexlify(b"cd7cf67be39c794acd7cf67b") for ad, ct in [ (binascii.unhexlify(b"87e229d4500845a079c0"), b"09394ed41cf16d3c0820c5e0caf8a7bf"), (None, b"07bf99e3c0d8aaac48c04e1f93b12a63"), ]: output, mac = pysodium.crypto_aead_chacha20poly1305_ietf_encrypt_detached(input_, ad, nonce, key) self.assertEqual(binascii.unhexlify(b"eef4c561bdda5ef7e044"), output) self.assertEqual(binascii.unhexlify(ct), mac) output = pysodium.crypto_aead_chacha20poly1305_ietf_decrypt_detached(output, mac, ad, nonce, key) self.assertEqual(output, input_)
def test_aead_chacha20poly1305_detached(self): if not pysodium.sodium_version_check(1, 0, 9): return key = binascii.unhexlify(b"4290bcb154173531f314af57f3be3b5006da371ece272afa1b5dbdd1100a1007") input_ = binascii.unhexlify(b"86d09974840bded2a5ca") nonce = binascii.unhexlify(b"cd7cf67be39c794a") for ad, ct in [ (binascii.unhexlify(b"87e229d4500845a079c0"), b"677dabf4e3d24b876bb284753896e1d6"), (None, b"69e7789bcd954e658ed38423e23161dc"), ]: output, mac = pysodium.crypto_aead_chacha20poly1305_encrypt_detached(input_, ad, nonce, key) self.assertEqual(binascii.unhexlify(b"e3e446f7ede9a19b62a4"), output) self.assertEqual(binascii.unhexlify(ct), mac) output = pysodium.crypto_aead_chacha20poly1305_decrypt_detached(output, mac, ad, nonce, key) self.assertEqual(output, input_)
def test0(): if not pysodium.sodium_version_check(1, 0, 9): return pk, sk = pysodium.crypto_box_keypair() #print(pk) #print(sk) p = binascii.hexlify(pk) s = binascii.hexlify(sk) print(p) print(s) c = pysodium.crypto_box_seal(b"passwd", pk) print(binascii.hexlify(c)) print(pysodium.crypto_box_seal_open(c, pk, sk))
def test_crypto_secretstream_xchacha20poly1305_missing_rekey(self): if not pysodium.sodium_version_check(1, 0, 15): return key = pysodium.crypto_secretstream_xchacha20poly1305_keygen() state, header = pysodium.crypto_secretstream_xchacha20poly1305_init_push(key) # Encrypt two messages with intermediate re-key ciphertext = pysodium.crypto_secretstream_xchacha20poly1305_push(state, b"Correct Horse Battery Staple", None, 0) pysodium.crypto_secretstream_xchacha20poly1305_rekey(state) ciphertext2 = pysodium.crypto_secretstream_xchacha20poly1305_push(state, b"howdy", None, pysodium.crypto_secretstream_xchacha20poly1305_TAG_FINAL) state2 = pysodium.crypto_secretstream_xchacha20poly1305_init_pull(header, key) msg, tag = pysodium.crypto_secretstream_xchacha20poly1305_pull(state2, ciphertext, None) # re-key should be here, so following call should fail self.assertRaises(ValueError, pysodium.crypto_secretstream_xchacha20poly1305_pull, state2, ciphertext2, None)
def test_crypto_secretstream_xchacha20poly1305_pull_corrupted(self): if not pysodium.sodium_version_check(1, 0, 15): return key = pysodium.crypto_secretstream_xchacha20poly1305_keygen() state, header = pysodium.crypto_secretstream_xchacha20poly1305_init_push(key) ad = 'additional data' ciphertext = pysodium.crypto_secretstream_xchacha20poly1305_push(state, b"Correct Horse Battery Staple", ad, 0) # Verify error is raised if cypher text is changed state2 = pysodium.crypto_secretstream_xchacha20poly1305_init_pull(header, key) self.assertRaises(ValueError, pysodium.crypto_secretstream_xchacha20poly1305_pull, state2, ciphertext + 'this is a corruption'.encode(), ad) # Verify error is raised if additional data is changed ad2 = 'this is not the same' state2 = pysodium.crypto_secretstream_xchacha20poly1305_init_pull(header, key) self.assertRaises(ValueError, pysodium.crypto_secretstream_xchacha20poly1305_pull, state2, ciphertext, ad2)
def test_crypto_secretstream_xchacha20poly1305_pull_multiple(self): if not pysodium.sodium_version_check(1, 0, 15): return key = pysodium.crypto_secretstream_xchacha20poly1305_keygen() state, header = pysodium.crypto_secretstream_xchacha20poly1305_init_push(key) ciphertext = pysodium.crypto_secretstream_xchacha20poly1305_push(state, b"Correct Horse Battery Staple", None, 0) ciphertext2 = pysodium.crypto_secretstream_xchacha20poly1305_push(state, b"howdy", None, pysodium.crypto_secretstream_xchacha20poly1305_TAG_FINAL) # Verify decryption state2 = pysodium.crypto_secretstream_xchacha20poly1305_init_pull(header, key) msg, tag = pysodium.crypto_secretstream_xchacha20poly1305_pull(state2, ciphertext, None) msg2, tag2 = pysodium.crypto_secretstream_xchacha20poly1305_pull(state2, ciphertext2, None) self.assertEqual(msg, b"Correct Horse Battery Staple") self.assertEqual(tag, 0) self.assertEqual(msg2, b"howdy") self.assertEqual(tag2, pysodium.crypto_secretstream_xchacha20poly1305_TAG_FINAL)
def test_crypto_secretstream_xchacha20poly1305_rekey(self): if not pysodium.sodium_version_check(1, 0, 15): return key = pysodium.crypto_secretstream_xchacha20poly1305_keygen() state, header = pysodium.crypto_secretstream_xchacha20poly1305_init_push(key) # Encrypt two messages with intermediate re-key ciphertext = pysodium.crypto_secretstream_xchacha20poly1305_push(state, b"Correct Horse Battery Staple", None, 0) pysodium.crypto_secretstream_xchacha20poly1305_rekey(state) ciphertext2 = pysodium.crypto_secretstream_xchacha20poly1305_push(state, b"howdy", None, pysodium.crypto_secretstream_xchacha20poly1305_TAG_FINAL) # Verify by decrypting them state2 = pysodium.crypto_secretstream_xchacha20poly1305_init_pull(header, key) msg, tag = pysodium.crypto_secretstream_xchacha20poly1305_pull(state2, ciphertext, None) pysodium.crypto_secretstream_xchacha20poly1305_rekey(state2) msg2, tag2 = pysodium.crypto_secretstream_xchacha20poly1305_pull(state2, ciphertext2, None) self.assertEqual(msg, b"Correct Horse Battery Staple") self.assertEqual(tag, 0) self.assertEqual(msg2, b"howdy") self.assertEqual(tag2, pysodium.crypto_secretstream_xchacha20poly1305_TAG_FINAL)
def test_crypto_secretstream_xchacha20poly1305_init_pull(self): if not pysodium.sodium_version_check(1, 0, 15): return key = pysodium.crypto_secretstream_xchacha20poly1305_keygen() state, header = pysodium.crypto_secretstream_xchacha20poly1305_init_push(key) state2 = pysodium.crypto_secretstream_xchacha20poly1305_init_pull(header, key)
def test_crypto_secretstream_xchacha20poly1305_push(self): if not pysodium.sodium_version_check(1, 0, 15): return key = pysodium.crypto_secretstream_xchacha20poly1305_keygen() state, header = pysodium.crypto_secretstream_xchacha20poly1305_init_push(key) ciphertext = pysodium.crypto_secretstream_xchacha20poly1305_push(state, b"howdy", None, 0)
def test_crypto_box_seal(self): if not pysodium.sodium_version_check(1, 0, 3): return pk, sk = pysodium.crypto_box_keypair() c = pysodium.crypto_box_seal(b"howdy", pk) self.assertEqual(pysodium.crypto_box_seal_open(c, pk, sk), b'howdy')
def test_crypto_pwhash_str_verify(self): if not pysodium.sodium_version_check(1, 0, 9): return
def test_crypto_pwhash_storage(self): if not pysodium.sodium_version_check(1, 0, 9): return pw = "Correct Horse Battery Staple" pstr = pysodium.crypto_pwhash_str(pw, pysodium.crypto_pwhash_OPSLIMIT_INTERACTIVE, pysodium.crypto_pwhash_MEMLIMIT_INTERACTIVE) self.assertTrue(pysodium.crypto_pwhash_str_verify(pstr, pw))
def test_crypto_pwhash(self): if not pysodium.sodium_version_check(1, 0, 9): return pw = "Correct Horse Battery Staple" salt = binascii.unhexlify(b'0f58b94c7a369fd8a9a7083e4cd75266') out = pysodium.crypto_pwhash(pysodium.crypto_auth_KEYBYTES, pw, salt, pysodium.crypto_pwhash_OPSLIMIT_INTERACTIVE, pysodium.crypto_pwhash_MEMLIMIT_INTERACTIVE) self.assertEqual(binascii.hexlify(out), b'79db3095517c7358449d84ee3b2f81f0e9907fbd4e0bae4e0bcc6c79821427dc')
def test_crypto_secretstream_xchacha20poly1305_keygen(self): if not pysodium.sodium_version_check(1, 0, 15): return key = pysodium.crypto_secretstream_xchacha20poly1305_keygen() self.assertEqual(len(key), 32)
def test_crypto_core_ristretto255_from_hash(self): if not pysodium.sodium_version_check(1, 0, 18): return h = pysodium.crypto_generichash( b'howdy', outlen=pysodium.crypto_core_ristretto255_HASHBYTES) p = pysodium.crypto_core_ristretto255_from_hash(h) pysodium.crypto_core_ristretto255_is_valid_point(p)
def test_crypto_core_ristretto255_scalar_random(self): if not pysodium.sodium_version_check(1, 0, 18): return a = pysodium.crypto_core_ristretto255_scalar_random() b = pysodium.crypto_core_ristretto255_scalar_random() # stupid check that random returns different values... self.assertNotEqual(a, b)