1
0
forked from cory/tildefriends
Files
apps
core
deps
codemirror
codemirror_src
crypt_blowfish
libbacktrace
libbacktrace_config
libsodium
.github
build-aux
builds
ci
contrib
dist-build
m4
packaging
regen-msvc
src
test
default
Makefile.am
Makefile.in
aead_aegis128l.c
aead_aegis128l.exp
aead_aegis256.c
aead_aegis256.exp
aead_aes256gcm.c
aead_aes256gcm.exp
aead_aes256gcm2.c
aead_aes256gcm2.exp
aead_chacha20poly1305.c
aead_chacha20poly1305.exp
aead_chacha20poly13052.c
aead_chacha20poly13052.exp
aead_xchacha20poly1305.c
aead_xchacha20poly1305.exp
auth.c
auth.exp
auth2.c
auth2.exp
auth3.c
auth3.exp
auth5.c
auth5.exp
auth6.c
auth6.exp
auth7.c
auth7.exp
box.c
box.exp
box2.c
box2.exp
box7.c
box7.exp
box8.c
box8.exp
box_easy.c
box_easy.exp
box_easy2.c
box_easy2.exp
box_seal.c
box_seal.exp
box_seed.c
box_seed.exp
chacha20.c
chacha20.exp
cmptest.h
codecs.c
codecs.exp
core1.c
core1.exp
core2.c
core2.exp
core3.c
core3.exp
core4.c
core4.exp
core5.c
core5.exp
core6.c
core6.exp
core_ed25519.c
core_ed25519.exp
core_ristretto255.c
core_ristretto255.exp
ed25519_convert.c
ed25519_convert.exp
generichash.c
generichash.exp
generichash2.c
generichash2.exp
generichash3.c
generichash3.exp
hash.c
hash.exp
hash3.c
hash3.exp
index.html.tpl
kdf.c
kdf.exp
kdf_hkdf.c
kdf_hkdf.exp
keygen.c
keygen.exp
kx.c
kx.exp
metamorphic.c
metamorphic.exp
misuse.c
misuse.exp
onetimeauth.c
onetimeauth.exp
onetimeauth2.c
onetimeauth2.exp
onetimeauth7.c
onetimeauth7.exp
pre.js.inc
pwhash_argon2i.c
pwhash_argon2i.exp
pwhash_argon2id.c
pwhash_argon2id.exp
pwhash_scrypt.c
pwhash_scrypt.exp
pwhash_scrypt_ll.c
pwhash_scrypt_ll.exp
randombytes.c
randombytes.exp
run.sh
scalarmult.c
scalarmult.exp
scalarmult2.c
scalarmult2.exp
scalarmult5.c
scalarmult5.exp
scalarmult6.c
scalarmult6.exp
scalarmult7.c
scalarmult7.exp
scalarmult8.c
scalarmult8.exp
scalarmult_ed25519.c
scalarmult_ed25519.exp
scalarmult_ristretto255.c
scalarmult_ristretto255.exp
secretbox.c
secretbox.exp
secretbox2.c
secretbox2.exp
secretbox7.c
secretbox7.exp
secretbox8.c
secretbox8.exp
secretbox_easy.c
secretbox_easy.exp
secretbox_easy2.c
secretbox_easy2.exp
secretstream_xchacha20poly1305.c
secretstream_xchacha20poly1305.exp
shorthash.c
shorthash.exp
sign.c
sign.exp
siphashx24.c
siphashx24.exp
sodium_core.c
sodium_core.exp
sodium_utils.c
sodium_utils.exp
sodium_utils2.c
sodium_utils2.exp
sodium_utils3.c
sodium_utils3.exp
sodium_version.c
sodium_version.exp
stream.c
stream.exp
stream2.c
stream2.exp
stream3.c
stream3.exp
stream4.c
stream4.exp
verify1.c
verify1.exp
wasi-test-wrapper.sh
wintest.bat
xchacha20.c
xchacha20.exp
quirks
Makefile.am
Makefile.in
constcheck.sh
.gitignore
AUTHORS
CITATION.cff
ChangeLog
LICENSE
Makefile.am
Makefile.in
README.markdown
THANKS
aclocal.m4
appveyor.yml
autogen.sh
azure-pipelines.yml
build.zig
configure
configure.ac
lgtm.yml
libsodium-uninstalled.pc.in
libsodium.pc.in
logo.png
libuv
lit
openssl
picohttpparser
quickjs
speedscope
sqlite
xopt
zlib
docs
src
tools
.dockerignore
Dockerfile
GNUmakefile
LICENSE
README.md
tildefriends/deps/libsodium/test/default/scalarmult.c

