• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

go-sql-driver / mysql / 14665995848

25 Apr 2025 01:39PM UTC coverage: 82.772% (-0.2%) from 82.961%
14665995848

Pull #1696

github

rusher
use named constants for caching_sha2_password
Pull Request #1696: Authentication

321 of 387 new or added lines in 9 files covered. (82.95%)

7 existing lines in 3 files now uncovered.

3315 of 4005 relevant lines covered (82.77%)

2440698.09 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.62
/auth_ed25519.go
1
// Go MySQL Driver - A MySQL-Driver for Go's database/sql package
2
//
3
// Copyright 2023 The Go-MySQL-Driver Authors. All rights reserved.
4
//
5
// This Source Code Form is subject to the terms of the Mozilla Public
6
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
7
// You can obtain one at http://mozilla.org/MPL/2.0/.
8

9
package mysql
10

11
import (
12
        "crypto/sha512"
13
        "filippo.io/edwards25519"
14
)
15

16
// ClientEd25519Plugin implements the client_ed25519 authentication
17
type ClientEd25519Plugin struct {
18
        SimpleAuth
19
}
20

21
func init() {
32✔
22
        RegisterAuthPlugin(&ClientEd25519Plugin{})
32✔
23
}
32✔
24

25
func (p *ClientEd25519Plugin) PluginName() string {
32✔
26
        return "client_ed25519"
32✔
27
}
32✔
28

29
func (p *ClientEd25519Plugin) InitAuth(authData []byte, cfg *Config) ([]byte, error) {
32✔
30
        // Derived from https://github.com/MariaDB/server/blob/d8e6bb00888b1f82c031938f4c8ac5d97f6874c3/plugin/auth_ed25519/ref10/sign.c
32✔
31
        // Code style is from https://cs.opensource.google/go/go/+/refs/tags/go1.21.5:src/crypto/ed25519/ed25519.go;l=207
32✔
32
        h := sha512.Sum512([]byte(cfg.Passwd))
32✔
33

32✔
34
        s, err := edwards25519.NewScalar().SetBytesWithClamping(h[:32])
32✔
35
        if err != nil {
32✔
NEW
36
                return nil, err
×
NEW
37
        }
×
38
        A := (&edwards25519.Point{}).ScalarBaseMult(s)
32✔
39

32✔
40
        mh := sha512.New()
32✔
41
        mh.Write(h[32:])
32✔
42
        mh.Write(authData)
32✔
43
        messageDigest := mh.Sum(nil)
32✔
44
        r, err := edwards25519.NewScalar().SetUniformBytes(messageDigest)
32✔
45
        if err != nil {
32✔
NEW
46
                return nil, err
×
NEW
47
        }
×
48

49
        R := (&edwards25519.Point{}).ScalarBaseMult(r)
32✔
50

32✔
51
        kh := sha512.New()
32✔
52
        kh.Write(R.Bytes())
32✔
53
        kh.Write(A.Bytes())
32✔
54
        kh.Write(authData)
32✔
55
        hramDigest := kh.Sum(nil)
32✔
56
        k, err := edwards25519.NewScalar().SetUniformBytes(hramDigest)
32✔
57
        if err != nil {
32✔
NEW
58
                return nil, err
×
NEW
59
        }
×
60

61
        S := k.MultiplyAdd(k, s, r)
32✔
62

32✔
63
        return append(R.Bytes(), S.Bytes()...), nil
32✔
64
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc