Sha256: 37347f11457459e2773de3e5016747c31fd6f296965443185e99480101b25aa3

Contents?: true

Size: 1.63 KB

Versions: 5

Compression:

Stored size: 1.63 KB

Contents

#include "crypto_scalarmult_curve25519.h"
#include "scalarmult_curve25519.h"
#include "runtime.h"

#ifdef HAVE_AVX_ASM
# include "sandy2x/curve25519_sandy2x.h"
#endif
#ifdef HAVE_TI_MODE
# include "donna_c64/curve25519_donna_c64.h"
static const crypto_scalarmult_curve25519_implementation *implementation =
    &crypto_scalarmult_curve25519_donna_c64_implementation;
#else
# include "ref10/x25519_ref10.h"
static const crypto_scalarmult_curve25519_implementation *implementation =
    &crypto_scalarmult_curve25519_ref10_implementation;
#endif

int
crypto_scalarmult_curve25519(unsigned char *q, const unsigned char *n,
                             const unsigned char *p)
{
    size_t        i;
    unsigned char d = 0;

    if (implementation->mult(q, n, p) != 0) {
        return -1;
    }
    for (i = 0; i < crypto_scalarmult_curve25519_BYTES; i++) {
        d |= q[i];
    }
    return -(1 & ((d - 1) >> 8));
}

int
crypto_scalarmult_curve25519_base(unsigned char *q, const unsigned char *n)
{
    return implementation->mult_base(q, n);
}

size_t
crypto_scalarmult_curve25519_bytes(void)
{
    return crypto_scalarmult_curve25519_BYTES;
}

size_t
crypto_scalarmult_curve25519_scalarbytes(void)
{
    return crypto_scalarmult_curve25519_SCALARBYTES;
}

int
_crypto_scalarmult_curve25519_pick_best_implementation(void)
{
#ifdef HAVE_TI_MODE
    implementation = &crypto_scalarmult_curve25519_donna_c64_implementation;
#else
    implementation = &crypto_scalarmult_curve25519_ref10_implementation;
#endif
#ifdef HAVE_AVX_ASM
    if (sodium_runtime_has_avx()) {
        implementation = &crypto_scalarmult_curve25519_sandy2x_implementation;
    }
#endif
    return 0;
}

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rbnacl-libsodium-1.0.13 vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/scalarmult_curve25519.c
rbnacl-libsodium-1.0.11 vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/scalarmult_curve25519.c
rbnacl-libsodium-1.0.10 vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/scalarmult_curve25519.c
rbnacl-libsodium-1.0.9 vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/scalarmult_curve25519.c
rbnacl-libsodium-1.0.8 vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/scalarmult_curve25519.c