hughesjr / rpms / golang

Forked from rpms/golang 5 years ago
Clone

Blame SOURCES/golang-1.2-remove-ECC-p224.patch

e1de19
commit f8eb1e50541c8a9e55545d7470dbeab96073a632
e1de19
Author: Vincent Batts <vbatts@hashbangbash.com>
e1de19
Date:   Thu Jul 16 11:38:45 2015 -0400
e1de19
e1de19
    p224
e1de19
e1de19
diff --git a/api/go1.txt b/api/go1.txt
e1de19
index 5e3dea5..1a1ee83 100644
e1de19
--- a/api/go1.txt
e1de19
+++ b/api/go1.txt
e1de19
@@ -412,7 +412,6 @@ pkg crypto/ecdsa, type PublicKey struct, Y *big.Int
4d1d36
 pkg crypto/ecdsa, type PublicKey struct, embedded elliptic.Curve
4d1d36
 pkg crypto/elliptic, func GenerateKey(Curve, io.Reader) ([]uint8, *big.Int, *big.Int, error)
4d1d36
 pkg crypto/elliptic, func Marshal(Curve, *big.Int, *big.Int) []uint8
4d1d36
-pkg crypto/elliptic, func P224() Curve
4d1d36
 pkg crypto/elliptic, func P256() Curve
4d1d36
 pkg crypto/elliptic, func P384() Curve
4d1d36
 pkg crypto/elliptic, func P521() Curve
e1de19
diff --git a/src/crypto/ecdsa/ecdsa_test.go b/src/crypto/ecdsa/ecdsa_test.go
e1de19
index 169944d..c653464 100644
e1de19
--- a/src/crypto/ecdsa/ecdsa_test.go
e1de19
+++ b/src/crypto/ecdsa/ecdsa_test.go
e1de19
@@ -33,11 +33,10 @@ func testKeyGeneration(t *testing.T, c elliptic.Curve, tag string) {
4d1d36
 }
4d1d36
 
4d1d36
 func TestKeyGeneration(t *testing.T) {
4d1d36
-	testKeyGeneration(t, elliptic.P224(), "p224")
e1de19
+	testKeyGeneration(t, elliptic.P256(), "p256")
4d1d36
 	if testing.Short() {
4d1d36
 		return
4d1d36
 	}
e1de19
-	testKeyGeneration(t, elliptic.P256(), "p256")
e1de19
 	testKeyGeneration(t, elliptic.P384(), "p384")
e1de19
 	testKeyGeneration(t, elliptic.P521(), "p521")
e1de19
 }
e1de19
@@ -63,11 +62,10 @@ func testSignAndVerify(t *testing.T, c elliptic.Curve, tag string) {
4d1d36
 }
4d1d36
 
4d1d36
 func TestSignAndVerify(t *testing.T) {
4d1d36
-	testSignAndVerify(t, elliptic.P224(), "p224")
e1de19
+	testSignAndVerify(t, elliptic.P256(), "p256")
e1de19
 	if testing.Short() {
e1de19
 		return
e1de19
 	}
e1de19
-	testSignAndVerify(t, elliptic.P256(), "p256")
e1de19
 	testSignAndVerify(t, elliptic.P384(), "p384")
e1de19
 	testSignAndVerify(t, elliptic.P521(), "p521")
e1de19
 }
e1de19
@@ -100,11 +98,10 @@ func testNonceSafety(t *testing.T, c elliptic.Curve, tag string) {
e1de19
 }
e1de19
 
e1de19
 func TestNonceSafety(t *testing.T) {
e1de19
-	testNonceSafety(t, elliptic.P224(), "p224")
e1de19
+	testNonceSafety(t, elliptic.P256(), "p256")
e1de19
 	if testing.Short() {
e1de19
 		return
e1de19
 	}
e1de19
-	testNonceSafety(t, elliptic.P256(), "p256")
e1de19
 	testNonceSafety(t, elliptic.P384(), "p384")
e1de19
 	testNonceSafety(t, elliptic.P521(), "p521")
e1de19
 }
e1de19
@@ -135,11 +132,10 @@ func testINDCCA(t *testing.T, c elliptic.Curve, tag string) {
e1de19
 }
e1de19
 
e1de19
 func TestINDCCA(t *testing.T) {
e1de19
-	testINDCCA(t, elliptic.P224(), "p224")
e1de19
+	testINDCCA(t, elliptic.P256(), "p256")
4d1d36
 	if testing.Short() {
4d1d36
 		return
4d1d36
 	}
e1de19
-	testINDCCA(t, elliptic.P256(), "p256")
e1de19
 	testINDCCA(t, elliptic.P384(), "p384")
e1de19
 	testINDCCA(t, elliptic.P521(), "p521")
e1de19
 }
