aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/golang.org/x/crypto/openpgp/packet/packet.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/golang.org/x/crypto/openpgp/packet/packet.go')
-rw-r--r--vendor/golang.org/x/crypto/openpgp/packet/packet.go44
1 files changed, 29 insertions, 15 deletions
diff --git a/vendor/golang.org/x/crypto/openpgp/packet/packet.go b/vendor/golang.org/x/crypto/openpgp/packet/packet.go
index 3eded93..5af64c5 100644
--- a/vendor/golang.org/x/crypto/openpgp/packet/packet.go
+++ b/vendor/golang.org/x/crypto/openpgp/packet/packet.go
@@ -11,10 +11,12 @@ import (
11 "crypto/aes" 11 "crypto/aes"
12 "crypto/cipher" 12 "crypto/cipher"
13 "crypto/des" 13 "crypto/des"
14 "golang.org/x/crypto/cast5" 14 "crypto/rsa"
15 "golang.org/x/crypto/openpgp/errors"
16 "io" 15 "io"
17 "math/big" 16 "math/big"
17
18 "golang.org/x/crypto/cast5"
19 "golang.org/x/crypto/openpgp/errors"
18) 20)
19 21
20// readFull is the same as io.ReadFull except that reading zero bytes returns 22// readFull is the same as io.ReadFull except that reading zero bytes returns
@@ -402,14 +404,16 @@ const (
402type PublicKeyAlgorithm uint8 404type PublicKeyAlgorithm uint8
403 405
404const ( 406const (
405 PubKeyAlgoRSA PublicKeyAlgorithm = 1 407 PubKeyAlgoRSA PublicKeyAlgorithm = 1
406 PubKeyAlgoRSAEncryptOnly PublicKeyAlgorithm = 2 408 PubKeyAlgoElGamal PublicKeyAlgorithm = 16
407 PubKeyAlgoRSASignOnly PublicKeyAlgorithm = 3 409 PubKeyAlgoDSA PublicKeyAlgorithm = 17
408 PubKeyAlgoElGamal PublicKeyAlgorithm = 16
409 PubKeyAlgoDSA PublicKeyAlgorithm = 17
410 // RFC 6637, Section 5. 410 // RFC 6637, Section 5.
411 PubKeyAlgoECDH PublicKeyAlgorithm = 18 411 PubKeyAlgoECDH PublicKeyAlgorithm = 18
412 PubKeyAlgoECDSA PublicKeyAlgorithm = 19 412 PubKeyAlgoECDSA PublicKeyAlgorithm = 19
413
414 // Deprecated in RFC 4880, Section 13.5. Use key flags instead.
415 PubKeyAlgoRSAEncryptOnly PublicKeyAlgorithm = 2
416 PubKeyAlgoRSASignOnly PublicKeyAlgorithm = 3
413) 417)
414 418
415// CanEncrypt returns true if it's possible to encrypt a message to a public 419// CanEncrypt returns true if it's possible to encrypt a message to a public
@@ -500,19 +504,17 @@ func readMPI(r io.Reader) (mpi []byte, bitLength uint16, err error) {
500 numBytes := (int(bitLength) + 7) / 8 504 numBytes := (int(bitLength) + 7) / 8
501 mpi = make([]byte, numBytes) 505 mpi = make([]byte, numBytes)
502 _, err = readFull(r, mpi) 506 _, err = readFull(r, mpi)
503 return 507 // According to RFC 4880 3.2. we should check that the MPI has no leading
504} 508 // zeroes (at least when not an encrypted MPI?), but this implementation
505 509 // does generate leading zeroes, so we keep accepting them.
506// mpiLength returns the length of the given *big.Int when serialized as an
507// MPI.
508func mpiLength(n *big.Int) (mpiLengthInBytes int) {
509 mpiLengthInBytes = 2 /* MPI length */
510 mpiLengthInBytes += (n.BitLen() + 7) / 8
511 return 510 return
512} 511}
513 512
514// writeMPI serializes a big integer to w. 513// writeMPI serializes a big integer to w.
515func writeMPI(w io.Writer, bitLength uint16, mpiBytes []byte) (err error) { 514func writeMPI(w io.Writer, bitLength uint16, mpiBytes []byte) (err error) {
515 // Note that we can produce leading zeroes, in violation of RFC 4880 3.2.
516 // Implementations seem to be tolerant of them, and stripping them would
517 // make it complex to guarantee matching re-serialization.
516 _, err = w.Write([]byte{byte(bitLength >> 8), byte(bitLength)}) 518 _, err = w.Write([]byte{byte(bitLength >> 8), byte(bitLength)})
517 if err == nil { 519 if err == nil {
518 _, err = w.Write(mpiBytes) 520 _, err = w.Write(mpiBytes)
@@ -525,6 +527,18 @@ func writeBig(w io.Writer, i *big.Int) error {
525 return writeMPI(w, uint16(i.BitLen()), i.Bytes()) 527 return writeMPI(w, uint16(i.BitLen()), i.Bytes())
526} 528}
527 529
530// padToKeySize left-pads a MPI with zeroes to match the length of the
531// specified RSA public.
532func padToKeySize(pub *rsa.PublicKey, b []byte) []byte {
533 k := (pub.N.BitLen() + 7) / 8
534 if len(b) >= k {
535 return b
536 }
537 bb := make([]byte, k)
538 copy(bb[len(bb)-len(b):], b)
539 return bb
540}
541
528// CompressionAlgo Represents the different compression algorithms 542// CompressionAlgo Represents the different compression algorithms
529// supported by OpenPGP (except for BZIP2, which is not currently 543// supported by OpenPGP (except for BZIP2, which is not currently
530// supported). See Section 9.3 of RFC 4880. 544// supported). See Section 9.3 of RFC 4880.