import (
"crypto/cipher"
- error_ "crypto/openpgp/error"
- "crypto/rand"
+ "crypto/openpgp/errors"
"crypto/sha1"
"crypto/subtle"
"hash"
return err
}
if buf[0] != symmetricallyEncryptedVersion {
- return error_.UnsupportedError("unknown SymmetricallyEncrypted version")
+ return errors.UnsupportedError("unknown SymmetricallyEncrypted version")
}
}
se.contents = r
func (se *SymmetricallyEncrypted) Decrypt(c CipherFunction, key []byte) (io.ReadCloser, error) {
keySize := c.KeySize()
if keySize == 0 {
- return nil, error_.UnsupportedError("unknown cipher: " + strconv.Itoa(int(c)))
+ return nil, errors.UnsupportedError("unknown cipher: " + strconv.Itoa(int(c)))
}
if len(key) != keySize {
- return nil, error_.InvalidArgumentError("SymmetricallyEncrypted: incorrect key length")
+ return nil, errors.InvalidArgumentError("SymmetricallyEncrypted: incorrect key length")
}
if se.prefix == nil {
return nil, err
}
} else if len(se.prefix) != c.blockSize()+2 {
- return nil, error_.InvalidArgumentError("can't try ciphers with different block lengths")
+ return nil, errors.InvalidArgumentError("can't try ciphers with different block lengths")
}
ocfbResync := cipher.OCFBResync
s := cipher.NewOCFBDecrypter(c.new(key), se.prefix, ocfbResync)
if s == nil {
- return nil, error_.KeyIncorrectError
+ return nil, errors.KeyIncorrectError
}
plaintext := cipher.StreamReader{S: s, R: se.contents}
func (ser *seMDCReader) Close() error {
if ser.error {
- return error_.SignatureError("error during reading")
+ return errors.SignatureError("error during reading")
}
for !ser.eof {
break
}
if err != nil {
- return error_.SignatureError("error during reading")
+ return errors.SignatureError("error during reading")
}
}
if ser.trailer[0] != mdcPacketTagByte || ser.trailer[1] != sha1.Size {
- return error_.SignatureError("MDC packet not found")
+ return errors.SignatureError("MDC packet not found")
}
ser.h.Write(ser.trailer[:2])
final := ser.h.Sum(nil)
if subtle.ConstantTimeCompare(final, ser.trailer[2:]) != 1 {
- return error_.SignatureError("hash mismatch")
+ return errors.SignatureError("hash mismatch")
}
return nil
}
// SerializeSymmetricallyEncrypted serializes a symmetrically encrypted packet
// to w and returns a WriteCloser to which the to-be-encrypted packets can be
// written.
-func SerializeSymmetricallyEncrypted(w io.Writer, c CipherFunction, key []byte) (contents io.WriteCloser, err error) {
+func SerializeSymmetricallyEncrypted(w io.Writer, rand io.Reader, c CipherFunction, key []byte) (contents io.WriteCloser, err error) {
if c.KeySize() != len(key) {
- return nil, error_.InvalidArgumentError("SymmetricallyEncrypted.Serialize: bad key length")
+ return nil, errors.InvalidArgumentError("SymmetricallyEncrypted.Serialize: bad key length")
}
writeCloser := noOpCloser{w}
ciphertext, err := serializeStreamHeader(writeCloser, packetTypeSymmetricallyEncryptedMDC)
block := c.new(key)
blockSize := block.BlockSize()
iv := make([]byte, blockSize)
- _, err = rand.Reader.Read(iv)
+ _, err = rand.Read(iv)
if err != nil {
return
}