Giter Club home page Giter Club logo

sodium's Introduction

sodium

A wrapper for libsodium in golang

See documents GoDoc.

Currently this is build against libsodium 1.0.18.

Following functions included:

  • crypto_auth crypto_auth_verify
  • crypto_sign_keypair crypto_sign_seed_keypair crypto_sign_ed25519_sk_to_seed crypto_sign_ed25519_sk_to_pk
  • crypto_sign crypto_sign_open crypto_sign_detached crypto_sign_verify_detached
  • crypto_sign_init crypto_sign_update crypto_sign_final_create crypto_sign_final_verify
  • crypto_sign_ed25519_sk_to_curve25519 crypto_sign_ed25519_pk_to_curve25519
  • crypto_scalarmult_base crypto_scalarmult
  • crypto_box_keypair crypto_box_seed_keypair
  • crypto_box_seal crypto_box_seal_open
  • crypto_box_easy crypto_box_open_easy crypto_box_detached crypto_box_open_detached
  • crypto_secretbox_easy crypto_secretbox_open_easy crypto_secretbox_detached crypto_secretbox_open_detached
  • crypto_pwhash crypto_pwhash_str crypto_pwhash_str_verify
  • crypto_pwhash_opslimit_interactive crypto_pwhash_memlimit_interactive
  • crypto_pwhash_opslimit_moderate crypto_pwhash_memlimit_moderate
  • crypto_pwhash_opslimit_sensitive crypto_pwhash_memlimit_sensitive
  • crypto_shorthash crypto_generichash_init crypto_generichash_update crypto_generichash_final
  • crypto_kdf_keygen crypto_kdf_derive_from_key
  • crypto_kx_keypair crypto_kx_seed_keypair crypto_kx_server_session_keys crypto_kx_client_session_keys
  • crypto_aead_chacha20poly1305_ietf_keygen crypto_aead_chacha20poly1305_ietf_encrypt crypto_aead_chacha20poly1305_ietf_decrypt
  • crypto_aead_chacha20poly1305_ietf_encrypt_detached crypto_aead_chacha20poly1305_ietf_decrypt_detached
  • crypto_aead_xchacha20poly1305_ietf_keygen crypto_aead_xchacha20poly1305_ietf_encrypt crypto_aead_xchacha20poly1305_ietf_decrypt
  • crypto_aead_xchacha20poly1305_ietf_encrypt_detached crypto_aead_xchacha20poly1305_ietf_decrypt_detached
  • crypto_secretstream_xchacha20poly1305_keygen crypto_secretstream_xchacha20poly1305_push_init crypto_secretstream_xchacha20poly1305_push
  • crypto_secretstream_xchacha20poly1305_pull_init crypto_secretstream_xchacha20poly1305_pull
  • sodium_memzero sodium_memcmp sodium_increment

NOTE: This is a modified and enhanced version based on github.com/GoKillers/libsodium-go. Because there're a lot of package reformat and interface changes, I'd like to launch a new project. Thankfully, the original author permits reuse its code as long as the original LICENSE remains. You can find the LICENSE.original and README.original.md stating the original license. And this version is released under MIT License.

sodium's People

Contributors

jamesruan avatar zean00 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sodium's Issues

sodium_add?

I'm trying to implement a client-server webSocket pair which uses Diffie-Hellman key exchange to establish a common key and sodium.SecretBox/sodium.SecretBoxOpen to encrypt the data between them. The nonce on the server always starts at 0 and increments by 2 and on the client starts at 1 and increments by 2. So on the server the nonce will be 0,2,4,6... and on the client the nonce will be 1,3,5,7...

Is it possible to include sodium_add and perhaps have Nonce implement a Add(size int) function? I am currently calling Next() twice for each nonce and that seems a bit inelegant.

Thank you.

could not determine kind of name for C.crypto_kx_client_session_keys

My Dockerfile:

FROM s390x/golang
WORKDIR /go/src/app
ADD BusinessLogicServices .
RUN apt-get update
RUN apt-get install -y libsodium-dev
RUN go get -d -v ./...
RUN go run -v ./...

inside my BusineesLogicService there is file crypto.go which imports a golang libsodium library
package main

import (
"github.com/jamesruan/sodium"
)

and inside "github.com/jamesruan/sodium" there is file exchange.go which contains following

package sodium

// #cgo pkg-config: libsodium
// #include <stdlib.h>
// #include <sodium.h>
import "C"

var (
cryptoKXPublicKeyBytes = int(C.crypto_kx_publickeybytes())
cryptoKXSecretKeyBytes = int(C.crypto_kx_secretkeybytes())
cryptoKXSeedBytes = int(C.crypto_kx_seedbytes())
cryptoKXSessionKeyBytes = int(C.crypto_kx_sessionkeybytes())
)

output of docker build -t abc .
Step 7/7 : RUN go run -v ./...
---> Running in a805355aaa6a
../github.com/jamesruan/sodium/exchange.go:9:32: could not determine kind of name for C.crypto_kx_publickeybytes

HOST OS = Ubuntu 18.04

docker version:
Client:
Version: 17.12.1-ce
API version: 1.35
Go version: go1.10.1
Git commit: 7390fc6
Built: Wed Apr 18 01:22:24 2018
OS/Arch: linux/s390x

Server:
Engine:
Version: 18.06.1-ce
API version: 1.38 (minimum version 1.12)
Go version: go1.10.4
Git commit: e68fc7a
Built: Mon Oct 1 14:06:53 2018
OS/Arch: linux/s390x
Experimental: false

If i run it without docker containers then it works.

SecretBoxOpen panic on empty message

If the remote ends encrypts a 0 byte plain text (yielding just the 16 cryptoSecretBoxMacBytes bytes), this happens:

panic: runtime error: index out of range

goroutine 1 [running]:
github.com/jamesruan/sodium.Bytes.SecretBoxOpen(0xc42008a3e0, 0x10, 0x10, 0xc4200a20e0, 0x18, 0x20, 0xc4200a4030, 0x20, 0x21, 0xc4200a2120, ...)
	/Users/peter/go/src/github.com/jamesruan/sodium/secretbox.go:69 +0x26f

To make sure I wasn't doing anything weird, I tested golang.org/x/crypto/nacl/secretbox which correctly gives me zero bytes.

commit ba4580b963e28a6914afc33c847b183070030dfb (HEAD -> master, tag: 1.0.12, origin/master, origin/HEAD)

undefined: GenericHashKey

Getting following error while compiling:

# github.com/jamesruan/sodium
../../../../go/pkg/mod/github.com/jamesruan/[email protected]/support.go:12:8: undefined: GenericHashKey
../../../../go/pkg/mod/github.com/jamesruan/[email protected]/support.go:14:15: undefined: cryptoGenericHashBytesMin
../../../../go/pkg/mod/github.com/jamesruan/[email protected]/support.go:14:42: undefined: cryptoGenericHashBytesMax
../../../../go/pkg/mod/github.com/jamesruan/[email protected]/support.go:16:8: undefined: SubKey
../../../../go/pkg/mod/github.com/jamesruan/[email protected]/support.go:18:15: undefined: CryptoKDFBytesMin
../../../../go/pkg/mod/github.com/jamesruan/[email protected]/support.go:18:34: undefined: CryptoKDFBytesMax

Using libsodium 1.0.18

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.