https://github.com/wolframalph/dh
Diffie-Hellman key exchange implementation in Go
https://github.com/wolframalph/dh
cryptography diffie-hellman golang
Last synced: 3 months ago
JSON representation
Diffie-Hellman key exchange implementation in Go
- Host: GitHub
- URL: https://github.com/wolframalph/dh
- Owner: WolframAlph
- License: apache-2.0
- Created: 2022-04-04T17:33:12.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-04-04T21:15:42.000Z (over 3 years ago)
- Last Synced: 2025-07-01T03:54:29.799Z (3 months ago)
- Topics: cryptography, diffie-hellman, golang
- Language: Go
- Homepage:
- Size: 15.6 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# dh
dh is a simple, ready to use Diffie-Hellman-Ephemeral implementation written in golang
using MODP groups as defined in [RFC3526](https://datatracker.ietf.org/doc/html/rfc3526).Example:
```go
package mainimport (
"fmt"
"reflect"
"github.com/WolframAlph/dh"
)
func main() {
alice := dh.New()
bob := dh.New()
aliceSecret := alice.ComputeSecret(bob.PublicKey)
bobSecret := bob.ComputeSecret(alice.PublicKey)
fmt.Println(reflect.DeepEqual(aliceSecret, bobSecret)) // true
}
```## Notes
You must use the same MODP group on both sides, or else you
end up with non-matching keys. Group #14 is used by default. You
can use different group from available (5, 14, 15, 16, 17, 18).
Example using other group:```go
package mainimport (
"fmt"
"reflect"
"github.com/WolframAlph/dh"
)
func main() {
modpGroup := 16
alice := dh.New(modpGroup)
bob := dh.New(modpGroup)
aliceSecret := alice.ComputeSecret(bob.PublicKey)
bobSecret := bob.ComputeSecret(alice.PublicKey)
fmt.Println(reflect.DeepEqual(aliceSecret, bobSecret)) // true
}
```Example using different groups:
```go
package mainimport (
"fmt"
"reflect"
"github.com/WolframAlph/dh"
)
func main() {
alice := dh.New(15)
bob := dh.New(18)
aliceSecret := alice.ComputeSecret(bob.PublicKey)
bobSecret := bob.ComputeSecret(alice.PublicKey)
fmt.Println(reflect.DeepEqual(aliceSecret, bobSecret)) // false
}
```