mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Remove network dependency from toxcrypto
This commit is contained in:
parent
b19a9e5464
commit
1387c8f150
|
@ -205,9 +205,6 @@ include(CheckFunctionExists)
|
||||||
check_function_exists(explicit_bzero HAVE_EXPLICIT_BZERO)
|
check_function_exists(explicit_bzero HAVE_EXPLICIT_BZERO)
|
||||||
check_function_exists(memset_s HAVE_MEMSET_S)
|
check_function_exists(memset_s HAVE_MEMSET_S)
|
||||||
target_link_modules(toxcrypto ${LIBSODIUM_LIBRARIES})
|
target_link_modules(toxcrypto ${LIBSODIUM_LIBRARIES})
|
||||||
if(WIN32)
|
|
||||||
target_link_modules(toxcrypto ws2_32) # for htonl
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# LAYER 2: Basic networking
|
# LAYER 2: Basic networking
|
||||||
# -------------------------
|
# -------------------------
|
||||||
|
|
|
@ -27,10 +27,9 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "ccompat.h"
|
||||||
#include "crypto_core.h"
|
#include "crypto_core.h"
|
||||||
|
|
||||||
#include "network.h"
|
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#ifndef VANILLA_NACL
|
#ifndef VANILLA_NACL
|
||||||
|
@ -210,6 +209,20 @@ void increment_nonce(uint8_t *nonce)
|
||||||
carry >>= 8;
|
carry >>= 8;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint32_t host_to_network(uint32_t x)
|
||||||
|
{
|
||||||
|
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||||
|
return
|
||||||
|
((x >> 24) & 0x000000FF) | // move byte 3 to byte 0
|
||||||
|
((x >> 8) & 0x0000FF00) | // move byte 2 to byte 1
|
||||||
|
((x << 8) & 0x00FF0000) | // move byte 1 to byte 2
|
||||||
|
((x << 24) & 0xFF000000); // move byte 0 to byte 3
|
||||||
|
#else
|
||||||
|
return x;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/* increment the given nonce by num */
|
/* increment the given nonce by num */
|
||||||
void increment_nonce_number(uint8_t *nonce, uint32_t host_order_num)
|
void increment_nonce_number(uint8_t *nonce, uint32_t host_order_num)
|
||||||
{
|
{
|
||||||
|
@ -218,7 +231,7 @@ void increment_nonce_number(uint8_t *nonce, uint32_t host_order_num)
|
||||||
* that loop bounds and their potential underflow or overflow
|
* that loop bounds and their potential underflow or overflow
|
||||||
* are independent of user-controlled input (you may have heard of the Heartbleed bug).
|
* are independent of user-controlled input (you may have heard of the Heartbleed bug).
|
||||||
*/
|
*/
|
||||||
const uint32_t big_endian_num = net_htonl(host_order_num);
|
const uint32_t big_endian_num = host_to_network(host_order_num);
|
||||||
const uint8_t *const num_vec = (const uint8_t *) &big_endian_num;
|
const uint8_t *const num_vec = (const uint8_t *) &big_endian_num;
|
||||||
uint8_t num_as_nonce[crypto_box_NONCEBYTES] = {0};
|
uint8_t num_as_nonce[crypto_box_NONCEBYTES] = {0};
|
||||||
num_as_nonce[crypto_box_NONCEBYTES - 4] = num_vec[0];
|
num_as_nonce[crypto_box_NONCEBYTES - 4] = num_vec[0];
|
||||||
|
|
Loading…
Reference in New Issue
Block a user