aes.go 816 B

12345678910111213141516171819202122232425262728293031323334
  1. package dhellman
  2. import (
  3. "crypto/aes"
  4. "crypto/cipher"
  5. "git.ali33.ru/fcg-xvii/curve/v2/tools"
  6. )
  7. func aesEncode(data []byte, p *tools.Point) ([]byte, error) {
  8. rData := make([]byte, len(data))
  9. copy(rData, data)
  10. block, err := aes.NewCipher(tools.Bytes32(p.X()))
  11. if err != nil {
  12. return nil, err
  13. }
  14. iv := tools.Bytes32(p.Y())[:aes.BlockSize]
  15. stream := cipher.NewCFBEncrypter(block, iv)
  16. stream.XORKeyStream(rData, rData)
  17. return rData, nil
  18. }
  19. func aesDecode(encrypted []byte, p *tools.Point) ([]byte, error) {
  20. rData := make([]byte, len(encrypted))
  21. copy(rData, encrypted)
  22. block, err := aes.NewCipher(tools.Bytes32(p.X()))
  23. if err != nil {
  24. return nil, err
  25. }
  26. iv := tools.Bytes32(p.Y())[:aes.BlockSize]
  27. stream := cipher.NewCFBDecrypter(block, iv)
  28. stream.XORKeyStream(rData, rData)
  29. return rData, nil
  30. }