summaryrefslogtreecommitdiff
path: root/pipermail/pycrypto/2014q1.txt
blob: 6a509c4f7bbe629ce5b8fc84b6232a0e1f230f01 (plain)
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
From hugh.macdonald at nvizible.com  Tue Jan  7 09:43:03 2014
From: hugh.macdonald at nvizible.com (Hugh Macdonald)
Date: Tue, 7 Jan 2014 17:43:03 +0000
Subject: [pycrypto] Docs/code mis-match - not specifying IV fails
Message-ID: <CAL_xc9ip-UxK_2=5EvJBtEN9guqwZa-4=xUfCy527uKzj2dycA@mail.gmail.com>

Hi,

I've just been trying to figure out why some code of mine broke after an
update from 2.0.1 to 2.6.1, and found that I hadn't been passing an IV into
AES.new() (using MODE_CFB).

Previously, it was happy with this, and, according to the docs here (
https://www.dlitz.net/software/pycrypto/api/current/), "It is optional and
when not present it will be given a default value of all zeroes."

Looking at the code that throws the exception (
https://github.com/dlitz/pycrypto/blob/master/src/block_template.c, line
163), it doesn't allow for doing what the docs suggest it will.

I'm not sure whether I've either misunderstood something or which of the
two is wrong, but I thought I'd at least flag it for discussion...


Hugh

-- 
D I S C L A I M E R : This email and any files transmitted with it are 
intended solely for the intended addressee, and may contain confidential 
information or material protected by law, copyright or other legislation.  
If you have received this message in error, please return it to the sender 
or notify the sender by calling +44 (0)20 3167 3860, and immediately and 
permanently delete it. You should not copy it or use it for any purpose, 
nor disclose its contents to any other person. Only the intended recipient 
may place any reliance upon it. Nvizible Limited accepts no responsibility 
or liability for emails sent by its employees or personnel which are not 
sent in the course of its business or that of its clients.
 
Nvizible Limited, 8/9 Carlisle Street, London W1D 3BP .  Registered in 
England & Wales with Company Number: 6900121
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.dlitz.net/pipermail/pycrypto/attachments/20140107/2dcce815/attachment.html>

From cnibley at gmail.com  Tue Jan  7 16:59:10 2014
From: cnibley at gmail.com (Charley Nibley)
Date: Tue, 7 Jan 2014 16:59:10 -0800
Subject: [pycrypto] Docs/code mis-match - not specifying IV fails
In-Reply-To: <CAL_xc9ip-UxK_2=5EvJBtEN9guqwZa-4=xUfCy527uKzj2dycA@mail.gmail.com>
References: <CAL_xc9ip-UxK_2=5EvJBtEN9guqwZa-4=xUfCy527uKzj2dycA@mail.gmail.com>
Message-ID: <CABRBVqR9XorktfarOshnzVPB5CMCzjG2+onYvYbtHNt7=p3MuQ@mail.gmail.com>

Hi Hugh,

This behavior you are seeing is expected.  It changed with a fix to prevent
an empty string IV passed to the function. IV is always mandatory even if
at some point in a previous build it was being passed as all zeros.  I
believe the doc just needs updating.

See line 173:
https://github.com/dlitz/pycrypto/commit/411f60f58cea79f7e93476ba0c069b80a2a4c1a0

And see the comments here: https://bugs.launchpad.net/pycrypto/+bug/997464

Charley Nibley


On Tue, Jan 7, 2014 at 9:43 AM, Hugh Macdonald
<hugh.macdonald at nvizible.com>wrote:

> Hi,
>
> I've just been trying to figure out why some code of mine broke after an
> update from 2.0.1 to 2.6.1, and found that I hadn't been passing an IV into
> AES.new() (using MODE_CFB).
>
> Previously, it was happy with this, and, according to the docs here (
> https://www.dlitz.net/software/pycrypto/api/current/), "It is optional
> and when not present it will be given a default value of all zeroes."
>
> Looking at the code that throws the exception (
> https://github.com/dlitz/pycrypto/blob/master/src/block_template.c, line
> 163), it doesn't allow for doing what the docs suggest it will.
>
> I'm not sure whether I've either misunderstood something or which of the
> two is wrong, but I thought I'd at least flag it for discussion...
>
>
> Hugh
>
> D I S C L A I M E R : This email and any files transmitted with it are
> intended solely for the intended addressee, and may contain confidential
> information or material protected by law, copyright or other legislation.
> If you have received this message in error, please return it to the sender
> or notify the sender by calling +44 (0)20 3167 3860, and immediately and
> permanently delete it. You should not copy it or use it for any purpose,
> nor disclose its contents to any other person. Only the intended recipient
> may place any reliance upon it. Nvizible Limited accepts no responsibility
> or liability for emails sent by its employees or personnel which are not
> sent in the course of its business or that of its clients.
>
> Nvizible Limited, 8/9 Carlisle Street, London W1D 3BP .  Registered in
> England & Wales with Company Number: 6900121
>
> _______________________________________________
> pycrypto mailing list
> pycrypto at lists.dlitz.net
> http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.dlitz.net/pipermail/pycrypto/attachments/20140107/1bd828fb/attachment.html>

From hugh.macdonald at nvizible.com  Wed Jan  8 01:32:59 2014
From: hugh.macdonald at nvizible.com (Hugh Macdonald)
Date: Wed, 8 Jan 2014 09:32:59 +0000
Subject: [pycrypto] Docs/code mis-match - not specifying IV fails
In-Reply-To: <CABRBVqR9XorktfarOshnzVPB5CMCzjG2+onYvYbtHNt7=p3MuQ@mail.gmail.com>
References: <CAL_xc9ip-UxK_2=5EvJBtEN9guqwZa-4=xUfCy527uKzj2dycA@mail.gmail.com>
 <CABRBVqR9XorktfarOshnzVPB5CMCzjG2+onYvYbtHNt7=p3MuQ@mail.gmail.com>
Message-ID: <CAL_xc9iYv1w+OefAVNBQjxFET7=Ofz2Mqxjk15wRtNoVZje-hw@mail.gmail.com>

Hi Charley,

Thanks for clarifying that - that makes sense to me.


Cheers

Hugh


On 8 January 2014 00:59, Charley Nibley <cnibley at gmail.com> wrote:

> Hi Hugh,
>
> This behavior you are seeing is expected.  It changed with a fix to
> prevent an empty string IV passed to the function. IV is always mandatory
> even if at some point in a previous build it was being passed as all
> zeros.  I believe the doc just needs updating.
>
> See line 173:
> https://github.com/dlitz/pycrypto/commit/411f60f58cea79f7e93476ba0c069b80a2a4c1a0
>
> And see the comments here: https://bugs.launchpad.net/pycrypto/+bug/997464
>
> Charley Nibley
>
>
> On Tue, Jan 7, 2014 at 9:43 AM, Hugh Macdonald <
> hugh.macdonald at nvizible.com> wrote:
>
>> Hi,
>>
>> I've just been trying to figure out why some code of mine broke after an
>> update from 2.0.1 to 2.6.1, and found that I hadn't been passing an IV into
>> AES.new() (using MODE_CFB).
>>
>> Previously, it was happy with this, and, according to the docs here (
>> https://www.dlitz.net/software/pycrypto/api/current/), "It is optional
>> and when not present it will be given a default value of all zeroes."
>>
>> Looking at the code that throws the exception (
>> https://github.com/dlitz/pycrypto/blob/master/src/block_template.c, line
>> 163), it doesn't allow for doing what the docs suggest it will.
>>
>> I'm not sure whether I've either misunderstood something or which of the
>> two is wrong, but I thought I'd at least flag it for discussion...
>>
>>
>> Hugh
>>
>> D I S C L A I M E R : This email and any files transmitted with it are
>> intended solely for the intended addressee, and may contain confidential
>> information or material protected by law, copyright or other legislation.
>> If you have received this message in error, please return it to the sender
>> or notify the sender by calling +44 (0)20 3167 3860, and immediately and
>> permanently delete it. You should not copy it or use it for any purpose,
>> nor disclose its contents to any other person. Only the intended recipient
>> may place any reliance upon it. Nvizible Limited accepts no responsibility
>> or liability for emails sent by its employees or personnel which are not
>> sent in the course of its business or that of its clients.
>>
>> Nvizible Limited, 8/9 Carlisle Street, London W1D 3BP .  Registered in
>> England & Wales with Company Number: 6900121
>>
>> _______________________________________________
>> pycrypto mailing list
>> pycrypto at lists.dlitz.net
>> http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto
>>
>>
>
> _______________________________________________
> pycrypto mailing list
> pycrypto at lists.dlitz.net
> http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto
>
>

-- 
D I S C L A I M E R : This email and any files transmitted with it are 
intended solely for the intended addressee, and may contain confidential 
information or material protected by law, copyright or other legislation.  
If you have received this message in error, please return it to the sender 
or notify the sender by calling +44 (0)20 3167 3860, and immediately and 
permanently delete it. You should not copy it or use it for any purpose, 
nor disclose its contents to any other person. Only the intended recipient 
may place any reliance upon it. Nvizible Limited accepts no responsibility 
or liability for emails sent by its employees or personnel which are not 
sent in the course of its business or that of its clients.
 
Nvizible Limited, 8/9 Carlisle Street, London W1D 3BP .  Registered in 
England & Wales with Company Number: 6900121
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.dlitz.net/pipermail/pycrypto/attachments/20140108/af732de7/attachment.html>

From dave.pawson at gmail.com  Wed Jan  8 02:00:55 2014
From: dave.pawson at gmail.com (Dave Pawson)
Date: Wed, 8 Jan 2014 10:00:55 +0000
Subject: [pycrypto] Docs/code mis-match - not specifying IV fails
In-Reply-To: <CAL_xc9iYv1w+OefAVNBQjxFET7=Ofz2Mqxjk15wRtNoVZje-hw@mail.gmail.com>
References: <CAL_xc9ip-UxK_2=5EvJBtEN9guqwZa-4=xUfCy527uKzj2dycA@mail.gmail.com>
 <CABRBVqR9XorktfarOshnzVPB5CMCzjG2+onYvYbtHNt7=p3MuQ@mail.gmail.com>
 <CAL_xc9iYv1w+OefAVNBQjxFET7=Ofz2Mqxjk15wRtNoVZje-hw@mail.gmail.com>
Message-ID: <CAEncD4eAVgEGXPdxCxzHiLS0khkK+8oNMfnLpn+cegNyM6AjWA@mail.gmail.com>

What does not make sense is that this group seems to accept this
discrepency between
docs and code.

Does anyone know if the docs maintainer has any interest these days?

regards

On 8 January 2014 09:32, Hugh Macdonald <hugh.macdonald at nvizible.com> wrote:
> Hi Charley,
>
> Thanks for clarifying that - that makes sense to me.
>
>
> Cheers
>
> Hugh
>
>
> On 8 January 2014 00:59, Charley Nibley <cnibley at gmail.com> wrote:
>>
>> Hi Hugh,
>>
>> This behavior you are seeing is expected.  It changed with a fix to
>> prevent an empty string IV passed to the function. IV is always mandatory
>> even if at some point in a previous build it was being passed as all zeros.
>> I believe the doc just needs updating.
>>
>> See line 173:
>> https://github.com/dlitz/pycrypto/commit/411f60f58cea79f7e93476ba0c069b80a2a4c1a0
>>
>> And see the comments here: https://bugs.launchpad.net/pycrypto/+bug/997464
>>
>> Charley Nibley
>>
>>
>> On Tue, Jan 7, 2014 at 9:43 AM, Hugh Macdonald
>> <hugh.macdonald at nvizible.com> wrote:
>>>
>>> Hi,
>>>
>>> I've just been trying to figure out why some code of mine broke after an
>>> update from 2.0.1 to 2.6.1, and found that I hadn't been passing an IV into
>>> AES.new() (using MODE_CFB).
>>>
>>> Previously, it was happy with this, and, according to the docs here
>>> (https://www.dlitz.net/software/pycrypto/api/current/), "It is optional and
>>> when not present it will be given a default value of all zeroes."
>>>
>>> Looking at the code that throws the exception
>>> (https://github.com/dlitz/pycrypto/blob/master/src/block_template.c, line
>>> 163), it doesn't allow for doing what the docs suggest it will.
>>>
>>> I'm not sure whether I've either misunderstood something or which of the
>>> two is wrong, but I thought I'd at least flag it for discussion...
>>>
>>>
>>> Hugh
>>>
>>> D I S C L A I M E R : This email and any files transmitted with it are
>>> intended solely for the intended addressee, and may contain confidential
>>> information or material protected by law, copyright or other legislation.
>>> If you have received this message in error, please return it to the sender
>>> or notify the sender by calling +44 (0)20 3167 3860, and immediately and
>>> permanently delete it. You should not copy it or use it for any purpose, nor
>>> disclose its contents to any other person. Only the intended recipient may
>>> place any reliance upon it. Nvizible Limited accepts no responsibility or
>>> liability for emails sent by its employees or personnel which are not sent
>>> in the course of its business or that of its clients.
>>>
>>> Nvizible Limited, 8/9 Carlisle Street, London W1D 3BP .  Registered in
>>> England & Wales with Company Number: 6900121
>>>
>>> _______________________________________________
>>> pycrypto mailing list
>>> pycrypto at lists.dlitz.net
>>> http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto
>>>
>>
>>
>> _______________________________________________
>> pycrypto mailing list
>> pycrypto at lists.dlitz.net
>> http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto
>>
>
>
> D I S C L A I M E R : This email and any files transmitted with it are
> intended solely for the intended addressee, and may contain confidential
> information or material protected by law, copyright or other legislation.
> If you have received this message in error, please return it to the sender
> or notify the sender by calling +44 (0)20 3167 3860, and immediately and
> permanently delete it. You should not copy it or use it for any purpose, nor
> disclose its contents to any other person. Only the intended recipient may
> place any reliance upon it. Nvizible Limited accepts no responsibility or
> liability for emails sent by its employees or personnel which are not sent
> in the course of its business or that of its clients.
>
> Nvizible Limited, 8/9 Carlisle Street, London W1D 3BP .  Registered in
> England & Wales with Company Number: 6900121
>
> _______________________________________________
> pycrypto mailing list
> pycrypto at lists.dlitz.net
> http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto
>



-- 
Dave Pawson
XSLT XSL-FO FAQ.
Docbook FAQ.
http://www.dpawson.co.uk

From dave.pawson at gmail.com  Wed Jan 22 02:30:54 2014
From: dave.pawson at gmail.com (Dave Pawson)
Date: Wed, 22 Jan 2014 10:30:54 +0000
Subject: [pycrypto] windows + linux line endings issue
Message-ID: <CAEncD4cNyTLicEMuucaJUmaBv-Rx+DgyVnKQ7Fe-pWM0NWxyQA@mail.gmail.com>

I want to share an encrypted file across Windows / Linux (say by
saving the file to Dropbox).

When I encrypt using Linux and decrypt using Windows, the
line ending differences screw up the decryption.

I think it's a Python issue, but I'm unsure. Has anyone addressed
this please?

TiA

-- 
Dave Pawson
XSLT XSL-FO FAQ.
Docbook FAQ.
http://www.dpawson.co.uk

From niccokunzmann at rambler.ru  Wed Jan 22 03:01:49 2014
From: niccokunzmann at rambler.ru (Nicco Kunzmann)
Date: Wed, 22 Jan 2014 12:01:49 +0100
Subject: [pycrypto] windows + linux line endings issue
In-Reply-To: <CAEncD4cNyTLicEMuucaJUmaBv-Rx+DgyVnKQ7Fe-pWM0NWxyQA@mail.gmail.com>
References: <CAEncD4cNyTLicEMuucaJUmaBv-Rx+DgyVnKQ7Fe-pWM0NWxyQA@mail.gmail.com>
Message-ID: <52DFA51D.10203@rambler.ru>

Hello,

I do not know your code but could you check that you save (open(..,
'w*b*')) and load the file (open(..., 'r*b*')) in the binary mode
instead of text  mode without 'b'?

Greetings!

Am 22.01.2014 11:30, schrieb Dave Pawson:
> I want to share an encrypted file across Windows / Linux (say by
> saving the file to Dropbox).
>
> When I encrypt using Linux and decrypt using Windows, the
> line ending differences screw up the decryption.
>
> I think it's a Python issue, but I'm unsure. Has anyone addressed
> this please?
>
> TiA
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.dlitz.net/pipermail/pycrypto/attachments/20140122/46b8efd2/attachment.html>

From dave.pawson at gmail.com  Wed Jan 22 03:15:17 2014
From: dave.pawson at gmail.com (Dave Pawson)
Date: Wed, 22 Jan 2014 11:15:17 +0000
Subject: [pycrypto] windows + linux line endings issue
In-Reply-To: <52DFA51D.10203@rambler.ru>
References: <CAEncD4cNyTLicEMuucaJUmaBv-Rx+DgyVnKQ7Fe-pWM0NWxyQA@mail.gmail.com>
 <52DFA51D.10203@rambler.ru>
Message-ID: <CAEncD4fW=LWU-dSQ5HZrR8XH2weowXvf2o-F1hTn-UF1wvfp8w@mail.gmail.com>

On 22 January 2014 11:01, Nicco Kunzmann <niccokunzmann at rambler.ru> wrote:
> Hello,
>
> I do not know your code but could you check that you save (open(.., 'wb'))
> and load the file (open(..., 'rb')) in the binary mode instead of text  mode
> without 'b'?
>
> Greetings!

Hi Nicco.

with open(in_filename, 'rb') as infile:
        with open(out_filename, 'wb') as outfile:

is used to read plain text, write encrypted
and

 with open(in_filename, 'rb') as infile:
for decrypt.

Google searching suggested that - but I was already using it.
  Not sure what else affects it?

regards





>
> Am 22.01.2014 11:30, schrieb Dave Pawson:
>
> I want to share an encrypted file across Windows / Linux (say by
> saving the file to Dropbox).
>
> When I encrypt using Linux and decrypt using Windows, the
> line ending differences screw up the decryption.
>
> I think it's a Python issue, but I'm unsure. Has anyone addressed
> this please?
>
> TiA
>
>
>
> _______________________________________________
> pycrypto mailing list
> pycrypto at lists.dlitz.net
> http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto
>



-- 
Dave Pawson
XSLT XSL-FO FAQ.
Docbook FAQ.
http://www.dpawson.co.uk

From helderijs at gmail.com  Mon Jan 27 13:35:28 2014
From: helderijs at gmail.com (Legrandin)
Date: Mon, 27 Jan 2014 22:35:28 +0100
Subject: [pycrypto] Any progress with pycrypto 2.7?
Message-ID: <CAGfyce0tbAYya=84b79eNHQVRhFJvNGv6pxUAKsxqpUOPDhG3A@mail.gmail.com>

The current alpha1 version contains a few critical bugs which make it
highly unsuitable for release:
1) Hard crash on recent recent Intel CPUs (due gcc and AESNI)
2) Potential DoS when importing an RSA key (segfault of the interpreter)
3) Silent, incorrect HMAC construction for SHA-2

Is there any chance the relevant patches are applied on the short term?
It would be great to fix at least the version which is available from
download from the website.

Besides, is there any news about 2.8? I recall some solid plans for
internal refactoring plus there are 62 open bug reports and 26 pull
requests open.
I am really interested in seeing progress so if there anything that
can be done to help, let me know.

L.

From dave.pawson at gmail.com  Mon Feb  3 01:39:43 2014
From: dave.pawson at gmail.com (Dave Pawson)
Date: Mon, 3 Feb 2014 09:39:43 +0000
Subject: [pycrypto] Unicode?
Message-ID: <CAEncD4eWkV-pH14iJWFCndt9=Z9c0k0uOgJNNozipFnn9DQgGw@mail.gmail.com>

I'm having a problem 'sharing' an encrypted file between
MSDOS and Linux.

so I thought I'd replace \nl in the plain text with a non ASCII
character prior to encryption.

encryptor = AES.new(key, AES.MODE_CBC, iv)
outfile.write(encryptor.encrypt(chunk))

gives me

 File "/usr/lib64/python2.7/site-packages/Crypto/Cipher/blockalgo.py",
line 244, in encrypt
    return self._cipher.encrypt(plaintext)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2022' in
position 34: ordinal not in range(128)


It would seem I can't use non-ASCII characters, at least with AES, is
this right ?

If not, how to address it please?


regards


-- 
Dave Pawson
XSLT XSL-FO FAQ.
Docbook FAQ.
http://www.dpawson.co.uk

From dave.pawson at gmail.com  Mon Feb  3 02:35:03 2014
From: dave.pawson at gmail.com (Dave Pawson)
Date: Mon, 3 Feb 2014 10:35:03 +0000
Subject: [pycrypto] Unicode?
In-Reply-To: <CAEncD4eWkV-pH14iJWFCndt9=Z9c0k0uOgJNNozipFnn9DQgGw@mail.gmail.com>
References: <CAEncD4eWkV-pH14iJWFCndt9=Z9c0k0uOgJNNozipFnn9DQgGw@mail.gmail.com>
Message-ID: <CAEncD4fpFxt47dGVSLiryL8iPqZSqhJkL0YZHqSDUSML-c+e2A@mail.gmail.com>

Now resolved.
Source plain text is created / modified in either DOS or Linux (np to add Mac)

read using
chunk = unicode(infile.read(chunksize))
# replace newline as appropriate
chunk=replaceNL(chunk)
# Convert to byte string
chunk=safe_str(chunk)
encrypt and write to disk


# for decrypt
#Iterate over file to read into string
# replace the individual bytes of the Unicode character (u2022 in my case)
# with \n for the local machine
retval = replaceBullet(retval)

code below

#
#Swap \n for \u2022
#
def replaceNL(str):
    # If DOS, replace \r\x0A
    # If Unix, replace \n
    lineEnd=u'\n'
    if string.find(str,'\r\x0a'):
        lineEnd=u'\r\x0A'
    return string.replace(str,lineEnd,u'\u2022')

#
# Replace bullet by \n
#
def replaceBullet(bstr):
    return string.replace(bstr,u'\\u2022',u'\n')



def safe_str(obj):
    """ return the byte string representation of obj """
    try:
        return str(obj)
    except UnicodeEncodeError:
        # obj is unicode
        return unicode(obj).encode('unicode_escape')

HTH others, though it seems messy, it works.

Dave


On 3 February 2014 09:39, Dave Pawson <dave.pawson at gmail.com> wrote:
> I'm having a problem 'sharing' an encrypted file between
> MSDOS and Linux.
>
> so I thought I'd replace \nl in the plain text with a non ASCII
> character prior to encryption.
>
> encryptor = AES.new(key, AES.MODE_CBC, iv)
> outfile.write(encryptor.encrypt(chunk))
>
> gives me
>
>  File "/usr/lib64/python2.7/site-packages/Crypto/Cipher/blockalgo.py",
> line 244, in encrypt
>     return self._cipher.encrypt(plaintext)
> UnicodeEncodeError: 'ascii' codec can't encode character u'\u2022' in
> position 34: ordinal not in range(128)
>
>
> It would seem I can't use non-ASCII characters, at least with AES, is
> this right ?
>
> If not, how to address it please?
>
>
> regards
>
>
> --
> Dave Pawson
> XSLT XSL-FO FAQ.
> Docbook FAQ.
> http://www.dpawson.co.uk



-- 
Dave Pawson
XSLT XSL-FO FAQ.
Docbook FAQ.
http://www.dpawson.co.uk

From jrgray at gmail.com  Mon Feb  3 04:40:14 2014
From: jrgray at gmail.com (Jeremy Gray)
Date: Mon, 3 Feb 2014 07:40:14 -0500
Subject: [pycrypto] Unicode?
In-Reply-To: <CAEncD4fpFxt47dGVSLiryL8iPqZSqhJkL0YZHqSDUSML-c+e2A@mail.gmail.com>
References: <CAEncD4eWkV-pH14iJWFCndt9=Z9c0k0uOgJNNozipFnn9DQgGw@mail.gmail.com>
 <CAEncD4fpFxt47dGVSLiryL8iPqZSqhJkL0YZHqSDUSML-c+e2A@mail.gmail.com>
Message-ID: <CANqwJFjV2SSsh8Ctvpi3_fDM8ssc=itGx=iJxP_z+uS9=7oX4w@mail.gmail.com>

I may not understand the constraints of your situation, but wouldn't
python's "universal newlines" file-open mode achieve what you want?  infile
= open(filename, 'Urb')

--Jeremy


On Mon, Feb 3, 2014 at 5:35 AM, Dave Pawson <dave.pawson at gmail.com> wrote:

> Now resolved.
> Source plain text is created / modified in either DOS or Linux (np to add
> Mac)
>
> read using
> chunk = unicode(infile.read(chunksize))
> # replace newline as appropriate
> chunk=replaceNL(chunk)
> # Convert to byte string
> chunk=safe_str(chunk)
> encrypt and write to disk
>
>
> # for decrypt
> #Iterate over file to read into string
> # replace the individual bytes of the Unicode character (u2022 in my case)
> # with \n for the local machine
> retval = replaceBullet(retval)
>
> code below
>
> #
> #Swap \n for \u2022
> #
> def replaceNL(str):
>     # If DOS, replace \r\x0A
>     # If Unix, replace \n
>     lineEnd=u'\n'
>     if string.find(str,'\r\x0a'):
>         lineEnd=u'\r\x0A'
>     return string.replace(str,lineEnd,u'\u2022')
>
> #
> # Replace bullet by \n
> #
> def replaceBullet(bstr):
>     return string.replace(bstr,u'\\u2022',u'\n')
>
>
>
> def safe_str(obj):
>     """ return the byte string representation of obj """
>     try:
>         return str(obj)
>     except UnicodeEncodeError:
>         # obj is unicode
>         return unicode(obj).encode('unicode_escape')
>
> HTH others, though it seems messy, it works.
>
> Dave
>
>
> On 3 February 2014 09:39, Dave Pawson <dave.pawson at gmail.com> wrote:
> > I'm having a problem 'sharing' an encrypted file between
> > MSDOS and Linux.
> >
> > so I thought I'd replace \nl in the plain text with a non ASCII
> > character prior to encryption.
> >
> > encryptor = AES.new(key, AES.MODE_CBC, iv)
> > outfile.write(encryptor.encrypt(chunk))
> >
> > gives me
> >
> >  File "/usr/lib64/python2.7/site-packages/Crypto/Cipher/blockalgo.py",
> > line 244, in encrypt
> >     return self._cipher.encrypt(plaintext)
> > UnicodeEncodeError: 'ascii' codec can't encode character u'\u2022' in
> > position 34: ordinal not in range(128)
> >
> >
> > It would seem I can't use non-ASCII characters, at least with AES, is
> > this right ?
> >
> > If not, how to address it please?
> >
> >
> > regards
> >
> >
> > --
> > Dave Pawson
> > XSLT XSL-FO FAQ.
> > Docbook FAQ.
> > http://www.dpawson.co.uk
>
>
>
> --
> Dave Pawson
> XSLT XSL-FO FAQ.
> Docbook FAQ.
> http://www.dpawson.co.uk
> _______________________________________________
> pycrypto mailing list
> pycrypto at lists.dlitz.net
> http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.dlitz.net/pipermail/pycrypto/attachments/20140203/88c7c334/attachment.html>

From dave.pawson at gmail.com  Mon Feb  3 05:21:28 2014
From: dave.pawson at gmail.com (Dave Pawson)
Date: Mon, 3 Feb 2014 13:21:28 +0000
Subject: [pycrypto] Unicode?
In-Reply-To: <CANqwJFjV2SSsh8Ctvpi3_fDM8ssc=itGx=iJxP_z+uS9=7oX4w@mail.gmail.com>
References: <CAEncD4eWkV-pH14iJWFCndt9=Z9c0k0uOgJNNozipFnn9DQgGw@mail.gmail.com>
 <CAEncD4fpFxt47dGVSLiryL8iPqZSqhJkL0YZHqSDUSML-c+e2A@mail.gmail.com>
 <CANqwJFjV2SSsh8Ctvpi3_fDM8ssc=itGx=iJxP_z+uS9=7oX4w@mail.gmail.com>
Message-ID: <CAEncD4eja_Su42nR-6QLcM578RBsrF+KyNDZ9R_8_s2S+7GTvw@mail.gmail.com>

<grin/>
Not sure Jeremy! I'd never heard of it.
I'll let you know.... I'm assuming it is 2.x compatible?

regards

On 3 February 2014 12:40, Jeremy Gray <jrgray at gmail.com> wrote:
> I may not understand the constraints of your situation, but wouldn't
> python's "universal newlines" file-open mode achieve what you want?  infile
> = open(filename, 'Urb')
>
> --Jeremy
>
>
> On Mon, Feb 3, 2014 at 5:35 AM, Dave Pawson <dave.pawson at gmail.com> wrote:
>>
>> Now resolved.
>> Source plain text is created / modified in either DOS or Linux (np to add
>> Mac)
>>
>> read using
>> chunk = unicode(infile.read(chunksize))
>> # replace newline as appropriate
>> chunk=replaceNL(chunk)
>> # Convert to byte string
>> chunk=safe_str(chunk)
>> encrypt and write to disk
>>
>>
>> # for decrypt
>> #Iterate over file to read into string
>> # replace the individual bytes of the Unicode character (u2022 in my case)
>> # with \n for the local machine
>> retval = replaceBullet(retval)
>>
>> code below
>>
>> #
>> #Swap \n for \u2022
>> #
>> def replaceNL(str):
>>     # If DOS, replace \r\x0A
>>     # If Unix, replace \n
>>     lineEnd=u'\n'
>>     if string.find(str,'\r\x0a'):
>>         lineEnd=u'\r\x0A'
>>     return string.replace(str,lineEnd,u'\u2022')
>>
>> #
>> # Replace bullet by \n
>> #
>> def replaceBullet(bstr):
>>     return string.replace(bstr,u'\\u2022',u'\n')
>>
>>
>>
>> def safe_str(obj):
>>     """ return the byte string representation of obj """
>>     try:
>>         return str(obj)
>>     except UnicodeEncodeError:
>>         # obj is unicode
>>         return unicode(obj).encode('unicode_escape')
>>
>> HTH others, though it seems messy, it works.
>>
>> Dave
>>
>>
>> On 3 February 2014 09:39, Dave Pawson <dave.pawson at gmail.com> wrote:
>> > I'm having a problem 'sharing' an encrypted file between
>> > MSDOS and Linux.
>> >
>> > so I thought I'd replace \nl in the plain text with a non ASCII
>> > character prior to encryption.
>> >
>> > encryptor = AES.new(key, AES.MODE_CBC, iv)
>> > outfile.write(encryptor.encrypt(chunk))
>> >
>> > gives me
>> >
>> >  File "/usr/lib64/python2.7/site-packages/Crypto/Cipher/blockalgo.py",
>> > line 244, in encrypt
>> >     return self._cipher.encrypt(plaintext)
>> > UnicodeEncodeError: 'ascii' codec can't encode character u'\u2022' in
>> > position 34: ordinal not in range(128)
>> >
>> >
>> > It would seem I can't use non-ASCII characters, at least with AES, is
>> > this right ?
>> >
>> > If not, how to address it please?
>> >
>> >
>> > regards
>> >
>> >
>> > --
>> > Dave Pawson
>> > XSLT XSL-FO FAQ.
>> > Docbook FAQ.
>> > http://www.dpawson.co.uk
>>
>>
>>
>> --
>> Dave Pawson
>> XSLT XSL-FO FAQ.
>> Docbook FAQ.
>> http://www.dpawson.co.uk
>> _______________________________________________
>> pycrypto mailing list
>> pycrypto at lists.dlitz.net
>> http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto
>
>
>
> _______________________________________________
> pycrypto mailing list
> pycrypto at lists.dlitz.net
> http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto
>



-- 
Dave Pawson
XSLT XSL-FO FAQ.
Docbook FAQ.
http://www.dpawson.co.uk

From jrgray at gmail.com  Mon Feb  3 05:59:39 2014
From: jrgray at gmail.com (Jeremy Gray)
Date: Mon, 3 Feb 2014 08:59:39 -0500
Subject: [pycrypto] Unicode?
In-Reply-To: <CAEncD4eja_Su42nR-6QLcM578RBsrF+KyNDZ9R_8_s2S+7GTvw@mail.gmail.com>
References: <CAEncD4eWkV-pH14iJWFCndt9=Z9c0k0uOgJNNozipFnn9DQgGw@mail.gmail.com>
 <CAEncD4fpFxt47dGVSLiryL8iPqZSqhJkL0YZHqSDUSML-c+e2A@mail.gmail.com>
 <CANqwJFjV2SSsh8Ctvpi3_fDM8ssc=itGx=iJxP_z+uS9=7oX4w@mail.gmail.com>
 <CAEncD4eja_Su42nR-6QLcM578RBsrF+KyNDZ9R_8_s2S+7GTvw@mail.gmail.com>
Message-ID: <CANqwJFh3swP0Qh2AwSMQzm2n40qCSOSME1DrofTNVN3Rcouw-g@mail.gmail.com>

> <grin/>
> Not sure Jeremy! I'd never heard of it.
>

Actually, it looks like 'rU' might be the way to go, not 'Urb'. I've never
used it but probably should. :-)


