Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
405cb3bdea | ||
|
|
913d3ae741 | ||
|
|
dbb6ec16ec | ||
|
|
403f69900e | ||
|
|
055043dfed | ||
|
|
08396bb92b | ||
|
|
9d2ee975ef | ||
|
|
4e5a26183e | ||
|
|
152cdb1503 | ||
|
|
fdfe1f8531 | ||
|
|
b8ffc16e10 | ||
|
|
7e6fbd82c8 | ||
|
|
bda2f3f5cf | ||
|
|
325b735346 | ||
|
|
1eadac50a5 | ||
|
|
b2d7c26edb | ||
|
|
1c17e20020 | ||
|
|
270bf2552c | ||
|
|
1cf1811d71 | ||
|
|
a2edfb5072 | ||
|
|
ff15cd57d1 | ||
|
|
eb61739cd9 | ||
|
|
42c83fffff | ||
|
|
e668aa9b45 | ||
|
|
df0bc9e1bb | ||
|
|
74c2ba9521 | ||
|
|
cf8dcb0f7d | ||
|
|
4f30245552 | ||
|
|
1d57292618 | ||
|
|
8779cbd1c9 | ||
|
|
2aeefc3f8a | ||
|
|
e3cc52e598 | ||
|
|
833695f0a5 | ||
|
|
ec07f4e35b | ||
|
|
b665ba6f6f | ||
|
|
a1aeb9b34e | ||
|
|
28c53ff63c | ||
|
|
3f0842a464 | ||
|
|
e90f1e17ee | ||
|
|
d359caa4a3 | ||
|
|
c5370d2cc6 | ||
|
|
0d375be9b6 | ||
|
|
b4ddeeda5b | ||
|
|
edc325d13a | ||
|
|
eab9315960 | ||
|
|
ddfa82138e | ||
|
|
d08e19beac | ||
|
|
12e1fcd8c0 | ||
|
|
3f8f0645c2 | ||
|
|
5df3b59941 | ||
|
|
2e82bdd171 | ||
|
|
64e0e99383 | ||
|
|
23b1b90df2 | ||
|
|
e98487292d | ||
|
|
183630ada7 | ||
|
|
a9e447dde7 | ||
|
|
64c3993f5c | ||
|
|
5fe8145aca | ||
|
|
043e94c17a | ||
|
|
0d502d7cd6 | ||
|
|
0ff60057bb | ||
|
|
8e447d8cc5 | ||
|
|
22c9997952 | ||
|
|
d0b316056b | ||
|
|
16222386f4 | ||
|
|
a4e984136a | ||
|
|
3ef8056490 | ||
|
|
a8cc953517 | ||
|
|
7d6d3f5d4a | ||
|
|
1faeef9713 | ||
|
|
00fd4ff485 | ||
|
|
018c28f8a1 | ||
|
|
9cd0187c09 | ||
|
|
c6a20f9984 | ||
|
|
776e461a4e | ||
|
|
ebe92624d1 | ||
|
|
a9f661cb6e | ||
|
|
310bfa40f1 | ||
|
|
59ff47295c | ||
|
|
3d872d0428 | ||
|
|
bc7d1d1eb5 | ||
|
|
7e3ac2043e | ||
|
|
23edec0b38 | ||
|
|
f495dc37d5 | ||
|
|
eb2c406296 | ||
|
|
2c476679df | ||
|
|
0ec7e8322c | ||
|
|
6fad3dfc18 | ||
|
|
21d60a1521 |
+9
-22
@@ -354,11 +354,12 @@ func TestWaitAuthorization(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
t.Run("context cancel", func(t *testing.T) {
|
t.Run("context cancel", func(t *testing.T) {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 200*time.Millisecond)
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
_, err := runWaitAuthorization(ctx, t, func(w http.ResponseWriter, r *http.Request) {
|
_, err := runWaitAuthorization(ctx, t, func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Retry-After", "60")
|
w.Header().Set("Retry-After", "60")
|
||||||
fmt.Fprintf(w, `{"status":"pending"}`)
|
fmt.Fprintf(w, `{"status":"pending"}`)
|
||||||
|
time.AfterFunc(1*time.Millisecond, cancel)
|
||||||
})
|
})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Error("err is nil")
|
t.Error("err is nil")
|
||||||
@@ -373,28 +374,14 @@ func runWaitAuthorization(ctx context.Context, t *testing.T, h http.HandlerFunc)
|
|||||||
h(w, r)
|
h(w, r)
|
||||||
}))
|
}))
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
type res struct {
|
|
||||||
authz *Authorization
|
client := &Client{
|
||||||
err error
|
Key: testKey,
|
||||||
|
DirectoryURL: ts.URL,
|
||||||
|
dir: &Directory{},
|
||||||
|
KID: "some-key-id", // set to avoid lookup attempt
|
||||||
}
|
}
|
||||||
ch := make(chan res, 1)
|
return client.WaitAuthorization(ctx, ts.URL)
|
||||||
go func() {
|
|
||||||
client := &Client{
|
|
||||||
Key: testKey,
|
|
||||||
DirectoryURL: ts.URL,
|
|
||||||
dir: &Directory{},
|
|
||||||
KID: "some-key-id", // set to avoid lookup attempt
|
|
||||||
}
|
|
||||||
a, err := client.WaitAuthorization(ctx, ts.URL)
|
|
||||||
ch <- res{a, err}
|
|
||||||
}()
|
|
||||||
select {
|
|
||||||
case <-time.After(3 * time.Second):
|
|
||||||
t.Fatal("WaitAuthorization took too long to return")
|
|
||||||
case v := <-ch:
|
|
||||||
return v.authz, v.err
|
|
||||||
}
|
|
||||||
panic("runWaitAuthorization: out of select")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRevokeAuthorization(t *testing.T) {
|
func TestRevokeAuthorization(t *testing.T) {
|
||||||
|
|||||||
@@ -427,18 +427,7 @@ func TestGetCertificate(t *testing.T) {
|
|||||||
|
|
||||||
man.Client = &acme.Client{DirectoryURL: s.URL()}
|
man.Client = &acme.Client{DirectoryURL: s.URL()}
|
||||||
|
|
||||||
var tlscert *tls.Certificate
|
tlscert, err := man.GetCertificate(tt.hello)
|
||||||
var err error
|
|
||||||
done := make(chan struct{})
|
|
||||||
go func() {
|
|
||||||
tlscert, err = man.GetCertificate(tt.hello)
|
|
||||||
close(done)
|
|
||||||
}()
|
|
||||||
select {
|
|
||||||
case <-time.After(time.Minute):
|
|
||||||
t.Fatal("man.GetCertificate took too long to return")
|
|
||||||
case <-done:
|
|
||||||
}
|
|
||||||
if tt.expectError != "" {
|
if tt.expectError != "" {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("expected error, got certificate")
|
t.Fatal("expected error, got certificate")
|
||||||
@@ -515,15 +504,12 @@ func TestGetCertificate_failedAttempt(t *testing.T) {
|
|||||||
if _, err := man.GetCertificate(hello); err == nil {
|
if _, err := man.GetCertificate(hello); err == nil {
|
||||||
t.Error("GetCertificate: err is nil")
|
t.Error("GetCertificate: err is nil")
|
||||||
}
|
}
|
||||||
select {
|
|
||||||
case <-time.After(5 * time.Second):
|
<-done
|
||||||
t.Errorf("took too long to remove the %q state", exampleCertKey)
|
man.stateMu.Lock()
|
||||||
case <-done:
|
defer man.stateMu.Unlock()
|
||||||
man.stateMu.Lock()
|
if v, exist := man.state[exampleCertKey]; exist {
|
||||||
defer man.stateMu.Unlock()
|
t.Errorf("state exists for %v: %+v", exampleCertKey, v)
|
||||||
if v, exist := man.state[exampleCertKey]; exist {
|
|
||||||
t.Errorf("state exists for %v: %+v", exampleCertKey, v)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -542,8 +528,9 @@ func TestRevokeFailedAuthz(t *testing.T) {
|
|||||||
t.Fatal("expected GetCertificate to fail")
|
t.Fatal("expected GetCertificate to fail")
|
||||||
}
|
}
|
||||||
|
|
||||||
start := time.Now()
|
logTicker := time.NewTicker(3 * time.Second)
|
||||||
for time.Since(start) < 3*time.Second {
|
defer logTicker.Stop()
|
||||||
|
for {
|
||||||
authz, err := m.Client.GetAuthorization(context.Background(), ca.URL()+"/authz/0")
|
authz, err := m.Client.GetAuthorization(context.Background(), ca.URL()+"/authz/0")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@@ -551,10 +538,14 @@ func TestRevokeFailedAuthz(t *testing.T) {
|
|||||||
if authz.Status == acme.StatusDeactivated {
|
if authz.Status == acme.StatusDeactivated {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
select {
|
||||||
|
case <-logTicker.C:
|
||||||
|
t.Logf("still waiting on revocations")
|
||||||
|
default:
|
||||||
|
}
|
||||||
time.Sleep(50 * time.Millisecond)
|
time.Sleep(50 * time.Millisecond)
|
||||||
}
|
}
|
||||||
t.Error("revocations took too long")
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHTTPHandlerDefaultFallback(t *testing.T) {
|
func TestHTTPHandlerDefaultFallback(t *testing.T) {
|
||||||
|
|||||||
+1
-1
@@ -117,7 +117,7 @@ func (c *Client) updateRegRFC(ctx context.Context, a *Account) (*Account, error)
|
|||||||
return responseAccount(res)
|
return responseAccount(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
// getGegRFC is equivalent to c.GetReg but for CAs implementing RFC 8555.
|
// getRegRFC is equivalent to c.GetReg but for CAs implementing RFC 8555.
|
||||||
// It expects c.Discover to have already been called.
|
// It expects c.Discover to have already been called.
|
||||||
func (c *Client) getRegRFC(ctx context.Context) (*Account, error) {
|
func (c *Client) getRegRFC(ctx context.Context) (*Account, error) {
|
||||||
req := json.RawMessage(`{"onlyReturnExisting": true}`)
|
req := json.RawMessage(`{"onlyReturnExisting": true}`)
|
||||||
|
|||||||
+25
-50
@@ -177,8 +177,7 @@ func TestRFC_postKID(t *testing.T) {
|
|||||||
}))
|
}))
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
ctx := context.Background()
|
||||||
defer cancel()
|
|
||||||
cl := &Client{
|
cl := &Client{
|
||||||
Key: testKey,
|
Key: testKey,
|
||||||
DirectoryURL: ts.URL,
|
DirectoryURL: ts.URL,
|
||||||
@@ -316,8 +315,7 @@ func TestRFC_Register(t *testing.T) {
|
|||||||
s.start()
|
s.start()
|
||||||
defer s.close()
|
defer s.close()
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
ctx := context.Background()
|
||||||
defer cancel()
|
|
||||||
cl := &Client{
|
cl := &Client{
|
||||||
Key: testKeyEC,
|
Key: testKeyEC,
|
||||||
DirectoryURL: s.url("/"),
|
DirectoryURL: s.url("/"),
|
||||||
@@ -454,8 +452,7 @@ func TestRFC_RegisterExternalAccountBinding(t *testing.T) {
|
|||||||
s.start()
|
s.start()
|
||||||
defer s.close()
|
defer s.close()
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
ctx := context.Background()
|
||||||
defer cancel()
|
|
||||||
cl := &Client{
|
cl := &Client{
|
||||||
Key: testKeyEC,
|
Key: testKeyEC,
|
||||||
DirectoryURL: s.url("/"),
|
DirectoryURL: s.url("/"),
|
||||||
@@ -867,24 +864,13 @@ func testWaitOrderStatus(t *testing.T, okStatus string) {
|
|||||||
s.start()
|
s.start()
|
||||||
defer s.close()
|
defer s.close()
|
||||||
|
|
||||||
var order *Order
|
cl := &Client{Key: testKeyEC, DirectoryURL: s.url("/")}
|
||||||
var err error
|
order, err := cl.WaitOrder(context.Background(), s.url("/orders/1"))
|
||||||
done := make(chan struct{})
|
if err != nil {
|
||||||
go func() {
|
t.Fatalf("WaitOrder: %v", err)
|
||||||
cl := &Client{Key: testKeyEC, DirectoryURL: s.url("/")}
|
}
|
||||||
order, err = cl.WaitOrder(context.Background(), s.url("/orders/1"))
|
if order.Status != okStatus {
|
||||||
close(done)
|
t.Errorf("order.Status = %q; want %q", order.Status, okStatus)
|
||||||
}()
|
|
||||||
select {
|
|
||||||
case <-time.After(3 * time.Second):
|
|
||||||
t.Fatal("WaitOrder took too long to return")
|
|
||||||
case <-done:
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("WaitOrder: %v", err)
|
|
||||||
}
|
|
||||||
if order.Status != okStatus {
|
|
||||||
t.Errorf("order.Status = %q; want %q", order.Status, okStatus)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -909,30 +895,20 @@ func TestRFC_WaitOrderError(t *testing.T) {
|
|||||||
s.start()
|
s.start()
|
||||||
defer s.close()
|
defer s.close()
|
||||||
|
|
||||||
var err error
|
cl := &Client{Key: testKeyEC, DirectoryURL: s.url("/")}
|
||||||
done := make(chan struct{})
|
_, err := cl.WaitOrder(context.Background(), s.url("/orders/1"))
|
||||||
go func() {
|
if err == nil {
|
||||||
cl := &Client{Key: testKeyEC, DirectoryURL: s.url("/")}
|
t.Fatal("WaitOrder returned nil error")
|
||||||
_, err = cl.WaitOrder(context.Background(), s.url("/orders/1"))
|
}
|
||||||
close(done)
|
e, ok := err.(*OrderError)
|
||||||
}()
|
if !ok {
|
||||||
select {
|
t.Fatalf("err = %v (%T); want OrderError", err, err)
|
||||||
case <-time.After(3 * time.Second):
|
}
|
||||||
t.Fatal("WaitOrder took too long to return")
|
if e.OrderURL != s.url("/orders/1") {
|
||||||
case <-done:
|
t.Errorf("e.OrderURL = %q; want %q", e.OrderURL, s.url("/orders/1"))
|
||||||
if err == nil {
|
}
|
||||||
t.Fatal("WaitOrder returned nil error")
|
if e.Status != StatusInvalid {
|
||||||
}
|
t.Errorf("e.Status = %q; want %q", e.Status, StatusInvalid)
|
||||||
e, ok := err.(*OrderError)
|
|
||||||
if !ok {
|
|
||||||
t.Fatalf("err = %v (%T); want OrderError", err, err)
|
|
||||||
}
|
|
||||||
if e.OrderURL != s.url("/orders/1") {
|
|
||||||
t.Errorf("e.OrderURL = %q; want %q", e.OrderURL, s.url("/orders/1"))
|
|
||||||
}
|
|
||||||
if e.Status != StatusInvalid {
|
|
||||||
t.Errorf("e.Status = %q; want %q", e.Status, StatusInvalid)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -972,8 +948,7 @@ func TestRFC_CreateOrderCert(t *testing.T) {
|
|||||||
})
|
})
|
||||||
s.start()
|
s.start()
|
||||||
defer s.close()
|
defer s.close()
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
ctx := context.Background()
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
cl := &Client{Key: testKeyEC, DirectoryURL: s.url("/")}
|
cl := &Client{Key: testKeyEC, DirectoryURL: s.url("/")}
|
||||||
cert, curl, err := cl.CreateOrderCert(ctx, s.url("/pleaseissue"), csr, true)
|
cert, curl, err := cl.CreateOrderCert(ctx, s.url("/pleaseissue"), csr, true)
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build go1.12
|
//go:build go1.12
|
||||||
// +build go1.12
|
|
||||||
|
|
||||||
package acme
|
package acme
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build amd64 && gc && !purego
|
//go:build amd64 && gc && !purego
|
||||||
// +build amd64,gc,!purego
|
|
||||||
|
|
||||||
package argon2
|
package argon2
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build amd64 && gc && !purego
|
//go:build amd64 && gc && !purego
|
||||||
// +build amd64,gc,!purego
|
|
||||||
|
|
||||||
#include "textflag.h"
|
#include "textflag.h"
|
||||||
|
|
||||||
@@ -200,8 +199,8 @@ TEXT ·mixBlocksSSE2(SB), 4, $0-32
|
|||||||
MOVQ out+0(FP), DX
|
MOVQ out+0(FP), DX
|
||||||
MOVQ a+8(FP), AX
|
MOVQ a+8(FP), AX
|
||||||
MOVQ b+16(FP), BX
|
MOVQ b+16(FP), BX
|
||||||
MOVQ a+24(FP), CX
|
MOVQ c+24(FP), CX
|
||||||
MOVQ $128, BP
|
MOVQ $128, DI
|
||||||
|
|
||||||
loop:
|
loop:
|
||||||
MOVOU 0(AX), X0
|
MOVOU 0(AX), X0
|
||||||
@@ -214,7 +213,7 @@ loop:
|
|||||||
ADDQ $16, BX
|
ADDQ $16, BX
|
||||||
ADDQ $16, CX
|
ADDQ $16, CX
|
||||||
ADDQ $16, DX
|
ADDQ $16, DX
|
||||||
SUBQ $2, BP
|
SUBQ $2, DI
|
||||||
JA loop
|
JA loop
|
||||||
RET
|
RET
|
||||||
|
|
||||||
@@ -223,8 +222,8 @@ TEXT ·xorBlocksSSE2(SB), 4, $0-32
|
|||||||
MOVQ out+0(FP), DX
|
MOVQ out+0(FP), DX
|
||||||
MOVQ a+8(FP), AX
|
MOVQ a+8(FP), AX
|
||||||
MOVQ b+16(FP), BX
|
MOVQ b+16(FP), BX
|
||||||
MOVQ a+24(FP), CX
|
MOVQ c+24(FP), CX
|
||||||
MOVQ $128, BP
|
MOVQ $128, DI
|
||||||
|
|
||||||
loop:
|
loop:
|
||||||
MOVOU 0(AX), X0
|
MOVOU 0(AX), X0
|
||||||
@@ -239,6 +238,6 @@ loop:
|
|||||||
ADDQ $16, BX
|
ADDQ $16, BX
|
||||||
ADDQ $16, CX
|
ADDQ $16, CX
|
||||||
ADDQ $16, DX
|
ADDQ $16, DX
|
||||||
SUBQ $2, BP
|
SUBQ $2, DI
|
||||||
JA loop
|
JA loop
|
||||||
RET
|
RET
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build !amd64 || purego || !gc
|
//go:build !amd64 || purego || !gc
|
||||||
// +build !amd64 purego !gc
|
|
||||||
|
|
||||||
package argon2
|
package argon2
|
||||||
|
|
||||||
|
|||||||
+10
-1
@@ -50,7 +50,7 @@ func (ih InvalidHashPrefixError) Error() string {
|
|||||||
type InvalidCostError int
|
type InvalidCostError int
|
||||||
|
|
||||||
func (ic InvalidCostError) Error() string {
|
func (ic InvalidCostError) Error() string {
|
||||||
return fmt.Sprintf("crypto/bcrypt: cost %d is outside allowed range (%d,%d)", int(ic), int(MinCost), int(MaxCost))
|
return fmt.Sprintf("crypto/bcrypt: cost %d is outside allowed range (%d,%d)", int(ic), MinCost, MaxCost)
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -82,11 +82,20 @@ type hashed struct {
|
|||||||
minor byte
|
minor byte
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ErrPasswordTooLong is returned when the password passed to
|
||||||
|
// GenerateFromPassword is too long (i.e. > 72 bytes).
|
||||||
|
var ErrPasswordTooLong = errors.New("bcrypt: password length exceeds 72 bytes")
|
||||||
|
|
||||||
// GenerateFromPassword returns the bcrypt hash of the password at the given
|
// GenerateFromPassword returns the bcrypt hash of the password at the given
|
||||||
// cost. If the cost given is less than MinCost, the cost will be set to
|
// cost. If the cost given is less than MinCost, the cost will be set to
|
||||||
// DefaultCost, instead. Use CompareHashAndPassword, as defined in this package,
|
// DefaultCost, instead. Use CompareHashAndPassword, as defined in this package,
|
||||||
// to compare the returned hashed password with its cleartext version.
|
// to compare the returned hashed password with its cleartext version.
|
||||||
|
// GenerateFromPassword does not accept passwords longer than 72 bytes, which
|
||||||
|
// is the longest password bcrypt will operate on.
|
||||||
func GenerateFromPassword(password []byte, cost int) ([]byte, error) {
|
func GenerateFromPassword(password []byte, cost int) ([]byte, error) {
|
||||||
|
if len(password) > 72 {
|
||||||
|
return nil, ErrPasswordTooLong
|
||||||
|
}
|
||||||
p, err := newFromPassword(password, cost)
|
p, err := newFromPassword(password, cost)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -241,3 +241,10 @@ func TestNoSideEffectsFromCompare(t *testing.T) {
|
|||||||
t.Errorf("got=%q want=%q", got, want)
|
t.Errorf("got=%q want=%q", got, want)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPasswordTooLong(t *testing.T) {
|
||||||
|
_, err := GenerateFromPassword(make([]byte, 73), 1)
|
||||||
|
if err != ErrPasswordTooLong {
|
||||||
|
t.Errorf("unexpected error: got %q, want %q", err, ErrPasswordTooLong)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,8 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build go1.7 && amd64 && gc && !purego
|
//go:build amd64 && gc && !purego
|
||||||
// +build go1.7,amd64,gc,!purego
|
|
||||||
|
|
||||||
package blake2b
|
package blake2b
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build go1.7 && amd64 && gc && !purego
|
//go:build amd64 && gc && !purego
|
||||||
// +build go1.7,amd64,gc,!purego
|
|
||||||
|
|
||||||
#include "textflag.h"
|
#include "textflag.h"
|
||||||
|
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
// Copyright 2016 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
//go:build !go1.7 && amd64 && gc && !purego
|
|
||||||
// +build !go1.7,amd64,gc,!purego
|
|
||||||
|
|
||||||
package blake2b
|
|
||||||
|
|
||||||
import "golang.org/x/sys/cpu"
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
useSSE4 = cpu.X86.HasSSE41
|
|
||||||
}
|
|
||||||
|
|
||||||
//go:noescape
|
|
||||||
func hashBlocksSSE4(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte)
|
|
||||||
|
|
||||||
func hashBlocks(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte) {
|
|
||||||
if useSSE4 {
|
|
||||||
hashBlocksSSE4(h, c, flag, blocks)
|
|
||||||
} else {
|
|
||||||
hashBlocksGeneric(h, c, flag, blocks)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build amd64 && gc && !purego
|
//go:build amd64 && gc && !purego
|
||||||
// +build amd64,gc,!purego
|
|
||||||
|
|
||||||
#include "textflag.h"
|
#include "textflag.h"
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build !amd64 || purego || !gc
|
//go:build !amd64 || purego || !gc
|
||||||
// +build !amd64 purego !gc
|
|
||||||
|
|
||||||
package blake2b
|
package blake2b
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build go1.9
|
|
||||||
// +build go1.9
|
|
||||||
|
|
||||||
package blake2b
|
package blake2b
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build 386 && gc && !purego
|
//go:build 386 && gc && !purego
|
||||||
// +build 386,gc,!purego
|
|
||||||
|
|
||||||
package blake2s
|
package blake2s
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build 386 && gc && !purego
|
//go:build 386 && gc && !purego
|
||||||
// +build 386,gc,!purego
|
|
||||||
|
|
||||||
#include "textflag.h"
|
#include "textflag.h"
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build amd64 && gc && !purego
|
//go:build amd64 && gc && !purego
|
||||||
// +build amd64,gc,!purego
|
|
||||||
|
|
||||||
package blake2s
|
package blake2s
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build amd64 && gc && !purego
|
//go:build amd64 && gc && !purego
|
||||||
// +build amd64,gc,!purego
|
|
||||||
|
|
||||||
#include "textflag.h"
|
#include "textflag.h"
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build (!amd64 && !386) || !gc || purego
|
//go:build (!amd64 && !386) || !gc || purego
|
||||||
// +build !amd64,!386 !gc purego
|
|
||||||
|
|
||||||
package blake2s
|
package blake2s
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build go1.9
|
//go:build go1.9
|
||||||
// +build go1.9
|
|
||||||
|
|
||||||
package blake2s
|
package blake2s
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build go1.11 && gc && !purego
|
//go:build gc && !purego
|
||||||
// +build go1.11,gc,!purego
|
|
||||||
|
|
||||||
package chacha20
|
package chacha20
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build go1.11 && gc && !purego
|
//go:build gc && !purego
|
||||||
// +build go1.11,gc,!purego
|
|
||||||
|
|
||||||
#include "textflag.h"
|
#include "textflag.h"
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build (!arm64 && !s390x && !ppc64le) || (arm64 && !go1.11) || !gc || purego
|
//go:build (!arm64 && !s390x && !ppc64le) || !gc || purego
|
||||||
// +build !arm64,!s390x,!ppc64le arm64,!go1.11 !gc purego
|
|
||||||
|
|
||||||
package chacha20
|
package chacha20
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build gc && !purego
|
//go:build gc && !purego
|
||||||
// +build gc,!purego
|
|
||||||
|
|
||||||
package chacha20
|
package chacha20
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,6 @@
|
|||||||
// due to the calling conventions and initialization of constants.
|
// due to the calling conventions and initialization of constants.
|
||||||
|
|
||||||
//go:build gc && !purego
|
//go:build gc && !purego
|
||||||
// +build gc,!purego
|
|
||||||
|
|
||||||
#include "textflag.h"
|
#include "textflag.h"
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build gc && !purego
|
//go:build gc && !purego
|
||||||
// +build gc,!purego
|
|
||||||
|
|
||||||
package chacha20
|
package chacha20
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build gc && !purego
|
//go:build gc && !purego
|
||||||
// +build gc,!purego
|
|
||||||
|
|
||||||
#include "go_asm.h"
|
#include "go_asm.h"
|
||||||
#include "textflag.h"
|
#include "textflag.h"
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build gc && !purego
|
//go:build gc && !purego
|
||||||
// +build gc,!purego
|
|
||||||
|
|
||||||
package chacha20poly1305
|
package chacha20poly1305
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
// This file was originally from https://golang.org/cl/24717 by Vlad Krasnov of CloudFlare.
|
// This file was originally from https://golang.org/cl/24717 by Vlad Krasnov of CloudFlare.
|
||||||
|
|
||||||
//go:build gc && !purego
|
//go:build gc && !purego
|
||||||
// +build gc,!purego
|
|
||||||
|
|
||||||
#include "textflag.h"
|
#include "textflag.h"
|
||||||
// General register allocation
|
// General register allocation
|
||||||
@@ -184,11 +183,31 @@ GLOBL ·andMask<>(SB), (NOPTR+RODATA), $240
|
|||||||
#define shiftD1Right BYTE $0x66; BYTE $0x45; BYTE $0x0f; BYTE $0x3a; BYTE $0x0f; BYTE $0xd2; BYTE $0x04 // PALIGNR $4, X10, X10
|
#define shiftD1Right BYTE $0x66; BYTE $0x45; BYTE $0x0f; BYTE $0x3a; BYTE $0x0f; BYTE $0xd2; BYTE $0x04 // PALIGNR $4, X10, X10
|
||||||
#define shiftD2Right BYTE $0x66; BYTE $0x45; BYTE $0x0f; BYTE $0x3a; BYTE $0x0f; BYTE $0xdb; BYTE $0x04 // PALIGNR $4, X11, X11
|
#define shiftD2Right BYTE $0x66; BYTE $0x45; BYTE $0x0f; BYTE $0x3a; BYTE $0x0f; BYTE $0xdb; BYTE $0x04 // PALIGNR $4, X11, X11
|
||||||
#define shiftD3Right BYTE $0x66; BYTE $0x45; BYTE $0x0f; BYTE $0x3a; BYTE $0x0f; BYTE $0xff; BYTE $0x04 // PALIGNR $4, X15, X15
|
#define shiftD3Right BYTE $0x66; BYTE $0x45; BYTE $0x0f; BYTE $0x3a; BYTE $0x0f; BYTE $0xff; BYTE $0x04 // PALIGNR $4, X15, X15
|
||||||
|
|
||||||
// Some macros
|
// Some macros
|
||||||
|
|
||||||
|
// ROL rotates the uint32s in register R left by N bits, using temporary T.
|
||||||
|
#define ROL(N, R, T) \
|
||||||
|
MOVO R, T; PSLLL $(N), T; PSRLL $(32-(N)), R; PXOR T, R
|
||||||
|
|
||||||
|
// ROL16 rotates the uint32s in register R left by 16, using temporary T if needed.
|
||||||
|
#ifdef GOAMD64_v2
|
||||||
|
#define ROL16(R, T) PSHUFB ·rol16<>(SB), R
|
||||||
|
#else
|
||||||
|
#define ROL16(R, T) ROL(16, R, T)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ROL8 rotates the uint32s in register R left by 8, using temporary T if needed.
|
||||||
|
#ifdef GOAMD64_v2
|
||||||
|
#define ROL8(R, T) PSHUFB ·rol8<>(SB), R
|
||||||
|
#else
|
||||||
|
#define ROL8(R, T) ROL(8, R, T)
|
||||||
|
#endif
|
||||||
|
|
||||||
#define chachaQR(A, B, C, D, T) \
|
#define chachaQR(A, B, C, D, T) \
|
||||||
PADDD B, A; PXOR A, D; PSHUFB ·rol16<>(SB), D \
|
PADDD B, A; PXOR A, D; ROL16(D, T) \
|
||||||
PADDD D, C; PXOR C, B; MOVO B, T; PSLLL $12, T; PSRLL $20, B; PXOR T, B \
|
PADDD D, C; PXOR C, B; MOVO B, T; PSLLL $12, T; PSRLL $20, B; PXOR T, B \
|
||||||
PADDD B, A; PXOR A, D; PSHUFB ·rol8<>(SB), D \
|
PADDD B, A; PXOR A, D; ROL8(D, T) \
|
||||||
PADDD D, C; PXOR C, B; MOVO B, T; PSLLL $7, T; PSRLL $25, B; PXOR T, B
|
PADDD D, C; PXOR C, B; MOVO B, T; PSLLL $7, T; PSRLL $25, B; PXOR T, B
|
||||||
|
|
||||||
#define chachaQR_AVX2(A, B, C, D, T) \
|
#define chachaQR_AVX2(A, B, C, D, T) \
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build !amd64 || !gc || purego
|
//go:build !amd64 || !gc || purego
|
||||||
// +build !amd64 !gc purego
|
|
||||||
|
|
||||||
package chacha20poly1305
|
package chacha20poly1305
|
||||||
|
|
||||||
|
|||||||
+58
-42
@@ -264,36 +264,35 @@ func (s *String) ReadASN1Boolean(out *bool) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
var bigIntType = reflect.TypeOf((*big.Int)(nil)).Elem()
|
|
||||||
|
|
||||||
// ReadASN1Integer decodes an ASN.1 INTEGER into out and advances. If out does
|
// ReadASN1Integer decodes an ASN.1 INTEGER into out and advances. If out does
|
||||||
// not point to an integer or to a big.Int, it panics. It reports whether the
|
// not point to an integer, to a big.Int, or to a []byte it panics. Only
|
||||||
// read was successful.
|
// positive and zero values can be decoded into []byte, and they are returned as
|
||||||
|
// big-endian binary values that share memory with s. Positive values will have
|
||||||
|
// no leading zeroes, and zero will be returned as a single zero byte.
|
||||||
|
// ReadASN1Integer reports whether the read was successful.
|
||||||
func (s *String) ReadASN1Integer(out interface{}) bool {
|
func (s *String) ReadASN1Integer(out interface{}) bool {
|
||||||
if reflect.TypeOf(out).Kind() != reflect.Ptr {
|
switch out := out.(type) {
|
||||||
panic("out is not a pointer")
|
case *int, *int8, *int16, *int32, *int64:
|
||||||
}
|
|
||||||
switch reflect.ValueOf(out).Elem().Kind() {
|
|
||||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
|
||||||
var i int64
|
var i int64
|
||||||
if !s.readASN1Int64(&i) || reflect.ValueOf(out).Elem().OverflowInt(i) {
|
if !s.readASN1Int64(&i) || reflect.ValueOf(out).Elem().OverflowInt(i) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
reflect.ValueOf(out).Elem().SetInt(i)
|
reflect.ValueOf(out).Elem().SetInt(i)
|
||||||
return true
|
return true
|
||||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
case *uint, *uint8, *uint16, *uint32, *uint64:
|
||||||
var u uint64
|
var u uint64
|
||||||
if !s.readASN1Uint64(&u) || reflect.ValueOf(out).Elem().OverflowUint(u) {
|
if !s.readASN1Uint64(&u) || reflect.ValueOf(out).Elem().OverflowUint(u) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
reflect.ValueOf(out).Elem().SetUint(u)
|
reflect.ValueOf(out).Elem().SetUint(u)
|
||||||
return true
|
return true
|
||||||
case reflect.Struct:
|
case *big.Int:
|
||||||
if reflect.TypeOf(out).Elem() == bigIntType {
|
return s.readASN1BigInt(out)
|
||||||
return s.readASN1BigInt(out.(*big.Int))
|
case *[]byte:
|
||||||
}
|
return s.readASN1Bytes(out)
|
||||||
|
default:
|
||||||
|
panic("out does not point to an integer type")
|
||||||
}
|
}
|
||||||
panic("out does not point to an integer type")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkASN1Integer(bytes []byte) bool {
|
func checkASN1Integer(bytes []byte) bool {
|
||||||
@@ -333,6 +332,21 @@ func (s *String) readASN1BigInt(out *big.Int) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *String) readASN1Bytes(out *[]byte) bool {
|
||||||
|
var bytes String
|
||||||
|
if !s.ReadASN1(&bytes, asn1.INTEGER) || !checkASN1Integer(bytes) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if bytes[0]&0x80 == 0x80 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for len(bytes) > 1 && bytes[0] == 0 {
|
||||||
|
bytes = bytes[1:]
|
||||||
|
}
|
||||||
|
*out = bytes
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func (s *String) readASN1Int64(out *int64) bool {
|
func (s *String) readASN1Int64(out *int64) bool {
|
||||||
var bytes String
|
var bytes String
|
||||||
if !s.ReadASN1(&bytes, asn1.INTEGER) || !checkASN1Integer(bytes) || !asn1Signed(out, bytes) {
|
if !s.ReadASN1(&bytes, asn1.INTEGER) || !checkASN1Integer(bytes) || !asn1Signed(out, bytes) {
|
||||||
@@ -417,6 +431,14 @@ func (s *String) readBase128Int(out *int) bool {
|
|||||||
}
|
}
|
||||||
ret <<= 7
|
ret <<= 7
|
||||||
b := s.read(1)[0]
|
b := s.read(1)[0]
|
||||||
|
|
||||||
|
// ITU-T X.690, section 8.19.2:
|
||||||
|
// The subidentifier shall be encoded in the fewest possible octets,
|
||||||
|
// that is, the leading octet of the subidentifier shall not have the value 0x80.
|
||||||
|
if i == 0 && b == 0x80 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
ret |= int(b & 0x7f)
|
ret |= int(b & 0x7f)
|
||||||
if b&0x80 == 0 {
|
if b&0x80 == 0 {
|
||||||
*out = ret
|
*out = ret
|
||||||
@@ -532,7 +554,7 @@ func (s *String) ReadASN1BitString(out *encoding_asn1.BitString) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
paddingBits := uint8(bytes[0])
|
paddingBits := bytes[0]
|
||||||
bytes = bytes[1:]
|
bytes = bytes[1:]
|
||||||
if paddingBits > 7 ||
|
if paddingBits > 7 ||
|
||||||
len(bytes) == 0 && paddingBits != 0 ||
|
len(bytes) == 0 && paddingBits != 0 ||
|
||||||
@@ -545,7 +567,7 @@ func (s *String) ReadASN1BitString(out *encoding_asn1.BitString) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadASN1BitString decodes an ASN.1 BIT STRING into out and advances. It is
|
// ReadASN1BitStringAsBytes decodes an ASN.1 BIT STRING into out and advances. It is
|
||||||
// an error if the BIT STRING is not a whole number of bytes. It reports
|
// an error if the BIT STRING is not a whole number of bytes. It reports
|
||||||
// whether the read was successful.
|
// whether the read was successful.
|
||||||
func (s *String) ReadASN1BitStringAsBytes(out *[]byte) bool {
|
func (s *String) ReadASN1BitStringAsBytes(out *[]byte) bool {
|
||||||
@@ -554,7 +576,7 @@ func (s *String) ReadASN1BitStringAsBytes(out *[]byte) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
paddingBits := uint8(bytes[0])
|
paddingBits := bytes[0]
|
||||||
if paddingBits != 0 {
|
if paddingBits != 0 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -654,34 +676,27 @@ func (s *String) SkipOptionalASN1(tag asn1.Tag) bool {
|
|||||||
return s.ReadASN1(&unused, tag)
|
return s.ReadASN1(&unused, tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadOptionalASN1Integer attempts to read an optional ASN.1 INTEGER
|
// ReadOptionalASN1Integer attempts to read an optional ASN.1 INTEGER explicitly
|
||||||
// explicitly tagged with tag into out and advances. If no element with a
|
// tagged with tag into out and advances. If no element with a matching tag is
|
||||||
// matching tag is present, it writes defaultValue into out instead. If out
|
// present, it writes defaultValue into out instead. Otherwise, it behaves like
|
||||||
// does not point to an integer or to a big.Int, it panics. It reports
|
// ReadASN1Integer.
|
||||||
// whether the read was successful.
|
|
||||||
func (s *String) ReadOptionalASN1Integer(out interface{}, tag asn1.Tag, defaultValue interface{}) bool {
|
func (s *String) ReadOptionalASN1Integer(out interface{}, tag asn1.Tag, defaultValue interface{}) bool {
|
||||||
if reflect.TypeOf(out).Kind() != reflect.Ptr {
|
|
||||||
panic("out is not a pointer")
|
|
||||||
}
|
|
||||||
var present bool
|
var present bool
|
||||||
var i String
|
var i String
|
||||||
if !s.ReadOptionalASN1(&i, &present, tag) {
|
if !s.ReadOptionalASN1(&i, &present, tag) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if !present {
|
if !present {
|
||||||
switch reflect.ValueOf(out).Elem().Kind() {
|
switch out.(type) {
|
||||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
|
case *int, *int8, *int16, *int32, *int64,
|
||||||
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
*uint, *uint8, *uint16, *uint32, *uint64, *[]byte:
|
||||||
reflect.ValueOf(out).Elem().Set(reflect.ValueOf(defaultValue))
|
reflect.ValueOf(out).Elem().Set(reflect.ValueOf(defaultValue))
|
||||||
case reflect.Struct:
|
case *big.Int:
|
||||||
if reflect.TypeOf(out).Elem() != bigIntType {
|
if defaultValue, ok := defaultValue.(*big.Int); ok {
|
||||||
panic("invalid integer type")
|
out.(*big.Int).Set(defaultValue)
|
||||||
}
|
} else {
|
||||||
if reflect.TypeOf(defaultValue).Kind() != reflect.Ptr ||
|
|
||||||
reflect.TypeOf(defaultValue).Elem() != bigIntType {
|
|
||||||
panic("out points to big.Int, but defaultValue does not")
|
panic("out points to big.Int, but defaultValue does not")
|
||||||
}
|
}
|
||||||
out.(*big.Int).Set(defaultValue.(*big.Int))
|
|
||||||
default:
|
default:
|
||||||
panic("invalid integer type")
|
panic("invalid integer type")
|
||||||
}
|
}
|
||||||
@@ -718,13 +733,14 @@ func (s *String) ReadOptionalASN1OctetString(out *[]byte, outPresent *bool, tag
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadOptionalASN1Boolean sets *out to the value of the next ASN.1 BOOLEAN or,
|
// ReadOptionalASN1Boolean attempts to read an optional ASN.1 BOOLEAN
|
||||||
// if the next bytes are not an ASN.1 BOOLEAN, to the value of defaultValue.
|
// explicitly tagged with tag into out and advances. If no element with a
|
||||||
// It reports whether the operation was successful.
|
// matching tag is present, it sets "out" to defaultValue instead. It reports
|
||||||
func (s *String) ReadOptionalASN1Boolean(out *bool, defaultValue bool) bool {
|
// whether the read was successful.
|
||||||
|
func (s *String) ReadOptionalASN1Boolean(out *bool, tag asn1.Tag, defaultValue bool) bool {
|
||||||
var present bool
|
var present bool
|
||||||
var child String
|
var child String
|
||||||
if !s.ReadOptionalASN1(&child, &present, asn1.BOOLEAN) {
|
if !s.ReadOptionalASN1(&child, &present, tag) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -733,7 +749,7 @@ func (s *String) ReadOptionalASN1Boolean(out *bool, defaultValue bool) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
return s.ReadASN1Boolean(out)
|
return child.ReadASN1Boolean(out)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *String) readASN1(out *String, outTag *asn1.Tag, skipHeader bool) bool {
|
func (s *String) readASN1(out *String, outTag *asn1.Tag, skipHeader bool) bool {
|
||||||
|
|||||||
@@ -115,6 +115,28 @@ func TestReadASN1OptionalInteger(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const defaultBool = false
|
||||||
|
|
||||||
|
var optionalBoolTestData = []readASN1Test{
|
||||||
|
{"empty", []byte{}, 0xa0, true, false},
|
||||||
|
{"invalid", []byte{0xa1, 0x3, 0x1, 0x2, 0x7f}, 0xa1, false, defaultBool},
|
||||||
|
{"missing", []byte{0xa1, 0x3, 0x1, 0x1, 0x7f}, 0xa0, true, defaultBool},
|
||||||
|
{"present", []byte{0xa1, 0x3, 0x1, 0x1, 0xff}, 0xa1, true, true},
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestReadASN1OptionalBoolean(t *testing.T) {
|
||||||
|
for _, test := range optionalBoolTestData {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
in := String(test.in)
|
||||||
|
var out bool
|
||||||
|
ok := in.ReadOptionalASN1Boolean(&out, test.tag, defaultBool)
|
||||||
|
if ok != test.ok || ok && out != test.out.(bool) {
|
||||||
|
t.Errorf("in.ReadOptionalASN1Boolean() = %v, want %v; out = %v, want %v", ok, test.ok, out, test.out)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestReadASN1IntegerSigned(t *testing.T) {
|
func TestReadASN1IntegerSigned(t *testing.T) {
|
||||||
testData64 := []struct {
|
testData64 := []struct {
|
||||||
in []byte
|
in []byte
|
||||||
@@ -154,6 +176,32 @@ func TestReadASN1IntegerSigned(t *testing.T) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Repeat the same cases, reading into a []byte.
|
||||||
|
t.Run("bytes", func(t *testing.T) {
|
||||||
|
for i, test := range testData64 {
|
||||||
|
in := String(test.in)
|
||||||
|
var out []byte
|
||||||
|
ok := in.ReadASN1Integer(&out)
|
||||||
|
if test.out < 0 {
|
||||||
|
if ok {
|
||||||
|
t.Errorf("#%d: in.ReadASN1Integer(%d) = %v, want false", i, test.out, ok)
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if !ok {
|
||||||
|
t.Errorf("#%d: in.ReadASN1Integer() = %v, want true", i, ok)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
n := new(big.Int).SetBytes(out).Int64()
|
||||||
|
if n != test.out {
|
||||||
|
t.Errorf("#%d: in.ReadASN1Integer() = %v, want true; out = %x, want %d", i, ok, out, test.out)
|
||||||
|
}
|
||||||
|
if out[0] == 0 && len(out) > 1 {
|
||||||
|
t.Errorf("#%d: in.ReadASN1Integer() = %v; out = %x, has leading zeroes", i, ok, out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// Repeat with the implicit-tagging functions
|
// Repeat with the implicit-tagging functions
|
||||||
t.Run("WithTag", func(t *testing.T) {
|
t.Run("WithTag", func(t *testing.T) {
|
||||||
for i, test := range testData64 {
|
for i, test := range testData64 {
|
||||||
@@ -250,6 +298,7 @@ func TestASN1ObjectIdentifier(t *testing.T) {
|
|||||||
{[]byte{6, 7, 85, 0x02, 0x85, 0xc7, 0xcc, 0xfb, 0x01}, true, []int{2, 5, 2, 1492336001}},
|
{[]byte{6, 7, 85, 0x02, 0x85, 0xc7, 0xcc, 0xfb, 0x01}, true, []int{2, 5, 2, 1492336001}},
|
||||||
{[]byte{6, 7, 0x55, 0x02, 0x87, 0xff, 0xff, 0xff, 0x7f}, true, []int{2, 5, 2, 2147483647}}, // 2**31-1
|
{[]byte{6, 7, 0x55, 0x02, 0x87, 0xff, 0xff, 0xff, 0x7f}, true, []int{2, 5, 2, 2147483647}}, // 2**31-1
|
||||||
{[]byte{6, 7, 0x55, 0x02, 0x88, 0x80, 0x80, 0x80, 0x00}, false, []int{}}, // 2**31
|
{[]byte{6, 7, 0x55, 0x02, 0x88, 0x80, 0x80, 0x80, 0x00}, false, []int{}}, // 2**31
|
||||||
|
{[]byte{6, 3, 85, 0x80, 0x02}, false, []int{}}, // leading 0x80 octet
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, test := range testData {
|
for i, test := range testData {
|
||||||
|
|||||||
+11
-3
@@ -95,6 +95,11 @@ func (b *Builder) AddUint32(v uint32) {
|
|||||||
b.add(byte(v>>24), byte(v>>16), byte(v>>8), byte(v))
|
b.add(byte(v>>24), byte(v>>16), byte(v>>8), byte(v))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddUint48 appends a big-endian, 48-bit value to the byte string.
|
||||||
|
func (b *Builder) AddUint48(v uint64) {
|
||||||
|
b.add(byte(v>>40), byte(v>>32), byte(v>>24), byte(v>>16), byte(v>>8), byte(v))
|
||||||
|
}
|
||||||
|
|
||||||
// AddUint64 appends a big-endian, 64-bit value to the byte string.
|
// AddUint64 appends a big-endian, 64-bit value to the byte string.
|
||||||
func (b *Builder) AddUint64(v uint64) {
|
func (b *Builder) AddUint64(v uint64) {
|
||||||
b.add(byte(v>>56), byte(v>>48), byte(v>>40), byte(v>>32), byte(v>>24), byte(v>>16), byte(v>>8), byte(v))
|
b.add(byte(v>>56), byte(v>>48), byte(v>>40), byte(v>>32), byte(v>>24), byte(v>>16), byte(v>>8), byte(v))
|
||||||
@@ -303,9 +308,9 @@ func (b *Builder) add(bytes ...byte) {
|
|||||||
b.result = append(b.result, bytes...)
|
b.result = append(b.result, bytes...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unwrite rolls back n bytes written directly to the Builder. An attempt by a
|
// Unwrite rolls back non-negative n bytes written directly to the Builder.
|
||||||
// child builder passed to a continuation to unwrite bytes from its parent will
|
// An attempt by a child builder passed to a continuation to unwrite bytes
|
||||||
// panic.
|
// from its parent will panic.
|
||||||
func (b *Builder) Unwrite(n int) {
|
func (b *Builder) Unwrite(n int) {
|
||||||
if b.err != nil {
|
if b.err != nil {
|
||||||
return
|
return
|
||||||
@@ -317,6 +322,9 @@ func (b *Builder) Unwrite(n int) {
|
|||||||
if length < 0 {
|
if length < 0 {
|
||||||
panic("cryptobyte: internal error")
|
panic("cryptobyte: internal error")
|
||||||
}
|
}
|
||||||
|
if n < 0 {
|
||||||
|
panic("cryptobyte: attempted to unwrite negative number of bytes")
|
||||||
|
}
|
||||||
if n > length {
|
if n > length {
|
||||||
panic("cryptobyte: attempted to unwrite more than was written")
|
panic("cryptobyte: attempted to unwrite more than was written")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -179,6 +179,27 @@ func TestUint32(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestUint48(t *testing.T) {
|
||||||
|
var b Builder
|
||||||
|
var u uint64 = 0xfefcff3cfdfc
|
||||||
|
b.AddUint48(u)
|
||||||
|
if err := builderBytesEq(&b, 254, 252, 255, 60, 253, 252); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var s String = b.BytesOrPanic()
|
||||||
|
var v uint64
|
||||||
|
if !s.ReadUint48(&v) {
|
||||||
|
t.Error("ReadUint48() = false, want true")
|
||||||
|
}
|
||||||
|
if v != u {
|
||||||
|
t.Errorf("v = %x, want %x", v, u)
|
||||||
|
}
|
||||||
|
if len(s) != 0 {
|
||||||
|
t.Errorf("len(s) = %d, want 0", len(s))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestUint64(t *testing.T) {
|
func TestUint64(t *testing.T) {
|
||||||
var b Builder
|
var b Builder
|
||||||
b.AddUint64(0xf2fefefcff3cfdfc)
|
b.AddUint64(0xf2fefefcff3cfdfc)
|
||||||
|
|||||||
@@ -81,6 +81,17 @@ func (s *String) ReadUint32(out *uint32) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ReadUint48 decodes a big-endian, 48-bit value into out and advances over it.
|
||||||
|
// It reports whether the read was successful.
|
||||||
|
func (s *String) ReadUint48(out *uint64) bool {
|
||||||
|
v := s.read(6)
|
||||||
|
if v == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
*out = uint64(v[0])<<40 | uint64(v[1])<<32 | uint64(v[2])<<24 | uint64(v[3])<<16 | uint64(v[4])<<8 | uint64(v[5])
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
// ReadUint64 decodes a big-endian, 64-bit value into out and advances over it.
|
// ReadUint64 decodes a big-endian, 64-bit value into out and advances over it.
|
||||||
// It reports whether the read was successful.
|
// It reports whether the read was successful.
|
||||||
func (s *String) ReadUint64(out *uint64) bool {
|
func (s *String) ReadUint64(out *uint64) bool {
|
||||||
|
|||||||
@@ -5,71 +5,18 @@
|
|||||||
// Package curve25519 provides an implementation of the X25519 function, which
|
// Package curve25519 provides an implementation of the X25519 function, which
|
||||||
// performs scalar multiplication on the elliptic curve known as Curve25519.
|
// performs scalar multiplication on the elliptic curve known as Curve25519.
|
||||||
// See RFC 7748.
|
// See RFC 7748.
|
||||||
|
//
|
||||||
|
// Starting in Go 1.20, this package is a wrapper for the X25519 implementation
|
||||||
|
// in the crypto/ecdh package.
|
||||||
package curve25519 // import "golang.org/x/crypto/curve25519"
|
package curve25519 // import "golang.org/x/crypto/curve25519"
|
||||||
|
|
||||||
import (
|
|
||||||
"crypto/subtle"
|
|
||||||
"errors"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"golang.org/x/crypto/curve25519/internal/field"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ScalarMult sets dst to the product scalar * point.
|
// ScalarMult sets dst to the product scalar * point.
|
||||||
//
|
//
|
||||||
// Deprecated: when provided a low-order point, ScalarMult will set dst to all
|
// Deprecated: when provided a low-order point, ScalarMult will set dst to all
|
||||||
// zeroes, irrespective of the scalar. Instead, use the X25519 function, which
|
// zeroes, irrespective of the scalar. Instead, use the X25519 function, which
|
||||||
// will return an error.
|
// will return an error.
|
||||||
func ScalarMult(dst, scalar, point *[32]byte) {
|
func ScalarMult(dst, scalar, point *[32]byte) {
|
||||||
var e [32]byte
|
scalarMult(dst, scalar, point)
|
||||||
|
|
||||||
copy(e[:], scalar[:])
|
|
||||||
e[0] &= 248
|
|
||||||
e[31] &= 127
|
|
||||||
e[31] |= 64
|
|
||||||
|
|
||||||
var x1, x2, z2, x3, z3, tmp0, tmp1 field.Element
|
|
||||||
x1.SetBytes(point[:])
|
|
||||||
x2.One()
|
|
||||||
x3.Set(&x1)
|
|
||||||
z3.One()
|
|
||||||
|
|
||||||
swap := 0
|
|
||||||
for pos := 254; pos >= 0; pos-- {
|
|
||||||
b := e[pos/8] >> uint(pos&7)
|
|
||||||
b &= 1
|
|
||||||
swap ^= int(b)
|
|
||||||
x2.Swap(&x3, swap)
|
|
||||||
z2.Swap(&z3, swap)
|
|
||||||
swap = int(b)
|
|
||||||
|
|
||||||
tmp0.Subtract(&x3, &z3)
|
|
||||||
tmp1.Subtract(&x2, &z2)
|
|
||||||
x2.Add(&x2, &z2)
|
|
||||||
z2.Add(&x3, &z3)
|
|
||||||
z3.Multiply(&tmp0, &x2)
|
|
||||||
z2.Multiply(&z2, &tmp1)
|
|
||||||
tmp0.Square(&tmp1)
|
|
||||||
tmp1.Square(&x2)
|
|
||||||
x3.Add(&z3, &z2)
|
|
||||||
z2.Subtract(&z3, &z2)
|
|
||||||
x2.Multiply(&tmp1, &tmp0)
|
|
||||||
tmp1.Subtract(&tmp1, &tmp0)
|
|
||||||
z2.Square(&z2)
|
|
||||||
|
|
||||||
z3.Mult32(&tmp1, 121666)
|
|
||||||
x3.Square(&x3)
|
|
||||||
tmp0.Add(&tmp0, &z3)
|
|
||||||
z3.Multiply(&x1, &z2)
|
|
||||||
z2.Multiply(&tmp1, &tmp0)
|
|
||||||
}
|
|
||||||
|
|
||||||
x2.Swap(&x3, swap)
|
|
||||||
z2.Swap(&z3, swap)
|
|
||||||
|
|
||||||
z2.Invert(&z2)
|
|
||||||
x2.Multiply(&x2, &z2)
|
|
||||||
copy(dst[:], x2.Bytes())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ScalarBaseMult sets dst to the product scalar * base where base is the
|
// ScalarBaseMult sets dst to the product scalar * base where base is the
|
||||||
@@ -78,7 +25,7 @@ func ScalarMult(dst, scalar, point *[32]byte) {
|
|||||||
// It is recommended to use the X25519 function with Basepoint instead, as
|
// It is recommended to use the X25519 function with Basepoint instead, as
|
||||||
// copying into fixed size arrays can lead to unexpected bugs.
|
// copying into fixed size arrays can lead to unexpected bugs.
|
||||||
func ScalarBaseMult(dst, scalar *[32]byte) {
|
func ScalarBaseMult(dst, scalar *[32]byte) {
|
||||||
ScalarMult(dst, scalar, &basePoint)
|
scalarBaseMult(dst, scalar)
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -91,21 +38,10 @@ const (
|
|||||||
// Basepoint is the canonical Curve25519 generator.
|
// Basepoint is the canonical Curve25519 generator.
|
||||||
var Basepoint []byte
|
var Basepoint []byte
|
||||||
|
|
||||||
var basePoint = [32]byte{9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
|
var basePoint = [32]byte{9}
|
||||||
|
|
||||||
func init() { Basepoint = basePoint[:] }
|
func init() { Basepoint = basePoint[:] }
|
||||||
|
|
||||||
func checkBasepoint() {
|
|
||||||
if subtle.ConstantTimeCompare(Basepoint, []byte{
|
|
||||||
0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
}) != 1 {
|
|
||||||
panic("curve25519: global Basepoint value was modified")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// X25519 returns the result of the scalar multiplication (scalar * point),
|
// X25519 returns the result of the scalar multiplication (scalar * point),
|
||||||
// according to RFC 7748, Section 5. scalar, point and the return value are
|
// according to RFC 7748, Section 5. scalar, point and the return value are
|
||||||
// slices of 32 bytes.
|
// slices of 32 bytes.
|
||||||
@@ -121,26 +57,3 @@ func X25519(scalar, point []byte) ([]byte, error) {
|
|||||||
var dst [32]byte
|
var dst [32]byte
|
||||||
return x25519(&dst, scalar, point)
|
return x25519(&dst, scalar, point)
|
||||||
}
|
}
|
||||||
|
|
||||||
func x25519(dst *[32]byte, scalar, point []byte) ([]byte, error) {
|
|
||||||
var in [32]byte
|
|
||||||
if l := len(scalar); l != 32 {
|
|
||||||
return nil, errors.New("bad scalar length: " + strconv.Itoa(l) + ", expected 32")
|
|
||||||
}
|
|
||||||
if l := len(point); l != 32 {
|
|
||||||
return nil, errors.New("bad point length: " + strconv.Itoa(l) + ", expected 32")
|
|
||||||
}
|
|
||||||
copy(in[:], scalar)
|
|
||||||
if &point[0] == &Basepoint[0] {
|
|
||||||
checkBasepoint()
|
|
||||||
ScalarBaseMult(dst, &in)
|
|
||||||
} else {
|
|
||||||
var base, zero [32]byte
|
|
||||||
copy(base[:], point)
|
|
||||||
ScalarMult(dst, &in, &base)
|
|
||||||
if subtle.ConstantTimeCompare(dst[:], zero[:]) == 1 {
|
|
||||||
return nil, errors.New("bad input point: low order point")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return dst[:], nil
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -0,0 +1,105 @@
|
|||||||
|
// Copyright 2019 The Go Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
//go:build !go1.20
|
||||||
|
|
||||||
|
package curve25519
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/subtle"
|
||||||
|
"errors"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"golang.org/x/crypto/curve25519/internal/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
func scalarMult(dst, scalar, point *[32]byte) {
|
||||||
|
var e [32]byte
|
||||||
|
|
||||||
|
copy(e[:], scalar[:])
|
||||||
|
e[0] &= 248
|
||||||
|
e[31] &= 127
|
||||||
|
e[31] |= 64
|
||||||
|
|
||||||
|
var x1, x2, z2, x3, z3, tmp0, tmp1 field.Element
|
||||||
|
x1.SetBytes(point[:])
|
||||||
|
x2.One()
|
||||||
|
x3.Set(&x1)
|
||||||
|
z3.One()
|
||||||
|
|
||||||
|
swap := 0
|
||||||
|
for pos := 254; pos >= 0; pos-- {
|
||||||
|
b := e[pos/8] >> uint(pos&7)
|
||||||
|
b &= 1
|
||||||
|
swap ^= int(b)
|
||||||
|
x2.Swap(&x3, swap)
|
||||||
|
z2.Swap(&z3, swap)
|
||||||
|
swap = int(b)
|
||||||
|
|
||||||
|
tmp0.Subtract(&x3, &z3)
|
||||||
|
tmp1.Subtract(&x2, &z2)
|
||||||
|
x2.Add(&x2, &z2)
|
||||||
|
z2.Add(&x3, &z3)
|
||||||
|
z3.Multiply(&tmp0, &x2)
|
||||||
|
z2.Multiply(&z2, &tmp1)
|
||||||
|
tmp0.Square(&tmp1)
|
||||||
|
tmp1.Square(&x2)
|
||||||
|
x3.Add(&z3, &z2)
|
||||||
|
z2.Subtract(&z3, &z2)
|
||||||
|
x2.Multiply(&tmp1, &tmp0)
|
||||||
|
tmp1.Subtract(&tmp1, &tmp0)
|
||||||
|
z2.Square(&z2)
|
||||||
|
|
||||||
|
z3.Mult32(&tmp1, 121666)
|
||||||
|
x3.Square(&x3)
|
||||||
|
tmp0.Add(&tmp0, &z3)
|
||||||
|
z3.Multiply(&x1, &z2)
|
||||||
|
z2.Multiply(&tmp1, &tmp0)
|
||||||
|
}
|
||||||
|
|
||||||
|
x2.Swap(&x3, swap)
|
||||||
|
z2.Swap(&z3, swap)
|
||||||
|
|
||||||
|
z2.Invert(&z2)
|
||||||
|
x2.Multiply(&x2, &z2)
|
||||||
|
copy(dst[:], x2.Bytes())
|
||||||
|
}
|
||||||
|
|
||||||
|
func scalarBaseMult(dst, scalar *[32]byte) {
|
||||||
|
checkBasepoint()
|
||||||
|
scalarMult(dst, scalar, &basePoint)
|
||||||
|
}
|
||||||
|
|
||||||
|
func x25519(dst *[32]byte, scalar, point []byte) ([]byte, error) {
|
||||||
|
var in [32]byte
|
||||||
|
if l := len(scalar); l != 32 {
|
||||||
|
return nil, errors.New("bad scalar length: " + strconv.Itoa(l) + ", expected 32")
|
||||||
|
}
|
||||||
|
if l := len(point); l != 32 {
|
||||||
|
return nil, errors.New("bad point length: " + strconv.Itoa(l) + ", expected 32")
|
||||||
|
}
|
||||||
|
copy(in[:], scalar)
|
||||||
|
if &point[0] == &Basepoint[0] {
|
||||||
|
scalarBaseMult(dst, &in)
|
||||||
|
} else {
|
||||||
|
var base, zero [32]byte
|
||||||
|
copy(base[:], point)
|
||||||
|
scalarMult(dst, &in, &base)
|
||||||
|
if subtle.ConstantTimeCompare(dst[:], zero[:]) == 1 {
|
||||||
|
return nil, errors.New("bad input point: low order point")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dst[:], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkBasepoint() {
|
||||||
|
if subtle.ConstantTimeCompare(Basepoint, []byte{
|
||||||
|
0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
}) != 1 {
|
||||||
|
panic("curve25519: global Basepoint value was modified")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
// Copyright 2022 The Go Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
//go:build go1.20
|
||||||
|
|
||||||
|
package curve25519
|
||||||
|
|
||||||
|
import "crypto/ecdh"
|
||||||
|
|
||||||
|
func x25519(dst *[32]byte, scalar, point []byte) ([]byte, error) {
|
||||||
|
curve := ecdh.X25519()
|
||||||
|
pub, err := curve.NewPublicKey(point)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
priv, err := curve.NewPrivateKey(scalar)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
out, err := priv.ECDH(pub)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
copy(dst[:], out)
|
||||||
|
return dst[:], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func scalarMult(dst, scalar, point *[32]byte) {
|
||||||
|
if _, err := x25519(dst, scalar[:], point[:]); err != nil {
|
||||||
|
// The only error condition for x25519 when the inputs are 32 bytes long
|
||||||
|
// is if the output would have been the all-zero value.
|
||||||
|
for i := range dst {
|
||||||
|
dst[i] = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func scalarBaseMult(dst, scalar *[32]byte) {
|
||||||
|
curve := ecdh.X25519()
|
||||||
|
priv, err := curve.NewPrivateKey(scalar[:])
|
||||||
|
if err != nil {
|
||||||
|
panic("curve25519: internal error: scalarBaseMult was not 32 bytes")
|
||||||
|
}
|
||||||
|
copy(dst[:], priv.PublicKey().Bytes())
|
||||||
|
}
|
||||||
@@ -2,13 +2,15 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package curve25519
|
package curve25519_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"golang.org/x/crypto/curve25519"
|
||||||
)
|
)
|
||||||
|
|
||||||
const expectedHex = "89161fde887b2b53de549af483940106ecc114d6982daa98256de23bdf77661a"
|
const expectedHex = "89161fde887b2b53de549af483940106ecc114d6982daa98256de23bdf77661a"
|
||||||
@@ -19,7 +21,7 @@ func TestX25519Basepoint(t *testing.T) {
|
|||||||
|
|
||||||
for i := 0; i < 200; i++ {
|
for i := 0; i < 200; i++ {
|
||||||
var err error
|
var err error
|
||||||
x, err = X25519(x, Basepoint)
|
x, err = curve25519.X25519(x, curve25519.Basepoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -32,12 +34,12 @@ func TestX25519Basepoint(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestLowOrderPoints(t *testing.T) {
|
func TestLowOrderPoints(t *testing.T) {
|
||||||
scalar := make([]byte, ScalarSize)
|
scalar := make([]byte, curve25519.ScalarSize)
|
||||||
if _, err := rand.Read(scalar); err != nil {
|
if _, err := rand.Read(scalar); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
for i, p := range lowOrderPoints {
|
for i, p := range lowOrderPoints {
|
||||||
out, err := X25519(scalar, p)
|
out, err := curve25519.X25519(scalar, p)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("%d: expected error, got nil", i)
|
t.Errorf("%d: expected error, got nil", i)
|
||||||
}
|
}
|
||||||
@@ -48,10 +50,10 @@ func TestLowOrderPoints(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestTestVectors(t *testing.T) {
|
func TestTestVectors(t *testing.T) {
|
||||||
t.Run("Legacy", func(t *testing.T) { testTestVectors(t, ScalarMult) })
|
t.Run("Legacy", func(t *testing.T) { testTestVectors(t, curve25519.ScalarMult) })
|
||||||
t.Run("X25519", func(t *testing.T) {
|
t.Run("X25519", func(t *testing.T) {
|
||||||
testTestVectors(t, func(dst, scalar, point *[32]byte) {
|
testTestVectors(t, func(dst, scalar, point *[32]byte) {
|
||||||
out, err := X25519(scalar[:], point[:])
|
out, err := curve25519.X25519(scalar[:], point[:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -88,10 +90,10 @@ func TestHighBitIgnored(t *testing.T) {
|
|||||||
var hi0, hi1 [32]byte
|
var hi0, hi1 [32]byte
|
||||||
|
|
||||||
u[31] &= 0x7f
|
u[31] &= 0x7f
|
||||||
ScalarMult(&hi0, &s, &u)
|
curve25519.ScalarMult(&hi0, &s, &u)
|
||||||
|
|
||||||
u[31] |= 0x80
|
u[31] |= 0x80
|
||||||
ScalarMult(&hi1, &s, &u)
|
curve25519.ScalarMult(&hi1, &s, &u)
|
||||||
|
|
||||||
if !bytes.Equal(hi0[:], hi1[:]) {
|
if !bytes.Equal(hi0[:], hi1[:]) {
|
||||||
t.Errorf("high bit of group point should not affect result")
|
t.Errorf("high bit of group point should not affect result")
|
||||||
@@ -101,14 +103,14 @@ func TestHighBitIgnored(t *testing.T) {
|
|||||||
var benchmarkSink byte
|
var benchmarkSink byte
|
||||||
|
|
||||||
func BenchmarkX25519Basepoint(b *testing.B) {
|
func BenchmarkX25519Basepoint(b *testing.B) {
|
||||||
scalar := make([]byte, ScalarSize)
|
scalar := make([]byte, curve25519.ScalarSize)
|
||||||
if _, err := rand.Read(scalar); err != nil {
|
if _, err := rand.Read(scalar); err != nil {
|
||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
out, err := X25519(scalar, Basepoint)
|
out, err := curve25519.X25519(scalar, curve25519.Basepoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -117,11 +119,11 @@ func BenchmarkX25519Basepoint(b *testing.B) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkX25519(b *testing.B) {
|
func BenchmarkX25519(b *testing.B) {
|
||||||
scalar := make([]byte, ScalarSize)
|
scalar := make([]byte, curve25519.ScalarSize)
|
||||||
if _, err := rand.Read(scalar); err != nil {
|
if _, err := rand.Read(scalar); err != nil {
|
||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
}
|
}
|
||||||
point, err := X25519(scalar, Basepoint)
|
point, err := curve25519.X25519(scalar, curve25519.Basepoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -131,7 +133,7 @@ func BenchmarkX25519(b *testing.B) {
|
|||||||
|
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
out, err := X25519(scalar, point)
|
out, err := curve25519.X25519(scalar, point)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,16 @@
|
|||||||
module asm
|
module asm
|
||||||
|
|
||||||
go 1.16
|
go 1.18
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/mmcloughlin/avo v0.4.0
|
github.com/mmcloughlin/avo v0.5.0
|
||||||
golang.org/x/crypto v0.0.0
|
golang.org/x/crypto v0.1.0
|
||||||
)
|
)
|
||||||
|
|
||||||
replace golang.org/x/crypto v0.0.0 => ../../../..
|
require (
|
||||||
|
golang.org/x/mod v0.8.0 // indirect
|
||||||
|
golang.org/x/sys v0.14.0 // indirect
|
||||||
|
golang.org/x/tools v0.6.0 // indirect
|
||||||
|
)
|
||||||
|
|
||||||
|
replace golang.org/x/crypto v0.1.0 => ../../../..
|
||||||
|
|||||||
@@ -1,34 +1,51 @@
|
|||||||
github.com/mmcloughlin/avo v0.4.0 h1:jeHDRktVD+578ULxWpQHkilor6pkdLF7u7EiTzDbfcU=
|
github.com/mmcloughlin/avo v0.5.0 h1:nAco9/aI9Lg2kiuROBY6BhCI/z0t5jEvJfjWbL8qXLU=
|
||||||
github.com/mmcloughlin/avo v0.4.0/go.mod h1:RW9BfYA3TgO9uCdNrKU2h6J8cPD8ZLznvfgHAeszb1s=
|
github.com/mmcloughlin/avo v0.5.0/go.mod h1:ChHFdoV7ql95Wi7vuq2YT1bwCJqiWdZrQ1im3VujLYM=
|
||||||
github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||||
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
|
golang.org/x/arch v0.1.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||||
golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
|
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||||
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
golang.org/x/mod v0.6.0/go.mod h1:4mET923SAdbXp2ki8ey+zGs1SLqsuM2Y0uvdZR/fUNI=
|
||||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8=
|
||||||
|
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||||
|
golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
|
||||||
|
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||||
|
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
|
||||||
|
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20211030160813-b3129d9d1021 h1:giLT+HuUP/gXYrG2Plg9WTjj4qhfgaW424ZIFog3rlk=
|
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20211030160813-b3129d9d1021/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
|
||||||
|
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
|
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||||
|
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||||
|
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||||
|
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
|
||||||
|
golang.org/x/term v0.14.0/go.mod h1:TySc+nGkYR6qt8km8wUhuFRTVSMIX3XPR58y2lC8vww=
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
|
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||||
|
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||||
|
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||||
|
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||||
|
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
golang.org/x/tools v0.1.7 h1:6j8CgantCy3yc8JGBqkDLMKWqZ0RDU2g1HVgacojGWQ=
|
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||||
golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo=
|
golang.org/x/tools v0.2.0/go.mod h1:y4OqIKeOV/fWJetJ8bXPU1sEVniLMIyDAZWeHdV+NTA=
|
||||||
|
golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM=
|
||||||
|
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
||||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
|
||||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
|
|
||||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
|
||||||
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
|
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
// Code generated by command: go run fe_amd64_asm.go -out ../fe_amd64.s -stubs ../fe_amd64.go -pkg field. DO NOT EDIT.
|
// Code generated by command: go run fe_amd64_asm.go -out ../fe_amd64.s -stubs ../fe_amd64.go -pkg field. DO NOT EDIT.
|
||||||
|
|
||||||
//go:build amd64 && gc && !purego
|
//go:build amd64 && gc && !purego
|
||||||
// +build amd64,gc,!purego
|
|
||||||
|
|
||||||
package field
|
package field
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
// Code generated by command: go run fe_amd64_asm.go -out ../fe_amd64.s -stubs ../fe_amd64.go -pkg field. DO NOT EDIT.
|
// Code generated by command: go run fe_amd64_asm.go -out ../fe_amd64.s -stubs ../fe_amd64.go -pkg field. DO NOT EDIT.
|
||||||
|
|
||||||
//go:build amd64 && gc && !purego
|
//go:build amd64 && gc && !purego
|
||||||
// +build amd64,gc,!purego
|
|
||||||
|
|
||||||
#include "textflag.h"
|
#include "textflag.h"
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build !amd64 || !gc || purego
|
//go:build !amd64 || !gc || purego
|
||||||
// +build !amd64 !gc purego
|
|
||||||
|
|
||||||
package field
|
package field
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build arm64 && gc && !purego
|
//go:build arm64 && gc && !purego
|
||||||
// +build arm64,gc,!purego
|
|
||||||
|
|
||||||
package field
|
package field
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build arm64 && gc && !purego
|
//go:build arm64 && gc && !purego
|
||||||
// +build arm64,gc,!purego
|
|
||||||
|
|
||||||
#include "textflag.h"
|
#include "textflag.h"
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build !arm64 || !gc || purego
|
//go:build !arm64 || !gc || purego
|
||||||
// +build !arm64 !gc purego
|
|
||||||
|
|
||||||
package field
|
package field
|
||||||
|
|
||||||
|
|||||||
@@ -245,7 +245,7 @@ func feSquareGeneric(v, a *Element) {
|
|||||||
v.carryPropagate()
|
v.carryPropagate()
|
||||||
}
|
}
|
||||||
|
|
||||||
// carryPropagate brings the limbs below 52 bits by applying the reduction
|
// carryPropagateGeneric brings the limbs below 52 bits by applying the reduction
|
||||||
// identity (a * 2²⁵⁵ + b = a * 19 + b) to the l4 carry. TODO inline
|
// identity (a * 2²⁵⁵ + b = a * 19 + b) to the l4 carry. TODO inline
|
||||||
func (v *Element) carryPropagateGeneric() *Element {
|
func (v *Element) carryPropagateGeneric() *Element {
|
||||||
c0 := v.l0 >> 51
|
c0 := v.l0 >> 51
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package curve25519
|
package curve25519_test
|
||||||
|
|
||||||
// lowOrderPoints from libsodium.
|
// lowOrderPoints from libsodium.
|
||||||
// https://github.com/jedisct1/libsodium/blob/65621a1059a37d/src/libsodium/crypto_scalarmult/curve25519/ref10/x25519_ref10.c#L11-L70
|
// https://github.com/jedisct1/libsodium/blob/65621a1059a37d/src/libsodium/crypto_scalarmult/curve25519/ref10/x25519_ref10.c#L11-L70
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
module golang.org/x/crypto
|
module golang.org/x/crypto
|
||||||
|
|
||||||
go 1.17
|
go 1.18
|
||||||
|
|
||||||
require (
|
require (
|
||||||
golang.org/x/net v0.2.0
|
golang.org/x/net v0.10.0 // tagx:ignore
|
||||||
golang.org/x/sys v0.2.0
|
golang.org/x/sys v0.17.0
|
||||||
golang.org/x/term v0.2.0
|
golang.org/x/term v0.17.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require golang.org/x/text v0.4.0 // indirect
|
require golang.org/x/text v0.14.0 // indirect
|
||||||
|
|||||||
@@ -1,31 +1,8 @@
|
|||||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
||||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
|
||||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/term v0.17.0 h1:mkTF7LCd6WGJNL3K1Ad7kwxNfYAW6a8a8QqtMblp/4U=
|
||||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
|
||||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
|
||||||
golang.org/x/net v0.2.0 h1:sZfSu1wtKLGlWI4ZZayP0ck9Y73K1ynO6gqzTdBVdPU=
|
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||||
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
|
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A=
|
|
||||||
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
|
||||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
|
||||||
golang.org/x/term v0.2.0 h1:z85xZCsEl7bi/KwbNADeBYoOP0++7W1ipu+aGnpwzRM=
|
|
||||||
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
|
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
|
||||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
|
||||||
golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg=
|
|
||||||
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
|
||||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
|
||||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
|
||||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
|
||||||
|
|||||||
+3
-1
@@ -56,7 +56,9 @@ func (f *hkdf) Read(p []byte) (int, error) {
|
|||||||
|
|
||||||
// Fill the rest of the buffer
|
// Fill the rest of the buffer
|
||||||
for len(p) > 0 {
|
for len(p) > 0 {
|
||||||
f.expander.Reset()
|
if f.counter > 1 {
|
||||||
|
f.expander.Reset()
|
||||||
|
}
|
||||||
f.expander.Write(f.prev)
|
f.expander.Write(f.prev)
|
||||||
f.expander.Write(f.info)
|
f.expander.Write(f.info)
|
||||||
f.expander.Write([]byte{f.counter})
|
f.expander.Write([]byte{f.counter})
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build !purego
|
//go:build !purego
|
||||||
// +build !purego
|
|
||||||
|
|
||||||
// Package alias implements memory aliasing tests.
|
// Package alias implements memory aliasing tests.
|
||||||
package alias
|
package alias
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build purego
|
//go:build purego
|
||||||
// +build purego
|
|
||||||
|
|
||||||
// Package alias implements memory aliasing tests.
|
// Package alias implements memory aliasing tests.
|
||||||
package alias
|
package alias
|
||||||
|
|||||||
@@ -1,40 +0,0 @@
|
|||||||
// Copyright 2019 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
//go:build !go1.13
|
|
||||||
// +build !go1.13
|
|
||||||
|
|
||||||
package poly1305
|
|
||||||
|
|
||||||
// Generic fallbacks for the math/bits intrinsics, copied from
|
|
||||||
// src/math/bits/bits.go. They were added in Go 1.12, but Add64 and Sum64 had
|
|
||||||
// variable time fallbacks until Go 1.13.
|
|
||||||
|
|
||||||
func bitsAdd64(x, y, carry uint64) (sum, carryOut uint64) {
|
|
||||||
sum = x + y + carry
|
|
||||||
carryOut = ((x & y) | ((x | y) &^ sum)) >> 63
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func bitsSub64(x, y, borrow uint64) (diff, borrowOut uint64) {
|
|
||||||
diff = x - y - borrow
|
|
||||||
borrowOut = ((^x & y) | (^(x ^ y) & diff)) >> 63
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func bitsMul64(x, y uint64) (hi, lo uint64) {
|
|
||||||
const mask32 = 1<<32 - 1
|
|
||||||
x0 := x & mask32
|
|
||||||
x1 := x >> 32
|
|
||||||
y0 := y & mask32
|
|
||||||
y1 := y >> 32
|
|
||||||
w0 := x0 * y0
|
|
||||||
t := x1*y0 + w0>>32
|
|
||||||
w1 := t & mask32
|
|
||||||
w2 := t >> 32
|
|
||||||
w1 += x0 * y1
|
|
||||||
hi = x1*y1 + w2 + w1>>32
|
|
||||||
lo = x * y
|
|
||||||
return
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
// Copyright 2019 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
//go:build go1.13
|
|
||||||
// +build go1.13
|
|
||||||
|
|
||||||
package poly1305
|
|
||||||
|
|
||||||
import "math/bits"
|
|
||||||
|
|
||||||
func bitsAdd64(x, y, carry uint64) (sum, carryOut uint64) {
|
|
||||||
return bits.Add64(x, y, carry)
|
|
||||||
}
|
|
||||||
|
|
||||||
func bitsSub64(x, y, borrow uint64) (diff, borrowOut uint64) {
|
|
||||||
return bits.Sub64(x, y, borrow)
|
|
||||||
}
|
|
||||||
|
|
||||||
func bitsMul64(x, y uint64) (hi, lo uint64) {
|
|
||||||
return bits.Mul64(x, y)
|
|
||||||
}
|
|
||||||
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build (!amd64 && !ppc64le && !s390x) || !gc || purego
|
//go:build (!amd64 && !ppc64le && !s390x) || !gc || purego
|
||||||
// +build !amd64,!ppc64le,!s390x !gc purego
|
|
||||||
|
|
||||||
package poly1305
|
package poly1305
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build gc && !purego
|
//go:build gc && !purego
|
||||||
// +build gc,!purego
|
|
||||||
|
|
||||||
package poly1305
|
package poly1305
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build gc && !purego
|
//go:build gc && !purego
|
||||||
// +build gc,!purego
|
|
||||||
|
|
||||||
#include "textflag.h"
|
#include "textflag.h"
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,10 @@
|
|||||||
|
|
||||||
package poly1305
|
package poly1305
|
||||||
|
|
||||||
import "encoding/binary"
|
import (
|
||||||
|
"encoding/binary"
|
||||||
|
"math/bits"
|
||||||
|
)
|
||||||
|
|
||||||
// Poly1305 [RFC 7539] is a relatively simple algorithm: the authentication tag
|
// Poly1305 [RFC 7539] is a relatively simple algorithm: the authentication tag
|
||||||
// for a 64 bytes message is approximately
|
// for a 64 bytes message is approximately
|
||||||
@@ -114,13 +117,13 @@ type uint128 struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func mul64(a, b uint64) uint128 {
|
func mul64(a, b uint64) uint128 {
|
||||||
hi, lo := bitsMul64(a, b)
|
hi, lo := bits.Mul64(a, b)
|
||||||
return uint128{lo, hi}
|
return uint128{lo, hi}
|
||||||
}
|
}
|
||||||
|
|
||||||
func add128(a, b uint128) uint128 {
|
func add128(a, b uint128) uint128 {
|
||||||
lo, c := bitsAdd64(a.lo, b.lo, 0)
|
lo, c := bits.Add64(a.lo, b.lo, 0)
|
||||||
hi, c := bitsAdd64(a.hi, b.hi, c)
|
hi, c := bits.Add64(a.hi, b.hi, c)
|
||||||
if c != 0 {
|
if c != 0 {
|
||||||
panic("poly1305: unexpected overflow")
|
panic("poly1305: unexpected overflow")
|
||||||
}
|
}
|
||||||
@@ -155,8 +158,8 @@ func updateGeneric(state *macState, msg []byte) {
|
|||||||
// hide leading zeroes. For full chunks, that's 1 << 128, so we can just
|
// hide leading zeroes. For full chunks, that's 1 << 128, so we can just
|
||||||
// add 1 to the most significant (2¹²⁸) limb, h2.
|
// add 1 to the most significant (2¹²⁸) limb, h2.
|
||||||
if len(msg) >= TagSize {
|
if len(msg) >= TagSize {
|
||||||
h0, c = bitsAdd64(h0, binary.LittleEndian.Uint64(msg[0:8]), 0)
|
h0, c = bits.Add64(h0, binary.LittleEndian.Uint64(msg[0:8]), 0)
|
||||||
h1, c = bitsAdd64(h1, binary.LittleEndian.Uint64(msg[8:16]), c)
|
h1, c = bits.Add64(h1, binary.LittleEndian.Uint64(msg[8:16]), c)
|
||||||
h2 += c + 1
|
h2 += c + 1
|
||||||
|
|
||||||
msg = msg[TagSize:]
|
msg = msg[TagSize:]
|
||||||
@@ -165,8 +168,8 @@ func updateGeneric(state *macState, msg []byte) {
|
|||||||
copy(buf[:], msg)
|
copy(buf[:], msg)
|
||||||
buf[len(msg)] = 1
|
buf[len(msg)] = 1
|
||||||
|
|
||||||
h0, c = bitsAdd64(h0, binary.LittleEndian.Uint64(buf[0:8]), 0)
|
h0, c = bits.Add64(h0, binary.LittleEndian.Uint64(buf[0:8]), 0)
|
||||||
h1, c = bitsAdd64(h1, binary.LittleEndian.Uint64(buf[8:16]), c)
|
h1, c = bits.Add64(h1, binary.LittleEndian.Uint64(buf[8:16]), c)
|
||||||
h2 += c
|
h2 += c
|
||||||
|
|
||||||
msg = nil
|
msg = nil
|
||||||
@@ -219,9 +222,9 @@ func updateGeneric(state *macState, msg []byte) {
|
|||||||
m3 := h2r1
|
m3 := h2r1
|
||||||
|
|
||||||
t0 := m0.lo
|
t0 := m0.lo
|
||||||
t1, c := bitsAdd64(m1.lo, m0.hi, 0)
|
t1, c := bits.Add64(m1.lo, m0.hi, 0)
|
||||||
t2, c := bitsAdd64(m2.lo, m1.hi, c)
|
t2, c := bits.Add64(m2.lo, m1.hi, c)
|
||||||
t3, _ := bitsAdd64(m3.lo, m2.hi, c)
|
t3, _ := bits.Add64(m3.lo, m2.hi, c)
|
||||||
|
|
||||||
// Now we have the result as 4 64-bit limbs, and we need to reduce it
|
// Now we have the result as 4 64-bit limbs, and we need to reduce it
|
||||||
// modulo 2¹³⁰ - 5. The special shape of this Crandall prime lets us do
|
// modulo 2¹³⁰ - 5. The special shape of this Crandall prime lets us do
|
||||||
@@ -243,14 +246,14 @@ func updateGeneric(state *macState, msg []byte) {
|
|||||||
|
|
||||||
// To add c * 5 to h, we first add cc = c * 4, and then add (cc >> 2) = c.
|
// To add c * 5 to h, we first add cc = c * 4, and then add (cc >> 2) = c.
|
||||||
|
|
||||||
h0, c = bitsAdd64(h0, cc.lo, 0)
|
h0, c = bits.Add64(h0, cc.lo, 0)
|
||||||
h1, c = bitsAdd64(h1, cc.hi, c)
|
h1, c = bits.Add64(h1, cc.hi, c)
|
||||||
h2 += c
|
h2 += c
|
||||||
|
|
||||||
cc = shiftRightBy2(cc)
|
cc = shiftRightBy2(cc)
|
||||||
|
|
||||||
h0, c = bitsAdd64(h0, cc.lo, 0)
|
h0, c = bits.Add64(h0, cc.lo, 0)
|
||||||
h1, c = bitsAdd64(h1, cc.hi, c)
|
h1, c = bits.Add64(h1, cc.hi, c)
|
||||||
h2 += c
|
h2 += c
|
||||||
|
|
||||||
// h2 is at most 3 + 1 + 1 = 5, making the whole of h at most
|
// h2 is at most 3 + 1 + 1 = 5, making the whole of h at most
|
||||||
@@ -287,9 +290,9 @@ func finalize(out *[TagSize]byte, h *[3]uint64, s *[2]uint64) {
|
|||||||
// in constant time, we compute t = h - (2¹³⁰ - 5), and select h as the
|
// in constant time, we compute t = h - (2¹³⁰ - 5), and select h as the
|
||||||
// result if the subtraction underflows, and t otherwise.
|
// result if the subtraction underflows, and t otherwise.
|
||||||
|
|
||||||
hMinusP0, b := bitsSub64(h0, p0, 0)
|
hMinusP0, b := bits.Sub64(h0, p0, 0)
|
||||||
hMinusP1, b := bitsSub64(h1, p1, b)
|
hMinusP1, b := bits.Sub64(h1, p1, b)
|
||||||
_, b = bitsSub64(h2, p2, b)
|
_, b = bits.Sub64(h2, p2, b)
|
||||||
|
|
||||||
// h = h if h < p else h - p
|
// h = h if h < p else h - p
|
||||||
h0 = select64(b, h0, hMinusP0)
|
h0 = select64(b, h0, hMinusP0)
|
||||||
@@ -301,8 +304,8 @@ func finalize(out *[TagSize]byte, h *[3]uint64, s *[2]uint64) {
|
|||||||
//
|
//
|
||||||
// by just doing a wide addition with the 128 low bits of h and discarding
|
// by just doing a wide addition with the 128 low bits of h and discarding
|
||||||
// the overflow.
|
// the overflow.
|
||||||
h0, c := bitsAdd64(h0, s[0], 0)
|
h0, c := bits.Add64(h0, s[0], 0)
|
||||||
h1, _ = bitsAdd64(h1, s[1], c)
|
h1, _ = bits.Add64(h1, s[1], c)
|
||||||
|
|
||||||
binary.LittleEndian.PutUint64(out[0:8], h0)
|
binary.LittleEndian.PutUint64(out[0:8], h0)
|
||||||
binary.LittleEndian.PutUint64(out[8:16], h1)
|
binary.LittleEndian.PutUint64(out[8:16], h1)
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build gc && !purego
|
//go:build gc && !purego
|
||||||
// +build gc,!purego
|
|
||||||
|
|
||||||
package poly1305
|
package poly1305
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build gc && !purego
|
//go:build gc && !purego
|
||||||
// +build gc,!purego
|
|
||||||
|
|
||||||
#include "textflag.h"
|
#include "textflag.h"
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build gc && !purego
|
//go:build gc && !purego
|
||||||
// +build gc,!purego
|
|
||||||
|
|
||||||
package poly1305
|
package poly1305
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build gc && !purego
|
//go:build gc && !purego
|
||||||
// +build gc,!purego
|
|
||||||
|
|
||||||
#include "textflag.h"
|
#include "textflag.h"
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,120 @@
|
|||||||
|
// Copyright 2023 The Go Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package testenv
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"reflect"
|
||||||
|
"strconv"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CommandContext is like exec.CommandContext, but:
|
||||||
|
// - skips t if the platform does not support os/exec,
|
||||||
|
// - sends SIGQUIT (if supported by the platform) instead of SIGKILL
|
||||||
|
// in its Cancel function
|
||||||
|
// - if the test has a deadline, adds a Context timeout and WaitDelay
|
||||||
|
// for an arbitrary grace period before the test's deadline expires,
|
||||||
|
// - fails the test if the command does not complete before the test's deadline, and
|
||||||
|
// - sets a Cleanup function that verifies that the test did not leak a subprocess.
|
||||||
|
func CommandContext(t testing.TB, ctx context.Context, name string, args ...string) *exec.Cmd {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
|
var (
|
||||||
|
cancelCtx context.CancelFunc
|
||||||
|
gracePeriod time.Duration // unlimited unless the test has a deadline (to allow for interactive debugging)
|
||||||
|
)
|
||||||
|
|
||||||
|
if t, ok := t.(interface {
|
||||||
|
testing.TB
|
||||||
|
Deadline() (time.Time, bool)
|
||||||
|
}); ok {
|
||||||
|
if td, ok := t.Deadline(); ok {
|
||||||
|
// Start with a minimum grace period, just long enough to consume the
|
||||||
|
// output of a reasonable program after it terminates.
|
||||||
|
gracePeriod = 100 * time.Millisecond
|
||||||
|
if s := os.Getenv("GO_TEST_TIMEOUT_SCALE"); s != "" {
|
||||||
|
scale, err := strconv.Atoi(s)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("invalid GO_TEST_TIMEOUT_SCALE: %v", err)
|
||||||
|
}
|
||||||
|
gracePeriod *= time.Duration(scale)
|
||||||
|
}
|
||||||
|
|
||||||
|
// If time allows, increase the termination grace period to 5% of the
|
||||||
|
// test's remaining time.
|
||||||
|
testTimeout := time.Until(td)
|
||||||
|
if gp := testTimeout / 20; gp > gracePeriod {
|
||||||
|
gracePeriod = gp
|
||||||
|
}
|
||||||
|
|
||||||
|
// When we run commands that execute subprocesses, we want to reserve two
|
||||||
|
// grace periods to clean up: one for the delay between the first
|
||||||
|
// termination signal being sent (via the Cancel callback when the Context
|
||||||
|
// expires) and the process being forcibly terminated (via the WaitDelay
|
||||||
|
// field), and a second one for the delay becween the process being
|
||||||
|
// terminated and and the test logging its output for debugging.
|
||||||
|
//
|
||||||
|
// (We want to ensure that the test process itself has enough time to
|
||||||
|
// log the output before it is also terminated.)
|
||||||
|
cmdTimeout := testTimeout - 2*gracePeriod
|
||||||
|
|
||||||
|
if cd, ok := ctx.Deadline(); !ok || time.Until(cd) > cmdTimeout {
|
||||||
|
// Either ctx doesn't have a deadline, or its deadline would expire
|
||||||
|
// after (or too close before) the test has already timed out.
|
||||||
|
// Add a shorter timeout so that the test will produce useful output.
|
||||||
|
ctx, cancelCtx = context.WithTimeout(ctx, cmdTimeout)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd := exec.CommandContext(ctx, name, args...)
|
||||||
|
// Set the Cancel and WaitDelay fields only if present (go 1.20 and later).
|
||||||
|
// TODO: When Go 1.19 is no longer supported, remove this use of reflection
|
||||||
|
// and instead set the fields directly.
|
||||||
|
if cmdCancel := reflect.ValueOf(cmd).Elem().FieldByName("Cancel"); cmdCancel.IsValid() {
|
||||||
|
cmdCancel.Set(reflect.ValueOf(func() error {
|
||||||
|
if cancelCtx != nil && ctx.Err() == context.DeadlineExceeded {
|
||||||
|
// The command timed out due to running too close to the test's deadline.
|
||||||
|
// There is no way the test did that intentionally — it's too close to the
|
||||||
|
// wire! — so mark it as a test failure. That way, if the test expects the
|
||||||
|
// command to fail for some other reason, it doesn't have to distinguish
|
||||||
|
// between that reason and a timeout.
|
||||||
|
t.Errorf("test timed out while running command: %v", cmd)
|
||||||
|
} else {
|
||||||
|
// The command is being terminated due to ctx being canceled, but
|
||||||
|
// apparently not due to an explicit test deadline that we added.
|
||||||
|
// Log that information in case it is useful for diagnosing a failure,
|
||||||
|
// but don't actually fail the test because of it.
|
||||||
|
t.Logf("%v: terminating command: %v", ctx.Err(), cmd)
|
||||||
|
}
|
||||||
|
return cmd.Process.Signal(Sigquit)
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
if cmdWaitDelay := reflect.ValueOf(cmd).Elem().FieldByName("WaitDelay"); cmdWaitDelay.IsValid() {
|
||||||
|
cmdWaitDelay.Set(reflect.ValueOf(gracePeriod))
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Cleanup(func() {
|
||||||
|
if cancelCtx != nil {
|
||||||
|
cancelCtx()
|
||||||
|
}
|
||||||
|
if cmd.Process != nil && cmd.ProcessState == nil {
|
||||||
|
t.Errorf("command was started, but test did not wait for it to complete: %v", cmd)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
|
|
||||||
|
// Command is like exec.Command, but applies the same changes as
|
||||||
|
// testenv.CommandContext (with a default Context).
|
||||||
|
func Command(t testing.TB, name string, args ...string) *exec.Cmd {
|
||||||
|
t.Helper()
|
||||||
|
return CommandContext(t, context.Background(), name, args...)
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
// Copyright 2021 The Go Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
//go:build windows || plan9 || (js && wasm) || wasip1
|
||||||
|
|
||||||
|
package testenv
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Sigquit is the signal to send to kill a hanging subprocess.
|
||||||
|
// On Unix we send SIGQUIT, but on non-Unix we only have os.Kill.
|
||||||
|
var Sigquit = os.Kill
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
// Copyright 2021 The Go Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
//go:build unix
|
||||||
|
|
||||||
|
package testenv
|
||||||
|
|
||||||
|
import (
|
||||||
|
"syscall"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Sigquit is the signal to send to kill a hanging subprocess.
|
||||||
|
// Send SIGQUIT to get a stack trace.
|
||||||
|
var Sigquit = syscall.SIGQUIT
|
||||||
@@ -118,7 +118,7 @@ func TestECDHStdLib(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
shared := decodeHex(tt.Shared)
|
shared := decodeHex(tt.Shared)
|
||||||
x, err := curve.ECDH(priv, pub)
|
x, err := priv.ECDH(pub)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if tg.Curve == "curve25519" && !shouldPass {
|
if tg.Curve == "curve25519" && !shouldPass {
|
||||||
// ECDH is expected to only return an error when using X25519,
|
// ECDH is expected to only return an error when using X25519,
|
||||||
|
|||||||
@@ -6,7 +6,11 @@ package wycheproof
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
|
"math/big"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"golang.org/x/crypto/cryptobyte"
|
||||||
|
"golang.org/x/crypto/cryptobyte/asn1"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestECDSA(t *testing.T) {
|
func TestECDSA(t *testing.T) {
|
||||||
@@ -76,9 +80,25 @@ func TestECDSA(t *testing.T) {
|
|||||||
h.Reset()
|
h.Reset()
|
||||||
h.Write(decodeHex(sig.Msg))
|
h.Write(decodeHex(sig.Msg))
|
||||||
hashed := h.Sum(nil)
|
hashed := h.Sum(nil)
|
||||||
got := ecdsa.VerifyASN1(pub, hashed, decodeHex(sig.Sig))
|
sigBytes := decodeHex(sig.Sig)
|
||||||
|
got := ecdsa.VerifyASN1(pub, hashed, sigBytes)
|
||||||
if want := shouldPass(sig.Result, sig.Flags, flagsShouldPass); got != want {
|
if want := shouldPass(sig.Result, sig.Flags, flagsShouldPass); got != want {
|
||||||
t.Errorf("tcid: %d, type: %s, comment: %q, wanted success: %t", sig.TcID, sig.Result, sig.Comment, want)
|
t.Errorf("tcid: %d, type: %s, comment: %q, VerifyASN1 wanted success: %t", sig.TcID, sig.Result, sig.Comment, want)
|
||||||
|
}
|
||||||
|
|
||||||
|
var r, s big.Int
|
||||||
|
var inner cryptobyte.String
|
||||||
|
input := cryptobyte.String(sigBytes)
|
||||||
|
if !input.ReadASN1(&inner, asn1.SEQUENCE) ||
|
||||||
|
!input.Empty() ||
|
||||||
|
!inner.ReadASN1Integer(&r) ||
|
||||||
|
!inner.ReadASN1Integer(&s) ||
|
||||||
|
!inner.Empty() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
got = ecdsa.Verify(pub, hashed, &r, &s)
|
||||||
|
if want := shouldPass(sig.Result, sig.Flags, flagsShouldPass); got != want {
|
||||||
|
t.Errorf("tcid: %d, type: %s, comment: %q, Verify wanted success: %t", sig.TcID, sig.Result, sig.Comment, want)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,14 +3,12 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build go1.13
|
//go:build go1.13
|
||||||
// +build go1.13
|
|
||||||
|
|
||||||
package wycheproof
|
package wycheproof
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/ed25519"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"golang.org/x/crypto/ed25519"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestEddsa(t *testing.T) {
|
func TestEddsa(t *testing.T) {
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import (
|
|||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
@@ -28,6 +29,11 @@ const wycheproofModVer = "v0.0.0-20191219022705-2196000605e4"
|
|||||||
var wycheproofTestVectorsDir string
|
var wycheproofTestVectorsDir string
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
|
flag.Parse()
|
||||||
|
if flag.Lookup("test.short").Value.(flag.Getter).Get().(bool) {
|
||||||
|
log.Println("skipping test that downloads testdata via 'go mod download' in short mode")
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
if _, err := exec.LookPath("go"); err != nil {
|
if _, err := exec.LookPath("go"); err != nil {
|
||||||
log.Printf("skipping test because 'go' command is unavailable: %v", err)
|
log.Printf("skipping test because 'go' command is unavailable: %v", err)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
@@ -42,8 +48,6 @@ func TestMain(m *testing.M) {
|
|||||||
// can be used in the following tests.
|
// can be used in the following tests.
|
||||||
path := "github.com/google/wycheproof@" + wycheproofModVer
|
path := "github.com/google/wycheproof@" + wycheproofModVer
|
||||||
cmd := exec.Command("go", "mod", "download", "-json", path)
|
cmd := exec.Command("go", "mod", "download", "-json", path)
|
||||||
// TODO: enable the sumdb once the Trybots proxy supports it.
|
|
||||||
cmd.Env = append(os.Environ(), "GONOSUMDB=*")
|
|
||||||
output, err := cmd.Output()
|
output, err := cmd.Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("failed to run `go mod download -json %s`, output: %s", path, output)
|
log.Fatalf("failed to run `go mod download -json %s`, output: %s", path, output)
|
||||||
|
|||||||
+1
-1
@@ -21,9 +21,9 @@
|
|||||||
package sign
|
package sign
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/ed25519"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"golang.org/x/crypto/ed25519"
|
|
||||||
"golang.org/x/crypto/internal/alias"
|
"golang.org/x/crypto/internal/alias"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build go1.7
|
//go:build go1.7
|
||||||
// +build go1.7
|
|
||||||
|
|
||||||
package ocsp
|
package ocsp
|
||||||
|
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ func (r *openpgpReader) Read(p []byte) (n int, err error) {
|
|||||||
n, err = r.b64Reader.Read(p)
|
n, err = r.b64Reader.Read(p)
|
||||||
r.currentCRC = crc24(r.currentCRC, p[:n])
|
r.currentCRC = crc24(r.currentCRC, p[:n])
|
||||||
|
|
||||||
if err == io.EOF && r.lReader.crcSet && r.lReader.crc != uint32(r.currentCRC&crc24Mask) {
|
if err == io.EOF && r.lReader.crcSet && r.lReader.crc != r.currentCRC&crc24Mask {
|
||||||
return 0, ArmorCorrupt
|
return 0, ArmorCorrupt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -61,7 +61,7 @@ type Key struct {
|
|||||||
type KeyRing interface {
|
type KeyRing interface {
|
||||||
// KeysById returns the set of keys that have the given key id.
|
// KeysById returns the set of keys that have the given key id.
|
||||||
KeysById(id uint64) []Key
|
KeysById(id uint64) []Key
|
||||||
// KeysByIdAndUsage returns the set of keys with the given id
|
// KeysByIdUsage returns the set of keys with the given id
|
||||||
// that also meet the key usage given by requiredUsage.
|
// that also meet the key usage given by requiredUsage.
|
||||||
// The requiredUsage is expressed as the bitwise-OR of
|
// The requiredUsage is expressed as the bitwise-OR of
|
||||||
// packet.KeyFlag* values.
|
// packet.KeyFlag* values.
|
||||||
@@ -183,7 +183,7 @@ func (el EntityList) KeysById(id uint64) (keys []Key) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// KeysByIdAndUsage returns the set of keys with the given id that also meet
|
// KeysByIdUsage returns the set of keys with the given id that also meet
|
||||||
// the key usage given by requiredUsage. The requiredUsage is expressed as
|
// the key usage given by requiredUsage. The requiredUsage is expressed as
|
||||||
// the bitwise-OR of packet.KeyFlag* values.
|
// the bitwise-OR of packet.KeyFlag* values.
|
||||||
func (el EntityList) KeysByIdUsage(id uint64, requiredUsage byte) (keys []Key) {
|
func (el EntityList) KeysByIdUsage(id uint64, requiredUsage byte) (keys []Key) {
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ func (c *Compressed) parse(r io.Reader) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// compressedWriterCloser represents the serialized compression stream
|
// compressedWriteCloser represents the serialized compression stream
|
||||||
// header and the compressor. Its Close() method ensures that both the
|
// header and the compressor. Its Close() method ensures that both the
|
||||||
// compressor and serialized stream header are closed. Its Write()
|
// compressor and serialized stream header are closed. Its Write()
|
||||||
// method writes to the compressor.
|
// method writes to the compressor.
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
// This code can be compiled and used to test the otr package against libotr.
|
// This code can be compiled and used to test the otr package against libotr.
|
||||||
// See otr_test.go.
|
// See otr_test.go.
|
||||||
|
|
||||||
// +build ignore
|
//go:build ignore
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build amd64 && !purego && gc
|
//go:build amd64 && !purego && gc
|
||||||
// +build amd64,!purego,gc
|
|
||||||
|
|
||||||
package salsa
|
package salsa
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build amd64 && !purego && gc
|
//go:build amd64 && !purego && gc
|
||||||
// +build amd64,!purego,gc
|
|
||||||
|
|
||||||
// This code was translated into a form compatible with 6a from the public
|
// This code was translated into a form compatible with 6a from the public
|
||||||
// domain sources in SUPERCOP: https://bench.cr.yp.to/supercop.html
|
// domain sources in SUPERCOP: https://bench.cr.yp.to/supercop.html
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build amd64 && !purego && gc
|
//go:build amd64 && !purego && gc
|
||||||
// +build amd64,!purego,gc
|
|
||||||
|
|
||||||
package salsa
|
package salsa
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build !amd64 || purego || !gc
|
//go:build !amd64 || purego || !gc
|
||||||
// +build !amd64 purego !gc
|
|
||||||
|
|
||||||
package salsa
|
package salsa
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build !gc || purego || !s390x
|
//go:build !gc || purego || !s390x
|
||||||
// +build !gc purego !s390x
|
|
||||||
|
|
||||||
package sha3
|
package sha3
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build !amd64 || purego || !gc
|
//go:build !amd64 || purego || !gc
|
||||||
// +build !amd64 purego !gc
|
|
||||||
|
|
||||||
package sha3
|
package sha3
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build amd64 && !purego && gc
|
//go:build amd64 && !purego && gc
|
||||||
// +build amd64,!purego,gc
|
|
||||||
|
|
||||||
package sha3
|
package sha3
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build amd64 && !purego && gc
|
//go:build amd64 && !purego && gc
|
||||||
// +build amd64,!purego,gc
|
|
||||||
|
|
||||||
// This code was translated into a form compatible with 6a from the public
|
// This code was translated into a form compatible with 6a from the public
|
||||||
// domain sources at https://github.com/gvanas/KeccakCodePackage
|
// domain sources at https://github.com/gvanas/KeccakCodePackage
|
||||||
@@ -320,9 +319,9 @@
|
|||||||
MOVQ rDi, _si(oState); \
|
MOVQ rDi, _si(oState); \
|
||||||
MOVQ rDo, _so(oState) \
|
MOVQ rDo, _so(oState) \
|
||||||
|
|
||||||
// func keccakF1600(state *[25]uint64)
|
// func keccakF1600(a *[25]uint64)
|
||||||
TEXT ·keccakF1600(SB), 0, $200-8
|
TEXT ·keccakF1600(SB), 0, $200-8
|
||||||
MOVQ state+0(FP), rpState
|
MOVQ a+0(FP), rpState
|
||||||
|
|
||||||
// Convert the user state into an internal state
|
// Convert the user state into an internal state
|
||||||
NOTQ _be(rpState)
|
NOTQ _be(rpState)
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build go1.4
|
//go:build go1.4
|
||||||
// +build go1.4
|
|
||||||
|
|
||||||
package sha3
|
package sha3
|
||||||
|
|
||||||
|
|||||||
+9
-5
@@ -121,11 +121,11 @@ func (d *state) padAndPermute(dsbyte byte) {
|
|||||||
copyOut(d, d.buf)
|
copyOut(d, d.buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write absorbs more data into the hash's state. It produces an error
|
// Write absorbs more data into the hash's state. It panics if any
|
||||||
// if more data is written to the ShakeHash after writing
|
// output has already been read.
|
||||||
func (d *state) Write(p []byte) (written int, err error) {
|
func (d *state) Write(p []byte) (written int, err error) {
|
||||||
if d.state != spongeAbsorbing {
|
if d.state != spongeAbsorbing {
|
||||||
panic("sha3: write to sponge after read")
|
panic("sha3: Write after Read")
|
||||||
}
|
}
|
||||||
if d.buf == nil {
|
if d.buf == nil {
|
||||||
d.buf = d.storage.asBytes()[:0]
|
d.buf = d.storage.asBytes()[:0]
|
||||||
@@ -182,12 +182,16 @@ func (d *state) Read(out []byte) (n int, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Sum applies padding to the hash state and then squeezes out the desired
|
// Sum applies padding to the hash state and then squeezes out the desired
|
||||||
// number of output bytes.
|
// number of output bytes. It panics if any output has already been read.
|
||||||
func (d *state) Sum(in []byte) []byte {
|
func (d *state) Sum(in []byte) []byte {
|
||||||
|
if d.state != spongeAbsorbing {
|
||||||
|
panic("sha3: Sum after Read")
|
||||||
|
}
|
||||||
|
|
||||||
// Make a copy of the original hash so that caller can keep writing
|
// Make a copy of the original hash so that caller can keep writing
|
||||||
// and summing.
|
// and summing.
|
||||||
dup := d.clone()
|
dup := d.clone()
|
||||||
hash := make([]byte, dup.outputLen)
|
hash := make([]byte, dup.outputLen, 64) // explicit cap to allow stack allocation
|
||||||
dup.Read(hash)
|
dup.Read(hash)
|
||||||
return append(in, hash...)
|
return append(in, hash...)
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-5
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build gc && !purego
|
//go:build gc && !purego
|
||||||
// +build gc,!purego
|
|
||||||
|
|
||||||
package sha3
|
package sha3
|
||||||
|
|
||||||
@@ -49,7 +48,7 @@ type asmState struct {
|
|||||||
buf []byte // care must be taken to ensure cap(buf) is a multiple of rate
|
buf []byte // care must be taken to ensure cap(buf) is a multiple of rate
|
||||||
rate int // equivalent to block size
|
rate int // equivalent to block size
|
||||||
storage [3072]byte // underlying storage for buf
|
storage [3072]byte // underlying storage for buf
|
||||||
outputLen int // output length if fixed, 0 if not
|
outputLen int // output length for full security
|
||||||
function code // KIMD/KLMD function code
|
function code // KIMD/KLMD function code
|
||||||
state spongeDirection // whether the sponge is absorbing or squeezing
|
state spongeDirection // whether the sponge is absorbing or squeezing
|
||||||
}
|
}
|
||||||
@@ -72,8 +71,10 @@ func newAsmState(function code) *asmState {
|
|||||||
s.outputLen = 64
|
s.outputLen = 64
|
||||||
case shake_128:
|
case shake_128:
|
||||||
s.rate = 168
|
s.rate = 168
|
||||||
|
s.outputLen = 32
|
||||||
case shake_256:
|
case shake_256:
|
||||||
s.rate = 136
|
s.rate = 136
|
||||||
|
s.outputLen = 64
|
||||||
default:
|
default:
|
||||||
panic("sha3: unrecognized function code")
|
panic("sha3: unrecognized function code")
|
||||||
}
|
}
|
||||||
@@ -108,7 +109,7 @@ func (s *asmState) resetBuf() {
|
|||||||
// It never returns an error.
|
// It never returns an error.
|
||||||
func (s *asmState) Write(b []byte) (int, error) {
|
func (s *asmState) Write(b []byte) (int, error) {
|
||||||
if s.state != spongeAbsorbing {
|
if s.state != spongeAbsorbing {
|
||||||
panic("sha3: write to sponge after read")
|
panic("sha3: Write after Read")
|
||||||
}
|
}
|
||||||
length := len(b)
|
length := len(b)
|
||||||
for len(b) > 0 {
|
for len(b) > 0 {
|
||||||
@@ -192,8 +193,8 @@ func (s *asmState) Read(out []byte) (n int, err error) {
|
|||||||
// Sum appends the current hash to b and returns the resulting slice.
|
// Sum appends the current hash to b and returns the resulting slice.
|
||||||
// It does not change the underlying hash state.
|
// It does not change the underlying hash state.
|
||||||
func (s *asmState) Sum(b []byte) []byte {
|
func (s *asmState) Sum(b []byte) []byte {
|
||||||
if s.outputLen == 0 {
|
if s.state != spongeAbsorbing {
|
||||||
panic("sha3: cannot call Sum on SHAKE functions")
|
panic("sha3: Sum after Read")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy the state to preserve the original.
|
// Copy the state to preserve the original.
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build gc && !purego
|
//go:build gc && !purego
|
||||||
// +build gc,!purego
|
|
||||||
|
|
||||||
#include "textflag.h"
|
#include "textflag.h"
|
||||||
|
|
||||||
|
|||||||
+14
-15
@@ -17,26 +17,25 @@ package sha3
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
"hash"
|
||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ShakeHash defines the interface to hash functions that
|
// ShakeHash defines the interface to hash functions that support
|
||||||
// support arbitrary-length output.
|
// arbitrary-length output. When used as a plain [hash.Hash], it
|
||||||
|
// produces minimum-length outputs that provide full-strength generic
|
||||||
|
// security.
|
||||||
type ShakeHash interface {
|
type ShakeHash interface {
|
||||||
// Write absorbs more data into the hash's state. It panics if input is
|
hash.Hash
|
||||||
// written to it after output has been read from it.
|
|
||||||
io.Writer
|
|
||||||
|
|
||||||
// Read reads more output from the hash; reading affects the hash's
|
// Read reads more output from the hash; reading affects the hash's
|
||||||
// state. (ShakeHash.Read is thus very different from Hash.Sum)
|
// state. (ShakeHash.Read is thus very different from Hash.Sum)
|
||||||
// It never returns an error.
|
// It never returns an error, but subsequent calls to Write or Sum
|
||||||
|
// will panic.
|
||||||
io.Reader
|
io.Reader
|
||||||
|
|
||||||
// Clone returns a copy of the ShakeHash in its current state.
|
// Clone returns a copy of the ShakeHash in its current state.
|
||||||
Clone() ShakeHash
|
Clone() ShakeHash
|
||||||
|
|
||||||
// Reset resets the ShakeHash to its initial state.
|
|
||||||
Reset()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// cSHAKE specific context
|
// cSHAKE specific context
|
||||||
@@ -81,8 +80,8 @@ func leftEncode(value uint64) []byte {
|
|||||||
return b[i-1:]
|
return b[i-1:]
|
||||||
}
|
}
|
||||||
|
|
||||||
func newCShake(N, S []byte, rate int, dsbyte byte) ShakeHash {
|
func newCShake(N, S []byte, rate, outputLen int, dsbyte byte) ShakeHash {
|
||||||
c := cshakeState{state: &state{rate: rate, dsbyte: dsbyte}}
|
c := cshakeState{state: &state{rate: rate, outputLen: outputLen, dsbyte: dsbyte}}
|
||||||
|
|
||||||
// leftEncode returns max 9 bytes
|
// leftEncode returns max 9 bytes
|
||||||
c.initBlock = make([]byte, 0, 9*2+len(N)+len(S))
|
c.initBlock = make([]byte, 0, 9*2+len(N)+len(S))
|
||||||
@@ -119,7 +118,7 @@ func NewShake128() ShakeHash {
|
|||||||
if h := newShake128Asm(); h != nil {
|
if h := newShake128Asm(); h != nil {
|
||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
return &state{rate: rate128, dsbyte: dsbyteShake}
|
return &state{rate: rate128, outputLen: 32, dsbyte: dsbyteShake}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewShake256 creates a new SHAKE256 variable-output-length ShakeHash.
|
// NewShake256 creates a new SHAKE256 variable-output-length ShakeHash.
|
||||||
@@ -129,7 +128,7 @@ func NewShake256() ShakeHash {
|
|||||||
if h := newShake256Asm(); h != nil {
|
if h := newShake256Asm(); h != nil {
|
||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
return &state{rate: rate256, dsbyte: dsbyteShake}
|
return &state{rate: rate256, outputLen: 64, dsbyte: dsbyteShake}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCShake128 creates a new instance of cSHAKE128 variable-output-length ShakeHash,
|
// NewCShake128 creates a new instance of cSHAKE128 variable-output-length ShakeHash,
|
||||||
@@ -142,7 +141,7 @@ func NewCShake128(N, S []byte) ShakeHash {
|
|||||||
if len(N) == 0 && len(S) == 0 {
|
if len(N) == 0 && len(S) == 0 {
|
||||||
return NewShake128()
|
return NewShake128()
|
||||||
}
|
}
|
||||||
return newCShake(N, S, rate128, dsbyteCShake)
|
return newCShake(N, S, rate128, 32, dsbyteCShake)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCShake256 creates a new instance of cSHAKE256 variable-output-length ShakeHash,
|
// NewCShake256 creates a new instance of cSHAKE256 variable-output-length ShakeHash,
|
||||||
@@ -155,7 +154,7 @@ func NewCShake256(N, S []byte) ShakeHash {
|
|||||||
if len(N) == 0 && len(S) == 0 {
|
if len(N) == 0 && len(S) == 0 {
|
||||||
return NewShake256()
|
return NewShake256()
|
||||||
}
|
}
|
||||||
return newCShake(N, S, rate256, dsbyteCShake)
|
return newCShake(N, S, rate256, 64, dsbyteCShake)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ShakeSum128 writes an arbitrary-length digest of data into hash.
|
// ShakeSum128 writes an arbitrary-length digest of data into hash.
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build !gc || purego || !s390x
|
//go:build !gc || purego || !s390x
|
||||||
// +build !gc purego !s390x
|
|
||||||
|
|
||||||
package sha3
|
package sha3
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build (!amd64 && !386 && !ppc64le) || purego
|
//go:build (!amd64 && !386 && !ppc64le) || purego
|
||||||
// +build !amd64,!386,!ppc64le purego
|
|
||||||
|
|
||||||
package sha3
|
package sha3
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build (amd64 || 386 || ppc64le) && !purego
|
//go:build (amd64 || 386 || ppc64le) && !purego
|
||||||
// +build amd64 386 ppc64le
|
|
||||||
// +build !purego
|
|
||||||
|
|
||||||
package sha3
|
package sha3
|
||||||
|
|
||||||
|
|||||||
+10
-5
@@ -16,6 +16,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"crypto/dsa"
|
"crypto/dsa"
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
|
"crypto/ed25519"
|
||||||
"crypto/elliptic"
|
"crypto/elliptic"
|
||||||
"crypto/rsa"
|
"crypto/rsa"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
@@ -26,7 +27,6 @@ import (
|
|||||||
"math/big"
|
"math/big"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"golang.org/x/crypto/ed25519"
|
|
||||||
"golang.org/x/crypto/ssh"
|
"golang.org/x/crypto/ssh"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -141,9 +141,14 @@ const (
|
|||||||
agentAddSmartcardKeyConstrained = 26
|
agentAddSmartcardKeyConstrained = 26
|
||||||
|
|
||||||
// 3.7 Key constraint identifiers
|
// 3.7 Key constraint identifiers
|
||||||
agentConstrainLifetime = 1
|
agentConstrainLifetime = 1
|
||||||
agentConstrainConfirm = 2
|
agentConstrainConfirm = 2
|
||||||
agentConstrainExtension = 3
|
// Constraint extension identifier up to version 2 of the protocol. A
|
||||||
|
// backward incompatible change will be required if we want to add support
|
||||||
|
// for SSH_AGENT_CONSTRAIN_MAXSIGN which uses the same ID.
|
||||||
|
agentConstrainExtensionV00 = 3
|
||||||
|
// Constraint extension identifier in version 3 and later of the protocol.
|
||||||
|
agentConstrainExtension = 255
|
||||||
)
|
)
|
||||||
|
|
||||||
// maxAgentResponseBytes is the maximum agent reply size that is accepted. This
|
// maxAgentResponseBytes is the maximum agent reply size that is accepted. This
|
||||||
@@ -205,7 +210,7 @@ type constrainLifetimeAgentMsg struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type constrainExtensionAgentMsg struct {
|
type constrainExtensionAgentMsg struct {
|
||||||
ExtensionName string `sshtype:"3"`
|
ExtensionName string `sshtype:"255|3"`
|
||||||
ExtensionDetails []byte
|
ExtensionDetails []byte
|
||||||
|
|
||||||
// Rest is a field used for parsing, not part of message
|
// Rest is a field used for parsing, not part of message
|
||||||
|
|||||||
@@ -29,6 +29,9 @@ func startOpenSSHAgent(t *testing.T) (client ExtendedAgent, socket string, clean
|
|||||||
// types supported vary by platform.
|
// types supported vary by platform.
|
||||||
t.Skip("skipping test due to -short")
|
t.Skip("skipping test due to -short")
|
||||||
}
|
}
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
t.Skip("skipping on windows, we don't support connecting to the ssh-agent via a named pipe")
|
||||||
|
}
|
||||||
|
|
||||||
bin, err := exec.LookPath("ssh-agent")
|
bin, err := exec.LookPath("ssh-agent")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -366,7 +369,8 @@ func TestAuth(t *testing.T) {
|
|||||||
go func() {
|
go func() {
|
||||||
conn, _, _, err := ssh.NewServerConn(a, &serverConf)
|
conn, _, _, err := ssh.NewServerConn(a, &serverConf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Server: %v", err)
|
t.Errorf("NewServerConn error: %v", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
conn.Close()
|
conn.Close()
|
||||||
}()
|
}()
|
||||||
|
|||||||
+3
-3
@@ -7,6 +7,7 @@ package agent
|
|||||||
import (
|
import (
|
||||||
"crypto/dsa"
|
"crypto/dsa"
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
|
"crypto/ed25519"
|
||||||
"crypto/elliptic"
|
"crypto/elliptic"
|
||||||
"crypto/rsa"
|
"crypto/rsa"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
@@ -16,11 +17,10 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"golang.org/x/crypto/ed25519"
|
|
||||||
"golang.org/x/crypto/ssh"
|
"golang.org/x/crypto/ssh"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server wraps an Agent and uses it to implement the agent side of
|
// server wraps an Agent and uses it to implement the agent side of
|
||||||
// the SSH-agent, wire protocol.
|
// the SSH-agent, wire protocol.
|
||||||
type server struct {
|
type server struct {
|
||||||
agent Agent
|
agent Agent
|
||||||
@@ -208,7 +208,7 @@ func parseConstraints(constraints []byte) (lifetimeSecs uint32, confirmBeforeUse
|
|||||||
case agentConstrainConfirm:
|
case agentConstrainConfirm:
|
||||||
confirmBeforeUse = true
|
confirmBeforeUse = true
|
||||||
constraints = constraints[1:]
|
constraints = constraints[1:]
|
||||||
case agentConstrainExtension:
|
case agentConstrainExtension, agentConstrainExtensionV00:
|
||||||
var msg constrainExtensionAgentMsg
|
var msg constrainExtensionAgentMsg
|
||||||
if err = ssh.Unmarshal(constraints, &msg); err != nil {
|
if err = ssh.Unmarshal(constraints, &msg); err != nil {
|
||||||
return 0, false, nil, err
|
return 0, false, nil, err
|
||||||
|
|||||||
@@ -53,10 +53,11 @@ func TestSetupForwardAgent(t *testing.T) {
|
|||||||
incoming := make(chan *ssh.ServerConn, 1)
|
incoming := make(chan *ssh.ServerConn, 1)
|
||||||
go func() {
|
go func() {
|
||||||
conn, _, _, err := ssh.NewServerConn(a, &serverConf)
|
conn, _, _, err := ssh.NewServerConn(a, &serverConf)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Server: %v", err)
|
|
||||||
}
|
|
||||||
incoming <- conn
|
incoming <- conn
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("NewServerConn error: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
conf := ssh.ClientConfig{
|
conf := ssh.ClientConfig{
|
||||||
@@ -71,8 +72,10 @@ func TestSetupForwardAgent(t *testing.T) {
|
|||||||
if err := ForwardToRemote(client, socket); err != nil {
|
if err := ForwardToRemote(client, socket); err != nil {
|
||||||
t.Fatalf("SetupForwardAgent: %v", err)
|
t.Fatalf("SetupForwardAgent: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
server := <-incoming
|
server := <-incoming
|
||||||
|
if server == nil {
|
||||||
|
t.Fatal("Unable to get server")
|
||||||
|
}
|
||||||
ch, reqs, err := server.OpenChannel(channelType, nil)
|
ch, reqs, err := server.OpenChannel(channelType, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("OpenChannel(%q): %v", channelType, err)
|
t.Fatalf("OpenChannel(%q): %v", channelType, err)
|
||||||
@@ -240,7 +243,11 @@ func TestParseConstraints(t *testing.T) {
|
|||||||
ExtensionDetails: []byte(fmt.Sprintf("details: %d", i)),
|
ExtensionDetails: []byte(fmt.Sprintf("details: %d", i)),
|
||||||
}
|
}
|
||||||
expect = append(expect, ext)
|
expect = append(expect, ext)
|
||||||
data = append(data, agentConstrainExtension)
|
if i%2 == 0 {
|
||||||
|
data = append(data, agentConstrainExtension)
|
||||||
|
} else {
|
||||||
|
data = append(data, agentConstrainExtensionV00)
|
||||||
|
}
|
||||||
data = append(data, ssh.Marshal(ext)...)
|
data = append(data, ssh.Marshal(ext)...)
|
||||||
}
|
}
|
||||||
_, _, extensions, err := parseConstraints(data)
|
_, _, extensions, err := parseConstraints(data)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ package ssh
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -90,16 +91,16 @@ func BenchmarkEndToEnd(b *testing.B) {
|
|||||||
go func() {
|
go func() {
|
||||||
newCh, err := server.Accept()
|
newCh, err := server.Accept()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatalf("Client: %v", err)
|
panic(fmt.Sprintf("Client: %v", err))
|
||||||
}
|
}
|
||||||
ch, incoming, err := newCh.Accept()
|
ch, incoming, err := newCh.Accept()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatalf("Accept: %v", err)
|
panic(fmt.Sprintf("Accept: %v", err))
|
||||||
}
|
}
|
||||||
go DiscardRequests(incoming)
|
go DiscardRequests(incoming)
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if _, err := io.ReadFull(ch, output); err != nil {
|
if _, err := io.ReadFull(ch, output); err != nil {
|
||||||
b.Fatalf("ReadFull: %v", err)
|
panic(fmt.Sprintf("ReadFull: %v", err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ch.Close()
|
ch.Close()
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user