Git Product home page Git Product logo

libsodium-go's Introduction

!This code requires an independent audit check!

libsodium-go

A binding library made in Go for the popular portable cryptography library Sodium.

Purpose

The goal of this binding library is to make use of Sodium in a more Go friendly matter. And of course making it easier to make secure software.

Team (as of now...)

  • Stephen Chavez (@redragonx)
  • Graham Smith (@neuegram)

Contributors

Silkeh

How to build

For linux, this should be easy since there's pkg-config support. Please make sure libsodium is installed on your system first.

Pre-setup:

  1. Please install Libsodium here https://download.libsodium.org/doc/installation/index.html
  2. sudo ldconfig
  3. sudo apt-get install pkg-config

Install libsodium-go:

  1. go get -d github.com/GoKillers/libsodium-go
  2. cd $GOPATH/src/github.com/GoKillers/libsodium-go
  3. ./build.sh

For Windows, this requires a little more work.

  1. Download and install pkg-config for win32 or win64
  2. Add a system or user variable PKG_CONFIG_PATH pointing to a folder containing pkg-config files, including libsodium
  3. go get -d github.com/GoKillers/libsodium-go
  4. cd %GOPATH%/src/github.com/GoKillers/libsodium-go
  5. build.bat

License

Copyright 2015 - GoKillers

libsodium-go's People

Contributors

alexbakker avatar elimisteve avatar impyy avatar jedisct1 avatar mtaylor91 avatar neuegram avatar redragonx avatar silkeh 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  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  avatar

libsodium-go's Issues

Unable to generate `RandomBytes` on OSX

Calling randombytes.RandomBytes(24) returns the following error:

../../pkg/mod/github.com/!go!killers/[email protected]/randombytes/randombytes.go:79:77: cannot take the address of _Cmacro_randombytes_salsa20_implementation()

Thanks for the port. Any help to resolve this would be much appreciated! ๐Ÿ™

Byte mismatch

Why am I not getting the same bytes in decPlain as in the slice plain, when decrypting the message?

pk, sk, err := cryptobox.CryptoBoxKeyPair()
if err != 0 {
    panic("error generating keys")
}

fmt.Printf("plain: [% x] \n", plain)
nonce := make([]byte, 24)
binary.BigEndian.PutUint64(nonce, 0)

testMsg, err := cryptobox.CryptoBoxEasy(plain, nonce, pk, sk)
if err != 0 {
    panic("error encrypting")
}
fmt.Printf("testMsg: [% x] \n", testMsg)

decPlain, err := cryptobox.CryptoBoxOpenEasy(testMsg, nonce, pk, sk)
if err != 0 {
    panic("error decrypting")
}
fmt.Printf("decPlain: [% x] \n", decPlain)

plain: [0a 40 0a 15 43 6c 69 65 6e 74 48 65 6c 6c 6f 5f 48 61 6e 64 73 68 61 6b 65 12 20 3b ef 6e e0 ef d4 f2 3e 72 04 bd eb 81 03 06 ed 04 45 ed 4e f3 90 20 37 f5 1f 8f 32 9b 2e fa 17 1a 03 6c 6f 6c 20 2a]

testMsg: [c9 aa 34 b9 05 ee 59 b4 e8 8e 91 fa d3 c0 48 dc f8 c2 20 ca b0 6a 85 a4 67 6b 68 78 3b 0f 76 e1 6e d9 ec 1b b1 c6 18 1a e3 45 1f 2f 79 4f b2 13 56 20 b3 f4 44 8a d3 93 80 5f 5f 0f 62 4f 78 d3 7c 30 f3 74 f9 52 a3 80 d0 f8 c0 e0 4f 60 51 6f 52 50]

decPlain: [4c 90 83 1b 42 91 8d 5e a0 df 41 52 7f 07 75 a6 3b 28 1e 66 f6 e8 b5 75 e1 91 b1 e7 84 a3 51 62 de 7a a2 b5 72 c4 fc d5 e1 3c 57 6c ad 2e 24 1d ec 0b 61 9d f1 f1 20 08 60 1c ad 24 5e ed 84 33 ba 30]

Is this library still maintained?

Hi, I'm currently trying to tidy up the bindings linked on the libsodium website. If this library is still maintained, then please let me know; otherwise, the link to this library will likely be removed from the bindings page to help users find up to date and maintained bindings.

Hashing an empty slice leads to panic

Hi, this sample of code causes a crash on commit db67a0d:

hash, err := generichash.CryptoGenericHash(32, make([]byte, 0), nil)

runtime error: index out of range

I believe this is because of line 56 in crypto_generichash.go:

(*C.uchar)(&in[0]),

outdated ticket: Wrap status - 03/15/17

Please note this ticket may not represent the true status for everything! Sorry.

Here is the current status so far as of 07/30/15