> I'll let you know.... I'm assuming it is 2.x compatible?
>

yes 2.7, not sure about earlier

--Jeremy




>
> regards
>
> On 3 February 2014 12:40, Jeremy Gray <jrgray at gmail.com> wrote:
> > I may not understand the constraints of your situation, but wouldn't
> > python's "universal newlines" file-open mode achieve what you want?
>  infile
> > = open(filename, 'Urb')
> >
> > --Jeremy
> >
> >
> > On Mon, Feb 3, 2014 at 5:35 AM, Dave Pawson <dave.pawson at gmail.com>
> wrote:
> >>
> >> Now resolved.
> >> Source plain text is created / modified in either DOS or Linux (np to
> add
> >> Mac)
> >>
> >> read using
> >> chunk = unicode(infile.read(chunksize))
> >> # replace newline as appropriate
> >> chunk=replaceNL(chunk)
> >> # Convert to byte string
> >> chunk=safe_str(chunk)
> >> encrypt and write to disk
> >>
> >>
> >> # for decrypt
> >> #Iterate over file to read into string
> >> # replace the individual bytes of the Unicode character (u2022 in my
> case)
> >> # with \n for the local machine
> >> retval = replaceBullet(retval)
> >>
> >> code below
> >>
> >> #
> >> #Swap \n for \u2022
> >> #
> >> def replaceNL(str):
> >>     # If DOS, replace \r\x0A
> >>     # If Unix, replace \n
> >>     lineEnd=u'\n'
> >>     if string.find(str,'\r\x0a'):
> >>         lineEnd=u'\r\x0A'
> >>     return string.replace(str,lineEnd,u'\u2022')
> >>
> >> #
> >> # Replace bullet by \n
> >> #
> >> def replaceBullet(bstr):
> >>     return string.replace(bstr,u'\\u2022',u'\n')
> >>
> >>
> >>
> >> def safe_str(obj):
> >>     """ return the byte string representation of obj """
> >>     try:
> >>         return str(obj)
> >>     except UnicodeEncodeError:
> >>         # obj is unicode
> >>         return unicode(obj).encode('unicode_escape')
> >>
> >> HTH others, though it seems messy, it works.
> >>
> >> Dave
> >>
> >>
> >> On 3 February 2014 09:39, Dave Pawson <dave.pawson at gmail.com> wrote:
> >> > I'm having a problem 'sharing' an encrypted file between
> >> > MSDOS and Linux.
> >> >
> >> > so I thought I'd replace \nl in the plain text with a non ASCII
> >> > character prior to encryption.
> >> >
> >> > encryptor = AES.new(key, AES.MODE_CBC, iv)
> >> > outfile.write(encryptor.encrypt(chunk))
> >> >
> >> > gives me
> >> >
> >> >  File "/usr/lib64/python2.7/site-packages/Crypto/Cipher/blockalgo.py",
> >> > line 244, in encrypt
> >> >     return self._cipher.encrypt(plaintext)
> >> > UnicodeEncodeError: 'ascii' codec can't encode character u'\u2022' in
> >> > position 34: ordinal not in range(128)
> >> >
> >> >
> >> > It would seem I can't use non-ASCII characters, at least with AES, is
> >> > this right ?
> >> >
> >> > If not, how to address it please?
> >> >
> >> >
> >> > regards
> >> >
> >> >
> >> > --
> >> > Dave Pawson
> >> > XSLT XSL-FO FAQ.
> >> > Docbook FAQ.
> >> > http://www.dpawson.co.uk
> >>
> >>
> >>
> >> --
> >> Dave Pawson
> >> XSLT XSL-FO FAQ.
> >> Docbook FAQ.
> >> http://www.dpawson.co.uk
> >> _______________________________________________
> >> pycrypto mailing list
> >> pycrypto at lists.dlitz.net
> >> http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto
> >
> >
> >
> > _______________________________________________
> > pycrypto mailing list
> > pycrypto at lists.dlitz.net
> > http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto
> >
>
>
>
> --
> Dave Pawson
> XSLT XSL-FO FAQ.
> Docbook FAQ.
> http://www.dpawson.co.uk
> _______________________________________________
> pycrypto mailing list
> pycrypto at lists.dlitz.net
> http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.dlitz.net/pipermail/pycrypto/attachments/20140203/dd2d7c15/attachment-0001.html>

From dave.pawson at gmail.com  Mon Feb  3 06:02:04 2014
From: dave.pawson at gmail.com (Dave Pawson)
Date: Mon, 3 Feb 2014 14:02:04 +0000
Subject: [pycrypto] Unicode?
In-Reply-To: <CANqwJFjV2SSsh8Ctvpi3_fDM8ssc=itGx=iJxP_z+uS9=7oX4w@mail.gmail.com>
References: <CAEncD4eWkV-pH14iJWFCndt9=Z9c0k0uOgJNNozipFnn9DQgGw@mail.gmail.com>
 <CAEncD4fpFxt47dGVSLiryL8iPqZSqhJkL0YZHqSDUSML-c+e2A@mail.gmail.com>
 <CANqwJFjV2SSsh8Ctvpi3_fDM8ssc=itGx=iJxP_z+uS9=7oX4w@mail.gmail.com>
Message-ID: <CAEncD4c0sC+YH=qNGRpHfz8BFt_v7Jw7JLwbHEbD2cnEG2dhyg@mail.gmail.com>

Doh! Don't you just hate those smart guys :-)

Many thanks Jeremy, that works perfectly without the oddities.

Lesson learned.

DaveP

On 3 February 2014 12:40, Jeremy Gray <jrgray at gmail.com> wrote:
> I may not understand the constraints of your situation, but wouldn't
> python's "universal newlines" file-open mode achieve what you want?  infile
> = open(filename, 'Urb')
>
> --Jeremy
>
>
> On Mon, Feb 3, 2014 at 5:35 AM, Dave Pawson <dave.pawson at gmail.com> wrote:
>>
>> Now resolved.
>> Source plain text is created / modified in either DOS or Linux (np to add
>> Mac)
>>
>> read using
>> chunk = unicode(infile.read(chunksize))
>> # replace newline as appropriate
>> chunk=replaceNL(chunk)
>> # Convert to byte string
>> chunk=safe_str(chunk)
>> encrypt and write to disk
>>
>>
>> # for decrypt
>> #Iterate over file to read into string
>> # replace the individual bytes of the Unicode character (u2022 in my case)
>> # with \n for the local machine
>> retval = replaceBullet(retval)
>>
>> code below
>>
>> #
>> #Swap \n for \u2022
>> #
>> def replaceNL(str):
>>     # If DOS, replace \r\x0A
>>     # If Unix, replace \n
>>     lineEnd=u'\n'
>>     if string.find(str,'\r\x0a'):
>>         lineEnd=u'\r\x0A'
>>     return string.replace(str,lineEnd,u'\u2022')
>>
>> #
>> # Replace bullet by \n
>> #
>> def replaceBullet(bstr):
>>     return string.replace(bstr,u'\\u2022',u'\n')
>>
>>
>>
>> def safe_str(obj):
>>     """ return the byte string representation of obj """
>>     try:
>>         return str(obj)
>>     except UnicodeEncodeError:
>>         # obj is unicode
>>         return unicode(obj).encode('unicode_escape')
>>
>> HTH others, though it seems messy, it works.
>>
>> Dave
>>
>>
>> On 3 February 2014 09:39, Dave Pawson <dave.pawson at gmail.com> wrote:
>> > I'm having a problem 'sharing' an encrypted file between
>> > MSDOS and Linux.
>> >
>> > so I thought I'd replace \nl in the plain text with a non ASCII
>> > character prior to encryption.
>> >
>> > encryptor = AES.new(key, AES.MODE_CBC, iv)
>> > outfile.write(encryptor.encrypt(chunk))
>> >
>> > gives me
>> >
>> >  File "/usr/lib64/python2.7/site-packages/Crypto/Cipher/blockalgo.py",
>> > line 244, in encrypt
>> >     return self._cipher.encrypt(plaintext)
>> > UnicodeEncodeError: 'ascii' codec can't encode character u'\u2022' in
>> > position 34: ordinal not in range(128)
>> >
>> >
>> > It would seem I can't use non-ASCII characters, at least with AES, is
>> > this right ?
>> >
>> > If not, how to address it please?
>> >
>> >
>> > regards
>> >
>> >
>> > --
>> > Dave Pawson
>> > XSLT XSL-FO FAQ.
>> > Docbook FAQ.
>> > http://www.dpawson.co.uk
>>
>>
>>
>> --
>> Dave Pawson
>> XSLT XSL-FO FAQ.
>> Docbook FAQ.
>> http://www.dpawson.co.uk
>> _______________________________________________
>> pycrypto mailing list
>> pycrypto at lists.dlitz.net
>> http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto
>
>
>
> _______________________________________________
> pycrypto mailing list
> pycrypto at lists.dlitz.net
> http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto
>



