~juju-qa/ubuntu/xenial/juju/2.0-rc2

« back to all changes in this revision

Viewing changes to src/golang.org/x/crypto/ssh/cipher.go

  • Committer: Nicholas Skaggs
  • Date: 2016-09-30 14:39:30 UTC
  • mfrom: (1.8.1)
  • Revision ID: nicholas.skaggs@canonical.com-20160930143930-vwwhrefh6ftckccy
import upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
import (
8
8
        "crypto/aes"
9
9
        "crypto/cipher"
 
10
        "crypto/des"
10
11
        "crypto/rc4"
11
12
        "crypto/subtle"
12
13
        "encoding/binary"
115
116
        // should invest a cleaner way to do this.
116
117
        gcmCipherID: {16, 12, 0, nil},
117
118
 
118
 
        // insecure cipher, see http://www.isg.rhul.ac.uk/~kp/SandPfinal.pdf
119
 
        // uncomment below to enable it.
120
 
        // aes128cbcID: {16, aes.BlockSize, 0, nil},
 
119
        // CBC mode is insecure and so is not included in the default config.
 
120
        // (See http://www.isg.rhul.ac.uk/~kp/SandPfinal.pdf). If absolutely
 
121
        // needed, it's possible to specify a custom Config to enable it.
 
122
        // You should expect that an active attacker can recover plaintext if
 
123
        // you do.
 
124
        aes128cbcID: {16, aes.BlockSize, 0, nil},
 
125
 
 
126
        // 3des-cbc is insecure and is disabled by default.
 
127
        tripledescbcID: {24, des.BlockSize, 0, nil},
121
128
}
122
129
 
123
130
// prefixLen is the length of the packet prefix that contains the packet length
365
372
        oracleCamouflage uint32
366
373
}
367
374
 
368
 
func newAESCBCCipher(iv, key, macKey []byte, algs directionAlgorithms) (packetCipher, error) {
369
 
        c, err := aes.NewCipher(key)
370
 
        if err != nil {
371
 
                return nil, err
372
 
        }
373
 
 
 
375
func newCBCCipher(c cipher.Block, iv, key, macKey []byte, algs directionAlgorithms) (packetCipher, error) {
374
376
        cbc := &cbcCipher{
375
377
                mac:        macModes[algs.MAC].new(macKey),
376
378
                decrypter:  cipher.NewCBCDecrypter(c, iv),
384
386
        return cbc, nil
385
387
}
386
388
 
 
389
func newAESCBCCipher(iv, key, macKey []byte, algs directionAlgorithms) (packetCipher, error) {
 
390
        c, err := aes.NewCipher(key)
 
391
        if err != nil {
 
392
                return nil, err
 
393
        }
 
394
 
 
395
        cbc, err := newCBCCipher(c, iv, key, macKey, algs)
 
396
        if err != nil {
 
397
                return nil, err
 
398
        }
 
399
 
 
400
        return cbc, nil
 
401
}
 
402
 
 
403
func newTripleDESCBCCipher(iv, key, macKey []byte, algs directionAlgorithms) (packetCipher, error) {
 
404
        c, err := des.NewTripleDESCipher(key)
 
405
        if err != nil {
 
406
                return nil, err
 
407
        }
 
408
 
 
409
        cbc, err := newCBCCipher(c, iv, key, macKey, algs)
 
410
        if err != nil {
 
411
                return nil, err
 
412
        }
 
413
 
 
414
        return cbc, nil
 
415
}
 
416
 
387
417
func maxUInt32(a, b int) uint32 {
388
418
        if a > b {
389
419
                return uint32(a)