An open API service indexing awesome lists of open source software.

https://github.com/pseusys/monocypher-go

Yet another monocypher bindings package for GO
https://github.com/pseusys/monocypher-go

bindings c c-for-go cgo go monocypher

Last synced: about 1 month ago
JSON representation

Yet another monocypher bindings package for GO

Awesome Lists containing this project

README

        

# Monocypher-Go

> Inspired by [`pymonocypher`](https://github.com/jetperch/pymonocypher).

GO bindings for [`monocypher`](https://monocypher.org/).

> Originally, a part of [`SeasideVPN`](https://github.com/pseusys/SeasideVPN) project.

## Preamble

Currently, there are no maintained GO bindings for [`monocypher`](https://github.com/LoupVaillant/Monocypher).
The only repository that I could google was [demonshreder/monocypher-go](https://github.com/demonshreder/monocypher-go) one, however it is marked as not maintained.
The proposed replacement was [HACKERALERT/Monocypher-Go](https://github.com/HACKERALERT/Monocypher-Go), however this repository is not currently accessible.
Its [go index](https://pkg.go.dev/github.com/HACKERALERT/monocypher-go) 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.

## Version

The package depends on Monocypher version [`4.0.2`](https://github.com/LoupVaillant/Monocypher/releases).
As for now, it is the latest version.

## Platforms

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!

## Generation

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.

### Requirements

This repository uses [`c-for-go`](https://github.com/xlab/c-for-go) for bindings generation.
It can normally be installed using this command:

```bash
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.

### Build

The bindings can be generated using `make generate` command.

This command can also be triggered normally by `go generate`, running `go generate ./...`.

## Usage

It is recommended to add this package as a [`submodule`](https://git-scm.com/book/en/v2/Git-Tools-Submodules) to your git project, directly to the go module requiring it.
Then, consider adding the following line to your `go.mod`:

```txt
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):

```shell
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.

### Contents

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](https://dave.cheney.net/2016/01/18/cgo-is-not-go) 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`](https://pkg.go.dev/golang.org/x/crypto/blake2b)
- SHA512: [`crypto/sha512`](https://pkg.go.dev/crypto/sha512)
- X25519: [`crypto/curve25519`](https://pkg.go.dev/golang.org/x/crypto/curve25519)
- Ed25519: [`crypto/ed25519`](https://pkg.go.dev/crypto/ed25519)
- (X)ChaCha20: [`crypto/chacha20`](https://pkg.go.dev/golang.org/x/crypto/chacha20)
- Poly1305: [`crypto/poly1305`](https://pkg.go.dev/golang.org/x/crypto/poly1305)
- (X)ChaCha20-Poly1305: [`crypto/chacha20poly1305`](https://pkg.go.dev/golang.org/x/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.

### Lower and Higher

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](https://github.com/jetperch/pymonocypher)).
Feel free to contribute any other high-end bindings you need!

## Licenses

This repository is published under [MIT license](./LICENCE) itself.
However, do not forget to check the licenses of the other libraries it heavily depends on:

1. Source library code: [`monocypher` license](https://github.com/LoupVaillant/Monocypher/blob/master/LICENCE.md).
2. High-level borrowed from: [`pymonocypher` license](https://github.com/jetperch/pymonocypher/blob/main/LICENSE.txt).
3. The generated bindings code: [`c-for-go` generated license](https://github.com/xlab/c-for-go/wiki/Generator-config-section#packagelicense).