-- 
Dave Pawson
XSLT XSL-FO FAQ.
Docbook FAQ.
http://www.dpawson.co.uk

From dave.pawson at gmail.com  Mon Feb  3 06:14:25 2014
From: dave.pawson at gmail.com (Dave Pawson)
Date: Mon, 3 Feb 2014 14:14:25 +0000
Subject: [pycrypto] AES, python 2.7 vs 3
Message-ID: <CAEncD4dJXvFDeKq3aNqQ5vi1VwLDifzZJrDUxyGxaP+eCZrckw@mail.gmail.com>

  iv = ''.join(chr(random.randint(0, 0xFF)) for i in range(16))
    print("key is %d, iv is %d" % (len(key), len(iv)))
    encryptor = AES.new(key, AES.MODE_CBC, iv)

prints 16 bytes for both key and iv.

runs fine under python 2.7.5
Under python 3

key is 16, iv is 16
Traceback (most recent call last):
  File "testNL.py", line 134, in <module>
    encrypt_file(key,plainfile,encfile)
  File "testNL.py", line 40, in encrypt_file
    encryptor = AES.new(key, AES.MODE_CBC, iv)
  File "/usr/lib64/python3.3/site-packages/Crypto/Cipher/AES.py", line
95, in new
    return AESCipher(key, *args, **kwargs)
  File "/usr/lib64/python3.3/site-packages/Crypto/Cipher/AES.py", line
59, in __init__
    blockalgo.BlockAlgo.__init__(self, _AES, key, *args, **kwargs)
  File "/usr/lib64/python3.3/site-packages/Crypto/Cipher/blockalgo.py",
line 141, in __init__
    self._cipher = factory.new(key, *args, **kwargs)
ValueError: IV must be 16 bytes long


yet again the print statement shows 16 for the length of both?

Any suggestions where to start looking please?

DaveP


-- 
Dave Pawson
XSLT XSL-FO FAQ.
Docbook FAQ.
http://www.dpawson.co.uk

From mirko.dziadzka at gmail.com  Mon Feb  3 06:51:06 2014
From: mirko.dziadzka at gmail.com (Mirko Dziadzka)
Date: Mon, 3 Feb 2014 15:51:06 +0100
Subject: [pycrypto] AES, python 2.7 vs 3
In-Reply-To: <CAEncD4dJXvFDeKq3aNqQ5vi1VwLDifzZJrDUxyGxaP+eCZrckw@mail.gmail.com>
References: <CAEncD4dJXvFDeKq3aNqQ5vi1VwLDifzZJrDUxyGxaP+eCZrckw@mail.gmail.com>
Message-ID: <60E10C8A-0D99-498B-8F81-28C942D52960@gmail.com>

Hi

Without testing or verifying:

You should probably use bytes in Python 3, not characters.

> v = ''.join(chr(random.randint(0, 0xFF)) for i in range(16))

creates a string of 16 (unicode) characters in Python 3

iv = os.urandom(16)

creates 16 bytes

    Mirko



From dave.pawson at gmail.com  Mon Feb  3 06:56:24 2014
From: dave.pawson at gmail.com (Dave Pawson)
Date: Mon, 3 Feb 2014 14:56:24 +0000
Subject: [pycrypto] AES, python 2.7 vs 3
In-Reply-To: <60E10C8A-0D99-498B-8F81-28C942D52960@gmail.com>
References: <CAEncD4dJXvFDeKq3aNqQ5vi1VwLDifzZJrDUxyGxaP+eCZrckw@mail.gmail.com>
 <60E10C8A-0D99-498B-8F81-28C942D52960@gmail.com>
Message-ID: <CAEncD4ex63yBS4PGujXBF9G-JjdkfDpmzdB5AUK6whyOF+cvsA@mail.gmail.com>

On 3 February 2014 14:51, Mirko Dziadzka <mirko.dziadzka at gmail.com> wrote:
> Hi
>
> Without testing or verifying:
>
> You should probably use bytes in Python 3, not characters.
>
>> v = ''.join(chr(random.randint(0, 0xFF)) for i in range(16))
>
> creates a string of 16 (unicode) characters in Python 3
>
> iv = os.urandom(16)
>
> creates 16 bytes
>
>     Mirko

Which is what I had (and works fine in 2.7)

iv = Random.new().read(AES.block_size)
seems to work OK in 3.3


regards

-- 
Dave Pawson
XSLT XSL-FO FAQ.
Docbook FAQ.
http://www.dpawson.co.uk

From anurag.chourasia at gmail.com  Wed Feb  5 18:54:31 2014
From: anurag.chourasia at gmail.com (Anurag Chourasia)
Date: Wed, 5 Feb 2014 23:54:31 -0300
Subject: [pycrypto] XML Digital Signature (XML-DSig)
Message-ID: <CANFgmFAYCrhYmJL1_BuYPTh1zAYpYDZhA-uaYU_SJs8ipKp7hw@mail.gmail.com>

Hi All,

Is it possible to digitally sign <http://www.w3.org/TR/xmldsig-core/> a XML
document using the PyCrypto library, provided that I have the certificate
in .pfx format?

A sample signed XML is at http://dpaste.com/1587241

I am a little thin on the concept and appreciate your comments and guidance.

Regards,
Anurag
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.dlitz.net/pipermail/pycrypto/attachments/20140205/2c09ed64/attachment.html>

From dlitz at dlitz.net  Thu Feb  6 08:49:50 2014
From: dlitz at dlitz.net (Dwayne Litzenberger)
Date: Thu, 6 Feb 2014 08:49:50 -0800
Subject: [pycrypto] AES, python 2.7 vs 3
In-Reply-To: <60E10C8A-0D99-498B-8F81-28C942D52960@gmail.com>
References: <CAEncD4dJXvFDeKq3aNqQ5vi1VwLDifzZJrDUxyGxaP+eCZrckw@mail.gmail.com>
 <60E10C8A-0D99-498B-8F81-28C942D52960@gmail.com>
Message-ID: <20140206164950.GB1152@rivest.dlitz.net>

On Mon, Feb 03, 2014 at 03:51:06PM +0100, Mirko Dziadzka wrote:
>Hi
>
>Without testing or verifying:
>
>You should probably use bytes in Python 3, not characters.

Yeah, this is a known bug.   Under Python 3, PyCrypto should raise a 
TypeError in most places where unicode strings are used instead of 
bytes, but right now it just does weird things.  Sorry about that.

-- 
Dwayne C. Litzenberger <dlitz at dlitz.net>
  OpenPGP: 19E1 1FE8 B3CF F273 ED17  4A24 928C EC13 39C2 5CF7

From dlitz at dlitz.net  Thu Feb  6 09:12:31 2014
From: dlitz at dlitz.net (Dwayne Litzenberger)
Date: Thu, 6 Feb 2014 09:12:31 -0800
Subject: [pycrypto] XML Digital Signature (XML-DSig)
In-Reply-To: <CANFgmFAYCrhYmJL1_BuYPTh1zAYpYDZhA-uaYU_SJs8ipKp7hw@mail.gmail.com>
References: <CANFgmFAYCrhYmJL1_BuYPTh1zAYpYDZhA-uaYU_SJs8ipKp7hw@mail.gmail.com>
Message-ID: <20140206171231.GC1152@rivest.dlitz.net>