e1de19
@@ -201,8 +197,6 @@ func TestVectors(t *testing.T) {
4d1d36
 			parts := strings.SplitN(line, ",", 2)
4d1d36
 
4d1d36
 			switch parts[0] {
4d1d36
-			case "P-224":
4d1d36
-				pub.Curve = elliptic.P224()
4d1d36
 			case "P-256":
4d1d36
 				pub.Curve = elliptic.P256()
4d1d36
 			case "P-384":
e1de19
diff --git a/src/crypto/elliptic/bottombits.go b/src/crypto/elliptic/bottombits.go
e1de19
new file mode 100644
e1de19
index 0000000..4544722
9b5743
--- /dev/null
e1de19
+++ b/src/crypto/elliptic/bottombits.go
e1de19
@@ -0,0 +1,4 @@
4d1d36
+package elliptic
4d1d36
+
4d1d36
+const bottom28Bits = 0xfffffff
4d1d36
+const two31m3 = 1<<31 - 1<<3
e1de19
diff --git a/src/crypto/elliptic/elliptic.go b/src/crypto/elliptic/elliptic.go
e1de19
index f3b84e1..ca0b7cf 100644
e1de19
--- a/src/crypto/elliptic/elliptic.go
e1de19
+++ b/src/crypto/elliptic/elliptic.go
e1de19
@@ -331,7 +331,6 @@ var p384 *CurveParams
4d1d36
 var p521 *CurveParams
4d1d36
 
4d1d36
 func initAll() {
4d1d36
-	initP224()
4d1d36
 	initP256()
4d1d36
 	initP384()
4d1d36
 	initP521()
e1de19
diff --git a/src/crypto/elliptic/elliptic_test.go b/src/crypto/elliptic/elliptic_test.go
e1de19
index 7e27913..e0034fc 100644
e1de19
--- a/src/crypto/elliptic/elliptic_test.go
e1de19
+++ b/src/crypto/elliptic/elliptic_test.go
e1de19
@@ -6,27 +6,25 @@ package elliptic
e1de19
 
e1de19
 import (
e1de19
 	"crypto/rand"
e1de19
-	"encoding/hex"
e1de19
-	"fmt"
e1de19
 	"math/big"
e1de19
 	"testing"
e1de19
 )
e1de19
 
e1de19
 func TestOnCurve(t *testing.T) {
e1de19
-	p224 := P224()
e1de19
-	if !p224.IsOnCurve(p224.Params().Gx, p224.Params().Gy) {
e1de19
+	p256 := P256()
e1de19
+	if !p256.IsOnCurve(p256.Params().Gx, p256.Params().Gy) {
e1de19
 		t.Errorf("FAIL")
4d1d36
 	}
4d1d36
 }
4d1d36
 
e1de19
 func TestOffCurve(t *testing.T) {
e1de19
-	p224 := P224()
e1de19
+	p256 := P256()
e1de19
 	x, y := new(big.Int).SetInt64(1), new(big.Int).SetInt64(1)
e1de19
-	if p224.IsOnCurve(x, y) {
e1de19
+	if p256.IsOnCurve(x, y) {
e1de19
 		t.Errorf("FAIL: point off curve is claimed to be on the curve")
e1de19
 	}
e1de19
-	b := Marshal(p224, x, y)
e1de19
-	x1, y1 := Unmarshal(p224, b)
e1de19
+	b := Marshal(p256, x, y)
e1de19
+	x1, y1 := Unmarshal(p256, b)
e1de19
 	if x1 != nil || y1 != nil {
e1de19
 		t.Errorf("FAIL: unmarshalling a point not on the curve succeeded")
e1de19
 	}
e1de19
@@ -37,7 +35,7 @@ type baseMultTest struct {
e1de19
 	x, y string
e1de19
 }
e1de19
 
e1de19
-var p224BaseMultTests = []baseMultTest{
e1de19
+var p256BaseMultTests = []baseMultTest{
e1de19
 	{
e1de19
 		"1",
e1de19
 		"b70e0cbd6bb4bf7f321390b94a03c1d356c21122343280d6115c1d21",
e1de19
@@ -300,47 +298,12 @@ var p224BaseMultTests = []baseMultTest{
e1de19
 	},
e1de19
 }
e1de19
 
e1de19
-func TestBaseMult(t *testing.T) {
e1de19
-	p224 := P224()
e1de19
-	for i, e := range p224BaseMultTests {
e1de19
-		k, ok := new(big.Int).SetString(e.k, 10)
e1de19
-		if !ok {
e1de19
-			t.Errorf("%d: bad value for k: %s", i, e.k)
e1de19
-		}
e1de19
-		x, y := p224.ScalarBaseMult(k.Bytes())
e1de19
-		if fmt.Sprintf("%x", x) != e.x || fmt.Sprintf("%x", y) != e.y {
e1de19
-			t.Errorf("%d: bad output for k=%s: got (%x, %x), want (%s, %s)", i, e.k, x, y, e.x, e.y)
e1de19
-		}
e1de19
-		if testing.Short() && i > 5 {
e1de19
-			break
e1de19
-		}
e1de19
-	}
e1de19
-}
e1de19
-
e1de19
-func TestGenericBaseMult(t *testing.T) {
e1de19
-	// We use the P224 CurveParams directly in order to test the generic implementation.
e1de19
-	p224 := P224().Params()
e1de19
-	for i, e := range p224BaseMultTests {
e1de19
-		k, ok := new(big.Int).SetString(e.k, 10)
e1de19
-		if !ok {
e1de19
-			t.Errorf("%d: bad value for k: %s", i, e.k)
e1de19
-		}
e1de19
-		x, y := p224.ScalarBaseMult(k.Bytes())
e1de19
-		if fmt.Sprintf("%x", x) != e.x || fmt.Sprintf("%x", y) != e.y {
e1de19
-			t.Errorf("%d: bad output for k=%s: got (%x, %x), want (%s, %s)", i, e.k, x, y, e.x, e.y)
e1de19
-		}
e1de19
-		if testing.Short() && i > 5 {
e1de19
-			break
e1de19
-		}
e1de19
-	}
e1de19
-}
e1de19
-
e1de19
 func TestP256BaseMult(t *testing.T) {
e1de19
 	p256 := P256()
e1de19
 	p256Generic := p256.Params()
e1de19
 
e1de19
-	scalars := make([]*big.Int, 0, len(p224BaseMultTests)+1)
e1de19
-	for _, e := range p224BaseMultTests {
e1de19
+	scalars := make([]*big.Int, 0, len(p256BaseMultTests)+1)
e1de19
+	for _, e := range p256BaseMultTests {
e1de19
 		k, _ := new(big.Int).SetString(e.k, 10)
e1de19
 		scalars = append(scalars, k)
e1de19
 	}
e1de19
@@ -365,7 +328,7 @@ func TestP256Mult(t *testing.T) {
e1de19
 	p256 := P256()
e1de19
 	p256Generic := p256.Params()
e1de19
 
e1de19
-	for i, e := range p224BaseMultTests {
e1de19
+	for i, e := range p256BaseMultTests {
e1de19
 		x, _ := new(big.Int).SetString(e.x, 16)
e1de19
 		y, _ := new(big.Int).SetString(e.y, 16)
e1de19
 		k, _ := new(big.Int).SetString(e.k, 10)
e1de19
@@ -386,7 +349,6 @@ func TestInfinity(t *testing.T) {
e1de19
 		name  string
e1de19
 		curve Curve
e1de19
 	}{
e1de19
-		{"p224", P224()},
e1de19
 		{"p256", P256()},
e1de19
 	}
e1de19
 
e1de19
@@ -419,21 +381,10 @@ func TestInfinity(t *testing.T) {
e1de19
 	}
e1de19
 }
e1de19
 
e1de19
-func BenchmarkBaseMult(b *testing.B) {
e1de19
-	b.ResetTimer()
e1de19
-	p224 := P224()
e1de19
-	e := p224BaseMultTests[25]
e1de19
-	k, _ := new(big.Int).SetString(e.k, 10)
e1de19
-	b.StartTimer()
e1de19
-	for i := 0; i < b.N; i++ {
e1de19
-		p224.ScalarBaseMult(k.Bytes())
e1de19
-	}
e1de19
-}
e1de19
-
e1de19
 func BenchmarkBaseMultP256(b *testing.B) {
e1de19
 	b.ResetTimer()
e1de19
 	p256 := P256()
e1de19
-	e := p224BaseMultTests[25]
e1de19
+	e := p256BaseMultTests[25]
e1de19
 	k, _ := new(big.Int).SetString(e.k, 10)
e1de19
 	b.StartTimer()
e1de19
 	for i := 0; i < b.N; i++ {
e1de19
@@ -442,14 +393,14 @@ func BenchmarkBaseMultP256(b *testing.B) {
e1de19
 }
e1de19
 
e1de19
 func TestMarshal(t *testing.T) {
e1de19
-	p224 := P224()
e1de19
-	_, x, y, err := GenerateKey(p224, rand.Reader)
e1de19
+	p256 := P256()
e1de19
+	_, x, y, err := GenerateKey(p256, rand.Reader)
e1de19
 	if err != nil {
e1de19
 		t.Error(err)
e1de19
 		return
e1de19
 	}
e1de19
-	serialized := Marshal(p224, x, y)
e1de19
-	xx, yy := Unmarshal(p224, serialized)
e1de19
+	serialized := Marshal(p256, x, y)
e1de19
+	xx, yy := Unmarshal(p256, serialized)
e1de19
 	if xx == nil {
e1de19
 		t.Error("failed to unmarshal")
e1de19
 		return
e1de19
@@ -459,13 +410,3 @@ func TestMarshal(t *testing.T) {
e1de19
 		return
e1de19
 	}
e1de19
 }
e1de19
-
e1de19
-func TestP224Overflow(t *testing.T) {
e1de19
-	// This tests for a specific bug in the P224 implementation.
e1de19
-	p224 := P224()
e1de19
-	pointData, _ := hex.DecodeString("049B535B45FB0A2072398A6831834624C7E32CCFD5A4B933BCEAF77F1DD945E08BBE5178F5EDF5E733388F196D2A631D2E075BB16CBFEEA15B")
e1de19
-	x, y := Unmarshal(p224, pointData)
e1de19
-	if !p224.IsOnCurve(x, y) {
e1de19
-		t.Error("P224 failed to validate a correct point")
e1de19
-	}
e1de19
-}
e1de19
diff --git a/src/crypto/elliptic/p224.go b/src/crypto/elliptic/p224.go
e1de19
deleted file mode 100644
e1de19
index 2d3fac7..0000000
e1de19
--- a/src/crypto/elliptic/p224.go
e1de19
+++ /dev/null
e1de19
@@ -1,765 +0,0 @@
e1de19
-// Copyright 2012 The Go Authors.  All rights reserved.
e1de19
-// Use of this source code is governed by a BSD-style
e1de19
-// license that can be found in the LICENSE file.
e1de19
-
e1de19
-package elliptic
e1de19
-
e1de19
-// This is a constant-time, 32-bit implementation of P224. See FIPS 186-3,
e1de19
-// section D.2.2.
e1de19
-//
e1de19
-// See http://www.imperialviolet.org/2010/12/04/ecc.html ([1]) for background.
e1de19
-
e1de19
-import (
e1de19
-	"math/big"
e1de19
-)
e1de19
-
e1de19
-var p224 p224Curve
e1de19
-
e1de19
-type p224Curve struct {
e1de19
-	*CurveParams
e1de19
-	gx, gy, b p224FieldElement
e1de19
-}
e1de19
-
e1de19
-func initP224() {
e1de19
-	// See FIPS 186-3, section D.2.2
e1de19
-	p224.CurveParams = &CurveParams{Name: "P-224"}
e1de19
-	p224.P, _ = new(big.Int).SetString("26959946667150639794667015087019630673557916260026308143510066298881", 10)
e1de19
-	p224.N, _ = new(big.Int).SetString("26959946667150639794667015087019625940457807714424391721682722368061", 10)
e1de19
-	p224.B, _ = new(big.Int).SetString("b4050a850c04b3abf54132565044b0b7d7bfd8ba270b39432355ffb4", 16)
e1de19
-	p224.Gx, _ = new(big.Int).SetString("b70e0cbd6bb4bf7f321390b94a03c1d356c21122343280d6115c1d21", 16)
e1de19
-	p224.Gy, _ = new(big.Int).SetString("bd376388b5f723fb4c22dfe6cd4375a05a07476444d5819985007e34", 16)
e1de19
-	p224.BitSize = 224
e1de19
-
e1de19
-	p224FromBig(&p224.gx, p224.Gx)
e1de19
-	p224FromBig(&p224.gy, p224.Gy)
e1de19
-	p224FromBig(&p224.b, p224.B)
e1de19
-}
e1de19
-
e1de19
-// P224 returns a Curve which implements P-224 (see FIPS 186-3, section D.2.2)
e1de19
-func P224() Curve {
e1de19
-	initonce.Do(initAll)
e1de19
-	return p224
e1de19
-}
e1de19
-
e1de19
-func (curve p224Curve) Params() *CurveParams {
e1de19
-	return curve.CurveParams
e1de19
-}
e1de19
-
e1de19
-func (curve p224Curve) IsOnCurve(bigX, bigY *big.Int) bool {
e1de19
-	var x, y p224FieldElement
e1de19
-	p224FromBig(&x, bigX)
e1de19
-	p224FromBig(&y, bigY)
e1de19
-
e1de19
-	// y² = x³ - 3x + b
e1de19
-	var tmp p224LargeFieldElement
e1de19
-	var x3 p224FieldElement
e1de19
-	p224Square(&x3, &x, &tmp)
e1de19
-	p224Mul(&x3, &x3, &x, &tmp)
e1de19
-
e1de19
-	for i := 0; i < 8; i++ {
e1de19
-		x[i] *= 3
e1de19
-	}
e1de19
-	p224Sub(&x3, &x3, &x)
e1de19
-	p224Reduce(&x3)
e1de19
-	p224Add(&x3, &x3, &curve.b)
e1de19
-	p224Contract(&x3, &x3)
e1de19
-
e1de19
-	p224Square(&y, &y, &tmp)
e1de19
-	p224Contract(&y, &y)
e1de19
-
e1de19
-	for i := 0; i < 8; i++ {
e1de19
-		if y[i] != x3[i] {
e1de19
-			return false
e1de19
-		}
e1de19
-	}
e1de19
-	return true
e1de19
-}
e1de19
-
e1de19
-func (p224Curve) Add(bigX1, bigY1, bigX2, bigY2 *big.Int) (x, y *big.Int) {
e1de19
-	var x1, y1, z1, x2, y2, z2, x3, y3, z3 p224FieldElement
e1de19
-
e1de19
-	p224FromBig(&x1, bigX1)
e1de19
-	p224FromBig(&y1, bigY1)
e1de19
-	if bigX1.Sign() != 0 || bigY1.Sign() != 0 {
e1de19
-		z1[0] = 1
e1de19
-	}
e1de19
-	p224FromBig(&x2, bigX2)
e1de19
-	p224FromBig(&y2, bigY2)
e1de19
-	if bigX2.Sign() != 0 || bigY2.Sign() != 0 {
e1de19
-		z2[0] = 1
e1de19
-	}
e1de19
-
e1de19
-	p224AddJacobian(&x3, &y3, &z3, &x1, &y1, &z1, &x2, &y2, &z2)
e1de19
-	return p224ToAffine(&x3, &y3, &z3)
e1de19
-}
e1de19
-
e1de19
-func (p224Curve) Double(bigX1, bigY1 *big.Int) (x, y *big.Int) {
e1de19
-	var x1, y1, z1, x2, y2, z2 p224FieldElement
e1de19
-
e1de19
-	p224FromBig(&x1, bigX1)
e1de19
-	p224FromBig(&y1, bigY1)
e1de19
-	z1[0] = 1
e1de19
-
e1de19
-	p224DoubleJacobian(&x2, &y2, &z2, &x1, &y1, &z1)
e1de19
-	return p224ToAffine(&x2, &y2, &z2)
e1de19
-}
e1de19
-
e1de19
-func (p224Curve) ScalarMult(bigX1, bigY1 *big.Int, scalar []byte) (x, y *big.Int) {
e1de19
-	var x1, y1, z1, x2, y2, z2 p224FieldElement
e1de19
-
e1de19
-	p224FromBig(&x1, bigX1)
e1de19
-	p224FromBig(&y1, bigY1)
e1de19
-	z1[0] = 1
e1de19
-
e1de19
-	p224ScalarMult(&x2, &y2, &z2, &x1, &y1, &z1, scalar)
e1de19
-	return p224ToAffine(&x2, &y2, &z2)
e1de19
-}
e1de19
-
e1de19
-func (curve p224Curve) ScalarBaseMult(scalar []byte) (x, y *big.Int) {
e1de19
-	var z1, x2, y2, z2 p224FieldElement
e1de19
-
e1de19
-	z1[0] = 1
e1de19
-	p224ScalarMult(&x2, &y2, &z2, &curve.gx, &curve.gy, &z1, scalar)
e1de19
-	return p224ToAffine(&x2, &y2, &z2)
e1de19
-}
e1de19
-
e1de19
-// Field element functions.
e1de19
-//
e1de19
-// The field that we're dealing with is ℤ/pℤ where p = 2**224 - 2**96 + 1.
e1de19
-//
e1de19
-// Field elements are represented by a FieldElement, which is a typedef to an
e1de19
-// array of 8 uint32's. The value of a FieldElement, a, is:
e1de19
-//   a[0] + 2**28·a[1] + 2**56·a[1] + ... + 2**196·a[7]
e1de19
-//
e1de19
-// Using 28-bit limbs means that there's only 4 bits of headroom, which is less
e1de19
-// than we would really like. But it has the useful feature that we hit 2**224
e1de19
-// exactly, making the reflections during a reduce much nicer.
e1de19
-type p224FieldElement [8]uint32
e1de19
-
e1de19
-// p224P is the order of the field, represented as a p224FieldElement.
e1de19
-var p224P = [8]uint32{1, 0, 0, 0xffff000, 0xfffffff, 0xfffffff, 0xfffffff, 0xfffffff}
e1de19
-
e1de19
-// p224IsZero returns 1 if a == 0 mod p and 0 otherwise.
e1de19
-//
e1de19
-// a[i] < 2**29
e1de19
-func p224IsZero(a *p224FieldElement) uint32 {
e1de19
-	// Since a p224FieldElement contains 224 bits there are two possible
e1de19
-	// representations of 0: 0 and p.
e1de19
-	var minimal p224FieldElement
e1de19
-	p224Contract(&minimal, a)
e1de19
-
e1de19
-	var isZero, isP uint32
e1de19
-	for i, v := range minimal {
e1de19
-		isZero |= v
e1de19
-		isP |= v - p224P[i]
e1de19
-	}
e1de19
-
e1de19
-	// If either isZero or isP is 0, then we should return 1.
e1de19
-	isZero |= isZero >> 16
e1de19
-	isZero |= isZero >> 8
e1de19
-	isZero |= isZero >> 4
e1de19
-	isZero |= isZero >> 2
e1de19
-	isZero |= isZero >> 1
e1de19
-
e1de19
-	isP |= isP >> 16
e1de19
-	isP |= isP >> 8
e1de19
-	isP |= isP >> 4
e1de19
-	isP |= isP >> 2
e1de19
-	isP |= isP >> 1
e1de19
-
e1de19
-	// For isZero and isP, the LSB is 0 iff all the bits are zero.
e1de19
-	result := isZero & isP
e1de19
-	result = (^result) & 1
e1de19
-
e1de19
-	return result
e1de19
-}
e1de19
-
e1de19
-// p224Add computes *out = a+b
e1de19
-//
e1de19
-// a[i] + b[i] < 2**32
e1de19
-func p224Add(out, a, b *p224FieldElement) {
e1de19
-	for i := 0; i < 8; i++ {
e1de19
-		out[i] = a[i] + b[i]
e1de19
-	}
e1de19
-}
e1de19
-
4d1d36
-const two31p3 = 1<<31 + 1<<3
4d1d36
-const two31m3 = 1<<31 - 1<<3
4d1d36
-const two31m15m3 = 1<<31 - 1<<15 - 1<<3
4d1d36
-
e1de19
-// p224ZeroModP31 is 0 mod p where bit 31 is set in all limbs so that we can
e1de19
-// subtract smaller amounts without underflow. See the section "Subtraction" in
e1de19
-// [1] for reasoning.
e1de19
-var p224ZeroModP31 = []uint32{two31p3, two31m3, two31m3, two31m15m3, two31m3, two31m3, two31m3, two31m3}
e1de19
-
e1de19
-// p224Sub computes *out = a-b
e1de19
-//
e1de19
-// a[i], b[i] < 2**30
e1de19
-// out[i] < 2**32
e1de19
-func p224Sub(out, a, b *p224FieldElement) {
e1de19
-	for i := 0; i < 8; i++ {
e1de19
-		out[i] = a[i] + p224ZeroModP31[i] - b[i]
e1de19
-	}
e1de19
-}
e1de19
-
e1de19
-// LargeFieldElement also represents an element of the field. The limbs are
e1de19
-// still spaced 28-bits apart and in little-endian order. So the limbs are at
e1de19
-// 0, 28, 56, ..., 392 bits, each 64-bits wide.
e1de19
-type p224LargeFieldElement [15]uint64
e1de19
-
e1de19
-const two63p35 = 1<<63 + 1<<35
e1de19
-const two63m35 = 1<<63 - 1<<35
e1de19
-const two63m35m19 = 1<<63 - 1<<35 - 1<<19
e1de19
-
e1de19
-// p224ZeroModP63 is 0 mod p where bit 63 is set in all limbs. See the section
e1de19
-// "Subtraction" in [1] for why.
e1de19
-var p224ZeroModP63 = [8]uint64{two63p35, two63m35, two63m35, two63m35, two63m35m19, two63m35, two63m35, two63m35}
e1de19
-
4d1d36
-const bottom12Bits = 0xfff
4d1d36
-const bottom28Bits = 0xfffffff
4d1d36
-
e1de19
-// p224Mul computes *out = a*b
e1de19
-//
e1de19
-// a[i] < 2**29, b[i] < 2**30 (or vice versa)
e1de19
-// out[i] < 2**29
e1de19
-func p224Mul(out, a, b *p224FieldElement, tmp *p224LargeFieldElement) {
e1de19
-	for i := 0; i < 15; i++ {
e1de19
-		tmp[i] = 0
e1de19
-	}
e1de19
-
e1de19
-	for i := 0; i < 8; i++ {
e1de19
-		for j := 0; j < 8; j++ {
e1de19
-			tmp[i+j] += uint64(a[i]) * uint64(b[j])
e1de19
-		}
e1de19
-	}
e1de19
-
e1de19
-	p224ReduceLarge(out, tmp)
e1de19
-}
e1de19
-
e1de19
-// Square computes *out = a*a
e1de19
-//
e1de19
-// a[i] < 2**29
e1de19
-// out[i] < 2**29
e1de19
-func p224Square(out, a *p224FieldElement, tmp *p224LargeFieldElement) {
e1de19
-	for i := 0; i < 15; i++ {
e1de19
-		tmp[i] = 0
e1de19
-	}
e1de19
-
e1de19
-	for i := 0; i < 8; i++ {
e1de19
-		for j := 0; j <= i; j++ {
e1de19
-			r := uint64(a[i]) * uint64(a[j])
e1de19
-			if i == j {
e1de19
-				tmp[i+j] += r
e1de19
-			} else {
e1de19
-				tmp[i+j] += r << 1
e1de19
-			}
e1de19
-		}
e1de19
-	}
e1de19
-
e1de19
-	p224ReduceLarge(out, tmp)
e1de19
-}
e1de19
-
e1de19
-// ReduceLarge converts a p224LargeFieldElement to a p224FieldElement.
e1de19
-//
e1de19
-// in[i] < 2**62
e1de19
-func p224ReduceLarge(out *p224FieldElement, in *p224LargeFieldElement) {
e1de19
-	for i := 0; i < 8; i++ {
e1de19
-		in[i] += p224ZeroModP63[i]
e1de19
-	}
e1de19
-
e1de19
-	// Eliminate the coefficients at 2**224 and greater.
e1de19
-	for i := 14; i >= 8; i-- {
e1de19
-		in[i-8] -= in[i]
e1de19
-		in[i-5] += (in[i] & 0xffff) << 12
e1de19
-		in[i-4] += in[i] >> 16
e1de19
-	}
e1de19
-	in[8] = 0
e1de19
-	// in[0..8] < 2**64
e1de19
-
e1de19
-	// As the values become small enough, we start to store them in |out|
e1de19
-	// and use 32-bit operations.
e1de19
-	for i := 1; i < 8; i++ {
e1de19
-		in[i+1] += in[i] >> 28
e1de19
-		out[i] = uint32(in[i] & bottom28Bits)
e1de19
-	}
e1de19
-	in[0] -= in[8]
e1de19
-	out[3] += uint32(in[8]&0xffff) << 12
e1de19
-	out[4] += uint32(in[8] >> 16)
e1de19
-	// in[0] < 2**64
e1de19
-	// out[3] < 2**29
e1de19
-	// out[4] < 2**29
e1de19
-	// out[1,2,5..7] < 2**28
e1de19
-
e1de19
-	out[0] = uint32(in[0] & bottom28Bits)
e1de19
-	out[1] += uint32((in[0] >> 28) & bottom28Bits)
e1de19
-	out[2] += uint32(in[0] >> 56)
e1de19
-	// out[0] < 2**28
e1de19
-	// out[1..4] < 2**29
e1de19
-	// out[5..7] < 2**28
e1de19
-}
e1de19
-
e1de19
-// Reduce reduces the coefficients of a to smaller bounds.
e1de19
-//
e1de19
-// On entry: a[i] < 2**31 + 2**30
e1de19
-// On exit: a[i] < 2**29
e1de19
-func p224Reduce(a *p224FieldElement) {
e1de19
-	for i := 0; i < 7; i++ {
e1de19
-		a[i+1] += a[i] >> 28
e1de19
-		a[i] &= bottom28Bits
e1de19
-	}
e1de19
-	top := a[7] >> 28
e1de19
-	a[7] &= bottom28Bits
e1de19
-
e1de19
-	// top < 2**4
e1de19
-	mask := top
e1de19
-	mask |= mask >> 2
e1de19
-	mask |= mask >> 1
e1de19
-	mask <<= 31
e1de19
-	mask = uint32(int32(mask) >> 31)
e1de19
-	// Mask is all ones if top != 0, all zero otherwise
e1de19
-
e1de19
-	a[0] -= top
e1de19
-	a[3] += top << 12
e1de19
-
e1de19
-	// We may have just made a[0] negative but, if we did, then we must
e1de19
-	// have added something to a[3], this it's > 2**12. Therefore we can
e1de19
-	// carry down to a[0].
e1de19
-	a[3] -= 1 & mask
e1de19
-	a[2] += mask & (1<<28 - 1)
e1de19
-	a[1] += mask & (1<<28 - 1)
e1de19
-	a[0] += mask & (1 << 28)
e1de19
-}
e1de19
-
e1de19
-// p224Invert calculates *out = in**-1 by computing in**(2**224 - 2**96 - 1),
e1de19
-// i.e. Fermat's little theorem.
e1de19
-func p224Invert(out, in *p224FieldElement) {
e1de19
-	var f1, f2, f3, f4 p224FieldElement
e1de19
-	var c p224LargeFieldElement
e1de19
-
e1de19
-	p224Square(&f1, in, &c)    // 2
e1de19
-	p224Mul(&f1, &f1, in, &c)  // 2**2 - 1
e1de19
-	p224Square(&f1, &f1, &c)   // 2**3 - 2
e1de19
-	p224Mul(&f1, &f1, in, &c)  // 2**3 - 1
e1de19
-	p224Square(&f2, &f1, &c)   // 2**4 - 2
e1de19
-	p224Square(&f2, &f2, &c)   // 2**5 - 4
e1de19
-	p224Square(&f2, &f2, &c)   // 2**6 - 8
e1de19
-	p224Mul(&f1, &f1, &f2, &c) // 2**6 - 1
e1de19
-	p224Square(&f2, &f1, &c)   // 2**7 - 2
e1de19
-	for i := 0; i < 5; i++ {   // 2**12 - 2**6
e1de19
-		p224Square(&f2, &f2, &c)
e1de19
-	}
e1de19
-	p224Mul(&f2, &f2, &f1, &c) // 2**12 - 1
e1de19
-	p224Square(&f3, &f2, &c)   // 2**13 - 2
e1de19
-	for i := 0; i < 11; i++ {  // 2**24 - 2**12
e1de19
-		p224Square(&f3, &f3, &c)
e1de19
-	}
e1de19
-	p224Mul(&f2, &f3, &f2, &c) // 2**24 - 1
e1de19
-	p224Square(&f3, &f2, &c)   // 2**25 - 2
e1de19
-	for i := 0; i < 23; i++ {  // 2**48 - 2**24
e1de19
-		p224Square(&f3, &f3, &c)
e1de19
-	}
e1de19
-	p224Mul(&f3, &f3, &f2, &c) // 2**48 - 1
e1de19
-	p224Square(&f4, &f3, &c)   // 2**49 - 2
e1de19
-	for i := 0; i < 47; i++ {  // 2**96 - 2**48
e1de19
-		p224Square(&f4, &f4, &c)
e1de19
-	}
e1de19
-	p224Mul(&f3, &f3, &f4, &c) // 2**96 - 1
e1de19
-	p224Square(&f4, &f3, &c)   // 2**97 - 2
e1de19
-	for i := 0; i < 23; i++ {  // 2**120 - 2**24
e1de19
-		p224Square(&f4, &f4, &c)
e1de19
-	}
e1de19
-	p224Mul(&f2, &f4, &f2, &c) // 2**120 - 1
e1de19
-	for i := 0; i < 6; i++ {   // 2**126 - 2**6
e1de19
-		p224Square(&f2, &f2, &c)
e1de19
-	}
e1de19
-	p224Mul(&f1, &f1, &f2, &c) // 2**126 - 1
e1de19
-	p224Square(&f1, &f1, &c)   // 2**127 - 2
e1de19
-	p224Mul(&f1, &f1, in, &c)  // 2**127 - 1
e1de19
-	for i := 0; i < 97; i++ {  // 2**224 - 2**97
e1de19
-		p224Square(&f1, &f1, &c)
e1de19
-	}
e1de19
-	p224Mul(out, &f1, &f3, &c) // 2**224 - 2**96 - 1
e1de19
-}
e1de19
-
e1de19
-// p224Contract converts a FieldElement to its unique, minimal form.
e1de19
-//
e1de19
-// On entry, in[i] < 2**29
e1de19
-// On exit, in[i] < 2**28
e1de19
-func p224Contract(out, in *p224FieldElement) {
e1de19
-	copy(out[:], in[:])
e1de19
-
e1de19
-	for i := 0; i < 7; i++ {
e1de19
-		out[i+1] += out[i] >> 28
e1de19
-		out[i] &= bottom28Bits
e1de19
-	}
e1de19
-	top := out[7] >> 28
e1de19
-	out[7] &= bottom28Bits
e1de19
-
e1de19
-	out[0] -= top
e1de19
-	out[3] += top << 12
e1de19
-
e1de19
-	// We may just have made out[i] negative. So we carry down. If we made
e1de19
-	// out[0] negative then we know that out[3] is sufficiently positive
e1de19
-	// because we just added to it.
e1de19
-	for i := 0; i < 3; i++ {
e1de19
-		mask := uint32(int32(out[i]) >> 31)
e1de19
-		out[i] += (1 << 28) & mask
e1de19
-		out[i+1] -= 1 & mask
e1de19
-	}
e1de19
-
e1de19
-	// We might have pushed out[3] over 2**28 so we perform another, partial,
e1de19
-	// carry chain.
e1de19
-	for i := 3; i < 7; i++ {
e1de19
-		out[i+1] += out[i] >> 28
e1de19
-		out[i] &= bottom28Bits
e1de19
-	}
e1de19
-	top = out[7] >> 28
e1de19
-	out[7] &= bottom28Bits
e1de19
-
e1de19
-	// Eliminate top while maintaining the same value mod p.
e1de19
-	out[0] -= top
e1de19
-	out[3] += top << 12
e1de19
-
e1de19
-	// There are two cases to consider for out[3]:
e1de19
-	//   1) The first time that we eliminated top, we didn't push out[3] over
e1de19
-	//      2**28. In this case, the partial carry chain didn't change any values
e1de19
-	//      and top is zero.
e1de19
-	//   2) We did push out[3] over 2**28 the first time that we eliminated top.
e1de19
-	//      The first value of top was in [0..16), therefore, prior to eliminating
e1de19
-	//      the first top, 0xfff1000 <= out[3] <= 0xfffffff. Therefore, after
e1de19
-	//      overflowing and being reduced by the second carry chain, out[3] <=
e1de19
-	//      0xf000. Thus it cannot have overflowed when we eliminated top for the
e1de19
-	//      second time.
e1de19
-
e1de19
-	// Again, we may just have made out[0] negative, so do the same carry down.
e1de19
-	// As before, if we made out[0] negative then we know that out[3] is
e1de19
-	// sufficiently positive.
e1de19
-	for i := 0; i < 3; i++ {
e1de19
-		mask := uint32(int32(out[i]) >> 31)
e1de19
-		out[i] += (1 << 28) & mask
e1de19
-		out[i+1] -= 1 & mask
e1de19
-	}
e1de19
-
e1de19
-	// Now we see if the value is >= p and, if so, subtract p.
e1de19
-
e1de19
-	// First we build a mask from the top four limbs, which must all be
e1de19
-	// equal to bottom28Bits if the whole value is >= p. If top4AllOnes
e1de19
-	// ends up with any zero bits in the bottom 28 bits, then this wasn't
e1de19
-	// true.
e1de19
-	top4AllOnes := uint32(0xffffffff)
e1de19
-	for i := 4; i < 8; i++ {
e1de19
-		top4AllOnes &= out[i]
e1de19
-	}
e1de19
-	top4AllOnes |= 0xf0000000
e1de19
-	// Now we replicate any zero bits to all the bits in top4AllOnes.
e1de19
-	top4AllOnes &= top4AllOnes >> 16
e1de19
-	top4AllOnes &= top4AllOnes >> 8
e1de19
-	top4AllOnes &= top4AllOnes >> 4
e1de19
-	top4AllOnes &= top4AllOnes >> 2
e1de19
-	top4AllOnes &= top4AllOnes >> 1
e1de19
-	top4AllOnes = uint32(int32(top4AllOnes<<31) >> 31)
e1de19
-
e1de19
-	// Now we test whether the bottom three limbs are non-zero.
e1de19
-	bottom3NonZero := out[0] | out[1] | out[2]
e1de19
-	bottom3NonZero |= bottom3NonZero >> 16
e1de19
-	bottom3NonZero |= bottom3NonZero >> 8
e1de19
-	bottom3NonZero |= bottom3NonZero >> 4
e1de19
-	bottom3NonZero |= bottom3NonZero >> 2
e1de19
-	bottom3NonZero |= bottom3NonZero >> 1
e1de19
-	bottom3NonZero = uint32(int32(bottom3NonZero<<31) >> 31)
e1de19
-
e1de19
-	// Everything depends on the value of out[3].
e1de19
-	//    If it's > 0xffff000 and top4AllOnes != 0 then the whole value is >= p
e1de19
-	//    If it's = 0xffff000 and top4AllOnes != 0 and bottom3NonZero != 0,
e1de19
-	//      then the whole value is >= p
e1de19
-	//    If it's < 0xffff000, then the whole value is < p
e1de19
-	n := out[3] - 0xffff000
e1de19
-	out3Equal := n
e1de19
-	out3Equal |= out3Equal >> 16
e1de19
-	out3Equal |= out3Equal >> 8
e1de19
-	out3Equal |= out3Equal >> 4
e1de19
-	out3Equal |= out3Equal >> 2
e1de19
-	out3Equal |= out3Equal >> 1
e1de19
-	out3Equal = ^uint32(int32(out3Equal<<31) >> 31)
e1de19
-
e1de19
-	// If out[3] > 0xffff000 then n's MSB will be zero.
e1de19
-	out3GT := ^uint32(int32(n) >> 31)
e1de19
-
e1de19
-	mask := top4AllOnes & ((out3Equal & bottom3NonZero) | out3GT)
e1de19
-	out[0] -= 1 & mask
e1de19
-	out[3] -= 0xffff000 & mask
e1de19
-	out[4] -= 0xfffffff & mask
e1de19
-	out[5] -= 0xfffffff & mask
e1de19
-	out[6] -= 0xfffffff & mask
e1de19
-	out[7] -= 0xfffffff & mask
e1de19
-}
e1de19
-
e1de19
-// Group element functions.
e1de19
-//
e1de19
-// These functions deal with group elements. The group is an elliptic curve
e1de19
-// group with a = -3 defined in FIPS 186-3, section D.2.2.
e1de19
-
e1de19
-// p224AddJacobian computes *out = a+b where a != b.
e1de19
-func p224AddJacobian(x3, y3, z3, x1, y1, z1, x2, y2, z2 *p224FieldElement) {
e1de19
-	// See http://hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-3.html#addition-p224Add-2007-bl
e1de19
-	var z1z1, z2z2, u1, u2, s1, s2, h, i, j, r, v p224FieldElement
e1de19
-	var c p224LargeFieldElement
e1de19
-
e1de19
-	z1IsZero := p224IsZero(z1)
e1de19
-	z2IsZero := p224IsZero(z2)
e1de19
-
e1de19
-	// Z1Z1 = Z1²
e1de19
-	p224Square(&z1z1, z1, &c)
e1de19
-	// Z2Z2 = Z2²
e1de19
-	p224Square(&z2z2, z2, &c)
e1de19
-	// U1 = X1*Z2Z2
e1de19
-	p224Mul(&u1, x1, &z2z2, &c)
e1de19
-	// U2 = X2*Z1Z1
e1de19
-	p224Mul(&u2, x2, &z1z1, &c)
e1de19
-	// S1 = Y1*Z2*Z2Z2
e1de19
-	p224Mul(&s1, z2, &z2z2, &c)
e1de19
-	p224Mul(&s1, y1, &s1, &c)
e1de19
-	// S2 = Y2*Z1*Z1Z1
e1de19
-	p224Mul(&s2, z1, &z1z1, &c)
e1de19
-	p224Mul(&s2, y2, &s2, &c)
e1de19
-	// H = U2-U1
e1de19
-	p224Sub(&h, &u2, &u1)
e1de19
-	p224Reduce(&h)
e1de19
-	xEqual := p224IsZero(&h)
e1de19
-	// I = (2*H)²
e1de19
-	for j := 0; j < 8; j++ {
e1de19
-		i[j] = h[j] << 1
e1de19
-	}
e1de19
-	p224Reduce(&i)
e1de19
-	p224Square(&i, &i, &c)
e1de19
-	// J = H*I
e1de19
-	p224Mul(&j, &h, &i, &c)
e1de19
-	// r = 2*(S2-S1)
e1de19
-	p224Sub(&r, &s2, &s1)
e1de19
-	p224Reduce(&r)
e1de19
-	yEqual := p224IsZero(&r)
e1de19
-	if xEqual == 1 && yEqual == 1 && z1IsZero == 0 && z2IsZero == 0 {
e1de19
-		p224DoubleJacobian(x3, y3, z3, x1, y1, z1)
e1de19
-		return
e1de19
-	}
e1de19
-	for i := 0; i < 8; i++ {
e1de19
-		r[i] <<= 1
e1de19
-	}
e1de19
-	p224Reduce(&r)
e1de19
-	// V = U1*I
e1de19
-	p224Mul(&v, &u1, &i, &c)
e1de19
-	// Z3 = ((Z1+Z2)²-Z1Z1-Z2Z2)*H
e1de19
-	p224Add(&z1z1, &z1z1, &z2z2)
e1de19
-	p224Add(&z2z2, z1, z2)
e1de19
-	p224Reduce(&z2z2)
e1de19
-	p224Square(&z2z2, &z2z2, &c)
e1de19
-	p224Sub(z3, &z2z2, &z1z1)
e1de19
-	p224Reduce(z3)
e1de19
-	p224Mul(z3, z3, &h, &c)
e1de19
-	// X3 = r²-J-2*V
e1de19
-	for i := 0; i < 8; i++ {
e1de19
-		z1z1[i] = v[i] << 1
e1de19
-	}
e1de19
-	p224Add(&z1z1, &j, &z1z1)
e1de19
-	p224Reduce(&z1z1)
e1de19
-	p224Square(x3, &r, &c)
e1de19
-	p224Sub(x3, x3, &z1z1)
e1de19
-	p224Reduce(x3)
e1de19
-	// Y3 = r*(V-X3)-2*S1*J
e1de19
-	for i := 0; i < 8; i++ {
e1de19
-		s1[i] <<= 1
e1de19
-	}
e1de19
-	p224Mul(&s1, &s1, &j, &c)
e1de19
-	p224Sub(&z1z1, &v, x3)
e1de19
-	p224Reduce(&z1z1)
e1de19
-	p224Mul(&z1z1, &z1z1, &r, &c)
e1de19
-	p224Sub(y3, &z1z1, &s1)
e1de19
-	p224Reduce(y3)
e1de19
-
e1de19
-	p224CopyConditional(x3, x2, z1IsZero)
e1de19
-	p224CopyConditional(x3, x1, z2IsZero)
e1de19
-	p224CopyConditional(y3, y2, z1IsZero)
e1de19
-	p224CopyConditional(y3, y1, z2IsZero)
e1de19
-	p224CopyConditional(z3, z2, z1IsZero)
e1de19
-	p224CopyConditional(z3, z1, z2IsZero)
e1de19
-}
e1de19
-
e1de19
-// p224DoubleJacobian computes *out = a+a.
e1de19
-func p224DoubleJacobian(x3, y3, z3, x1, y1, z1 *p224FieldElement) {
e1de19
-	var delta, gamma, beta, alpha, t p224FieldElement
e1de19
-	var c p224LargeFieldElement
e1de19
-
e1de19
-	p224Square(&delta, z1, &c)
e1de19
-	p224Square(&gamma, y1, &c)
e1de19
-	p224Mul(&beta, x1, &gamma, &c)
e1de19
-
e1de19
-	// alpha = 3*(X1-delta)*(X1+delta)
e1de19
-	p224Add(&t, x1, &delta)
e1de19
-	for i := 0; i < 8; i++ {
e1de19
-		t[i] += t[i] << 1
e1de19
-	}
e1de19
-	p224Reduce(&t)
e1de19
-	p224Sub(&alpha, x1, &delta)
e1de19
-	p224Reduce(&alpha)
e1de19
-	p224Mul(&alpha, &alpha, &t, &c)
e1de19
-
e1de19
-	// Z3 = (Y1+Z1)²-gamma-delta
e1de19
-	p224Add(z3, y1, z1)
e1de19
-	p224Reduce(z3)
e1de19
-	p224Square(z3, z3, &c)
e1de19
-	p224Sub(z3, z3, &gamma)
e1de19
-	p224Reduce(z3)
e1de19
-	p224Sub(z3, z3, &delta)
e1de19
-	p224Reduce(z3)
e1de19
-
e1de19
-	// X3 = alpha²-8*beta
e1de19
-	for i := 0; i < 8; i++ {
e1de19
-		delta[i] = beta[i] << 3
e1de19
-	}
e1de19
-	p224Reduce(&delta)
e1de19
-	p224Square(x3, &alpha, &c)
e1de19
-	p224Sub(x3, x3, &delta)
e1de19
-	p224Reduce(x3)
e1de19
-
e1de19
-	// Y3 = alpha*(4*beta-X3)-8*gamma²
e1de19
-	for i := 0; i < 8; i++ {
e1de19
-		beta[i] <<= 2
e1de19
-	}
e1de19
-	p224Sub(&beta, &beta, x3)
e1de19
-	p224Reduce(&beta)
e1de19
-	p224Square(&gamma, &gamma, &c)
e1de19
-	for i := 0; i < 8; i++ {
e1de19
-		gamma[i] <<= 3
e1de19
-	}
e1de19
-	p224Reduce(&gamma)
e1de19
-	p224Mul(y3, &alpha, &beta, &c)
e1de19
-	p224Sub(y3, y3, &gamma)
e1de19
-	p224Reduce(y3)
e1de19
-}
e1de19
-
e1de19
-// p224CopyConditional sets *out = *in iff the least-significant-bit of control
e1de19
-// is true, and it runs in constant time.
e1de19
-func p224CopyConditional(out, in *p224FieldElement, control uint32) {
e1de19
-	control <<= 31
e1de19
-	control = uint32(int32(control) >> 31)
e1de19
-
e1de19
-	for i := 0; i < 8; i++ {
e1de19
-		out[i] ^= (out[i] ^ in[i]) & control
e1de19
-	}
e1de19
-}
e1de19
-
e1de19
-func p224ScalarMult(outX, outY, outZ, inX, inY, inZ *p224FieldElement, scalar []byte) {
e1de19
-	var xx, yy, zz p224FieldElement
e1de19
-	for i := 0; i < 8; i++ {
e1de19
-		outX[i] = 0
e1de19
-		outY[i] = 0
e1de19
-		outZ[i] = 0
e1de19
-	}
e1de19
-
e1de19
-	for _, byte := range scalar {
e1de19
-		for bitNum := uint(0); bitNum < 8; bitNum++ {
e1de19
-			p224DoubleJacobian(outX, outY, outZ, outX, outY, outZ)
e1de19
-			bit := uint32((byte >> (7 - bitNum)) & 1)
e1de19
-			p224AddJacobian(&xx, &yy, &zz, inX, inY, inZ, outX, outY, outZ)
e1de19
-			p224CopyConditional(outX, &xx, bit)
e1de19
-			p224CopyConditional(outY, &yy, bit)
e1de19
-			p224CopyConditional(outZ, &zz, bit)
e1de19
-		}
e1de19
-	}
e1de19
-}
e1de19
-
e1de19
-// p224ToAffine converts from Jacobian to affine form.
e1de19
-func p224ToAffine(x, y, z *p224FieldElement) (*big.Int, *big.Int) {
e1de19
-	var zinv, zinvsq, outx, outy p224FieldElement
e1de19
-	var tmp p224LargeFieldElement
e1de19
-
e1de19
-	if isPointAtInfinity := p224IsZero(z); isPointAtInfinity == 1 {
e1de19
-		return new(big.Int), new(big.Int)
e1de19
-	}
e1de19
-
e1de19
-	p224Invert(&zinv, z)
e1de19
-	p224Square(&zinvsq, &zinv, &tmp)
e1de19
-	p224Mul(x, x, &zinvsq, &tmp)
e1de19
-	p224Mul(&zinvsq, &zinvsq, &zinv, &tmp)
e1de19
-	p224Mul(y, y, &zinvsq, &tmp)
e1de19
-
e1de19
-	p224Contract(&outx, x)
e1de19
-	p224Contract(&outy, y)
e1de19
-	return p224ToBig(&outx), p224ToBig(&outy)
e1de19
-}
e1de19
-
e1de19
-// get28BitsFromEnd returns the least-significant 28 bits from buf>>shift,
e1de19
-// where buf is interpreted as a big-endian number.
e1de19
-func get28BitsFromEnd(buf []byte, shift uint) (uint32, []byte) {
e1de19
-	var ret uint32
e1de19
-
e1de19
-	for i := uint(0); i < 4; i++ {
e1de19
-		var b byte
e1de19
-		if l := len(buf); l > 0 {
e1de19
-			b = buf[l-1]
e1de19
-			// We don't remove the byte if we're about to return and we're not
e1de19
-			// reading all of it.
e1de19
-			if i != 3 || shift == 4 {
e1de19
-				buf = buf[:l-1]
e1de19
-			}
e1de19
-		}
e1de19
-		ret |= uint32(b) << (8 * i) >> shift
e1de19
-	}
e1de19
-	ret &= bottom28Bits
e1de19
-	return ret, buf
e1de19
-}
e1de19
-
e1de19
-// p224FromBig sets *out = *in.
e1de19
-func p224FromBig(out *p224FieldElement, in *big.Int) {
e1de19
-	bytes := in.Bytes()
e1de19
-	out[0], bytes = get28BitsFromEnd(bytes, 0)
e1de19
-	out[1], bytes = get28BitsFromEnd(bytes, 4)
e1de19
-	out[2], bytes = get28BitsFromEnd(bytes, 0)
e1de19
-	out[3], bytes = get28BitsFromEnd(bytes, 4)
e1de19
-	out[4], bytes = get28BitsFromEnd(bytes, 0)
e1de19
-	out[5], bytes = get28BitsFromEnd(bytes, 4)
e1de19
-	out[6], bytes = get28BitsFromEnd(bytes, 0)
e1de19
-	out[7], bytes = get28BitsFromEnd(bytes, 4)
e1de19
-}
e1de19
-
e1de19
-// p224ToBig returns in as a big.Int.
e1de19
-func p224ToBig(in *p224FieldElement) *big.Int {
e1de19
-	var buf [28]byte
e1de19
-	buf[27] = byte(in[0])
e1de19
-	buf[26] = byte(in[0] >> 8)
e1de19
-	buf[25] = byte(in[0] >> 16)
e1de19
-	buf[24] = byte(((in[0] >> 24) & 0x0f) | (in[1]<<4)&0xf0)
e1de19
-
e1de19
-	buf[23] = byte(in[1] >> 4)
e1de19
-	buf[22] = byte(in[1] >> 12)
e1de19
-	buf[21] = byte(in[1] >> 20)
e1de19
-
e1de19
-	buf[20] = byte(in[2])
e1de19
-	buf[19] = byte(in[2] >> 8)
e1de19
-	buf[18] = byte(in[2] >> 16)
e1de19
-	buf[17] = byte(((in[2] >> 24) & 0x0f) | (in[3]<<4)&0xf0)
e1de19
-
e1de19
-	buf[16] = byte(in[3] >> 4)
e1de19
-	buf[15] = byte(in[3] >> 12)
e1de19
-	buf[14] = byte(in[3] >> 20)
e1de19
-
e1de19
-	buf[13] = byte(in[4])
e1de19
-	buf[12] = byte(in[4] >> 8)
e1de19
-	buf[11] = byte(in[4] >> 16)
e1de19
-	buf[10] = byte(((in[4] >> 24) & 0x0f) | (in[5]<<4)&0xf0)
e1de19
-
e1de19
-	buf[9] = byte(in[5] >> 4)
e1de19
-	buf[8] = byte(in[5] >> 12)
e1de19
-	buf[7] = byte(in[5] >> 20)
e1de19
-
e1de19
-	buf[6] = byte(in[6])
e1de19
-	buf[5] = byte(in[6] >> 8)
e1de19
-	buf[4] = byte(in[6] >> 16)
e1de19
-	buf[3] = byte(((in[6] >> 24) & 0x0f) | (in[7]<<4)&0xf0)
e1de19
-
e1de19
-	buf[2] = byte(in[7] >> 4)
e1de19
-	buf[1] = byte(in[7] >> 12)
e1de19
-	buf[0] = byte(in[7] >> 20)
e1de19
-
e1de19
-	return new(big.Int).SetBytes(buf[:])
e1de19
-}
e1de19
diff --git a/src/crypto/elliptic/p224_test.go b/src/crypto/elliptic/p224_test.go
e1de19
deleted file mode 100644
e1de19
index 4b26d16..0000000
e1de19
--- a/src/crypto/elliptic/p224_test.go
e1de19
+++ /dev/null
e1de19
@@ -1,47 +0,0 @@
e1de19
-// Copyright 2012 The Go Authors.  All rights reserved.
e1de19
-// Use of this source code is governed by a BSD-style
e1de19
-// license that can be found in the LICENSE file.
e1de19
-
e1de19
-package elliptic
e1de19
-
e1de19
-import (
e1de19
-	"math/big"
e1de19
-	"testing"
e1de19
-)
e1de19
-
e1de19
-var toFromBigTests = []string{
e1de19
-	"0",
e1de19
-	"1",
e1de19
-	"23",
e1de19
-	"b70e0cb46bb4bf7f321390b94a03c1d356c01122343280d6105c1d21",
e1de19
-	"706a46d476dcb76798e6046d89474788d164c18032d268fd10704fa6",
e1de19
-}
e1de19
-
e1de19
-func p224AlternativeToBig(in *p224FieldElement) *big.Int {
e1de19
-	ret := new(big.Int)
e1de19
-	tmp := new(big.Int)
e1de19
-
e1de19
-	for i := uint(0); i < 8; i++ {
e1de19
-		tmp.SetInt64(int64(in[i]))
e1de19
-		tmp.Lsh(tmp, 28*i)
e1de19
-		ret.Add(ret, tmp)
e1de19
-	}
e1de19
-	ret.Mod(ret, p224.P)
e1de19
-	return ret
e1de19
-}
e1de19
-
e1de19
-func TestToFromBig(t *testing.T) {
e1de19
-	for i, test := range toFromBigTests {
e1de19
-		n, _ := new(big.Int).SetString(test, 16)
e1de19
-		var x p224FieldElement
e1de19
-		p224FromBig(&x, n)
e1de19
-		m := p224ToBig(&x)
e1de19
-		if n.Cmp(m) != 0 {
e1de19
-			t.Errorf("#%d: %x != %x", i, n, m)
e1de19
-		}
e1de19
-		q := p224AlternativeToBig(&x)
e1de19
-		if n.Cmp(q) != 0 {
e1de19
-			t.Errorf("#%d: %x != %x (alternative)", i, n, m)
e1de19
-		}
e1de19
-	}
e1de19
-}
e1de19
diff --git a/src/crypto/tls/generate_cert.go b/src/crypto/tls/generate_cert.go
e1de19
index 83f9916..dea8589 100644
e1de19
--- a/src/crypto/tls/generate_cert.go
e1de19
+++ b/src/crypto/tls/generate_cert.go
e1de19
@@ -33,7 +33,7 @@ var (
e1de19
 	validFor   = flag.Duration("duration", 365*24*time.Hour, "Duration that certificate is valid for")
e1de19
 	isCA       = flag.Bool("ca", false, "whether this cert should be its own Certificate Authority")
e1de19
 	rsaBits    = flag.Int("rsa-bits", 2048, "Size of RSA key to generate. Ignored if --ecdsa-curve is set")
e1de19
-	ecdsaCurve = flag.String("ecdsa-curve", "", "ECDSA curve to use to generate a key. Valid values are P224, P256, P384, P521")
e1de19
+	ecdsaCurve = flag.String("ecdsa-curve", "", "ECDSA curve to use to generate a key. Valid values are P256, P384, P521")
e1de19
 )
e1de19
 
e1de19
 func publicKey(priv interface{}) interface{} {
e1de19
@@ -75,8 +75,6 @@ func main() {
e1de19
 	switch *ecdsaCurve {
e1de19
 	case "":
e1de19
 		priv, err = rsa.GenerateKey(rand.Reader, *rsaBits)
e1de19
-	case "P224":
e1de19
-		priv, err = ecdsa.GenerateKey(elliptic.P224(), rand.Reader)
e1de19
 	case "P256":
e1de19
 		priv, err = ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
e1de19
 	case "P384":
e1de19
diff --git a/src/crypto/x509/x509.go b/src/crypto/x509/x509.go
e1de19
index be6c013..428053a 100644
e1de19
--- a/src/crypto/x509/x509.go
e1de19
+++ b/src/crypto/x509/x509.go
e1de19
@@ -308,9 +308,6 @@ func getPublicKeyAlgorithmFromOID(oid asn1.ObjectIdentifier) PublicKeyAlgorithm
4d1d36
 
4d1d36
 // RFC 5480, 2.1.1.1. Named Curve
4d1d36
 //
4d1d36
-// secp224r1 OBJECT IDENTIFIER ::= {
4d1d36
-//   iso(1) identified-organization(3) certicom(132) curve(0) 33 }
4d1d36
-//
4d1d36
 // secp256r1 OBJECT IDENTIFIER ::= {
4d1d36
 //   iso(1) member-body(2) us(840) ansi-X9-62(10045) curves(3)
4d1d36
 //   prime(1) 7 }
e1de19
@@ -323,7 +320,6 @@ func getPublicKeyAlgorithmFromOID(oid asn1.ObjectIdentifier) PublicKeyAlgorithm
4d1d36
 //
4d1d36
 // NB: secp256r1 is equivalent to prime256v1
4d1d36
 var (
4d1d36
-	oidNamedCurveP224 = asn1.ObjectIdentifier{1, 3, 132, 0, 33}
4d1d36
 	oidNamedCurveP256 = asn1.ObjectIdentifier{1, 2, 840, 10045, 3, 1, 7}
4d1d36
 	oidNamedCurveP384 = asn1.ObjectIdentifier{1, 3, 132, 0, 34}
4d1d36
 	oidNamedCurveP521 = asn1.ObjectIdentifier{1, 3, 132, 0, 35}
e1de19
@@ -331,8 +327,6 @@ var (
4d1d36
 
4d1d36
 func namedCurveFromOID(oid asn1.ObjectIdentifier) elliptic.Curve {
4d1d36
 	switch {
4d1d36
-	case oid.Equal(oidNamedCurveP224):
4d1d36
-		return elliptic.P224()
4d1d36
 	case oid.Equal(oidNamedCurveP256):
4d1d36
 		return elliptic.P256()
4d1d36
 	case oid.Equal(oidNamedCurveP384):
e1de19
@@ -345,8 +339,6 @@ func namedCurveFromOID(oid asn1.ObjectIdentifier) elliptic.Curve {
4d1d36
 
4d1d36
 func oidFromNamedCurve(curve elliptic.Curve) (asn1.ObjectIdentifier, bool) {
4d1d36
 	switch curve {
4d1d36
-	case elliptic.P224():
4d1d36
-		return oidNamedCurveP224, true
4d1d36
 	case elliptic.P256():
4d1d36
 		return oidNamedCurveP256, true
4d1d36
 	case elliptic.P384():
e1de19
@@ -1466,7 +1458,7 @@ func signingParamsForPublicKey(pub interface{}, requestedSigAlgo SignatureAlgori
9b5743
 		pubType = ECDSA
9b5743
 
e1de19
 		switch pub.Curve {
4d1d36
-		case elliptic.P224(), elliptic.P256():
4d1d36
+		case elliptic.P256():
4d1d36
 			hashFunc = crypto.SHA256
9b5743
 			sigAlgo.Algorithm = oidSignatureECDSAWithSHA256
4d1d36
 		case elliptic.P384():