| 248 | } |
| 249 | |
| 250 | func (s socket) createCipher(key []byte) (cipher.AEAD, cipher.AEAD, error) { |
| 251 | readCipher, readCipherErr := aes.NewCipher(key) |
| 252 | |
| 253 | if readCipherErr != nil { |
| 254 | return nil, nil, readCipherErr |
| 255 | } |
| 256 | |
| 257 | writeCipher, writeCipherErr := aes.NewCipher(key) |
| 258 | |
| 259 | if writeCipherErr != nil { |
| 260 | return nil, nil, writeCipherErr |
| 261 | } |
| 262 | |
| 263 | gcmRead, gcmReadErr := cipher.NewGCMWithNonceSize( |
| 264 | readCipher, socketGCMStandardNonceSize) |
| 265 | |
| 266 | if gcmReadErr != nil { |
| 267 | return nil, nil, gcmReadErr |
| 268 | } |
| 269 | |
| 270 | gcmWrite, gcmWriteErr := cipher.NewGCMWithNonceSize( |
| 271 | writeCipher, socketGCMStandardNonceSize) |
| 272 | |
| 273 | if gcmWriteErr != nil { |
| 274 | return nil, nil, gcmWriteErr |
| 275 | } |
| 276 | |
| 277 | return gcmRead, gcmWrite, nil |
| 278 | } |
| 279 | |
| 280 | func (s socket) privateKey() string { |
| 281 | if len(s.commonCfg.SharedKey) > 0 { |