In crypt.c/.h a var/arg naming was changed as well.
This commit is contained in:
parent
e075a99a28
commit
051d18ba40
34
src/crypt.c
34
src/crypt.c
@ -3,11 +3,11 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
int crypt_key_gen(crypt_key_t *k) {
|
int crypt_key_gen(crypt_key_t *k) {
|
||||||
if (crypto_kx_keypair(k->kxPub, k->kxSec) < 0) {
|
if (crypto_kx_keypair(k->kx_pub, k->kx_sec) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (crypto_sign_keypair(k->signPub, k->signSec) < 0) {
|
if (crypto_sign_keypair(k->sign_pub, k->sign_sec) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -18,16 +18,16 @@ int crypt_key_gen(crypt_key_t *k) {
|
|||||||
|
|
||||||
int crypt_key_from_hex(crypt_key_t *k, char phex[CRYPT_PUBKEY_HEXSIZE], char shex[CRYPT_SECKEY_HEXSIZE]) {
|
int crypt_key_from_hex(crypt_key_t *k, char phex[CRYPT_PUBKEY_HEXSIZE], char shex[CRYPT_SECKEY_HEXSIZE]) {
|
||||||
int res = 0;
|
int res = 0;
|
||||||
res = sodium_hex2bin(k->kxPub, crypto_kx_PUBLICKEYBYTES, phex, crypto_kx_PUBLICKEYBYTES * 2, NULL, NULL, NULL);
|
res = sodium_hex2bin(k->kx_pub, crypto_kx_PUBLICKEYBYTES, phex, crypto_kx_PUBLICKEYBYTES * 2, NULL, NULL, NULL);
|
||||||
if (res < 0)
|
if (res < 0)
|
||||||
return -1;
|
return -1;
|
||||||
res = sodium_hex2bin(k->kxSec, crypto_kx_SECRETKEYBYTES, shex, crypto_kx_SECRETKEYBYTES * 2, NULL, NULL, NULL);
|
res = sodium_hex2bin(k->kx_sec, crypto_kx_SECRETKEYBYTES, shex, crypto_kx_SECRETKEYBYTES * 2, NULL, NULL, NULL);
|
||||||
if (res < 0)
|
if (res < 0)
|
||||||
return -1;
|
return -1;
|
||||||
res = sodium_hex2bin(k->signPub, crypto_sign_PUBLICKEYBYTES, phex+(crypto_kx_PUBLICKEYBYTES * 2), crypto_sign_PUBLICKEYBYTES * 2, NULL, NULL, NULL);
|
res = sodium_hex2bin(k->sign_pub, crypto_sign_PUBLICKEYBYTES, phex+(crypto_kx_PUBLICKEYBYTES * 2), crypto_sign_PUBLICKEYBYTES * 2, NULL, NULL, NULL);
|
||||||
if (res < 0)
|
if (res < 0)
|
||||||
return -1;
|
return -1;
|
||||||
res = sodium_hex2bin(k->signSec, crypto_sign_SECRETKEYBYTES, shex+(crypto_kx_SECRETKEYBYTES * 2), crypto_sign_SECRETKEYBYTES * 2, NULL, NULL, NULL);
|
res = sodium_hex2bin(k->sign_sec, crypto_sign_SECRETKEYBYTES, shex+(crypto_kx_SECRETKEYBYTES * 2), crypto_sign_SECRETKEYBYTES * 2, NULL, NULL, NULL);
|
||||||
if (res < 0)
|
if (res < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@ -38,10 +38,10 @@ int crypt_key_from_hex(crypt_key_t *k, char phex[CRYPT_PUBKEY_HEXSIZE], char she
|
|||||||
|
|
||||||
int crypt_key_from_hex_public(crypt_key_t *k, char phex[CRYPT_PUBKEY_HEXSIZE]) {
|
int crypt_key_from_hex_public(crypt_key_t *k, char phex[CRYPT_PUBKEY_HEXSIZE]) {
|
||||||
int res = 0;
|
int res = 0;
|
||||||
res = sodium_hex2bin(k->kxPub, crypto_kx_PUBLICKEYBYTES, phex, crypto_kx_PUBLICKEYBYTES * 2, NULL, NULL, NULL);
|
res = sodium_hex2bin(k->kx_pub, crypto_kx_PUBLICKEYBYTES, phex, crypto_kx_PUBLICKEYBYTES * 2, NULL, NULL, NULL);
|
||||||
if (res < 0)
|
if (res < 0)
|
||||||
return -1;
|
return -1;
|
||||||
res = sodium_hex2bin(k->signPub, crypto_sign_PUBLICKEYBYTES, phex+(crypto_kx_PUBLICKEYBYTES * 2), crypto_sign_PUBLICKEYBYTES * 2, NULL, NULL, NULL);
|
res = sodium_hex2bin(k->sign_pub, crypto_sign_PUBLICKEYBYTES, phex+(crypto_kx_PUBLICKEYBYTES * 2), crypto_sign_PUBLICKEYBYTES * 2, NULL, NULL, NULL);
|
||||||
if (res < 0)
|
if (res < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@ -51,29 +51,29 @@ int crypt_key_from_hex_public(crypt_key_t *k, char phex[CRYPT_PUBKEY_HEXSIZE]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void crypt_key_export_public(crypt_key_t *k, char hex[CRYPT_PUBKEY_HEXSIZE]) {
|
void crypt_key_export_public(crypt_key_t *k, char hex[CRYPT_PUBKEY_HEXSIZE]) {
|
||||||
sodium_bin2hex(hex, crypto_kx_PUBLICKEYBYTES * 2 + 1, k->kxPub, crypto_kx_PUBLICKEYBYTES);
|
sodium_bin2hex(hex, crypto_kx_PUBLICKEYBYTES * 2 + 1, k->kx_pub, crypto_kx_PUBLICKEYBYTES);
|
||||||
sodium_bin2hex(hex+(crypto_kx_PUBLICKEYBYTES * 2), crypto_sign_PUBLICKEYBYTES * 2 + 1, k->signPub, crypto_sign_PUBLICKEYBYTES);
|
sodium_bin2hex(hex+(crypto_kx_PUBLICKEYBYTES * 2), crypto_sign_PUBLICKEYBYTES * 2 + 1, k->sign_pub, crypto_sign_PUBLICKEYBYTES);
|
||||||
}
|
}
|
||||||
|
|
||||||
void crypt_key_export_secret(crypt_key_t *k, char hex[CRYPT_SECKEY_HEXSIZE]) {
|
void crypt_key_export_secret(crypt_key_t *k, char hex[CRYPT_SECKEY_HEXSIZE]) {
|
||||||
sodium_bin2hex(hex, crypto_kx_SECRETKEYBYTES * 2 + 1, k->kxSec, crypto_kx_SECRETKEYBYTES);
|
sodium_bin2hex(hex, crypto_kx_SECRETKEYBYTES * 2 + 1, k->kx_sec, crypto_kx_SECRETKEYBYTES);
|
||||||
sodium_bin2hex(hex+(crypto_kx_SECRETKEYBYTES * 2), crypto_sign_SECRETKEYBYTES * 2 + 1, k->signSec, crypto_sign_SECRETKEYBYTES);
|
sodium_bin2hex(hex+(crypto_kx_SECRETKEYBYTES * 2), crypto_sign_SECRETKEYBYTES * 2 + 1, k->sign_sec, crypto_sign_SECRETKEYBYTES);
|
||||||
}
|
}
|
||||||
|
|
||||||
int crypt_session_init(crypt_session_t *s, crypt_key_t *own, crypt_key_t *remote, bool dirClient) {
|
int crypt_session_init(crypt_session_t *s, crypt_key_t *own, crypt_key_t *remote, bool is_client) {
|
||||||
if (dirClient) {
|
if (is_client) {
|
||||||
if (crypto_kx_client_session_keys(s->rx, s->tx, own->kxPub, own->kxSec, remote->kxPub) != 0) {
|
if (crypto_kx_client_session_keys(s->rx, s->tx, own->kx_pub, own->kx_sec, remote->kx_pub) != 0) {
|
||||||
fprintf(stderr, "Failed to instantiate a client session.\n");
|
fprintf(stderr, "Failed to instantiate a client session.\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (crypto_kx_server_session_keys(s->rx, s->tx, own->kxPub, own->kxSec, remote->kxPub) != 0) {
|
if (crypto_kx_server_session_keys(s->rx, s->tx, own->kx_pub, own->kx_sec, remote->kx_pub) != 0) {
|
||||||
fprintf(stderr, "Failed to instantiate a server session.\n");
|
fprintf(stderr, "Failed to instantiate a server session.\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
s->remoteKey = remote;
|
s->remote_key = remote;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
12
src/crypt.h
12
src/crypt.h
@ -9,10 +9,10 @@
|
|||||||
#define CRYPT_SECKEY_HEXSIZE (crypto_kx_SECRETKEYBYTES + crypto_sign_SECRETKEYBYTES) * 2 + 1
|
#define CRYPT_SECKEY_HEXSIZE (crypto_kx_SECRETKEYBYTES + crypto_sign_SECRETKEYBYTES) * 2 + 1
|
||||||
|
|
||||||
typedef struct crypt_key_t {
|
typedef struct crypt_key_t {
|
||||||
unsigned char kxPub[crypto_kx_PUBLICKEYBYTES];
|
unsigned char kx_pub[crypto_kx_PUBLICKEYBYTES];
|
||||||
unsigned char kxSec[crypto_kx_SECRETKEYBYTES];
|
unsigned char kx_sec[crypto_kx_SECRETKEYBYTES];
|
||||||
unsigned char signPub[crypto_sign_PUBLICKEYBYTES];
|
unsigned char sign_pub[crypto_sign_PUBLICKEYBYTES];
|
||||||
unsigned char signSec[crypto_sign_SECRETKEYBYTES];
|
unsigned char sign_sec[crypto_sign_SECRETKEYBYTES];
|
||||||
bool hasSecKey;
|
bool hasSecKey;
|
||||||
} crypt_key_t;
|
} crypt_key_t;
|
||||||
|
|
||||||
@ -26,9 +26,9 @@ void crypt_key_export_secret(crypt_key_t *k, char hex[CRYPT_SECKEY_HEXSIZE]);
|
|||||||
typedef struct crypt_session_t {
|
typedef struct crypt_session_t {
|
||||||
unsigned char rx[crypto_kx_SESSIONKEYBYTES];
|
unsigned char rx[crypto_kx_SESSIONKEYBYTES];
|
||||||
unsigned char tx[crypto_kx_SESSIONKEYBYTES];
|
unsigned char tx[crypto_kx_SESSIONKEYBYTES];
|
||||||
crypt_key_t *remoteKey;
|
crypt_key_t *remote_key;
|
||||||
} crypt_session_t;
|
} crypt_session_t;
|
||||||
|
|
||||||
int crypt_session_init(crypt_session_t *s, crypt_key_t *own, crypt_key_t *remote, bool dirClient);
|
int crypt_session_init(crypt_session_t *s, crypt_key_t *own, crypt_key_t *remote, bool is_client);
|
||||||
|
|
||||||
#endif /* _CRYPT_H_ */
|
#endif /* _CRYPT_H_ */
|
Loading…
Reference in New Issue
Block a user