def test_crypto_stream_xor(self): pysodium.crypto_stream_xor(b'howdy', len(b'howdy')) pysodium.crypto_stream_xor(b'howdy' * 16, len(b'howdy') * 16)
def test_crypto_stream_xor(self): pysodium.crypto_stream_xor(b'howdy', len(b'howdy')) pysodium.crypto_stream_xor(b'howdy' * 16, len(b'howdy') * 16)
def test_crypto_stream_xor(self): nonce = b'\x00' * pysodium.crypto_stream_NONCEBYTES key = b'\x00' * pysodium.crypto_stream_KEYBYTES pysodium.crypto_stream_xor(b'howdy', len(b'howdy'), nonce, key) pysodium.crypto_stream_xor(b'howdy' * 16, len(b'howdy') * 16, nonce, key)
sys.exit('Error: Unable to import public key, aborting.') if clargs.file is None: message = sys.stdin.read().encode() else: with open(clargs.file, 'r') as msgfile: message = msgfile.read().encode() if (message is None) or (len(message) == 0): sys.exit('Error: Plaintext length 0, aborting.') # generate a random (ephemeral) private key eprivkey = FieldElement.urandom(curve.p) SharedPt = Pubkey * eprivkey sbytes = SharedPt.compressed() key = sha256(sbytes).digest() nonce = pysodium.randombytes(pysodium.crypto_stream_NONCEBYTES) assert pysodium.crypto_stream_NONCEBYTES == 24 assert pysodium.crypto_stream_KEYBYTES == 32 ctext = pysodium.crypto_stream_xor(message, len(message), nonce, key) # public key point for ephemeral key Gpt = ECPoint(curve, curve.G) ePubkey = Gpt * eprivkey DERmsg = der_encode_message(ePubkey, nonce, ctext) print(pem_wrap(DERmsg, 'ECDHE_XSALSA20 ENCRYPTED MESSAGE'))
sys.exit('Error: Unable to import private key, aborting.') if privkey is None: sys.exit('Error: Unable to import public key, aborting.') if clargs.file is None: inCtxt = sys.stdin.read() else: with open(clargs.file, 'r') as msgfile: inCtxt=msgfile.read() ctder = pem_unwrap(inCtxt, 'ECDHE_XSALSA20 ENCRYPTED MESSAGE') if ctder is None: sys.exit('unable to decode ECDHE_XSALSA20 ENCRYPTED MESSAGE in base64 PEM format') (ePubkeybytes, nonce, ctext) = der_decode_message(ctder) try: ePubkey = ECPoint(curve, ePubkeybytes) except (TypeError, ValueError): sys.exit('Pubkey value invalid for curve') # generate a random (ephemeral) private key SharedPt = ePubkey * privkey sbytes = SharedPt.compressed() key = sha256(sbytes).digest() ptext = pysodium.crypto_stream_xor(ctext, len(ctext), nonce, key) print(ptext.decode(), end='')
def test_crypto_stream_xor(self): nonce = b'\x00' * pysodium.crypto_stream_NONCEBYTES key = b'\x00' * pysodium.crypto_stream_KEYBYTES pysodium.crypto_stream_xor(b'howdy', len(b'howdy'), nonce, key) pysodium.crypto_stream_xor(b'howdy' * 16, len(b'howdy') * 16, nonce, key)