zenroom

package
v1.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 3, 2020 License: AGPL-3.0 Imports: 4 Imported by: 0

README

Zenroom-Go

Build Status GoDoc

Zenroom Binding for Go

Introduction

Zenroom is a brand new virtual machine for fast cryptographic operations on Elliptic Curves. The Zenroom VM has no external dependencies, includes a cutting edge selection of C99 libraries and builds a small executable ready to run on: desktop, embedded, mobile, cloud and browsers (webassembly). This library adds a CGO wrapper for Zenroom, which aims to make the Zenroom VM easy to use from Go.

Installation

Currently the bindings are only available for Linux machines, but if this is your current environment you should be able to just do:

$ go get github.com/DECODEproject/Zenroom/bindings/golang/zenroom

Usage

package main

import (
	"fmt"
	"log"

	"github.com/DECODEproject/Zenroom/bindings/golang/zenroom"
)

	genKeysScript := []byte(`
		keyring = ecdh.new('ec25519')
		keyring:keygen()
		
		output = JSON.encode({
			public = keyring:public():base64(),
			private = keyring:private():base64()
		})
		print(output)
	`)
	
	keys, err := zenroom.Exec(genKeysScript)
	if err != nil {
		log.Fatal(err)
	}
	log.Printf("Keys: %s", keys)

More Documentation

Contributors

The original Go bindings for Zenroom were created by @chespinoza, later updates by @smulube.

Documentation

Overview

Package zenroom is a CGO wrapper for the Zenroom virtual machine, which aims to make Zenroom easily usable from Go programs. Currently the C binary we wrap is only available for Linux.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ZencodeExec

func ZencodeExec(script []byte, options ...Option) ([]byte, error)

ZencodeExec is our primary public API method, and it is here that we call Zenroom's zencode_exec_tobuf function. This method attempts to pass a required script, and some optional extra parameters to the Zenroom virtual machine, where cryptographic operations are performed with the result being returned to the caller. The method signature has been tweaked slightly from the original function defined by Zenroom; rather than making all parameters required, instead we have just included as a required parameter the input SCRIPT, while all other properties must be supplied via one of the previously defined Option helpers.

Returns the output of the execution of the Zenroom virtual machine, or an error.

func ZenroomExec

func ZenroomExec(script []byte, options ...Option) ([]byte, error)

ZenroomExec is our primary public API method, and it is here that we call Zenroom's zenroom_exec_tobuf function. This method attempts to pass a required script, and some optional extra parameters to the Zenroom virtual machine, where cryptographic operations are performed with the result being returned to the caller. The method signature has been tweaked slightly from the original function defined by Zenroom; rather than making all parameters required, instead we have just included as a required parameter the input SCRIPT, while all other properties must be supplied via one of the previously defined Option helpers.

Returns the output of the execution of the Zenroom virtual machine, or an error.

Example
package main

import (
	"fmt"

	"github.com/DECODEproject/Zenroom/bindings/golang/zenroom"
)

func main() {
	script := []byte(`print("hello")`)
	res, _ := zenroom.ZenroomExec(script)
	fmt.Println(string(res))
}
Output:

hello

Types

type Option

type Option func(*config)

Option is a type alias we use to supply optional configuration to the primary Exec method this library exposes. Option is a functional configuration type alias for a function that takes as a parameter an unexported configuration object. Callers can supply keys, data, conf and verbosity via an Option using one of the WithXXX helper functions.

func WithConf

func WithConf(conf string) Option

WithConf is a configuration helper that allows the caller to pass in a value for the CONF parameter that Zenroom supports. The default for this value if not supplied is an empty string.

func WithData

func WithData(data []byte) Option

WithData is a configuration helper that allows the caller to pass in a value for the DATA parameter that Zenroom supports. The value of KEYS is a string, often but not required to be JSON formatted, containing data over which the script should operate. As with the KEYS property, DATA is passed separately from either the SCRIPT or the KEYS as these different values will often have different security requirements or may come from different sources. DATA must be passed as a byte slice.

func WithKeys

func WithKeys(keys []byte) Option

WithKeys is a configuration helper that allows the caller to pass in a value for the KEYS parameter that Zenroom supports. The value of KEYS is typically a string, often JSON formatted, that contains one or more keys that the primary script requires in order to operate. These are passed separately from the main script as they will typically have different security requirements than the main script contents. Keys must be passed in to the helper in a byte slice.

func WithVerbosity

func WithVerbosity(verbosity int) Option

WithVerbosity is a configuration helper that allows the caller to specify how verbose Zenroom should be with its output. The value of this configuration must be an integer from 1 to 3, where 1 is the least verbose, and 3 is the most. The default if this value is not supplied is 1.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL