1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE> [pycrypto] AES, MODE_CTR
</TITLE>
<LINK REL="Index" HREF="index.html" >
<LINK REL="made" HREF="mailto:pycrypto%40lists.dlitz.net?Subject=Re%3A%20%5Bpycrypto%5D%20AES%2C%20MODE_CTR&In-Reply-To=%3CCAGfyce0iDJxF17dUcF26T%3D1nP%2BHs9kDmLmXSN%3D93yuN4HDF%3D9Q%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="000748.html">
<LINK REL="Next" HREF="000750.html">
</HEAD>
<BODY BGCOLOR="#ffffff">
<H1>[pycrypto] AES, MODE_CTR</H1>
<B>Legrandin</B>
<A HREF="mailto:pycrypto%40lists.dlitz.net?Subject=Re%3A%20%5Bpycrypto%5D%20AES%2C%20MODE_CTR&In-Reply-To=%3CCAGfyce0iDJxF17dUcF26T%3D1nP%2BHs9kDmLmXSN%3D93yuN4HDF%3D9Q%40mail.gmail.com%3E"
TITLE="[pycrypto] AES, MODE_CTR">helderijs at gmail.com
</A><BR>
<I>Thu Dec 5 11:41:05 PST 2013</I>
<P><UL>
<LI>Previous message: <A HREF="000748.html">[pycrypto] AES, MODE_CTR
</A></li>
<LI>Next message: <A HREF="000750.html">[pycrypto] AES, MODE_CTR
</A></li>
<LI> <B>Messages sorted by:</B>
<a href="date.html#749">[ date ]</a>
<a href="thread.html#749">[ thread ]</a>
<a href="subject.html#749">[ subject ]</a>
<a href="author.html#749">[ author ]</a>
</LI>
</UL>
<HR>
<!--beginarticle-->
<PRE>><i>Thanks Richard. Now working
</I>><i> def test_AES5(self):
</I>><i> pt=b' '*10
</I>><i> ctr=Counter.new(128)
</I>><i> iv = Random.new().read(AES.block_size)
</I>><i> cipher = AES.new(b' '*16, AES.MODE_CTR, IV=iv, counter=ctr)
</I>><i> ct = cipher.encrypt(pt)
</I>><i> ctrr=Counter.new(128)
</I>><i> decipher = AES.new(b' '*16, AES.MODE_CTR, IV=iv, counter=ctrr)
</I>><i> ptr = decipher.decrypt(ct)
</I>><i> self.assertEqual(pt,ptr)
</I>><i> iv added as suggested.
</I>
Actually, the IV parameter is ignored in Counter mode.
If you want to add a nonce to the counter block you must pass it to
the Counter class:
nonce = Random.new().read(8)
ctr = Counter.new(64, nonce)
cipher = AES.new(b' '*16, AES.MODE_CTR, counter=ctr)
The counter block is then made up by 64 bits of nonce and 64 bits of counter.
PS: I think I get 1 out of 3 messages out of this mailing list.
</PRE>
<!--endarticle-->
<HR>
<P><UL>
<!--threads-->
<LI>Previous message: <A HREF="000748.html">[pycrypto] AES, MODE_CTR
</A></li>
<LI>Next message: <A HREF="000750.html">[pycrypto] AES, MODE_CTR
</A></li>
<LI> <B>Messages sorted by:</B>
<a href="date.html#749">[ date ]</a>
<a href="thread.html#749">[ thread ]</a>
<a href="subject.html#749">[ subject ]</a>
<a href="author.html#749">[ 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>
|