Skip to content

Commit

Permalink
Update libhydrogen submodule, formatting (#2)
Browse files Browse the repository at this point in the history
* remove fmt script, use 1-liners for prototypes to avoid formatting annoyances

* add run-locallib to test against submodule

* update libhydrogen submodule

96d393b2109b99a469a98f4ad55936d35aa752f0
  • Loading branch information
someburner authored Apr 5, 2023
1 parent da3232d commit b57d0b4
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 45 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ all:
@echo "make libhydrogen | build libhydrogen"
@echo "make libhydrogen-clean | clean libhydrogen"
@echo "make run | run examples"
@echo "make run-locallib | run examples"

libhydrogen:
make -C libhydrogen
Expand All @@ -21,14 +22,17 @@ libhydrogen-clean:
################################################################################
.PHONY: fmt run test run_custom_ld rerun
fmt:
$(SHELL) scripts/cmd.sh "fmt"
go fmt ./...;

test:
env CGO_ENABLED=1 go test *_test.go

run:
env CGO_ENABLED=1 go run tests/main.go

run-locallib:
env CGO_ENABLED=1 CGO_LDFLAGS="-Llibhydrogen" CGO_CFLAGS="-Ilibhydrogen" go run tests/main.go

run_custom_ld:
env CGO_ENABLED=1 CGO_LDFLAGS="-L/path/to/libhydrogen" CGO_CFLAGS="-I/path/to/libhydrogen" go run tests/main.go

Expand Down
2 changes: 1 addition & 1 deletion core.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func CheckIntGtOrEq(n int, lower int, descrip string) {
}
}

