Skip to content

pseusys/monocypher-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Monocypher-Go

Inspired by pymonocypher.

GO bindings for monocypher.

Originally, a part of SeasideVPN project.

Preamble

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.

Version

The package depends on Monocypher version 4.0.2. 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 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.

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

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 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:

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). Feel free to contribute any other high-end bindings you need!

Licenses

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

  1. Source library code: monocypher license.
  2. High-level borrowed from: pymonocypher license.
  3. The generated bindings code: c-for-go generated license.