Skip to content

Commit

Permalink
Merge pull request #27 from hoffin/master
Browse files Browse the repository at this point in the history
Key derivation >= 1.0.12
  • Loading branch information
redragonx authored Jun 21, 2017
2 parents c3faa9a + a0dd7f9 commit 548dff0
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions cryptokdf/crypto_kdf.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
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() []byte {
k := make([]byte, CryptoKdfKeybytes())
C.crypto_kdf_keygen((*C.uchar)(&k[0]))
return k
}

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 548dff0

Please sign in to comment.