#! /usr/bin/python
'''Generate encrypted passwords for GRUB.'''
import crypt
import getopt
import getpass
import sys
def usage():
'''Output usage message to stderr and exit.'''
print >> sys.stderr, 'Usage: grub-crypt [OPTION]...'
print >> sys.stderr, 'Try `$progname --help\' for more information.'
sys.exit(1)
def gen_salt():
'''Generate a random salt.'''
ret = ''
with open('/dev/urandom', 'rb') as urandom:
while True:
byte = urandom.read(1)
if byte in ('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
'./0123456789'):
ret += byte
if len(ret) == 16:
break
return ret
def main():
'''Top level.'''
crypt_type = '$6$' # SHA-256
try:
opts, args = getopt.getopt(sys.argv[1:], 'hv',
('help', 'version', 'md5', 'sha-256',
'sha-512'))
except getopt.GetoptError, err:
print >> sys.stderr, str(err)
usage()
if args:
print >> sys.stderr, 'Unexpected argument `%s\'' % (args[0],)
usage()
for (opt, _) in opts:
if opt in ('-h', '--help'):
print (
'''Usage: grub-crypt [OPTION]...
Encrypt a password.
-h, --help Print this message and exit
-v, --version Print the version information and exit
--md5 Use MD5 to encrypt the password
--sha-256 Use SHA-256 to encrypt the password
--sha-512 Use SHA-512 to encrypt the password (default)
Report bugs to