Inspired by
pymonocypher
.
GO bindings for monocypher
.
Originally, a part of
SeasideVPN
project.
Currently, there are no maintained GO bindings for monocypher
.
The only repository that I could google was demonshreder/monocypher-go one, however it is marked as not maintained.
The proposed replacement was HACKERALERT/Monocypher-Go, however this repository is not currently accessible.
Its go index page, however, states:
Please note that I will not be adding new Monocypher functions or features, and that I will only fix security issues for this repository.
Well, I will support this repository of mine, if I have free time and also if I can.
The package depends on Monocypher version 4.0.2
.
As for now, it is the latest version.
This module is currently Linux-only and I do not think I will try to support any other platforms right now. However, all contributions are welcome!
This package does not include any compiled C binaries, ensuring platform-specific flexibility of sources.
However, as a downside, it can not be used as-is (using go install github.com/pseusys/monocypher-go@latest
command), instead it should be compiled from source.
No worries, however, the sources contain all the scripts required for binaries generation.
This repository uses c-for-go
for bindings generation.
It can normally be installed using this command:
go install github.com/xlab/c-for-go@latest
This package also (surprisingly!) uses CGO.
That is why something like build-essentials
package or whatever might be required, but who doesn't have them, right?
Also, make
, tar
and wget
are required for monocypher sources downloading and unpacking, but they should be normally available on any linux distribution.
The bindings can be generated using make generate
command.
This command can also be triggered normally by go generate
, running go generate ./...
.
It is recommended to add this package as a submodule
to your git project, directly to the go module requiring it.
Then, consider adding the following line to your go.mod
:
replace github.com/pseusys/monocypher-go => ./monocypher-go
That way the package imports (github.com/pseusys/monocypher-go
) will point to the local directory.
Finally, add this to your build pipeline (or just run it once):
make -C monocypher-go generate
You're all done! Package is ready for use and does not require any additional setup or runtime dependencies!
NB! Unlike normal CGO, package will be linked statically with the binary.
This package is not a translation of monocypher
to GO, it only provides bindings to C implementation.
The original package is cool and unique, however there are some serious issues with CGO. Use it at your own risk and be aware of the portability and performance issues that might arise!
In performance-critical environments, some of the GO-native implementations for some algorithms might be preferred:
- Blake2b:
crypto/blake2
- SHA512:
crypto/sha512
- X25519:
crypto/curve25519
- Ed25519:
crypto/ed25519
- (X)ChaCha20:
crypto/chacha20
- Poly1305:
crypto/poly1305
- (X)ChaCha20-Poly1305:
crypto/chacha20poly1305
Can they be used? Are they compatible? Who knows!
If you ask my personal opinion, I would suggest using this very package for elligator
implementation only.
The package includes the generated C bindings, all of them are public and available in monocypher_internal
subpackage.
Also, there are some of the higher-level functions implemented (the ones that I found useful in the Python bindings repository). Feel free to contribute any other high-end bindings you need!
This repository is published under MIT license itself. However, do not forget to check the licenses of the other libraries it heavily depends on:
- Source library code:
monocypher
license. - High-level borrowed from:
pymonocypher
license. - The generated bindings code:
c-for-go
generated license.