//MemZero sets the buffer to zero
// MemZero sets the buffer to zero
func MemZero(buf []byte) {
if len(buf) > 0 {
C.hydro_memzero(unsafe.Pointer(&buf[0]), C.size_t(len(buf)))
Expand Down
2 changes: 1 addition & 1 deletion libhydrogen
30 changes: 6 additions & 24 deletions pwhash.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ func PwHashKeygen() []byte {
}

// Prototype:
// int hydro_pwhash_deterministic(uint8_t *h, size_t h_len, const char *passwd,
// size_t passwd_len, const char ctx[hydro_pwhash_CONTEXTBYTES],
// const uint8_t master_key[hydro_pwhash_MASTERKEYBYTES],
// uint64_t opslimit, size_t memlimit, uint8_t threads);
// int hydro_pwhash_deterministic(uint8_t *h, size_t h_len, const char *passwd, size_t passwd_len, const char ctx[hydro_pwhash_CONTEXTBYTES], const uint8_t master_key[hydro_pwhash_MASTERKEYBYTES], uint64_t opslimit, size_t memlimit, uint8_t threads);
func PwHashDeterministic(h_len int, passwd string, ctx string, master_key []byte, opslimit uint64) ([]byte, int) {
CheckIntGt(h_len, 0, "h_len")
CheckIntGt(len(passwd), 0, "len(passwd)")
Expand All @@ -55,10 +52,7 @@ func PwHashDeterministic(h_len int, passwd string, ctx string, master_key []byte
}

// Prototype:
// int hydro_pwhash_create(uint8_t stored[hydro_pwhash_STOREDBYTES],
// const char *passwd, size_t passwd_len,
// const uint8_t master_key[hydro_pwhash_MASTERKEYBYTES], uint64_t opslimit,
// size_t memlimit, uint8_t threads);
// int hydro_pwhash_create(uint8_t stored[hydro_pwhash_STOREDBYTES], const char *passwd, size_t passwd_len, const uint8_t master_key[hydro_pwhash_MASTERKEYBYTES], uint64_t opslimit, size_t memlimit, uint8_t threads);
func PwHashCreate(passwd string, master_key []byte, opslimit uint64, memlimit int, threads uint8) ([]byte, int) {
CheckIntGt(len(passwd), 0, "len(passwd)")
CheckSize(master_key, PwHashMasterKeyBytes, "master_key len")
Expand All @@ -78,10 +72,7 @@ func PwHashCreate(passwd string, master_key []byte, opslimit uint64, memlimit in
}

// Prototype:
// int hydro_pwhash_verify(const uint8_t stored[hydro_pwhash_STOREDBYTES],
// const char *passwd, size_t passwd_len,
// const uint8_t master_key[hydro_pwhash_MASTERKEYBYTES],
// uint64_t opslimit_max, size_t memlimit_max, uint8_t threads_max);
// int hydro_pwhash_verify(const uint8_t stored[hydro_pwhash_STOREDBYTES], const char *passwd, size_t passwd_len, const uint8_t master_key[hydro_pwhash_MASTERKEYBYTES], uint64_t opslimit_max, size_t memlimit_max, uint8_t threads_max);
func PwHashVerify(stored []byte, passwd string, master_key []byte, opslimit_max uint64, memlimit_max int, threads_max uint8) int {
CheckIntGt(len(passwd), 0, "len(passwd)")
CheckSize(stored, PwHashStoredBytes, "stored len")
Expand All @@ -101,12 +92,7 @@ func PwHashVerify(stored []byte, passwd string, master_key []byte, opslimit_max
}

// Prototype:
// int hydro_pwhash_derive_static_key(uint8_t *static_key,
// size_t static_key_len, const uint8_t stored[hydro_pwhash_STOREDBYTES],
// const char *passwd, size_t passwd_len,
// const char ctx[hydro_pwhash_CONTEXTBYTES],
// const uint8_t master_key[hydro_pwhash_MASTERKEYBYTES],
// uint64_t opslimit_max, size_t memlimit_max, uint8_t threads_max);
// int hydro_pwhash_derive_static_key(uint8_t *static_key, size_t static_key_len, const uint8_t stored[hydro_pwhash_STOREDBYTES], const char *passwd, size_t passwd_len, const char ctx[hydro_pwhash_CONTEXTBYTES], const uint8_t master_key[hydro_pwhash_MASTERKEYBYTES], uint64_t opslimit_max, size_t memlimit_max, uint8_t threads_max);
func PwHashDeriveStaticKey(static_key_len int, stored []byte, passwd string, ctx string, master_key []byte, opslimit_max uint64, memlimit_max int, threads_max uint8) ([]byte, int) {
CheckIntGt(static_key_len, 0, "len(static_key_len)")
CheckSize(stored, PwHashStoredBytes, "stored len")
Expand All @@ -133,9 +119,7 @@ func PwHashDeriveStaticKey(static_key_len int, stored []byte, passwd string, ctx
}

// Prototype:
// int hydro_pwhash_reencrypt(uint8_t stored[hydro_pwhash_STOREDBYTES],
// const uint8_t master_key[hydro_pwhash_MASTERKEYBYTES],
// const uint8_t new_master_key[hydro_pwhash_MASTERKEYBYTES]);
// int hydro_pwhash_reencrypt(uint8_t stored[hydro_pwhash_STOREDBYTES], const uint8_t master_key[hydro_pwhash_MASTERKEYBYTES], const uint8_t new_master_key[hydro_pwhash_MASTERKEYBYTES]);
func PwHashReEncrypt(stored []byte, master_key []byte, new_master_key []byte) int {
CheckSize(stored, PwHashStoredBytes, "stored len")
CheckSize(master_key, PwHashMasterKeyBytes, "master_key len")
Expand All @@ -150,9 +134,7 @@ func PwHashReEncrypt(stored []byte, master_key []byte, new_master_key []byte) in
}

// Prototype:
// int hydro_pwhash_upgrade(uint8_t stored[hydro_pwhash_STOREDBYTES],
// const uint8_t master_key[hydro_pwhash_MASTERKEYBYTES], uint64_t opslimit,
// size_t memlimit, uint8_t threads);
// int hydro_pwhash_upgrade(uint8_t stored[hydro_pwhash_STOREDBYTES], const uint8_t master_key[hydro_pwhash_MASTERKEYBYTES], uint64_t opslimit, size_t memlimit, uint8_t threads);
func PwHashUpgrade(stored []byte, master_key []byte, opslimit uint64, memlimit int, threads uint8) int {
CheckSize(stored, PwHashStoredBytes, "stored len")
CheckSize(master_key, PwHashMasterKeyBytes, "master_key len")
Expand Down
18 changes: 0 additions & 18 deletions scripts/cmd.sh

This file was deleted.

1 change: 1 addition & 0 deletions tests/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func main() {
ExampleSecretbox()
ExampleSign()
fmt.Println("\n\nOKAY\nAll Example methods ran to completion\n")
fmt.Println(hydro.VersionVerbose())
}

const GOOD_CTX = "goctx123"
Expand Down

0 comments on commit b57d0b4

Please sign in to comment.