You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.0 KiB

5 years ago
  1. ## ECC ElGamal
  2. - https://en.wikipedia.org/wiki/ElGamal_encryption
  3. - [x] ECC ElGamal key generation
  4. - [x] ECC ElGamal Encrypton
  5. - [x] ECC ElGamal Decryption
  6. #### Usage
  7. - NewEG, Encryption, Decryption
  8. ```go
  9. // define new elliptic curve
  10. ec := ecc.NewEC(big.NewInt(int64(1)), big.NewInt(int64(18)), big.NewInt(int64(19)))
  11. // define new point
  12. g := ecc.Point{big.NewInt(int64(7)), big.NewInt(int64(11))}
  13. // define new ElGamal crypto system with the elliptic curve and the point
  14. eg, err := NewEG(ec, g)
  15. if err!=nil {
  16. fmt.Println(err)
  17. }
  18. // define privK&pubK over the elliptic curve
  19. privK := big.NewInt(int64(5))
  20. pubK, err := eg.PubK(privK)
  21. if err!=nil {
  22. fmt.Println(err)
  23. }
  24. // define point to encrypt
  25. m := ecc.Point{big.NewInt(int64(11)), big.NewInt(int64(12))}
  26. // encrypt
  27. c, err := eg.Encrypt(m, pubK, big.NewInt(int64(15)))
  28. if err!=nil {
  29. fmt.Println(err)
  30. }
  31. // decrypt
  32. d, err := eg.Decrypt(c, privK)
  33. if err!=nil {
  34. fmt.Println(err)
  35. }
  36. // check that decryption is correct
  37. if !m.Equal(d) {
  38. fmt.Println("decrypted not equal to original")
  39. }
  40. ```