libpass 1.7.5.post0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. libpass-1.7.5.post0.dist-info/METADATA +81 -0
  2. libpass-1.7.5.post0.dist-info/RECORD +69 -0
  3. libpass-1.7.5.post0.dist-info/WHEEL +4 -0
  4. libpass-1.7.5.post0.dist-info/licenses/LICENSE +116 -0
  5. passlib/__init__.py +3 -0
  6. passlib/_data/wordsets/bip39.txt +2049 -0
  7. passlib/_data/wordsets/eff_long.txt +7776 -0
  8. passlib/_data/wordsets/eff_prefixed.txt +1296 -0
  9. passlib/_data/wordsets/eff_short.txt +1296 -0
  10. passlib/_setup/__init__.py +1 -0
  11. passlib/_setup/stamp.py +159 -0
  12. passlib/apache.py +1185 -0
  13. passlib/apps.py +260 -0
  14. passlib/context.py +2066 -0
  15. passlib/crypto/__init__.py +1 -0
  16. passlib/crypto/_blowfish/__init__.py +171 -0
  17. passlib/crypto/_blowfish/_gen_files.py +256 -0
  18. passlib/crypto/_blowfish/base.py +1239 -0
  19. passlib/crypto/_blowfish/unrolled.py +1691 -0
  20. passlib/crypto/_md4.py +249 -0
  21. passlib/crypto/des.py +2283 -0
  22. passlib/crypto/digest.py +1111 -0
  23. passlib/crypto/scrypt/__init__.py +299 -0
  24. passlib/crypto/scrypt/_builtin.py +254 -0
  25. passlib/crypto/scrypt/_gen_files.py +161 -0
  26. passlib/crypto/scrypt/_salsa.py +188 -0
  27. passlib/exc.py +432 -0
  28. passlib/ext/__init__.py +1 -0
  29. passlib/ext/django/__init__.py +6 -0
  30. passlib/ext/django/models.py +38 -0
  31. passlib/ext/django/utils.py +1326 -0
  32. passlib/handlers/__init__.py +1 -0
  33. passlib/handlers/argon2.py +1119 -0
  34. passlib/handlers/bcrypt.py +1217 -0
  35. passlib/handlers/cisco.py +450 -0
  36. passlib/handlers/des_crypt.py +642 -0
  37. passlib/handlers/digests.py +184 -0
  38. passlib/handlers/django.py +545 -0
  39. passlib/handlers/fshp.py +223 -0
  40. passlib/handlers/ldap_digests.py +379 -0
  41. passlib/handlers/md5_crypt.py +375 -0
  42. passlib/handlers/misc.py +224 -0
  43. passlib/handlers/mssql.py +258 -0
  44. passlib/handlers/mysql.py +136 -0
  45. passlib/handlers/oracle.py +177 -0
  46. passlib/handlers/pbkdf2.py +521 -0
  47. passlib/handlers/phpass.py +142 -0
  48. passlib/handlers/postgres.py +61 -0
  49. passlib/handlers/roundup.py +33 -0
  50. passlib/handlers/scram.py +589 -0
  51. passlib/handlers/scrypt.py +413 -0
  52. passlib/handlers/sha1_crypt.py +173 -0
  53. passlib/handlers/sha2_crypt.py +657 -0
  54. passlib/handlers/sun_md5_crypt.py +387 -0
  55. passlib/handlers/windows.py +349 -0
  56. passlib/hash.py +111 -0
  57. passlib/hosts.py +112 -0
  58. passlib/ifc.py +354 -0
  59. passlib/pwd.py +813 -0
  60. passlib/registry.py +583 -0
  61. passlib/totp.py +1968 -0
  62. passlib/utils/__init__.py +1221 -0
  63. passlib/utils/binary.py +897 -0
  64. passlib/utils/compat/__init__.py +200 -0
  65. passlib/utils/decor.py +234 -0
  66. passlib/utils/des.py +35 -0
  67. passlib/utils/handlers.py +2857 -0
  68. passlib/utils/md4.py +34 -0
  69. passlib/utils/pbkdf2.py +188 -0