On Wed, Feb 05, 2014 at 11:54:31PM -0300, Anurag Chourasia wrote:
>Hi All,
>
>Is it possible to digitally sign <http://www.w3.org/TR/xmldsig-core/> a XML
>document using the PyCrypto library, provided that I have the certificate
>in .pfx format?
>
>A sample signed XML is at http://dpaste.com/1587241
>
>I am a little thin on the concept and appreciate your comments and guidance.

Implementing the XML Security spec is way beyond the scope of PyCrypto.  
See https://www.cs.auckland.ac.nz/~pgut001/pubs/xmlsec.txt

It's a really terrible idea anyway.  Individually, X.509 and XML 
Canonicalization are complicated, overengineered specifications.  
Exposing their *combined* complexity to attackers is not advisable.

If, for legacy reasons, you still need to do this, you might be able to 
use an external library (such as pyxmlsec or pyxser) to do most of the 
work, but the only recommendation I can give is "don't do that".


-- 
Dwayne C. Litzenberger <dlitz at dlitz.net>
  OpenPGP: 19E1 1FE8 B3CF F273 ED17  4A24 928C EC13 39C2 5CF7

From dlitz at dlitz.net  Thu Feb  6 09:51:39 2014
From: dlitz at dlitz.net (Dwayne Litzenberger)
Date: Thu, 6 Feb 2014 09:51:39 -0800
Subject: [pycrypto] Need your input: Major modernization;
 dropping legacy Python support?
In-Reply-To: <20131030172448.GB17774@ramacher.at>
References: <20131030060924.GC5005@rivest.dlitz.net>
 <20131030172448.GB17774@ramacher.at>
Message-ID: <20140206175139.GA1741@rivest.dlitz.net>

