Commit eb48f83a authored by Adam Langley's avatar Adam Langley

crypto/tls (part 5/5)

Make RSA and X509 build by using big. (This involves commenting out
key generation for now since I haven't written Miller-Rabin in big
yet.)

Add entries to the Makefile.

R=rsc
CC=go-dev
http://go/go-review/1022005
parent 950f2637
...@@ -5,8 +5,8 @@ bignum.install: fmt.install ...@@ -5,8 +5,8 @@ bignum.install: fmt.install
bufio.install: io.install os.install strconv.install utf8.install bufio.install: io.install os.install strconv.install utf8.install
bytes.install: os.install unicode.install utf8.install bytes.install: os.install unicode.install utf8.install
compress/flate.install: bufio.install bytes.install io.install math.install os.install sort.install strconv.install compress/flate.install: bufio.install bytes.install io.install math.install os.install sort.install strconv.install
compress/gzip.install: bufio.install compress/flate.install hash.install hash/crc32.install io.install os.install compress/gzip.install: bufio.install compress/flate.install hash/crc32.install hash.install io.install os.install
compress/zlib.install: bufio.install compress/flate.install hash.install hash/adler32.install io.install os.install compress/zlib.install: bufio.install compress/flate.install hash/adler32.install hash.install io.install os.install
container/heap.install: sort.install container/heap.install: sort.install
container/list.install: container/list.install:
container/ring.install: container/ring.install:
...@@ -16,8 +16,11 @@ crypto/block.install: fmt.install hash.install io.install os.install strconv.ins ...@@ -16,8 +16,11 @@ crypto/block.install: fmt.install hash.install io.install os.install strconv.ins
crypto/hmac.install: crypto/md5.install crypto/sha1.install hash.install os.install crypto/hmac.install: crypto/md5.install crypto/sha1.install hash.install os.install
crypto/md5.install: hash.install os.install crypto/md5.install: hash.install os.install
crypto/rc4.install: os.install strconv.install crypto/rc4.install: os.install strconv.install
crypto/rsa.install: big.install bytes.install crypto/subtle.install hash.install io.install os.install
crypto/sha1.install: hash.install os.install crypto/sha1.install: hash.install os.install
crypto/subtle.install: crypto/subtle.install:
crypto/tls.install: bufio.install bytes.install container/list.install crypto/hmac.install crypto/md5.install crypto/rc4.install crypto/rsa.install crypto/sha1.install crypto/subtle.install fmt.install hash.install io.install net.install os.install strings.install time.install
crypto/x509.install: asn1.install big.install crypto/rsa.install os.install
debug/dwarf.install: encoding/binary.install os.install strconv.install debug/dwarf.install: encoding/binary.install os.install strconv.install
debug/macho.install: bytes.install debug/dwarf.install encoding/binary.install fmt.install io.install os.install strconv.install debug/macho.install: bytes.install debug/dwarf.install encoding/binary.install fmt.install io.install os.install strconv.install
debug/elf.install: bytes.install debug/dwarf.install encoding/binary.install fmt.install io.install os.install strconv.install debug/elf.install: bytes.install debug/dwarf.install encoding/binary.install fmt.install io.install os.install strconv.install
...@@ -49,7 +52,7 @@ hash/adler32.install: hash.install os.install ...@@ -49,7 +52,7 @@ hash/adler32.install: hash.install os.install
hash/crc32.install: hash.install os.install hash/crc32.install: hash.install os.install
http.install: bufio.install bytes.install container/vector.install fmt.install io.install log.install net.install os.install path.install strconv.install strings.install utf8.install http.install: bufio.install bytes.install container/vector.install fmt.install io.install log.install net.install os.install path.install strconv.install strings.install utf8.install
image.install: image.install:
image/png.install: bufio.install compress/zlib.install hash.install hash/crc32.install image.install io.install os.install strconv.install image/png.install: bufio.install compress/zlib.install hash/crc32.install hash.install image.install io.install os.install strconv.install
io.install: bytes.install os.install sort.install strings.install sync.install io.install: bytes.install os.install sort.install strings.install sync.install
json.install: bytes.install container/vector.install fmt.install math.install reflect.install strconv.install strings.install utf8.install json.install: bytes.install container/vector.install fmt.install math.install reflect.install strconv.install strings.install utf8.install
log.install: fmt.install io.install os.install runtime.install time.install log.install: fmt.install io.install os.install runtime.install time.install
......
...@@ -30,8 +30,11 @@ DIRS=\ ...@@ -30,8 +30,11 @@ DIRS=\
crypto/hmac\ crypto/hmac\
crypto/md5\ crypto/md5\
crypto/rc4\ crypto/rc4\
crypto/rsa\
crypto/sha1\ crypto/sha1\
crypto/subtle\ crypto/subtle\
crypto/tls\
crypto/x509\
debug/dwarf\ debug/dwarf\
debug/macho\ debug/macho\
debug/elf\ debug/elf\
......
...@@ -5,9 +5,9 @@ ...@@ -5,9 +5,9 @@
package rsa package rsa
import ( import (
"big";
"bytes"; "bytes";
"crypto/subtle"; "crypto/subtle";
big "gmp";
"io"; "io";
"os"; "os";
) )
......
...@@ -5,9 +5,9 @@ ...@@ -5,9 +5,9 @@
package rsa package rsa
import ( import (
"big";
"bytes"; "bytes";
"encoding/base64"; "encoding/base64";
big "gmp";
"os"; "os";
"io"; "io";
"strings"; "strings";
......
...@@ -8,9 +8,9 @@ package rsa ...@@ -8,9 +8,9 @@ package rsa
// TODO(agl): Add support for PSS padding. // TODO(agl): Add support for PSS padding.
import ( import (
"big";
"bytes"; "bytes";
"crypto/subtle"; "crypto/subtle";
big "gmp";
"hash"; "hash";
"io"; "io";
"os"; "os";
...@@ -19,6 +19,10 @@ import ( ...@@ -19,6 +19,10 @@ import (
var bigZero = big.NewInt(0) var bigZero = big.NewInt(0)
var bigOne = big.NewInt(1) var bigOne = big.NewInt(1)
/*
TODO(agl): Enable once big implements ProbablyPrime.
// randomSafePrime returns a number, p, of the given size, such that p and // randomSafePrime returns a number, p, of the given size, such that p and
// (p-1)/2 are both prime with high probability. // (p-1)/2 are both prime with high probability.
func randomSafePrime(rand io.Reader, bits int) (p *big.Int, err os.Error) { func randomSafePrime(rand io.Reader, bits int) (p *big.Int, err os.Error) {
...@@ -53,6 +57,8 @@ func randomSafePrime(rand io.Reader, bits int) (p *big.Int, err os.Error) { ...@@ -53,6 +57,8 @@ func randomSafePrime(rand io.Reader, bits int) (p *big.Int, err os.Error) {
return; return;
} }
*/
// randomNumber returns a uniform random value in [0, max). // randomNumber returns a uniform random value in [0, max).
func randomNumber(rand io.Reader, max *big.Int) (n *big.Int, err os.Error) { func randomNumber(rand io.Reader, max *big.Int) (n *big.Int, err os.Error) {
k := (max.Len() + 7)/8; k := (max.Len() + 7)/8;
...@@ -103,6 +109,9 @@ type PrivateKey struct { ...@@ -103,6 +109,9 @@ type PrivateKey struct {
// It returns nil if the key is valid, or else an os.Error describing a problem. // It returns nil if the key is valid, or else an os.Error describing a problem.
func (priv PrivateKey) Validate() os.Error { func (priv PrivateKey) Validate() os.Error {
/*
TODO(agl): Enable once big implements ProbablyPrime.
// Check that p and q are prime. // Check that p and q are prime.
if !priv.P.ProbablyPrime(20) { if !priv.P.ProbablyPrime(20) {
return os.ErrorString("P is composite"); return os.ErrorString("P is composite");
...@@ -110,6 +119,7 @@ func (priv PrivateKey) Validate() os.Error { ...@@ -110,6 +119,7 @@ func (priv PrivateKey) Validate() os.Error {
if !priv.Q.ProbablyPrime(20) { if !priv.Q.ProbablyPrime(20) {
return os.ErrorString("Q is composite"); return os.ErrorString("Q is composite");
} }
*/
// Check that p*q == n. // Check that p*q == n.
modulus := new(big.Int).Mul(priv.P, priv.Q); modulus := new(big.Int).Mul(priv.P, priv.Q);
if big.CmpInt(modulus, priv.N) != 0 { if big.CmpInt(modulus, priv.N) != 0 {
...@@ -136,6 +146,8 @@ func (priv PrivateKey) Validate() os.Error { ...@@ -136,6 +146,8 @@ func (priv PrivateKey) Validate() os.Error {
return nil; return nil;
} }
/*
// GenerateKeyPair generates an RSA keypair of the given bit size. // GenerateKeyPair generates an RSA keypair of the given bit size.
func GenerateKey(rand io.Reader, bits int) (priv *PrivateKey, err os.Error) { func GenerateKey(rand io.Reader, bits int) (priv *PrivateKey, err os.Error) {
priv = new(PrivateKey); priv = new(PrivateKey);
...@@ -192,6 +204,8 @@ func GenerateKey(rand io.Reader, bits int) (priv *PrivateKey, err os.Error) { ...@@ -192,6 +204,8 @@ func GenerateKey(rand io.Reader, bits int) (priv *PrivateKey, err os.Error) {
return; return;
} }
*/
// incCounter increments a four byte, big-endian counter. // incCounter increments a four byte, big-endian counter.
func incCounter(c *[4]byte) { func incCounter(c *[4]byte) {
if c[3]++; c[3] != 0 { if c[3]++; c[3] != 0 {
......
...@@ -5,13 +5,17 @@ ...@@ -5,13 +5,17 @@
package rsa package rsa
import ( import (
"big";
"bytes"; "bytes";
"crypto/sha1"; "crypto/sha1";
big "gmp";
"os"; "os";
"testing"; "testing";
) )
/*
TODO(agl): Enable once big implements ProbablyPrime.
func TestKeyGeneration(t *testing.T) { func TestKeyGeneration(t *testing.T) {
urandom, err := os.Open("/dev/urandom", os.O_RDONLY, 0); urandom, err := os.Open("/dev/urandom", os.O_RDONLY, 0);
if err != nil { if err != nil {
...@@ -42,6 +46,8 @@ func TestKeyGeneration(t *testing.T) { ...@@ -42,6 +46,8 @@ func TestKeyGeneration(t *testing.T) {
} }
} }
*/
type testEncryptOAEPMessage struct { type testEncryptOAEPMessage struct {
in []byte; in []byte;
seed []byte; seed []byte;
......
...@@ -9,9 +9,9 @@ package x509 ...@@ -9,9 +9,9 @@ package x509
import ( import (
"asn1"; "asn1";
"big";
"crypto/rsa"; "crypto/rsa";
"os"; "os";
big "gmp";
) )
// pkcs1PrivateKey is a structure which mirrors the PKCS#1 ASN.1 for an RSA private key. // pkcs1PrivateKey is a structure which mirrors the PKCS#1 ASN.1 for an RSA private key.
......
...@@ -5,12 +5,12 @@ ...@@ -5,12 +5,12 @@
package x509 package x509
import ( import (
"big";
"crypto/rsa"; "crypto/rsa";
"encoding/pem"; "encoding/pem";
"reflect"; "reflect";
"strings"; "strings";
"testing"; "testing";
big "gmp";
) )
func TestParsePKCS1PrivateKey(t *testing.T) { func TestParsePKCS1PrivateKey(t *testing.T) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment