MCPcopy Create free account
hub / github.com/PyMySQL/PyMySQL / ed25519_password

Function ed25519_password

pymysql/_auth.py:76–111  ·  view source on GitHub ↗

Sign a random scramble with elliptic curve Ed25519. Secret and public key are derived from password.

(password, scramble)

Source from the content-addressed store, hash-verified

74
75
76def ed25519_password(password, scramble):
77 """Sign a random scramble with elliptic curve Ed25519.
78
79 Secret and public key are derived from password.
80 """
81 # variable names based on rfc8032 section-5.1.6
82 #
83 if not _nacl_bindings:
84 _init_nacl()
85
86 # h = SHA512(password)
87 h = hashlib.sha512(password).digest()
88
89 # s = prune(first_half(h))
90 s = _scalar_clamp(h[:32])
91
92 # r = SHA512(second_half(h) || M)
93 r = hashlib.sha512(h[32:] + scramble).digest()
94
95 # R = encoded point [r]B
96 r = _nacl_bindings.crypto_core_ed25519_scalar_reduce(r)
97 R = _nacl_bindings.crypto_scalarmult_ed25519_base_noclamp(r)
98
99 # A = encoded point [s]B
100 A = _nacl_bindings.crypto_scalarmult_ed25519_base_noclamp(s)
101
102 # k = SHA512(R || A || M)
103 k = hashlib.sha512(R + A + scramble).digest()
104
105 # S = (k * s + r) mod L
106 k = _nacl_bindings.crypto_core_ed25519_scalar_reduce(k)
107 ks = _nacl_bindings.crypto_core_ed25519_scalar_mul(k, s)
108 S = _nacl_bindings.crypto_core_ed25519_scalar_add(ks, r)
109
110 # signature = R || S
111 return R + S
112
113
114# sha256_password

Callers

nothing calls this directly

Calls 2

_init_naclFunction · 0.85
_scalar_clampFunction · 0.85

Tested by

no test coverage detected