Blame SOURCES/gcc6-libgo-p224.patch

7d9f3d
--- libgo/Makefile.am.jj	2014-01-08 13:53:06.000000000 +0100
7d9f3d
+++ libgo/Makefile.am	2014-03-05 15:20:09.938466093 +0100
7d9f3d
@@ -1133,7 +1133,6 @@ go_crypto_ecdsa_files = \
7d9f3d
 	go/crypto/ecdsa/ecdsa.go
7d9f3d
 go_crypto_elliptic_files = \
7d9f3d
 	go/crypto/elliptic/elliptic.go \
7d9f3d
-	go/crypto/elliptic/p224.go \
7d9f3d
 	go/crypto/elliptic/p256.go
7d9f3d
 go_crypto_hmac_files = \
7d9f3d
 	go/crypto/hmac/hmac.go
7d9f3d
--- libgo/Makefile.in.jj	2014-01-08 13:53:06.000000000 +0100
7d9f3d
+++ libgo/Makefile.in	2014-03-05 15:20:20.372465471 +0100
7d9f3d
@@ -1291,7 +1291,6 @@ go_crypto_ecdsa_files = \
7d9f3d
 
7d9f3d
 go_crypto_elliptic_files = \
7d9f3d
 	go/crypto/elliptic/elliptic.go \
7d9f3d
-	go/crypto/elliptic/p224.go \
7d9f3d
 	go/crypto/elliptic/p256.go
7d9f3d
 
7d9f3d
 go_crypto_hmac_files = \
7d9f3d
--- libgo/go/crypto/elliptic/elliptic.go.jj	2016-02-05 20:11:20.000000000 +0100
7d9f3d
+++ libgo/go/crypto/elliptic/elliptic.go	2016-02-05 22:36:06.145039321 +0100
7d9f3d
@@ -338,7 +338,6 @@ var p384 *CurveParams
7d9f3d
 var p521 *CurveParams
7d9f3d
 
