mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Random number functions belong in crypto_core.
This commit is contained in:
parent
47aa53a384
commit
deb8bfc350
|
@ -25,6 +25,7 @@
|
|||
#define DHT_H
|
||||
|
||||
#include "crypto_core.h"
|
||||
#include "network.h"
|
||||
|
||||
/* Size of the client_id in bytes. */
|
||||
#define CLIENT_ID_SIZE crypto_box_PUBLICKEYBYTES
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#define LOSSLESS_UDP_H
|
||||
|
||||
#include "network.h"
|
||||
#include "crypto_core.h"
|
||||
#include "misc_tools.h"
|
||||
|
||||
|
||||
|
|
|
@ -50,6 +50,22 @@ int crypto_cmp(uint8_t *mem1, uint8_t *mem2, uint32_t length)
|
|||
return (1 & ((check - 1) >> 8)) - 1;
|
||||
}
|
||||
|
||||
/* return a random number.
|
||||
*/
|
||||
uint32_t random_int(void)
|
||||
{
|
||||
uint32_t randnum;
|
||||
randombytes((uint8_t *)&randnum , sizeof(randnum));
|
||||
return randnum;
|
||||
}
|
||||
|
||||
uint64_t random_64b(void)
|
||||
{
|
||||
uint64_t randnum;
|
||||
randombytes((uint8_t *)&randnum, sizeof(randnum));
|
||||
return randnum;
|
||||
}
|
||||
|
||||
/* Precomputes the shared key from their public_key and our secret_key.
|
||||
* This way we can avoid an expensive elliptic curve scalar multiply for each
|
||||
* encrypt/decrypt operation.
|
||||
|
|
|
@ -45,6 +45,15 @@
|
|||
return -1 if they are not. */
|
||||
int crypto_cmp(uint8_t *mem1, uint8_t *mem2, uint32_t length);
|
||||
|
||||
/* return a random number.
|
||||
*
|
||||
* random_int for a 32bin int.
|
||||
* random_64b for a 64bit int.
|
||||
*/
|
||||
uint32_t random_int(void);
|
||||
uint64_t random_64b(void);
|
||||
|
||||
|
||||
/* Encrypts plain of length length to encrypted of length + 16 using the
|
||||
* public key(32 bytes) of the receiver and the secret key of the sender and a 24 byte nonce.
|
||||
*
|
||||
|
|
|
@ -204,21 +204,6 @@ uint64_t current_time(void)
|
|||
#endif
|
||||
}
|
||||
|
||||
/* return a random number.
|
||||
*/
|
||||
uint32_t random_int(void)
|
||||
{
|
||||
uint32_t randnum;
|
||||
randombytes((uint8_t *)&randnum , sizeof(randnum));
|
||||
return randnum;
|
||||
}
|
||||
|
||||
uint64_t random_64b(void)
|
||||
{
|
||||
uint64_t randnum;
|
||||
randombytes((uint8_t *)&randnum, sizeof(randnum));
|
||||
return randnum;
|
||||
}
|
||||
|
||||
#ifdef LOGGING
|
||||
static void loglogdata(char *message, uint8_t *buffer, size_t buflen, IP_Port *ip_port, ssize_t res);
|
||||
|
|
|
@ -325,11 +325,6 @@ int set_socket_dualstack(sock_t sock);
|
|||
/* return current UNIX time in microseconds (us). */
|
||||
uint64_t current_time(void);
|
||||
|
||||
/* return a random number.
|
||||
*/
|
||||
uint32_t random_int(void);
|
||||
uint64_t random_64b(void);
|
||||
|
||||
/* Basic network functions: */
|
||||
|
||||
/* Function to send packet(data) of length length to ip_port. */
|
||||
|
|
Loading…
Reference in New Issue
Block a user