78 lines
2.6 KiB
C

#define TEST_NAME "scalarmult"
#include "cmptest.h"
static const unsigned char alicesk[crypto_scalarmult_BYTES] = {
0x77, 0x07, 0x6d, 0x0a, 0x73, 0x18, 0xa5, 0x7d, 0x3c, 0x16, 0xc1,
0x72, 0x51, 0xb2, 0x66, 0x45, 0xdf, 0x4c, 0x2f, 0x87, 0xeb, 0xc0,
0x99, 0x2a, 0xb1, 0x77, 0xfb, 0xa5, 0x1d, 0xb9, 0x2c, 0x2a
};
static const unsigned char bobsk[crypto_scalarmult_BYTES] = {
0x5d, 0xab, 0x08, 0x7e, 0x62, 0x4a, 0x8a, 0x4b, 0x79, 0xe1, 0x7f,
0x8b, 0x83, 0x80, 0x0e, 0xe6, 0x6f, 0x3b, 0xb1, 0x29, 0x26, 0x18,
0xb6, 0xfd, 0x1c, 0x2f, 0x8b, 0x27, 0xff, 0x88, 0xe0, 0xeb
};
static const unsigned char small_order_p[crypto_scalarmult_BYTES] = {
0xe0, 0xeb, 0x7a, 0x7c, 0x3b, 0x41, 0xb8, 0xae, 0x16, 0x56, 0xe3,
0xfa, 0xf1, 0x9f, 0xc4, 0x6a, 0xda, 0x09, 0x8d, 0xeb, 0x9c, 0x32,
0xb1, 0xfd, 0x86, 0x62, 0x05, 0x16, 0x5f, 0x49, 0xb8, 0x00
};
static char hex[crypto_scalarmult_BYTES * 2 + 1];
int
main(void)
{
unsigned char *alicepk =
(unsigned char *) sodium_malloc(crypto_scalarmult_BYTES);
unsigned char *bobpk =
(unsigned char *) sodium_malloc(crypto_scalarmult_BYTES);
unsigned char *k = (unsigned char *) sodium_malloc(crypto_scalarmult_BYTES);
int ret;
assert(alicepk != NULL && bobpk != NULL && k != NULL);
crypto_scalarmult_base(alicepk, alicesk);
sodium_bin2hex(hex, sizeof hex, alicepk, crypto_scalarmult_BYTES);
printf("%s\n", hex);
crypto_scalarmult_base(bobpk, bobsk);
sodium_bin2hex(hex, sizeof hex, bobpk, crypto_scalarmult_BYTES);
printf("%s\n", hex);
ret = crypto_scalarmult(k, alicesk, bobpk);
assert(ret == 0);
sodium_bin2hex(hex, sizeof hex, k, crypto_scalarmult_BYTES);
printf("%s\n", hex);
ret = crypto_scalarmult(k, bobsk, alicepk);
assert(ret == 0);
sodium_bin2hex(hex, sizeof hex, k, crypto_scalarmult_BYTES);
printf("%s\n", hex);
alicepk[31] ^= 0x80;
ret = crypto_scalarmult(k, bobsk, alicepk);
assert(ret == 0);
sodium_bin2hex(hex, sizeof hex, k, crypto_scalarmult_BYTES);
printf("%s\n", hex);
ret = crypto_scalarmult(k, bobsk, small_order_p);
assert(ret == -1);
sodium_free(bobpk);
sodium_free(alicepk);
sodium_free(k);
assert(crypto_scalarmult_bytes() > 0U);
assert(crypto_scalarmult_scalarbytes() > 0U);
assert(strcmp(crypto_scalarmult_primitive(), "curve25519") == 0);
assert(crypto_scalarmult_bytes() == crypto_scalarmult_curve25519_bytes());
assert(crypto_scalarmult_scalarbytes() ==
crypto_scalarmult_curve25519_scalarbytes());
assert(crypto_scalarmult_bytes() == crypto_scalarmult_scalarbytes());
return 0;
}