Random number functions belong in crypto_core.

This commit is contained in:
irungentoo 2014-05-01 19:42:44 -04:00
parent 47aa53a384
commit deb8bfc350
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98
6 changed files with 27 additions and 20 deletions

View File

@ -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

View File

@ -25,6 +25,7 @@
#define LOSSLESS_UDP_H
#include "network.h"
#include "crypto_core.h"
#include "misc_tools.h"

View File

@ -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.

View File

@ -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.
*

View File

@ -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);

View File

@ -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. */