aes.go 709 B

123456789101112131415161718192021222324252627282930
  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. block, err := aes.NewCipher(tools.Bytes32(p.X()))
  9. if err != nil {
  10. return nil, err
  11. }
  12. iv := tools.Bytes32(p.Y())[:aes.BlockSize]
  13. stream := cipher.NewCFBEncrypter(block, iv)
  14. stream.XORKeyStream(data, data)
  15. return data, nil
  16. }
  17. func aesDecode(encrypted []byte, p *tools.Point) ([]byte, error) {
  18. block, err := aes.NewCipher(tools.Bytes32(p.X()))
  19. if err != nil {
  20. return nil, err
  21. }
  22. iv := tools.Bytes32(p.Y())[:aes.BlockSize]
  23. stream := cipher.NewCFBDecrypter(block, iv)
  24. stream.XORKeyStream(encrypted, encrypted)
  25. return encrypted, nil
  26. }