예제 #1
0
파일: argon2.py 프로젝트: dragoncsc/HDsite
 def _calc_checksum(self, secret):
     # TODO: add in 'encoding' support once that's finalized in 1.8 / 1.9.
     uh.validate_secret(secret)
     secret = to_bytes(secret, "utf-8")
     if self.type_d:
         type = _argon2pure.ARGON2D
     else:
         type = _argon2pure.ARGON2I
     kwds = dict(
         password=secret,
         salt=self.salt,
         time_cost=self.rounds,
         memory_cost=self.memory_cost,
         parallelism=self.parallelism,
         tag_length=self.checksum_size,
         type_code=type,
         version=self.version,
     )
     if self.max_threads > 0:
         kwds['threads'] = self.max_threads
     if self.pure_use_threads:
         kwds['use_threads'] = True
     if self.data:
         kwds['associated_data'] = self.data
     # NOTE: should return raw bytes
     # NOTE: this may raise _argon2pure.Argon2ParameterError,
     #       but it if does that, there's a bug in our own parameter checking code.
     try:
         return _argon2pure.argon2(**kwds)
     except _argon2pure.Argon2Error as err:
         raise self._adapt_backend_error(err, self=self)
예제 #2
0
파일: argon2.py 프로젝트: perpi06/ttoffline
 def _calc_checksum(self, secret):
     uh.validate_secret(secret)
     secret = to_bytes(secret, 'utf-8')
     if self.type_d:
         type = _argon2pure.ARGON2D
     else:
         type = _argon2pure.ARGON2I
     kwds = dict(password=secret,
                 salt=self.salt,
                 time_cost=self.rounds,
                 memory_cost=self.memory_cost,
                 parallelism=self.parallelism,
                 tag_length=self.checksum_size,
                 type_code=type,
                 version=self.version)
     if self.max_threads > 0:
         kwds['threads'] = self.max_threads
     if self.pure_use_threads:
         kwds['use_threads'] = True
     if self.data:
         kwds['associated_data'] = self.data
     try:
         return _argon2pure.argon2(**kwds)
     except _argon2pure.Argon2Error as err:
         raise self._adapt_backend_error(err, self=self)
예제 #3
0
 def _calc_checksum(self, secret):
     # TODO: add in 'encoding' support once that's finalized in 1.8 / 1.9.
     uh.validate_secret(secret)
     secret = to_bytes(secret, "utf-8")
     kwds = dict(
         password=secret,
         salt=self.salt,
         time_cost=self.rounds,
         memory_cost=self.memory_cost,
         parallelism=self.parallelism,
         tag_length=self.checksum_size,
         type_code=self._get_backend_type(self.type),
         version=self.version,
     )
     if self.max_threads > 0:
         kwds['threads'] = self.max_threads
     if self.pure_use_threads:
         kwds['use_threads'] = True
     if self.data:
         kwds['associated_data'] = self.data
     # NOTE: should return raw bytes
     # NOTE: this may raise _argon2pure.Argon2ParameterError,
     #       but it if does that, there's a bug in our own parameter checking code.
     try:
         return _argon2pure.argon2(**kwds)
     except _argon2pure.Argon2Error as err:
         raise self._adapt_backend_error(err, self=self)
예제 #4
0
 def _test(self, time_cost, memory_cost, parallelism):
     for type_code, version in itertools.product(
             (argon2pure.ARGON2D, argon2pure.ARGON2I),
             (0x10, 0x13)):
         cffi_type = (argon2.Type.I if type_code == argon2pure.ARGON2I
                                 else argon2.Type.D)
         self.assertEqual(
                 argon2.low_level.hash_secret_raw(
                     b'password', b'saltysaltsaltysalt',
                     time_cost, memory_cost, parallelism, 32,
                     cffi_type, version=version),
                 argon2pure.argon2(
                     b'password', b'saltysaltsaltysalt',
                     time_cost, memory_cost, parallelism, 32,
                     b'', b'', type_code, version=version))
예제 #5
0
 def _test(self, time_cost, memory_cost, parallelism):
     for type_code, version in itertools.product(
         (argon2pure.ARGON2D, argon2pure.ARGON2I), (0x10, 0x13)):
         cffi_type = (argon2.Type.I
                      if type_code == argon2pure.ARGON2I else argon2.Type.D)
         self.assertEqual(
             argon2.low_level.hash_secret_raw(b'password',
                                              b'saltysaltsaltysalt',
                                              time_cost,
                                              memory_cost,
                                              parallelism,
                                              32,
                                              cffi_type,
                                              version=version),
             argon2pure.argon2(b'password',
                               b'saltysaltsaltysalt',
                               time_cost,
                               memory_cost,
                               parallelism,
                               32,
                               b'',
                               b'',
                               type_code,
                               version=version))