On Wed, Oct 30, 2013 at 06:24:48PM +0100, Sebastian Ramacher wrote:
>> 2. I'm thinking of pulling in additional dependencies (e.g. cffi),
>> requiring setuptools, and basically joining what the rest of the
>> Python community is doing in 2013.
>>
>> 3. What if src/*.c were removed, and any relevant C code moved into
>> an    independent library, which could be loaded using cffi?  (This
>> is    basically what we need to do to support PyPy properly.)
>
>I wouldn't mind if the C code is moved into a library, however cffi
>doesn't seem to be ready to be used in binary distributions without
>resorting to hacks ([1] for the upstream bug, [2] for a very short
>thread on debian-python). I'm told that this will be fixed in cffi at
>some point.
>
>I've always had a good experience with Cython. What do you thinkg about
>that?
>
>Anyway, as long as we are not starting to use ctypes, I'll be fine.
>Depending on the timeframe of this change, I'd prefer PyCrypto to use
>someting that does not require hacks in binary distributions. If cffi is
>fixed until the change happens, I won't complain.
>
>[1] https://bitbucket.org/cffi/cffi/issue/109/enable-sane-packaging-for-cffi
>[2] https://lists.debian.org/debian-python/2013/10/msg00070.html

ctypes is definitely not on the list.

 From what I understand, CFFI will only try to build binaries if they're 
not already found.  I think as long as packages that use CFFI include 
the appropriate rules in their `setup.py build_ext` process, it 
shouldn't be a problem.  (I'd certainly work with you to make sure the 
packaging isn't a nightmare.)

>> 4. What if Crypto.* became a wrapper around some other crypto library?
>
>This depends on the crypto library you're thinking of. If it's openssl,
>then all the GPL licensed reverse dependencies might have a problem (at
>least in Debian).
>
>> 5. The Apache License 2.0.  What if PyCrypto were licensed under it,
>> or    included dependencies that are licensed under it?
>
>With my Debian maintainer hat on, this would be a problem for me. We
>still ship software that is GPL 2 only that depends on PyCrypto.
>However, GPL 2 and the Apache License 2.0 are incompatible.
>
>Examples of these packages include revelation and pymsnt (I stopped
>searching for GPL 2 only reverse dependencies after I've found two).
>
>Of course, if the license changes or python-crypto starts depending on
>something licensed under Apache 2.0 this needs to be checked on a case by
>case basis, but I'd rather avoid it if there is no really good reason to
>do so.

Ugh, GPL 2 only.  I wish people would at least do "or any later 
version".

I'm thinking of merging with the folks at https://cryptography.io/, 
which is covered by an Apache 2.0 license.  My concern is that there are 
a really small number of good crypto implementers in the FOSS world, and 
we're all working on different projects, so Linus' Law isn't really 
taking effect, to the detriment of our users.

With the increase in direct, state-sponsored attacks on deployed 
cryptosystems, there's a renewed interest in deploying "crypto 
everywhere", but our APIs are all terrible, our implementations are 
questionable, our protocols are error-prone.  I feel that we really need 
to combine our efforts if we want to have any hope of fixing these 
problems so that application developers can provide real security to us 
all.  If it means cutting loose a few rarely-used GPL2-only packages, it 
might be worth it.

How bad is the situation with GPL2-only packages?

-- 
Dwayne C. Litzenberger <dlitz at dlitz.net>
  OpenPGP: 19E1 1FE8 B3CF F273 ED17  4A24 928C EC13 39C2 5CF7

From dlitz at dlitz.net  Thu Feb  6 09:55:24 2014
From: dlitz at dlitz.net (Dwayne Litzenberger)
Date: Thu, 6 Feb 2014 09:55:24 -0800
Subject: [pycrypto] Any progress with pycrypto 2.7?
In-Reply-To: <CAGfyce0tbAYya=84b79eNHQVRhFJvNGv6pxUAKsxqpUOPDhG3A@mail.gmail.com>
References: <CAGfyce0tbAYya=84b79eNHQVRhFJvNGv6pxUAKsxqpUOPDhG3A@mail.gmail.com>
Message-ID: <20140206175524.GD1152@rivest.dlitz.net>

On Mon, Jan 27, 2014 at 10:35:28PM +0100, Legrandin wrote:
>The current alpha1 version contains a few critical bugs which make it
>highly unsuitable for release:
>1) Hard crash on recent recent Intel CPUs (due gcc and AESNI)
>2) Potential DoS when importing an RSA key (segfault of the interpreter)
>3) Silent, incorrect HMAC construction for SHA-2
>
>Is there any chance the relevant patches are applied on the short term?
>It would be great to fix at least the version which is available from
>download from the website.

I'll see if I can find some time this weekend to take care of some of 
these issues.

-- 
Dwayne C. Litzenberger <dlitz at dlitz.net>
  OpenPGP: 19E1 1FE8 B3CF F273 ED17  4A24 928C EC13 39C2 5CF7

From anurag.chourasia at gmail.com  Thu Feb  6 20:10:07 2014
From: anurag.chourasia at gmail.com (Anurag Chourasia)
Date: Fri, 7 Feb 2014 01:10:07 -0300
Subject: [pycrypto] Public Key (X.509) in Modulus/Exponent Format
Message-ID: <CANFgmFAHKh_P_pGG-wYm9j+jEqeeMFk2ZSoOMGEMQOUmOqN7ZA@mail.gmail.com>

Hi All,

Is it possible to get a Modulus Exponent representation of the public key
(X.509) using PyCrypto?

For example, the X.509 is

*-----BEGIN CERTIFICATE-----
MIICLDCCAZWgAwIBAgIQRjRrx4AAVrwR024uxBCzsDANBgkqhkiG9w0BAQUFADAS
MRAwDgYDVQQDEwdDYXJsUlNBMB4XDTk5MDkxOTAxMDg0N1oXDTM5MTIzMTIzNTk1
OVowEzERMA8GA1UEAxMIQWxpY2VSU0EwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJ
AoGBAOCJczmN2PX16Id2OX9OsAW7U4PeD7er3H3HdSkNBS5tEt+mhibU0m+qWCn8
l+z6glEPMIC+sVCeRkTxLLvYMs/GaG8H2bBgrL7uNAlqE/X3BQWT3166NVbZYf8Z
f8mB5vhs6odAcO+sbSx0ny36VTq5mXcCpkhSjE7zVzhXdFdfAgMBAAGjgYEwfzAM
BgNVHRMBAf8EAjAAMA4GA1UdDwEB/wQEAwIGwDAfBgNVHSMEGDAWgBTp4JAnrHgg
eprTTPJCN04irp44uzAdBgNVHQ4EFgQUd9K00bdMioqjzkWdzuw8oDrj/1AwHwYD
VR0RBBgwFoEUQWxpY2VSU0FAZXhhbXBsZS5jb20wDQYJKoZIhvcNAQEFBQADgYEA
PnBHqEjME1iPylFxa042GF0EfoCxjU3MyqOPzH1WyLzPbrMcWakgqgWBqE4lradw
FHUv9ceb0Q7pY9Jkt8ZmbnMhVN/0uiVdfUnTlGsiNnRzuErsL2Tt0z3Sp0LF6DeK
tNufZ+S9n/n+dO/q+e5jatg/SyUJtdgadq7rm9tJsCI=
-----END CERTIFICATE-----*

And i need to get to the following representation

*<RSAKeyValue>
  <Modulus>
    4IlzOY3Y9fXoh3Y5f06wBbtTg94Pt6vcfcd1KQ0FLm0S36aGJtTSb6pYKfyX7PqCUQ8wgL6xUJ5GRPEsu9gyz8
    ZobwfZsGCsvu40CWoT9fcFBZPfXro1Vtlh/xl/yYHm+Gzqh0Bw76xtLHSfLfpVOrmZdwKmSFKMTvNXOFd0V18=
  </Modulus>
  <Exponent>AQAB</Exponent>
</RSAKeyValue>*

Please guide.

Regards,
Anurag
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.dlitz.net/pipermail/pycrypto/attachments/20140207/43006f21/attachment.html>

From dave.pawson at gmail.com  Thu Feb  6 22:29:31 2014
From: dave.pawson at gmail.com (Dave Pawson)
Date: Fri, 7 Feb 2014 06:29:31 +0000
Subject: [pycrypto] AES, python 2.7 vs 3
In-Reply-To: <20140206164950.GB1152@rivest.dlitz.net>
References: <CAEncD4dJXvFDeKq3aNqQ5vi1VwLDifzZJrDUxyGxaP+eCZrckw@mail.gmail.com>
 <60E10C8A-0D99-498B-8F81-28C942D52960@gmail.com>
 <20140206164950.GB1152@rivest.dlitz.net>
Message-ID: <CAEncD4d=BH1Z6GA-dJ2Yf6Dqgjoh4Z1D1=xMW1mcukCEU4d40A@mail.gmail.com>

On 6 February 2014 16:49, Dwayne Litzenberger <dlitz at dlitz.net> wrote:
> On Mon, Feb 03, 2014 at 03:51:06PM +0100, Mirko Dziadzka wrote:
>>
>> Hi
>>
>> Without testing or verifying:
>>
>> You should probably use bytes in Python 3, not characters.
>
>
> Yeah, this is a known bug.   Under Python 3, PyCrypto should raise a
> TypeError in most places where unicode strings are used instead of bytes,
> but right now it just does weird things.  Sorry about that.


Recently playing about with reading / writing between Linux / Windows,
one symptom I came across was that the decrypted string contained b' <string>'
is that a part of this bug?


regards



-- 
Dave Pawson
XSLT XSL-FO FAQ.
Docbook FAQ.
http://www.dpawson.co.uk

From helderijs at gmail.com  Fri Feb  7 02:52:49 2014
From: helderijs at gmail.com (Legrandin)
Date: Fri, 7 Feb 2014 11:52:49 +0100
Subject: [pycrypto] Public Key (X.509) in Modulus/Exponent Format
In-Reply-To: <CANFgmFAHKh_P_pGG-wYm9j+jEqeeMFk2ZSoOMGEMQOUmOqN7ZA@mail.gmail.com>
References: <CANFgmFAHKh_P_pGG-wYm9j+jEqeeMFk2ZSoOMGEMQOUmOqN7ZA@mail.gmail.com>
Message-ID: <CAGfyce0JvX1PRSVeobsxrqM8X+F-pv2tWzy0g=0grCDS45K3ew@mail.gmail.com>

Hi,

This answer on stackoverflow shows how you can read the RSA public key
embedded in a PEM X.509 certificate:

http://stackoverflow.com/questions/12911373/how-do-i-use-a-x509-certificate-with-pycrypto

Once you have loaded the RSA public key, you can get modulus and
exponent in the way you need with something like this:

from Crypto.Util.number import long_to_bytes
import base64

for part in rsa_key.n, rsa_key.e:
    print base64.b64encode(long_to_bytes(part))

2014-02-07 5:10 GMT+01:00 Anurag Chourasia <anurag.chourasia at gmail.com>:
> Hi All,
>
> Is it possible to get a Modulus Exponent representation of the public key
> (X.509) using PyCrypto?
>
> For example, the X.509 is
>
> -----BEGIN CERTIFICATE-----
> MIICLDCCAZWgAwIBAgIQRjRrx4AAVrwR024uxBCzsDANBgkqhkiG9w0BAQUFADAS
> MRAwDgYDVQQDEwdDYXJsUlNBMB4XDTk5MDkxOTAxMDg0N1oXDTM5MTIzMTIzNTk1
> OVowEzERMA8GA1UEAxMIQWxpY2VSU0EwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJ
> AoGBAOCJczmN2PX16Id2OX9OsAW7U4PeD7er3H3HdSkNBS5tEt+mhibU0m+qWCn8
> l+z6glEPMIC+sVCeRkTxLLvYMs/GaG8H2bBgrL7uNAlqE/X3BQWT3166NVbZYf8Z
> f8mB5vhs6odAcO+sbSx0ny36VTq5mXcCpkhSjE7zVzhXdFdfAgMBAAGjgYEwfzAM
> BgNVHRMBAf8EAjAAMA4GA1UdDwEB/wQEAwIGwDAfBgNVHSMEGDAWgBTp4JAnrHgg
> eprTTPJCN04irp44uzAdBgNVHQ4EFgQUd9K00bdMioqjzkWdzuw8oDrj/1AwHwYD
> VR0RBBgwFoEUQWxpY2VSU0FAZXhhbXBsZS5jb20wDQYJKoZIhvcNAQEFBQADgYEA
> PnBHqEjME1iPylFxa042GF0EfoCxjU3MyqOPzH1WyLzPbrMcWakgqgWBqE4lradw
> FHUv9ceb0Q7pY9Jkt8ZmbnMhVN/0uiVdfUnTlGsiNnRzuErsL2Tt0z3Sp0LF6DeK
> tNufZ+S9n/n+dO/q+e5jatg/SyUJtdgadq7rm9tJsCI=
> -----END CERTIFICATE-----
>
> And i need to get to the following representation
>
> <RSAKeyValue>
>   <Modulus>
>
> 4IlzOY3Y9fXoh3Y5f06wBbtTg94Pt6vcfcd1KQ0FLm0S36aGJtTSb6pYKfyX7PqCUQ8wgL6xUJ5GRPEsu9gyz8
>
> ZobwfZsGCsvu40CWoT9fcFBZPfXro1Vtlh/xl/yYHm+Gzqh0Bw76xtLHSfLfpVOrmZdwKmSFKMTvNXOFd0V18=
>   </Modulus>
>   <Exponent>AQAB</Exponent>
> </RSAKeyValue>
>
> Please guide.
>
> Regards,
> Anurag
>
> _______________________________________________
> pycrypto mailing list
> pycrypto at lists.dlitz.net
> http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto
>

From Paul_Koning at Dell.com  Fri Feb  7 08:26:43 2014
From: Paul_Koning at Dell.com (Paul_Koning at Dell.com)
Date: Fri, 7 Feb 2014 16:26:43 +0000
Subject: [pycrypto] AES, python 2.7 vs 3
In-Reply-To: <CAEncD4d=BH1Z6GA-dJ2Yf6Dqgjoh4Z1D1=xMW1mcukCEU4d40A@mail.gmail.com>
References: <CAEncD4dJXvFDeKq3aNqQ5vi1VwLDifzZJrDUxyGxaP+eCZrckw@mail.gmail.com>
 <60E10C8A-0D99-498B-8F81-28C942D52960@gmail.com>
 <20140206164950.GB1152@rivest.dlitz.net>
 <CAEncD4d=BH1Z6GA-dJ2Yf6Dqgjoh4Z1D1=xMW1mcukCEU4d40A@mail.gmail.com>
Message-ID: <C75A84166056C94F84D238A44AF9F6AD06ED0FB4@AUSX10MPC103.AMER.DELL.COM>


On Feb 7, 2014, at 1:29 AM, Dave Pawson <dave.pawson at gmail.com> wrote:

> On 6 February 2014 16:49, Dwayne Litzenberger <dlitz at dlitz.net> wrote:
>> On Mon, Feb 03, 2014 at 03:51:06PM +0100, Mirko Dziadzka wrote:
>>> 
>>> Hi
>>> 
>>> Without testing or verifying:
>>> 
>>> You should probably use bytes in Python 3, not characters.
>> 
>> 
>> Yeah, this is a known bug.   Under Python 3, PyCrypto should raise a
>> TypeError in most places where unicode strings are used instead of bytes,
>> but right now it just does weird things.  Sorry about that.
> 
> 
> Recently playing about with reading / writing between Linux / Windows,
> one symptom I came across was that the decrypted string contained b' <string>'
> is that a part of this bug?

b?something? is Python 3 syntax for a ?bytes? literal.

It?s a good idea to spend some time reading the Python 3 documentation on text vs. bytes ? ?str? vs. ?bytes? type.  They really got this right, and it completely cures the ugly mess you get in Python 2 when dealing with strings vs. their encoding.

But it is new, and it?s different from what was done before ? for good reasons.

One short summary is: ?str? contains text, it?s abstract, it represents Unicode characters but does not talk about encoding.  ?bytes? contains sequences of bytes (octets ? 8 bit integers), it?s concrete, it represents encoding of data in the outside world.  You convert ?str? to/from ?bytes? when doing I/O.  Anytime you are doing operations that need sequences of bytes, the type has to be ?bytes?.  Encryption is one such operation.

	paul

From dave.pawson at gmail.com  Fri Feb  7 08:47:21 2014
From: dave.pawson at gmail.com (Dave Pawson)
Date: Fri, 7 Feb 2014 16:47:21 +0000
Subject: [pycrypto] AES, python 2.7 vs 3
In-Reply-To: <C75A84166056C94F84D238A44AF9F6AD06ED0FB4@AUSX10MPC103.AMER.DELL.COM>
References: <CAEncD4dJXvFDeKq3aNqQ5vi1VwLDifzZJrDUxyGxaP+eCZrckw@mail.gmail.com>
 <60E10C8A-0D99-498B-8F81-28C942D52960@gmail.com>
 <20140206164950.GB1152@rivest.dlitz.net>
 <CAEncD4d=BH1Z6GA-dJ2Yf6Dqgjoh4Z1D1=xMW1mcukCEU4d40A@mail.gmail.com>
 <C75A84166056C94F84D238A44AF9F6AD06ED0FB4@AUSX10MPC103.AMER.DELL.COM>
Message-ID: <CAEncD4fTL4keSGxiyWWh7DN4AVpxC+i6y11fXYC7MKQm2i66Sg@mail.gmail.com>

Thanks Paul. I was going along those lines, but without much understanding?
Is it correct that pycrypto relies on byte strings and *cannot* deal
with Unicode strings?

regards

On 7 February 2014 16:26,  <Paul_Koning at dell.com> wrote:
>
> On Feb 7, 2014, at 1:29 AM, Dave Pawson <dave.pawson at gmail.com> wrote:
>
>> On 6 February 2014 16:49, Dwayne Litzenberger <dlitz at dlitz.net> wrote:
>>> On Mon, Feb 03, 2014 at 03:51:06PM +0100, Mirko Dziadzka wrote:
>>>>
>>>> Hi
>>>>
>>>> Without testing or verifying:
>>>>
>>>> You should probably use bytes in Python 3, not characters.
>>>
>>>
>>> Yeah, this is a known bug.   Under Python 3, PyCrypto should raise a
>>> TypeError in most places where unicode strings are used instead of bytes,
>>> but right now it just does weird things.  Sorry about that.
>>
>>
>> Recently playing about with reading / writing between Linux / Windows,
>> one symptom I came across was that the decrypted string contained b' <string>'
>> is that a part of this bug?
>
> b?something? is Python 3 syntax for a ?bytes? literal.
>
> It?s a good idea to spend some time reading the Python 3 documentation on text vs. bytes ? ?str? vs. ?bytes? type.  They really got this right, and it completely cures the ugly mess you get in Python 2 when dealing with strings vs. their encoding.
>
> But it is new, and it?s different from what was done before ? for good reasons.
>
> One short summary is: ?str? contains text, it?s abstract, it represents Unicode characters but does not talk about encoding.  ?bytes? contains sequences of bytes (octets ? 8 bit integers), it?s concrete, it represents encoding of data in the outside world.  You convert ?str? to/from ?bytes? when doing I/O.  Anytime you are doing operations that need sequences of bytes, the type has to be ?bytes?.  Encryption is one such operation.
>
>         paul
> _______________________________________________
> pycrypto mailing list
> pycrypto at lists.dlitz.net
> http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto



-- 
Dave Pawson
XSLT XSL-FO FAQ.
Docbook FAQ.
http://www.dpawson.co.uk

From Paul_Koning at Dell.com  Fri Feb  7 09:01:04 2014
From: Paul_Koning at Dell.com (Paul_Koning at Dell.com)
Date: Fri, 7 Feb 2014 17:01:04 +0000
Subject: [pycrypto] AES, python 2.7 vs 3
In-Reply-To: <CAEncD4fTL4keSGxiyWWh7DN4AVpxC+i6y11fXYC7MKQm2i66Sg@mail.gmail.com>
References: <CAEncD4dJXvFDeKq3aNqQ5vi1VwLDifzZJrDUxyGxaP+eCZrckw@mail.gmail.com>
 <60E10C8A-0D99-498B-8F81-28C942D52960@gmail.com>
 <20140206164950.GB1152@rivest.dlitz.net>
 <CAEncD4d=BH1Z6GA-dJ2Yf6Dqgjoh4Z1D1=xMW1mcukCEU4d40A@mail.gmail.com>
 <C75A84166056C94F84D238A44AF9F6AD06ED0FB4@AUSX10MPC103.AMER.DELL.COM>
 <CAEncD4fTL4keSGxiyWWh7DN4AVpxC+i6y11fXYC7MKQm2i66Sg@mail.gmail.com>
Message-ID: <C75A84166056C94F84D238A44AF9F6AD06ED1633@AUSX10MPC103.AMER.DELL.COM>

That?s what pycrypto needs to do, yes.  From what Dwayne says, it sounds like that?s currently not finished yet.

The easiest way to look at this is as a data type matching exercise.  Cryptographic operations are functions that operate on sequences of bytes.  Unicode strings are NOT sequences of bytes ? they are an entirely different data type.

It is valid to speak of specific encodings of Unicode strings as sequences of bytes, but the key point is that you have to do the encoding ? which means, first of all, choosing WHICH encoding ? in order to have that sequence of bytes.

Since you have to make those choices, it?s not safe for APIs like crypto to accept strings and effectively do some encoding as a side effect.  Better to require bytes in the interface, and let you handle the encode/decode steps explicitly, in the way you want them to be done.

	paul

On Feb 7, 2014, at 11:47 AM, Dave Pawson <dave.pawson at gmail.com> wrote:

> Thanks Paul. I was going along those lines, but without much understanding?
> Is it correct that pycrypto relies on byte strings and *cannot* deal
> with Unicode strings?
> 
> regards
> 
> On 7 February 2014 16:26,  <Paul_Koning at dell.com> wrote:
>> 
>> On Feb 7, 2014, at 1:29 AM, Dave Pawson <dave.pawson at gmail.com> wrote:
>> 
>>> On 6 February 2014 16:49, Dwayne Litzenberger <dlitz at dlitz.net> wrote:
>>>> On Mon, Feb 03, 2014 at 03:51:06PM +0100, Mirko Dziadzka wrote:
>>>>> 
>>>>> Hi
>>>>> 
>>>>> Without testing or verifying:
>>>>> 
>>>>> You should probably use bytes in Python 3, not characters.
>>>> 
>>>> 
>>>> Yeah, this is a known bug.   Under Python 3, PyCrypto should raise a
>>>> TypeError in most places where unicode strings are used instead of bytes,
>>>> but right now it just does weird things.  Sorry about that.
>>> 
>>> 
>>> Recently playing about with reading / writing between Linux / Windows,
>>> one symptom I came across was that the decrypted string contained b' <string>'
>>> is that a part of this bug?
>> 
>> b?something? is Python 3 syntax for a ?bytes? literal.
>> 
>> It?s a good idea to spend some time reading the Python 3 documentation on text vs. bytes ? ?str? vs. ?bytes? type.  They really got this right, and it completely cures the ugly mess you get in Python 2 when dealing with strings vs. their encoding.
>> 
>> But it is new, and it?s different from what was done before ? for good reasons.
>> 
>> One short summary is: ?str? contains text, it?s abstract, it represents Unicode characters but does not talk about encoding.  ?bytes? contains sequences of bytes (octets ? 8 bit integers), it?s concrete, it represents encoding of data in the outside world.  You convert ?str? to/from ?bytes? when doing I/O.  Anytime you are doing operations that need sequences of bytes, the type has to be ?bytes?.  Encryption is one such operation.
>> 
>>        paul
>> _______________________________________________
>> pycrypto mailing list
>> pycrypto at lists.dlitz.net
>> http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto
> 
> 
> 
> -- 
> Dave Pawson
> XSLT XSL-FO FAQ.
> Docbook FAQ.
> http://www.dpawson.co.uk
> _______________________________________________
> pycrypto mailing list
> pycrypto at lists.dlitz.net
> http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto

From dave.pawson at gmail.com  Sat Feb  8 00:25:02 2014
From: dave.pawson at gmail.com (Dave Pawson)
Date: Sat, 8 Feb 2014 08:25:02 +0000
Subject: [pycrypto] AES, python 2.7 vs 3
In-Reply-To: <C75A84166056C94F84D238A44AF9F6AD06ED1633@AUSX10MPC103.AMER.DELL.COM>
References: <CAEncD4dJXvFDeKq3aNqQ5vi1VwLDifzZJrDUxyGxaP+eCZrckw@mail.gmail.com>
 <60E10C8A-0D99-498B-8F81-28C942D52960@gmail.com>
 <20140206164950.GB1152@rivest.dlitz.net>
 <CAEncD4d=BH1Z6GA-dJ2Yf6Dqgjoh4Z1D1=xMW1mcukCEU4d40A@mail.gmail.com>
 <C75A84166056C94F84D238A44AF9F6AD06ED0FB4@AUSX10MPC103.AMER.DELL.COM>
 <CAEncD4fTL4keSGxiyWWh7DN4AVpxC+i6y11fXYC7MKQm2i66Sg@mail.gmail.com>
 <C75A84166056C94F84D238A44AF9F6AD06ED1633@AUSX10MPC103.AMER.DELL.COM>
Message-ID: <CAEncD4cFFA+wa15+W0bqQWU6xuu42b=dvAZVcZd7qPM1beyB+g@mail.gmail.com>

On 7 February 2014 17:01,  <Paul_Koning at dell.com> wrote:
> That?s what pycrypto needs to do, yes.  From what Dwayne says, it sounds like that?s currently not finished yet.
>
> The easiest way to look at this is as a data type matching exercise.  Cryptographic operations are functions that operate on sequences of bytes.  Unicode strings are NOT sequences of bytes ? they are an entirely different data type.

How (if at all) does that statement change if I am using unicode,
utf-8 encoding please Paul?
As I understand it, utf-8 constitutes octets? Or am I wrong?


>
> It is valid to speak of specific encodings of Unicode strings as sequences of bytes, but the key point is that you have to do the encoding ? which means, first of all, choosing WHICH encoding ? in order to have that sequence of bytes.

And how does that match with Python 3, which (appears |  is) based on
Unicode strings?


>
> Since you have to make those choices, it?s not safe for APIs like crypto to accept strings and effectively do some encoding as a side effect.  Better to require bytes in the interface, and let you handle the encode/decode steps explicitly, in the way you want them to be done.


Thanks for that Paul... you seem to be pointing at Pycrypto as the
source of my problem. An approach paper / web page would be very
helpful to me (and others facing the same issues) in managing this
slippery (to me) aspect of crypto.

Again, thanks for the comments.

DaveP


>
>         paul
>
> On Feb 7, 2014, at 11:47 AM, Dave Pawson <dave.pawson at gmail.com> wrote:
>
>> Thanks Paul. I was going along those lines, but without much understanding?
>> Is it correct that pycrypto relies on byte strings and *cannot* deal
>> with Unicode strings?
>>
>> regards
>>
>> On 7 February 2014 16:26,  <Paul_Koning at dell.com> wrote:
>>>
>>> On Feb 7, 2014, at 1:29 AM, Dave Pawson <dave.pawson at gmail.com> wrote:
>>>
>>>> On 6 February 2014 16:49, Dwayne Litzenberger <dlitz at dlitz.net> wrote:
>>>>> On Mon, Feb 03, 2014 at 03:51:06PM +0100, Mirko Dziadzka wrote:
>>>>>>
>>>>>> Hi
>>>>>>
>>>>>> Without testing or verifying:
>>>>>>
>>>>>> You should probably use bytes in Python 3, not characters.
>>>>>
>>>>>
>>>>> Yeah, this is a known bug.   Under Python 3, PyCrypto should raise a
>>>>> TypeError in most places where unicode strings are used instead of bytes,
>>>>> but right now it just does weird things.  Sorry about that.
>>>>
>>>>
>>>> Recently playing about with reading / writing between Linux / Windows,
>>>> one symptom I came across was that the decrypted string contained b' <string>'
>>>> is that a part of this bug?
>>>
>>> b?something? is Python 3 syntax for a ?bytes? literal.
>>>
>>> It?s a good idea to spend some time reading the Python 3 documentation on text vs. bytes ? ?str? vs. ?bytes? type.  They really got this right, and it completely cures the ugly mess you get in Python 2 when dealing with strings vs. their encoding.
>>>
>>> But it is new, and it?s different from what was done before ? for good reasons.
>>>
>>> One short summary is: ?str? contains text, it?s abstract, it represents Unicode characters but does not talk about encoding.  ?bytes? contains sequences of bytes (octets ? 8 bit integers), it?s concrete, it represents encoding of data in the outside world.  You convert ?str? to/from ?bytes? when doing I/O.  Anytime you are doing operations that need sequences of bytes, the type has to be ?bytes?.  Encryption is one such operation.
>>>
>>>        paul
>>> _______________________________________________
>>> pycrypto mailing list
>>> pycrypto at lists.dlitz.net
>>> http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto
>>
>>
>>
>> --
>> Dave Pawson
>> XSLT XSL-FO FAQ.
>> Docbook FAQ.
>> http://www.dpawson.co.uk
>> _______________________________________________
>> pycrypto mailing list
>> pycrypto at lists.dlitz.net
>> http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto
> _______________________________________________
> pycrypto mailing list
> pycrypto at lists.dlitz.net
> http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto



-- 
Dave Pawson
XSLT XSL-FO FAQ.
Docbook FAQ.
http://www.dpawson.co.uk

From Paul_Koning at Dell.com  Mon Feb 10 08:40:53 2014
From: Paul_Koning at Dell.com (Paul_Koning at Dell.com)
Date: Mon, 10 Feb 2014 16:40:53 +0000
Subject: [pycrypto] AES, python 2.7 vs 3
In-Reply-To: <CAEncD4cFFA+wa15+W0bqQWU6xuu42b=dvAZVcZd7qPM1beyB+g@mail.gmail.com>
References: <CAEncD4dJXvFDeKq3aNqQ5vi1VwLDifzZJrDUxyGxaP+eCZrckw@mail.gmail.com>
 <60E10C8A-0D99-498B-8F81-28C942D52960@gmail.com>
 <20140206164950.GB1152@rivest.dlitz.net>
 <CAEncD4d=BH1Z6GA-dJ2Yf6Dqgjoh4Z1D1=xMW1mcukCEU4d40A@mail.gmail.com>
 <C75A84166056C94F84D238A44AF9F6AD06ED0FB4@AUSX10MPC103.AMER.DELL.COM>
 <CAEncD4fTL4keSGxiyWWh7DN4AVpxC+i6y11fXYC7MKQm2i66Sg@mail.gmail.com>
 <C75A84166056C94F84D238A44AF9F6AD06ED1633@AUSX10MPC103.AMER.DELL.COM>
 <CAEncD4cFFA+wa15+W0bqQWU6xuu42b=dvAZVcZd7qPM1beyB+g@mail.gmail.com>
Message-ID: <C75A84166056C94F84D238A44AF9F6AD06ED39B1@AUSX10MPC103.AMER.DELL.COM>


On Feb 8, 2014, at 3:25 AM, Dave Pawson <dave.pawson at gmail.com> wrote:

> On 7 February 2014 17:01,  <Paul_Koning at dell.com> wrote:
>> That?s what pycrypto needs to do, yes.  From what Dwayne says, it sounds like that?s currently not finished yet.
>> 
>> The easiest way to look at this is as a data type matching exercise.  Cryptographic operations are functions that operate on sequences of bytes.  Unicode strings are NOT sequences of bytes ? they are an entirely different data type.
> 
> How (if at all) does that statement change if I am using unicode,
> utf-8 encoding please Paul?
> As I understand it, utf-8 constitutes octets? Or am I wrong?

Yes, UTF-8 is one of several encodings you can use for Unicode.  It?s probably the most popular one for a variety of reasons.  So unless you have a reason to do otherwise, UTF-8 is a good default choice for encoding of Unicode strings.

> 
> 
>> 
>> It is valid to speak of specific encodings of Unicode strings as sequences of bytes, but the key point is that you have to do the encoding ? which means, first of all, choosing WHICH encoding ? in order to have that sequence of bytes.
> 
> And how does that match with Python 3, which (appears |  is) based on
> Unicode strings?

The ?str? type is Unicode.  To turn it into ?bytes? ? for I/O, for crypto, or for other purposes that need octet strings, you have to encode the Unicode.  As I mentioned, UTF-8 is a typical choice, but if you had a reason for using something else, you would specify that encoding instead.

For example:
$ python3
>>> s="foo"
>>> type(s)
<class 'str'>
>>> b=s.encode("utf-8")
>>> type(b)
<class 'bytes'>
>>> b
b'foo'
>>> s="a??"
>>> b=s.encode("utf-8")
>>> b
b'a\xc3\xa9\xc3\xb6'

> 
> 
>> 
>> Since you have to make those choices, it?s not safe for APIs like crypto to accept strings and effectively do some encoding as a side effect.  Better to require bytes in the interface, and let you handle the encode/decode steps explicitly, in the way you want them to be done.
> 
> 
> Thanks for that Paul... you seem to be pointing at Pycrypto as the
> source of my problem. An approach paper / web page would be very
> helpful to me (and others facing the same issues) in managing this
> slippery (to me) aspect of crypto.
> 
> Again, thanks for the comments.

This http://docs.python.org/3/howto/unicode.html might be helpful for a much more detailed explanation of what I?ve been talking about.

	paul

From dlitz at dlitz.net  Fri Feb 21 20:34:09 2014
From: dlitz at dlitz.net (Dwayne Litzenberger)
Date: Fri, 21 Feb 2014 20:34:09 -0800
Subject: [pycrypto] Any progress with pycrypto 2.7?
In-Reply-To: <CAGfyce0tbAYya=84b79eNHQVRhFJvNGv6pxUAKsxqpUOPDhG3A@mail.gmail.com>
References: <CAGfyce0tbAYya=84b79eNHQVRhFJvNGv6pxUAKsxqpUOPDhG3A@mail.gmail.com>
Message-ID: <20140222043409.GA26458@rivest.dlitz.net>

For reference, here are the relevant bugs and/or pull requests, where 
discussion is taking place.  I've added comments to all three.

>1) Hard crash on recent recent Intel CPUs (due gcc and AESNI)

https://github.com/dlitz/pycrypto/pull/62

>2) Potential DoS when importing an RSA key (segfault of the interpreter)

I assume you mean the floating-point exception that occurs when you pass 
an even modulus to RSA.construct?

https://bugs.launchpad.net/pycrypto/+bug/1193521
https://github.com/dlitz/pycrypto/pull/50

On pull request #50 ("Add checks to verify correctness of 
RSA/DSA/ElGamal keys"), it would be helpful if others could chime in 
about the potential for leaking private keys via timing side-channels.

>3) Silent, incorrect HMAC construction for SHA-2

https://bugs.launchpad.net/pycrypto/+bug/1209399
https://github.com/dlitz/pycrypto/pull/57

-- 
Dwayne C. Litzenberger <dlitz at dlitz.net>
  OpenPGP: 19E1 1FE8 B3CF F273 ED17  4A24 928C EC13 39C2 5CF7

From sebastian+lists at ramacher.at  Sat Feb 22 12:50:50 2014
From: sebastian+lists at ramacher.at (Sebastian Ramacher)
Date: Sat, 22 Feb 2014 21:50:50 +0100
Subject: [pycrypto] Need your input: Major modernization;
 dropping legacy Python support?
In-Reply-To: <20140206175139.GA1741@rivest.dlitz.net>
References: <20131030060924.GC5005@rivest.dlitz.net>
 <20131030172448.GB17774@ramacher.at>
 <20140206175139.GA1741@rivest.dlitz.net>
Message-ID: <20140222205050.GC7112@ramacher.at>

On 2014-02-06 09:51:39, Dwayne Litzenberger wrote:
> On Wed, Oct 30, 2013 at 06:24:48PM +0100, Sebastian Ramacher wrote:
> >>2. I'm thinking of pulling in additional dependencies (e.g. cffi),
> >>requiring setuptools, and basically joining what the rest of the
> >>Python community is doing in 2013.
> >>
> >>3. What if src/*.c were removed, and any relevant C code moved into
> >>an    independent library, which could be loaded using cffi?  (This
> >>is    basically what we need to do to support PyPy properly.)
> >
> >I wouldn't mind if the C code is moved into a library, however cffi
> >doesn't seem to be ready to be used in binary distributions without
> >resorting to hacks ([1] for the upstream bug, [2] for a very short
> >thread on debian-python). I'm told that this will be fixed in cffi at
> >some point.
> >
> >I've always had a good experience with Cython. What do you thinkg about
> >that?
> >
> >Anyway, as long as we are not starting to use ctypes, I'll be fine.
> >Depending on the timeframe of this change, I'd prefer PyCrypto to use
> >someting that does not require hacks in binary distributions. If cffi is
> >fixed until the change happens, I won't complain.
> >
> >[1] https://bitbucket.org/cffi/cffi/issue/109/enable-sane-packaging-for-cffi
> >[2] https://lists.debian.org/debian-python/2013/10/msg00070.html
> 
> ctypes is definitely not on the list.
> 
> From what I understand, CFFI will only try to build binaries if
> they're not already found.  I think as long as packages that use
> CFFI include the appropriate rules in their `setup.py build_ext`
> process, it shouldn't be a problem.  (I'd certainly work with you to
> make sure the packaging isn't a nightmare.)

cffi 0.8 has been released in the meantime. I hope the issues have been
fixed, but I haven't had the time to check out the new version.

> >>4. What if Crypto.* became a wrapper around some other crypto library?
> >
> >This depends on the crypto library you're thinking of. If it's openssl,
> >then all the GPL licensed reverse dependencies might have a problem (at
> >least in Debian).
> >
> >>5. The Apache License 2.0.  What if PyCrypto were licensed under it,
> >>or    included dependencies that are licensed under it?
> >
> >With my Debian maintainer hat on, this would be a problem for me. We
> >still ship software that is GPL 2 only that depends on PyCrypto.
> >However, GPL 2 and the Apache License 2.0 are incompatible.
> >
> >Examples of these packages include revelation and pymsnt (I stopped
> >searching for GPL 2 only reverse dependencies after I've found two).
> >
> >Of course, if the license changes or python-crypto starts depending on
> >something licensed under Apache 2.0 this needs to be checked on a case by
> >case basis, but I'd rather avoid it if there is no really good reason to
> >do so.
> 
> Ugh, GPL 2 only.  I wish people would at least do "or any later
> version".
> 
> I'm thinking of merging with the folks at https://cryptography.io/,
> which is covered by an Apache 2.0 license.

What is the merge going to look like?

> How bad is the situation with GPL2-only packages?

I'll check the reverse dependencies in a couple of days.

Regards
-- 
Sebastian Ramacher
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.dlitz.net/pipermail/pycrypto/attachments/20140222/0da79cc2/attachment.sig>

From helderijs at gmail.com  Tue Mar  4 13:25:25 2014
From: helderijs at gmail.com (Legrandin)
Date: Tue, 4 Mar 2014 22:25:25 +0100
Subject: [pycrypto] Any progress with pycrypto 2.7?
In-Reply-To: <20140222043409.GA26458@rivest.dlitz.net>
References: <CAGfyce0tbAYya=84b79eNHQVRhFJvNGv6pxUAKsxqpUOPDhG3A@mail.gmail.com>
 <20140222043409.GA26458@rivest.dlitz.net>
Message-ID: <CAGfyce3Gkov=o1iLBNt+ebM6t++Vw-4m1BFg=8yg4vGysq_gsQ@mail.gmail.com>

>> 2) Potential DoS when importing an RSA key (segfault of the interpreter)
> I assume you mean the floating-point exception that occurs when you pass an
> even modulus to RSA.construct?

Correct.

> https://bugs.launchpad.net/pycrypto/+bug/1193521
> https://github.com/dlitz/pycrypto/pull/50
>
> On pull request #50 ("Add checks to verify correctness of RSA/DSA/ElGamal
> keys"), it would be helpful if others could chime in about the potential for
> leaking private keys via timing side-channels.

In addition to fixing the DoS, PR #50 also replaced the custom
KeyFormatError exception with ValueError in the DSA code (I wrote it
before you expressed preference for not having custom exceptions at
all).

I would actually apply first this other PR:

https://github.com/dlitz/pycrypto/pull/71

Since there are 2 other exception types to fix.
Hopefully PR #50 still applies cleanly after it.

From wanggang at goldenapptechnology.com  Tue Mar 11 20:22:14 2014
From: wanggang at goldenapptechnology.com (wanggang)
Date: Wed, 12 Mar 2014 11:22:14 +0800
Subject: [pycrypto] Got different PKCS1_v1_5 signature result on the same
	message & same rsa key pair
Message-ID: <201403121122133419764@goldenapptechnology.com>

Hi pycrypto,

This may be a simple problem since I am a newbiee to crypto.
I am not sure why I got different result from PKCS1_v1_5.new(RSA.construct(lst)).sign(SHA.new(a2b(m))) , 
I have mentioned the 'stateful' comment in API doc, but still can't fix the code below.
besides I have used DES for a lot, & never got stuck in such situation.

if __name__ == "__main__":
    t = (modulus, publicExponent, privateExponent, prime1, prime2, coefficient)
    lst = [long(x,16) for x in t]

    k = '1234'
    e1 = RSA.construct(lst).encrypt(m, k)
    e2 = RSA.construct(lst).encrypt(m, k)
    assert e1 == e2 # passed
    
    signature1 = PKCS1_v1_5.new(RSA.construct(lst)).sign(SHA.new(a2b(m)))
    print binascii.b2a_hex(signature1)
    signature2 = PKCS1_v1_5.new(RSA.construct(lst)).sign(SHA.new(a2b(m)))
    print binascii.b2a_hex(signature2)
    assert signature1==signature2 # why this assertion failed ?

Thank you in advance!    
--------------
 Wang Gang

From campadrenalin at gmail.com  Tue Mar 11 22:55:16 2014
From: campadrenalin at gmail.com (Philip Horger)
Date: Tue, 11 Mar 2014 22:55:16 -0700
Subject: [pycrypto] Got different PKCS1_v1_5 signature result on the
 same message & same rsa key pair
In-Reply-To: <201403121122133419764@goldenapptechnology.com>
References: <201403121122133419764@goldenapptechnology.com>
Message-ID: <CAHAkNZ1T0AD9rdOO4Z-qNDtJW__D4yzAVb8zSSfLeGpLErCbwg@mail.gmail.com>

I'm not the king of crypto, but if I recall correctly, some signature
standards (and I think PKCS1 is one of them) include a random salt in the
signature. This happens automatically, behind the scenes, on your behalf.
So two signatures can be of the same content, with the same key, and not be
equal - in fact, it's dramatically more likely than not! So you can't rely
on bit-for-bit equality of signatures.


On Tue, Mar 11, 2014 at 8:22 PM, wanggang
<wanggang at goldenapptechnology.com>wrote:

> Hi pycrypto,
>
> This may be a simple problem since I am a newbiee to crypto.
> I am not sure why I got different result from
> PKCS1_v1_5.new(RSA.construct(lst)).sign(SHA.new(a2b(m))) ,
> I have mentioned the 'stateful' comment in API doc, but still can't fix
> the code below.
> besides I have used DES for a lot, & never got stuck in such situation.
>
> if __name__ == "__main__":
>     t = (modulus, publicExponent, privateExponent, prime1, prime2,
> coefficient)
>     lst = [long(x,16) for x in t]
>
>     k = '1234'
>     e1 = RSA.construct(lst).encrypt(m, k)
>     e2 = RSA.construct(lst).encrypt(m, k)
>     assert e1 == e2 # passed
>
>     signature1 = PKCS1_v1_5.new(RSA.construct(lst)).sign(SHA.new(a2b(m)))
>     print binascii.b2a_hex(signature1)
>     signature2 = PKCS1_v1_5.new(RSA.construct(lst)).sign(SHA.new(a2b(m)))
>     print binascii.b2a_hex(signature2)
>     assert signature1==signature2 # why this assertion failed ?
>
> Thank you in advance!
> --------------
>  Wang Gang
> _______________________________________________
> pycrypto mailing list
> pycrypto at lists.dlitz.net
> http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.dlitz.net/pipermail/pycrypto/attachments/20140311/b842a24a/attachment.html>

From helderijs at gmail.com  Wed Mar 12 03:47:15 2014
From: helderijs at gmail.com (Legrandin)
Date: Wed, 12 Mar 2014 11:47:15 +0100
Subject: [pycrypto] Got different PKCS1_v1_5 signature result on the
 same message & same rsa key pair
In-Reply-To: <CAHAkNZ1T0AD9rdOO4Z-qNDtJW__D4yzAVb8zSSfLeGpLErCbwg@mail.gmail.com>
References: <201403121122133419764@goldenapptechnology.com>
 <CAHAkNZ1T0AD9rdOO4Z-qNDtJW__D4yzAVb8zSSfLeGpLErCbwg@mail.gmail.com>
Message-ID: <CAGfyce3FDy=or1eOMmdSnePurU3qs+BH3F1EqU_Fodn83GNFZg@mail.gmail.com>

PKCS#1v1.5 happens to be a deterministic signature scheme, so in theory the
assertion should not fail.

I believe that the RSA key that Wang Gang is using is not correct.
For instance, some of the CRT coefficients may not be matching the private
exponent.

When that happens, the blinding countermeasures will not cancel out and the
result of RSA operations will be random (in addition to being incorrect).

2014-03-12 6:55 GMT+01:00 Philip Horger <campadrenalin at gmail.com>:

> I'm not the king of crypto, but if I recall correctly, some signature
> standards (and I think PKCS1 is one of them) include a random salt in the
> signature. This happens automatically, behind the scenes, on your behalf.
> So two signatures can be of the same content, with the same key, and not be
> equal - in fact, it's dramatically more likely than not! So you can't rely
> on bit-for-bit equality of signatures.
>
>
> On Tue, Mar 11, 2014 at 8:22 PM, wanggang <
> wanggang at goldenapptechnology.com> wrote:
>
>> Hi pycrypto,
>>
>> This may be a simple problem since I am a newbiee to crypto.
>> I am not sure why I got different result from
>> PKCS1_v1_5.new(RSA.construct(lst)).sign(SHA.new(a2b(m))) ,
>> I have mentioned the 'stateful' comment in API doc, but still can't fix
>> the code below.
>> besides I have used DES for a lot, & never got stuck in such situation.
>>
>> if __name__ == "__main__":
>>     t = (modulus, publicExponent, privateExponent, prime1, prime2,
>> coefficient)
>>     lst = [long(x,16) for x in t]
>>
>>     k = '1234'
>>     e1 = RSA.construct(lst).encrypt(m, k)
>>     e2 = RSA.construct(lst).encrypt(m, k)
>>     assert e1 == e2 # passed
>>
>>     signature1 = PKCS1_v1_5.new(RSA.construct(lst)).sign(SHA.new(a2b(m)))
>>     print binascii.b2a_hex(signature1)
>>     signature2 = PKCS1_v1_5.new(RSA.construct(lst)).sign(SHA.new(a2b(m)))
>>     print binascii.b2a_hex(signature2)
>>     assert signature1==signature2 # why this assertion failed ?
>>
>> Thank you in advance!
>> --------------
>>  Wang Gang
>> _______________________________________________
>> pycrypto mailing list
>> pycrypto at lists.dlitz.net
>> http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto
>>
>
>
> _______________________________________________
> pycrypto mailing list
> pycrypto at lists.dlitz.net
> http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.dlitz.net/pipermail/pycrypto/attachments/20140312/2620fdef/attachment.html>