@@ -0,0 +1,657 @@
1
+ """passlib.handlers.sha2_crypt - SHA256-Crypt / SHA512-Crypt"""
2
+
3
+ # =============================================================================
4
+ # imports
5
+ # =============================================================================
6
+ # core
7
+ import hashlib
8
+ import logging
9
+
10
+ log = logging.getLogger(__name__)
11
+ # site
12
+ # pkg
13
+ from passlib.utils import safe_crypt, test_crypt, repeat_string, to_unicode
14
+ from passlib.utils.binary import h64
15
+ import passlib.utils.handlers as uh
16
+
17
+ # local
18
+ __all__ = [
19
+ "sha512_crypt",
20
+ "sha256_crypt",
21
+ ]
22
+
23
+ # =============================================================================
24
+ # pure-python backend, used by both sha256_crypt & sha512_crypt
25
+ # when crypt.crypt() backend is not available.
26
+ # =============================================================================
27
+ _BNULL = b"\x00"
28
+
29
+ # pre-calculated offsets used to speed up C digest stage (see notes below).
30
+ # sequence generated using the following:
31
+ ##perms_order = "p,pp,ps,psp,sp,spp".split(",")
32
+ ##def offset(i):
33
+ ## key = (("p" if i % 2 else "") + ("s" if i % 3 else "") +
34
+ ## ("p" if i % 7 else "") + ("" if i % 2 else "p"))
35
+ ## return perms_order.index(key)
36
+ ##_c_digest_offsets = [(offset(i), offset(i+1)) for i in range(0,42,2)]
37
+ _c_digest_offsets = (
38
+ (0, 3),
39
+ (5, 1),
40
+ (5, 3),
41
+ (1, 2),
42
+ (5, 1),
43
+ (5, 3),
44
+ (1, 3),
45
+ (4, 1),
46
+ (5, 3),
47
+ (1, 3),
48
+ (5, 0),
49
+ (5, 3),
50
+ (1, 3),
51
+ (5, 1),
52
+ (4, 3),
53
+ (1, 3),
54
+ (5, 1),
55
+ (5, 2),
56
+ (1, 3),
57
+ (5, 1),
58
+ (5, 3),
59
+ )
60
+
61
+ # map used to transpose bytes when encoding final sha256_crypt digest
62
+ _256_transpose_map = (
63
+ 20,
64
+ 10,
65
+ 0,
66
+ 11,
67
+ 1,
68
+ 21,
69
+ 2,
70
+ 22,
71
+ 12,
72
+ 23,
73
+ 13,
74
+ 3,
75
+ 14,
76
+ 4,
77
+ 24,
78
+ 5,
79
+ 25,
80
+ 15,
81
+ 26,
82
+ 16,
83
+ 6,
84
+ 17,
85
+ 7,
86
+ 27,
87
+ 8,
88
+ 28,
89
+ 18,
90
+ 29,
91
+ 19,
92
+ 9,
93
+ 30,
94
+ 31,
95
+ )
96
+
97
+ # map used to transpose bytes when encoding final sha512_crypt digest
98
+ _512_transpose_map = (
99
+ 42,
100
+ 21,
101
+ 0,
102
+ 1,
103
+ 43,
104
+ 22,
105
+ 23,
106
+ 2,
107
+ 44,
108
+ 45,
109
+ 24,
110
+ 3,
111
+ 4,
112
+ 46,
113
+ 25,
114
+ 26,
115
+ 5,
116
+ 47,
117
+ 48,
118
+ 27,
119
+ 6,
120
+ 7,
121
+ 49,
122
+ 28,
123
+ 29,
124
+ 8,
125
+ 50,
126
+ 51,
127
+ 30,
128
+ 9,
129
+ 10,
130
+ 52,
131
+ 31,
132
+ 32,
133
+ 11,
134
+ 53,
135
+ 54,
136
+ 33,
137
+ 12,
138
+ 13,
139
+ 55,
140
+ 34,
141
+ 35,
142
+ 14,
143
+ 56,
144
+ 57,
145
+ 36,
146
+ 15,
147
+ 16,
148
+ 58,
149
+ 37,
150
+ 38,
151
+ 17,
152
+ 59,
153
+ 60,
154
+ 39,
155
+ 18,
156
+ 19,
157
+ 61,
158
+ 40,
159
+ 41,
160
+ 20,
161
+ 62,
162
+ 63,
163
+ )
164
+
165
+
166
+ def _raw_sha2_crypt(pwd, salt, rounds, use_512=False):
167
+ """perform raw sha256-crypt / sha512-crypt
168
+
169
+ this function provides a pure-python implementation of the internals
170
+ for the SHA256-Crypt and SHA512-Crypt algorithms; it doesn't
171
+ handle any of the parsing/validation of the hash strings themselves.
172
+
173
+ :arg pwd: password chars/bytes to hash
174
+ :arg salt: salt chars to use
175
+ :arg rounds: linear rounds cost
176
+ :arg use_512: use sha512-crypt instead of sha256-crypt mode
177
+
178
+ :returns:
179
+ encoded checksum chars
180
+ """
181
+ # ===================================================================
182
+ # init & validate inputs
183
+ # ===================================================================
184
+
185
+ # NOTE: the setup portion of this algorithm scales ~linearly in time
186
+ # with the size of the password, making it vulnerable to a DOS from
187
+ # unreasonably large inputs. the following code has some optimizations
188
+ # which would make things even worse, using O(pwd_len**2) memory
189
+ # when calculating digest P.
190
+ #
191
+ # to mitigate these two issues: 1) this code switches to a
192
+ # O(pwd_len)-memory algorithm for passwords that are much larger
193
+ # than average, and 2) Passlib enforces a library-wide max limit on
194
+ # the size of passwords it will allow, to prevent this algorithm and
195
+ # others from being DOSed in this way (see passlib.exc.PasswordSizeError
196
+ # for details).
197
+
198
+ # validate secret
199
+ if isinstance(pwd, str):
200
+ # XXX: not sure what official unicode policy is, using this as default
201
+ pwd = pwd.encode("utf-8")
202
+ assert isinstance(pwd, bytes)
203
+ if _BNULL in pwd:
204
+ raise uh.exc.NullPasswordError(sha512_crypt if use_512 else sha256_crypt)
205
+ pwd_len = len(pwd)
206
+
207
+ # validate rounds
208
+ assert 1000 <= rounds <= 999999999, "invalid rounds"
209
+ # NOTE: spec says out-of-range rounds should be clipped, instead of
210
+ # causing an error. this function assumes that's been taken care of
211
+ # by the handler class.
212
+
213
+ # validate salt
214
+ assert isinstance(salt, str), "salt not str"
215
+ salt = salt.encode("ascii")
216
+ salt_len = len(salt)
217
+ assert salt_len < 17, "salt too large"
218
+ # NOTE: spec says salts larger than 16 bytes should be truncated,
219
+ # instead of causing an error. this function assumes that's been
220
+ # taken care of by the handler class.
221
+
222
+ # load sha256/512 specific constants
223
+ if use_512:
224
+ hash_const = hashlib.sha512
225
+ transpose_map = _512_transpose_map
226
+ else:
227
+ hash_const = hashlib.sha256
228
+ transpose_map = _256_transpose_map
229
+
230
+ # ===================================================================
231
+ # digest B - used as subinput to digest A
232
+ # ===================================================================
233
+ db = hash_const(pwd + salt + pwd).digest()
234
+
235
+ # ===================================================================
236
+ # digest A - used to initialize first round of digest C
237
+ # ===================================================================
238
+ # start out with pwd + salt
239
+ a_ctx = hash_const(pwd + salt)
240
+ a_ctx_update = a_ctx.update
241
+
242
+ # add pwd_len bytes of b, repeating b as many times as needed.
243
+ a_ctx_update(repeat_string(db, pwd_len))
244
+
245
+ # for each bit in pwd_len: add b if it's 1, or pwd if it's 0
246
+ i = pwd_len
247
+ while i:
248
+ a_ctx_update(db if i & 1 else pwd)
249
+ i >>= 1
250
+
251
+ # finish A
252
+ da = a_ctx.digest()
253
+
254
+ # ===================================================================
255
+ # digest P from password - used instead of password itself
256
+ # when calculating digest C.
257
+ # ===================================================================
258
+ if pwd_len < 96:
259
+ # this method is faster under python, but uses O(pwd_len**2) memory;
260
+ # so we don't use it for larger passwords to avoid a potential DOS.
261
+ dp = repeat_string(hash_const(pwd * pwd_len).digest(), pwd_len)
262
+ else:
263
+ # this method is slower under python, but uses a fixed amount of memory.
264
+ tmp_ctx = hash_const(pwd)
265
+ tmp_ctx_update = tmp_ctx.update
266
+ i = pwd_len - 1
267
+ while i:
268
+ tmp_ctx_update(pwd)
269
+ i -= 1
270
+ dp = repeat_string(tmp_ctx.digest(), pwd_len)
271
+ assert len(dp) == pwd_len
272
+
273
+ # ===================================================================
274
+ # digest S - used instead of salt itself when calculating digest C
275
+ # ===================================================================
276
+ ds = hash_const(salt * (16 + da[0])).digest()[:salt_len]
277
+ assert len(ds) == salt_len, "salt_len somehow > hash_len!"
278
+
279
+ # ===================================================================
280
+ # digest C - for a variable number of rounds, combine A, S, and P
281
+ # digests in various ways; in order to burn CPU time.
282
+ # ===================================================================
283
+
284
+ # NOTE: the original SHA256/512-Crypt specification performs the C digest
285
+ # calculation using the following loop:
286
+ #
287
+ ##dc = da
288
+ ##i = 0
289
+ ##while i < rounds:
290
+ ## tmp_ctx = hash_const(dp if i & 1 else dc)
291
+ ## if i % 3:
292
+ ## tmp_ctx.update(ds)
293
+ ## if i % 7:
294
+ ## tmp_ctx.update(dp)
295
+ ## tmp_ctx.update(dc if i & 1 else dp)
296
+ ## dc = tmp_ctx.digest()
297
+ ## i += 1
298
+ #
299
+ # The code Passlib uses (below) implements an equivalent algorithm,
300
+ # it's just been heavily optimized to pre-calculate a large number
301
+ # of things beforehand. It works off of a couple of observations
302
+ # about the original algorithm:
303
+ #
304
+ # 1. each round is a combination of 'dc', 'ds', and 'dp'; determined
305
+ # by the whether 'i' a multiple of 2,3, and/or 7.
306
+ # 2. since lcm(2,3,7)==42, the series of combinations will repeat
307
+ # every 42 rounds.
308
+ # 3. even rounds 0-40 consist of 'hash(dc + round-specific-constant)';
309
+ # while odd rounds 1-41 consist of hash(round-specific-constant + dc)
310
+ #
311
+ # Using these observations, the following code...
312
+ # * calculates the round-specific combination of ds & dp for each round 0-41
313
+ # * runs through as many 42-round blocks as possible
314
+ # * runs through as many pairs of rounds as possible for remaining rounds
315
+ # * performs once last round if the total rounds should be odd.
316
+ #
317
+ # this cuts out a lot of the control overhead incurred when running the
318
+ # original loop 40,000+ times in python, resulting in ~20% increase in
319
+ # speed under CPython (though still 2x slower than glibc crypt)
320
+
321
+ # prepare the 6 combinations of ds & dp which are needed
322
+ # (order of 'perms' must match how _c_digest_offsets was generated)
323
+ dp_dp = dp + dp
324
+ dp_ds = dp + ds
325
+ perms = [dp, dp_dp, dp_ds, dp_ds + dp, ds + dp, ds + dp_dp]
326
+
327
+ # build up list of even-round & odd-round constants,
328
+ # and store in 21-element list as (even,odd) pairs.
329
+ data = [(perms[even], perms[odd]) for even, odd in _c_digest_offsets]
330
+
331
+ # perform as many full 42-round blocks as possible
332
+ dc = da
333
+ blocks, tail = divmod(rounds, 42)
334
+ while blocks:
335
+ for even, odd in data:
336
+ dc = hash_const(odd + hash_const(dc + even).digest()).digest()
337
+ blocks -= 1
338
+
339
+ # perform any leftover rounds
340
+ if tail:
341
+ # perform any pairs of rounds
342
+ pairs = tail >> 1
343
+ for even, odd in data[:pairs]:
344
+ dc = hash_const(odd + hash_const(dc + even).digest()).digest()
345
+
346
+ # if rounds was odd, do one last round (since we started at 0,
347
+ # last round will be an even-numbered round)
348
+ if tail & 1:
349
+ dc = hash_const(dc + data[pairs][0]).digest()
350
+
351
+ # ===================================================================
352
+ # encode digest using appropriate transpose map
353
+ # ===================================================================
354
+ return h64.encode_transposed_bytes(dc, transpose_map).decode("ascii")
355
+
356
+
357
+ # =============================================================================
358
+ # handlers
359
+ # =============================================================================
360
+ _UROUNDS = "rounds="
361
+ _UDOLLAR = "$"
362
+ _UZERO = "0"
363
+
364
+
365
+ class _SHA2_Common(uh.HasManyBackends, uh.HasRounds, uh.HasSalt, uh.GenericHandler):
366
+ """class containing common code shared by sha256_crypt & sha512_crypt"""
367
+
368
+ # ===================================================================
369
+ # class attrs
370
+ # ===================================================================
371
+ # name - set by subclass
372
+ setting_kwds = ("salt", "rounds", "implicit_rounds", "salt_size")
373
+ # ident - set by subclass
374
+ checksum_chars = uh.HASH64_CHARS
375
+ # checksum_size - set by subclass
376
+
377
+ max_salt_size = 16
378
+ salt_chars = uh.HASH64_CHARS
379
+
380
+ min_rounds = 1000 # bounds set by spec
381
+ max_rounds = 999999999 # bounds set by spec
382
+ rounds_cost = "linear"
383
+
384
+ _cdb_use_512 = False # flag for _calc_digest_builtin()
385
+ _rounds_prefix = None # ident + _UROUNDS
386
+
387
+ # ===================================================================
388
+ # methods
389
+ # ===================================================================
390
+ implicit_rounds = False
391
+
392
+ def __init__(self, implicit_rounds=None, **kwds):
393
+ super().__init__(**kwds)
394
+ # if user calls hash() w/ 5000 rounds, default to compact form.
395
+ if implicit_rounds is None:
396
+ implicit_rounds = self.use_defaults and self.rounds == 5000
397
+ self.implicit_rounds = implicit_rounds
398
+
399
+ def _parse_salt(self, salt):
400
+ # required per SHA2-crypt spec -- truncate config salts rather than throwing error
401
+ return self._norm_salt(salt, relaxed=self.checksum is None)
402
+
403
+ def _parse_rounds(self, rounds):
404
+ # required per SHA2-crypt spec -- clip config rounds rather than throwing error
405
+ return self._norm_rounds(rounds, relaxed=self.checksum is None)
406
+
407
+ @classmethod
408
+ def from_string(cls, hash):
409
+ # basic format this parses -
410
+ # $5$[rounds=<rounds>$]<salt>[$<checksum>]
411
+
412
+ # TODO: this *could* use uh.parse_mc3(), except that the rounds
413
+ # portion has a slightly different grammar.
414
+
415
+ # convert to unicode, check for ident prefix, split on dollar signs.
416
+ hash = to_unicode(hash, "ascii", "hash")
417
+ ident = cls.ident
418
+ if not hash.startswith(ident):
419
+ raise uh.exc.InvalidHashError(cls)
420
+ assert len(ident) == 3
421
+ parts = hash[3:].split(_UDOLLAR)
422
+
423
+ # extract rounds value
424
+ if parts[0].startswith(_UROUNDS):
425
+ assert len(_UROUNDS) == 7
426
+ rounds = parts.pop(0)[7:]
427
+ if rounds.startswith(_UZERO) and rounds != _UZERO:
428
+ raise uh.exc.ZeroPaddedRoundsError(cls)
429
+ rounds = int(rounds)
430
+ implicit_rounds = False
431
+ else:
432
+ rounds = 5000
433
+ implicit_rounds = True
434
+
435
+ # rest should be salt and checksum
436
+ if len(parts) == 2:
437
+ salt, chk = parts
438
+ elif len(parts) == 1:
439
+ salt = parts[0]
440
+ chk = None
441
+ else:
442
+ raise uh.exc.MalformedHashError(cls)
443
+
444
+ # return new object
445
+ return cls(
446
+ rounds=rounds,
447
+ salt=salt,
448
+ checksum=chk or None,
449
+ implicit_rounds=implicit_rounds,
450
+ )
451
+
452
+ def to_string(self):
453
+ if self.rounds == 5000 and self.implicit_rounds:
454
+ hash = "%s%s$%s" % (self.ident, self.salt, self.checksum or "")
455
+ else:
456
+ hash = "%srounds=%d$%s$%s" % (
457
+ self.ident,
458
+ self.rounds,
459
+ self.salt,
460
+ self.checksum or "",
461
+ )
462
+ return hash
463
+
464
+ # ===================================================================
465
+ # backends
466
+ # ===================================================================
467
+ backends = ("os_crypt", "builtin")
468
+
469
+ # ---------------------------------------------------------------
470
+ # os_crypt backend
471
+ # ---------------------------------------------------------------
472
+
473
+ #: test hash for OS detection -- provided by subclass
474
+ _test_hash = None
475
+
476
+ @classmethod
477
+ def _load_backend_os_crypt(cls):
478
+ if test_crypt(*cls._test_hash):
479
+ cls._set_calc_checksum_backend(cls._calc_checksum_os_crypt)
480
+ return True
481
+ else:
482
+ return False
483
+
484
+ def _calc_checksum_os_crypt(self, secret):
485
+ config = self.to_string()
486
+ hash = safe_crypt(secret, config)
487
+ if hash is None:
488
+ # py3's crypt.crypt() can't handle non-utf8 bytes.
489
+ # fallback to builtin alg, which is always available.
490
+ return self._calc_checksum_builtin(secret)
491
+ # NOTE: avoiding full parsing routine via from_string().checksum,
492
+ # and just extracting the bit we need.
493
+ cs = self.checksum_size
494
+ if not hash.startswith(self.ident) or hash[-cs - 1] != _UDOLLAR:
495
+ raise uh.exc.CryptBackendError(self, config, hash)
496
+ return hash[-cs:]
497
+
498
+ # ---------------------------------------------------------------
499
+ # builtin backend
500
+ # ---------------------------------------------------------------
501
+ @classmethod
502
+ def _load_backend_builtin(cls):
503
+ cls._set_calc_checksum_backend(cls._calc_checksum_builtin)
504
+ return True
505
+
506
+ def _calc_checksum_builtin(self, secret):
507
+ return _raw_sha2_crypt(secret, self.salt, self.rounds, self._cdb_use_512)
508
+
509
+ # ===================================================================
510
+ # eoc
511
+ # ===================================================================
512
+
513
+
514
+ class sha256_crypt(_SHA2_Common):
515
+ """This class implements the SHA256-Crypt password hash, and follows the :ref:`password-hash-api`.
516
+
517
+ It supports a variable-length salt, and a variable number of rounds.
518
+
519
+ The :meth:`~passlib.ifc.PasswordHash.using` method accepts the following optional keywords:
520
+
521
+ :type salt: str
522
+ :param salt:
523
+ Optional salt string.
524
+ If not specified, one will be autogenerated (this is recommended).
525
+ If specified, it must be 0-16 characters, drawn from the regexp range ``[./0-9A-Za-z]``.
526
+
527
+ :type rounds: int
528
+ :param rounds:
529
+ Optional number of rounds to use.
530
+ Defaults to 535000, must be between 1000 and 999999999, inclusive.
531
+
532
+ .. note::
533
+ per the official specification, when the rounds parameter is set to 5000,
534
+ it may be omitted from the hash string.
535
+
536
+ :type relaxed: bool
537
+ :param relaxed:
538
+ By default, providing an invalid value for one of the other
539
+ keywords will result in a :exc:`ValueError`. If ``relaxed=True``,
540
+ and the error can be corrected, a :exc:`~passlib.exc.PasslibHashWarning`
541
+ will be issued instead. Correctable errors include ``rounds``
542
+ that are too small or too large, and ``salt`` strings that are too long.
543
+
544
+ .. versionadded:: 1.6
545
+
546
+ ..
547
+ commented out, currently only supported by :meth:`hash`, and not via :meth:`using`:
548
+
549
+ :type implicit_rounds: bool
550
+ :param implicit_rounds:
551
+ this is an internal option which generally doesn't need to be touched.
552
+
553
+ this flag determines whether the hash should omit the rounds parameter
554
+ when encoding it to a string; this is only permitted by the spec for rounds=5000,
555
+ and the flag is ignored otherwise. the spec requires the two different
556
+ encodings be preserved as they are, instead of normalizing them.
557
+ """
558
+
559
+ # ===================================================================
560
+ # class attrs
561
+ # ===================================================================
562
+ name = "sha256_crypt"
563
+ ident = "$5$"
564
+ checksum_size = 43
565
+ # NOTE: using 25/75 weighting of builtin & os_crypt backends
566
+ default_rounds = 535000
567
+
568
+ # ===================================================================
569
+ # backends
570
+ # ===================================================================
571
+ _test_hash = (
572
+ "test",
573
+ "$5$rounds=1000$test$QmQADEXMG8POI5W" "Dsaeho0P36yK3Tcrgboabng6bkb/",
574
+ )
575
+
576
+ # ===================================================================
577
+ # eoc
578
+ # ===================================================================
579
+
580
+
581
+ # =============================================================================
582
+ # sha 512 crypt
583
+ # =============================================================================
584
+ class sha512_crypt(_SHA2_Common):
585
+ """This class implements the SHA512-Crypt password hash, and follows the :ref:`password-hash-api`.
586
+
587
+ It supports a variable-length salt, and a variable number of rounds.
588
+
589
+ The :meth:`~passlib.ifc.PasswordHash.using` method accepts the following optional keywords:
590
+
591
+ :type salt: str
592
+ :param salt:
593
+ Optional salt string.
594
+ If not specified, one will be autogenerated (this is recommended).
595
+ If specified, it must be 0-16 characters, drawn from the regexp range ``[./0-9A-Za-z]``.
596
+
597
+ :type rounds: int
598
+ :param rounds:
599
+ Optional number of rounds to use.
600
+ Defaults to 656000, must be between 1000 and 999999999, inclusive.
601
+
602
+ .. note::
603
+ per the official specification, when the rounds parameter is set to 5000,
604
+ it may be omitted from the hash string.
605
+
606
+ :type relaxed: bool
607
+ :param relaxed:
608
+ By default, providing an invalid value for one of the other
609
+ keywords will result in a :exc:`ValueError`. If ``relaxed=True``,
610
+ and the error can be corrected, a :exc:`~passlib.exc.PasslibHashWarning`
611
+ will be issued instead. Correctable errors include ``rounds``
612
+ that are too small or too large, and ``salt`` strings that are too long.
613
+
614
+ .. versionadded:: 1.6
615
+
616
+ ..
617
+ commented out, currently only supported by :meth:`hash`, and not via :meth:`using`:
618
+
619
+ :type implicit_rounds: bool
620
+ :param implicit_rounds:
621
+ this is an internal option which generally doesn't need to be touched.
622
+
623
+ this flag determines whether the hash should omit the rounds parameter
624
+ when encoding it to a string; this is only permitted by the spec for rounds=5000,
625
+ and the flag is ignored otherwise. the spec requires the two different
626
+ encodings be preserved as they are, instead of normalizing them.
627
+ """
628
+
629
+ # ===================================================================
630
+ # class attrs
631
+ # ===================================================================
632
+ name = "sha512_crypt"
633
+ ident = "$6$"
634
+ checksum_size = 86
635
+ _cdb_use_512 = True
636
+ # NOTE: using 25/75 weighting of builtin & os_crypt backends
637
+ default_rounds = 656000
638
+
639
+ # ===================================================================
640
+ # backend
641
+ # ===================================================================
642
+ _test_hash = (
643
+ "test",
644
+ "$6$rounds=1000$test$2M/Lx6Mtobqj"
645
+ "Ljobw0Wmo4Q5OFx5nVLJvmgseatA6oMn"
646
+ "yWeBdRDx4DU.1H3eGmse6pgsOgDisWBG"
647
+ "I5c7TZauS0",
648
+ )
649
+
650
+ # ===================================================================
651
+ # eoc
652
+ # ===================================================================
653
+
654
+
655
+ # =============================================================================
656
+ # eof
657
+ # =============================================================================