Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!feeder1.xsusenet.com!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.05; 'sufficient': 0.05; 'chunk': 0.07; 'block.': 0.09; 'chunks': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'slow.': 0.09; 'stored': 0.10; 'python': 0.11; 'assume': 0.11; 'algorithm': 0.13; 'def': 0.14; 'output': 0.15; '(about': 0.16; 'dest)': 0.16; 'discussion.': 0.16; 'disk.': 0.16; 'encryption': 0.16; 'included"': 0.16; 'nefarious': 0.16; 'peer-to-peer': 0.16; 'prepend': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'wrote:': 0.16; 'say,': 0.18; 'software.': 0.22; 'thanks.': 0.22; 'strip': 0.22; 'installation': 0.23; 'written': 0.24; 'header:User-Agent:1': 0.26; 'idea': 0.26; 'header:X-Complaints-To:1': 0.26; 'appreciated.': 0.27; 'data,': 0.27; 'block,': 0.29; 'protocol.': 0.29; 'guess': 0.29; 'random': 0.29; "i'd": 0.31; 'supposed': 0.31; "can't": 0.32; 'to:addr:python-list': 0.35; 'ahead': 0.35; 'machines': 0.35; 'really': 0.35; 'skip:o 20': 0.35; 'but': 0.36; 'too': 0.36; 'subject:: ': 0.37; 'received:org': 0.38; 'to:addr:python.org': 0.39; 'data': 0.40; 'where': 0.40; 'received:de': 0.40; 'some': 0.40; 'even': 0.61; 'skip:u 10': 0.62; 'subject:Data': 0.66; 'protect': 0.74; 'smith': 0.76; 'payload': 0.84; 'senders': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: Pure Python Data Mangling or Encrypting Date: Sat, 27 Jun 2015 10:29:06 +0200 Organization: None References: Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p57bd9288.dip0.t-ipconnect.de User-Agent: KNode/4.13.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1435393759 news.xs4all.nl 2927 [2001:888:2000:d::a6]:41115 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:93229 Randall Smith wrote: > Chunks of data (about 2MB) are to be stored on machines using a > peer-to-peer protocol. The recipient of these chunks can't assume that > the payload is benign. While the data senders are supposed to encrypt > data, that's not guaranteed, and I'd like to protect the recipient > against exposure to nefarious data by mangling or encrypting the data > before it is written to disk. > > My original idea was for the recipient to encrypt using AES. But I want > to keep this software pure Python "batteries included" and not require > installation of other platform-dependent software. Pure Python AES and > even DES are just way too slow. I don't know that I really need > encryption here, but some type of fast mangling algorithm where a bad > actor sending a payload can't guess the output ahead of time. > > Any ideas are appreciated. Thanks. Would it be sufficient to prepend the chunk with one block, say, of random data? To unmangle you'd just strip off that block. BLOCK = os.urandom(BLOCKSIZE) def mangle(source, dest): dest.write(BLOCK) shutil.copyfileobj(source, dest) def unmangle(source, dest): source.read(BLOCKSIZE) shutil.copyfileobj(source, dest) Disclaimer: I did not follow the ongoing discussion.