48 lines
1.2 KiB
Python
48 lines
1.2 KiB
Python
#
|
|
# Requirements: argon2-cffi
|
|
#
|
|
|
|
import argon2
|
|
import argparse
|
|
import getpass
|
|
import sys
|
|
|
|
#
|
|
# WARNING: Changing any of the parameters below will affect password generation
|
|
#
|
|
|
|
# Default SALT to use; this cannot be random since passgeny must
|
|
# generate predictable passwords
|
|
PASSGENY_SALT_DEFAULT = b"Passgeny v1"
|
|
# Memory cost expresssed in kb
|
|
PASSGENY_ARGON2_MEMORY_COST = 8192
|
|
# Number of iterations
|
|
PASSGENY_ARGON2_TIME_COST = 6
|
|
# Number of parallel threads
|
|
PASSGENY_ARGON2_PARALLEL = 4
|
|
# Hash length - 512 bits by default
|
|
PASSGENY_ARGON2_HASH_LEN = 64
|
|
|
|
def argon2_hash(message):
|
|
return argon2.low_level.hash_secret_raw(
|
|
message,
|
|
PASSGENY_SALT_DEFAULT,
|
|
type = argon2.Type.ID,
|
|
memory_cost = PASSGENY_ARGON2_MEMORY_COST,
|
|
time_cost = PASSGENY_ARGON2_TIME_COST,
|
|
parallelism = PASSGENY_ARGON2_PARALLEL,
|
|
hash_len = PASSGENY_ARGON2_HASH_LEN)
|
|
|
|
def passgeny_hash(master_password, token_list):
|
|
message = b''
|
|
|
|
# Construct the message to be hashed
|
|
for x in token_list:
|
|
message += x.encode() + b'\0'
|
|
|
|
message += master_password.encode() + b'\0'
|
|
return argon2_hash(message)
|
|
|
|
mpw = getpass.getpass("Master password: ")
|
|
print(passgeny_hash(mpw, ("1", "2", "3")))
|