libsodium

  • crypto_aead/chacha20poly1305/sodium/aead_chacha20poly1305.c
  • crypto_auth
    • some parts
  • crypto_box
    • curve25519xsalsa20poly1305
    • crypto_box.c
    • crypto_box_easy.c
    • crypto_box_seal.c
  • crypto_core
    • some parts
  • crypto_generichash
    • some parts
  • crypto_hash
  • crypto_onetimeauth
  • crypto_pwhash
  • crypto_scalarmult
    • curve25519
    • crypto_scalarmult.c
  • crypto_secretbox
  • crypto_shorthash
  • crypto_sign
  • crypto_stream
  • crypto_verify
  • randombytes
  • sodium
    • core.c
    • runtime.c
    • utils.c
    • version.c
  • Argon2

More detailed instructions

Hello I just thought it might be helpful to include some more detailed instructions like this.

install libsodium here https://download.libsodium.org/doc/installation/index.html
sudo ldconfig
sudo apt-get install pkg-config

go get -d github.com/GoKillers/libsodium-go
cd $GOPATH/src/github.com/GoKillers/libsodium-go
./build.sh

package main

import (
        "fmt"
        "github.com/GoKillers/libsodium-go/cryptosign"
)

func main() {

        fmt.Println(cryptosign.CryptoSignBytes())
}

Naming conventions

As golint helpfully points out:

func name will be used as randombytes.RandomBytesSeedBytes by other packages, and that stutters; consider calling this SeedBytes

It gets especially cumbersome with functions like: cryptoaead.CryptoAEADAES256GCMEncrypt.

Additionally, overlap in naming with with crypto/nacl could result in making this library a drop-in replacement.

I think the most convenient way to structure the packages would be crypto/box, crypto/aead/aes256gcm and crypto/stream/xsalsa20.

Renaming, however, does break backward compatibility in a major way.

GenericHash produces different value when compared to pynacl or sodium-native(JS)

Hi,
We are using different client libraries for libsodium, specifically, we use libsodium-go for Go projects and sodium-native for JavaScript projects. The operation of generic hashing produces different value in libsodium-go when compared to the same operation in sodium-native and pynacl. Initially, I thought it was due to some bug in sodium-native but pynacl also produce the same value as sodium-native, so the conclusion was it was specific to libsodium-go. Below is a very simple code for testing, I am not sure if I am missing some encoding or setting some parameters. Looking at the libsodium-go code for generichash, it is just making the C call so I am totally puzzled at why the values are different.

Also, I am ensuring that the libsodium linking is the same between all the tests, in this case, I am using 1.0.16

Go Code

package main

import (
	b64 "encoding/base64"
	"fmt"

	"github.com/GoKillers/libsodium-go/cryptogenerichash"
	"github.com/GoKillers/libsodium-go/sodium"
)

//Hash a Message and return Hash String as b64, Hash bytes
func HashSimple(message string) (hashString string, hashBytes []byte) {
	m := []byte(message)
	k := make([]byte, generichash.CryptoGenericHashKeyBytes())
	sodium.MemZero(k)

	hashBytes, _ = generichash.CryptoGenericHash(generichash.CryptoGenericHashBytes(), m, k)
	hashString = b64.StdEncoding.EncodeToString(hashBytes)
	return hashString, hashBytes
}

func main() {
	message := "T"
	hashString, hashBytes := HashSimple(message)
	fmt.Println(HashSimple(hashString))
	fmt.Printf("%x\n", hashBytes)
} 

Equivalent Python code using pynacl

from nacl.hash import blake2b
import base64
from binascii import unhexlify

def hextobase64(txt):
  raw = unhexlify(txt)
  return base64.b64encode(raw)


encodedStr = str.encode("T")
hash = blake2b(encodedStr)
hash64 = hextobase64(hash)
print(hash64)
print(hash)

Result from libsodium-go

eqgBf1Il5zRJaYnGDIkPr6fgkuacNfxJN3S4Aikb7Ck=
7aa8017f5225e734496989c60c890fafa7e092e69c35fc493774b802291bec29

Results from pynacl and sodium-native

b'iWEBxL5gXFXlQLCWfEBZeRt+TgpfKxGkYHTonIon62Y='
b'896101c4be605c55e540b0967c4059791b7e4e0a5f2b11a46074e89c8a27eb66'

Code from sodium-native for reference that produces the same output as pynacl

const sodium = require('/Users/jaye/projects/att3/sodium-native');

const hashMessage = (input) => {

const output = sodium.sodium_malloc(sodium.crypto_generichash_BYTES)
const data = Buffer.from("T",sodium.crypto_generichash_BYTES)
const key = sodium.sodium_malloc(sodium.crypto_generichash_KEYBYTES)
sodium.crypto_generichash(output, data)
return output

}
message = "T"
const hashOut = hashMessage(message)

console.log(hashOut.toString('base64'))
console.log(hashOut.toString('hex'))

Note that both b64 and bytes are different so it also not an issue with b64 encoding. Any suggestions to get the same behavior as other libsodium would be great because we really like the library and would like to use in Go program.

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.