catch sodium_init() return

This commit is contained in:
TLINDEN
2015-11-15 17:02:51 +01:00
parent ab3ff3182e
commit f7aa9d7aaf
5 changed files with 8 additions and 5 deletions

View File

@@ -43,7 +43,10 @@ PCPCTX *ptx_new() {
p->pcppubkey_hash = NULL; p->pcppubkey_hash = NULL;
p->pcpkeysig_hash = NULL; p->pcpkeysig_hash = NULL;
sodium_init(); if(sodium_init() == -1) {
perror("failed to initialize libsodium");
exit(1);
}
return p; return p;
} }

View File

@@ -12,7 +12,7 @@ void pr(char *var, unsigned char *d, size_t len) {
} }
int main() { int main() {
sodium_init(); if(sodium_init() == -1) return 1;
pcp_key_t *a = pcpkey_new(); pcp_key_t *a = pcpkey_new();
pcp_key_t *b = pcpkey_new(); pcp_key_t *b = pcpkey_new();

View File

@@ -10,7 +10,7 @@ int main() {
strcpy(o, "xxxx"); strcpy(o, "xxxx");
strcpy(m, "xxxx"); strcpy(m, "xxxx");
sodium_init(); if(sodium_init() == -1) return 1;
PCPCTX *ptx = ptx_new(); PCPCTX *ptx = ptx_new();
pcp_key_t *k = pcpkey_new (); pcp_key_t *k = pcpkey_new ();

View File

@@ -25,7 +25,7 @@ int main() {
pw *have = NULL; pw *have = NULL;
unsigned char nonce[32] = {1}; unsigned char nonce[32] = {1};
sodium_init(); if(sodium_init() == -1) return 1;
for(i=97; i<126; ++i) { for(i=97; i<126; ++i) {
pass[0] = i; pass[0] = i;

View File

@@ -2,7 +2,7 @@
#include "static.h" #include "static.h"
int main() { int main() {
sodium_init(); if(sodium_init() == -1) return 1;
unsigned char *t = ucmalloc(12); unsigned char *t = ucmalloc(12);
if(crypto_box_open_easy(t, cipher, cipher_len, nonce, public_a, secret_b) == 0) { if(crypto_box_open_easy(t, cipher, cipher_len, nonce, public_a, secret_b) == 0) {
if(memcmp(t, message, message_len) == 0) { if(memcmp(t, message, message_len) == 0) {