Add gitignore and WIP tests
This commit is contained in:
parent
f89b327373
commit
ea8241b0f7
3 changed files with 53 additions and 15 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
.*
|
||||
!.gitignore
|
|
@ -1,4 +1,4 @@
|
|||
package main
|
||||
package sodium
|
||||
|
||||
/*
|
||||
#cgo CFLAGS: -g -Wall
|
||||
|
@ -6,28 +6,51 @@ package main
|
|||
#include <sodium.h>
|
||||
*/
|
||||
import "C"
|
||||
import "log"
|
||||
import "unsafe"
|
||||
|
||||
const block_size int = 16 * 1024 // 16 KiB
|
||||
const KeyLen int = C.crypto_secretstream_xchacha20poly1305_KEYBYTES
|
||||
const BlockSize int = 16 * 1024 // 16 KiB
|
||||
|
||||
// Should take a reader as input and be a reader
|
||||
func GenerateKey() [KeyLen]byte {
|
||||
var key [KeyLen]byte
|
||||
keywrap := (*C.uchar)(unsafe.Pointer(&key[0]))
|
||||
C.crypto_secretstream_xchacha20poly1305_keygen(keywrap)
|
||||
return key
|
||||
}
|
||||
/*
|
||||
// Maybe use io.Pipe() for io.Writer
|
||||
|
||||
func (*Saliere) Read(p []byte) (n int, err error)
|
||||
type SecretStreamEncode struct {
|
||||
src io.Reader
|
||||
state C.crypto_secretstream_xchacha20poly1305_state
|
||||
}
|
||||
|
||||
func main() {
|
||||
log.Println("Test cgo")
|
||||
type SecretStreamDecode struct {
|
||||
src io.Reader
|
||||
state C.crypto_secretstream_xchacha20poly1305_state
|
||||
}
|
||||
|
||||
func NewSecretStreamEncode(key []byte, src io.Reader) *SecretStream {
|
||||
// it's ok to call init multiple times according to sodium doc
|
||||
ret := C.sodium_init()
|
||||
if ret < 0 {
|
||||
log.Panic("Failed to init sodium.")
|
||||
}
|
||||
//unsigned char array as requested
|
||||
var key [C.crypto_secretstream_xchacha20poly1305_KEYBYTES]C.uchar
|
||||
C.crypto_secretstream_xchacha20poly1305_keygen(&key[0])
|
||||
if ret < 0 { log.Panic("Failed to init sodium.") }
|
||||
|
||||
var state C.crypto_secretstream_xchacha20poly1305_state
|
||||
s := { src: src}
|
||||
var header [C.crypto_secretstream_xchacha20poly1305_HEADERBYTES]C.uchar
|
||||
C.crypto_secretstream_xchacha20poly1305_init_push(&s.state, &header[0], &key[0])
|
||||
// @FIXME do something with header
|
||||
|
||||
return &s
|
||||
}
|
||||
|
||||
// Encode
|
||||
func (s *SecretStream) Read(p []byte) (n int, err error) {
|
||||
s/
|
||||
}
|
||||
*/
|
||||
/*
|
||||
func main() {
|
||||
|
||||
C.crypto_secretstream_xchacha20poly1305_init_push(&state, &header[0], &key[0])
|
||||
log.Print("key", key)
|
||||
log.Print("header", header)
|
||||
|
||||
|
@ -37,3 +60,4 @@ func main() {
|
|||
C.crypto_secretstream_xchacha20poly1305_push(&state, &c1[0], nil, &plain[0], C.ulonglong(len(plain)), nil, 0, 0)
|
||||
log.Print("c1", c1)
|
||||
}
|
||||
*/
|
||||
|
|
12
sodium/secret_stream_test.go
Normal file
12
sodium/secret_stream_test.go
Normal file
|
@ -0,0 +1,12 @@
|
|||
package sodium
|
||||
|
||||
import "testing"
|
||||
import "log"
|
||||
|
||||
func TestGenerateKey(t *testing.T) {
|
||||
k := GenerateKey()
|
||||
if len(k) != KeyLen {
|
||||
t.Errorf("Wrong keylen %d instead of %d", len(k), KeyLen)
|
||||
}
|
||||
log.Printf("Generated Key: %v", k)
|
||||
}
|
Loading…
Reference in a new issue