7d9f3d
 func initAll() {
7d9f3d
-	initP224()
7d9f3d
 	initP256()
7d9f3d
 	initP384()
7d9f3d
 	initP521()
7d9f3d
--- libgo/go/crypto/elliptic/elliptic_test.go.jj	2016-02-05 20:11:19.000000000 +0100
7d9f3d
+++ libgo/go/crypto/elliptic/elliptic_test.go	2016-02-05 22:37:37.857772875 +0100
7d9f3d
@@ -5,39 +5,16 @@
7d9f3d
 package elliptic
7d9f3d
 
7d9f3d
 import (
7d9f3d
-	"crypto/rand"
7d9f3d
-	"encoding/hex"
7d9f3d
-	"fmt"
7d9f3d
 	"math/big"
7d9f3d
 	"testing"
7d9f3d
 )
7d9f3d
 
7d9f3d
-func TestOnCurve(t *testing.T) {
7d9f3d
-	p224 := P224()
7d9f3d
-	if !p224.IsOnCurve(p224.Params().Gx, p224.Params().Gy) {
7d9f3d
-		t.Errorf("FAIL")
7d9f3d
-	}
7d9f3d
-}
7d9f3d
-
7d9f3d
-func TestOffCurve(t *testing.T) {
7d9f3d
-	p224 := P224()
7d9f3d
-	x, y := new(big.Int).SetInt64(1), new(big.Int).SetInt64(1)
7d9f3d
-	if p224.IsOnCurve(x, y) {
7d9f3d
-		t.Errorf("FAIL: point off curve is claimed to be on the curve")
7d9f3d
-	}
7d9f3d
-	b := Marshal(p224, x, y)
7d9f3d
-	x1, y1 := Unmarshal(p224, b)
7d9f3d
-	if x1 != nil || y1 != nil {
7d9f3d
-		t.Errorf("FAIL: unmarshalling a point not on the curve succeeded")
7d9f3d
-	}
7d9f3d
-}
7d9f3d
-
7d9f3d
 type baseMultTest struct {
7d9f3d
 	k    string
7d9f3d
 	x, y string
7d9f3d
 }
7d9f3d
 
7d9f3d
-var p224BaseMultTests = []baseMultTest{
7d9f3d
+var p256BaseMultTests = []baseMultTest{
7d9f3d
 	{
7d9f3d
 		"1",
7d9f3d
 		"b70e0cbd6bb4bf7f321390b94a03c1d356c21122343280d6115c1d21",
7d9f3d
@@ -300,47 +277,12 @@ var p224BaseMultTests = []baseMultTest{
7d9f3d
 	},
7d9f3d
 }
7d9f3d
 
7d9f3d
-func TestBaseMult(t *testing.T) {
7d9f3d
-	p224 := P224()
7d9f3d
-	for i, e := range p224BaseMultTests {
7d9f3d
-		k, ok := new(big.Int).SetString(e.k, 10)
7d9f3d
-		if !ok {
7d9f3d
-			t.Errorf("%d: bad value for k: %s", i, e.k)
7d9f3d
-		}
7d9f3d
-		x, y := p224.ScalarBaseMult(k.Bytes())
7d9f3d
-		if fmt.Sprintf("%x", x) != e.x || fmt.Sprintf("%x", y) != e.y {
7d9f3d
-			t.Errorf("%d: bad output for k=%s: got (%x, %x), want (%s, %s)", i, e.k, x, y, e.x, e.y)
7d9f3d
-		}
7d9f3d
-		if testing.Short() && i > 5 {
7d9f3d
-			break
7d9f3d
-		}
7d9f3d
-	}
7d9f3d
-}
7d9f3d
-
7d9f3d
-func TestGenericBaseMult(t *testing.T) {
7d9f3d
-	// We use the P224 CurveParams directly in order to test the generic implementation.
7d9f3d
-	p224 := P224().Params()
7d9f3d
-	for i, e := range p224BaseMultTests {
7d9f3d
-		k, ok := new(big.Int).SetString(e.k, 10)
7d9f3d
-		if !ok {
7d9f3d
-			t.Errorf("%d: bad value for k: %s", i, e.k)
7d9f3d
-		}
7d9f3d
-		x, y := p224.ScalarBaseMult(k.Bytes())
7d9f3d
-		if fmt.Sprintf("%x", x) != e.x || fmt.Sprintf("%x", y) != e.y {
7d9f3d
-			t.Errorf("%d: bad output for k=%s: got (%x, %x), want (%s, %s)", i, e.k, x, y, e.x, e.y)
7d9f3d
-		}
7d9f3d
-		if testing.Short() && i > 5 {
7d9f3d
-			break
7d9f3d
-		}
7d9f3d
-	}
7d9f3d
-}
7d9f3d
-
7d9f3d
 func TestP256BaseMult(t *testing.T) {
7d9f3d
 	p256 := P256()
7d9f3d
 	p256Generic := p256.Params()
7d9f3d
 
7d9f3d
-	scalars := make([]*big.Int, 0, len(p224BaseMultTests)+1)
7d9f3d
-	for _, e := range p224BaseMultTests {
7d9f3d
+	scalars := make([]*big.Int, 0, len(p256BaseMultTests)+1)
7d9f3d
+	for _, e := range p256BaseMultTests {
7d9f3d
 		k, _ := new(big.Int).SetString(e.k, 10)
7d9f3d
 		scalars = append(scalars, k)
7d9f3d
 	}
7d9f3d
@@ -365,7 +307,7 @@ func TestP256Mult(t *testing.T) {
7d9f3d
 	p256 := P256()
7d9f3d
 	p256Generic := p256.Params()
7d9f3d
 
7d9f3d
-	for i, e := range p224BaseMultTests {
7d9f3d
+	for i, e := range p256BaseMultTests {
7d9f3d
 		x, _ := new(big.Int).SetString(e.x, 16)
7d9f3d
 		y, _ := new(big.Int).SetString(e.y, 16)
7d9f3d
 		k, _ := new(big.Int).SetString(e.k, 10)
7d9f3d
@@ -386,7 +328,6 @@ func TestInfinity(t *testing.T) {
7d9f3d
 		name  string
7d9f3d
 		curve Curve
7d9f3d
 	}{
7d9f3d
-		{"p224", P224()},
7d9f3d
 		{"p256", P256()},
7d9f3d
 	}
7d9f3d
 
7d9f3d
@@ -419,21 +360,10 @@ func TestInfinity(t *testing.T) {
7d9f3d
 	}
7d9f3d
 }
7d9f3d
 
7d9f3d
-func BenchmarkBaseMult(b *testing.B) {
7d9f3d
-	b.ResetTimer()
7d9f3d
-	p224 := P224()
7d9f3d
-	e := p224BaseMultTests[25]
7d9f3d
-	k, _ := new(big.Int).SetString(e.k, 10)
7d9f3d
-	b.StartTimer()
7d9f3d
-	for i := 0; i < b.N; i++ {
7d9f3d
-		p224.ScalarBaseMult(k.Bytes())
7d9f3d
-	}
7d9f3d
-}
7d9f3d
-
7d9f3d
 func BenchmarkBaseMultP256(b *testing.B) {
7d9f3d
 	b.ResetTimer()
7d9f3d
 	p256 := P256()
7d9f3d
-	e := p224BaseMultTests[25]
7d9f3d
+	e := p256BaseMultTests[25]
7d9f3d
 	k, _ := new(big.Int).SetString(e.k, 10)
7d9f3d
 	b.StartTimer()
7d9f3d
 	for i := 0; i < b.N; i++ {
7d9f3d
@@ -452,32 +382,3 @@ func BenchmarkScalarMultP256(b *testing.
7d9f3d
 		p256.ScalarMult(x, y, priv)
7d9f3d
 	}
7d9f3d
 }
7d9f3d
-
7d9f3d
-func TestMarshal(t *testing.T) {
7d9f3d
-	p224 := P224()
7d9f3d
-	_, x, y, err := GenerateKey(p224, rand.Reader)
7d9f3d
-	if err != nil {
7d9f3d
-		t.Error(err)
7d9f3d
-		return
7d9f3d
-	}
7d9f3d
-	serialized := Marshal(p224, x, y)
7d9f3d
-	xx, yy := Unmarshal(p224, serialized)
7d9f3d
-	if xx == nil {
7d9f3d
-		t.Error("failed to unmarshal")
7d9f3d
-		return
7d9f3d
-	}
7d9f3d
-	if xx.Cmp(x) != 0 || yy.Cmp(y) != 0 {
7d9f3d
-		t.Error("unmarshal returned different values")
7d9f3d
-		return
7d9f3d
-	}
7d9f3d
-}
7d9f3d
-
7d9f3d
-func TestP224Overflow(t *testing.T) {
7d9f3d
-	// This tests for a specific bug in the P224 implementation.
7d9f3d
-	p224 := P224()
7d9f3d
-	pointData, _ := hex.DecodeString("049B535B45FB0A2072398A6831834624C7E32CCFD5A4B933BCEAF77F1DD945E08BBE5178F5EDF5E733388F196D2A631D2E075BB16CBFEEA15B")
7d9f3d
-	x, y := Unmarshal(p224, pointData)
7d9f3d
-	if !p224.IsOnCurve(x, y) {
7d9f3d
-		t.Error("P224 failed to validate a correct point")
7d9f3d
-	}
7d9f3d
-}
7d9f3d
--- libgo/go/crypto/ecdsa/ecdsa_test.go.jj	2016-02-05 20:10:59.000000000 +0100
7d9f3d
+++ libgo/go/crypto/ecdsa/ecdsa_test.go	2016-02-05 22:41:54.916215999 +0100
7d9f3d
@@ -33,7 +33,6 @@ func testKeyGeneration(t *testing.T, c e
7d9f3d
 }
7d9f3d
 
7d9f3d
 func TestKeyGeneration(t *testing.T) {
7d9f3d
-	testKeyGeneration(t, elliptic.P224(), "p224")
7d9f3d
 	if testing.Short() {
7d9f3d
 		return
7d9f3d
 	}
7d9f3d
@@ -98,7 +97,6 @@ func testSignAndVerify(t *testing.T, c e
7d9f3d
 }
7d9f3d
 
7d9f3d
 func TestSignAndVerify(t *testing.T) {
7d9f3d
-	testSignAndVerify(t, elliptic.P224(), "p224")
7d9f3d
 	if testing.Short() {
7d9f3d
 		return
7d9f3d
 	}
7d9f3d
@@ -135,7 +133,6 @@ func testNonceSafety(t *testing.T, c ell
7d9f3d
 }
7d9f3d
 
7d9f3d
 func TestNonceSafety(t *testing.T) {
7d9f3d
-	testNonceSafety(t, elliptic.P224(), "p224")
7d9f3d
 	if testing.Short() {
7d9f3d
 		return
7d9f3d
 	}
7d9f3d
@@ -170,7 +167,6 @@ func testINDCCA(t *testing.T, c elliptic
7d9f3d
 }
7d9f3d
 
7d9f3d
 func TestINDCCA(t *testing.T) {
7d9f3d
-	testINDCCA(t, elliptic.P224(), "p224")
7d9f3d
 	if testing.Short() {
7d9f3d
 		return
7d9f3d
 	}
7d9f3d
@@ -236,8 +232,6 @@ func TestVectors(t *testing.T) {
7d9f3d
 			parts := strings.SplitN(line, ",", 2)
7d9f3d
 
7d9f3d
 			switch parts[0] {
7d9f3d
-			case "P-224":
7d9f3d
-				pub.Curve = elliptic.P224()
7d9f3d
 			case "P-256":
7d9f3d
 				pub.Curve = elliptic.P256()
7d9f3d
 			case "P-384":
7d9f3d
--- libgo/go/crypto/x509/x509.go.jj	2016-02-05 20:11:19.000000000 +0100
7d9f3d
+++ libgo/go/crypto/x509/x509.go	2016-02-05 22:36:06.147039294 +0100
7d9f3d
@@ -334,9 +334,6 @@ func getPublicKeyAlgorithmFromOID(oid as
7d9f3d
 
7d9f3d
 // RFC 5480, 2.1.1.1. Named Curve
7d9f3d
 //
7d9f3d
-// secp224r1 OBJECT IDENTIFIER ::= {
7d9f3d
-//   iso(1) identified-organization(3) certicom(132) curve(0) 33 }
7d9f3d
-//
7d9f3d
 // secp256r1 OBJECT IDENTIFIER ::= {
7d9f3d
 //   iso(1) member-body(2) us(840) ansi-X9-62(10045) curves(3)
7d9f3d
 //   prime(1) 7 }
7d9f3d
@@ -349,7 +346,6 @@ func getPublicKeyAlgorithmFromOID(oid as
7d9f3d
 //
7d9f3d
 // NB: secp256r1 is equivalent to prime256v1
7d9f3d
 var (
7d9f3d
-	oidNamedCurveP224 = asn1.ObjectIdentifier{1, 3, 132, 0, 33}
7d9f3d
 	oidNamedCurveP256 = asn1.ObjectIdentifier{1, 2, 840, 10045, 3, 1, 7}
7d9f3d
 	oidNamedCurveP384 = asn1.ObjectIdentifier{1, 3, 132, 0, 34}
7d9f3d
 	oidNamedCurveP521 = asn1.ObjectIdentifier{1, 3, 132, 0, 35}
7d9f3d
@@ -357,8 +353,6 @@ var (
7d9f3d
 
7d9f3d
 func namedCurveFromOID(oid asn1.ObjectIdentifier) elliptic.Curve {
7d9f3d
 	switch {
7d9f3d
-	case oid.Equal(oidNamedCurveP224):
7d9f3d
-		return elliptic.P224()
7d9f3d
 	case oid.Equal(oidNamedCurveP256):
7d9f3d
 		return elliptic.P256()
7d9f3d
 	case oid.Equal(oidNamedCurveP384):
7d9f3d
@@ -371,8 +365,6 @@ func namedCurveFromOID(oid asn1.ObjectId
7d9f3d
 
7d9f3d
 func oidFromNamedCurve(curve elliptic.Curve) (asn1.ObjectIdentifier, bool) {
7d9f3d
 	switch curve {
7d9f3d
-	case elliptic.P224():
7d9f3d
-		return oidNamedCurveP224, true
7d9f3d
 	case elliptic.P256():
7d9f3d
 		return oidNamedCurveP256, true
7d9f3d
 	case elliptic.P384():
7d9f3d
@@ -1502,7 +1494,7 @@ func signingParamsForPublicKey(pub inter
7d9f3d
 		pubType = ECDSA
7d9f3d
 
7d9f3d
 		switch pub.Curve {
7d9f3d
-		case elliptic.P224(), elliptic.P256():
7d9f3d
+		case elliptic.P256():
7d9f3d
 			hashFunc = crypto.SHA256
7d9f3d
 			sigAlgo.Algorithm = oidSignatureECDSAWithSHA256
7d9f3d
 		case elliptic.P384():
7d9f3d
--- libgo/go/crypto/elliptic/p224.go.jj	2016-01-15 10:58:09.000000000 +0100
7d9f3d
+++ libgo/go/crypto/elliptic/p224.go	2016-02-05 22:36:06.147039294 +0100
7d9f3d
@@ -1,765 +0,0 @@
7d9f3d
-// Copyright 2012 The Go Authors.  All rights reserved.
7d9f3d
-// Use of this source code is governed by a BSD-style
7d9f3d
-// license that can be found in the LICENSE file.
7d9f3d
-
7d9f3d
-package elliptic
7d9f3d
-
7d9f3d
-// This is a constant-time, 32-bit implementation of P224. See FIPS 186-3,
7d9f3d
-// section D.2.2.
7d9f3d
-//
7d9f3d
-// See http://www.imperialviolet.org/2010/12/04/ecc.html ([1]) for background.
7d9f3d
-
7d9f3d
-import (
7d9f3d
-	"math/big"
7d9f3d
-)
7d9f3d
-
7d9f3d
-var p224 p224Curve
7d9f3d
-
7d9f3d
-type p224Curve struct {
7d9f3d
-	*CurveParams
7d9f3d
-	gx, gy, b p224FieldElement
7d9f3d
-}
7d9f3d
-
7d9f3d
-func initP224() {
7d9f3d
-	// See FIPS 186-3, section D.2.2
7d9f3d
-	p224.CurveParams = &CurveParams{Name: "P-224"}
7d9f3d
-	p224.P, _ = new(big.Int).SetString("26959946667150639794667015087019630673557916260026308143510066298881", 10)
7d9f3d
-	p224.N, _ = new(big.Int).SetString("26959946667150639794667015087019625940457807714424391721682722368061", 10)
7d9f3d
-	p224.B, _ = new(big.Int).SetString("b4050a850c04b3abf54132565044b0b7d7bfd8ba270b39432355ffb4", 16)
7d9f3d
-	p224.Gx, _ = new(big.Int).SetString("b70e0cbd6bb4bf7f321390b94a03c1d356c21122343280d6115c1d21", 16)
7d9f3d
-	p224.Gy, _ = new(big.Int).SetString("bd376388b5f723fb4c22dfe6cd4375a05a07476444d5819985007e34", 16)
7d9f3d
-	p224.BitSize = 224
7d9f3d
-
7d9f3d
-	p224FromBig(&p224.gx, p224.Gx)
7d9f3d
-	p224FromBig(&p224.gy, p224.Gy)
7d9f3d
-	p224FromBig(&p224.b, p224.B)
7d9f3d
-}
7d9f3d
-
7d9f3d
-// P224 returns a Curve which implements P-224 (see FIPS 186-3, section D.2.2)
7d9f3d
-func P224() Curve {
7d9f3d
-	initonce.Do(initAll)
7d9f3d
-	return p224
7d9f3d
-}
7d9f3d
-
7d9f3d
-func (curve p224Curve) Params() *CurveParams {
7d9f3d
-	return curve.CurveParams
7d9f3d
-}
7d9f3d
-
7d9f3d
-func (curve p224Curve) IsOnCurve(bigX, bigY *big.Int) bool {
7d9f3d
-	var x, y p224FieldElement
7d9f3d
-	p224FromBig(&x, bigX)
7d9f3d
-	p224FromBig(&y, bigY)
7d9f3d
-
7d9f3d
-	// y² = x³ - 3x + b
7d9f3d
-	var tmp p224LargeFieldElement
7d9f3d
-	var x3 p224FieldElement
7d9f3d
-	p224Square(&x3, &x, &tmp)
7d9f3d
-	p224Mul(&x3, &x3, &x, &tmp)
7d9f3d
-
7d9f3d
-	for i := 0; i < 8; i++ {
7d9f3d
-		x[i] *= 3
7d9f3d
-	}
7d9f3d
-	p224Sub(&x3, &x3, &x)
7d9f3d
-	p224Reduce(&x3)
7d9f3d
-	p224Add(&x3, &x3, &curve.b)
7d9f3d
-	p224Contract(&x3, &x3)
7d9f3d
-
7d9f3d
-	p224Square(&y, &y, &tmp)
7d9f3d
-	p224Contract(&y, &y)
7d9f3d
-
7d9f3d
-	for i := 0; i < 8; i++ {
7d9f3d
-		if y[i] != x3[i] {
7d9f3d
-			return false
7d9f3d
-		}
7d9f3d
-	}
7d9f3d
-	return true
7d9f3d
-}
7d9f3d
-
7d9f3d
-func (p224Curve) Add(bigX1, bigY1, bigX2, bigY2 *big.Int) (x, y *big.Int) {
7d9f3d
-	var x1, y1, z1, x2, y2, z2, x3, y3, z3 p224FieldElement
7d9f3d
-
7d9f3d
-	p224FromBig(&x1, bigX1)
7d9f3d
-	p224FromBig(&y1, bigY1)
7d9f3d
-	if bigX1.Sign() != 0 || bigY1.Sign() != 0 {
7d9f3d
-		z1[0] = 1
7d9f3d
-	}
7d9f3d
-	p224FromBig(&x2, bigX2)
7d9f3d
-	p224FromBig(&y2, bigY2)
7d9f3d
-	if bigX2.Sign() != 0 || bigY2.Sign() != 0 {
7d9f3d
-		z2[0] = 1
7d9f3d
-	}
7d9f3d
-
7d9f3d
-	p224AddJacobian(&x3, &y3, &z3, &x1, &y1, &z1, &x2, &y2, &z2)
7d9f3d
-	return p224ToAffine(&x3, &y3, &z3)
7d9f3d
-}
7d9f3d
-
7d9f3d
-func (p224Curve) Double(bigX1, bigY1 *big.Int) (x, y *big.Int) {
7d9f3d
-	var x1, y1, z1, x2, y2, z2 p224FieldElement
7d9f3d
-
7d9f3d
-	p224FromBig(&x1, bigX1)
7d9f3d
-	p224FromBig(&y1, bigY1)
7d9f3d
-	z1[0] = 1
7d9f3d
-
7d9f3d
-	p224DoubleJacobian(&x2, &y2, &z2, &x1, &y1, &z1)
7d9f3d
-	return p224ToAffine(&x2, &y2, &z2)
7d9f3d
-}
7d9f3d
-
7d9f3d
-func (p224Curve) ScalarMult(bigX1, bigY1 *big.Int, scalar []byte) (x, y *big.Int) {
7d9f3d
-	var x1, y1, z1, x2, y2, z2 p224FieldElement
7d9f3d
-
7d9f3d
-	p224FromBig(&x1, bigX1)
7d9f3d
-	p224FromBig(&y1, bigY1)
7d9f3d
-	z1[0] = 1
7d9f3d
-
7d9f3d
-	p224ScalarMult(&x2, &y2, &z2, &x1, &y1, &z1, scalar)
7d9f3d
-	return p224ToAffine(&x2, &y2, &z2)
7d9f3d
-}
7d9f3d
-
7d9f3d
-func (curve p224Curve) ScalarBaseMult(scalar []byte) (x, y *big.Int) {
7d9f3d
-	var z1, x2, y2, z2 p224FieldElement
7d9f3d
-
7d9f3d
-	z1[0] = 1
7d9f3d
-	p224ScalarMult(&x2, &y2, &z2, &curve.gx, &curve.gy, &z1, scalar)
7d9f3d
-	return p224ToAffine(&x2, &y2, &z2)
7d9f3d
-}
7d9f3d
-
7d9f3d
-// Field element functions.
7d9f3d
-//
7d9f3d
-// The field that we're dealing with is ℤ/pℤ where p = 2**224 - 2**96 + 1.
7d9f3d
-//
7d9f3d
-// Field elements are represented by a FieldElement, which is a typedef to an
7d9f3d
-// array of 8 uint32's. The value of a FieldElement, a, is:
7d9f3d
-//   a[0] + 2**28·a[1] + 2**56·a[1] + ... + 2**196·a[7]
7d9f3d
-//
7d9f3d
-// Using 28-bit limbs means that there's only 4 bits of headroom, which is less
7d9f3d
-// than we would really like. But it has the useful feature that we hit 2**224
7d9f3d
-// exactly, making the reflections during a reduce much nicer.
7d9f3d
-type p224FieldElement [8]uint32
7d9f3d
-
7d9f3d
-// p224P is the order of the field, represented as a p224FieldElement.
7d9f3d
-var p224P = [8]uint32{1, 0, 0, 0xffff000, 0xfffffff, 0xfffffff, 0xfffffff, 0xfffffff}
7d9f3d
-
7d9f3d
-// p224IsZero returns 1 if a == 0 mod p and 0 otherwise.
7d9f3d
-//
7d9f3d
-// a[i] < 2**29
7d9f3d
-func p224IsZero(a *p224FieldElement) uint32 {
7d9f3d
-	// Since a p224FieldElement contains 224 bits there are two possible
7d9f3d
-	// representations of 0: 0 and p.
7d9f3d
-	var minimal p224FieldElement
7d9f3d
-	p224Contract(&minimal, a)
7d9f3d
-
7d9f3d
-	var isZero, isP uint32
7d9f3d
-	for i, v := range minimal {
7d9f3d
-		isZero |= v
7d9f3d
-		isP |= v - p224P[i]
7d9f3d
-	}
7d9f3d
-
7d9f3d
-	// If either isZero or isP is 0, then we should return 1.
7d9f3d
-	isZero |= isZero >> 16
7d9f3d
-	isZero |= isZero >> 8
7d9f3d
-	isZero |= isZero >> 4
7d9f3d
-	isZero |= isZero >> 2
7d9f3d
-	isZero |= isZero >> 1
7d9f3d
-
7d9f3d
-	isP |= isP >> 16
7d9f3d
-	isP |= isP >> 8
7d9f3d
-	isP |= isP >> 4
7d9f3d
-	isP |= isP >> 2
7d9f3d
-	isP |= isP >> 1
7d9f3d
-
7d9f3d
-	// For isZero and isP, the LSB is 0 iff all the bits are zero.
7d9f3d
-	result := isZero & isP
7d9f3d
-	result = (^result) & 1
7d9f3d
-
7d9f3d
-	return result
7d9f3d
-}
7d9f3d
-
7d9f3d
-// p224Add computes *out = a+b
7d9f3d
-//
7d9f3d
-// a[i] + b[i] < 2**32
7d9f3d
-func p224Add(out, a, b *p224FieldElement) {
7d9f3d
-	for i := 0; i < 8; i++ {
7d9f3d
-		out[i] = a[i] + b[i]
7d9f3d
-	}
7d9f3d
-}
7d9f3d
-
7d9f3d
-const two31p3 = 1<<31 + 1<<3
7d9f3d
-const two31m3 = 1<<31 - 1<<3
7d9f3d
-const two31m15m3 = 1<<31 - 1<<15 - 1<<3
7d9f3d
-
7d9f3d
-// p224ZeroModP31 is 0 mod p where bit 31 is set in all limbs so that we can
7d9f3d
-// subtract smaller amounts without underflow. See the section "Subtraction" in
7d9f3d
-// [1] for reasoning.
7d9f3d
-var p224ZeroModP31 = []uint32{two31p3, two31m3, two31m3, two31m15m3, two31m3, two31m3, two31m3, two31m3}
7d9f3d
-
7d9f3d
-// p224Sub computes *out = a-b
7d9f3d
-//
7d9f3d
-// a[i], b[i] < 2**30
7d9f3d
-// out[i] < 2**32
7d9f3d
-func p224Sub(out, a, b *p224FieldElement) {
7d9f3d
-	for i := 0; i < 8; i++ {
7d9f3d
-		out[i] = a[i] + p224ZeroModP31[i] - b[i]
7d9f3d
-	}
7d9f3d
-}
7d9f3d
-
7d9f3d
-// LargeFieldElement also represents an element of the field. The limbs are
7d9f3d
-// still spaced 28-bits apart and in little-endian order. So the limbs are at
7d9f3d
-// 0, 28, 56, ..., 392 bits, each 64-bits wide.
7d9f3d
-type p224LargeFieldElement [15]uint64
7d9f3d
-
7d9f3d
-const two63p35 = 1<<63 + 1<<35
7d9f3d
-const two63m35 = 1<<63 - 1<<35
7d9f3d
-const two63m35m19 = 1<<63 - 1<<35 - 1<<19
7d9f3d
-
7d9f3d
-// p224ZeroModP63 is 0 mod p where bit 63 is set in all limbs. See the section
7d9f3d
-// "Subtraction" in [1] for why.
7d9f3d
-var p224ZeroModP63 = [8]uint64{two63p35, two63m35, two63m35, two63m35, two63m35m19, two63m35, two63m35, two63m35}
7d9f3d
-
7d9f3d
-const bottom12Bits = 0xfff
7d9f3d
-const bottom28Bits = 0xfffffff
7d9f3d
-
7d9f3d
-// p224Mul computes *out = a*b
7d9f3d
-//
7d9f3d
-// a[i] < 2**29, b[i] < 2**30 (or vice versa)
7d9f3d
-// out[i] < 2**29
7d9f3d
-func p224Mul(out, a, b *p224FieldElement, tmp *p224LargeFieldElement) {
7d9f3d
-	for i := 0; i < 15; i++ {
7d9f3d
-		tmp[i] = 0
7d9f3d
-	}
7d9f3d
-
7d9f3d
-	for i := 0; i < 8; i++ {
7d9f3d
-		for j := 0; j < 8; j++ {
7d9f3d
-			tmp[i+j] += uint64(a[i]) * uint64(b[j])
7d9f3d
-		}
7d9f3d
-	}
7d9f3d
-
7d9f3d
-	p224ReduceLarge(out, tmp)
7d9f3d
-}
7d9f3d
-
7d9f3d
-// Square computes *out = a*a
7d9f3d
-//
7d9f3d
-// a[i] < 2**29
7d9f3d
-// out[i] < 2**29
7d9f3d
-func p224Square(out, a *p224FieldElement, tmp *p224LargeFieldElement) {
7d9f3d
-	for i := 0; i < 15; i++ {
7d9f3d
-		tmp[i] = 0
7d9f3d
-	}
7d9f3d
-
7d9f3d
-	for i := 0; i < 8; i++ {
7d9f3d
-		for j := 0; j <= i; j++ {
7d9f3d
-			r := uint64(a[i]) * uint64(a[j])
7d9f3d
-			if i == j {
7d9f3d
-				tmp[i+j] += r
7d9f3d
-			} else {
7d9f3d
-				tmp[i+j] += r << 1
7d9f3d
-			}
7d9f3d
-		}
7d9f3d
-	}
7d9f3d
-
7d9f3d
-	p224ReduceLarge(out, tmp)
7d9f3d
-}
7d9f3d
-
7d9f3d
-// ReduceLarge converts a p224LargeFieldElement to a p224FieldElement.
7d9f3d
-//
7d9f3d
-// in[i] < 2**62
7d9f3d
-func p224ReduceLarge(out *p224FieldElement, in *p224LargeFieldElement) {
7d9f3d
-	for i := 0; i < 8; i++ {
7d9f3d
-		in[i] += p224ZeroModP63[i]
7d9f3d
-	}
7d9f3d
-
7d9f3d
-	// Eliminate the coefficients at 2**224 and greater.
7d9f3d
-	for i := 14; i >= 8; i-- {
7d9f3d
-		in[i-8] -= in[i]
7d9f3d
-		in[i-5] += (in[i] & 0xffff) << 12
7d9f3d
-		in[i-4] += in[i] >> 16
7d9f3d
-	}
7d9f3d
-	in[8] = 0
7d9f3d
-	// in[0..8] < 2**64
7d9f3d
-
7d9f3d
-	// As the values become small enough, we start to store them in |out|
7d9f3d
-	// and use 32-bit operations.
7d9f3d
-	for i := 1; i < 8; i++ {
7d9f3d
-		in[i+1] += in[i] >> 28
7d9f3d
-		out[i] = uint32(in[i] & bottom28Bits)
7d9f3d
-	}
7d9f3d
-	in[0] -= in[8]
7d9f3d
-	out[3] += uint32(in[8]&0xffff) << 12
7d9f3d
-	out[4] += uint32(in[8] >> 16)
7d9f3d
-	// in[0] < 2**64
7d9f3d
-	// out[3] < 2**29
7d9f3d
-	// out[4] < 2**29
7d9f3d
-	// out[1,2,5..7] < 2**28
7d9f3d
-
7d9f3d
-	out[0] = uint32(in[0] & bottom28Bits)
7d9f3d
-	out[1] += uint32((in[0] >> 28) & bottom28Bits)
7d9f3d
-	out[2] += uint32(in[0] >> 56)
7d9f3d
-	// out[0] < 2**28
7d9f3d
-	// out[1..4] < 2**29
7d9f3d
-	// out[5..7] < 2**28
7d9f3d
-}
7d9f3d
-
7d9f3d
-// Reduce reduces the coefficients of a to smaller bounds.
7d9f3d
-//
7d9f3d
-// On entry: a[i] < 2**31 + 2**30
7d9f3d
-// On exit: a[i] < 2**29
7d9f3d
-func p224Reduce(a *p224FieldElement) {
7d9f3d
-	for i := 0; i < 7; i++ {
7d9f3d
-		a[i+1] += a[i] >> 28
7d9f3d
-		a[i] &= bottom28Bits
7d9f3d
-	}
7d9f3d
-	top := a[7] >> 28
7d9f3d
-	a[7] &= bottom28Bits
7d9f3d
-
7d9f3d
-	// top < 2**4
7d9f3d
-	mask := top
7d9f3d
-	mask |= mask >> 2
7d9f3d
-	mask |= mask >> 1
7d9f3d
-	mask <<= 31
7d9f3d
-	mask = uint32(int32(mask) >> 31)
7d9f3d
-	// Mask is all ones if top != 0, all zero otherwise
7d9f3d
-
7d9f3d
-	a[0] -= top
7d9f3d
-	a[3] += top << 12
7d9f3d
-
7d9f3d
-	// We may have just made a[0] negative but, if we did, then we must
7d9f3d
-	// have added something to a[3], this it's > 2**12. Therefore we can
7d9f3d
-	// carry down to a[0].
7d9f3d
-	a[3] -= 1 & mask
7d9f3d
-	a[2] += mask & (1<<28 - 1)
7d9f3d
-	a[1] += mask & (1<<28 - 1)
7d9f3d
-	a[0] += mask & (1 << 28)
7d9f3d
-}
7d9f3d
-
7d9f3d
-// p224Invert calculates *out = in**-1 by computing in**(2**224 - 2**96 - 1),
7d9f3d
-// i.e. Fermat's little theorem.
7d9f3d
-func p224Invert(out, in *p224FieldElement) {
7d9f3d
-	var f1, f2, f3, f4 p224FieldElement
7d9f3d
-	var c p224LargeFieldElement
7d9f3d
-
7d9f3d
-	p224Square(&f1, in, &c)    // 2
7d9f3d
-	p224Mul(&f1, &f1, in, &c)  // 2**2 - 1
7d9f3d
-	p224Square(&f1, &f1, &c)   // 2**3 - 2
7d9f3d
-	p224Mul(&f1, &f1, in, &c)  // 2**3 - 1
7d9f3d
-	p224Square(&f2, &f1, &c)   // 2**4 - 2
7d9f3d
-	p224Square(&f2, &f2, &c)   // 2**5 - 4
7d9f3d
-	p224Square(&f2, &f2, &c)   // 2**6 - 8
7d9f3d
-	p224Mul(&f1, &f1, &f2, &c) // 2**6 - 1
7d9f3d
-	p224Square(&f2, &f1, &c)   // 2**7 - 2
7d9f3d
-	for i := 0; i < 5; i++ {   // 2**12 - 2**6
7d9f3d
-		p224Square(&f2, &f2, &c)
7d9f3d
-	}
7d9f3d
-	p224Mul(&f2, &f2, &f1, &c) // 2**12 - 1
7d9f3d
-	p224Square(&f3, &f2, &c)   // 2**13 - 2
7d9f3d
-	for i := 0; i < 11; i++ {  // 2**24 - 2**12
7d9f3d
-		p224Square(&f3, &f3, &c)
7d9f3d
-	}
7d9f3d
-	p224Mul(&f2, &f3, &f2, &c) // 2**24 - 1
7d9f3d
-	p224Square(&f3, &f2, &c)   // 2**25 - 2
7d9f3d
-	for i := 0; i < 23; i++ {  // 2**48 - 2**24
7d9f3d
-		p224Square(&f3, &f3, &c)
7d9f3d
-	}
7d9f3d
-	p224Mul(&f3, &f3, &f2, &c) // 2**48 - 1
7d9f3d
-	p224Square(&f4, &f3, &c)   // 2**49 - 2
7d9f3d
-	for i := 0; i < 47; i++ {  // 2**96 - 2**48
7d9f3d
-		p224Square(&f4, &f4, &c)
7d9f3d
-	}
7d9f3d
-	p224Mul(&f3, &f3, &f4, &c) // 2**96 - 1
7d9f3d
-	p224Square(&f4, &f3, &c)   // 2**97 - 2
7d9f3d
-	for i := 0; i < 23; i++ {  // 2**120 - 2**24
7d9f3d
-		p224Square(&f4, &f4, &c)
7d9f3d
-	}
7d9f3d
-	p224Mul(&f2, &f4, &f2, &c) // 2**120 - 1
7d9f3d
-	for i := 0; i < 6; i++ {   // 2**126 - 2**6
7d9f3d
-		p224Square(&f2, &f2, &c)
7d9f3d
-	}
7d9f3d
-	p224Mul(&f1, &f1, &f2, &c) // 2**126 - 1
7d9f3d
-	p224Square(&f1, &f1, &c)   // 2**127 - 2
7d9f3d
-	p224Mul(&f1, &f1, in, &c)  // 2**127 - 1
7d9f3d
-	for i := 0; i < 97; i++ {  // 2**224 - 2**97
7d9f3d
-		p224Square(&f1, &f1, &c)
7d9f3d
-	}
7d9f3d
-	p224Mul(out, &f1, &f3, &c) // 2**224 - 2**96 - 1
7d9f3d
-}
7d9f3d
-
7d9f3d
-// p224Contract converts a FieldElement to its unique, minimal form.
7d9f3d
-//
7d9f3d
-// On entry, in[i] < 2**29
7d9f3d
-// On exit, in[i] < 2**28
7d9f3d
-func p224Contract(out, in *p224FieldElement) {
7d9f3d
-	copy(out[:], in[:])
7d9f3d
-
7d9f3d
-	for i := 0; i < 7; i++ {
7d9f3d
-		out[i+1] += out[i] >> 28
7d9f3d
-		out[i] &= bottom28Bits
7d9f3d
-	}
7d9f3d
-	top := out[7] >> 28
7d9f3d
-	out[7] &= bottom28Bits
7d9f3d
-
7d9f3d
-	out[0] -= top
7d9f3d
-	out[3] += top << 12
7d9f3d
-
7d9f3d
-	// We may just have made out[i] negative. So we carry down. If we made
7d9f3d
-	// out[0] negative then we know that out[3] is sufficiently positive
7d9f3d
-	// because we just added to it.
7d9f3d
-	for i := 0; i < 3; i++ {
7d9f3d
-		mask := uint32(int32(out[i]) >> 31)
7d9f3d
-		out[i] += (1 << 28) & mask
7d9f3d
-		out[i+1] -= 1 & mask
7d9f3d
-	}
7d9f3d
-
7d9f3d
-	// We might have pushed out[3] over 2**28 so we perform another, partial,
7d9f3d
-	// carry chain.
7d9f3d
-	for i := 3; i < 7; i++ {
7d9f3d
-		out[i+1] += out[i] >> 28
7d9f3d
-		out[i] &= bottom28Bits
7d9f3d
-	}
7d9f3d
-	top = out[7] >> 28
7d9f3d
-	out[7] &= bottom28Bits
7d9f3d
-
7d9f3d
-	// Eliminate top while maintaining the same value mod p.
7d9f3d
-	out[0] -= top
7d9f3d
-	out[3] += top << 12
7d9f3d
-
7d9f3d
-	// There are two cases to consider for out[3]:
7d9f3d
-	//   1) The first time that we eliminated top, we didn't push out[3] over
7d9f3d
-	//      2**28. In this case, the partial carry chain didn't change any values
7d9f3d
-	//      and top is zero.
7d9f3d
-	//   2) We did push out[3] over 2**28 the first time that we eliminated top.
7d9f3d
-	//      The first value of top was in [0..16), therefore, prior to eliminating
7d9f3d
-	//      the first top, 0xfff1000 <= out[3] <= 0xfffffff. Therefore, after
7d9f3d
-	//      overflowing and being reduced by the second carry chain, out[3] <=
7d9f3d
-	//      0xf000. Thus it cannot have overflowed when we eliminated top for the
7d9f3d
-	//      second time.
7d9f3d
-
7d9f3d
-	// Again, we may just have made out[0] negative, so do the same carry down.
7d9f3d
-	// As before, if we made out[0] negative then we know that out[3] is
7d9f3d
-	// sufficiently positive.
7d9f3d
-	for i := 0; i < 3; i++ {
7d9f3d
-		mask := uint32(int32(out[i]) >> 31)
7d9f3d
-		out[i] += (1 << 28) & mask
7d9f3d
-		out[i+1] -= 1 & mask
7d9f3d
-	}
7d9f3d
-
7d9f3d
-	// Now we see if the value is >= p and, if so, subtract p.
7d9f3d
-
7d9f3d
-	// First we build a mask from the top four limbs, which must all be
7d9f3d
-	// equal to bottom28Bits if the whole value is >= p. If top4AllOnes
7d9f3d
-	// ends up with any zero bits in the bottom 28 bits, then this wasn't
7d9f3d
-	// true.
7d9f3d
-	top4AllOnes := uint32(0xffffffff)
7d9f3d
-	for i := 4; i < 8; i++ {
7d9f3d
-		top4AllOnes &= out[i]
7d9f3d
-	}
7d9f3d
-	top4AllOnes |= 0xf0000000
7d9f3d
-	// Now we replicate any zero bits to all the bits in top4AllOnes.
7d9f3d
-	top4AllOnes &= top4AllOnes >> 16
7d9f3d
-	top4AllOnes &= top4AllOnes >> 8
7d9f3d
-	top4AllOnes &= top4AllOnes >> 4
7d9f3d
-	top4AllOnes &= top4AllOnes >> 2
7d9f3d
-	top4AllOnes &= top4AllOnes >> 1
7d9f3d
-	top4AllOnes = uint32(int32(top4AllOnes<<31) >> 31)
7d9f3d
-
7d9f3d
-	// Now we test whether the bottom three limbs are non-zero.
7d9f3d
-	bottom3NonZero := out[0] | out[1] | out[2]
7d9f3d
-	bottom3NonZero |= bottom3NonZero >> 16
7d9f3d
-	bottom3NonZero |= bottom3NonZero >> 8
7d9f3d
-	bottom3NonZero |= bottom3NonZero >> 4
7d9f3d
-	bottom3NonZero |= bottom3NonZero >> 2
7d9f3d
-	bottom3NonZero |= bottom3NonZero >> 1
7d9f3d
-	bottom3NonZero = uint32(int32(bottom3NonZero<<31) >> 31)
7d9f3d
-
7d9f3d
-	// Everything depends on the value of out[3].
7d9f3d
-	//    If it's > 0xffff000 and top4AllOnes != 0 then the whole value is >= p
7d9f3d
-	//    If it's = 0xffff000 and top4AllOnes != 0 and bottom3NonZero != 0,
7d9f3d
-	//      then the whole value is >= p
7d9f3d
-	//    If it's < 0xffff000, then the whole value is < p
7d9f3d
-	n := out[3] - 0xffff000
7d9f3d
-	out3Equal := n
7d9f3d
-	out3Equal |= out3Equal >> 16
7d9f3d
-	out3Equal |= out3Equal >> 8
7d9f3d
-	out3Equal |= out3Equal >> 4
7d9f3d
-	out3Equal |= out3Equal >> 2
7d9f3d
-	out3Equal |= out3Equal >> 1
7d9f3d
-	out3Equal = ^uint32(int32(out3Equal<<31) >> 31)
7d9f3d
-
7d9f3d
-	// If out[3] > 0xffff000 then n's MSB will be zero.
7d9f3d
-	out3GT := ^uint32(int32(n) >> 31)
7d9f3d
-
7d9f3d
-	mask := top4AllOnes & ((out3Equal & bottom3NonZero) | out3GT)
7d9f3d
-	out[0] -= 1 & mask
7d9f3d
-	out[3] -= 0xffff000 & mask
7d9f3d
-	out[4] -= 0xfffffff & mask
7d9f3d
-	out[5] -= 0xfffffff & mask
7d9f3d
-	out[6] -= 0xfffffff & mask
7d9f3d
-	out[7] -= 0xfffffff & mask
7d9f3d
-}
7d9f3d
-
7d9f3d
-// Group element functions.
7d9f3d
-//
7d9f3d
-// These functions deal with group elements. The group is an elliptic curve
7d9f3d
-// group with a = -3 defined in FIPS 186-3, section D.2.2.
7d9f3d
-
7d9f3d
-// p224AddJacobian computes *out = a+b where a != b.
7d9f3d
-func p224AddJacobian(x3, y3, z3, x1, y1, z1, x2, y2, z2 *p224FieldElement) {
7d9f3d
-	// See http://hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-3.html#addition-p224Add-2007-bl
7d9f3d
-	var z1z1, z2z2, u1, u2, s1, s2, h, i, j, r, v p224FieldElement
7d9f3d
-	var c p224LargeFieldElement
7d9f3d
-
7d9f3d
-	z1IsZero := p224IsZero(z1)
7d9f3d
-	z2IsZero := p224IsZero(z2)
7d9f3d
-
7d9f3d
-	// Z1Z1 = Z1²
7d9f3d
-	p224Square(&z1z1, z1, &c)
7d9f3d
-	// Z2Z2 = Z2²
7d9f3d
-	p224Square(&z2z2, z2, &c)
7d9f3d
-	// U1 = X1*Z2Z2
7d9f3d
-	p224Mul(&u1, x1, &z2z2, &c)
7d9f3d
-	// U2 = X2*Z1Z1
7d9f3d
-	p224Mul(&u2, x2, &z1z1, &c)
7d9f3d
-	// S1 = Y1*Z2*Z2Z2
7d9f3d
-	p224Mul(&s1, z2, &z2z2, &c)
7d9f3d
-	p224Mul(&s1, y1, &s1, &c)
7d9f3d
-	// S2 = Y2*Z1*Z1Z1
7d9f3d
-	p224Mul(&s2, z1, &z1z1, &c)
7d9f3d
-	p224Mul(&s2, y2, &s2, &c)
7d9f3d
-	// H = U2-U1
7d9f3d
-	p224Sub(&h, &u2, &u1)
7d9f3d
-	p224Reduce(&h)
7d9f3d
-	xEqual := p224IsZero(&h)
7d9f3d
-	// I = (2*H)²
7d9f3d
-	for j := 0; j < 8; j++ {
7d9f3d
-		i[j] = h[j] << 1
7d9f3d
-	}
7d9f3d
-	p224Reduce(&i)
7d9f3d
-	p224Square(&i, &i, &c)
7d9f3d
-	// J = H*I
7d9f3d
-	p224Mul(&j, &h, &i, &c)
7d9f3d
-	// r = 2*(S2-S1)
7d9f3d
-	p224Sub(&r, &s2, &s1)
7d9f3d
-	p224Reduce(&r)
7d9f3d
-	yEqual := p224IsZero(&r)
7d9f3d
-	if xEqual == 1 && yEqual == 1 && z1IsZero == 0 && z2IsZero == 0 {
7d9f3d
-		p224DoubleJacobian(x3, y3, z3, x1, y1, z1)
7d9f3d
-		return
7d9f3d
-	}
7d9f3d
-	for i := 0; i < 8; i++ {
7d9f3d
-		r[i] <<= 1
7d9f3d
-	}
7d9f3d
-	p224Reduce(&r)
7d9f3d
-	// V = U1*I
7d9f3d
-	p224Mul(&v, &u1, &i, &c)
7d9f3d
-	// Z3 = ((Z1+Z2)²-Z1Z1-Z2Z2)*H
7d9f3d
-	p224Add(&z1z1, &z1z1, &z2z2)
7d9f3d
-	p224Add(&z2z2, z1, z2)
7d9f3d
-	p224Reduce(&z2z2)
7d9f3d
-	p224Square(&z2z2, &z2z2, &c)
7d9f3d
-	p224Sub(z3, &z2z2, &z1z1)
7d9f3d
-	p224Reduce(z3)
7d9f3d
-	p224Mul(z3, z3, &h, &c)
7d9f3d
-	// X3 = r²-J-2*V
7d9f3d
-	for i := 0; i < 8; i++ {
7d9f3d
-		z1z1[i] = v[i] << 1
7d9f3d
-	}
7d9f3d
-	p224Add(&z1z1, &j, &z1z1)
7d9f3d
-	p224Reduce(&z1z1)
7d9f3d
-	p224Square(x3, &r, &c)
7d9f3d
-	p224Sub(x3, x3, &z1z1)
7d9f3d
-	p224Reduce(x3)
7d9f3d
-	// Y3 = r*(V-X3)-2*S1*J
7d9f3d
-	for i := 0; i < 8; i++ {
7d9f3d
-		s1[i] <<= 1
7d9f3d
-	}
7d9f3d
-	p224Mul(&s1, &s1, &j, &c)
7d9f3d
-	p224Sub(&z1z1, &v, x3)
7d9f3d
-	p224Reduce(&z1z1)
7d9f3d
-	p224Mul(&z1z1, &z1z1, &r, &c)
7d9f3d
-	p224Sub(y3, &z1z1, &s1)
7d9f3d
-	p224Reduce(y3)
7d9f3d
-
7d9f3d
-	p224CopyConditional(x3, x2, z1IsZero)
7d9f3d
-	p224CopyConditional(x3, x1, z2IsZero)
7d9f3d
-	p224CopyConditional(y3, y2, z1IsZero)
7d9f3d
-	p224CopyConditional(y3, y1, z2IsZero)
7d9f3d
-	p224CopyConditional(z3, z2, z1IsZero)
7d9f3d
-	p224CopyConditional(z3, z1, z2IsZero)
7d9f3d
-}
7d9f3d
-
7d9f3d
-// p224DoubleJacobian computes *out = a+a.
7d9f3d
-func p224DoubleJacobian(x3, y3, z3, x1, y1, z1 *p224FieldElement) {
7d9f3d
-	var delta, gamma, beta, alpha, t p224FieldElement
7d9f3d
-	var c p224LargeFieldElement
7d9f3d
-
7d9f3d
-	p224Square(&delta, z1, &c)
7d9f3d
-	p224Square(&gamma, y1, &c)
7d9f3d
-	p224Mul(&beta, x1, &gamma, &c)
7d9f3d
-
7d9f3d
-	// alpha = 3*(X1-delta)*(X1+delta)
7d9f3d
-	p224Add(&t, x1, &delta)
7d9f3d
-	for i := 0; i < 8; i++ {
7d9f3d
-		t[i] += t[i] << 1
7d9f3d
-	}
7d9f3d
-	p224Reduce(&t)
7d9f3d
-	p224Sub(&alpha, x1, &delta)
7d9f3d
-	p224Reduce(&alpha)
7d9f3d
-	p224Mul(&alpha, &alpha, &t, &c)
7d9f3d
-
7d9f3d
-	// Z3 = (Y1+Z1)²-gamma-delta
7d9f3d
-	p224Add(z3, y1, z1)
7d9f3d
-	p224Reduce(z3)
7d9f3d
-	p224Square(z3, z3, &c)
7d9f3d
-	p224Sub(z3, z3, &gamma)
7d9f3d
-	p224Reduce(z3)
7d9f3d
-	p224Sub(z3, z3, &delta)
7d9f3d
-	p224Reduce(z3)
7d9f3d
-
7d9f3d
-	// X3 = alpha²-8*beta
7d9f3d
-	for i := 0; i < 8; i++ {
7d9f3d
-		delta[i] = beta[i] << 3
7d9f3d
-	}
7d9f3d
-	p224Reduce(&delta)
7d9f3d
-	p224Square(x3, &alpha, &c)
7d9f3d
-	p224Sub(x3, x3, &delta)
7d9f3d
-	p224Reduce(x3)
7d9f3d
-
7d9f3d
-	// Y3 = alpha*(4*beta-X3)-8*gamma²
7d9f3d
-	for i := 0; i < 8; i++ {
7d9f3d
-		beta[i] <<= 2
7d9f3d
-	}
7d9f3d
-	p224Sub(&beta, &beta, x3)
7d9f3d
-	p224Reduce(&beta)
7d9f3d
-	p224Square(&gamma, &gamma, &c)
7d9f3d
-	for i := 0; i < 8; i++ {
7d9f3d
-		gamma[i] <<= 3
7d9f3d
-	}
7d9f3d
-	p224Reduce(&gamma)
7d9f3d
-	p224Mul(y3, &alpha, &beta, &c)
7d9f3d
-	p224Sub(y3, y3, &gamma)
7d9f3d
-	p224Reduce(y3)
7d9f3d
-}
7d9f3d
-
7d9f3d
-// p224CopyConditional sets *out = *in iff the least-significant-bit of control
7d9f3d
-// is true, and it runs in constant time.
7d9f3d
-func p224CopyConditional(out, in *p224FieldElement, control uint32) {
7d9f3d
-	control <<= 31
7d9f3d
-	control = uint32(int32(control) >> 31)
7d9f3d
-
7d9f3d
-	for i := 0; i < 8; i++ {
7d9f3d
-		out[i] ^= (out[i] ^ in[i]) & control
7d9f3d
-	}
7d9f3d
-}
7d9f3d
-
7d9f3d
-func p224ScalarMult(outX, outY, outZ, inX, inY, inZ *p224FieldElement, scalar []byte) {
7d9f3d
-	var xx, yy, zz p224FieldElement
7d9f3d
-	for i := 0; i < 8; i++ {
7d9f3d
-		outX[i] = 0
7d9f3d
-		outY[i] = 0
7d9f3d
-		outZ[i] = 0
7d9f3d
-	}
7d9f3d
-
7d9f3d
-	for _, byte := range scalar {
7d9f3d
-		for bitNum := uint(0); bitNum < 8; bitNum++ {
7d9f3d
-			p224DoubleJacobian(outX, outY, outZ, outX, outY, outZ)
7d9f3d
-			bit := uint32((byte >> (7 - bitNum)) & 1)
7d9f3d
-			p224AddJacobian(&xx, &yy, &zz, inX, inY, inZ, outX, outY, outZ)
7d9f3d
-			p224CopyConditional(outX, &xx, bit)
7d9f3d
-			p224CopyConditional(outY, &yy, bit)
7d9f3d
-			p224CopyConditional(outZ, &zz, bit)
7d9f3d
-		}
7d9f3d
-	}
7d9f3d
-}
7d9f3d
-
7d9f3d
-// p224ToAffine converts from Jacobian to affine form.
7d9f3d
-func p224ToAffine(x, y, z *p224FieldElement) (*big.Int, *big.Int) {
7d9f3d
-	var zinv, zinvsq, outx, outy p224FieldElement
7d9f3d
-	var tmp p224LargeFieldElement
7d9f3d
-
7d9f3d
-	if isPointAtInfinity := p224IsZero(z); isPointAtInfinity == 1 {
7d9f3d
-		return new(big.Int), new(big.Int)
7d9f3d
-	}
7d9f3d
-
7d9f3d
-	p224Invert(&zinv, z)
7d9f3d
-	p224Square(&zinvsq, &zinv, &tmp)
7d9f3d
-	p224Mul(x, x, &zinvsq, &tmp)
7d9f3d
-	p224Mul(&zinvsq, &zinvsq, &zinv, &tmp)
7d9f3d
-	p224Mul(y, y, &zinvsq, &tmp)
7d9f3d
-
7d9f3d
-	p224Contract(&outx, x)
7d9f3d
-	p224Contract(&outy, y)
7d9f3d
-	return p224ToBig(&outx), p224ToBig(&outy)
7d9f3d
-}
7d9f3d
-
7d9f3d
-// get28BitsFromEnd returns the least-significant 28 bits from buf>>shift,
7d9f3d
-// where buf is interpreted as a big-endian number.
7d9f3d
-func get28BitsFromEnd(buf []byte, shift uint) (uint32, []byte) {
7d9f3d
-	var ret uint32
7d9f3d
-
7d9f3d
-	for i := uint(0); i < 4; i++ {
7d9f3d
-		var b byte
7d9f3d
-		if l := len(buf); l > 0 {
7d9f3d
-			b = buf[l-1]
7d9f3d
-			// We don't remove the byte if we're about to return and we're not
7d9f3d
-			// reading all of it.
7d9f3d
-			if i != 3 || shift == 4 {
7d9f3d
-				buf = buf[:l-1]
7d9f3d
-			}
7d9f3d
-		}
7d9f3d
-		ret |= uint32(b) << (8 * i) >> shift
7d9f3d
-	}
7d9f3d
-	ret &= bottom28Bits
7d9f3d
-	return ret, buf
7d9f3d
-}
7d9f3d
-
7d9f3d
-// p224FromBig sets *out = *in.
7d9f3d
-func p224FromBig(out *p224FieldElement, in *big.Int) {
7d9f3d
-	bytes := in.Bytes()
7d9f3d
-	out[0], bytes = get28BitsFromEnd(bytes, 0)
7d9f3d
-	out[1], bytes = get28BitsFromEnd(bytes, 4)
7d9f3d
-	out[2], bytes = get28BitsFromEnd(bytes, 0)
7d9f3d
-	out[3], bytes = get28BitsFromEnd(bytes, 4)
7d9f3d
-	out[4], bytes = get28BitsFromEnd(bytes, 0)
7d9f3d
-	out[5], bytes = get28BitsFromEnd(bytes, 4)
7d9f3d
-	out[6], bytes = get28BitsFromEnd(bytes, 0)
7d9f3d
-	out[7], bytes = get28BitsFromEnd(bytes, 4)
7d9f3d
-}
7d9f3d
-
7d9f3d
-// p224ToBig returns in as a big.Int.
7d9f3d
-func p224ToBig(in *p224FieldElement) *big.Int {
7d9f3d
-	var buf [28]byte
7d9f3d
-	buf[27] = byte(in[0])
7d9f3d
-	buf[26] = byte(in[0] >> 8)
7d9f3d
-	buf[25] = byte(in[0] >> 16)
7d9f3d
-	buf[24] = byte(((in[0] >> 24) & 0x0f) | (in[1]<<4)&0xf0)
7d9f3d
-
7d9f3d
-	buf[23] = byte(in[1] >> 4)
7d9f3d
-	buf[22] = byte(in[1] >> 12)
7d9f3d
-	buf[21] = byte(in[1] >> 20)
7d9f3d
-
7d9f3d
-	buf[20] = byte(in[2])
7d9f3d
-	buf[19] = byte(in[2] >> 8)
7d9f3d
-	buf[18] = byte(in[2] >> 16)
7d9f3d
-	buf[17] = byte(((in[2] >> 24) & 0x0f) | (in[3]<<4)&0xf0)
7d9f3d
-
7d9f3d
-	buf[16] = byte(in[3] >> 4)
7d9f3d
-	buf[15] = byte(in[3] >> 12)
7d9f3d
-	buf[14] = byte(in[3] >> 20)
7d9f3d
-
7d9f3d
-	buf[13] = byte(in[4])
7d9f3d
-	buf[12] = byte(in[4] >> 8)
7d9f3d
-	buf[11] = byte(in[4] >> 16)
7d9f3d
-	buf[10] = byte(((in[4] >> 24) & 0x0f) | (in[5]<<4)&0xf0)
7d9f3d
-
7d9f3d
-	buf[9] = byte(in[5] >> 4)
7d9f3d
-	buf[8] = byte(in[5] >> 12)
7d9f3d
-	buf[7] = byte(in[5] >> 20)
7d9f3d
-
7d9f3d
-	buf[6] = byte(in[6])
7d9f3d
-	buf[5] = byte(in[6] >> 8)
7d9f3d
-	buf[4] = byte(in[6] >> 16)
7d9f3d
-	buf[3] = byte(((in[6] >> 24) & 0x0f) | (in[7]<<4)&0xf0)
7d9f3d
-
7d9f3d
-	buf[2] = byte(in[7] >> 4)
7d9f3d
-	buf[1] = byte(in[7] >> 12)
7d9f3d
-	buf[0] = byte(in[7] >> 20)
7d9f3d
-
7d9f3d
-	return new(big.Int).SetBytes(buf[:])
7d9f3d
-}
7d9f3d
--- libgo/go/crypto/elliptic/p224_test.go.jj	2016-01-15 10:58:09.000000000 +0100
7d9f3d
+++ libgo/go/crypto/elliptic/p224_test.go	2016-02-05 22:36:06.148039280 +0100
7d9f3d
@@ -1,47 +0,0 @@
7d9f3d
-// Copyright 2012 The Go Authors.  All rights reserved.
7d9f3d
-// Use of this source code is governed by a BSD-style
7d9f3d
-// license that can be found in the LICENSE file.
7d9f3d
-
7d9f3d
-package elliptic
7d9f3d
-
7d9f3d
-import (
7d9f3d
-	"math/big"
7d9f3d
-	"testing"
7d9f3d
-)
7d9f3d
-
7d9f3d
-var toFromBigTests = []string{
7d9f3d
-	"0",
7d9f3d
-	"1",
7d9f3d
-	"23",
7d9f3d
-	"b70e0cb46bb4bf7f321390b94a03c1d356c01122343280d6105c1d21",
7d9f3d
-	"706a46d476dcb76798e6046d89474788d164c18032d268fd10704fa6",
7d9f3d
-}
7d9f3d
-
7d9f3d
-func p224AlternativeToBig(in *p224FieldElement) *big.Int {
7d9f3d
-	ret := new(big.Int)
7d9f3d
-	tmp := new(big.Int)
7d9f3d
-
7d9f3d
-	for i := uint(0); i < 8; i++ {
7d9f3d
-		tmp.SetInt64(int64(in[i]))
7d9f3d
-		tmp.Lsh(tmp, 28*i)
7d9f3d
-		ret.Add(ret, tmp)
7d9f3d
-	}
7d9f3d
-	ret.Mod(ret, p224.P)
7d9f3d
-	return ret
7d9f3d
-}
7d9f3d
-
7d9f3d
-func TestToFromBig(t *testing.T) {
7d9f3d
-	for i, test := range toFromBigTests {
7d9f3d
-		n, _ := new(big.Int).SetString(test, 16)
7d9f3d
-		var x p224FieldElement
7d9f3d
-		p224FromBig(&x, n)
7d9f3d
-		m := p224ToBig(&x)
7d9f3d
-		if n.Cmp(m) != 0 {
7d9f3d
-			t.Errorf("#%d: %x != %x", i, n, m)
7d9f3d
-		}
7d9f3d
-		q := p224AlternativeToBig(&x)
7d9f3d
-		if n.Cmp(q) != 0 {
7d9f3d
-			t.Errorf("#%d: %x != %x (alternative)", i, n, m)
7d9f3d
-		}
7d9f3d
-	}
7d9f3d
-}
7d9f3d
--- libgo/go/crypto/elliptic/p256.go.jj	2016-02-05 20:11:19.000000000 +0100
7d9f3d
+++ libgo/go/crypto/elliptic/p256.go	2016-02-05 22:36:06.148039280 +0100
7d9f3d
@@ -235,6 +235,8 @@ func p256ReduceCarry(inout *[p256Limbs]u
7d9f3d
 	inout[7] += carry << 25
7d9f3d
 }
7d9f3d
 
7d9f3d
+const bottom28Bits = 0xfffffff
7d9f3d
+
7d9f3d
 // p256Sum sets out = in+in2.
7d9f3d
 //
7d9f3d
 // On entry, in[i]+in2[i] must not overflow a 32-bit word.
7d9f3d
@@ -267,6 +269,7 @@ const (
7d9f3d
 	two31m2    = 1<<31 - 1<<2
7d9f3d
 	two31p24m2 = 1<<31 + 1<<24 - 1<<2
7d9f3d
 	two30m27m2 = 1<<30 - 1<<27 - 1<<2
7d9f3d
+	two31m3    = 1<<31 - 1<<3
7d9f3d
 )
7d9f3d
 
7d9f3d
 // p256Zero31 is 0 mod p.