From owner-svn-src-head@freebsd.org Sun Sep 24 00:14:49 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id ACEB5E152D8; Sun, 24 Sep 2017 00:14:49 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 839EF6363E; Sun, 24 Sep 2017 00:14:49 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8O0Emkp027549; Sun, 24 Sep 2017 00:14:48 GMT (envelope-from ngie@FreeBSD.org) Received: (from ngie@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8O0EmGN027547; Sun, 24 Sep 2017 00:14:48 GMT (envelope-from ngie@FreeBSD.org) Message-Id: <201709240014.v8O0EmGN027547@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ngie set sender to ngie@FreeBSD.org using -f From: Ngie Cooper Date: Sun, 24 Sep 2017 00:14:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r323960 - head/tests/sys/opencrypto X-SVN-Group: head X-SVN-Commit-Author: ngie X-SVN-Commit-Paths: head/tests/sys/opencrypto X-SVN-Commit-Revision: 323960 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 24 Sep 2017 00:14:49 -0000 Author: ngie Date: Sun Sep 24 00:14:48 2017 New Revision: 323960 URL: https://svnweb.freebsd.org/changeset/base/323960 Log: Convert some idioms over to py3k-compatible idioms - Import print_function from __future__ and use print(..) instead of `print ..`. - Use repr instead of backticks when the object needs to be dumped, unless print(..) can do it lazily. Use str instead of backticks as appropriate for simplification reasons. This doesn't fully convert these modules over py3k. It just gets over some of the trivial compatibility hurdles. Modified: head/tests/sys/opencrypto/cryptodev.py head/tests/sys/opencrypto/cryptotest.py Modified: head/tests/sys/opencrypto/cryptodev.py ============================================================================== --- head/tests/sys/opencrypto/cryptodev.py Sun Sep 24 00:07:18 2017 (r323959) +++ head/tests/sys/opencrypto/cryptodev.py Sun Sep 24 00:14:48 2017 (r323960) @@ -30,6 +30,7 @@ # $FreeBSD$ # +from __future__ import print_function import array import dpkt from fcntl import ioctl @@ -174,9 +175,9 @@ class Crypto: if not cipher and not mac: raise ValueError('one of cipher or mac MUST be specified.') ses.crid = crid - #print `ses` + #print(ses) s = array.array('B', ses.pack_hdr()) - #print `s` + #print(s) ioctl(_cryptodev, CIOCGSESSION2, s, 1) ses.unpack(s) @@ -206,7 +207,7 @@ class Crypto: ivbuf = array.array('B', iv) cop.iv = ivbuf.buffer_info()[0] - #print 'cop:', `cop` + #print('cop:', cop) ioctl(_cryptodev, CIOCCRYPT, str(cop)) s = s.tostring() @@ -234,7 +235,8 @@ class Crypto: if tag is None: tag = array.array('B', [0] * self._maclen) else: - assert len(tag) == self._maclen, `len(tag), self._maclen` + assert len(tag) == self._maclen, \ + '%d != %d' % (len(tag), self._maclen) tag = array.array('B', tag) caead.tag = tag.buffer_info()[0] @@ -288,8 +290,8 @@ class Crypto: signal.signal(signal.SIGALRM, oldalarm) - print 'time:', end - start - print 'perf MB/sec:', (reps * size) / (end - start) / 1024 / 1024 + print('time:', end - start) + print('perf MB/sec:', (reps * size) / (end - start) / 1024 / 1024) def encrypt(self, data, iv, aad=None): if aad is None: @@ -332,7 +334,7 @@ class KATParser: if i[0] == '[': yield i[1:].split(']', 1)[0], self.fielditer() else: - raise ValueError('unknown line: %s' % `i`) + raise ValueError('unknown line: %r' % repr(i)) def eatblanks(self): while True: @@ -362,12 +364,12 @@ class KATParser: if line == 'FAIL': f, v = 'FAIL', '' else: - print 'line:', `line` + print('line:', repr(line)) raise v = v.strip() if f in values: - raise ValueError('already present: %s' % `f`) + raise ValueError('already present: %r' % repr(f)) values[f] = v line = self.fp.readline().strip() if not line: @@ -377,7 +379,7 @@ class KATParser: remain = self.fields.copy() - set(values.keys()) # XXX - special case GCM decrypt if remain and not ('FAIL' in values and 'PT' in remain): - raise ValueError('not all fields found: %s' % `remain`) + raise ValueError('not all fields found: %r' % repr(remain)) yield values @@ -388,22 +390,22 @@ if __name__ == '__main__': if True: try: crid = Crypto.findcrid('aesni0') - print 'aesni:', crid + print('aesni:', crid) except IOError: - print 'aesni0 not found' + print('aesni0 not found') for i in xrange(10): try: name = Crypto.getcridname(i) - print '%2d: %s' % (i, `name`) + print('%2d: %r' % (i, repr(name))) except IOError: pass elif False: kp = KATParser('/usr/home/jmg/aesni.testing/format tweak value input - data unit seq no/XTSGenAES128.rsp', [ 'COUNT', 'DataUnitLen', 'Key', 'DataUnitSeqNumber', 'PT', 'CT' ]) for mode, ni in kp: - print `i`, `ni` + print(i, ni) for j in ni: - print `j` + print(j) elif False: key = _spdechex('c939cc13397c1d37de6ae0e1cb7c423c') iv = _spdechex('00000000000000000000000000000001') @@ -414,15 +416,15 @@ if __name__ == '__main__': c = Crypto(CRYPTO_AES_ICM, key) enc = c.encrypt(pt, iv) - print 'enc:', enc.encode('hex') - print ' ct:', ct.encode('hex') + print('enc:', enc.encode('hex')) + print(' ct:', ct.encode('hex')) assert ct == enc dec = c.decrypt(ct, iv) - print 'dec:', dec.encode('hex') - print ' pt:', pt.encode('hex') + print('dec:', dec.encode('hex')) + print(' pt:', pt.encode('hex')) assert pt == dec elif False: @@ -435,15 +437,15 @@ if __name__ == '__main__': c = Crypto(CRYPTO_AES_ICM, key) enc = c.encrypt(pt, iv) - print 'enc:', enc.encode('hex') - print ' ct:', ct.encode('hex') + print('enc:', enc.encode('hex')) + print(' ct:', ct.encode('hex')) assert ct == enc dec = c.decrypt(ct, iv) - print 'dec:', dec.encode('hex') - print ' pt:', pt.encode('hex') + print('dec:', dec.encode('hex')) + print(' pt:', pt.encode('hex')) assert pt == dec elif False: @@ -455,15 +457,15 @@ if __name__ == '__main__': enc = c.encrypt(pt, iv) - print 'enc:', enc.encode('hex') - print ' ct:', ct.encode('hex') + print('enc:', enc.encode('hex')) + print(' ct:', ct.encode('hex')) assert ct == enc dec = c.decrypt(ct, iv) - print 'dec:', dec.encode('hex') - print ' pt:', pt.encode('hex') + print('dec:', dec.encode('hex')) + print(' pt:', pt.encode('hex')) assert pt == dec elif False: @@ -481,26 +483,26 @@ if __name__ == '__main__': enc, enctag = c.encrypt(pt, iv, aad=aad) - print 'enc:', enc.encode('hex') - print ' ct:', ct.encode('hex') + print('enc:', enc.encode('hex')) + print(' ct:', ct.encode('hex')) assert enc == ct - print 'etg:', enctag.encode('hex') - print 'tag:', tag.encode('hex') + print('etg:', enctag.encode('hex')) + print('tag:', tag.encode('hex')) assert enctag == tag # Make sure we get EBADMSG #enctag = enctag[:-1] + 'a' dec, dectag = c.decrypt(ct, iv, aad=aad, tag=enctag) - print 'dec:', dec.encode('hex') - print ' pt:', pt.encode('hex') + print('dec:', dec.encode('hex')) + print(' pt:', pt.encode('hex')) assert dec == pt - print 'dtg:', dectag.encode('hex') - print 'tag:', tag.encode('hex') + print('dtg:', dectag.encode('hex')) + print('tag:', tag.encode('hex')) assert dectag == tag elif False: @@ -517,13 +519,13 @@ if __name__ == '__main__': enc, enctag = c.encrypt(pt, iv, aad=aad) - print 'enc:', enc.encode('hex') - print ' ct:', ct.encode('hex') + print('enc:', enc.encode('hex')) + print(' ct:', ct.encode('hex')) assert enc == ct - print 'etg:', enctag.encode('hex') - print 'tag:', tag.encode('hex') + print('etg:', enctag.encode('hex')) + print('tag:', tag.encode('hex')) assert enctag == tag elif False: for i in xrange(100000): @@ -550,9 +552,9 @@ if __name__ == '__main__': else: key = '1bbfeadf539daedcae33ced497343f3ca1f2474ad932b903997d44707db41382'.decode('hex') - print 'XTS %d testing:' % (len(key) * 8) + print('XTS %d testing:' % (len(key) * 8)) c = Crypto(CRYPTO_AES_XTS, key) for i in [ 8192, 192*1024]: - print 'block size: %d' % i + print('block size: %d' % i) c.perftest(COP_ENCRYPT, i) c.perftest(COP_DECRYPT, i) Modified: head/tests/sys/opencrypto/cryptotest.py ============================================================================== --- head/tests/sys/opencrypto/cryptotest.py Sun Sep 24 00:07:18 2017 (r323959) +++ head/tests/sys/opencrypto/cryptotest.py Sun Sep 24 00:14:48 2017 (r323960) @@ -29,6 +29,7 @@ # $FreeBSD$ # +from __future__ import print_function import cryptodev import itertools import os @@ -57,17 +58,17 @@ def GenTestCase(cname): ############### ##### AES ##### ############### - @unittest.skipIf(cname not in aesmodules, 'skipping AES on %s' % `cname`) + @unittest.skipIf(cname not in aesmodules, 'skipping AES on %s' % (cname)) def test_xts(self): for i in katg('XTSTestVectors/format tweak value input - data unit seq no', '*.rsp'): self.runXTS(i, cryptodev.CRYPTO_AES_XTS) - @unittest.skipIf(cname not in aesmodules, 'skipping AES on %s' % `cname`) + @unittest.skipIf(cname not in aesmodules, 'skipping AES on %s' % (cname)) def test_cbc(self): for i in katg('KAT_AES', 'CBC[GKV]*.rsp'): self.runCBC(i) - @unittest.skipIf(cname not in aesmodules, 'skipping AES on %s' % `cname`) + @unittest.skipIf(cname not in aesmodules, 'skipping AES on %s' % (cname)) def test_gcm(self): for i in katg('gcmtestvectors', 'gcmEncrypt*'): self.runGCM(i, 'ENCRYPT') @@ -88,7 +89,7 @@ def GenTestCase(cname): swapptct = True curfun = Crypto.decrypt else: - raise RuntimeError('unknown mode: %s' % `mode`) + raise RuntimeError('unknown mode: %r' % repr(mode)) for bogusmode, lines in cryptodev.KATParser(fname, [ 'Count', 'Key', 'IV', 'CT', 'AAD', 'Tag', 'PT', ]): @@ -116,8 +117,8 @@ def GenTestCase(cname): rtag = rtag[:len(tag)] data['rct'] = rct.encode('hex') data['rtag'] = rtag.encode('hex') - self.assertEqual(rct, ct, `data`) - self.assertEqual(rtag, tag, `data`) + self.assertEqual(rct, ct, repr(data)) + self.assertEqual(rtag, tag, repr(data)) else: if len(tag) != 16: continue @@ -130,7 +131,7 @@ def GenTestCase(cname): data['rpt'] = rpt.encode('hex') data['rtag'] = rtag.encode('hex') self.assertEqual(rpt, pt, - `data`) + repr(data)) def runCBC(self, fname): curfun = None @@ -143,7 +144,7 @@ def GenTestCase(cname): swapptct = True curfun = Crypto.decrypt else: - raise RuntimeError('unknown mode: %s' % `mode`) + raise RuntimeError('unknown mode: %r' % repr(mode)) for data in lines: curcnt = int(data['COUNT']) @@ -171,7 +172,7 @@ def GenTestCase(cname): swapptct = True curfun = Crypto.decrypt else: - raise RuntimeError('unknown mode: %s' % `mode`) + raise RuntimeError('unknown mode: %r' % repr(mode)) for data in lines: curcnt = int(data['COUNT']) @@ -194,7 +195,7 @@ def GenTestCase(cname): ############### ##### DES ##### ############### - @unittest.skipIf(cname not in desmodules, 'skipping DES on %s' % `cname`) + @unittest.skipIf(cname not in desmodules, 'skipping DES on %s' % (cname)) def test_tdes(self): for i in katg('KAT_TDES', 'TCBC[a-z]*.rsp'): self.runTDES(i) @@ -210,7 +211,7 @@ def GenTestCase(cname): swapptct = True curfun = Crypto.decrypt else: - raise RuntimeError('unknown mode: %s' % `mode`) + raise RuntimeError('unknown mode: %r' % repr(mode)) for data in lines: curcnt = int(data['COUNT']) @@ -230,14 +231,14 @@ def GenTestCase(cname): ############### ##### SHA ##### ############### - @unittest.skipIf(cname not in shamodules, 'skipping SHA on %s' % `cname`) + @unittest.skipIf(cname not in shamodules, 'skipping SHA on %s' % str(cname)) def test_sha(self): # SHA not available in software pass #for i in iglob('SHA1*'): # self.runSHA(i) - @unittest.skipIf(cname not in shamodules, 'skipping SHA on %s' % `cname`) + @unittest.skipIf(cname not in shamodules, 'skipping SHA on %s' % str(cname)) def test_sha1hmac(self): for i in katg('hmactestvectors', 'HMAC.rsp'): self.runSHA1HMAC(i)