Sha256: 82f30aa6a82f766140c99e9a56e575094ee8fd3a2daf26300d08e5a88a6ec1a4

Contents?: true

Size: 1.46 KB

Versions: 5

Compression:

Stored size: 1.46 KB

Contents

#include <assert.h>
#include <stdint.h>
#include <stdlib.h>

#ifdef __native_client__
# include <irt.h>

# include "core.h"
# include "utils.h"
# include "randombytes.h"
# include "randombytes_nativeclient.h"

static void
randombytes_nativeclient_buf(void * const buf, const size_t size)
{
    unsigned char          *buf_ = (unsigned char *) buf;
    struct nacl_irt_random  rand_intf;
    size_t                  readnb = (size_t) 0U;
    size_t                  toread = size;

    if (nacl_interface_query(NACL_IRT_RANDOM_v0_1, &rand_intf,
                             sizeof rand_intf) != sizeof rand_intf) {
        sodium_misuse();
    }
    while (toread > (size_t) 0U) {
        if (rand_intf.get_random_bytes(buf_, size, &readnb) != 0 ||
            readnb > size) {
            sodium_misuse();
        }
        toread -= readnb;
        buf_ += readnb;
    }
}

static uint32_t
randombytes_nativeclient_random(void)
{
    uint32_t r;

    randombytes_nativeclient_buf(&r, sizeof r);

    return r;
}

static const char *
randombytes_nativeclient_implementation_name(void)
{
    return "nativeclient";
}

struct randombytes_implementation randombytes_nativeclient_implementation = {
    SODIUM_C99(.implementation_name =) randombytes_nativeclient_implementation_name,
    SODIUM_C99(.random =) randombytes_nativeclient_random,
    SODIUM_C99(.stir =) NULL,
    SODIUM_C99(.uniform =) NULL,
    SODIUM_C99(.buf =) randombytes_nativeclient_buf,
    SODIUM_C99(.close =) NULL
};

#endif

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
laag-libsodium-1.0.16.2 vendor/github.com/jedisct1/libsodium/src/libsodium/randombytes/nativeclient/randombytes_nativeclient.c
laag-libsodium-1.0.16.0 vendor/github.com/jedisct1/libsodium/src/libsodium/randombytes/nativeclient/randombytes_nativeclient.c
rbnacl-libsodium-1.0.16 vendor/libsodium/src/libsodium/randombytes/nativeclient/randombytes_nativeclient.c
rbnacl-libsodium-1.0.15.1 vendor/libsodium/src/libsodium/randombytes/nativeclient/randombytes_nativeclient.c
rbnacl-libsodium-1.0.15 vendor/libsodium/src/libsodium/randombytes/nativeclient/randombytes_nativeclient.c