Ejemplo n.º 1
0
 def to_string(self):
     ident = self.ident
     if ident == IDENT_SCRYPT:
         return "$scrypt$ln=%d,r=%d,p=%d$%s$%s" % (
             self.rounds,
             self.block_size,
             self.parallelism,
             bascii_to_str(b64s_encode(self.salt)),
             bascii_to_str(b64s_encode(self.checksum)),
         )
     else:
         assert ident == IDENT_7
         salt = self.salt
         try:
             salt.decode("ascii")
         except UnicodeDecodeError:
             raise suppress_cause(
                 NotImplementedError(
                     "scrypt $7$ hashes dont support non-ascii salts"))
         return bascii_to_str(b"".join([
             b"$7$",
             h64.encode_int6(self.rounds),
             h64.encode_int30(self.block_size),
             h64.encode_int30(self.parallelism), self.salt, b"$",
             h64.encode_bytes(self.checksum)
         ]))
Ejemplo n.º 2
0
 def to_string(self):
     hash = u("%s%s%s%s") % (
         self.ident,
         h64.encode_int6(self.rounds).decode("ascii"),
         self.salt,
         self.checksum or u(""),
     )
     return uascii_to_str(hash)
Ejemplo n.º 3
0
def h_scrypt(phrase, rounds, salt):
    p = 1
    r = 8
    log2N = rounds + 7
    N = 1 << log2N

    bytesalt = salt.encode("ascii")
    setting = (b"$7$" + hash64.encode_int6(log2N) + hash64.encode_int30(r) +
               hash64.encode_int30(p) + bytesalt)

    binhash = raw_scrypt(phrase, salt=bytesalt, p=p, r=r, n=N, dklen=32)

    yield (phrase, setting, setting + b'$' + hash64.encode_bytes(binhash))
Ejemplo n.º 4
0
def h_scrypt(phrase, rounds, salt):
    p = 1
    r = 8
    log2N = rounds + 7
    N = 1 << log2N

    bytesalt = salt.encode("ascii")
    setting = (b"$7$" +
               hash64.encode_int6(log2N) +
               hash64.encode_int30(r) +
               hash64.encode_int30(p) +
               bytesalt)

    binhash = raw_scrypt(phrase, salt=bytesalt, p=p, r=r, n=N, dklen=32)

    yield (phrase, setting, setting + b'$' + hash64.encode_bytes(binhash))
Ejemplo n.º 5
0
 def to_string(self):
     hash = u("%s%s%s%s") % (self.ident,
                           h64.encode_int6(self.rounds).decode("ascii"),
                           self.salt,
                           self.checksum or u(''))
     return uascii_to_str(hash)