summaryrefslogtreecommitdiff
path: root/pipermail/pycrypto/2013q4/000741.html
diff options
context:
space:
mode:
Diffstat (limited to 'pipermail/pycrypto/2013q4/000741.html')
-rw-r--r--pipermail/pycrypto/2013q4/000741.html154
1 files changed, 154 insertions, 0 deletions
diff --git a/pipermail/pycrypto/2013q4/000741.html b/pipermail/pycrypto/2013q4/000741.html
new file mode 100644
index 0000000..8be514b
--- /dev/null
+++ b/pipermail/pycrypto/2013q4/000741.html
@@ -0,0 +1,154 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<HTML>
+ <HEAD>
+ <TITLE> [pycrypto] DES3 problem
+ </TITLE>
+ <LINK REL="Index" HREF="index.html" >
+ <LINK REL="made" HREF="mailto:pycrypto%40lists.dlitz.net?Subject=Re%3A%20%5Bpycrypto%5D%20DES3%20problem&In-Reply-To=%3CCAGfyce0oB2vFOj0p6U30RdZ2Xks9KyEjuNLyc_R_Q47f3mYQXg%40mail.gmail.com%3E">
+ <META NAME="robots" CONTENT="index,nofollow">
+ <style type="text/css">
+ pre {
+ white-space: pre-wrap; /* css-2.1, curent FF, Opera, Safari */
+ }
+ </style>
+ <META http-equiv="Content-Type" content="text/html; charset=us-ascii">
+ <LINK REL="Previous" HREF="000740.html">
+ <LINK REL="Next" HREF="000742.html">
+ </HEAD>
+ <BODY BGCOLOR="#ffffff">
+ <H1>[pycrypto] DES3 problem</H1>
+ <B>Legrandin</B>
+ <A HREF="mailto:pycrypto%40lists.dlitz.net?Subject=Re%3A%20%5Bpycrypto%5D%20DES3%20problem&In-Reply-To=%3CCAGfyce0oB2vFOj0p6U30RdZ2Xks9KyEjuNLyc_R_Q47f3mYQXg%40mail.gmail.com%3E"
+ TITLE="[pycrypto] DES3 problem">helderijs at gmail.com
+ </A><BR>
+ <I>Fri Nov 29 12:16:47 PST 2013</I>
+ <P><UL>
+ <LI>Previous message: <A HREF="000740.html">[pycrypto] DES3 problem
+</A></li>
+ <LI>Next message: <A HREF="000742.html">[pycrypto] DES3 problem
+</A></li>
+ <LI> <B>Messages sorted by:</B>
+ <a href="date.html#741">[ date ]</a>
+ <a href="thread.html#741">[ thread ]</a>
+ <a href="subject.html#741">[ subject ]</a>
+ <a href="author.html#741">[ author ]</a>
+ </LI>
+ </UL>
+ <HR>
+<!--beginarticle-->
+<PRE>Hi,
+
+Since a cipher object is stateful, it can be used for either
+encryption or decryption but not both.
+In order to simulate both ends of a communication, you need two cipher objects.
+Your code should be:
+
+&gt;&gt;&gt;<i> from Crypto.Cipher import DES3
+</I>&gt;&gt;&gt;<i> from Crypto import Random
+</I>&gt;&gt;&gt;<i> key = b'Sixteen byte key'
+</I>&gt;&gt;&gt;<i> iv = Random.new().read(DES3.block_size)
+</I>&gt;&gt;&gt;<i> cipher = DES3.new(key, DES3.MODE_OFB, iv)
+</I>&gt;&gt;&gt;<i> plaintext = b'sona si latine loqueris '
+</I>&gt;&gt;&gt;<i> msg = iv + cipher.encrypt(plaintext)
+</I>&gt;&gt;&gt;<i>
+</I>&gt;&gt;&gt;<i>
+</I>&gt;&gt;&gt;<i>
+</I>&gt;&gt;&gt;<i> iv = msg[:16]
+</I>&gt;&gt;&gt;<i> cipher = DES3.new(key, DES3.MODE_OFB, iv)
+</I>&gt;&gt;&gt;<i> p = cipher.decrypt(msg[16:])
+</I>&gt;&gt;&gt;<i> print(p)
+</I>
+The only exception is the ECB mode. Being it stateless, it lets you
+intermix encryption and decryption.
+However, that mode should be avoided when possible because it's very
+tricky to get right.
+
+A nonce (sometimes called IV) is critical a value required by most
+modes (ECB again being an exception).
+It is typically required to be unique per each combination of
+key/message. In some cases - like for CBC - it must also be
+unpredictable to an adversary. The nonce/IV does not need to kept
+secret but it needs to be delivered to the receiver somehow, otherwise
+it wouldn't be able to perform decryption.
+One common choice is to generate the nonce/IV randomly and prepend it
+to the ciphertext (that is, the result of a call to .encrypt() ) but
+nothing stops you from sending it afterwards.
+
+
+2013/11/29 Dave Pawson &lt;<A HREF="http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto">dave.pawson at gmail.com</A>&gt;:
+&gt;<i> On 29 November 2013 15:16, Legrandin &lt;<A HREF="http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto">helderijs at gmail.com</A>&gt; wrote:
+</I>&gt;<i>
+</I>&gt;&gt;<i> The DES3 example you are looking for is actually here:
+</I>&gt;&gt;<i>
+</I>&gt;&gt;<i> <A HREF="https://www.dlitz.net/software/pycrypto/api/current/Crypto.Cipher.DES-module.html">https://www.dlitz.net/software/pycrypto/api/current/Crypto.Cipher.DES-module.html</A>
+</I>&gt;<i>
+</I>&gt;<i>
+</I>&gt;<i> I can't get that working.
+</I>&gt;<i>
+</I>&gt;<i> Request please?
+</I>&gt;<i> Assuming I'm not unusual in wanting to both encrypt and then decrypt.
+</I>&gt;<i> It would be very helpful to show the decrypt after the encrypt?
+</I>&gt;<i> the oddities I'm finding,
+</I>&gt;<i> 1. Why is it sometimes (I don't know why) shown creating two ciphers,
+</I>&gt;<i> one for encrypt, one for decrypt.
+</I>&gt;<i> 2. The use of a nonce (as per above)
+</I>&gt;<i> Is it normal to decrypt using
+</I>&gt;<i>
+</I>&gt;<i> ciphertext=iv + ciphere.encrypt(plaintext)
+</I>&gt;<i> plain = cipherd.decrypt(ciphertext[16:])
+</I>&gt;<i>
+</I>&gt;<i> Using the example....
+</I>&gt;<i>
+</I>&gt;&gt;&gt;&gt;<i> from Crypto.Cipher import DES3
+</I>&gt;&gt;&gt;&gt;<i> from Crypto import Random
+</I>&gt;&gt;&gt;&gt;<i> key = b'Sixteen byte key'
+</I>&gt;&gt;&gt;&gt;<i> iv = Random.new().read(DES3.block_size)
+</I>&gt;&gt;&gt;&gt;<i> cipher = DES3.new(key, DES3.MODE_OFB, iv)
+</I>&gt;&gt;&gt;&gt;<i> plaintext = b'sona si latine loqueris '
+</I>&gt;&gt;&gt;&gt;<i> msg = iv + cipher.encrypt(plaintext)
+</I>&gt;&gt;&gt;&gt;<i> p = cipher.decrypt(msg[16:])
+</I>&gt;&gt;&gt;&gt;<i> print(p)
+</I>&gt;<i> b'\xc0/)~\xc1\xa4\xb0\xb3\x0c\x92y_\x9a\xaa\xe3\xa0'
+</I>&gt;<i>
+</I>&gt;<i> Any ideas please?
+</I>&gt;<i>
+</I>&gt;<i>
+</I>&gt;<i> TiA
+</I>&gt;<i>
+</I>&gt;<i>
+</I>&gt;<i>
+</I>&gt;<i>
+</I>&gt;<i>
+</I>&gt;<i>
+</I>&gt;<i> --
+</I>&gt;<i> Dave Pawson
+</I>&gt;<i> XSLT XSL-FO FAQ.
+</I>&gt;<i> Docbook FAQ.
+</I>&gt;<i> <A HREF="http://www.dpawson.co.uk">http://www.dpawson.co.uk</A>
+</I>&gt;<i> _______________________________________________
+</I>&gt;<i> pycrypto mailing list
+</I>&gt;<i> <A HREF="http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto">pycrypto at lists.dlitz.net</A>
+</I>&gt;<i> <A HREF="http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto">http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto</A>
+</I></PRE>
+
+
+<!--endarticle-->
+ <HR>
+ <P><UL>
+ <!--threads-->
+ <LI>Previous message: <A HREF="000740.html">[pycrypto] DES3 problem
+</A></li>
+ <LI>Next message: <A HREF="000742.html">[pycrypto] DES3 problem
+</A></li>
+ <LI> <B>Messages sorted by:</B>
+ <a href="date.html#741">[ date ]</a>
+ <a href="thread.html#741">[ thread ]</a>
+ <a href="subject.html#741">[ subject ]</a>
+ <a href="author.html#741">[ author ]</a>
+ </LI>
+ </UL>
+
+<hr>
+<a href="http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto">More information about the pycrypto
+mailing list</a><br>
+</body></html>