mirror of
https://github.com/opnsense/src.git
synced 2026-04-22 23:02:02 -04:00
This change moves the tests added in r313962 to an existing directory structure used by the geli TAP tests. It also, renames the test from pbkdf2 to pbkdf2_test . The changes to ObsoleteFiles.inc are being committed separately as they aren't needed for the MFC to ^/stable/11, etc, if the MFC for the tests is done all in one commit. MFC after: 2 weeks X-MFC with: r313962, r313972-r313973 Reviewed by: allanjude Sponsored by: Dell EMC Isilon Differential Revision: D9985
63 lines
1.6 KiB
Python
63 lines
1.6 KiB
Python
#!/usr/bin/env python
|
|
# $FreeBSD$
|
|
|
|
from hashlib import pbkdf2_hmac
|
|
import hashlib
|
|
import itertools
|
|
import string
|
|
|
|
#From: https://stackoverflow.com/questions/14945095/how-to-escape-string-for-generated-c
|
|
def cstring(s, encoding='ascii'):
|
|
if isinstance(s, unicode):
|
|
s = s.encode(encoding)
|
|
|
|
result = ''
|
|
for c in s:
|
|
if not (32 <= ord(c) < 127) or c in ('\\', '"'):
|
|
result += '\\%03o' % ord(c)
|
|
else:
|
|
result += c
|
|
|
|
return '"' + result + '"'
|
|
|
|
intarr = lambda y: ', '.join(map(lambda x: str(ord(x)), y))
|
|
|
|
_randfd = open('/dev/urandom', 'rb')
|
|
_maketrans = string.maketrans('', '')
|
|
def randgen(l, delchrs=None):
|
|
if delchrs is None:
|
|
return _randfd.read(l)
|
|
|
|
s = ''
|
|
while len(s) < l:
|
|
s += string.translate(_randfd.read(l - len(s)), _maketrans,
|
|
delchrs)
|
|
return s
|
|
|
|
def printhmacres(salt, passwd, itr, hmacout):
|
|
print '\t{ %s, %d, %s, %d, %s, %d },' % (cstring(salt), len(salt),
|
|
cstring(passwd), itr, cstring(hmacout), len(hmacout))
|
|
|
|
if __name__ == '__main__':
|
|
import sys
|
|
|
|
if len(sys.argv) == 1:
|
|
hashfun = 'sha512'
|
|
else:
|
|
hashfun = sys.argv[1]
|
|
|
|
if hashfun not in hashlib.algorithms:
|
|
print 'Invalid hash function: %s' % `hashfun`
|
|
sys.exit(1)
|
|
|
|
print '/* Test Vectors for PBKDF2-%s */' % hashfun.upper()
|
|
print '\t/* salt, saltlen, passwd, itr, hmacout, hmacoutlen */'
|
|
for saltl in xrange(8, 64, 8):
|
|
for itr in itertools.chain(xrange(100, 1000, 100), xrange(1000,
|
|
10000, 1000)):
|
|
for passlen in xrange(8, 80, 8):
|
|
salt = randgen(saltl)
|
|
passwd = randgen(passlen, '\x00')
|
|
hmacout = pbkdf2_hmac(hashfun, passwd, salt,
|
|
itr)
|
|
printhmacres(salt, passwd, itr, hmacout)
|