Skip to content

Commit ee271ad

Browse files
committed
code style changes
1 parent 68789d1 commit ee271ad

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

‎auth.go‎

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -228,40 +228,40 @@ func encryptPassword(password string, seed []byte, pub *rsa.PublicKey) ([]byte,
228228
returnrsa.EncryptOAEP(sha1, rand.Reader, pub, plain, nil)
229229
}
230230

231-
// Derived from https://github.com/MariaDB/server/blob/d8e6bb00888b1f82c031938f4c8ac5d97f6874c3/plugin/auth_ed25519/ref10/sign.c
232-
funcdoEd25519Auth(scramble []byte, passwordstring) ([]byte, error){
231+
// authEd25519 does ed25519 authentication used by MariaDB.
232+
funcauthEd25519(scramble []byte, passwordstring) ([]byte, error){
233+
// Derived from https://github.com/MariaDB/server/blob/d8e6bb00888b1f82c031938f4c8ac5d97f6874c3/plugin/auth_ed25519/ref10/sign.c
234+
// Code style is from https://cs.opensource.google/go/go/+/refs/tags/go1.21.5:src/crypto/ed25519/ed25519.go;l=207
233235
h:=sha512.Sum512([]byte(password))
234236

235237
s, err:=edwards25519.NewScalar().SetBytesWithClamping(h[:32])
236238
iferr!=nil{
237239
returnnil, err
238240
}
241+
A:= (&edwards25519.Point{}).ScalarBaseMult(s)
239242

240-
nonceHash:=sha512.New()
241-
nonceHash.Write(h[32:])
242-
nonceHash.Write(scramble)
243-
nonce:=nonceHash.Sum(nil)
244-
245-
r, err:=edwards25519.NewScalar().SetUniformBytes(nonce)
243+
mh:=sha512.New()
244+
mh.Write(h[32:])
245+
mh.Write(scramble)
246+
messageDigest:=mh.Sum(nil)
247+
r, err:=edwards25519.NewScalar().SetUniformBytes(messageDigest)
246248
iferr!=nil{
247249
returnnil, err
248250
}
249-
R:= (&edwards25519.Point{}).ScalarBaseMult(r)
250251

251-
A:= (&edwards25519.Point{}).ScalarBaseMult(s)
252-
253-
kHash:=sha512.New()
254-
kHash.Write(R.Bytes())
255-
kHash.Write(A.Bytes())
256-
kHash.Write(scramble)
257-
k:=kHash.Sum(nil)
252+
R:= (&edwards25519.Point{}).ScalarBaseMult(r)
258253

259-
K, err:=edwards25519.NewScalar().SetUniformBytes(k)
254+
kh:=sha512.New()
255+
kh.Write(R.Bytes())
256+
kh.Write(A.Bytes())
257+
kh.Write(scramble)
258+
hramDigest:=kh.Sum(nil)
259+
k, err:=edwards25519.NewScalar().SetUniformBytes(hramDigest)
260260
iferr!=nil{
261261
returnnil, err
262262
}
263263

264-
S:=K.MultiplyAdd(K, s, r)
264+
S:=k.MultiplyAdd(k, s, r)
265265

266266
returnappend(R.Bytes(), S.Bytes()...), nil
267267
}
@@ -335,8 +335,7 @@ func (mc *mysqlConn) auth(authData []byte, plugin string) ([]byte, error){
335335
iflen(authData) !=32{
336336
returnnil, ErrMalformPkt
337337
}
338-
339-
returndoEd25519Auth(authData, mc.cfg.Passwd)
338+
returnauthEd25519(authData, mc.cfg.Passwd)
340339

341340
default:
342341
mc.cfg.Logger.Print("unknown auth plugin:", plugin)

0 commit comments

Comments
(0)