Skip to content

Commit

Permalink
Added key derivation
Browse files Browse the repository at this point in the history
  • Loading branch information
David Michael committed Jun 18, 2017
1 parent c3faa9a commit 355e5dc
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions cryptokdf/crypto_kdf.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package cryptokdf

// #cgo pkg-config: libsodium
// #include <stdlib.h>
// #include <sodium.h>
import "C"
import "github.com/GoKillers/libsodium-go/support"

func CryptoKdfKeybytes() int {
return int(C.crypto_kdf_keybytes())
}

func CryptoKdfContextbytes() int {
return int(C.crypto_kdf_contextbytes())
}

func CryptoKdfBytesMin() int {
return int(C.crypto_kdf_bytes_min())
}

func CryptoKdfBytesMax() int {
return int(C.crypto_kdf_bytes_max())
}

func CryptoKdfKeygen(k []byte) {
support.CheckSize(k, CryptoKdfKeybytes(), "keybytes")
C.crypto_kdf_keygen((*C.uchar)(&k[0]))
}

func CryptoKdfDeriveFromKey(l int, i uint64, c string, k []byte) ([]byte, int) {
support.CheckSize(k, CryptoKdfKeybytes(), "keybytes")
support.CheckSize([]byte(c), CryptoKdfContextbytes(), "contextbytes")
support.CheckSizeInRange(l, CryptoKdfBytesMin(), CryptoKdfBytesMax(), "subkey_len")
out := make([]byte, l)

exit := int(C.crypto_kdf_derive_from_key(
(*C.uchar)(&out[0]),
(C.size_t)(l),
(C.uint64_t)(i),
C.CString(c),
(*C.uchar)(&k[0])))

return out, exit
}

0 comments on commit 355e5dc

Please sign in to comment.