mirror of
https://github.com/jedisct1/libsodium.git
synced 2024-12-20 02:25:14 -07:00
Merge branch 'master' of https://github.com/jedisct1/libsodium
This commit is contained in:
commit
3965574d3b
2
LICENSE
2
LICENSE
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* ISC License
|
||||
*
|
||||
* Copyright (c) 2013-2016
|
||||
* Copyright (c) 2013-2017
|
||||
* Frank Denis <j at pureftpd dot org>
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
|
@ -21,7 +21,7 @@ if [ ! -x "`which automake 2>/dev/null`" ] ; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -x "`which autoreconf 2>/dev/null`" ] ; then
|
||||
if autoreconf --version > /dev/null 2>&1 ; then
|
||||
exec autoreconf -ivf
|
||||
fi
|
||||
|
||||
|
12
configure.ac
12
configure.ac
@ -36,6 +36,7 @@ AC_SUBST(SODIUM_LIBRARY_VERSION_MINOR)
|
||||
AC_SUBST(SODIUM_LIBRARY_VERSION)
|
||||
AC_SUBST(DLL_VERSION)
|
||||
|
||||
AC_LANG_ASSERT(C)
|
||||
LX_CFLAGS=${CFLAGS-NONE}
|
||||
|
||||
dnl Path check
|
||||
@ -180,19 +181,14 @@ AX_CHECK_COMPILE_FLAG([-fvisibility=hidden],
|
||||
[CFLAGS="$CFLAGS -fvisibility=hidden"])
|
||||
|
||||
AS_CASE([$host_os], [cygwin*|mingw*|msys|pw32*|cegcc*], [ ], [
|
||||
AX_CHECK_COMPILE_FLAG([-fPIC], [
|
||||
AX_CHECK_LINK_FLAG([-fPIC],
|
||||
[CFLAGS="$CFLAGS -fPIC"]
|
||||
)
|
||||
])
|
||||
AX_CHECK_COMPILE_FLAG([-fPIC], [CFLAGS="$CFLAGS -fPIC"])
|
||||
])
|
||||
|
||||
AS_IF([test "$enable_pie" != "no"],[
|
||||
AX_CHECK_COMPILE_FLAG([-fPIE], [
|
||||
AX_CHECK_LINK_FLAG([-fPIE],
|
||||
[AX_CHECK_LINK_FLAG([-pie],
|
||||
AX_CHECK_LINK_FLAG([-pie], [
|
||||
[CFLAGS="$CFLAGS -fPIE"
|
||||
LDFLAGS="$LDFLAGS -pie"])
|
||||
LDFLAGS="$LDFLAGS -pie"]
|
||||
])
|
||||
])
|
||||
])
|
||||
|
@ -104,18 +104,14 @@ elseif (WIN32)
|
||||
message(FATAL_ERROR "the ${_TARGET_ARCH} architecture is not supported by Findsodium.cmake.")
|
||||
endif()
|
||||
string(APPEND _PLATFORM_PATH "/$$CONFIG$$")
|
||||
# this will need to be maintained manually -.-'
|
||||
if (MSVC_VERSION EQUAL 1600)
|
||||
string(APPEND _PLATFORM_PATH "/v100")
|
||||
elseif (MSVC_VERSION EQUAL 1700)
|
||||
string(APPEND _PLATFORM_PATH "/v110")
|
||||
elseif (MSVC_VERSION EQUAL 1800)
|
||||
string(APPEND _PLATFORM_PATH "/v120")
|
||||
elseif (MSVC_VERSION EQUAL 1900)
|
||||
string(APPEND _PLATFORM_PATH "/v140")
|
||||
|
||||
if (MSVC_VERSION LESS 1900)
|
||||
math(EXPR _VS_VERSION "${MSVC_VERSION} / 10 - 60")
|
||||
else()
|
||||
message(FATAL_ERROR "msvc version ${MSVC_VERSION} is not supported by Findsodium.cmake.")
|
||||
math(EXPR _VS_VERSION "${MSVC_VERSION} / 10 - 50")
|
||||
endif()
|
||||
string(APPEND _PLATFORM_PATH "/v${_VS_VERSION}")
|
||||
|
||||
if (sodium_USE_STATIC_LIBS)
|
||||
string(APPEND _PLATFORM_PATH "/static")
|
||||
else()
|
@ -1,3 +1,3 @@
|
||||
|
||||
EXTRA_DIST = \
|
||||
FindSodium.cmake
|
||||
Findsodium.cmake
|
||||
|
@ -53,7 +53,7 @@
|
||||
# modified version of the Autoconf Macro, you may extend this special
|
||||
# exception to the GPL to apply to your modified version as well.
|
||||
|
||||
#serial 2
|
||||
#serial 4
|
||||
|
||||
AC_DEFUN([AX_CHECK_COMPILE_FLAG],
|
||||
[AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF
|
||||
@ -61,8 +61,8 @@ AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl
|
||||
AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [
|
||||
ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS
|
||||
_AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1"
|
||||
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h>]],
|
||||
[[char x[42U], fodder = 0;if (fodder > -1000 && fgets(x,1000,stdin)) puts(x)]])],
|
||||
AC_TRY_LINK([#include <stdio.h>],
|
||||
[char x[42U], fodder = 0;if (fodder > -1000 && fgets(x,1000,stdin)) puts(x)],
|
||||
[AS_VAR_SET(CACHEVAR,[yes])],
|
||||
[AS_VAR_SET(CACHEVAR,[no])])
|
||||
_AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags])
|
||||
|
@ -8,12 +8,18 @@
|
||||
#
|
||||
# DESCRIPTION
|
||||
#
|
||||
# This macro searches for a GNU version of make. If a match is found, the
|
||||
# makefile variable `ifGNUmake' is set to the empty string, otherwise it
|
||||
# is set to "#". This is useful for including a special features in a
|
||||
# Makefile, which cannot be handled by other versions of make. The
|
||||
# variable _cv_gnu_make_command is set to the command to invoke GNU make
|
||||
# if it exists, the empty string otherwise.
|
||||
# This macro searches for a GNU version of make. If a match is found:
|
||||
#
|
||||
# * The makefile variable `ifGNUmake' is set to the empty string, otherwise
|
||||
# it is set to "#". This is useful for including a special features in a
|
||||
# Makefile, which cannot be handled by other versions of make.
|
||||
# * The variable `_cv_gnu_make_command` is set to the command to invoke
|
||||
# GNU make if it exists, the empty string otherwise.
|
||||
# * The variable `ax_cv_gnu_make_command` is set to the command to invoke
|
||||
# GNU make by copying `_cv_gnu_make_command`, otherwise it is unset.
|
||||
# * If GNU Make is found, its version is extracted from the output of
|
||||
# `make --version` as the last field of a record of space-separated
|
||||
# columns and saved into the variable `ax_check_gnu_make_version`.
|
||||
#
|
||||
# Here is an example of its use:
|
||||
#
|
||||
@ -48,31 +54,31 @@
|
||||
# LICENSE
|
||||
#
|
||||
# Copyright (c) 2008 John Darrington <j.darrington@elvis.murdoch.edu.au>
|
||||
# Copyright (c) 2015 Enrico M. Crisostomo <enrico.m.crisostomo@gmail.com>
|
||||
#
|
||||
# Copying and distribution of this file, with or without modification, are
|
||||
# permitted in any medium without royalty provided the copyright notice
|
||||
# and this notice are preserved. This file is offered as-is, without any
|
||||
# warranty.
|
||||
|
||||
#serial 7
|
||||
#serial 8
|
||||
|
||||
AC_DEFUN([AX_CHECK_GNU_MAKE], [ AC_CACHE_CHECK( for GNU make,_cv_gnu_make_command,
|
||||
_cv_gnu_make_command='' ;
|
||||
AC_DEFUN([AX_CHECK_GNU_MAKE],dnl
|
||||
[AC_PROG_AWK
|
||||
AC_CACHE_CHECK([for GNU make],[_cv_gnu_make_command],[dnl
|
||||
_cv_gnu_make_command="" ;
|
||||
dnl Search all the common names for GNU make
|
||||
for a in "$MAKE" make gmake gnumake ; do
|
||||
if test -z "$a" ; then continue ; fi ;
|
||||
if ( sh -c "$a --version" 2> /dev/null | grep GNU 2>&1 > /dev/null ) ; then
|
||||
if "$a" --version 2> /dev/null | grep GNU 2>&1 > /dev/null ; then
|
||||
_cv_gnu_make_command=$a ;
|
||||
break;
|
||||
AX_CHECK_GNU_MAKE_HEADLINE=$("$a" --version 2> /dev/null | grep "GNU Make")
|
||||
ax_check_gnu_make_version=$(echo ${AX_CHECK_GNU_MAKE_HEADLINE} | ${AWK} -F " " '{ print $(NF); }')
|
||||
break ;
|
||||
fi
|
||||
done ;
|
||||
) ;
|
||||
done ;])
|
||||
dnl If there was a GNU version, then set @ifGNUmake@ to the empty string, '#' otherwise
|
||||
if test "x$_cv_gnu_make_command" != "x" ; then
|
||||
ifGNUmake='' ;
|
||||
else
|
||||
ifGNUmake='#' ;
|
||||
AC_MSG_RESULT("Not found");
|
||||
fi
|
||||
AC_SUBST(ifGNUmake)
|
||||
] )
|
||||
AS_VAR_IF([_cv_gnu_make_command], [""], [AS_VAR_SET([ifGNUmake], ["#"])], [AS_VAR_SET([ifGNUmake], [""])])
|
||||
AS_VAR_IF([_cv_gnu_make_command], [""], [AS_UNSET(ax_cv_gnu_make_command)], [AS_VAR_SET([ax_cv_gnu_make_command], [${_cv_gnu_make_command}])])
|
||||
AC_SUBST([ifGNUmake])
|
||||
])
|
||||
|
@ -53,7 +53,7 @@
|
||||
# modified version of the Autoconf Macro, you may extend this special
|
||||
# exception to the GPL to apply to your modified version as well.
|
||||
|
||||
#serial 2
|
||||
#serial 4
|
||||
|
||||
AC_DEFUN([AX_CHECK_LINK_FLAG],
|
||||
[AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF
|
||||
|
@ -82,7 +82,7 @@
|
||||
# modified version of the Autoconf Macro, you may extend this special
|
||||
# exception to the GPL to apply to your modified version as well.
|
||||
|
||||
#serial 22
|
||||
#serial 23
|
||||
|
||||
AU_ALIAS([ACX_PTHREAD], [AX_PTHREAD])
|
||||
AC_DEFUN([AX_PTHREAD], [
|
||||
@ -212,7 +212,7 @@ case $host_os in
|
||||
ax_pthread_check_macro="_REENTRANT"
|
||||
;;
|
||||
|
||||
aix* | freebsd*)
|
||||
aix*)
|
||||
ax_pthread_check_macro="_THREAD_SAFE"
|
||||
;;
|
||||
|
||||
|
@ -3,7 +3,6 @@ lib_LTLIBRARIES = \
|
||||
|
||||
libsodium_la_SOURCES = \
|
||||
crypto_aead/chacha20poly1305/sodium/aead_chacha20poly1305.c \
|
||||
crypto_aead/xchacha20poly1305/sodium/aead_xchacha20poly1305.c \
|
||||
crypto_auth/crypto_auth.c \
|
||||
crypto_auth/hmacsha256/auth_hmacsha256_api.c \
|
||||
crypto_auth/hmacsha256/cp/hmac_hmacsha256.c \
|
||||
@ -170,6 +169,7 @@ endif
|
||||
|
||||
if !MINIMAL
|
||||
libsodium_la_SOURCES += \
|
||||
crypto_aead/xchacha20poly1305/sodium/aead_xchacha20poly1305.c \
|
||||
crypto_box/curve25519xchacha20poly1305/box_curve25519xchacha20poly1305_api.c \
|
||||
crypto_box/curve25519xchacha20poly1305/box_curve25519xchacha20poly1305_easy.c \
|
||||
crypto_box/curve25519xchacha20poly1305/sodium/after_curve25519xchacha20poly1305.c \
|
||||
|
@ -5,15 +5,14 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "crypto_aead_xchacha20poly1305.h"
|
||||
#include "crypto_onetimeauth_poly1305.h"
|
||||
#include "crypto_stream_xchacha20.h"
|
||||
#include "crypto_verify_16.h"
|
||||
#include "crypto_aead_chacha20poly1305.h"
|
||||
#include "crypto_core_hchacha20.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include "private/common.h"
|
||||
|
||||
int
|
||||
crypto_aead_xchacha20poly1305_encrypt_detached(unsigned char *c,
|
||||
crypto_aead_xchacha20poly1305_ietf_encrypt_detached(unsigned char *c,
|
||||
unsigned char *mac,
|
||||
unsigned long long *maclen_p,
|
||||
const unsigned char *m,
|
||||
@ -24,36 +23,22 @@ crypto_aead_xchacha20poly1305_encrypt_detached(unsigned char *c,
|
||||
const unsigned char *npub,
|
||||
const unsigned char *k)
|
||||
{
|
||||
crypto_onetimeauth_poly1305_state state;
|
||||
unsigned char block0[64U];
|
||||
unsigned char slen[8U];
|
||||
unsigned char k2[crypto_core_hchacha20_OUTPUTBYTES];
|
||||
unsigned char npub2[crypto_aead_chacha20poly1305_ietf_NPUBBYTES] = { 0 };
|
||||
int ret;
|
||||
|
||||
(void) nsec;
|
||||
crypto_stream_xchacha20(block0, sizeof block0, npub, k);
|
||||
crypto_onetimeauth_poly1305_init(&state, block0);
|
||||
sodium_memzero(block0, sizeof block0);
|
||||
crypto_core_hchacha20(k2, npub, k, NULL);
|
||||
memcpy(npub2 + 4, npub + crypto_core_hchacha20_INPUTBYTES,
|
||||
crypto_aead_chacha20poly1305_ietf_NPUBBYTES - 4);
|
||||
ret = crypto_aead_chacha20poly1305_ietf_encrypt_detached
|
||||
(c, mac, maclen_p, m, mlen, ad, adlen, nsec, npub2, k2);
|
||||
sodium_memzero(k2, crypto_core_hchacha20_OUTPUTBYTES);
|
||||
|
||||
crypto_onetimeauth_poly1305_update(&state, ad, adlen);
|
||||
STORE64_LE(slen, (uint64_t) adlen);
|
||||
crypto_onetimeauth_poly1305_update(&state, slen, sizeof slen);
|
||||
|
||||
crypto_stream_xchacha20_xor_ic(c, m, mlen, npub, 1U, k);
|
||||
|
||||
crypto_onetimeauth_poly1305_update(&state, c, mlen);
|
||||
STORE64_LE(slen, (uint64_t) mlen);
|
||||
crypto_onetimeauth_poly1305_update(&state, slen, sizeof slen);
|
||||
|
||||
crypto_onetimeauth_poly1305_final(&state, mac);
|
||||
sodium_memzero(&state, sizeof state);
|
||||
|
||||
if (maclen_p != NULL) {
|
||||
*maclen_p = crypto_aead_xchacha20poly1305_ABYTES;
|
||||
}
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
crypto_aead_xchacha20poly1305_encrypt(unsigned char *c,
|
||||
crypto_aead_xchacha20poly1305_ietf_encrypt(unsigned char *c,
|
||||
unsigned long long *clen_p,
|
||||
const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
@ -66,17 +51,14 @@ crypto_aead_xchacha20poly1305_encrypt(unsigned char *c,
|
||||
unsigned long long clen = 0ULL;
|
||||
int ret;
|
||||
|
||||
if (mlen > UINT64_MAX - crypto_aead_xchacha20poly1305_ABYTES) {
|
||||
if (mlen > UINT64_MAX - crypto_aead_xchacha20poly1305_ietf_ABYTES) {
|
||||
abort(); /* LCOV_EXCL_LINE */
|
||||
}
|
||||
ret = crypto_aead_xchacha20poly1305_encrypt_detached(c,
|
||||
c + mlen, NULL,
|
||||
m, mlen,
|
||||
ad, adlen,
|
||||
nsec, npub, k);
|
||||
ret = crypto_aead_xchacha20poly1305_ietf_encrypt_detached
|
||||
(c, c + mlen, NULL, m, mlen, ad, adlen, nsec, npub, k);
|
||||
if (clen_p != NULL) {
|
||||
if (ret == 0) {
|
||||
clen = mlen + crypto_aead_xchacha20poly1305_ABYTES;
|
||||
clen = mlen + crypto_aead_xchacha20poly1305_ietf_ABYTES;
|
||||
}
|
||||
*clen_p = clen;
|
||||
}
|
||||
@ -84,7 +66,7 @@ crypto_aead_xchacha20poly1305_encrypt(unsigned char *c,
|
||||
}
|
||||
|
||||
int
|
||||
crypto_aead_xchacha20poly1305_decrypt_detached(unsigned char *m,
|
||||
crypto_aead_xchacha20poly1305_ietf_decrypt_detached(unsigned char *m,
|
||||
unsigned char *nsec,
|
||||
const unsigned char *c,
|
||||
unsigned long long clen,
|
||||
@ -94,47 +76,23 @@ crypto_aead_xchacha20poly1305_decrypt_detached(unsigned char *m,
|
||||
const unsigned char *npub,
|
||||
const unsigned char *k)
|
||||
{
|
||||
crypto_onetimeauth_poly1305_state state;
|
||||
unsigned char block0[64U];
|
||||
unsigned char slen[8U];
|
||||
unsigned char computed_mac[crypto_aead_xchacha20poly1305_ABYTES];
|
||||
unsigned long long mlen;
|
||||
unsigned char k2[crypto_core_hchacha20_OUTPUTBYTES];
|
||||
unsigned char npub2[crypto_aead_chacha20poly1305_ietf_NPUBBYTES] = { 0 };
|
||||
int ret;
|
||||
|
||||
(void) nsec;
|
||||
crypto_stream_xchacha20(block0, sizeof block0, npub, k);
|
||||
crypto_onetimeauth_poly1305_init(&state, block0);
|
||||
sodium_memzero(block0, sizeof block0);
|
||||
crypto_core_hchacha20(k2, npub, k, NULL);
|
||||
memcpy(npub2 + 4, npub + crypto_core_hchacha20_INPUTBYTES,
|
||||
crypto_aead_chacha20poly1305_ietf_NPUBBYTES - 4);
|
||||
ret = crypto_aead_chacha20poly1305_ietf_decrypt_detached
|
||||
(m, nsec, c, clen, mac, ad, adlen, npub2, k2);
|
||||
sodium_memzero(k2, crypto_core_hchacha20_OUTPUTBYTES);
|
||||
|
||||
crypto_onetimeauth_poly1305_update(&state, ad, adlen);
|
||||
STORE64_LE(slen, (uint64_t) adlen);
|
||||
crypto_onetimeauth_poly1305_update(&state, slen, sizeof slen);
|
||||
|
||||
mlen = clen;
|
||||
crypto_onetimeauth_poly1305_update(&state, c, mlen);
|
||||
STORE64_LE(slen, (uint64_t) mlen);
|
||||
crypto_onetimeauth_poly1305_update(&state, slen, sizeof slen);
|
||||
|
||||
crypto_onetimeauth_poly1305_final(&state, computed_mac);
|
||||
sodium_memzero(&state, sizeof state);
|
||||
|
||||
(void) sizeof(int[sizeof computed_mac == 16U ? 1 : -1]);
|
||||
ret = crypto_verify_16(computed_mac, mac);
|
||||
sodium_memzero(computed_mac, sizeof computed_mac);
|
||||
if (m == NULL) {
|
||||
return ret;
|
||||
}
|
||||
if (ret != 0) {
|
||||
memset(m, 0, mlen);
|
||||
return -1;
|
||||
}
|
||||
crypto_stream_xchacha20_xor_ic(m, c, mlen, npub, 1U, k);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
crypto_aead_xchacha20poly1305_decrypt(unsigned char *m,
|
||||
crypto_aead_xchacha20poly1305_ietf_decrypt(unsigned char *m,
|
||||
unsigned long long *mlen_p,
|
||||
unsigned char *nsec,
|
||||
const unsigned char *c,
|
||||
@ -147,16 +105,16 @@ crypto_aead_xchacha20poly1305_decrypt(unsigned char *m,
|
||||
unsigned long long mlen = 0ULL;
|
||||
int ret = -1;
|
||||
|
||||
if (clen >= crypto_aead_xchacha20poly1305_ABYTES) {
|
||||
ret = crypto_aead_xchacha20poly1305_decrypt_detached
|
||||
if (clen >= crypto_aead_xchacha20poly1305_ietf_ABYTES) {
|
||||
ret = crypto_aead_xchacha20poly1305_ietf_decrypt_detached
|
||||
(m, nsec,
|
||||
c, clen - crypto_aead_xchacha20poly1305_ABYTES,
|
||||
c + clen - crypto_aead_xchacha20poly1305_ABYTES,
|
||||
c, clen - crypto_aead_xchacha20poly1305_ietf_ABYTES,
|
||||
c + clen - crypto_aead_xchacha20poly1305_ietf_ABYTES,
|
||||
ad, adlen, npub, k);
|
||||
}
|
||||
if (mlen_p != NULL) {
|
||||
if (ret == 0) {
|
||||
mlen = clen - crypto_aead_xchacha20poly1305_ABYTES;
|
||||
mlen = clen - crypto_aead_xchacha20poly1305_ietf_ABYTES;
|
||||
}
|
||||
*mlen_p = mlen;
|
||||
}
|
||||
@ -164,21 +122,21 @@ crypto_aead_xchacha20poly1305_decrypt(unsigned char *m,
|
||||
}
|
||||
|
||||
size_t
|
||||
crypto_aead_xchacha20poly1305_keybytes(void) {
|
||||
return crypto_aead_xchacha20poly1305_KEYBYTES;
|
||||
crypto_aead_xchacha20poly1305_ietf_keybytes(void) {
|
||||
return crypto_aead_xchacha20poly1305_ietf_KEYBYTES;
|
||||
}
|
||||
|
||||
size_t
|
||||
crypto_aead_xchacha20poly1305_npubbytes(void) {
|
||||
return crypto_aead_xchacha20poly1305_NPUBBYTES;
|
||||
crypto_aead_xchacha20poly1305_ietf_npubbytes(void) {
|
||||
return crypto_aead_xchacha20poly1305_ietf_NPUBBYTES;
|
||||
}
|
||||
|
||||
size_t
|
||||
crypto_aead_xchacha20poly1305_nsecbytes(void) {
|
||||
return crypto_aead_xchacha20poly1305_NSECBYTES;
|
||||
crypto_aead_xchacha20poly1305_ietf_nsecbytes(void) {
|
||||
return crypto_aead_xchacha20poly1305_ietf_NSECBYTES;
|
||||
}
|
||||
|
||||
size_t
|
||||
crypto_aead_xchacha20poly1305_abytes(void) {
|
||||
return crypto_aead_xchacha20poly1305_ABYTES;
|
||||
crypto_aead_xchacha20poly1305_ietf_abytes(void) {
|
||||
return crypto_aead_xchacha20poly1305_ietf_ABYTES;
|
||||
}
|
||||
|
@ -11,24 +11,24 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_aead_xchacha20poly1305_KEYBYTES 32U
|
||||
#define crypto_aead_xchacha20poly1305_ietf_KEYBYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_aead_xchacha20poly1305_keybytes(void);
|
||||
size_t crypto_aead_xchacha20poly1305_ietf_keybytes(void);
|
||||
|
||||
#define crypto_aead_xchacha20poly1305_NSECBYTES 0U
|
||||
#define crypto_aead_xchacha20poly1305_ietf_NSECBYTES 0U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_aead_xchacha20poly1305_nsecbytes(void);
|
||||
size_t crypto_aead_xchacha20poly1305_ietf_nsecbytes(void);
|
||||
|
||||
#define crypto_aead_xchacha20poly1305_NPUBBYTES 24U
|
||||
#define crypto_aead_xchacha20poly1305_ietf_NPUBBYTES 24U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_aead_xchacha20poly1305_npubbytes(void);
|
||||
size_t crypto_aead_xchacha20poly1305_ietf_npubbytes(void);
|
||||
|
||||
#define crypto_aead_xchacha20poly1305_ABYTES 16U
|
||||
#define crypto_aead_xchacha20poly1305_ietf_ABYTES 16U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_aead_xchacha20poly1305_abytes(void);
|
||||
size_t crypto_aead_xchacha20poly1305_ietf_abytes(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_aead_xchacha20poly1305_encrypt(unsigned char *c,
|
||||
int crypto_aead_xchacha20poly1305_ietf_encrypt(unsigned char *c,
|
||||
unsigned long long *clen_p,
|
||||
const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
@ -39,7 +39,7 @@ int crypto_aead_xchacha20poly1305_encrypt(unsigned char *c,
|
||||
const unsigned char *k);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_aead_xchacha20poly1305_decrypt(unsigned char *m,
|
||||
int crypto_aead_xchacha20poly1305_ietf_decrypt(unsigned char *m,
|
||||
unsigned long long *mlen_p,
|
||||
unsigned char *nsec,
|
||||
const unsigned char *c,
|
||||
@ -51,7 +51,7 @@ int crypto_aead_xchacha20poly1305_decrypt(unsigned char *m,
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_aead_xchacha20poly1305_encrypt_detached(unsigned char *c,
|
||||
int crypto_aead_xchacha20poly1305_ietf_encrypt_detached(unsigned char *c,
|
||||
unsigned char *mac,
|
||||
unsigned long long *maclen_p,
|
||||
const unsigned char *m,
|
||||
@ -63,7 +63,7 @@ int crypto_aead_xchacha20poly1305_encrypt_detached(unsigned char *c,
|
||||
const unsigned char *k);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_aead_xchacha20poly1305_decrypt_detached(unsigned char *m,
|
||||
int crypto_aead_xchacha20poly1305_ietf_decrypt_detached(unsigned char *m,
|
||||
unsigned char *nsec,
|
||||
const unsigned char *c,
|
||||
unsigned long long clen,
|
||||
@ -74,6 +74,13 @@ int crypto_aead_xchacha20poly1305_decrypt_detached(unsigned char *m,
|
||||
const unsigned char *k)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
/* Aliases */
|
||||
|
||||
#define crypto_aead_xchacha20poly1305_IETF_KEYBYTES crypto_aead_xchacha20poly1305_ietf_KEYBYTES
|
||||
#define crypto_aead_xchacha20poly1305_IETF_NSECBYTES crypto_aead_xchacha20poly1305_ietf_NSECBYTES
|
||||
#define crypto_aead_xchacha20poly1305_IETF_NPUBBYTES crypto_aead_xchacha20poly1305_ietf_NPUBBYTES
|
||||
#define crypto_aead_xchacha20poly1305_IETF_ABYTES crypto_aead_xchacha20poly1305_ietf_ABYTES
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -6,7 +6,11 @@
|
||||
# include <sys/time.h>
|
||||
#endif
|
||||
#ifdef __linux__
|
||||
# ifdef __dietlibc__
|
||||
# define _LINUX_SOURCE
|
||||
# else
|
||||
# include <sys/syscall.h>
|
||||
# endif
|
||||
# include <poll.h>
|
||||
#endif
|
||||
|
||||
@ -207,7 +211,7 @@ randombytes_salsa20_random_random_dev_open(void)
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(SYS_getrandom) && defined(__NR_getrandom)
|
||||
# if defined(__dietlibc__) || (defined(SYS_getrandom) && defined(__NR_getrandom))
|
||||
static int
|
||||
_randombytes_linux_getrandom(void * const buf, const size_t size)
|
||||
{
|
||||
@ -215,7 +219,11 @@ _randombytes_linux_getrandom(void * const buf, const size_t size)
|
||||
|
||||
assert(size <= 256U);
|
||||
do {
|
||||
# ifdef __dietlibc__
|
||||
readnb = getrandom(buf, size, 0);
|
||||
# else
|
||||
readnb = syscall(SYS_getrandom, buf, (int) size, 0);
|
||||
# endif
|
||||
} while (readnb < 0 && (errno == EINTR || errno == EAGAIN));
|
||||
|
||||
return (readnb == (int) size) - 1;
|
||||
|
@ -6,7 +6,11 @@
|
||||
# include <sys/time.h>
|
||||
#endif
|
||||
#ifdef __linux__
|
||||
# ifdef __dietlibc__
|
||||
# define _LINUX_SOURCE
|
||||
# else
|
||||
# include <sys/syscall.h>
|
||||
# endif
|
||||
# include <poll.h>
|
||||
#endif
|
||||
|
||||
@ -189,7 +193,7 @@ randombytes_sysrandom_random_dev_open(void)
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
||||
# if defined(SYS_getrandom) && defined(__NR_getrandom)
|
||||
# if defined(__dietlibc__) || (defined(SYS_getrandom) && defined(__NR_getrandom))
|
||||
static int
|
||||
_randombytes_linux_getrandom(void * const buf, const size_t size)
|
||||
{
|
||||
@ -197,7 +201,11 @@ _randombytes_linux_getrandom(void * const buf, const size_t size)
|
||||
|
||||
assert(size <= 256U);
|
||||
do {
|
||||
# ifdef __dietlibc__
|
||||
readnb = getrandom(buf, size, 0);
|
||||
# else
|
||||
readnb = syscall(SYS_getrandom, buf, (int) size, 0);
|
||||
# endif
|
||||
} while (readnb < 0 && (errno == EINTR || errno == EAGAIN));
|
||||
|
||||
return (readnb == (int) size) - 1;
|
||||
|
Loading…
Reference in New Issue
Block a user