diff options
author | Quentin Dufour <quentin@deuxfleurs.fr> | 2020-05-31 13:05:56 +0200 |
---|---|---|
committer | Quentin Dufour <quentin@deuxfleurs.fr> | 2020-05-31 13:05:56 +0200 |
commit | a2e1f61cf8b70f0e63fc6f8eddbbcf0477263f8f (patch) | |
tree | 2ba987a273cb56f3bb3dc4570c1a2e8798ce1757 | |
parent | 701da9ef260f3f451bd73f5829109652e587015a (diff) | |
download | infrastructure-a2e1f61cf8b70f0e63fc6f8eddbbcf0477263f8f.tar.gz infrastructure-a2e1f61cf8b70f0e63fc6f8eddbbcf0477263f8f.zip |
WIP sodium binding
-rw-r--r-- | docker/bckp/kv_to_s3.go | 1 | ||||
-rw-r--r-- | docker/bckp/sodium.go | 35 |
2 files changed, 36 insertions, 0 deletions
diff --git a/docker/bckp/kv_to_s3.go b/docker/bckp/kv_to_s3.go index 82dc96c..5b629b8 100644 --- a/docker/bckp/kv_to_s3.go +++ b/docker/bckp/kv_to_s3.go @@ -48,6 +48,7 @@ func main() { errIsPanic(err, "Unable to build a new client. %v", err) reader, _, err := consul.Snapshot().Save(&options) + defer reader.Close() errIsPanic(err, "Snapshot failed. %v", err) //--- Get encryption key and check it diff --git a/docker/bckp/sodium.go b/docker/bckp/sodium.go new file mode 100644 index 0000000..a4f25b4 --- /dev/null +++ b/docker/bckp/sodium.go @@ -0,0 +1,35 @@ +package main + +/* +#cgo CFLAGS: -g -Wall +#cgo LDFLAGS: -lsodium +#include <sodium.h> +*/ +import "C" +import "log" + +const block_size int = 16 * 1024 // 16 KiB + +func main() { + log.Println("Test cgo") + 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]) + + var state C.crypto_secretstream_xchacha20poly1305_state + var header [C.crypto_secretstream_xchacha20poly1305_HEADERBYTES]C.uchar + + C.crypto_secretstream_xchacha20poly1305_init_push(&state, &header[0], &key[0]) + log.Print("key", key) + log.Print("header", header) + + var plain [block_size]C.uchar + var c1 [block_size + C.crypto_secretstream_xchacha20poly1305_ABYTES]C.uchar + + C.crypto_secretstream_xchacha20poly1305_push(&state, &c1[0], nil, &plain[0], C.ulonglong(len(plain)), nil, 0, 0) + log.Print("c1", c1) +} |