Beispiel #1
0
def saltless_srp_create(username, password, hash_alg=srp.SHA1,
                        ng_type=srp.NG_2048, n_hex=None, g_hex=None):
    assert isinstance(username, str) # already UTF8-encoded
    # unfortunately the python SRP module doesn't make it easy to pass our
    # own salt into create_salted_verification_key(), so we have to get
    # messy. Other SRP libraries (e.g. SJCL) make this easier.
    from srp._pysrp import _hash_map, get_ng, long_to_bytes, gen_x
    from srp import NG_CUSTOM
    if ng_type == NG_CUSTOM and (n_hex is None or g_hex is None):
        raise ValueError("Both n_hex and g_hex are required when ng_type = NG_CUSTOM")
    hash_class = _hash_map[ hash_alg ]
    N,g = get_ng( ng_type, n_hex, g_hex )
    #_s = long_to_bytes( get_random( 4 ) )
    _s = None
    _v = long_to_bytes( pow(g,  gen_x(hash_class, _s, username, password), N))
    return _v
Beispiel #2
0
def create_verification_key(user, salt):
    hash_class = user.hash_class
    return srp.long_to_bytes(
        pow(user.g, srp.gen_x(hash_class, salt, user.I, user.p), user.N))
Beispiel #3
0
def create_verification_key(user, salt):
    hash_class = user.hash_class
    return srp.long_to_bytes(pow(user.g, srp.gen_x(hash_class, salt, user.I, user.p), user.N))