def rar3_s2k(psw, salt):
    """String-to-key hash for RAR3.
    """
    if not isinstance(psw, unicode):
        psw = psw.decode('utf8')
    seed = bytearray(psw.encode('utf-16le') + salt)
    h = Rar3Sha1(rarbug=True)
    iv = EMPTY
    for i in range(16):
        for j in range(0x4000):
            cnt = S_LONG.pack(i * 0x4000 + j)
            h.update(seed)
            h.update(cnt[:3])
            if j == 0:
                iv += h.digest()[19:20]
    key_be = h.digest()[:16]
    key_le = pack("<LLLL", *unpack(">LLLL", key_be))
    return key_le, iv
def rar3_s2k ( psw , salt ) : if not isinstance ( psw , unicode ) : psw = psw . decode ( 'utf8' ) seed = bytearray ( psw . encode ( 'utf-16le' ) + salt ) h = Rar3Sha1 ( rarbug = True ) iv = EMPTY for i in range ( 16 ) : for j in range ( 0x4000 ) : cnt = S_LONG . pack ( i * 0x4000 + j ) h . update ( seed ) h . update ( cnt [ : 3 ] ) if j == 0 : iv += h . digest ( ) [ 19 : 20 ] key_be = h . digest ( ) [ : 16 ] key_le = pack ( "<LLLL" , * unpack ( ">LLLL" , key_be ) ) return key_le , iv
String-to-key hash for RAR3.