mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-06-18 08:07:12 +02:00
Add MariaDB Connector/C as a built-in alternative (v3.2.3).
This commit is contained in:
132
vendor/MDBC/plugins/auth/CMakeLists.txt
vendored
Normal file
132
vendor/MDBC/plugins/auth/CMakeLists.txt
vendored
Normal file
@ -0,0 +1,132 @@
|
||||
SET(AUTH_DIR ${CC_SOURCE_DIR}/plugins/auth)
|
||||
|
||||
INCLUDE_DIRECTORIES(${AUTH_DIR})
|
||||
INCLUDE_DIRECTORIES(${CC_SOURCE_DIR}/include)
|
||||
|
||||
SET(CRYPTO_PLUGIN 1)
|
||||
IF(WIN32)
|
||||
SET(CRYPT_SOURCE ${CC_SOURCE_DIR}/libmariadb/secure/win_crypt.c)
|
||||
SET(CRYPT_LIBS crypt32 bcrypt)
|
||||
ELSEIF(WITH_SSL STREQUAL "OPENSSL")
|
||||
SET(CRYPT_SOURCE ${CC_SOURCE_DIR}/libmariadb/secure/openssl_crypt.c)
|
||||
SET(CRYPT_LIBS ${SSL_LIBRARIES})
|
||||
ELSEIF(WITH_SSL STREQUAL "GNUTLS")
|
||||
SET(CRYPT_SOURCE ${CC_SOURCE_DIR}/libmariadb/secure/gnutls_crypt.c)
|
||||
IF (NOT SSL_LIBRARIES MATCHES "^.*\\.a$")
|
||||
SET(CRYPT_LIBS ${SSL_LIBRARIES})
|
||||
ENDIF()
|
||||
ELSE()
|
||||
UNSET(CRYPTO_PLUGIN)
|
||||
ENDIF()
|
||||
|
||||
#native password
|
||||
REGISTER_PLUGIN(TARGET mysql_native_password
|
||||
TYPE MARIADB_CLIENT_PLUGIN_AUTH
|
||||
CONFIGURATIONS STATIC
|
||||
DEFAULT STATIC
|
||||
SOURCES ${CC_SOURCE_DIR}/plugins/auth/my_auth.c)
|
||||
|
||||
#Dialog client authentication plugin
|
||||
REGISTER_PLUGIN(TARGET dialog
|
||||
TYPE MARIADB_CLIENT_PLUGIN_AUTH
|
||||
CONFIGURATIONS DYNAMIC STATIC OFF
|
||||
DEFAULT DYNAMIC
|
||||
SOURCES ${CC_SOURCE_DIR}/plugins/auth/dialog.c
|
||||
${CC_SOURCE_DIR}/libmariadb/get_password.c)
|
||||
|
||||
|
||||
# Crypto plugins
|
||||
IF(CRYPTO_PLUGIN)
|
||||
|
||||
#ED25519 client authentication plugin
|
||||
SET(REF10_DIR ${CC_SOURCE_DIR}/plugins/auth/ref10)
|
||||
SET(REF10_SOURCES ${REF10_DIR}/fe_0.c ${REF10_DIR}/fe_isnegative.c ${REF10_DIR}/fe_sub.c ${REF10_DIR}/ge_p1p1_to_p2.c
|
||||
${REF10_DIR}/ge_p3_to_cached.c ${REF10_DIR}/open.c ${REF10_DIR}/fe_1.c ${REF10_DIR}/fe_isnonzero.c
|
||||
${REF10_DIR}/fe_tobytes.c ${REF10_DIR}/ge_p1p1_to_p3.c ${REF10_DIR}/ge_p3_to_p2.c ${REF10_DIR}/sc_muladd.c
|
||||
${REF10_DIR}/fe_add.c ${REF10_DIR}/fe_mul.c ${REF10_DIR}/ge_add.c ${REF10_DIR}/ge_p2_0.c ${REF10_DIR}/ge_precomp_0.c
|
||||
${REF10_DIR}/sc_reduce.c ${REF10_DIR}/fe_cmov.c ${REF10_DIR}/fe_neg.c ${REF10_DIR}/ge_double_scalarmult.c
|
||||
${REF10_DIR}/ge_p2_dbl.c ${REF10_DIR}/ge_scalarmult_base.c ${REF10_DIR}/sign.c ${REF10_DIR}/fe_copy.c
|
||||
${REF10_DIR}/fe_pow22523.c ${REF10_DIR}/ge_frombytes.c ${REF10_DIR}/ge_p3_0.c ${REF10_DIR}/ge_sub.c
|
||||
${REF10_DIR}/verify.c ${REF10_DIR}/fe_frombytes.c ${REF10_DIR}/fe_sq2.c ${REF10_DIR}/ge_madd.c
|
||||
${REF10_DIR}/ge_p3_dbl.c ${REF10_DIR}/ge_tobytes.c ${REF10_DIR}/fe_invert.c ${REF10_DIR}/fe_sq.c
|
||||
${REF10_DIR}/ge_msub.c ${REF10_DIR}/ge_p3_tobytes.c ${REF10_DIR}/keypair.c)
|
||||
|
||||
REGISTER_PLUGIN(TARGET client_ed25519
|
||||
TYPE MARIADB_CLIENT_PLUGIN_AUTH
|
||||
CONFIGURATIONS DYNAMIC STATIC OFF
|
||||
DEFAULT DYNAMIC
|
||||
SOURCES ${CC_SOURCE_DIR}/plugins/auth/ed25519.c
|
||||
${REF10_SOURCES}
|
||||
${CRYPT_SOURCE}
|
||||
INCLUDES ${REF10_DIR}
|
||||
LIBRARIES ${CRYPT_LIBS}
|
||||
COMPILE_OPTIONS -DMYSQL_CLIENT=1)
|
||||
IF(MSVC)
|
||||
# Silence conversion (integer truncantion) warnings from reference code
|
||||
SET_SOURCE_FILES_PROPERTIES(${REF10_SOURCES} PROPERTY COMPILE_FLAGS "-DMYSQL_CLIENT=1 /wd4244 /wd4146")
|
||||
ENDIF()
|
||||
|
||||
IF(CMAKE_C_COMPILER_ID MATCHES "GNU" AND CMAKE_C_COMPILER_VERSION LESS 11
|
||||
AND CMAKE_C_COMPILER_VERSION GREATER 6)
|
||||
SET_SOURCE_FILES_PROPERTIES(${REF10_SOURCES} PROPERTY COMPILE_FLAGS
|
||||
-fno-sanitize=shift)
|
||||
ENDIF()
|
||||
|
||||
# SHA256 caching plugin for MySQL 8.0 connection
|
||||
REGISTER_PLUGIN(TARGET caching_sha2_password
|
||||
TYPE MARIADB_CLIENT_PLUGIN_AUTH
|
||||
CONFIGURATIONS DYNAMIC STATIC OFF
|
||||
DEFAULT DYNAMIC
|
||||
SOURCES ${CC_SOURCE_DIR}/plugins/auth/caching_sha2_pw.c
|
||||
${CRYPT_SOURCE}
|
||||
LIBRARIES ${CRYPT_LIBS})
|
||||
|
||||
IF(WITH_SSL STREQUAL "GNUTLS" AND NOT WIN32)
|
||||
MESSAGE1(STATUS "sha256_password not supported by GnuTLS due to missing OAEP padding")
|
||||
ELSE()
|
||||
REGISTER_PLUGIN(TARGET sha256_password
|
||||
TYPE MARIADB_CLIENT_PLUGIN_AUTH
|
||||
CONFIGURATIONS DYNAMIC STATIC OFF
|
||||
DEFAULT DYNAMIC
|
||||
SOURCES ${AUTH_DIR}/sha256_pw.c
|
||||
LIBRARIES ${CRYPT_LIBS})
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
|
||||
#GSSAPI client authentication plugin
|
||||
IF(NOT WIN32)
|
||||
INCLUDE(${CC_SOURCE_DIR}/cmake/FindGSSAPI.cmake)
|
||||
IF(GSSAPI_FOUND)
|
||||
SET(GSSAPI_SOURCES ${AUTH_DIR}/auth_gssapi_client.c ${AUTH_DIR}/gssapi_client.c ${AUTH_DIR}/gssapi_errmsg.c)
|
||||
ENDIF()
|
||||
ELSE()
|
||||
SET(GSSAPI_LIBS secur32)
|
||||
SET(GSSAPI_SOURCES ${AUTH_DIR}/auth_gssapi_client.c ${AUTH_DIR}/sspi_client.c ${AUTH_DIR}/sspi_errmsg.c)
|
||||
ENDIF()
|
||||
IF(GSSAPI_SOURCES)
|
||||
REGISTER_PLUGIN(TARGET auth_gssapi_client
|
||||
TYPE MARIADB_CLIENT_PLUGIN_AUTH
|
||||
CONFIGURATIONS DYNAMIC STATIC OFF
|
||||
DEFAULT DYNAMIC
|
||||
SOURCES ${GSSAPI_SOURCES}
|
||||
INCLUDES ${CC_SOURCE_DIR}/plugins/auth ${GSSAPI_INCS}
|
||||
LIBRARIES ${GSSAPI_LIBS})
|
||||
IF(CMAKE_C_COMPILER_ID MATCHES "Clang")
|
||||
SET_SOURCE_FILES_PROPERTIES(${GSSAPI_SOURCES} PROPERTY COMPILE_FLAGS "-Wno-deprecated-declarations")
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
|
||||
# old_password plugin
|
||||
REGISTER_PLUGIN(TARGET mysql_old_password
|
||||
TYPE MARIADB_CLIENT_PLUGIN_AUTH
|
||||
CONFIGURATIONS STATIC DYNAMIC OFF
|
||||
DEFAULT STATIC
|
||||
SOURCES ${AUTH_DIR}/old_password.c)
|
||||
|
||||
# Cleartext
|
||||
REGISTER_PLUGIN(TARGET mysql_clear_password
|
||||
TYPE MARIADB_CLIENT_PLUGIN_AUTH
|
||||
CONFIGURATIONS DYNAMIC STATIC OFF
|
||||
DEFAULT DYNAMIC
|
||||
SOURCES ${AUTH_DIR}/mariadb_cleartext.c)
|
||||
|
121
vendor/MDBC/plugins/auth/auth_gssapi_client.c
vendored
Normal file
121
vendor/MDBC/plugins/auth/auth_gssapi_client.c
vendored
Normal file
@ -0,0 +1,121 @@
|
||||
/* Copyright (c) 2015-2016, Shuang Qiu, Robbie Harwood,
|
||||
Vladislav Vaintroub & MariaDB Corporation
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
@file
|
||||
|
||||
GSSAPI authentication plugin, client side
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <ma_global.h>
|
||||
#include <mysql.h>
|
||||
#include <ma_server_error.h>
|
||||
#include <mysql/client_plugin.h>
|
||||
#include <mysql.h>
|
||||
#include <stdio.h>
|
||||
#include "common.h"
|
||||
|
||||
extern int auth_client(char *principal_name,
|
||||
char *mech,
|
||||
MYSQL *mysql,
|
||||
MYSQL_PLUGIN_VIO *vio);
|
||||
|
||||
static void parse_server_packet(char *packet, size_t packet_len, char *spn, char *mech)
|
||||
{
|
||||
size_t spn_len;
|
||||
spn_len = strnlen(packet, packet_len);
|
||||
strncpy(spn, packet, PRINCIPAL_NAME_MAX);
|
||||
if (spn_len == packet_len - 1)
|
||||
{
|
||||
/* Mechanism not included into packet */
|
||||
*mech = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
strncpy(mech, packet + spn_len + 1, MECH_NAME_MAX);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Set client error message.
|
||||
*/
|
||||
void log_client_error(MYSQL *mysql, const char *format, ...)
|
||||
{
|
||||
NET *net= &mysql->net;
|
||||
va_list args;
|
||||
|
||||
net->last_errno= ER_UNKNOWN_ERROR;
|
||||
va_start(args, format);
|
||||
vsnprintf(net->last_error, sizeof(net->last_error) - 1,
|
||||
format, args);
|
||||
va_end(args);
|
||||
memcpy(net->sqlstate, "HY000", sizeof(net->sqlstate));
|
||||
}
|
||||
|
||||
/**
|
||||
The main client function of the GSSAPI plugin.
|
||||
*/
|
||||
static int gssapi_auth_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql)
|
||||
{
|
||||
int packet_len;
|
||||
unsigned char *packet;
|
||||
char spn[PRINCIPAL_NAME_MAX + 1];
|
||||
char mech[MECH_NAME_MAX + 1];
|
||||
|
||||
/* read from server for service principal name */
|
||||
packet_len= vio->read_packet(vio, &packet);
|
||||
if (packet_len < 0)
|
||||
{
|
||||
return CR_ERROR;
|
||||
}
|
||||
parse_server_packet((char *)packet, (size_t)packet_len, spn, mech);
|
||||
return auth_client(spn, mech, mysql, vio);
|
||||
}
|
||||
|
||||
|
||||
/* register client plugin */
|
||||
#ifndef PLUGIN_DYNAMIC
|
||||
struct st_mysql_client_plugin_AUTHENTICATION auth_gssapi_client_client_plugin=
|
||||
#else
|
||||
struct st_mysql_client_plugin_AUTHENTICATION _mysql_client_plugin_declaration_ =
|
||||
#endif
|
||||
{
|
||||
MYSQL_CLIENT_AUTHENTICATION_PLUGIN,
|
||||
MYSQL_CLIENT_AUTHENTICATION_PLUGIN_INTERFACE_VERSION,
|
||||
"auth_gssapi_client",
|
||||
"Shuang Qiu, Robbie Harwood, Vladislav Vaintroub, Georg Richter",
|
||||
"GSSAPI/SSPI based authentication",
|
||||
{0, 1, 0},
|
||||
"BSD",
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
gssapi_auth_client
|
||||
};
|
486
vendor/MDBC/plugins/auth/caching_sha2_pw.c
vendored
Normal file
486
vendor/MDBC/plugins/auth/caching_sha2_pw.c
vendored
Normal file
@ -0,0 +1,486 @@
|
||||
/************************************************************************************
|
||||
Copyright (C) 2017 MariaDB Corporation AB
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not see <http://www.gnu.org/licenses>
|
||||
or write to the Free Software Foundation, Inc.,
|
||||
51 Franklin St., Fifth Floor, Boston, MA 02110, USA
|
||||
*************************************************************************************/
|
||||
#ifndef _WIN32
|
||||
#define _GNU_SOURCE 1
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#define HAVE_WINCRYPT
|
||||
#undef HAVE_OPENSSL
|
||||
#undef HAVE_GNUTLS
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_OPENSSL) || defined(HAVE_WINCRYPT) || defined(HAVE_GNUTLS)
|
||||
|
||||
#include <ma_global.h>
|
||||
#include <mysql.h>
|
||||
#include <mysql/client_plugin.h>
|
||||
#include <string.h>
|
||||
#include <memory.h>
|
||||
#include <errmsg.h>
|
||||
#include <ma_global.h>
|
||||
#include <ma_sys.h>
|
||||
#include <ma_common.h>
|
||||
|
||||
#ifndef WIN32
|
||||
#include <dlfcn.h>
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_OPENSSL)
|
||||
#include <openssl/rsa.h>
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/err.h>
|
||||
#elif defined(HAVE_GNUTLS)
|
||||
#include <gnutls/gnutls.h>
|
||||
#elif defined(HAVE_WINCRYPT)
|
||||
#include <windows.h>
|
||||
#include <wincrypt.h>
|
||||
#include <bcrypt.h>
|
||||
|
||||
extern BCRYPT_ALG_HANDLE RsaProv;
|
||||
extern BCRYPT_ALG_HANDLE Sha256Prov;
|
||||
#endif
|
||||
|
||||
#include <ma_crypt.h>
|
||||
|
||||
#define MAX_PW_LEN 1024
|
||||
|
||||
#define REQUEST_PUBLIC_KEY 2
|
||||
#define CACHED_LOGIN_SUCCEEDED 3
|
||||
#define RSA_LOGIN_REQUIRED 4
|
||||
|
||||
/* MySQL server allows requesting public key only for non secure connections.
|
||||
secure connections are:
|
||||
- TLS/SSL connections
|
||||
- unix_socket connections
|
||||
*/
|
||||
static unsigned char is_connection_secure(MYSQL *mysql)
|
||||
{
|
||||
if (mysql->options.use_ssl ||
|
||||
mysql->net.pvio->type != PVIO_TYPE_SOCKET)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ma_sha256_scramble(unsigned char *scramble, size_t scramble_len,
|
||||
unsigned char *source, size_t source_len,
|
||||
unsigned char *salt, size_t salt_len)
|
||||
{
|
||||
unsigned char digest1[MA_SHA256_HASH_SIZE],
|
||||
digest2[MA_SHA256_HASH_SIZE],
|
||||
new_scramble[MA_SHA256_HASH_SIZE];
|
||||
#ifdef HAVE_WINCRYPT
|
||||
MA_HASH_CTX myctx;
|
||||
MA_HASH_CTX *ctx= &myctx;
|
||||
#else
|
||||
MA_HASH_CTX *ctx = NULL;
|
||||
#endif
|
||||
size_t i;
|
||||
|
||||
/* check if all specified lengtht are valid */
|
||||
if (!scramble_len || !source_len || !salt_len)
|
||||
return 1;
|
||||
|
||||
|
||||
/* Step1: create sha256 from source */
|
||||
if (!(ctx= ma_hash_new(MA_HASH_SHA256, ctx)))
|
||||
return 1;
|
||||
ma_hash_input(ctx, source, source_len);
|
||||
ma_hash_result(ctx, digest1);
|
||||
ma_hash_free(ctx);
|
||||
#ifndef HAVE_WINCRYPT
|
||||
ctx = NULL;
|
||||
#endif
|
||||
|
||||
/* Step2: create sha256 digest from digest1 */
|
||||
if (!(ctx= ma_hash_new(MA_HASH_SHA256, ctx)))
|
||||
return 1;
|
||||
ma_hash_input(ctx, digest1, MA_SHA256_HASH_SIZE);
|
||||
ma_hash_result(ctx, digest2);
|
||||
ma_hash_free(ctx);
|
||||
#ifndef HAVE_WINCRYPT
|
||||
ctx = NULL;
|
||||
#endif
|
||||
|
||||
/* Step3: create sha256 digest from digest2 + salt */
|
||||
if (!(ctx= ma_hash_new(MA_HASH_SHA256, ctx)))
|
||||
return 1;
|
||||
ma_hash_input(ctx, digest2, MA_SHA256_HASH_SIZE);
|
||||
ma_hash_input(ctx, salt, salt_len);
|
||||
ma_hash_result(ctx, new_scramble);
|
||||
ma_hash_free(ctx);
|
||||
|
||||
/* Step4: xor(digest1, scramble1) */
|
||||
for (i= 0; i < scramble_len; i++)
|
||||
scramble[i]= digest1[i] ^ new_scramble[i];
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* function prototypes */
|
||||
static int auth_caching_sha2_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql);
|
||||
static int auth_caching_sha2_deinit(void);
|
||||
static int auth_caching_sha2_init(char *unused1,
|
||||
size_t unused2,
|
||||
int unused3,
|
||||
va_list);
|
||||
|
||||
|
||||
#ifndef PLUGIN_DYNAMIC
|
||||
struct st_mysql_client_plugin_AUTHENTICATION caching_sha2_password_client_plugin=
|
||||
#else
|
||||
struct st_mysql_client_plugin_AUTHENTICATION _mysql_client_plugin_declaration_ =
|
||||
#endif
|
||||
{
|
||||
MYSQL_CLIENT_AUTHENTICATION_PLUGIN,
|
||||
MYSQL_CLIENT_AUTHENTICATION_PLUGIN_INTERFACE_VERSION,
|
||||
"caching_sha2_password",
|
||||
"Georg Richter",
|
||||
"Caching SHA2 Authentication Plugin",
|
||||
{0,1,0},
|
||||
"LGPL",
|
||||
NULL,
|
||||
auth_caching_sha2_init,
|
||||
auth_caching_sha2_deinit,
|
||||
NULL,
|
||||
auth_caching_sha2_client
|
||||
};
|
||||
|
||||
#ifdef HAVE_WINCRYPT
|
||||
static LPBYTE ma_load_pem(const char *buffer, DWORD *buffer_len)
|
||||
{
|
||||
LPBYTE der_buffer= NULL;
|
||||
DWORD der_buffer_length= 0;
|
||||
|
||||
if (buffer_len == NULL || *buffer_len == 0)
|
||||
return NULL;
|
||||
/* calculate the length of DER binary */
|
||||
if (!CryptStringToBinaryA(buffer, *buffer_len, CRYPT_STRING_BASE64HEADER,
|
||||
NULL, &der_buffer_length, NULL, NULL))
|
||||
goto end;
|
||||
/* allocate DER binary buffer */
|
||||
if (!(der_buffer= (LPBYTE)malloc(der_buffer_length)))
|
||||
goto end;
|
||||
/* convert to DER binary */
|
||||
if (!CryptStringToBinaryA(buffer, *buffer_len, CRYPT_STRING_BASE64HEADER,
|
||||
der_buffer, &der_buffer_length, NULL, NULL))
|
||||
goto end;
|
||||
|
||||
*buffer_len= der_buffer_length;
|
||||
|
||||
return der_buffer;
|
||||
|
||||
end:
|
||||
if (der_buffer)
|
||||
free(der_buffer);
|
||||
*buffer_len= 0;
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_GNUTLS
|
||||
static char *load_pub_key_file(const char *filename, int *pub_key_size)
|
||||
{
|
||||
FILE *fp= NULL;
|
||||
char *buffer= NULL;
|
||||
unsigned char error= 1;
|
||||
|
||||
if (!pub_key_size)
|
||||
return NULL;
|
||||
|
||||
if (!(fp= fopen(filename, "r")))
|
||||
goto end;
|
||||
|
||||
if (fseek(fp, 0, SEEK_END))
|
||||
goto end;
|
||||
|
||||
if ((*pub_key_size= ftell(fp)) < 0)
|
||||
goto end;
|
||||
|
||||
rewind(fp);
|
||||
|
||||
if (!(buffer= malloc(*pub_key_size + 1)))
|
||||
goto end;
|
||||
|
||||
if (fread(buffer, *pub_key_size, 1, fp) != (size_t)*pub_key_size)
|
||||
goto end;
|
||||
|
||||
error= 0;
|
||||
|
||||
end:
|
||||
if (fp)
|
||||
fclose(fp);
|
||||
if (error && buffer)
|
||||
{
|
||||
free(buffer);
|
||||
buffer= NULL;
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int auth_caching_sha2_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql)
|
||||
{
|
||||
unsigned char *packet;
|
||||
int packet_length;
|
||||
int rc= CR_ERROR;
|
||||
#if !defined(HAVE_GNUTLS)
|
||||
char passwd[MAX_PW_LEN];
|
||||
#ifdef HAVE_OPENSSL
|
||||
unsigned char *rsa_enc_pw= NULL;
|
||||
size_t rsa_size;
|
||||
#else
|
||||
unsigned char rsa_enc_pw[MAX_PW_LEN];
|
||||
ULONG rsa_size;
|
||||
#endif
|
||||
unsigned int pwlen, i;
|
||||
char *filebuffer= NULL;
|
||||
#endif
|
||||
unsigned char buf[MA_SHA256_HASH_SIZE];
|
||||
|
||||
#if defined(HAVE_OPENSSL)
|
||||
EVP_PKEY *pubkey= NULL;
|
||||
EVP_PKEY_CTX *ctx= NULL;
|
||||
BIO *bio;
|
||||
size_t outlen;
|
||||
#elif defined(HAVE_WINCRYPT)
|
||||
BCRYPT_KEY_HANDLE pubkey= 0;
|
||||
BCRYPT_OAEP_PADDING_INFO paddingInfo;
|
||||
LPBYTE der_buffer= NULL;
|
||||
DWORD der_buffer_len= 0;
|
||||
CERT_PUBLIC_KEY_INFO *publicKeyInfo= NULL;
|
||||
DWORD publicKeyInfoLen;
|
||||
#endif
|
||||
|
||||
/* read error */
|
||||
if ((packet_length= vio->read_packet(vio, &packet)) < 0)
|
||||
return CR_ERROR;
|
||||
|
||||
if (packet_length != SCRAMBLE_LENGTH + 1)
|
||||
return CR_SERVER_HANDSHAKE_ERR;
|
||||
|
||||
memmove(mysql->scramble_buff, packet, SCRAMBLE_LENGTH);
|
||||
mysql->scramble_buff[SCRAMBLE_LENGTH]= 0;
|
||||
|
||||
/* send empty packet if no password was provided */
|
||||
if (!mysql->passwd || !mysql->passwd[0])
|
||||
{
|
||||
if (vio->write_packet(vio, 0, 0))
|
||||
return CR_ERROR;
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
/* This is the normal authentication, if the host/user key is already in server
|
||||
cache. In case authentication will fail, we will not return an error but will
|
||||
try to connect via RSA encryption.
|
||||
*/
|
||||
if (ma_sha256_scramble(buf, MA_SHA256_HASH_SIZE,
|
||||
(unsigned char *)mysql->passwd, strlen(mysql->passwd),
|
||||
(unsigned char *)mysql->scramble_buff, SCRAMBLE_LENGTH))
|
||||
return CR_ERROR;
|
||||
|
||||
if (vio->write_packet(vio, buf, MA_SHA256_HASH_SIZE))
|
||||
return CR_ERROR;
|
||||
if ((packet_length=vio->read_packet(vio, &packet)) == -1)
|
||||
return CR_ERROR;
|
||||
if (packet_length == 1)
|
||||
{
|
||||
switch (*packet) {
|
||||
case CACHED_LOGIN_SUCCEEDED:
|
||||
return CR_OK;
|
||||
case RSA_LOGIN_REQUIRED:
|
||||
break;
|
||||
default:
|
||||
return CR_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_connection_secure(mysql))
|
||||
{
|
||||
#if defined(HAVE_GNUTLS)
|
||||
mysql->methods->set_error(mysql, CR_AUTH_PLUGIN_ERR, "HY000",
|
||||
"RSA Encryption not supported - caching_sha2_password plugin was built with GnuTLS support");
|
||||
return CR_ERROR;
|
||||
#else
|
||||
/* read public key file (if specified) */
|
||||
if (mysql->options.extension &&
|
||||
mysql->options.extension->server_public_key)
|
||||
{
|
||||
filebuffer= load_pub_key_file(mysql->options.extension->server_public_key,
|
||||
&packet_length);
|
||||
}
|
||||
|
||||
/* if no public key file was specified or if we couldn't read the file,
|
||||
we ask server to send public key */
|
||||
if (!filebuffer)
|
||||
{
|
||||
unsigned char request= REQUEST_PUBLIC_KEY;
|
||||
if (vio->write_packet(vio, &request, 1) ||
|
||||
(packet_length=vio->read_packet(vio, &packet)) == -1)
|
||||
{
|
||||
mysql->methods->set_error(mysql, CR_AUTH_PLUGIN_ERR, "HY000", "Couldn't read RSA public key from server");
|
||||
return CR_ERROR;
|
||||
}
|
||||
}
|
||||
#if defined(HAVE_OPENSSL)
|
||||
bio= BIO_new_mem_buf(filebuffer ? (unsigned char *)filebuffer : packet,
|
||||
packet_length);
|
||||
if ((pubkey= PEM_read_bio_PUBKEY(bio, NULL, NULL, NULL)))
|
||||
{
|
||||
if (!(ctx= EVP_PKEY_CTX_new(pubkey, NULL)))
|
||||
goto error;
|
||||
if (EVP_PKEY_encrypt_init(ctx) <= 0)
|
||||
goto error;
|
||||
if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_OAEP_PADDING) <= 0)
|
||||
goto error;
|
||||
rsa_size= EVP_PKEY_size(pubkey);
|
||||
}
|
||||
BIO_free(bio);
|
||||
bio= NULL;
|
||||
ERR_clear_error();
|
||||
#elif defined(HAVE_WINCRYPT)
|
||||
der_buffer_len= packet_length;
|
||||
/* Load pem and convert it to binary object. New length will be returned
|
||||
in der_buffer_len */
|
||||
if (!(der_buffer= ma_load_pem(filebuffer ? filebuffer : (char *)packet, &der_buffer_len)))
|
||||
goto error;
|
||||
|
||||
/* Create context and load public key */
|
||||
if (!CryptDecodeObjectEx(X509_ASN_ENCODING, X509_PUBLIC_KEY_INFO,
|
||||
der_buffer, der_buffer_len,
|
||||
CRYPT_DECODE_ALLOC_FLAG, NULL,
|
||||
&publicKeyInfo, &publicKeyInfoLen))
|
||||
goto error;
|
||||
free(der_buffer);
|
||||
|
||||
/* Import public key as cng key */
|
||||
if (!CryptImportPublicKeyInfoEx2(X509_ASN_ENCODING, publicKeyInfo,
|
||||
CRYPT_OID_INFO_PUBKEY_ENCRYPT_KEY_FLAG,
|
||||
NULL, &pubkey))
|
||||
goto error;
|
||||
|
||||
#endif
|
||||
if (!pubkey)
|
||||
return CR_ERROR;
|
||||
|
||||
pwlen= (unsigned int)strlen(mysql->passwd) + 1; /* include terminating zero */
|
||||
if (pwlen > MAX_PW_LEN)
|
||||
goto error;
|
||||
memcpy(passwd, mysql->passwd, pwlen);
|
||||
|
||||
/* xor password with scramble */
|
||||
for (i=0; i < pwlen; i++)
|
||||
passwd[i]^= *(mysql->scramble_buff + i % SCRAMBLE_LENGTH);
|
||||
|
||||
/* encrypt scrambled password */
|
||||
#if defined(HAVE_OPENSSL)
|
||||
if (EVP_PKEY_encrypt(ctx, NULL, &outlen, (unsigned char *)passwd, pwlen) <= 0)
|
||||
goto error;
|
||||
if (!(rsa_enc_pw= malloc(outlen)))
|
||||
goto error;
|
||||
if (EVP_PKEY_encrypt(ctx, rsa_enc_pw, &outlen, (unsigned char *)passwd, pwlen) <= 0)
|
||||
goto error;
|
||||
#elif defined(HAVE_WINCRYPT)
|
||||
ZeroMemory(&paddingInfo, sizeof(paddingInfo));
|
||||
paddingInfo.pszAlgId = BCRYPT_SHA1_ALGORITHM;
|
||||
if ((rc= BCryptEncrypt(pubkey, (PUCHAR)passwd, pwlen, &paddingInfo, NULL, 0, rsa_enc_pw,
|
||||
MAX_PW_LEN, &rsa_size, BCRYPT_PAD_OAEP)))
|
||||
goto error;
|
||||
|
||||
#endif
|
||||
if (vio->write_packet(vio, rsa_enc_pw, rsa_size))
|
||||
goto error;
|
||||
|
||||
rc= CR_OK;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
if (vio->write_packet(vio, (unsigned char *)mysql->passwd, (int)strlen(mysql->passwd) + 1))
|
||||
return CR_ERROR;
|
||||
return CR_OK;
|
||||
}
|
||||
#if !defined(HAVE_GNUTLS)
|
||||
error:
|
||||
#if defined(HAVE_OPENSSL)
|
||||
if (pubkey)
|
||||
EVP_PKEY_free(pubkey);
|
||||
if (rsa_enc_pw)
|
||||
free(rsa_enc_pw);
|
||||
if (bio)
|
||||
BIO_free(bio);
|
||||
if (ctx)
|
||||
EVP_PKEY_CTX_free(ctx);
|
||||
#elif defined(HAVE_WINCRYPT)
|
||||
if (pubkey)
|
||||
BCryptDestroyKey(pubkey);
|
||||
if (publicKeyInfo)
|
||||
LocalFree(publicKeyInfo);
|
||||
#endif
|
||||
free(filebuffer);
|
||||
#endif
|
||||
return rc;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ static int auth_caching_sha2_init */
|
||||
/*
|
||||
Initialization routine
|
||||
|
||||
SYNOPSIS
|
||||
auth_sha256_init
|
||||
unused1
|
||||
unused2
|
||||
unused3
|
||||
unused4
|
||||
|
||||
DESCRIPTION
|
||||
Init function checks if the caller provides own dialog function.
|
||||
The function name must be mariadb_auth_dialog or
|
||||
mysql_authentication_dialog_ask. If the function cannot be found,
|
||||
we will use owr own simple command line input.
|
||||
|
||||
RETURN
|
||||
0 success
|
||||
*/
|
||||
static int auth_caching_sha2_init(char *unused1 __attribute__((unused)),
|
||||
size_t unused2 __attribute__((unused)),
|
||||
int unused3 __attribute__((unused)),
|
||||
va_list unused4 __attribute__((unused)))
|
||||
{
|
||||
#if defined(HAVE_WINCRYPT)
|
||||
BCryptOpenAlgorithmProvider(&Sha256Prov, BCRYPT_SHA256_ALGORITHM, NULL, 0);
|
||||
BCryptOpenAlgorithmProvider(&RsaProv, BCRYPT_RSA_ALGORITHM, NULL, 0);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ auth_caching_sha2_deinit */
|
||||
static int auth_caching_sha2_deinit(void)
|
||||
{
|
||||
#if defined(HAVE_WINCRYPT)
|
||||
BCryptCloseAlgorithmProvider(Sha256Prov, 0);
|
||||
BCryptCloseAlgorithmProvider(RsaProv, 0);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
#endif /* defined(HAVE_OPENSSL) || defined(HAVE_WINCRYPT) || defined(HAVE_GNUTLS)*/
|
||||
|
4
vendor/MDBC/plugins/auth/common.h
vendored
Normal file
4
vendor/MDBC/plugins/auth/common.h
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
/** Maximal length of the target name */
|
||||
#define PRINCIPAL_NAME_MAX 256
|
||||
/** Maximal length of the mech string */
|
||||
#define MECH_NAME_MAX 30
|
222
vendor/MDBC/plugins/auth/dialog.c
vendored
Normal file
222
vendor/MDBC/plugins/auth/dialog.c
vendored
Normal file
@ -0,0 +1,222 @@
|
||||
/************************************************************************************
|
||||
Copyright (C) 2014-2018 MariaDB Corporation AB
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not see <http://www.gnu.org/licenses>
|
||||
or write to the Free Software Foundation, Inc.,
|
||||
51 Franklin St., Fifth Floor, Boston, MA 02110, USA
|
||||
*************************************************************************************/
|
||||
#ifndef _WIN32
|
||||
#define _GNU_SOURCE 1
|
||||
#endif
|
||||
|
||||
#include <ma_global.h>
|
||||
#include <mysql.h>
|
||||
#include <mysql/client_plugin.h>
|
||||
#include <string.h>
|
||||
#include <memory.h>
|
||||
|
||||
#ifndef WIN32
|
||||
#include <dlfcn.h>
|
||||
#endif
|
||||
|
||||
|
||||
/* function prototypes */
|
||||
extern char *get_tty_password(char *opt_message, char *buff, int bufflen);
|
||||
static int auth_dialog_open(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql);
|
||||
static int auth_dialog_init(char *unused1,
|
||||
size_t unused2,
|
||||
int unused3,
|
||||
va_list);
|
||||
|
||||
mysql_authentication_dialog_ask_t auth_dialog_func;
|
||||
|
||||
#ifndef PLUGIN_DYNAMIC
|
||||
struct st_mysql_client_plugin_AUTHENTICATION dialog_client_plugin=
|
||||
#else
|
||||
struct st_mysql_client_plugin_AUTHENTICATION _mysql_client_plugin_declaration_ =
|
||||
#endif
|
||||
{
|
||||
MYSQL_CLIENT_AUTHENTICATION_PLUGIN,
|
||||
MYSQL_CLIENT_AUTHENTICATION_PLUGIN_INTERFACE_VERSION,
|
||||
"dialog",
|
||||
"Sergei Golubchik, Georg Richter",
|
||||
"Dialog Client Authentication Plugin",
|
||||
{0,1,0},
|
||||
"LGPL",
|
||||
NULL,
|
||||
auth_dialog_init,
|
||||
NULL,
|
||||
NULL,
|
||||
auth_dialog_open
|
||||
};
|
||||
|
||||
|
||||
/* {{{ static char *auth_dialog_native_prompt */
|
||||
/*
|
||||
Native dialog prompt via stdin
|
||||
|
||||
SYNOPSIS
|
||||
auth_dialog_native_prompt
|
||||
mysql connection handle
|
||||
type input type
|
||||
prompt prompt
|
||||
buffer Input buffer
|
||||
buffer_len Input buffer length
|
||||
|
||||
DESCRIPTION
|
||||
|
||||
RETURNS
|
||||
Input buffer
|
||||
*/
|
||||
static char *auth_dialog_native_prompt(MYSQL *mysql __attribute__((unused)),
|
||||
int type,
|
||||
const char *prompt,
|
||||
char *buffer,
|
||||
int buffer_len)
|
||||
{
|
||||
/* display prompt */
|
||||
fprintf(stdout, "%s", prompt);
|
||||
|
||||
memset(buffer, 0, buffer_len);
|
||||
|
||||
/* for type 2 (password) don't display input */
|
||||
if (type != 2)
|
||||
{
|
||||
if (fgets(buffer, buffer_len - 1, stdin))
|
||||
{
|
||||
/* remove trailing line break */
|
||||
size_t length= strlen(buffer);
|
||||
if (length && buffer[length - 1] == '\n')
|
||||
buffer[length - 1]= 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
get_tty_password((char *)"", buffer, buffer_len - 1);
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ static int auth_dialog_open */
|
||||
/*
|
||||
opens dialog
|
||||
|
||||
SYNOPSIS
|
||||
vio Vio
|
||||
mysql connection handle
|
||||
|
||||
DESCRIPTION
|
||||
reads prompt from server, waits for input and sends
|
||||
input to server.
|
||||
Note that first byte of prompt indicates if we have a
|
||||
password which should not be echoed to stdout.
|
||||
|
||||
RETURN
|
||||
CR_ERROR if an error occurs
|
||||
CR_OK
|
||||
CR_OK_HANDSHAKE_COMPLETE
|
||||
*/
|
||||
static int auth_dialog_open(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql)
|
||||
{
|
||||
uchar *packet;
|
||||
uchar type= 0;
|
||||
char dialog_buffer[1024];
|
||||
char *response;
|
||||
int packet_length;
|
||||
my_bool first_loop= TRUE;
|
||||
|
||||
do {
|
||||
if ((packet_length= vio->read_packet(vio, &packet)) == -1)
|
||||
/* read error */
|
||||
return CR_ERROR;
|
||||
|
||||
if (packet_length > 0)
|
||||
{
|
||||
type= *packet;
|
||||
packet++;
|
||||
|
||||
/* check for protocol packet */
|
||||
if (!type || type == 254)
|
||||
return CR_OK_HANDSHAKE_COMPLETE;
|
||||
|
||||
if ((type >> 1) == 2 &&
|
||||
first_loop &&
|
||||
mysql->passwd && mysql->passwd[0])
|
||||
response= mysql->passwd;
|
||||
else
|
||||
response= auth_dialog_func(mysql, type >> 1,
|
||||
(const char *)packet,
|
||||
dialog_buffer, 1024);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* in case mysql_change_user was called the client needs
|
||||
to send packet first */
|
||||
response= mysql->passwd;
|
||||
}
|
||||
if (!response ||
|
||||
vio->write_packet(vio, (uchar *)response, (int)strlen(response) + 1))
|
||||
return CR_ERROR;
|
||||
|
||||
first_loop= FALSE;
|
||||
|
||||
} while((type & 1) != 1);
|
||||
return CR_OK;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ static int auth_dialog_init */
|
||||
/*
|
||||
Initialization routine
|
||||
|
||||
SYNOPSIS
|
||||
auth_dialog_init
|
||||
unused1
|
||||
unused2
|
||||
unused3
|
||||
unused4
|
||||
|
||||
DESCRIPTION
|
||||
Init function checks if the caller provides own dialog function.
|
||||
The function name must be mariadb_auth_dialog or
|
||||
mysql_authentication_dialog_ask. If the function cannot be found,
|
||||
we will use owr own simple command line input.
|
||||
|
||||
RETURN
|
||||
0 success
|
||||
*/
|
||||
static int auth_dialog_init(char *unused1 __attribute__((unused)),
|
||||
size_t unused2 __attribute__((unused)),
|
||||
int unused3 __attribute__((unused)),
|
||||
va_list unused4 __attribute__((unused)))
|
||||
{
|
||||
void *func;
|
||||
#ifdef WIN32
|
||||
if (!(func= GetProcAddress(GetModuleHandle(NULL), "mariadb_auth_dialog")))
|
||||
/* for MySQL users */
|
||||
func= GetProcAddress(GetModuleHandle(NULL), "mysql_authentication_dialog_ask");
|
||||
#else
|
||||
if (!(func= dlsym(RTLD_DEFAULT, "mariadb_auth_dialog")))
|
||||
/* for MySQL users */
|
||||
func= dlsym(RTLD_DEFAULT, "mysql_authentication_dialog_ask");
|
||||
#endif
|
||||
if (func)
|
||||
auth_dialog_func= (mysql_authentication_dialog_ask_t)func;
|
||||
else
|
||||
auth_dialog_func= auth_dialog_native_prompt;
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* }}} */
|
145
vendor/MDBC/plugins/auth/ed25519.c
vendored
Normal file
145
vendor/MDBC/plugins/auth/ed25519.c
vendored
Normal file
@ -0,0 +1,145 @@
|
||||
/************************************************************************************
|
||||
Copyright (C) 2017-2019 MariaDB Corporation AB
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not see <http://www.gnu.org/licenses>
|
||||
or write to the Free Software Foundation, Inc.,
|
||||
51 Franklin St., Fifth Floor, Boston, MA 02110, USA
|
||||
*************************************************************************************/
|
||||
#ifndef _WIN32
|
||||
#define _GNU_SOURCE 1
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#define HAVE_WINCRYPT
|
||||
#undef HAVE_OPENSSL
|
||||
#undef HAVE_GNUTLS
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_OPENSSL) || defined(HAVE_WINCRYPT) || defined(HAVE_GNUTLS)
|
||||
|
||||
#include <ma_global.h>
|
||||
#include <mysql.h>
|
||||
#include <mysql/client_plugin.h>
|
||||
#include <string.h>
|
||||
#include <memory.h>
|
||||
#include <errmsg.h>
|
||||
#include <ma_global.h>
|
||||
#include <ma_sys.h>
|
||||
#include <ma_common.h>
|
||||
|
||||
#ifndef WIN32
|
||||
#include <dlfcn.h>
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_WINCRYPT)
|
||||
#include <windows.h>
|
||||
#include <wincrypt.h>
|
||||
#include <bcrypt.h>
|
||||
extern BCRYPT_ALG_HANDLE Sha512Prov;
|
||||
#elif defined(HAVE_OPENSSL)
|
||||
#include <openssl/rsa.h>
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/err.h>
|
||||
#elif defined(HAVE_GNUTLS)
|
||||
#include <gnutls/gnutls.h>
|
||||
#endif
|
||||
|
||||
#include <ref10/api.h>
|
||||
#include <ref10/common.h>
|
||||
#include <ma_crypt.h>
|
||||
|
||||
/* function prototypes */
|
||||
static int auth_ed25519_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql);
|
||||
static int auth_ed25519_deinit(void);
|
||||
static int auth_ed25519_init(char *unused1,
|
||||
size_t unused2,
|
||||
int unused3,
|
||||
va_list);
|
||||
|
||||
|
||||
#ifndef PLUGIN_DYNAMIC
|
||||
struct st_mysql_client_plugin_AUTHENTICATION client_ed25519_client_plugin=
|
||||
#else
|
||||
struct st_mysql_client_plugin_AUTHENTICATION _mysql_client_plugin_declaration_ =
|
||||
#endif
|
||||
{
|
||||
MYSQL_CLIENT_AUTHENTICATION_PLUGIN,
|
||||
MYSQL_CLIENT_AUTHENTICATION_PLUGIN_INTERFACE_VERSION,
|
||||
"client_ed25519",
|
||||
"Sergei Golubchik, Georg Richter",
|
||||
"Ed25519 Authentication Plugin",
|
||||
{0,1,0},
|
||||
"LGPL",
|
||||
NULL,
|
||||
auth_ed25519_init,
|
||||
auth_ed25519_deinit,
|
||||
NULL,
|
||||
auth_ed25519_client
|
||||
};
|
||||
|
||||
|
||||
static int auth_ed25519_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql)
|
||||
{
|
||||
unsigned char *packet,
|
||||
signature[CRYPTO_BYTES + NONCE_BYTES];
|
||||
int pkt_len;
|
||||
|
||||
/*
|
||||
Step 1: Server sends nonce
|
||||
Step 2: check that packet length is equal to NONCE_BYTES (=32)
|
||||
Step 3: Sign the nonce with password
|
||||
Steo 4: Send the signature back to server
|
||||
*/
|
||||
|
||||
/* read and check nonce */
|
||||
pkt_len= vio->read_packet(vio, &packet);
|
||||
if (pkt_len != NONCE_BYTES)
|
||||
return CR_SERVER_HANDSHAKE_ERR;
|
||||
|
||||
/* Sign nonce: the crypto_sign function is part of ref10 */
|
||||
ma_crypto_sign(signature, packet, NONCE_BYTES, (unsigned char*)mysql->passwd, strlen(mysql->passwd));
|
||||
|
||||
/* send signature to server */
|
||||
if (vio->write_packet(vio, signature, CRYPTO_BYTES))
|
||||
return CR_ERROR;
|
||||
|
||||
return CR_OK;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ static int auth_ed25519_init */
|
||||
static int auth_ed25519_init(char *unused1 __attribute__((unused)),
|
||||
size_t unused2 __attribute__((unused)),
|
||||
int unused3 __attribute__((unused)),
|
||||
va_list unused4 __attribute__((unused)))
|
||||
{
|
||||
#if defined(HAVE_WINCRYPT)
|
||||
BCryptOpenAlgorithmProvider(&Sha512Prov, BCRYPT_SHA512_ALGORITHM, NULL, 0);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ auth_ed25519_deinit */
|
||||
static int auth_ed25519_deinit(void)
|
||||
{
|
||||
#if defined(HAVE_WINCRYPT)
|
||||
BCryptCloseAlgorithmProvider(Sha512Prov, 0);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
#endif /* defined(HAVE_OPENSSL) || defined(HAVE_WINCRYPT) || defined(HAVE_GNUTLS)*/
|
||||
|
131
vendor/MDBC/plugins/auth/gssapi_client.c
vendored
Normal file
131
vendor/MDBC/plugins/auth/gssapi_client.c
vendored
Normal file
@ -0,0 +1,131 @@
|
||||
/* Copyright (c) 2015, Shuang Qiu, Robbie Harwood,
|
||||
Vladislav Vaintroub & MariaDB Corporation
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(__FreeBSD__) || defined(SOLARIS) || defined(__sun)
|
||||
#include <gssapi/gssapi.h>
|
||||
#else
|
||||
#include <gssapi.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <mysql/plugin_auth.h>
|
||||
#include <ma_server_error.h>
|
||||
#include <mysql.h>
|
||||
#include "gssapi_errmsg.h"
|
||||
|
||||
extern void log_client_error(MYSQL *mysql,const char *fmt,...);
|
||||
|
||||
|
||||
/* This sends the error to the client */
|
||||
static void log_error(MYSQL *mysql, OM_uint32 major, OM_uint32 minor, const char *msg)
|
||||
{
|
||||
if (GSS_ERROR(major))
|
||||
{
|
||||
char sysmsg[1024];
|
||||
gssapi_errmsg(major, minor, sysmsg, sizeof(sysmsg));
|
||||
log_client_error(mysql,
|
||||
"Client GSSAPI error (major %u, minor %u) : %s - %s",
|
||||
major, minor, msg, sysmsg);
|
||||
}
|
||||
else
|
||||
{
|
||||
log_client_error(mysql, "Client GSSAPI error : %s", msg);
|
||||
}
|
||||
}
|
||||
|
||||
int auth_client(char *principal_name, char *mech __attribute__((unused)),
|
||||
MYSQL *mysql, MYSQL_PLUGIN_VIO *vio)
|
||||
{
|
||||
gss_buffer_desc input= {0,0};
|
||||
int ret= CR_ERROR;
|
||||
OM_uint32 major= 0, minor= 0;
|
||||
gss_ctx_id_t ctxt= GSS_C_NO_CONTEXT;
|
||||
gss_name_t service_name= GSS_C_NO_NAME;
|
||||
|
||||
if (principal_name && principal_name[0])
|
||||
{
|
||||
/* import principal from plain text */
|
||||
gss_buffer_desc principal_name_buf;
|
||||
principal_name_buf.length= strlen(principal_name);
|
||||
principal_name_buf.value= (void *) principal_name;
|
||||
major= gss_import_name(&minor, &principal_name_buf, GSS_C_NT_USER_NAME, &service_name);
|
||||
if (GSS_ERROR(major))
|
||||
{
|
||||
log_error(mysql, major, minor, "gss_import_name");
|
||||
return CR_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
gss_buffer_desc output= {0,0};
|
||||
major= gss_init_sec_context(&minor, GSS_C_NO_CREDENTIAL, &ctxt, service_name,
|
||||
GSS_C_NO_OID, 0, 0, GSS_C_NO_CHANNEL_BINDINGS,
|
||||
&input, NULL, &output, NULL, NULL);
|
||||
if (output.length)
|
||||
{
|
||||
/* send credential */
|
||||
if(vio->write_packet(vio, (unsigned char *)output.value, output.length))
|
||||
{
|
||||
/* Server error packet contains detailed message. */
|
||||
ret= CR_OK_HANDSHAKE_COMPLETE;
|
||||
gss_release_buffer (&minor, &output);
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
gss_release_buffer (&minor, &output);
|
||||
|
||||
if (GSS_ERROR(major))
|
||||
{
|
||||
log_error(mysql, major, minor,"gss_init_sec_context");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (major & GSS_S_CONTINUE_NEEDED)
|
||||
{
|
||||
int len= vio->read_packet(vio, (unsigned char **) &input.value);
|
||||
if (len <= 0)
|
||||
{
|
||||
/* Server error packet contains detailed message. */
|
||||
ret= CR_OK_HANDSHAKE_COMPLETE;
|
||||
goto cleanup;
|
||||
}
|
||||
input.length= len;
|
||||
}
|
||||
} while (major & GSS_S_CONTINUE_NEEDED);
|
||||
|
||||
ret= CR_OK;
|
||||
|
||||
cleanup:
|
||||
if (service_name != GSS_C_NO_NAME)
|
||||
gss_release_name(&minor, &service_name);
|
||||
if (ctxt != GSS_C_NO_CONTEXT)
|
||||
gss_delete_sec_context(&minor, &ctxt, GSS_C_NO_BUFFER);
|
||||
|
||||
return ret;
|
||||
}
|
79
vendor/MDBC/plugins/auth/gssapi_errmsg.c
vendored
Normal file
79
vendor/MDBC/plugins/auth/gssapi_errmsg.c
vendored
Normal file
@ -0,0 +1,79 @@
|
||||
/* Copyright (c) 2015, Shuang Qiu, Robbie Harwood,
|
||||
Vladislav Vaintroub & MariaDB Corporation
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(__FreeBSD__) || defined(SOLARIS) || defined(__sun)
|
||||
#include <gssapi/gssapi.h>
|
||||
#else
|
||||
#include <gssapi.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
void gssapi_errmsg(OM_uint32 major, OM_uint32 minor, char *buf, size_t size)
|
||||
{
|
||||
OM_uint32 message_context;
|
||||
OM_uint32 status_code;
|
||||
OM_uint32 maj_status;
|
||||
OM_uint32 min_status;
|
||||
gss_buffer_desc status_string;
|
||||
char *p= buf;
|
||||
char *end= buf + size - 1;
|
||||
int types[] = {GSS_C_GSS_CODE,GSS_C_MECH_CODE};
|
||||
int i;
|
||||
for(i= 0; i < 2;i++)
|
||||
{
|
||||
message_context= 0;
|
||||
status_code= types[i] == GSS_C_GSS_CODE?major:minor;
|
||||
|
||||
if(!status_code)
|
||||
continue;
|
||||
do
|
||||
{
|
||||
maj_status = gss_display_status(
|
||||
&min_status,
|
||||
status_code,
|
||||
types[i],
|
||||
GSS_C_NO_OID,
|
||||
&message_context,
|
||||
&status_string);
|
||||
|
||||
if(maj_status)
|
||||
break;
|
||||
|
||||
if(p + status_string.length + 2 < end)
|
||||
{
|
||||
memcpy(p,status_string.value, status_string.length);
|
||||
p += status_string.length;
|
||||
*p++ = '.';
|
||||
*p++ = ' ';
|
||||
}
|
||||
|
||||
gss_release_buffer(&min_status, &status_string);
|
||||
}
|
||||
while (message_context != 0);
|
||||
}
|
||||
*p= 0;
|
||||
}
|
29
vendor/MDBC/plugins/auth/gssapi_errmsg.h
vendored
Normal file
29
vendor/MDBC/plugins/auth/gssapi_errmsg.h
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
/* Copyright (c) 2015, Shuang Qiu, Robbie Harwood,
|
||||
Vladislav Vaintroub & MariaDB Corporation
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
extern void gssapi_errmsg(OM_uint32 major, OM_uint32 minor, char *buf, size_t size);
|
76
vendor/MDBC/plugins/auth/mariadb_cleartext.c
vendored
Normal file
76
vendor/MDBC/plugins/auth/mariadb_cleartext.c
vendored
Normal file
@ -0,0 +1,76 @@
|
||||
/************************************************************************************
|
||||
Copyright (C) 2014-2018 MariaDB Corporation AB
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not see <http://www.gnu.org/licenses>
|
||||
or write to the Free Software Foundation, Inc.,
|
||||
51 Franklin St., Fifth Floor, Boston, MA 02110, USA
|
||||
*************************************************************************************/
|
||||
#include <ma_global.h>
|
||||
#include <mysql.h>
|
||||
#include <mysql/client_plugin.h>
|
||||
#include <string.h>
|
||||
|
||||
/* clear text plugin submits the password without opening a dialog.
|
||||
This will be the case if pam-use-cleartext-plugin option is
|
||||
enabled on server side */
|
||||
|
||||
/* {{{ auth_send_plain_password() */
|
||||
/*
|
||||
sends an unencrypted password to server
|
||||
|
||||
SYNOPSIS
|
||||
auth_send_plain_password()
|
||||
vio pointer to vio structure
|
||||
mysql connection handle
|
||||
|
||||
DESCRIPTION
|
||||
sends an unencrypted password (which was specified either in
|
||||
mysql_real_connect or mysql_change_user) to server.
|
||||
|
||||
RETURN
|
||||
CR_OK
|
||||
CR_ERROR if an error occurred
|
||||
*/
|
||||
static int clear_password_auth_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql)
|
||||
{
|
||||
if (!vio || !mysql || !mysql->passwd)
|
||||
return CR_ERROR;
|
||||
|
||||
/* write password including terminating zero character */
|
||||
return vio->write_packet(vio, (const unsigned char *) mysql->passwd, (int)strlen(mysql->passwd) + 1) ?
|
||||
CR_ERROR : CR_OK;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
#ifndef PLUGIN_DYNAMIC
|
||||
struct st_mysql_client_plugin_AUTHENTICATION mysql_clear_password_client_plugin=
|
||||
#else
|
||||
struct st_mysql_client_plugin_AUTHENTICATION _mysql_client_plugin_declaration_ =
|
||||
#endif
|
||||
{
|
||||
MYSQL_CLIENT_AUTHENTICATION_PLUGIN,
|
||||
MYSQL_CLIENT_AUTHENTICATION_PLUGIN_INTERFACE_VERSION,
|
||||
"mysql_clear_password",
|
||||
"Georg Richter",
|
||||
"MariaDB clear password authentication plugin",
|
||||
{0,1,0},
|
||||
"LGPL",
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
clear_password_auth_client
|
||||
};
|
||||
|
||||
|
685
vendor/MDBC/plugins/auth/my_auth.c
vendored
Normal file
685
vendor/MDBC/plugins/auth/my_auth.c
vendored
Normal file
@ -0,0 +1,685 @@
|
||||
#include <ma_global.h>
|
||||
#include <ma_sys.h>
|
||||
#include <errmsg.h>
|
||||
#include <string.h>
|
||||
#include <ma_common.h>
|
||||
#include <mysql/client_plugin.h>
|
||||
|
||||
typedef struct st_mysql_client_plugin_AUTHENTICATION auth_plugin_t;
|
||||
static int client_mpvio_write_packet(struct st_plugin_vio*, const uchar*, size_t);
|
||||
static int native_password_auth_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql);
|
||||
static int dummy_fallback_auth_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql __attribute__((unused)));
|
||||
extern void read_user_name(char *name);
|
||||
extern char *ma_send_connect_attr(MYSQL *mysql, unsigned char *buffer);
|
||||
extern int ma_read_ok_packet(MYSQL *mysql, uchar *pos, ulong length);
|
||||
extern unsigned char *mysql_net_store_length(unsigned char *packet, size_t length);
|
||||
|
||||
typedef struct {
|
||||
int (*read_packet)(struct st_plugin_vio *vio, uchar **buf);
|
||||
int (*write_packet)(struct st_plugin_vio *vio, const uchar *pkt, size_t pkt_len);
|
||||
void (*info)(struct st_plugin_vio *vio, struct st_plugin_vio_info *info);
|
||||
/* -= end of MYSQL_PLUGIN_VIO =- */
|
||||
MYSQL *mysql;
|
||||
auth_plugin_t *plugin; /**< what plugin we're under */
|
||||
const char *db;
|
||||
struct {
|
||||
uchar *pkt; /**< pointer into NET::buff */
|
||||
uint pkt_len;
|
||||
} cached_server_reply;
|
||||
uint packets_read, packets_written; /**< counters for send/received packets */
|
||||
my_bool mysql_change_user; /**< if it's mysql_change_user() */
|
||||
int last_read_packet_len; /**< the length of the last *read* packet */
|
||||
} MCPVIO_EXT;
|
||||
/*
|
||||
#define compile_time_assert(A) \
|
||||
do {\
|
||||
typedef char constraint[(A) ? 1 : -1];\
|
||||
} while (0);
|
||||
*/
|
||||
|
||||
auth_plugin_t mysql_native_password_client_plugin=
|
||||
{
|
||||
MYSQL_CLIENT_AUTHENTICATION_PLUGIN,
|
||||
MYSQL_CLIENT_AUTHENTICATION_PLUGIN_INTERFACE_VERSION,
|
||||
native_password_plugin_name,
|
||||
"R.J.Silk, Sergei Golubchik",
|
||||
"Native MySQL authentication",
|
||||
{1, 0, 0},
|
||||
"LGPL",
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
native_password_auth_client
|
||||
};
|
||||
|
||||
|
||||
static int native_password_auth_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql)
|
||||
{
|
||||
int pkt_len;
|
||||
uchar *pkt;
|
||||
|
||||
if (((MCPVIO_EXT *)vio)->mysql_change_user)
|
||||
{
|
||||
/*
|
||||
in mysql_change_user() the client sends the first packet.
|
||||
we use the old scramble.
|
||||
*/
|
||||
pkt= (uchar*)mysql->scramble_buff;
|
||||
pkt_len= SCRAMBLE_LENGTH + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* read the scramble */
|
||||
if ((pkt_len= vio->read_packet(vio, &pkt)) < 0)
|
||||
return CR_ERROR;
|
||||
|
||||
if (pkt_len != SCRAMBLE_LENGTH + 1)
|
||||
return CR_SERVER_HANDSHAKE_ERR;
|
||||
|
||||
/* save it in MYSQL */
|
||||
memmove(mysql->scramble_buff, pkt, SCRAMBLE_LENGTH);
|
||||
mysql->scramble_buff[SCRAMBLE_LENGTH] = 0;
|
||||
}
|
||||
|
||||
if (mysql && mysql->passwd[0])
|
||||
{
|
||||
char scrambled[SCRAMBLE_LENGTH + 1];
|
||||
ma_scramble_41((uchar *)scrambled, (char*)pkt, mysql->passwd);
|
||||
if (vio->write_packet(vio, (uchar*)scrambled, SCRAMBLE_LENGTH))
|
||||
return CR_ERROR;
|
||||
}
|
||||
else
|
||||
if (vio->write_packet(vio, 0, 0)) /* no password */
|
||||
return CR_ERROR;
|
||||
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
auth_plugin_t dummy_fallback_client_plugin=
|
||||
{
|
||||
MYSQL_CLIENT_AUTHENTICATION_PLUGIN,
|
||||
MYSQL_CLIENT_AUTHENTICATION_PLUGIN_INTERFACE_VERSION,
|
||||
"dummy_fallback_auth",
|
||||
"Sergei Golubchik",
|
||||
"Dummy fallback plugin",
|
||||
{1, 0, 0},
|
||||
"LGPL",
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
dummy_fallback_auth_client
|
||||
};
|
||||
|
||||
|
||||
static int dummy_fallback_auth_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql __attribute__((unused)))
|
||||
{
|
||||
char last_error[MYSQL_ERRMSG_SIZE];
|
||||
unsigned int i, last_errno= ((MCPVIO_EXT *)vio)->mysql->net.last_errno;
|
||||
if (last_errno)
|
||||
{
|
||||
strncpy(last_error, ((MCPVIO_EXT *)vio)->mysql->net.last_error,
|
||||
sizeof(last_error) - 1);
|
||||
last_error[sizeof(last_error) - 1]= 0;
|
||||
}
|
||||
|
||||
/* safety-wise we only do 10 round-trips */
|
||||
for (i=0; i < 10; i++)
|
||||
{
|
||||
uchar *pkt;
|
||||
if (vio->read_packet(vio, &pkt) < 0)
|
||||
break;
|
||||
if (vio->write_packet(vio, 0, 0))
|
||||
break;
|
||||
}
|
||||
if (last_errno)
|
||||
{
|
||||
MYSQL *mysql= ((MCPVIO_EXT *)vio)->mysql;
|
||||
strncpy(mysql->net.last_error, last_error,
|
||||
sizeof(mysql->net.last_error) - 1);
|
||||
mysql->net.last_error[sizeof(mysql->net.last_error) - 1]= 0;
|
||||
}
|
||||
return CR_ERROR;
|
||||
}
|
||||
|
||||
static int send_change_user_packet(MCPVIO_EXT *mpvio,
|
||||
const uchar *data, int data_len)
|
||||
{
|
||||
MYSQL *mysql= mpvio->mysql;
|
||||
char *buff, *end;
|
||||
int res= 1;
|
||||
size_t conn_attr_len= (mysql->options.extension) ?
|
||||
mysql->options.extension->connect_attrs_len : 0;
|
||||
|
||||
buff= malloc(USERNAME_LENGTH+1 + data_len+1 + NAME_LEN+1 + 2 + NAME_LEN+1 + 9 + conn_attr_len);
|
||||
|
||||
end= ma_strmake(buff, mysql->user, USERNAME_LENGTH) + 1;
|
||||
|
||||
if (!data_len)
|
||||
*end++= 0;
|
||||
else
|
||||
{
|
||||
if (mysql->client_flag & CLIENT_SECURE_CONNECTION)
|
||||
{
|
||||
DBUG_ASSERT(data_len <= 255);
|
||||
if (data_len > 255)
|
||||
{
|
||||
my_set_error(mysql, CR_MALFORMED_PACKET, SQLSTATE_UNKNOWN, 0);
|
||||
goto error;
|
||||
}
|
||||
*end++= data_len;
|
||||
}
|
||||
else
|
||||
{
|
||||
DBUG_ASSERT(data_len == SCRAMBLE_LENGTH_323 + 1);
|
||||
DBUG_ASSERT(data[SCRAMBLE_LENGTH_323] == 0);
|
||||
}
|
||||
memcpy(end, data, data_len);
|
||||
end+= data_len;
|
||||
}
|
||||
end= ma_strmake(end, mpvio->db ? mpvio->db : "", NAME_LEN) + 1;
|
||||
|
||||
if (mysql->server_capabilities & CLIENT_PROTOCOL_41)
|
||||
{
|
||||
int2store(end, (ushort) mysql->charset->nr);
|
||||
end+= 2;
|
||||
}
|
||||
|
||||
if (mysql->server_capabilities & CLIENT_PLUGIN_AUTH)
|
||||
end= ma_strmake(end, mpvio->plugin->name, NAME_LEN) + 1;
|
||||
|
||||
end= ma_send_connect_attr(mysql, (unsigned char *)end);
|
||||
|
||||
res= ma_simple_command(mysql, COM_CHANGE_USER,
|
||||
buff, (ulong)(end-buff), 1, NULL);
|
||||
|
||||
error:
|
||||
free(buff);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int send_client_reply_packet(MCPVIO_EXT *mpvio,
|
||||
const uchar *data, int data_len)
|
||||
{
|
||||
MYSQL *mysql= mpvio->mysql;
|
||||
NET *net= &mysql->net;
|
||||
char *buff, *end;
|
||||
size_t conn_attr_len= (mysql->options.extension) ?
|
||||
mysql->options.extension->connect_attrs_len : 0;
|
||||
|
||||
/* see end= buff+32 below, fixed size of the packet is 32 bytes */
|
||||
buff= malloc(33 + USERNAME_LENGTH + data_len + NAME_LEN + NAME_LEN + conn_attr_len + 9);
|
||||
end= buff;
|
||||
|
||||
mysql->client_flag|= mysql->options.client_flag;
|
||||
mysql->client_flag|= CLIENT_CAPABILITIES;
|
||||
|
||||
if (mysql->client_flag & CLIENT_MULTI_STATEMENTS)
|
||||
mysql->client_flag|= CLIENT_MULTI_RESULTS;
|
||||
|
||||
#if defined(HAVE_TLS) && !defined(EMBEDDED_LIBRARY)
|
||||
if (mysql->options.ssl_key || mysql->options.ssl_cert ||
|
||||
mysql->options.ssl_ca || mysql->options.ssl_capath ||
|
||||
mysql->options.ssl_cipher || mysql->options.use_ssl ||
|
||||
(mysql->options.client_flag & CLIENT_SSL_VERIFY_SERVER_CERT))
|
||||
mysql->options.use_ssl= 1;
|
||||
if (mysql->options.use_ssl)
|
||||
mysql->client_flag|= CLIENT_SSL;
|
||||
#endif /* HAVE_TLS && !EMBEDDED_LIBRARY*/
|
||||
if (mpvio->db)
|
||||
mysql->client_flag|= CLIENT_CONNECT_WITH_DB;
|
||||
else
|
||||
/* See CONC-490: If no database was specified, we need
|
||||
to unset CLIENT_CONNECT_WITH_DB flag */
|
||||
mysql->client_flag&= ~CLIENT_CONNECT_WITH_DB;
|
||||
|
||||
/* if server doesn't support SSL and verification of server certificate
|
||||
was set to mandatory, we need to return an error */
|
||||
if (mysql->options.use_ssl && !(mysql->server_capabilities & CLIENT_SSL))
|
||||
{
|
||||
if ((mysql->client_flag & CLIENT_SSL_VERIFY_SERVER_CERT) ||
|
||||
(mysql->options.extension && (mysql->options.extension->tls_fp ||
|
||||
mysql->options.extension->tls_fp_list)))
|
||||
{
|
||||
my_set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN,
|
||||
ER(CR_SSL_CONNECTION_ERROR),
|
||||
"SSL is required, but the server does not support it");
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Remove options that server doesn't support */
|
||||
mysql->client_flag= mysql->client_flag &
|
||||
(~(CLIENT_COMPRESS | CLIENT_SSL | CLIENT_PROTOCOL_41)
|
||||
| mysql->server_capabilities);
|
||||
|
||||
#ifndef HAVE_COMPRESS
|
||||
mysql->client_flag&= ~CLIENT_COMPRESS;
|
||||
#endif
|
||||
|
||||
if (mysql->client_flag & CLIENT_PROTOCOL_41)
|
||||
{
|
||||
/* 4.1 server and 4.1 client has a 32 byte option flag */
|
||||
if (!(mysql->server_capabilities & CLIENT_MYSQL))
|
||||
mysql->client_flag&= ~CLIENT_MYSQL;
|
||||
int4store(buff,mysql->client_flag);
|
||||
int4store(buff+4, net->max_packet_size);
|
||||
buff[8]= (char) mysql->charset->nr;
|
||||
memset(buff + 9, 0, 32-9);
|
||||
if (!(mysql->server_capabilities & CLIENT_MYSQL))
|
||||
{
|
||||
uint server_extended_cap= mysql->extension->mariadb_server_capabilities;
|
||||
uint client_extended_cap= (uint)(MARIADB_CLIENT_SUPPORTED_FLAGS >> 32);
|
||||
mysql->extension->mariadb_client_flag=
|
||||
server_extended_cap & client_extended_cap;
|
||||
int4store(buff + 28, mysql->extension->mariadb_client_flag);
|
||||
}
|
||||
end= buff+32;
|
||||
}
|
||||
else
|
||||
{
|
||||
int2store(buff, mysql->client_flag);
|
||||
int3store(buff+2, net->max_packet_size);
|
||||
end= buff+5;
|
||||
}
|
||||
#ifdef HAVE_TLS
|
||||
if (mysql->options.ssl_key ||
|
||||
mysql->options.ssl_cert ||
|
||||
mysql->options.ssl_ca ||
|
||||
mysql->options.ssl_capath ||
|
||||
mysql->options.ssl_cipher
|
||||
#ifdef CRL_IMPLEMENTED
|
||||
|| (mysql->options.extension &&
|
||||
(mysql->options.extension->ssl_crl ||
|
||||
mysql->options.extension->ssl_crlpath))
|
||||
#endif
|
||||
)
|
||||
mysql->options.use_ssl= 1;
|
||||
if (mysql->options.use_ssl &&
|
||||
(mysql->client_flag & CLIENT_SSL))
|
||||
{
|
||||
/*
|
||||
Send mysql->client_flag, max_packet_size - unencrypted otherwise
|
||||
the server does not know we want to do SSL
|
||||
*/
|
||||
if (ma_net_write(net, (unsigned char *)buff, (size_t) (end-buff)) || ma_net_flush(net))
|
||||
{
|
||||
my_set_error(mysql, CR_SERVER_LOST, SQLSTATE_UNKNOWN,
|
||||
ER(CR_SERVER_LOST_EXTENDED),
|
||||
"sending connection information to server",
|
||||
errno);
|
||||
goto error;
|
||||
}
|
||||
if (ma_pvio_start_ssl(mysql->net.pvio))
|
||||
goto error;
|
||||
}
|
||||
#endif /* HAVE_TLS */
|
||||
|
||||
/* This needs to be changed as it's not useful with big packets */
|
||||
if (mysql->user && mysql->user[0])
|
||||
ma_strmake(end, mysql->user, USERNAME_LENGTH);
|
||||
else
|
||||
read_user_name(end);
|
||||
|
||||
/* We have to handle different version of handshake here */
|
||||
end+= strlen(end) + 1;
|
||||
if (data_len)
|
||||
{
|
||||
if (mysql->server_capabilities & CLIENT_SECURE_CONNECTION)
|
||||
{
|
||||
if (mysql->server_capabilities & CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA)
|
||||
{
|
||||
end= (char *)mysql_net_store_length((uchar *)end, data_len);
|
||||
}
|
||||
else {
|
||||
/* Without CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA capability password
|
||||
length is limited up to 255 chars */
|
||||
if (data_len > 0xFF)
|
||||
goto error;
|
||||
*end++= data_len;
|
||||
}
|
||||
memcpy(end, data, data_len);
|
||||
end+= data_len;
|
||||
}
|
||||
else
|
||||
{
|
||||
DBUG_ASSERT(data_len == SCRAMBLE_LENGTH_323 + 1); /* incl. \0 at the end */
|
||||
memcpy(end, data, data_len);
|
||||
end+= data_len;
|
||||
}
|
||||
}
|
||||
else
|
||||
*end++= 0;
|
||||
|
||||
/* Add database if needed */
|
||||
if (mpvio->db && (mysql->server_capabilities & CLIENT_CONNECT_WITH_DB))
|
||||
{
|
||||
end= ma_strmake(end, mpvio->db, NAME_LEN) + 1;
|
||||
mysql->db= strdup(mpvio->db);
|
||||
}
|
||||
|
||||
if (mysql->server_capabilities & CLIENT_PLUGIN_AUTH)
|
||||
end= ma_strmake(end, mpvio->plugin->name, NAME_LEN) + 1;
|
||||
|
||||
end= ma_send_connect_attr(mysql, (unsigned char *)end);
|
||||
|
||||
/* Write authentication package */
|
||||
if (ma_net_write(net, (unsigned char *)buff, (size_t) (end-buff)) || ma_net_flush(net))
|
||||
{
|
||||
my_set_error(mysql, CR_SERVER_LOST, SQLSTATE_UNKNOWN,
|
||||
ER(CR_SERVER_LOST_EXTENDED),
|
||||
"sending authentication information",
|
||||
errno);
|
||||
goto error;
|
||||
}
|
||||
free(buff);
|
||||
return 0;
|
||||
|
||||
error:
|
||||
free(buff);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
vio->read_packet() callback method for client authentication plugins
|
||||
|
||||
This function is called by a client authentication plugin, when it wants
|
||||
to read data from the server.
|
||||
*/
|
||||
|
||||
static int client_mpvio_read_packet(struct st_plugin_vio *mpv, uchar **buf)
|
||||
{
|
||||
MCPVIO_EXT *mpvio= (MCPVIO_EXT*)mpv;
|
||||
MYSQL *mysql= mpvio->mysql;
|
||||
ulong pkt_len;
|
||||
|
||||
/* there are cached data left, feed it to a plugin */
|
||||
if (mpvio->cached_server_reply.pkt)
|
||||
{
|
||||
*buf= mpvio->cached_server_reply.pkt;
|
||||
mpvio->cached_server_reply.pkt= 0;
|
||||
mpvio->packets_read++;
|
||||
return mpvio->cached_server_reply.pkt_len;
|
||||
}
|
||||
|
||||
if (mpvio->packets_read == 0)
|
||||
{
|
||||
/*
|
||||
the server handshake packet came from the wrong plugin,
|
||||
or it's mysql_change_user(). Either way, there is no data
|
||||
for a plugin to read. send a dummy packet to the server
|
||||
to initiate a dialog.
|
||||
*/
|
||||
if (client_mpvio_write_packet(mpv, 0, 0))
|
||||
return (int)packet_error;
|
||||
}
|
||||
|
||||
/* otherwise read the data */
|
||||
if ((pkt_len= ma_net_safe_read(mysql)) == packet_error)
|
||||
return (int)packet_error;
|
||||
|
||||
mpvio->last_read_packet_len= pkt_len;
|
||||
*buf= mysql->net.read_pos;
|
||||
|
||||
/* was it a request to change plugins ? */
|
||||
if (pkt_len && **buf == 254)
|
||||
return (int)packet_error; /* if yes, this plugin shan't continue */
|
||||
|
||||
/*
|
||||
the server sends \1\255 or \1\254 instead of just \255 or \254 -
|
||||
for us to not confuse it with an error or "change plugin" packets.
|
||||
We remove this escaping \1 here.
|
||||
|
||||
See also server_mpvio_write_packet() where the escaping is done.
|
||||
*/
|
||||
if (pkt_len && **buf == 1)
|
||||
{
|
||||
(*buf)++;
|
||||
pkt_len--;
|
||||
}
|
||||
mpvio->packets_read++;
|
||||
return pkt_len;
|
||||
}
|
||||
|
||||
/**
|
||||
vio->write_packet() callback method for client authentication plugins
|
||||
|
||||
This function is called by a client authentication plugin, when it wants
|
||||
to send data to the server.
|
||||
|
||||
It transparently wraps the data into a change user or authentication
|
||||
handshake packet, if necessary.
|
||||
*/
|
||||
|
||||
static int client_mpvio_write_packet(struct st_plugin_vio *mpv,
|
||||
const uchar *pkt, size_t pkt_len)
|
||||
{
|
||||
int res;
|
||||
MCPVIO_EXT *mpvio= (MCPVIO_EXT*)mpv;
|
||||
|
||||
if (mpvio->packets_written == 0)
|
||||
{
|
||||
if (mpvio->mysql_change_user)
|
||||
res= send_change_user_packet(mpvio, pkt, (int)pkt_len);
|
||||
else
|
||||
res= send_client_reply_packet(mpvio, pkt, (int)pkt_len);
|
||||
}
|
||||
else
|
||||
{
|
||||
NET *net= &mpvio->mysql->net;
|
||||
if (mpvio->mysql->thd)
|
||||
res= 1; /* no chit-chat in embedded */
|
||||
else
|
||||
res= ma_net_write(net, (unsigned char *)pkt, pkt_len) || ma_net_flush(net);
|
||||
}
|
||||
|
||||
if (res)
|
||||
{
|
||||
/* don't overwrite errors */
|
||||
if (!mysql_errno(mpvio->mysql))
|
||||
my_set_error(mpvio->mysql, CR_SERVER_LOST, SQLSTATE_UNKNOWN,
|
||||
ER(CR_SERVER_LOST_EXTENDED),
|
||||
"sending authentication information",
|
||||
errno);
|
||||
}
|
||||
mpvio->packets_written++;
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
fills MYSQL_PLUGIN_VIO_INFO structure with the information about the
|
||||
connection
|
||||
*/
|
||||
|
||||
void mpvio_info(MARIADB_PVIO *pvio, MYSQL_PLUGIN_VIO_INFO *info)
|
||||
{
|
||||
memset(info, 0, sizeof(*info));
|
||||
switch (pvio->type) {
|
||||
case PVIO_TYPE_SOCKET:
|
||||
info->protocol= MYSQL_VIO_TCP;
|
||||
ma_pvio_get_handle(pvio, &info->socket);
|
||||
return;
|
||||
case PVIO_TYPE_UNIXSOCKET:
|
||||
info->protocol= MYSQL_VIO_SOCKET;
|
||||
ma_pvio_get_handle(pvio, &info->socket);
|
||||
return;
|
||||
/*
|
||||
case VIO_TYPE_SSL:
|
||||
{
|
||||
struct sockaddr addr;
|
||||
SOCKET_SIZE_TYPE addrlen= sizeof(addr);
|
||||
if (getsockname(vio->sd, &addr, &addrlen))
|
||||
return;
|
||||
info->protocol= addr.sa_family == AF_UNIX ?
|
||||
MYSQL_VIO_SOCKET : MYSQL_VIO_TCP;
|
||||
info->socket= vio->sd;
|
||||
return;
|
||||
}
|
||||
*/
|
||||
#ifdef _WIN32
|
||||
/*
|
||||
case VIO_TYPE_NAMEDPIPE:
|
||||
info->protocol= MYSQL_VIO_PIPE;
|
||||
info->handle= vio->hPipe;
|
||||
return;
|
||||
*/
|
||||
/* not supported yet
|
||||
case VIO_TYPE_SHARED_MEMORY:
|
||||
info->protocol= MYSQL_VIO_MEMORY;
|
||||
info->handle= vio->handle_file_map;
|
||||
return;
|
||||
*/
|
||||
#endif
|
||||
default: DBUG_ASSERT(0);
|
||||
}
|
||||
}
|
||||
|
||||
static void client_mpvio_info(MYSQL_PLUGIN_VIO *vio,
|
||||
MYSQL_PLUGIN_VIO_INFO *info)
|
||||
{
|
||||
MCPVIO_EXT *mpvio= (MCPVIO_EXT*)vio;
|
||||
mpvio_info(mpvio->mysql->net.pvio, info);
|
||||
}
|
||||
|
||||
/**
|
||||
Client side of the plugin driver authentication.
|
||||
|
||||
@note this is used by both the mysql_real_connect and mysql_change_user
|
||||
|
||||
@param mysql mysql
|
||||
@param data pointer to the plugin auth data (scramble) in the
|
||||
handshake packet
|
||||
@param data_len the length of the data
|
||||
@param data_plugin a plugin that data were prepared for
|
||||
or 0 if it's mysql_change_user()
|
||||
@param db initial db to use, can be 0
|
||||
|
||||
@retval 0 ok
|
||||
@retval 1 error
|
||||
*/
|
||||
|
||||
int run_plugin_auth(MYSQL *mysql, char *data, uint data_len,
|
||||
const char *data_plugin, const char *db)
|
||||
{
|
||||
const char *auth_plugin_name= NULL;
|
||||
auth_plugin_t *auth_plugin;
|
||||
MCPVIO_EXT mpvio;
|
||||
ulong pkt_length;
|
||||
int res;
|
||||
|
||||
/* determine the default/initial plugin to use */
|
||||
if (mysql->server_capabilities & CLIENT_PLUGIN_AUTH)
|
||||
{
|
||||
if (mysql->options.extension && mysql->options.extension->default_auth)
|
||||
auth_plugin_name= mysql->options.extension->default_auth;
|
||||
else if (data_plugin)
|
||||
auth_plugin_name= data_plugin;
|
||||
}
|
||||
if (!auth_plugin_name)
|
||||
{
|
||||
if (mysql->server_capabilities & CLIENT_PROTOCOL_41)
|
||||
auth_plugin_name= native_password_plugin_name;
|
||||
else
|
||||
auth_plugin_name= "mysql_old_password";
|
||||
}
|
||||
if (!(auth_plugin= (auth_plugin_t*) mysql_client_find_plugin(mysql,
|
||||
auth_plugin_name, MYSQL_CLIENT_AUTHENTICATION_PLUGIN)))
|
||||
auth_plugin= &dummy_fallback_client_plugin;
|
||||
|
||||
mysql->net.last_errno= 0; /* just in case */
|
||||
|
||||
if (data_plugin && strcmp(data_plugin, auth_plugin_name))
|
||||
{
|
||||
/* data was prepared for a different plugin, so we don't
|
||||
send any data */
|
||||
data= 0;
|
||||
data_len= 0;
|
||||
}
|
||||
|
||||
mpvio.mysql_change_user= data_plugin == 0;
|
||||
mpvio.cached_server_reply.pkt= (uchar*)data;
|
||||
mpvio.cached_server_reply.pkt_len= data_len;
|
||||
mpvio.read_packet= client_mpvio_read_packet;
|
||||
mpvio.write_packet= client_mpvio_write_packet;
|
||||
mpvio.info= client_mpvio_info;
|
||||
mpvio.mysql= mysql;
|
||||
mpvio.packets_read= mpvio.packets_written= 0;
|
||||
mpvio.db= db;
|
||||
|
||||
retry:
|
||||
mpvio.plugin= auth_plugin;
|
||||
|
||||
mysql->net.read_pos[0]= 0;
|
||||
res= auth_plugin->authenticate_user((struct st_plugin_vio *)&mpvio, mysql);
|
||||
|
||||
if ((res == CR_ERROR && !mysql->net.buff) ||
|
||||
(res > CR_OK && mysql->net.read_pos[0] != 254))
|
||||
{
|
||||
/*
|
||||
the plugin returned an error. write it down in mysql,
|
||||
unless the error code is CR_ERROR and mysql->net.last_errno
|
||||
is already set (the plugin has done it)
|
||||
*/
|
||||
if (res > CR_ERROR)
|
||||
my_set_error(mysql, res, SQLSTATE_UNKNOWN, 0);
|
||||
else
|
||||
if (!mysql->net.last_errno) {
|
||||
my_set_error(mysql, CR_UNKNOWN_ERROR, SQLSTATE_UNKNOWN, 0);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* read the OK packet (or use the cached value in mysql->net.read_pos */
|
||||
if (res == CR_OK)
|
||||
pkt_length= ma_net_safe_read(mysql);
|
||||
else /* res == CR_OK_HANDSHAKE_COMPLETE or an error */
|
||||
pkt_length= mpvio.last_read_packet_len;
|
||||
|
||||
if (pkt_length == packet_error)
|
||||
{
|
||||
if (mysql->net.last_errno == CR_SERVER_LOST)
|
||||
my_set_error(mysql, CR_SERVER_LOST, SQLSTATE_UNKNOWN,
|
||||
ER(CR_SERVER_LOST_EXTENDED),
|
||||
"reading authorization packet",
|
||||
errno);
|
||||
return 1;
|
||||
}
|
||||
if (mysql->net.read_pos[0] == 254)
|
||||
{
|
||||
/* The server asked to use a different authentication plugin */
|
||||
if (pkt_length == 1)
|
||||
{
|
||||
/* old "use short scramble" packet */
|
||||
auth_plugin_name= old_password_plugin_name;
|
||||
mpvio.cached_server_reply.pkt= (uchar*)mysql->scramble_buff;
|
||||
mpvio.cached_server_reply.pkt_len= SCRAMBLE_LENGTH + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* new "use different plugin" packet */
|
||||
uint len;
|
||||
auth_plugin_name= (char*)mysql->net.read_pos + 1;
|
||||
len= (uint)strlen(auth_plugin_name); /* safe as ma_net_read always appends \0 */
|
||||
mpvio.cached_server_reply.pkt_len= pkt_length - len - 2;
|
||||
mpvio.cached_server_reply.pkt= mysql->net.read_pos + len + 2;
|
||||
}
|
||||
if (!(auth_plugin= (auth_plugin_t *) mysql_client_find_plugin(mysql,
|
||||
auth_plugin_name, MYSQL_CLIENT_AUTHENTICATION_PLUGIN)))
|
||||
auth_plugin= &dummy_fallback_client_plugin;
|
||||
|
||||
goto retry;
|
||||
|
||||
}
|
||||
/*
|
||||
net->read_pos[0] should always be 0 here if the server implements
|
||||
the protocol correctly
|
||||
*/
|
||||
if (mysql->net.read_pos[0] == 0)
|
||||
return ma_read_ok_packet(mysql, mysql->net.read_pos + 1, pkt_length);
|
||||
return 1;
|
||||
}
|
||||
|
117
vendor/MDBC/plugins/auth/old_password.c
vendored
Normal file
117
vendor/MDBC/plugins/auth/old_password.c
vendored
Normal file
@ -0,0 +1,117 @@
|
||||
/************************************************************************************
|
||||
Copyright (C) 2014,2015,2018 MariaDB Corporation AB
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not see <http://www.gnu.org/licenses>
|
||||
or write to the Free Software Foundation, Inc.,
|
||||
51 Franklin St., Fifth Floor, Boston, MA 02110, USA
|
||||
*************************************************************************************/
|
||||
#include <ma_global.h>
|
||||
#include <mysql.h>
|
||||
#include <mysql/client_plugin.h>
|
||||
#include <string.h>
|
||||
#include <memory.h>
|
||||
#include <errmsg.h>
|
||||
|
||||
|
||||
/* function prototypes */
|
||||
static int auth_old_password(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql);
|
||||
|
||||
typedef struct st_mysql_client_plugin_AUTHENTICATION auth_plugin_t;
|
||||
|
||||
typedef struct {
|
||||
int (*read_packet)(struct st_plugin_vio *vio, uchar **buf);
|
||||
int (*write_packet)(struct st_plugin_vio *vio, const uchar *pkt, size_t pkt_len);
|
||||
void (*info)(struct st_plugin_vio *vio, struct st_plugin_vio_info *info);
|
||||
/* -= end of MYSQL_PLUGIN_VIO =- */
|
||||
MYSQL *mysql;
|
||||
auth_plugin_t *plugin; /**< what plugin we're under */
|
||||
const char *db;
|
||||
struct {
|
||||
uchar *pkt; /**< pointer into NET::buff */
|
||||
uint pkt_len;
|
||||
} cached_server_reply;
|
||||
uint packets_read, packets_written; /**< counters for send/received packets */
|
||||
my_bool mysql_change_user; /**< if it's mysql_change_user() */
|
||||
int last_read_packet_len; /**< the length of the last *read* packet */
|
||||
} MCPVIO_EXT;
|
||||
|
||||
#ifndef PLUGIN_DYNAMIC
|
||||
struct st_mysql_client_plugin_AUTHENTICATION mysql_old_password_client_plugin=
|
||||
#else
|
||||
struct st_mysql_client_plugin_AUTHENTICATION _mysql_client_plugin_declaration_ =
|
||||
#endif
|
||||
{
|
||||
MYSQL_CLIENT_AUTHENTICATION_PLUGIN,
|
||||
MYSQL_CLIENT_AUTHENTICATION_PLUGIN_INTERFACE_VERSION,
|
||||
"mysql_old_password",
|
||||
"Sergei Golubchik, R.J. Silk, Georg Richter",
|
||||
"Old (pre 4.1) authentication plugin",
|
||||
{1,0,0},
|
||||
"LGPL",
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
auth_old_password
|
||||
};
|
||||
|
||||
/**
|
||||
client authentication plugin that does old MySQL authentication
|
||||
using an 8-byte (4.0-) scramble
|
||||
*/
|
||||
|
||||
static int auth_old_password(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql)
|
||||
{
|
||||
uchar *pkt;
|
||||
int pkt_len;
|
||||
|
||||
if (((MCPVIO_EXT *)vio)->mysql_change_user)
|
||||
{
|
||||
/*
|
||||
in mysql_change_user() the client sends the first packet.
|
||||
we use the old scramble.
|
||||
*/
|
||||
pkt= (uchar*)mysql->scramble_buff;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* read the scramble */
|
||||
if ((pkt_len= vio->read_packet(vio, &pkt)) < 0)
|
||||
return CR_ERROR;
|
||||
|
||||
if (pkt_len != SCRAMBLE_LENGTH_323 + 1 &&
|
||||
pkt_len != SCRAMBLE_LENGTH + 1)
|
||||
return CR_SERVER_HANDSHAKE_ERR;
|
||||
|
||||
/* save it in MYSQL */
|
||||
memmove(mysql->scramble_buff, pkt, pkt_len - 1);
|
||||
mysql->scramble_buff[pkt_len - 1] = 0;
|
||||
}
|
||||
|
||||
if (mysql && mysql->passwd[0])
|
||||
{
|
||||
char scrambled[SCRAMBLE_LENGTH_323 + 1];
|
||||
ma_scramble_323(scrambled, (char*)pkt, mysql->passwd);
|
||||
if (vio->write_packet(vio, (uchar*)scrambled, SCRAMBLE_LENGTH_323 + 1))
|
||||
return CR_ERROR;
|
||||
}
|
||||
else
|
||||
if (vio->write_packet(vio, 0, 0)) /* no password */
|
||||
return CR_ERROR;
|
||||
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
|
||||
|
3
vendor/MDBC/plugins/auth/ref10/api.h
vendored
Normal file
3
vendor/MDBC/plugins/auth/ref10/api.h
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
#define CRYPTO_PUBLICKEYBYTES 32
|
||||
#define CRYPTO_BYTES 64
|
||||
#define CRYPTO_DETERMINISTIC 1
|
1344
vendor/MDBC/plugins/auth/ref10/base.h
vendored
Normal file
1344
vendor/MDBC/plugins/auth/ref10/base.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
40
vendor/MDBC/plugins/auth/ref10/base2.h
vendored
Normal file
40
vendor/MDBC/plugins/auth/ref10/base2.h
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
{
|
||||
{ 25967493,-14356035,29566456,3660896,-12694345,4014787,27544626,-11754271,-6079156,2047605 },
|
||||
{ -12545711,934262,-2722910,3049990,-727428,9406986,12720692,5043384,19500929,-15469378 },
|
||||
{ -8738181,4489570,9688441,-14785194,10184609,-12363380,29287919,11864899,-24514362,-4438546 },
|
||||
},
|
||||
{
|
||||
{ 15636291,-9688557,24204773,-7912398,616977,-16685262,27787600,-14772189,28944400,-1550024 },
|
||||
{ 16568933,4717097,-11556148,-1102322,15682896,-11807043,16354577,-11775962,7689662,11199574 },
|
||||
{ 30464156,-5976125,-11779434,-15670865,23220365,15915852,7512774,10017326,-17749093,-9920357 },
|
||||
},
|
||||
{
|
||||
{ 10861363,11473154,27284546,1981175,-30064349,12577861,32867885,14515107,-15438304,10819380 },
|
||||
{ 4708026,6336745,20377586,9066809,-11272109,6594696,-25653668,12483688,-12668491,5581306 },
|
||||
{ 19563160,16186464,-29386857,4097519,10237984,-4348115,28542350,13850243,-23678021,-15815942 },
|
||||
},
|
||||
{
|
||||
{ 5153746,9909285,1723747,-2777874,30523605,5516873,19480852,5230134,-23952439,-15175766 },
|
||||
{ -30269007,-3463509,7665486,10083793,28475525,1649722,20654025,16520125,30598449,7715701 },
|
||||
{ 28881845,14381568,9657904,3680757,-20181635,7843316,-31400660,1370708,29794553,-1409300 },
|
||||
},
|
||||
{
|
||||
{ -22518993,-6692182,14201702,-8745502,-23510406,8844726,18474211,-1361450,-13062696,13821877 },
|
||||
{ -6455177,-7839871,3374702,-4740862,-27098617,-10571707,31655028,-7212327,18853322,-14220951 },
|
||||
{ 4566830,-12963868,-28974889,-12240689,-7602672,-2830569,-8514358,-10431137,2207753,-3209784 },
|
||||
},
|
||||
{
|
||||
{ -25154831,-4185821,29681144,7868801,-6854661,-9423865,-12437364,-663000,-31111463,-16132436 },
|
||||
{ 25576264,-2703214,7349804,-11814844,16472782,9300885,3844789,15725684,171356,6466918 },
|
||||
{ 23103977,13316479,9739013,-16149481,817875,-15038942,8965339,-14088058,-30714912,16193877 },
|
||||
},
|
||||
{
|
||||
{ -33521811,3180713,-2394130,14003687,-16903474,-16270840,17238398,4729455,-18074513,9256800 },
|
||||
{ -25182317,-4174131,32336398,5036987,-21236817,11360617,22616405,9761698,-19827198,630305 },
|
||||
{ -13720693,2639453,-24237460,-7406481,9494427,-5774029,-6554551,-15960994,-2449256,-14291300 },
|
||||
},
|
||||
{
|
||||
{ -3151181,-5046075,9282714,6866145,-31907062,-863023,-18940575,15033784,25105118,-7894876 },
|
||||
{ -24326370,15950226,-31801215,-14592823,-11662737,-5090925,1573892,-2625887,2198790,-15804619 },
|
||||
{ -3099351,10324967,-2241613,7453183,-5446979,-2735503,-13812022,-16236442,-32461234,-12290683 },
|
||||
},
|
23
vendor/MDBC/plugins/auth/ref10/common.h
vendored
Normal file
23
vendor/MDBC/plugins/auth/ref10/common.h
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
Copyright (c) 2017, MariaDB
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; version 2 of the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */
|
||||
|
||||
#include <mysql.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "ref10/api.h"
|
||||
#include "crypto_sign.h"
|
||||
|
||||
#define NONCE_BYTES 32
|
7
vendor/MDBC/plugins/auth/ref10/crypto_hash_sha512.h
vendored
Normal file
7
vendor/MDBC/plugins/auth/ref10/crypto_hash_sha512.h
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
#if defined(MYSQL_CLIENT) || defined(LIBMARIADB)
|
||||
#include <ma_crypt.h>
|
||||
#define crypto_hash_sha512(DST,SRC,SLEN) ma_hash(MA_HASH_SHA512, SRC, SLEN, DST)
|
||||
#else
|
||||
#include <mysql/service_sha2.h>
|
||||
#define crypto_hash_sha512(DST,SRC,SLEN) my_sha512(DST,(char*)(SRC),SLEN)
|
||||
#endif
|
5
vendor/MDBC/plugins/auth/ref10/crypto_int32.h
vendored
Normal file
5
vendor/MDBC/plugins/auth/ref10/crypto_int32.h
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
typedef int32_t crypto_int32;
|
||||
|
||||
#define select ed25519_select
|
5
vendor/MDBC/plugins/auth/ref10/crypto_int64.h
vendored
Normal file
5
vendor/MDBC/plugins/auth/ref10/crypto_int64.h
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
typedef int64_t crypto_int64;
|
||||
|
||||
#define select ed25519_select
|
13
vendor/MDBC/plugins/auth/ref10/crypto_sign.h
vendored
Normal file
13
vendor/MDBC/plugins/auth/ref10/crypto_sign.h
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
int crypto_sign_keypair(
|
||||
unsigned char *pk,
|
||||
unsigned char *pw, unsigned long long pwlen
|
||||
);
|
||||
int ma_crypto_sign(
|
||||
unsigned char *sm,
|
||||
const unsigned char *m, unsigned long long mlen,
|
||||
const unsigned char *pw, unsigned long long pwlen
|
||||
);
|
||||
int crypto_sign_open(
|
||||
unsigned char *sm, unsigned long long smlen,
|
||||
const unsigned char *pk
|
||||
);
|
5
vendor/MDBC/plugins/auth/ref10/crypto_uint32.h
vendored
Normal file
5
vendor/MDBC/plugins/auth/ref10/crypto_uint32.h
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
typedef uint32_t crypto_uint32;
|
||||
|
||||
#define select ed25519_select
|
5
vendor/MDBC/plugins/auth/ref10/crypto_uint64.h
vendored
Normal file
5
vendor/MDBC/plugins/auth/ref10/crypto_uint64.h
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
typedef uint64_t crypto_uint64;
|
||||
|
||||
#define select ed25519_select
|
1
vendor/MDBC/plugins/auth/ref10/crypto_verify.h
vendored
Normal file
1
vendor/MDBC/plugins/auth/ref10/crypto_verify.h
vendored
Normal file
@ -0,0 +1 @@
|
||||
int crypto_verify(const unsigned char *x,const unsigned char *y);
|
2
vendor/MDBC/plugins/auth/ref10/crypto_verify_32.h
vendored
Normal file
2
vendor/MDBC/plugins/auth/ref10/crypto_verify_32.h
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
#define crypto_verify_32 crypto_verify
|
||||
int crypto_verify(const unsigned char *x,const unsigned char *y);
|
1
vendor/MDBC/plugins/auth/ref10/d.h
vendored
Normal file
1
vendor/MDBC/plugins/auth/ref10/d.h
vendored
Normal file
@ -0,0 +1 @@
|
||||
-10913610,13857413,-15372611,6949391,114729,-8787816,-6275908,-3247719,-18696448,-12055116
|
1
vendor/MDBC/plugins/auth/ref10/d2.h
vendored
Normal file
1
vendor/MDBC/plugins/auth/ref10/d2.h
vendored
Normal file
@ -0,0 +1 @@
|
||||
-21827239,-5839606,-30745221,13898782,229458,15978800,-12551817,-6495438,29715968,9444199
|
56
vendor/MDBC/plugins/auth/ref10/fe.h
vendored
Normal file
56
vendor/MDBC/plugins/auth/ref10/fe.h
vendored
Normal file
@ -0,0 +1,56 @@
|
||||
#ifndef FE_H
|
||||
#define FE_H
|
||||
|
||||
#include "crypto_int32.h"
|
||||
|
||||
typedef crypto_int32 fe[10];
|
||||
|
||||
/*
|
||||
fe means field element.
|
||||
Here the field is \Z/(2^255-19).
|
||||
An element t, entries t[0]...t[9], represents the integer
|
||||
t[0]+2^26 t[1]+2^51 t[2]+2^77 t[3]+2^102 t[4]+...+2^230 t[9].
|
||||
Bounds on each t[i] vary depending on context.
|
||||
*/
|
||||
|
||||
#define fe_frombytes crypto_sign_ed25519_ref10_fe_frombytes
|
||||
#define fe_tobytes crypto_sign_ed25519_ref10_fe_tobytes
|
||||
#define fe_copy crypto_sign_ed25519_ref10_fe_copy
|
||||
#define fe_isnonzero crypto_sign_ed25519_ref10_fe_isnonzero
|
||||
#define fe_isnegative crypto_sign_ed25519_ref10_fe_isnegative
|
||||
#define fe_0 crypto_sign_ed25519_ref10_fe_0
|
||||
#define fe_1 crypto_sign_ed25519_ref10_fe_1
|
||||
#define fe_cswap crypto_sign_ed25519_ref10_fe_cswap
|
||||
#define fe_cmov crypto_sign_ed25519_ref10_fe_cmov
|
||||
#define fe_add crypto_sign_ed25519_ref10_fe_add
|
||||
#define fe_sub crypto_sign_ed25519_ref10_fe_sub
|
||||
#define fe_neg crypto_sign_ed25519_ref10_fe_neg
|
||||
#define fe_mul crypto_sign_ed25519_ref10_fe_mul
|
||||
#define fe_sq crypto_sign_ed25519_ref10_fe_sq
|
||||
#define fe_sq2 crypto_sign_ed25519_ref10_fe_sq2
|
||||
#define fe_mul121666 crypto_sign_ed25519_ref10_fe_mul121666
|
||||
#define fe_invert crypto_sign_ed25519_ref10_fe_invert
|
||||
#define fe_pow22523 crypto_sign_ed25519_ref10_fe_pow22523
|
||||
|
||||
extern void fe_frombytes(fe,const unsigned char *);
|
||||
extern void fe_tobytes(unsigned char *,const fe);
|
||||
|
||||
extern void fe_copy(fe,const fe);
|
||||
extern int fe_isnonzero(const fe);
|
||||
extern int fe_isnegative(const fe);
|
||||
extern void fe_0(fe);
|
||||
extern void fe_1(fe);
|
||||
extern void fe_cswap(fe,fe,unsigned int);
|
||||
extern void fe_cmov(fe,const fe,unsigned int);
|
||||
|
||||
extern void fe_add(fe,const fe,const fe);
|
||||
extern void fe_sub(fe,const fe,const fe);
|
||||
extern void fe_neg(fe,const fe);
|
||||
extern void fe_mul(fe,const fe,const fe);
|
||||
extern void fe_sq(fe,const fe);
|
||||
extern void fe_sq2(fe,const fe);
|
||||
extern void fe_mul121666(fe,const fe);
|
||||
extern void fe_invert(fe,const fe);
|
||||
extern void fe_pow22523(fe,const fe);
|
||||
|
||||
#endif
|
19
vendor/MDBC/plugins/auth/ref10/fe_0.c
vendored
Normal file
19
vendor/MDBC/plugins/auth/ref10/fe_0.c
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
#include "fe.h"
|
||||
|
||||
/*
|
||||
h = 0
|
||||
*/
|
||||
|
||||
void fe_0(fe h)
|
||||
{
|
||||
h[0] = 0;
|
||||
h[1] = 0;
|
||||
h[2] = 0;
|
||||
h[3] = 0;
|
||||
h[4] = 0;
|
||||
h[5] = 0;
|
||||
h[6] = 0;
|
||||
h[7] = 0;
|
||||
h[8] = 0;
|
||||
h[9] = 0;
|
||||
}
|
19
vendor/MDBC/plugins/auth/ref10/fe_1.c
vendored
Normal file
19
vendor/MDBC/plugins/auth/ref10/fe_1.c
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
#include "fe.h"
|
||||
|
||||
/*
|
||||
h = 1
|
||||
*/
|
||||
|
||||
void fe_1(fe h)
|
||||
{
|
||||
h[0] = 1;
|
||||
h[1] = 0;
|
||||
h[2] = 0;
|
||||
h[3] = 0;
|
||||
h[4] = 0;
|
||||
h[5] = 0;
|
||||
h[6] = 0;
|
||||
h[7] = 0;
|
||||
h[8] = 0;
|
||||
h[9] = 0;
|
||||
}
|
57
vendor/MDBC/plugins/auth/ref10/fe_add.c
vendored
Normal file
57
vendor/MDBC/plugins/auth/ref10/fe_add.c
vendored
Normal file
@ -0,0 +1,57 @@
|
||||
#include "fe.h"
|
||||
|
||||
/*
|
||||
h = f + g
|
||||
Can overlap h with f or g.
|
||||
|
||||
Preconditions:
|
||||
|f| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
|
||||
|g| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
|
||||
|
||||
Postconditions:
|
||||
|h| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
|
||||
*/
|
||||
|
||||
void fe_add(fe h,const fe f,const fe g)
|
||||
{
|
||||
crypto_int32 f0 = f[0];
|
||||
crypto_int32 f1 = f[1];
|
||||
crypto_int32 f2 = f[2];
|
||||
crypto_int32 f3 = f[3];
|
||||
crypto_int32 f4 = f[4];
|
||||
crypto_int32 f5 = f[5];
|
||||
crypto_int32 f6 = f[6];
|
||||
crypto_int32 f7 = f[7];
|
||||
crypto_int32 f8 = f[8];
|
||||
crypto_int32 f9 = f[9];
|
||||
crypto_int32 g0 = g[0];
|
||||
crypto_int32 g1 = g[1];
|
||||
crypto_int32 g2 = g[2];
|
||||
crypto_int32 g3 = g[3];
|
||||
crypto_int32 g4 = g[4];
|
||||
crypto_int32 g5 = g[5];
|
||||
crypto_int32 g6 = g[6];
|
||||
crypto_int32 g7 = g[7];
|
||||
crypto_int32 g8 = g[8];
|
||||
crypto_int32 g9 = g[9];
|
||||
crypto_int32 h0 = f0 + g0;
|
||||
crypto_int32 h1 = f1 + g1;
|
||||
crypto_int32 h2 = f2 + g2;
|
||||
crypto_int32 h3 = f3 + g3;
|
||||
crypto_int32 h4 = f4 + g4;
|
||||
crypto_int32 h5 = f5 + g5;
|
||||
crypto_int32 h6 = f6 + g6;
|
||||
crypto_int32 h7 = f7 + g7;
|
||||
crypto_int32 h8 = f8 + g8;
|
||||
crypto_int32 h9 = f9 + g9;
|
||||
h[0] = h0;
|
||||
h[1] = h1;
|
||||
h[2] = h2;
|
||||
h[3] = h3;
|
||||
h[4] = h4;
|
||||
h[5] = h5;
|
||||
h[6] = h6;
|
||||
h[7] = h7;
|
||||
h[8] = h8;
|
||||
h[9] = h9;
|
||||
}
|
63
vendor/MDBC/plugins/auth/ref10/fe_cmov.c
vendored
Normal file
63
vendor/MDBC/plugins/auth/ref10/fe_cmov.c
vendored
Normal file
@ -0,0 +1,63 @@
|
||||
#include "fe.h"
|
||||
|
||||
/*
|
||||
Replace (f,g) with (g,g) if b == 1;
|
||||
replace (f,g) with (f,g) if b == 0.
|
||||
|
||||
Preconditions: b in {0,1}.
|
||||
*/
|
||||
|
||||
void fe_cmov(fe f,const fe g,unsigned int b)
|
||||
{
|
||||
crypto_int32 f0 = f[0];
|
||||
crypto_int32 f1 = f[1];
|
||||
crypto_int32 f2 = f[2];
|
||||
crypto_int32 f3 = f[3];
|
||||
crypto_int32 f4 = f[4];
|
||||
crypto_int32 f5 = f[5];
|
||||
crypto_int32 f6 = f[6];
|
||||
crypto_int32 f7 = f[7];
|
||||
crypto_int32 f8 = f[8];
|
||||
crypto_int32 f9 = f[9];
|
||||
crypto_int32 g0 = g[0];
|
||||
crypto_int32 g1 = g[1];
|
||||
crypto_int32 g2 = g[2];
|
||||
crypto_int32 g3 = g[3];
|
||||
crypto_int32 g4 = g[4];
|
||||
crypto_int32 g5 = g[5];
|
||||
crypto_int32 g6 = g[6];
|
||||
crypto_int32 g7 = g[7];
|
||||
crypto_int32 g8 = g[8];
|
||||
crypto_int32 g9 = g[9];
|
||||
crypto_int32 x0 = f0 ^ g0;
|
||||
crypto_int32 x1 = f1 ^ g1;
|
||||
crypto_int32 x2 = f2 ^ g2;
|
||||
crypto_int32 x3 = f3 ^ g3;
|
||||
crypto_int32 x4 = f4 ^ g4;
|
||||
crypto_int32 x5 = f5 ^ g5;
|
||||
crypto_int32 x6 = f6 ^ g6;
|
||||
crypto_int32 x7 = f7 ^ g7;
|
||||
crypto_int32 x8 = f8 ^ g8;
|
||||
crypto_int32 x9 = f9 ^ g9;
|
||||
b = -b;
|
||||
x0 &= b;
|
||||
x1 &= b;
|
||||
x2 &= b;
|
||||
x3 &= b;
|
||||
x4 &= b;
|
||||
x5 &= b;
|
||||
x6 &= b;
|
||||
x7 &= b;
|
||||
x8 &= b;
|
||||
x9 &= b;
|
||||
f[0] = f0 ^ x0;
|
||||
f[1] = f1 ^ x1;
|
||||
f[2] = f2 ^ x2;
|
||||
f[3] = f3 ^ x3;
|
||||
f[4] = f4 ^ x4;
|
||||
f[5] = f5 ^ x5;
|
||||
f[6] = f6 ^ x6;
|
||||
f[7] = f7 ^ x7;
|
||||
f[8] = f8 ^ x8;
|
||||
f[9] = f9 ^ x9;
|
||||
}
|
29
vendor/MDBC/plugins/auth/ref10/fe_copy.c
vendored
Normal file
29
vendor/MDBC/plugins/auth/ref10/fe_copy.c
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
#include "fe.h"
|
||||
|
||||
/*
|
||||
h = f
|
||||
*/
|
||||
|
||||
void fe_copy(fe h,const fe f)
|
||||
{
|
||||
crypto_int32 f0 = f[0];
|
||||
crypto_int32 f1 = f[1];
|
||||
crypto_int32 f2 = f[2];
|
||||
crypto_int32 f3 = f[3];
|
||||
crypto_int32 f4 = f[4];
|
||||
crypto_int32 f5 = f[5];
|
||||
crypto_int32 f6 = f[6];
|
||||
crypto_int32 f7 = f[7];
|
||||
crypto_int32 f8 = f[8];
|
||||
crypto_int32 f9 = f[9];
|
||||
h[0] = f0;
|
||||
h[1] = f1;
|
||||
h[2] = f2;
|
||||
h[3] = f3;
|
||||
h[4] = f4;
|
||||
h[5] = f5;
|
||||
h[6] = f6;
|
||||
h[7] = f7;
|
||||
h[8] = f8;
|
||||
h[9] = f9;
|
||||
}
|
73
vendor/MDBC/plugins/auth/ref10/fe_frombytes.c
vendored
Normal file
73
vendor/MDBC/plugins/auth/ref10/fe_frombytes.c
vendored
Normal file
@ -0,0 +1,73 @@
|
||||
#include "fe.h"
|
||||
#include "crypto_int64.h"
|
||||
#include "crypto_uint64.h"
|
||||
|
||||
static crypto_uint64 load_3(const unsigned char *in)
|
||||
{
|
||||
crypto_uint64 result;
|
||||
result = (crypto_uint64) in[0];
|
||||
result |= ((crypto_uint64) in[1]) << 8;
|
||||
result |= ((crypto_uint64) in[2]) << 16;
|
||||
return result;
|
||||
}
|
||||
|
||||
static crypto_uint64 load_4(const unsigned char *in)
|
||||
{
|
||||
crypto_uint64 result;
|
||||
result = (crypto_uint64) in[0];
|
||||
result |= ((crypto_uint64) in[1]) << 8;
|
||||
result |= ((crypto_uint64) in[2]) << 16;
|
||||
result |= ((crypto_uint64) in[3]) << 24;
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
Ignores top bit of h.
|
||||
*/
|
||||
|
||||
void fe_frombytes(fe h,const unsigned char *s)
|
||||
{
|
||||
crypto_int64 h0 = load_4(s);
|
||||
crypto_int64 h1 = load_3(s + 4) << 6;
|
||||
crypto_int64 h2 = load_3(s + 7) << 5;
|
||||
crypto_int64 h3 = load_3(s + 10) << 3;
|
||||
crypto_int64 h4 = load_3(s + 13) << 2;
|
||||
crypto_int64 h5 = load_4(s + 16);
|
||||
crypto_int64 h6 = load_3(s + 20) << 7;
|
||||
crypto_int64 h7 = load_3(s + 23) << 5;
|
||||
crypto_int64 h8 = load_3(s + 26) << 4;
|
||||
crypto_int64 h9 = (load_3(s + 29) & 8388607) << 2;
|
||||
crypto_int64 carry0;
|
||||
crypto_int64 carry1;
|
||||
crypto_int64 carry2;
|
||||
crypto_int64 carry3;
|
||||
crypto_int64 carry4;
|
||||
crypto_int64 carry5;
|
||||
crypto_int64 carry6;
|
||||
crypto_int64 carry7;
|
||||
crypto_int64 carry8;
|
||||
crypto_int64 carry9;
|
||||
|
||||
carry9 = (h9 + (crypto_int64) (1<<24)) >> 25; h0 += carry9 * 19; h9 -= carry9 << 25;
|
||||
carry1 = (h1 + (crypto_int64) (1<<24)) >> 25; h2 += carry1; h1 -= carry1 << 25;
|
||||
carry3 = (h3 + (crypto_int64) (1<<24)) >> 25; h4 += carry3; h3 -= carry3 << 25;
|
||||
carry5 = (h5 + (crypto_int64) (1<<24)) >> 25; h6 += carry5; h5 -= carry5 << 25;
|
||||
carry7 = (h7 + (crypto_int64) (1<<24)) >> 25; h8 += carry7; h7 -= carry7 << 25;
|
||||
|
||||
carry0 = (h0 + (crypto_int64) (1<<25)) >> 26; h1 += carry0; h0 -= carry0 << 26;
|
||||
carry2 = (h2 + (crypto_int64) (1<<25)) >> 26; h3 += carry2; h2 -= carry2 << 26;
|
||||
carry4 = (h4 + (crypto_int64) (1<<25)) >> 26; h5 += carry4; h4 -= carry4 << 26;
|
||||
carry6 = (h6 + (crypto_int64) (1<<25)) >> 26; h7 += carry6; h6 -= carry6 << 26;
|
||||
carry8 = (h8 + (crypto_int64) (1<<25)) >> 26; h9 += carry8; h8 -= carry8 << 26;
|
||||
|
||||
h[0] = h0;
|
||||
h[1] = h1;
|
||||
h[2] = h2;
|
||||
h[3] = h3;
|
||||
h[4] = h4;
|
||||
h[5] = h5;
|
||||
h[6] = h6;
|
||||
h[7] = h7;
|
||||
h[8] = h8;
|
||||
h[9] = h9;
|
||||
}
|
14
vendor/MDBC/plugins/auth/ref10/fe_invert.c
vendored
Normal file
14
vendor/MDBC/plugins/auth/ref10/fe_invert.c
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
#include "fe.h"
|
||||
|
||||
void fe_invert(fe out,const fe z)
|
||||
{
|
||||
fe t0;
|
||||
fe t1;
|
||||
fe t2;
|
||||
fe t3;
|
||||
int i;
|
||||
|
||||
#include "pow225521.h"
|
||||
|
||||
return;
|
||||
}
|
16
vendor/MDBC/plugins/auth/ref10/fe_isnegative.c
vendored
Normal file
16
vendor/MDBC/plugins/auth/ref10/fe_isnegative.c
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
#include "fe.h"
|
||||
|
||||
/*
|
||||
return 1 if f is in {1,3,5,...,q-2}
|
||||
return 0 if f is in {0,2,4,...,q-1}
|
||||
|
||||
Preconditions:
|
||||
|f| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
|
||||
*/
|
||||
|
||||
int fe_isnegative(const fe f)
|
||||
{
|
||||
unsigned char s[32];
|
||||
fe_tobytes(s,f);
|
||||
return s[0] & 1;
|
||||
}
|
19
vendor/MDBC/plugins/auth/ref10/fe_isnonzero.c
vendored
Normal file
19
vendor/MDBC/plugins/auth/ref10/fe_isnonzero.c
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
#include "fe.h"
|
||||
#include "crypto_verify_32.h"
|
||||
|
||||
/*
|
||||
return 1 if f == 0
|
||||
return 0 if f != 0
|
||||
|
||||
Preconditions:
|
||||
|f| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
|
||||
*/
|
||||
|
||||
static const unsigned char zero[32];
|
||||
|
||||
int fe_isnonzero(const fe f)
|
||||
{
|
||||
unsigned char s[32];
|
||||
fe_tobytes(s,f);
|
||||
return crypto_verify_32(s,zero);
|
||||
}
|
253
vendor/MDBC/plugins/auth/ref10/fe_mul.c
vendored
Normal file
253
vendor/MDBC/plugins/auth/ref10/fe_mul.c
vendored
Normal file
@ -0,0 +1,253 @@
|
||||
#include "fe.h"
|
||||
#include "crypto_int64.h"
|
||||
|
||||
/*
|
||||
h = f * g
|
||||
Can overlap h with f or g.
|
||||
|
||||
Preconditions:
|
||||
|f| bounded by 1.65*2^26,1.65*2^25,1.65*2^26,1.65*2^25,etc.
|
||||
|g| bounded by 1.65*2^26,1.65*2^25,1.65*2^26,1.65*2^25,etc.
|
||||
|
||||
Postconditions:
|
||||
|h| bounded by 1.01*2^25,1.01*2^24,1.01*2^25,1.01*2^24,etc.
|
||||
*/
|
||||
|
||||
/*
|
||||
Notes on implementation strategy:
|
||||
|
||||
Using schoolbook multiplication.
|
||||
Karatsuba would save a little in some cost models.
|
||||
|
||||
Most multiplications by 2 and 19 are 32-bit precomputations;
|
||||
cheaper than 64-bit postcomputations.
|
||||
|
||||
There is one remaining multiplication by 19 in the carry chain;
|
||||
one *19 precomputation can be merged into this,
|
||||
but the resulting data flow is considerably less clean.
|
||||
|
||||
There are 12 carries below.
|
||||
10 of them are 2-way parallelizable and vectorizable.
|
||||
Can get away with 11 carries, but then data flow is much deeper.
|
||||
|
||||
With tighter constraints on inputs can squeeze carries into int32.
|
||||
*/
|
||||
|
||||
void fe_mul(fe h,const fe f,const fe g)
|
||||
{
|
||||
crypto_int32 f0 = f[0];
|
||||
crypto_int32 f1 = f[1];
|
||||
crypto_int32 f2 = f[2];
|
||||
crypto_int32 f3 = f[3];
|
||||
crypto_int32 f4 = f[4];
|
||||
crypto_int32 f5 = f[5];
|
||||
crypto_int32 f6 = f[6];
|
||||
crypto_int32 f7 = f[7];
|
||||
crypto_int32 f8 = f[8];
|
||||
crypto_int32 f9 = f[9];
|
||||
crypto_int32 g0 = g[0];
|
||||
crypto_int32 g1 = g[1];
|
||||
crypto_int32 g2 = g[2];
|
||||
crypto_int32 g3 = g[3];
|
||||
crypto_int32 g4 = g[4];
|
||||
crypto_int32 g5 = g[5];
|
||||
crypto_int32 g6 = g[6];
|
||||
crypto_int32 g7 = g[7];
|
||||
crypto_int32 g8 = g[8];
|
||||
crypto_int32 g9 = g[9];
|
||||
crypto_int32 g1_19 = 19 * g1; /* 1.959375*2^29 */
|
||||
crypto_int32 g2_19 = 19 * g2; /* 1.959375*2^30; still ok */
|
||||
crypto_int32 g3_19 = 19 * g3;
|
||||
crypto_int32 g4_19 = 19 * g4;
|
||||
crypto_int32 g5_19 = 19 * g5;
|
||||
crypto_int32 g6_19 = 19 * g6;
|
||||
crypto_int32 g7_19 = 19 * g7;
|
||||
crypto_int32 g8_19 = 19 * g8;
|
||||
crypto_int32 g9_19 = 19 * g9;
|
||||
crypto_int32 f1_2 = 2 * f1;
|
||||
crypto_int32 f3_2 = 2 * f3;
|
||||
crypto_int32 f5_2 = 2 * f5;
|
||||
crypto_int32 f7_2 = 2 * f7;
|
||||
crypto_int32 f9_2 = 2 * f9;
|
||||
crypto_int64 f0g0 = f0 * (crypto_int64) g0;
|
||||
crypto_int64 f0g1 = f0 * (crypto_int64) g1;
|
||||
crypto_int64 f0g2 = f0 * (crypto_int64) g2;
|
||||
crypto_int64 f0g3 = f0 * (crypto_int64) g3;
|
||||
crypto_int64 f0g4 = f0 * (crypto_int64) g4;
|
||||
crypto_int64 f0g5 = f0 * (crypto_int64) g5;
|
||||
crypto_int64 f0g6 = f0 * (crypto_int64) g6;
|
||||
crypto_int64 f0g7 = f0 * (crypto_int64) g7;
|
||||
crypto_int64 f0g8 = f0 * (crypto_int64) g8;
|
||||
crypto_int64 f0g9 = f0 * (crypto_int64) g9;
|
||||
crypto_int64 f1g0 = f1 * (crypto_int64) g0;
|
||||
crypto_int64 f1g1_2 = f1_2 * (crypto_int64) g1;
|
||||
crypto_int64 f1g2 = f1 * (crypto_int64) g2;
|
||||
crypto_int64 f1g3_2 = f1_2 * (crypto_int64) g3;
|
||||
crypto_int64 f1g4 = f1 * (crypto_int64) g4;
|
||||
crypto_int64 f1g5_2 = f1_2 * (crypto_int64) g5;
|
||||
crypto_int64 f1g6 = f1 * (crypto_int64) g6;
|
||||
crypto_int64 f1g7_2 = f1_2 * (crypto_int64) g7;
|
||||
crypto_int64 f1g8 = f1 * (crypto_int64) g8;
|
||||
crypto_int64 f1g9_38 = f1_2 * (crypto_int64) g9_19;
|
||||
crypto_int64 f2g0 = f2 * (crypto_int64) g0;
|
||||
crypto_int64 f2g1 = f2 * (crypto_int64) g1;
|
||||
crypto_int64 f2g2 = f2 * (crypto_int64) g2;
|
||||
crypto_int64 f2g3 = f2 * (crypto_int64) g3;
|
||||
crypto_int64 f2g4 = f2 * (crypto_int64) g4;
|
||||
crypto_int64 f2g5 = f2 * (crypto_int64) g5;
|
||||
crypto_int64 f2g6 = f2 * (crypto_int64) g6;
|
||||
crypto_int64 f2g7 = f2 * (crypto_int64) g7;
|
||||
crypto_int64 f2g8_19 = f2 * (crypto_int64) g8_19;
|
||||
crypto_int64 f2g9_19 = f2 * (crypto_int64) g9_19;
|
||||
crypto_int64 f3g0 = f3 * (crypto_int64) g0;
|
||||
crypto_int64 f3g1_2 = f3_2 * (crypto_int64) g1;
|
||||
crypto_int64 f3g2 = f3 * (crypto_int64) g2;
|
||||
crypto_int64 f3g3_2 = f3_2 * (crypto_int64) g3;
|
||||
crypto_int64 f3g4 = f3 * (crypto_int64) g4;
|
||||
crypto_int64 f3g5_2 = f3_2 * (crypto_int64) g5;
|
||||
crypto_int64 f3g6 = f3 * (crypto_int64) g6;
|
||||
crypto_int64 f3g7_38 = f3_2 * (crypto_int64) g7_19;
|
||||
crypto_int64 f3g8_19 = f3 * (crypto_int64) g8_19;
|
||||
crypto_int64 f3g9_38 = f3_2 * (crypto_int64) g9_19;
|
||||
crypto_int64 f4g0 = f4 * (crypto_int64) g0;
|
||||
crypto_int64 f4g1 = f4 * (crypto_int64) g1;
|
||||
crypto_int64 f4g2 = f4 * (crypto_int64) g2;
|
||||
crypto_int64 f4g3 = f4 * (crypto_int64) g3;
|
||||
crypto_int64 f4g4 = f4 * (crypto_int64) g4;
|
||||
crypto_int64 f4g5 = f4 * (crypto_int64) g5;
|
||||
crypto_int64 f4g6_19 = f4 * (crypto_int64) g6_19;
|
||||
crypto_int64 f4g7_19 = f4 * (crypto_int64) g7_19;
|
||||
crypto_int64 f4g8_19 = f4 * (crypto_int64) g8_19;
|
||||
crypto_int64 f4g9_19 = f4 * (crypto_int64) g9_19;
|
||||
crypto_int64 f5g0 = f5 * (crypto_int64) g0;
|
||||
crypto_int64 f5g1_2 = f5_2 * (crypto_int64) g1;
|
||||
crypto_int64 f5g2 = f5 * (crypto_int64) g2;
|
||||
crypto_int64 f5g3_2 = f5_2 * (crypto_int64) g3;
|
||||
crypto_int64 f5g4 = f5 * (crypto_int64) g4;
|
||||
crypto_int64 f5g5_38 = f5_2 * (crypto_int64) g5_19;
|
||||
crypto_int64 f5g6_19 = f5 * (crypto_int64) g6_19;
|
||||
crypto_int64 f5g7_38 = f5_2 * (crypto_int64) g7_19;
|
||||
crypto_int64 f5g8_19 = f5 * (crypto_int64) g8_19;
|
||||
crypto_int64 f5g9_38 = f5_2 * (crypto_int64) g9_19;
|
||||
crypto_int64 f6g0 = f6 * (crypto_int64) g0;
|
||||
crypto_int64 f6g1 = f6 * (crypto_int64) g1;
|
||||
crypto_int64 f6g2 = f6 * (crypto_int64) g2;
|
||||
crypto_int64 f6g3 = f6 * (crypto_int64) g3;
|
||||
crypto_int64 f6g4_19 = f6 * (crypto_int64) g4_19;
|
||||
crypto_int64 f6g5_19 = f6 * (crypto_int64) g5_19;
|
||||
crypto_int64 f6g6_19 = f6 * (crypto_int64) g6_19;
|
||||
crypto_int64 f6g7_19 = f6 * (crypto_int64) g7_19;
|
||||
crypto_int64 f6g8_19 = f6 * (crypto_int64) g8_19;
|
||||
crypto_int64 f6g9_19 = f6 * (crypto_int64) g9_19;
|
||||
crypto_int64 f7g0 = f7 * (crypto_int64) g0;
|
||||
crypto_int64 f7g1_2 = f7_2 * (crypto_int64) g1;
|
||||
crypto_int64 f7g2 = f7 * (crypto_int64) g2;
|
||||
crypto_int64 f7g3_38 = f7_2 * (crypto_int64) g3_19;
|
||||
crypto_int64 f7g4_19 = f7 * (crypto_int64) g4_19;
|
||||
crypto_int64 f7g5_38 = f7_2 * (crypto_int64) g5_19;
|
||||
crypto_int64 f7g6_19 = f7 * (crypto_int64) g6_19;
|
||||
crypto_int64 f7g7_38 = f7_2 * (crypto_int64) g7_19;
|
||||
crypto_int64 f7g8_19 = f7 * (crypto_int64) g8_19;
|
||||
crypto_int64 f7g9_38 = f7_2 * (crypto_int64) g9_19;
|
||||
crypto_int64 f8g0 = f8 * (crypto_int64) g0;
|
||||
crypto_int64 f8g1 = f8 * (crypto_int64) g1;
|
||||
crypto_int64 f8g2_19 = f8 * (crypto_int64) g2_19;
|
||||
crypto_int64 f8g3_19 = f8 * (crypto_int64) g3_19;
|
||||
crypto_int64 f8g4_19 = f8 * (crypto_int64) g4_19;
|
||||
crypto_int64 f8g5_19 = f8 * (crypto_int64) g5_19;
|
||||
crypto_int64 f8g6_19 = f8 * (crypto_int64) g6_19;
|
||||
crypto_int64 f8g7_19 = f8 * (crypto_int64) g7_19;
|
||||
crypto_int64 f8g8_19 = f8 * (crypto_int64) g8_19;
|
||||
crypto_int64 f8g9_19 = f8 * (crypto_int64) g9_19;
|
||||
crypto_int64 f9g0 = f9 * (crypto_int64) g0;
|
||||
crypto_int64 f9g1_38 = f9_2 * (crypto_int64) g1_19;
|
||||
crypto_int64 f9g2_19 = f9 * (crypto_int64) g2_19;
|
||||
crypto_int64 f9g3_38 = f9_2 * (crypto_int64) g3_19;
|
||||
crypto_int64 f9g4_19 = f9 * (crypto_int64) g4_19;
|
||||
crypto_int64 f9g5_38 = f9_2 * (crypto_int64) g5_19;
|
||||
crypto_int64 f9g6_19 = f9 * (crypto_int64) g6_19;
|
||||
crypto_int64 f9g7_38 = f9_2 * (crypto_int64) g7_19;
|
||||
crypto_int64 f9g8_19 = f9 * (crypto_int64) g8_19;
|
||||
crypto_int64 f9g9_38 = f9_2 * (crypto_int64) g9_19;
|
||||
crypto_int64 h0 = f0g0+f1g9_38+f2g8_19+f3g7_38+f4g6_19+f5g5_38+f6g4_19+f7g3_38+f8g2_19+f9g1_38;
|
||||
crypto_int64 h1 = f0g1+f1g0 +f2g9_19+f3g8_19+f4g7_19+f5g6_19+f6g5_19+f7g4_19+f8g3_19+f9g2_19;
|
||||
crypto_int64 h2 = f0g2+f1g1_2 +f2g0 +f3g9_38+f4g8_19+f5g7_38+f6g6_19+f7g5_38+f8g4_19+f9g3_38;
|
||||
crypto_int64 h3 = f0g3+f1g2 +f2g1 +f3g0 +f4g9_19+f5g8_19+f6g7_19+f7g6_19+f8g5_19+f9g4_19;
|
||||
crypto_int64 h4 = f0g4+f1g3_2 +f2g2 +f3g1_2 +f4g0 +f5g9_38+f6g8_19+f7g7_38+f8g6_19+f9g5_38;
|
||||
crypto_int64 h5 = f0g5+f1g4 +f2g3 +f3g2 +f4g1 +f5g0 +f6g9_19+f7g8_19+f8g7_19+f9g6_19;
|
||||
crypto_int64 h6 = f0g6+f1g5_2 +f2g4 +f3g3_2 +f4g2 +f5g1_2 +f6g0 +f7g9_38+f8g8_19+f9g7_38;
|
||||
crypto_int64 h7 = f0g7+f1g6 +f2g5 +f3g4 +f4g3 +f5g2 +f6g1 +f7g0 +f8g9_19+f9g8_19;
|
||||
crypto_int64 h8 = f0g8+f1g7_2 +f2g6 +f3g5_2 +f4g4 +f5g3_2 +f6g2 +f7g1_2 +f8g0 +f9g9_38;
|
||||
crypto_int64 h9 = f0g9+f1g8 +f2g7 +f3g6 +f4g5 +f5g4 +f6g3 +f7g2 +f8g1 +f9g0 ;
|
||||
crypto_int64 carry0;
|
||||
crypto_int64 carry1;
|
||||
crypto_int64 carry2;
|
||||
crypto_int64 carry3;
|
||||
crypto_int64 carry4;
|
||||
crypto_int64 carry5;
|
||||
crypto_int64 carry6;
|
||||
crypto_int64 carry7;
|
||||
crypto_int64 carry8;
|
||||
crypto_int64 carry9;
|
||||
|
||||
/*
|
||||
|h0| <= (1.65*1.65*2^52*(1+19+19+19+19)+1.65*1.65*2^50*(38+38+38+38+38))
|
||||
i.e. |h0| <= 1.4*2^60; narrower ranges for h2, h4, h6, h8
|
||||
|h1| <= (1.65*1.65*2^51*(1+1+19+19+19+19+19+19+19+19))
|
||||
i.e. |h1| <= 1.7*2^59; narrower ranges for h3, h5, h7, h9
|
||||
*/
|
||||
|
||||
carry0 = (h0 + (crypto_int64) (1<<25)) >> 26; h1 += carry0; h0 -= carry0 << 26;
|
||||
carry4 = (h4 + (crypto_int64) (1<<25)) >> 26; h5 += carry4; h4 -= carry4 << 26;
|
||||
/* |h0| <= 2^25 */
|
||||
/* |h4| <= 2^25 */
|
||||
/* |h1| <= 1.71*2^59 */
|
||||
/* |h5| <= 1.71*2^59 */
|
||||
|
||||
carry1 = (h1 + (crypto_int64) (1<<24)) >> 25; h2 += carry1; h1 -= carry1 << 25;
|
||||
carry5 = (h5 + (crypto_int64) (1<<24)) >> 25; h6 += carry5; h5 -= carry5 << 25;
|
||||
/* |h1| <= 2^24; from now on fits into int32 */
|
||||
/* |h5| <= 2^24; from now on fits into int32 */
|
||||
/* |h2| <= 1.41*2^60 */
|
||||
/* |h6| <= 1.41*2^60 */
|
||||
|
||||
carry2 = (h2 + (crypto_int64) (1<<25)) >> 26; h3 += carry2; h2 -= carry2 << 26;
|
||||
carry6 = (h6 + (crypto_int64) (1<<25)) >> 26; h7 += carry6; h6 -= carry6 << 26;
|
||||
/* |h2| <= 2^25; from now on fits into int32 unchanged */
|
||||
/* |h6| <= 2^25; from now on fits into int32 unchanged */
|
||||
/* |h3| <= 1.71*2^59 */
|
||||
/* |h7| <= 1.71*2^59 */
|
||||
|
||||
carry3 = (h3 + (crypto_int64) (1<<24)) >> 25; h4 += carry3; h3 -= carry3 << 25;
|
||||
carry7 = (h7 + (crypto_int64) (1<<24)) >> 25; h8 += carry7; h7 -= carry7 << 25;
|
||||
/* |h3| <= 2^24; from now on fits into int32 unchanged */
|
||||
/* |h7| <= 2^24; from now on fits into int32 unchanged */
|
||||
/* |h4| <= 1.72*2^34 */
|
||||
/* |h8| <= 1.41*2^60 */
|
||||
|
||||
carry4 = (h4 + (crypto_int64) (1<<25)) >> 26; h5 += carry4; h4 -= carry4 << 26;
|
||||
carry8 = (h8 + (crypto_int64) (1<<25)) >> 26; h9 += carry8; h8 -= carry8 << 26;
|
||||
/* |h4| <= 2^25; from now on fits into int32 unchanged */
|
||||
/* |h8| <= 2^25; from now on fits into int32 unchanged */
|
||||
/* |h5| <= 1.01*2^24 */
|
||||
/* |h9| <= 1.71*2^59 */
|
||||
|
||||
carry9 = (h9 + (crypto_int64) (1<<24)) >> 25; h0 += carry9 * 19; h9 -= carry9 << 25;
|
||||
/* |h9| <= 2^24; from now on fits into int32 unchanged */
|
||||
/* |h0| <= 1.1*2^39 */
|
||||
|
||||
carry0 = (h0 + (crypto_int64) (1<<25)) >> 26; h1 += carry0; h0 -= carry0 << 26;
|
||||
/* |h0| <= 2^25; from now on fits into int32 unchanged */
|
||||
/* |h1| <= 1.01*2^24 */
|
||||
|
||||
h[0] = h0;
|
||||
h[1] = h1;
|
||||
h[2] = h2;
|
||||
h[3] = h3;
|
||||
h[4] = h4;
|
||||
h[5] = h5;
|
||||
h[6] = h6;
|
||||
h[7] = h7;
|
||||
h[8] = h8;
|
||||
h[9] = h9;
|
||||
}
|
45
vendor/MDBC/plugins/auth/ref10/fe_neg.c
vendored
Normal file
45
vendor/MDBC/plugins/auth/ref10/fe_neg.c
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
#include "fe.h"
|
||||
|
||||
/*
|
||||
h = -f
|
||||
|
||||
Preconditions:
|
||||
|f| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
|
||||
|
||||
Postconditions:
|
||||
|h| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
|
||||
*/
|
||||
|
||||
void fe_neg(fe h,const fe f)
|
||||
{
|
||||
crypto_int32 f0 = f[0];
|
||||
crypto_int32 f1 = f[1];
|
||||
crypto_int32 f2 = f[2];
|
||||
crypto_int32 f3 = f[3];
|
||||
crypto_int32 f4 = f[4];
|
||||
crypto_int32 f5 = f[5];
|
||||
crypto_int32 f6 = f[6];
|
||||
crypto_int32 f7 = f[7];
|
||||
crypto_int32 f8 = f[8];
|
||||
crypto_int32 f9 = f[9];
|
||||
crypto_int32 h0 = -f0;
|
||||
crypto_int32 h1 = -f1;
|
||||
crypto_int32 h2 = -f2;
|
||||
crypto_int32 h3 = -f3;
|
||||
crypto_int32 h4 = -f4;
|
||||
crypto_int32 h5 = -f5;
|
||||
crypto_int32 h6 = -f6;
|
||||
crypto_int32 h7 = -f7;
|
||||
crypto_int32 h8 = -f8;
|
||||
crypto_int32 h9 = -f9;
|
||||
h[0] = h0;
|
||||
h[1] = h1;
|
||||
h[2] = h2;
|
||||
h[3] = h3;
|
||||
h[4] = h4;
|
||||
h[5] = h5;
|
||||
h[6] = h6;
|
||||
h[7] = h7;
|
||||
h[8] = h8;
|
||||
h[9] = h9;
|
||||
}
|
13
vendor/MDBC/plugins/auth/ref10/fe_pow22523.c
vendored
Normal file
13
vendor/MDBC/plugins/auth/ref10/fe_pow22523.c
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
#include "fe.h"
|
||||
|
||||
void fe_pow22523(fe out,const fe z)
|
||||
{
|
||||
fe t0;
|
||||
fe t1;
|
||||
fe t2;
|
||||
int i;
|
||||
|
||||
#include "pow22523.h"
|
||||
|
||||
return;
|
||||
}
|
149
vendor/MDBC/plugins/auth/ref10/fe_sq.c
vendored
Normal file
149
vendor/MDBC/plugins/auth/ref10/fe_sq.c
vendored
Normal file
@ -0,0 +1,149 @@
|
||||
#include "fe.h"
|
||||
#include "crypto_int64.h"
|
||||
|
||||
/*
|
||||
h = f * f
|
||||
Can overlap h with f.
|
||||
|
||||
Preconditions:
|
||||
|f| bounded by 1.65*2^26,1.65*2^25,1.65*2^26,1.65*2^25,etc.
|
||||
|
||||
Postconditions:
|
||||
|h| bounded by 1.01*2^25,1.01*2^24,1.01*2^25,1.01*2^24,etc.
|
||||
*/
|
||||
|
||||
/*
|
||||
See fe_mul.c for discussion of implementation strategy.
|
||||
*/
|
||||
|
||||
void fe_sq(fe h,const fe f)
|
||||
{
|
||||
crypto_int32 f0 = f[0];
|
||||
crypto_int32 f1 = f[1];
|
||||
crypto_int32 f2 = f[2];
|
||||
crypto_int32 f3 = f[3];
|
||||
crypto_int32 f4 = f[4];
|
||||
crypto_int32 f5 = f[5];
|
||||
crypto_int32 f6 = f[6];
|
||||
crypto_int32 f7 = f[7];
|
||||
crypto_int32 f8 = f[8];
|
||||
crypto_int32 f9 = f[9];
|
||||
crypto_int32 f0_2 = 2 * f0;
|
||||
crypto_int32 f1_2 = 2 * f1;
|
||||
crypto_int32 f2_2 = 2 * f2;
|
||||
crypto_int32 f3_2 = 2 * f3;
|
||||
crypto_int32 f4_2 = 2 * f4;
|
||||
crypto_int32 f5_2 = 2 * f5;
|
||||
crypto_int32 f6_2 = 2 * f6;
|
||||
crypto_int32 f7_2 = 2 * f7;
|
||||
crypto_int32 f5_38 = 38 * f5; /* 1.959375*2^30 */
|
||||
crypto_int32 f6_19 = 19 * f6; /* 1.959375*2^30 */
|
||||
crypto_int32 f7_38 = 38 * f7; /* 1.959375*2^30 */
|
||||
crypto_int32 f8_19 = 19 * f8; /* 1.959375*2^30 */
|
||||
crypto_int32 f9_38 = 38 * f9; /* 1.959375*2^30 */
|
||||
crypto_int64 f0f0 = f0 * (crypto_int64) f0;
|
||||
crypto_int64 f0f1_2 = f0_2 * (crypto_int64) f1;
|
||||
crypto_int64 f0f2_2 = f0_2 * (crypto_int64) f2;
|
||||
crypto_int64 f0f3_2 = f0_2 * (crypto_int64) f3;
|
||||
crypto_int64 f0f4_2 = f0_2 * (crypto_int64) f4;
|
||||
crypto_int64 f0f5_2 = f0_2 * (crypto_int64) f5;
|
||||
crypto_int64 f0f6_2 = f0_2 * (crypto_int64) f6;
|
||||
crypto_int64 f0f7_2 = f0_2 * (crypto_int64) f7;
|
||||
crypto_int64 f0f8_2 = f0_2 * (crypto_int64) f8;
|
||||
crypto_int64 f0f9_2 = f0_2 * (crypto_int64) f9;
|
||||
crypto_int64 f1f1_2 = f1_2 * (crypto_int64) f1;
|
||||
crypto_int64 f1f2_2 = f1_2 * (crypto_int64) f2;
|
||||
crypto_int64 f1f3_4 = f1_2 * (crypto_int64) f3_2;
|
||||
crypto_int64 f1f4_2 = f1_2 * (crypto_int64) f4;
|
||||
crypto_int64 f1f5_4 = f1_2 * (crypto_int64) f5_2;
|
||||
crypto_int64 f1f6_2 = f1_2 * (crypto_int64) f6;
|
||||
crypto_int64 f1f7_4 = f1_2 * (crypto_int64) f7_2;
|
||||
crypto_int64 f1f8_2 = f1_2 * (crypto_int64) f8;
|
||||
crypto_int64 f1f9_76 = f1_2 * (crypto_int64) f9_38;
|
||||
crypto_int64 f2f2 = f2 * (crypto_int64) f2;
|
||||
crypto_int64 f2f3_2 = f2_2 * (crypto_int64) f3;
|
||||
crypto_int64 f2f4_2 = f2_2 * (crypto_int64) f4;
|
||||
crypto_int64 f2f5_2 = f2_2 * (crypto_int64) f5;
|
||||
crypto_int64 f2f6_2 = f2_2 * (crypto_int64) f6;
|
||||
crypto_int64 f2f7_2 = f2_2 * (crypto_int64) f7;
|
||||
crypto_int64 f2f8_38 = f2_2 * (crypto_int64) f8_19;
|
||||
crypto_int64 f2f9_38 = f2 * (crypto_int64) f9_38;
|
||||
crypto_int64 f3f3_2 = f3_2 * (crypto_int64) f3;
|
||||
crypto_int64 f3f4_2 = f3_2 * (crypto_int64) f4;
|
||||
crypto_int64 f3f5_4 = f3_2 * (crypto_int64) f5_2;
|
||||
crypto_int64 f3f6_2 = f3_2 * (crypto_int64) f6;
|
||||
crypto_int64 f3f7_76 = f3_2 * (crypto_int64) f7_38;
|
||||
crypto_int64 f3f8_38 = f3_2 * (crypto_int64) f8_19;
|
||||
crypto_int64 f3f9_76 = f3_2 * (crypto_int64) f9_38;
|
||||
crypto_int64 f4f4 = f4 * (crypto_int64) f4;
|
||||
crypto_int64 f4f5_2 = f4_2 * (crypto_int64) f5;
|
||||
crypto_int64 f4f6_38 = f4_2 * (crypto_int64) f6_19;
|
||||
crypto_int64 f4f7_38 = f4 * (crypto_int64) f7_38;
|
||||
crypto_int64 f4f8_38 = f4_2 * (crypto_int64) f8_19;
|
||||
crypto_int64 f4f9_38 = f4 * (crypto_int64) f9_38;
|
||||
crypto_int64 f5f5_38 = f5 * (crypto_int64) f5_38;
|
||||
crypto_int64 f5f6_38 = f5_2 * (crypto_int64) f6_19;
|
||||
crypto_int64 f5f7_76 = f5_2 * (crypto_int64) f7_38;
|
||||
crypto_int64 f5f8_38 = f5_2 * (crypto_int64) f8_19;
|
||||
crypto_int64 f5f9_76 = f5_2 * (crypto_int64) f9_38;
|
||||
crypto_int64 f6f6_19 = f6 * (crypto_int64) f6_19;
|
||||
crypto_int64 f6f7_38 = f6 * (crypto_int64) f7_38;
|
||||
crypto_int64 f6f8_38 = f6_2 * (crypto_int64) f8_19;
|
||||
crypto_int64 f6f9_38 = f6 * (crypto_int64) f9_38;
|
||||
crypto_int64 f7f7_38 = f7 * (crypto_int64) f7_38;
|
||||
crypto_int64 f7f8_38 = f7_2 * (crypto_int64) f8_19;
|
||||
crypto_int64 f7f9_76 = f7_2 * (crypto_int64) f9_38;
|
||||
crypto_int64 f8f8_19 = f8 * (crypto_int64) f8_19;
|
||||
crypto_int64 f8f9_38 = f8 * (crypto_int64) f9_38;
|
||||
crypto_int64 f9f9_38 = f9 * (crypto_int64) f9_38;
|
||||
crypto_int64 h0 = f0f0 +f1f9_76+f2f8_38+f3f7_76+f4f6_38+f5f5_38;
|
||||
crypto_int64 h1 = f0f1_2+f2f9_38+f3f8_38+f4f7_38+f5f6_38;
|
||||
crypto_int64 h2 = f0f2_2+f1f1_2 +f3f9_76+f4f8_38+f5f7_76+f6f6_19;
|
||||
crypto_int64 h3 = f0f3_2+f1f2_2 +f4f9_38+f5f8_38+f6f7_38;
|
||||
crypto_int64 h4 = f0f4_2+f1f3_4 +f2f2 +f5f9_76+f6f8_38+f7f7_38;
|
||||
crypto_int64 h5 = f0f5_2+f1f4_2 +f2f3_2 +f6f9_38+f7f8_38;
|
||||
crypto_int64 h6 = f0f6_2+f1f5_4 +f2f4_2 +f3f3_2 +f7f9_76+f8f8_19;
|
||||
crypto_int64 h7 = f0f7_2+f1f6_2 +f2f5_2 +f3f4_2 +f8f9_38;
|
||||
crypto_int64 h8 = f0f8_2+f1f7_4 +f2f6_2 +f3f5_4 +f4f4 +f9f9_38;
|
||||
crypto_int64 h9 = f0f9_2+f1f8_2 +f2f7_2 +f3f6_2 +f4f5_2;
|
||||
crypto_int64 carry0;
|
||||
crypto_int64 carry1;
|
||||
crypto_int64 carry2;
|
||||
crypto_int64 carry3;
|
||||
crypto_int64 carry4;
|
||||
crypto_int64 carry5;
|
||||
crypto_int64 carry6;
|
||||
crypto_int64 carry7;
|
||||
crypto_int64 carry8;
|
||||
crypto_int64 carry9;
|
||||
|
||||
carry0 = (h0 + (crypto_int64) (1<<25)) >> 26; h1 += carry0; h0 -= carry0 << 26;
|
||||
carry4 = (h4 + (crypto_int64) (1<<25)) >> 26; h5 += carry4; h4 -= carry4 << 26;
|
||||
|
||||
carry1 = (h1 + (crypto_int64) (1<<24)) >> 25; h2 += carry1; h1 -= carry1 << 25;
|
||||
carry5 = (h5 + (crypto_int64) (1<<24)) >> 25; h6 += carry5; h5 -= carry5 << 25;
|
||||
|
||||
carry2 = (h2 + (crypto_int64) (1<<25)) >> 26; h3 += carry2; h2 -= carry2 << 26;
|
||||
carry6 = (h6 + (crypto_int64) (1<<25)) >> 26; h7 += carry6; h6 -= carry6 << 26;
|
||||
|
||||
carry3 = (h3 + (crypto_int64) (1<<24)) >> 25; h4 += carry3; h3 -= carry3 << 25;
|
||||
carry7 = (h7 + (crypto_int64) (1<<24)) >> 25; h8 += carry7; h7 -= carry7 << 25;
|
||||
|
||||
carry4 = (h4 + (crypto_int64) (1<<25)) >> 26; h5 += carry4; h4 -= carry4 << 26;
|
||||
carry8 = (h8 + (crypto_int64) (1<<25)) >> 26; h9 += carry8; h8 -= carry8 << 26;
|
||||
|
||||
carry9 = (h9 + (crypto_int64) (1<<24)) >> 25; h0 += carry9 * 19; h9 -= carry9 << 25;
|
||||
|
||||
carry0 = (h0 + (crypto_int64) (1<<25)) >> 26; h1 += carry0; h0 -= carry0 << 26;
|
||||
|
||||
h[0] = h0;
|
||||
h[1] = h1;
|
||||
h[2] = h2;
|
||||
h[3] = h3;
|
||||
h[4] = h4;
|
||||
h[5] = h5;
|
||||
h[6] = h6;
|
||||
h[7] = h7;
|
||||
h[8] = h8;
|
||||
h[9] = h9;
|
||||
}
|
160
vendor/MDBC/plugins/auth/ref10/fe_sq2.c
vendored
Normal file
160
vendor/MDBC/plugins/auth/ref10/fe_sq2.c
vendored
Normal file
@ -0,0 +1,160 @@
|
||||
#include "fe.h"
|
||||
#include "crypto_int64.h"
|
||||
|
||||
/*
|
||||
h = 2 * f * f
|
||||
Can overlap h with f.
|
||||
|
||||
Preconditions:
|
||||
|f| bounded by 1.65*2^26,1.65*2^25,1.65*2^26,1.65*2^25,etc.
|
||||
|
||||
Postconditions:
|
||||
|h| bounded by 1.01*2^25,1.01*2^24,1.01*2^25,1.01*2^24,etc.
|
||||
*/
|
||||
|
||||
/*
|
||||
See fe_mul.c for discussion of implementation strategy.
|
||||
*/
|
||||
|
||||
void fe_sq2(fe h,const fe f)
|
||||
{
|
||||
crypto_int32 f0 = f[0];
|
||||
crypto_int32 f1 = f[1];
|
||||
crypto_int32 f2 = f[2];
|
||||
crypto_int32 f3 = f[3];
|
||||
crypto_int32 f4 = f[4];
|
||||
crypto_int32 f5 = f[5];
|
||||
crypto_int32 f6 = f[6];
|
||||
crypto_int32 f7 = f[7];
|
||||
crypto_int32 f8 = f[8];
|
||||
crypto_int32 f9 = f[9];
|
||||
crypto_int32 f0_2 = 2 * f0;
|
||||
crypto_int32 f1_2 = 2 * f1;
|
||||
crypto_int32 f2_2 = 2 * f2;
|
||||
crypto_int32 f3_2 = 2 * f3;
|
||||
crypto_int32 f4_2 = 2 * f4;
|
||||
crypto_int32 f5_2 = 2 * f5;
|
||||
crypto_int32 f6_2 = 2 * f6;
|
||||
crypto_int32 f7_2 = 2 * f7;
|
||||
crypto_int32 f5_38 = 38 * f5; /* 1.959375*2^30 */
|
||||
crypto_int32 f6_19 = 19 * f6; /* 1.959375*2^30 */
|
||||
crypto_int32 f7_38 = 38 * f7; /* 1.959375*2^30 */
|
||||
crypto_int32 f8_19 = 19 * f8; /* 1.959375*2^30 */
|
||||
crypto_int32 f9_38 = 38 * f9; /* 1.959375*2^30 */
|
||||
crypto_int64 f0f0 = f0 * (crypto_int64) f0;
|
||||
crypto_int64 f0f1_2 = f0_2 * (crypto_int64) f1;
|
||||
crypto_int64 f0f2_2 = f0_2 * (crypto_int64) f2;
|
||||
crypto_int64 f0f3_2 = f0_2 * (crypto_int64) f3;
|
||||
crypto_int64 f0f4_2 = f0_2 * (crypto_int64) f4;
|
||||
crypto_int64 f0f5_2 = f0_2 * (crypto_int64) f5;
|
||||
crypto_int64 f0f6_2 = f0_2 * (crypto_int64) f6;
|
||||
crypto_int64 f0f7_2 = f0_2 * (crypto_int64) f7;
|
||||
crypto_int64 f0f8_2 = f0_2 * (crypto_int64) f8;
|
||||
crypto_int64 f0f9_2 = f0_2 * (crypto_int64) f9;
|
||||
crypto_int64 f1f1_2 = f1_2 * (crypto_int64) f1;
|
||||
crypto_int64 f1f2_2 = f1_2 * (crypto_int64) f2;
|
||||
crypto_int64 f1f3_4 = f1_2 * (crypto_int64) f3_2;
|
||||
crypto_int64 f1f4_2 = f1_2 * (crypto_int64) f4;
|
||||
crypto_int64 f1f5_4 = f1_2 * (crypto_int64) f5_2;
|
||||
crypto_int64 f1f6_2 = f1_2 * (crypto_int64) f6;
|
||||
crypto_int64 f1f7_4 = f1_2 * (crypto_int64) f7_2;
|
||||
crypto_int64 f1f8_2 = f1_2 * (crypto_int64) f8;
|
||||
crypto_int64 f1f9_76 = f1_2 * (crypto_int64) f9_38;
|
||||
crypto_int64 f2f2 = f2 * (crypto_int64) f2;
|
||||
crypto_int64 f2f3_2 = f2_2 * (crypto_int64) f3;
|
||||
crypto_int64 f2f4_2 = f2_2 * (crypto_int64) f4;
|
||||
crypto_int64 f2f5_2 = f2_2 * (crypto_int64) f5;
|
||||
crypto_int64 f2f6_2 = f2_2 * (crypto_int64) f6;
|
||||
crypto_int64 f2f7_2 = f2_2 * (crypto_int64) f7;
|
||||
crypto_int64 f2f8_38 = f2_2 * (crypto_int64) f8_19;
|
||||
crypto_int64 f2f9_38 = f2 * (crypto_int64) f9_38;
|
||||
crypto_int64 f3f3_2 = f3_2 * (crypto_int64) f3;
|
||||
crypto_int64 f3f4_2 = f3_2 * (crypto_int64) f4;
|
||||
crypto_int64 f3f5_4 = f3_2 * (crypto_int64) f5_2;
|
||||
crypto_int64 f3f6_2 = f3_2 * (crypto_int64) f6;
|
||||
crypto_int64 f3f7_76 = f3_2 * (crypto_int64) f7_38;
|
||||
crypto_int64 f3f8_38 = f3_2 * (crypto_int64) f8_19;
|
||||
crypto_int64 f3f9_76 = f3_2 * (crypto_int64) f9_38;
|
||||
crypto_int64 f4f4 = f4 * (crypto_int64) f4;
|
||||
crypto_int64 f4f5_2 = f4_2 * (crypto_int64) f5;
|
||||
crypto_int64 f4f6_38 = f4_2 * (crypto_int64) f6_19;
|
||||
crypto_int64 f4f7_38 = f4 * (crypto_int64) f7_38;
|
||||
crypto_int64 f4f8_38 = f4_2 * (crypto_int64) f8_19;
|
||||
crypto_int64 f4f9_38 = f4 * (crypto_int64) f9_38;
|
||||
crypto_int64 f5f5_38 = f5 * (crypto_int64) f5_38;
|
||||
crypto_int64 f5f6_38 = f5_2 * (crypto_int64) f6_19;
|
||||
crypto_int64 f5f7_76 = f5_2 * (crypto_int64) f7_38;
|
||||
crypto_int64 f5f8_38 = f5_2 * (crypto_int64) f8_19;
|
||||
crypto_int64 f5f9_76 = f5_2 * (crypto_int64) f9_38;
|
||||
crypto_int64 f6f6_19 = f6 * (crypto_int64) f6_19;
|
||||
crypto_int64 f6f7_38 = f6 * (crypto_int64) f7_38;
|
||||
crypto_int64 f6f8_38 = f6_2 * (crypto_int64) f8_19;
|
||||
crypto_int64 f6f9_38 = f6 * (crypto_int64) f9_38;
|
||||
crypto_int64 f7f7_38 = f7 * (crypto_int64) f7_38;
|
||||
crypto_int64 f7f8_38 = f7_2 * (crypto_int64) f8_19;
|
||||
crypto_int64 f7f9_76 = f7_2 * (crypto_int64) f9_38;
|
||||
crypto_int64 f8f8_19 = f8 * (crypto_int64) f8_19;
|
||||
crypto_int64 f8f9_38 = f8 * (crypto_int64) f9_38;
|
||||
crypto_int64 f9f9_38 = f9 * (crypto_int64) f9_38;
|
||||
crypto_int64 h0 = f0f0 +f1f9_76+f2f8_38+f3f7_76+f4f6_38+f5f5_38;
|
||||
crypto_int64 h1 = f0f1_2+f2f9_38+f3f8_38+f4f7_38+f5f6_38;
|
||||
crypto_int64 h2 = f0f2_2+f1f1_2 +f3f9_76+f4f8_38+f5f7_76+f6f6_19;
|
||||
crypto_int64 h3 = f0f3_2+f1f2_2 +f4f9_38+f5f8_38+f6f7_38;
|
||||
crypto_int64 h4 = f0f4_2+f1f3_4 +f2f2 +f5f9_76+f6f8_38+f7f7_38;
|
||||
crypto_int64 h5 = f0f5_2+f1f4_2 +f2f3_2 +f6f9_38+f7f8_38;
|
||||
crypto_int64 h6 = f0f6_2+f1f5_4 +f2f4_2 +f3f3_2 +f7f9_76+f8f8_19;
|
||||
crypto_int64 h7 = f0f7_2+f1f6_2 +f2f5_2 +f3f4_2 +f8f9_38;
|
||||
crypto_int64 h8 = f0f8_2+f1f7_4 +f2f6_2 +f3f5_4 +f4f4 +f9f9_38;
|
||||
crypto_int64 h9 = f0f9_2+f1f8_2 +f2f7_2 +f3f6_2 +f4f5_2;
|
||||
crypto_int64 carry0;
|
||||
crypto_int64 carry1;
|
||||
crypto_int64 carry2;
|
||||
crypto_int64 carry3;
|
||||
crypto_int64 carry4;
|
||||
crypto_int64 carry5;
|
||||
crypto_int64 carry6;
|
||||
crypto_int64 carry7;
|
||||
crypto_int64 carry8;
|
||||
crypto_int64 carry9;
|
||||
|
||||
h0 += h0;
|
||||
h1 += h1;
|
||||
h2 += h2;
|
||||
h3 += h3;
|
||||
h4 += h4;
|
||||
h5 += h5;
|
||||
h6 += h6;
|
||||
h7 += h7;
|
||||
h8 += h8;
|
||||
h9 += h9;
|
||||
|
||||
carry0 = (h0 + (crypto_int64) (1<<25)) >> 26; h1 += carry0; h0 -= carry0 << 26;
|
||||
carry4 = (h4 + (crypto_int64) (1<<25)) >> 26; h5 += carry4; h4 -= carry4 << 26;
|
||||
|
||||
carry1 = (h1 + (crypto_int64) (1<<24)) >> 25; h2 += carry1; h1 -= carry1 << 25;
|
||||
carry5 = (h5 + (crypto_int64) (1<<24)) >> 25; h6 += carry5; h5 -= carry5 << 25;
|
||||
|
||||
carry2 = (h2 + (crypto_int64) (1<<25)) >> 26; h3 += carry2; h2 -= carry2 << 26;
|
||||
carry6 = (h6 + (crypto_int64) (1<<25)) >> 26; h7 += carry6; h6 -= carry6 << 26;
|
||||
|
||||
carry3 = (h3 + (crypto_int64) (1<<24)) >> 25; h4 += carry3; h3 -= carry3 << 25;
|
||||
carry7 = (h7 + (crypto_int64) (1<<24)) >> 25; h8 += carry7; h7 -= carry7 << 25;
|
||||
|
||||
carry4 = (h4 + (crypto_int64) (1<<25)) >> 26; h5 += carry4; h4 -= carry4 << 26;
|
||||
carry8 = (h8 + (crypto_int64) (1<<25)) >> 26; h9 += carry8; h8 -= carry8 << 26;
|
||||
|
||||
carry9 = (h9 + (crypto_int64) (1<<24)) >> 25; h0 += carry9 * 19; h9 -= carry9 << 25;
|
||||
|
||||
carry0 = (h0 + (crypto_int64) (1<<25)) >> 26; h1 += carry0; h0 -= carry0 << 26;
|
||||
|
||||
h[0] = h0;
|
||||
h[1] = h1;
|
||||
h[2] = h2;
|
||||
h[3] = h3;
|
||||
h[4] = h4;
|
||||
h[5] = h5;
|
||||
h[6] = h6;
|
||||
h[7] = h7;
|
||||
h[8] = h8;
|
||||
h[9] = h9;
|
||||
}
|
57
vendor/MDBC/plugins/auth/ref10/fe_sub.c
vendored
Normal file
57
vendor/MDBC/plugins/auth/ref10/fe_sub.c
vendored
Normal file
@ -0,0 +1,57 @@
|
||||
#include "fe.h"
|
||||
|
||||
/*
|
||||
h = f - g
|
||||
Can overlap h with f or g.
|
||||
|
||||
Preconditions:
|
||||
|f| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
|
||||
|g| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
|
||||
|
||||
Postconditions:
|
||||
|h| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
|
||||
*/
|
||||
|
||||
void fe_sub(fe h,const fe f,const fe g)
|
||||
{
|
||||
crypto_int32 f0 = f[0];
|
||||
crypto_int32 f1 = f[1];
|
||||
crypto_int32 f2 = f[2];
|
||||
crypto_int32 f3 = f[3];
|
||||
crypto_int32 f4 = f[4];
|
||||
crypto_int32 f5 = f[5];
|
||||
crypto_int32 f6 = f[6];
|
||||
crypto_int32 f7 = f[7];
|
||||
crypto_int32 f8 = f[8];
|
||||
crypto_int32 f9 = f[9];
|
||||
crypto_int32 g0 = g[0];
|
||||
crypto_int32 g1 = g[1];
|
||||
crypto_int32 g2 = g[2];
|
||||
crypto_int32 g3 = g[3];
|
||||
crypto_int32 g4 = g[4];
|
||||
crypto_int32 g5 = g[5];
|
||||
crypto_int32 g6 = g[6];
|
||||
crypto_int32 g7 = g[7];
|
||||
crypto_int32 g8 = g[8];
|
||||
crypto_int32 g9 = g[9];
|
||||
crypto_int32 h0 = f0 - g0;
|
||||
crypto_int32 h1 = f1 - g1;
|
||||
crypto_int32 h2 = f2 - g2;
|
||||
crypto_int32 h3 = f3 - g3;
|
||||
crypto_int32 h4 = f4 - g4;
|
||||
crypto_int32 h5 = f5 - g5;
|
||||
crypto_int32 h6 = f6 - g6;
|
||||
crypto_int32 h7 = f7 - g7;
|
||||
crypto_int32 h8 = f8 - g8;
|
||||
crypto_int32 h9 = f9 - g9;
|
||||
h[0] = h0;
|
||||
h[1] = h1;
|
||||
h[2] = h2;
|
||||
h[3] = h3;
|
||||
h[4] = h4;
|
||||
h[5] = h5;
|
||||
h[6] = h6;
|
||||
h[7] = h7;
|
||||
h[8] = h8;
|
||||
h[9] = h9;
|
||||
}
|
119
vendor/MDBC/plugins/auth/ref10/fe_tobytes.c
vendored
Normal file
119
vendor/MDBC/plugins/auth/ref10/fe_tobytes.c
vendored
Normal file
@ -0,0 +1,119 @@
|
||||
#include "fe.h"
|
||||
|
||||
/*
|
||||
Preconditions:
|
||||
|h| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
|
||||
|
||||
Write p=2^255-19; q=floor(h/p).
|
||||
Basic claim: q = floor(2^(-255)(h + 19 2^(-25)h9 + 2^(-1))).
|
||||
|
||||
Proof:
|
||||
Have |h|<=p so |q|<=1 so |19^2 2^(-255) q|<1/4.
|
||||
Also have |h-2^230 h9|<2^231 so |19 2^(-255)(h-2^230 h9)|<1/4.
|
||||
|
||||
Write y=2^(-1)-19^2 2^(-255)q-19 2^(-255)(h-2^230 h9).
|
||||
Then 0<y<1.
|
||||
|
||||
Write r=h-pq.
|
||||
Have 0<=r<=p-1=2^255-20.
|
||||
Thus 0<=r+19(2^-255)r<r+19(2^-255)2^255<=2^255-1.
|
||||
|
||||
Write x=r+19(2^-255)r+y.
|
||||
Then 0<x<2^255 so floor(2^(-255)x) = 0 so floor(q+2^(-255)x) = q.
|
||||
|
||||
Have q+2^(-255)x = 2^(-255)(h + 19 2^(-25) h9 + 2^(-1))
|
||||
so floor(2^(-255)(h + 19 2^(-25) h9 + 2^(-1))) = q.
|
||||
*/
|
||||
|
||||
void fe_tobytes(unsigned char *s,const fe h)
|
||||
{
|
||||
crypto_int32 h0 = h[0];
|
||||
crypto_int32 h1 = h[1];
|
||||
crypto_int32 h2 = h[2];
|
||||
crypto_int32 h3 = h[3];
|
||||
crypto_int32 h4 = h[4];
|
||||
crypto_int32 h5 = h[5];
|
||||
crypto_int32 h6 = h[6];
|
||||
crypto_int32 h7 = h[7];
|
||||
crypto_int32 h8 = h[8];
|
||||
crypto_int32 h9 = h[9];
|
||||
crypto_int32 q;
|
||||
crypto_int32 carry0;
|
||||
crypto_int32 carry1;
|
||||
crypto_int32 carry2;
|
||||
crypto_int32 carry3;
|
||||
crypto_int32 carry4;
|
||||
crypto_int32 carry5;
|
||||
crypto_int32 carry6;
|
||||
crypto_int32 carry7;
|
||||
crypto_int32 carry8;
|
||||
crypto_int32 carry9;
|
||||
|
||||
q = (19 * h9 + (((crypto_int32) 1) << 24)) >> 25;
|
||||
q = (h0 + q) >> 26;
|
||||
q = (h1 + q) >> 25;
|
||||
q = (h2 + q) >> 26;
|
||||
q = (h3 + q) >> 25;
|
||||
q = (h4 + q) >> 26;
|
||||
q = (h5 + q) >> 25;
|
||||
q = (h6 + q) >> 26;
|
||||
q = (h7 + q) >> 25;
|
||||
q = (h8 + q) >> 26;
|
||||
q = (h9 + q) >> 25;
|
||||
|
||||
/* Goal: Output h-(2^255-19)q, which is between 0 and 2^255-20. */
|
||||
h0 += 19 * q;
|
||||
/* Goal: Output h-2^255 q, which is between 0 and 2^255-20. */
|
||||
|
||||
carry0 = h0 >> 26; h1 += carry0; h0 -= carry0 << 26;
|
||||
carry1 = h1 >> 25; h2 += carry1; h1 -= carry1 << 25;
|
||||
carry2 = h2 >> 26; h3 += carry2; h2 -= carry2 << 26;
|
||||
carry3 = h3 >> 25; h4 += carry3; h3 -= carry3 << 25;
|
||||
carry4 = h4 >> 26; h5 += carry4; h4 -= carry4 << 26;
|
||||
carry5 = h5 >> 25; h6 += carry5; h5 -= carry5 << 25;
|
||||
carry6 = h6 >> 26; h7 += carry6; h6 -= carry6 << 26;
|
||||
carry7 = h7 >> 25; h8 += carry7; h7 -= carry7 << 25;
|
||||
carry8 = h8 >> 26; h9 += carry8; h8 -= carry8 << 26;
|
||||
carry9 = h9 >> 25; h9 -= carry9 << 25;
|
||||
/* h10 = carry9 */
|
||||
|
||||
/*
|
||||
Goal: Output h0+...+2^255 h10-2^255 q, which is between 0 and 2^255-20.
|
||||
Have h0+...+2^230 h9 between 0 and 2^255-1;
|
||||
evidently 2^255 h10-2^255 q = 0.
|
||||
Goal: Output h0+...+2^230 h9.
|
||||
*/
|
||||
|
||||
s[0] = h0 >> 0;
|
||||
s[1] = h0 >> 8;
|
||||
s[2] = h0 >> 16;
|
||||
s[3] = (h0 >> 24) | (h1 << 2);
|
||||
s[4] = h1 >> 6;
|
||||
s[5] = h1 >> 14;
|
||||
s[6] = (h1 >> 22) | (h2 << 3);
|
||||
s[7] = h2 >> 5;
|
||||
s[8] = h2 >> 13;
|
||||
s[9] = (h2 >> 21) | (h3 << 5);
|
||||
s[10] = h3 >> 3;
|
||||
s[11] = h3 >> 11;
|
||||
s[12] = (h3 >> 19) | (h4 << 6);
|
||||
s[13] = h4 >> 2;
|
||||
s[14] = h4 >> 10;
|
||||
s[15] = h4 >> 18;
|
||||
s[16] = h5 >> 0;
|
||||
s[17] = h5 >> 8;
|
||||
s[18] = h5 >> 16;
|
||||
s[19] = (h5 >> 24) | (h6 << 1);
|
||||
s[20] = h6 >> 7;
|
||||
s[21] = h6 >> 15;
|
||||
s[22] = (h6 >> 23) | (h7 << 3);
|
||||
s[23] = h7 >> 5;
|
||||
s[24] = h7 >> 13;
|
||||
s[25] = (h7 >> 21) | (h8 << 4);
|
||||
s[26] = h8 >> 4;
|
||||
s[27] = h8 >> 12;
|
||||
s[28] = (h8 >> 20) | (h9 << 6);
|
||||
s[29] = h9 >> 2;
|
||||
s[30] = h9 >> 10;
|
||||
s[31] = h9 >> 18;
|
||||
}
|
95
vendor/MDBC/plugins/auth/ref10/ge.h
vendored
Normal file
95
vendor/MDBC/plugins/auth/ref10/ge.h
vendored
Normal file
@ -0,0 +1,95 @@
|
||||
#ifndef GE_H
|
||||
#define GE_H
|
||||
|
||||
/*
|
||||
ge means group element.
|
||||
|
||||
Here the group is the set of pairs (x,y) of field elements (see fe.h)
|
||||
satisfying -x^2 + y^2 = 1 + d x^2y^2
|
||||
where d = -121665/121666.
|
||||
|
||||
Representations:
|
||||
ge_p2 (projective): (X:Y:Z) satisfying x=X/Z, y=Y/Z
|
||||
ge_p3 (extended): (X:Y:Z:T) satisfying x=X/Z, y=Y/Z, XY=ZT
|
||||
ge_p1p1 (completed): ((X:Z),(Y:T)) satisfying x=X/Z, y=Y/T
|
||||
ge_precomp (Duif): (y+x,y-x,2dxy)
|
||||
*/
|
||||
|
||||
#include "fe.h"
|
||||
|
||||
typedef struct {
|
||||
fe X;
|
||||
fe Y;
|
||||
fe Z;
|
||||
} ge_p2;
|
||||
|
||||
typedef struct {
|
||||
fe X;
|
||||
fe Y;
|
||||
fe Z;
|
||||
fe T;
|
||||
} ge_p3;
|
||||
|
||||
typedef struct {
|
||||
fe X;
|
||||
fe Y;
|
||||
fe Z;
|
||||
fe T;
|
||||
} ge_p1p1;
|
||||
|
||||
typedef struct {
|
||||
fe yplusx;
|
||||
fe yminusx;
|
||||
fe xy2d;
|
||||
} ge_precomp;
|
||||
|
||||
typedef struct {
|
||||
fe YplusX;
|
||||
fe YminusX;
|
||||
fe Z;
|
||||
fe T2d;
|
||||
} ge_cached;
|
||||
|
||||
#define ge_frombytes_negate_vartime crypto_sign_ed25519_ref10_ge_frombytes_negate_vartime
|
||||
#define ge_tobytes crypto_sign_ed25519_ref10_ge_tobytes
|
||||
#define ge_p3_tobytes crypto_sign_ed25519_ref10_ge_p3_tobytes
|
||||
|
||||
#define ge_p2_0 crypto_sign_ed25519_ref10_ge_p2_0
|
||||
#define ge_p3_0 crypto_sign_ed25519_ref10_ge_p3_0
|
||||
#define ge_precomp_0 crypto_sign_ed25519_ref10_ge_precomp_0
|
||||
#define ge_p3_to_p2 crypto_sign_ed25519_ref10_ge_p3_to_p2
|
||||
#define ge_p3_to_cached crypto_sign_ed25519_ref10_ge_p3_to_cached
|
||||
#define ge_p1p1_to_p2 crypto_sign_ed25519_ref10_ge_p1p1_to_p2
|
||||
#define ge_p1p1_to_p3 crypto_sign_ed25519_ref10_ge_p1p1_to_p3
|
||||
#define ge_p2_dbl crypto_sign_ed25519_ref10_ge_p2_dbl
|
||||
#define ge_p3_dbl crypto_sign_ed25519_ref10_ge_p3_dbl
|
||||
|
||||
#define ge_madd crypto_sign_ed25519_ref10_ge_madd
|
||||
#define ge_msub crypto_sign_ed25519_ref10_ge_msub
|
||||
#define ge_add crypto_sign_ed25519_ref10_ge_add
|
||||
#define ge_sub crypto_sign_ed25519_ref10_ge_sub
|
||||
#define ge_scalarmult_base crypto_sign_ed25519_ref10_ge_scalarmult_base
|
||||
#define ge_double_scalarmult_vartime crypto_sign_ed25519_ref10_ge_double_scalarmult_vartime
|
||||
|
||||
extern void ge_tobytes(unsigned char *,const ge_p2 *);
|
||||
extern void ge_p3_tobytes(unsigned char *,const ge_p3 *);
|
||||
extern int ge_frombytes_negate_vartime(ge_p3 *,const unsigned char *);
|
||||
|
||||
extern void ge_p2_0(ge_p2 *);
|
||||
extern void ge_p3_0(ge_p3 *);
|
||||
extern void ge_precomp_0(ge_precomp *);
|
||||
extern void ge_p3_to_p2(ge_p2 *,const ge_p3 *);
|
||||
extern void ge_p3_to_cached(ge_cached *,const ge_p3 *);
|
||||
extern void ge_p1p1_to_p2(ge_p2 *,const ge_p1p1 *);
|
||||
extern void ge_p1p1_to_p3(ge_p3 *,const ge_p1p1 *);
|
||||
extern void ge_p2_dbl(ge_p1p1 *,const ge_p2 *);
|
||||
extern void ge_p3_dbl(ge_p1p1 *,const ge_p3 *);
|
||||
|
||||
extern void ge_madd(ge_p1p1 *,const ge_p3 *,const ge_precomp *);
|
||||
extern void ge_msub(ge_p1p1 *,const ge_p3 *,const ge_precomp *);
|
||||
extern void ge_add(ge_p1p1 *,const ge_p3 *,const ge_cached *);
|
||||
extern void ge_sub(ge_p1p1 *,const ge_p3 *,const ge_cached *);
|
||||
extern void ge_scalarmult_base(ge_p3 *,const unsigned char *);
|
||||
extern void ge_double_scalarmult_vartime(ge_p2 *,const unsigned char *,const ge_p3 *,const unsigned char *);
|
||||
|
||||
#endif
|
11
vendor/MDBC/plugins/auth/ref10/ge_add.c
vendored
Normal file
11
vendor/MDBC/plugins/auth/ref10/ge_add.c
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
#include "ge.h"
|
||||
|
||||
/*
|
||||
r = p + q
|
||||
*/
|
||||
|
||||
void ge_add(ge_p1p1 *r,const ge_p3 *p,const ge_cached *q)
|
||||
{
|
||||
fe t0;
|
||||
#include "ge_add.h"
|
||||
}
|
97
vendor/MDBC/plugins/auth/ref10/ge_add.h
vendored
Normal file
97
vendor/MDBC/plugins/auth/ref10/ge_add.h
vendored
Normal file
@ -0,0 +1,97 @@
|
||||
|
||||
/* qhasm: enter ge_add */
|
||||
|
||||
/* qhasm: fe X1 */
|
||||
|
||||
/* qhasm: fe Y1 */
|
||||
|
||||
/* qhasm: fe Z1 */
|
||||
|
||||
/* qhasm: fe Z2 */
|
||||
|
||||
/* qhasm: fe T1 */
|
||||
|
||||
/* qhasm: fe ZZ */
|
||||
|
||||
/* qhasm: fe YpX2 */
|
||||
|
||||
/* qhasm: fe YmX2 */
|
||||
|
||||
/* qhasm: fe T2d2 */
|
||||
|
||||
/* qhasm: fe X3 */
|
||||
|
||||
/* qhasm: fe Y3 */
|
||||
|
||||
/* qhasm: fe Z3 */
|
||||
|
||||
/* qhasm: fe T3 */
|
||||
|
||||
/* qhasm: fe YpX1 */
|
||||
|
||||
/* qhasm: fe YmX1 */
|
||||
|
||||
/* qhasm: fe A */
|
||||
|
||||
/* qhasm: fe B */
|
||||
|
||||
/* qhasm: fe C */
|
||||
|
||||
/* qhasm: fe D */
|
||||
|
||||
/* qhasm: YpX1 = Y1+X1 */
|
||||
/* asm 1: fe_add(>YpX1=fe#1,<Y1=fe#12,<X1=fe#11); */
|
||||
/* asm 2: fe_add(>YpX1=r->X,<Y1=p->Y,<X1=p->X); */
|
||||
fe_add(r->X,p->Y,p->X);
|
||||
|
||||
/* qhasm: YmX1 = Y1-X1 */
|
||||
/* asm 1: fe_sub(>YmX1=fe#2,<Y1=fe#12,<X1=fe#11); */
|
||||
/* asm 2: fe_sub(>YmX1=r->Y,<Y1=p->Y,<X1=p->X); */
|
||||
fe_sub(r->Y,p->Y,p->X);
|
||||
|
||||
/* qhasm: A = YpX1*YpX2 */
|
||||
/* asm 1: fe_mul(>A=fe#3,<YpX1=fe#1,<YpX2=fe#15); */
|
||||
/* asm 2: fe_mul(>A=r->Z,<YpX1=r->X,<YpX2=q->YplusX); */
|
||||
fe_mul(r->Z,r->X,q->YplusX);
|
||||
|
||||
/* qhasm: B = YmX1*YmX2 */
|
||||
/* asm 1: fe_mul(>B=fe#2,<YmX1=fe#2,<YmX2=fe#16); */
|
||||
/* asm 2: fe_mul(>B=r->Y,<YmX1=r->Y,<YmX2=q->YminusX); */
|
||||
fe_mul(r->Y,r->Y,q->YminusX);
|
||||
|
||||
/* qhasm: C = T2d2*T1 */
|
||||
/* asm 1: fe_mul(>C=fe#4,<T2d2=fe#18,<T1=fe#14); */
|
||||
/* asm 2: fe_mul(>C=r->T,<T2d2=q->T2d,<T1=p->T); */
|
||||
fe_mul(r->T,q->T2d,p->T);
|
||||
|
||||
/* qhasm: ZZ = Z1*Z2 */
|
||||
/* asm 1: fe_mul(>ZZ=fe#1,<Z1=fe#13,<Z2=fe#17); */
|
||||
/* asm 2: fe_mul(>ZZ=r->X,<Z1=p->Z,<Z2=q->Z); */
|
||||
fe_mul(r->X,p->Z,q->Z);
|
||||
|
||||
/* qhasm: D = 2*ZZ */
|
||||
/* asm 1: fe_add(>D=fe#5,<ZZ=fe#1,<ZZ=fe#1); */
|
||||
/* asm 2: fe_add(>D=t0,<ZZ=r->X,<ZZ=r->X); */
|
||||
fe_add(t0,r->X,r->X);
|
||||
|
||||
/* qhasm: X3 = A-B */
|
||||
/* asm 1: fe_sub(>X3=fe#1,<A=fe#3,<B=fe#2); */
|
||||
/* asm 2: fe_sub(>X3=r->X,<A=r->Z,<B=r->Y); */
|
||||
fe_sub(r->X,r->Z,r->Y);
|
||||
|
||||
/* qhasm: Y3 = A+B */
|
||||
/* asm 1: fe_add(>Y3=fe#2,<A=fe#3,<B=fe#2); */
|
||||
/* asm 2: fe_add(>Y3=r->Y,<A=r->Z,<B=r->Y); */
|
||||
fe_add(r->Y,r->Z,r->Y);
|
||||
|
||||
/* qhasm: Z3 = D+C */
|
||||
/* asm 1: fe_add(>Z3=fe#3,<D=fe#5,<C=fe#4); */
|
||||
/* asm 2: fe_add(>Z3=r->Z,<D=t0,<C=r->T); */
|
||||
fe_add(r->Z,t0,r->T);
|
||||
|
||||
/* qhasm: T3 = D-C */
|
||||
/* asm 1: fe_sub(>T3=fe#4,<D=fe#5,<C=fe#4); */
|
||||
/* asm 2: fe_sub(>T3=r->T,<D=t0,<C=r->T); */
|
||||
fe_sub(r->T,t0,r->T);
|
||||
|
||||
/* qhasm: return */
|
96
vendor/MDBC/plugins/auth/ref10/ge_double_scalarmult.c
vendored
Normal file
96
vendor/MDBC/plugins/auth/ref10/ge_double_scalarmult.c
vendored
Normal file
@ -0,0 +1,96 @@
|
||||
#include "ge.h"
|
||||
|
||||
static void slide(signed char *r,const unsigned char *a)
|
||||
{
|
||||
int i;
|
||||
int b;
|
||||
int k;
|
||||
|
||||
for (i = 0;i < 256;++i)
|
||||
r[i] = 1 & (a[i >> 3] >> (i & 7));
|
||||
|
||||
for (i = 0;i < 256;++i)
|
||||
if (r[i]) {
|
||||
for (b = 1;b <= 6 && i + b < 256;++b) {
|
||||
if (r[i + b]) {
|
||||
if (r[i] + (r[i + b] << b) <= 15) {
|
||||
r[i] += r[i + b] << b; r[i + b] = 0;
|
||||
} else if (r[i] - (r[i + b] << b) >= -15) {
|
||||
r[i] -= r[i + b] << b;
|
||||
for (k = i + b;k < 256;++k) {
|
||||
if (!r[k]) {
|
||||
r[k] = 1;
|
||||
break;
|
||||
}
|
||||
r[k] = 0;
|
||||
}
|
||||
} else
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static ge_precomp Bi[8] = {
|
||||
#include "base2.h"
|
||||
} ;
|
||||
|
||||
/*
|
||||
r = a * A + b * B
|
||||
where a = a[0]+256*a[1]+...+256^31 a[31].
|
||||
and b = b[0]+256*b[1]+...+256^31 b[31].
|
||||
B is the Ed25519 base point (x,4/5) with x positive.
|
||||
*/
|
||||
|
||||
void ge_double_scalarmult_vartime(ge_p2 *r,const unsigned char *a,const ge_p3 *A,const unsigned char *b)
|
||||
{
|
||||
signed char aslide[256];
|
||||
signed char bslide[256];
|
||||
ge_cached Ai[8]; /* A,3A,5A,7A,9A,11A,13A,15A */
|
||||
ge_p1p1 t;
|
||||
ge_p3 u;
|
||||
ge_p3 A2;
|
||||
int i;
|
||||
|
||||
slide(aslide,a);
|
||||
slide(bslide,b);
|
||||
|
||||
ge_p3_to_cached(&Ai[0],A);
|
||||
ge_p3_dbl(&t,A); ge_p1p1_to_p3(&A2,&t);
|
||||
ge_add(&t,&A2,&Ai[0]); ge_p1p1_to_p3(&u,&t); ge_p3_to_cached(&Ai[1],&u);
|
||||
ge_add(&t,&A2,&Ai[1]); ge_p1p1_to_p3(&u,&t); ge_p3_to_cached(&Ai[2],&u);
|
||||
ge_add(&t,&A2,&Ai[2]); ge_p1p1_to_p3(&u,&t); ge_p3_to_cached(&Ai[3],&u);
|
||||
ge_add(&t,&A2,&Ai[3]); ge_p1p1_to_p3(&u,&t); ge_p3_to_cached(&Ai[4],&u);
|
||||
ge_add(&t,&A2,&Ai[4]); ge_p1p1_to_p3(&u,&t); ge_p3_to_cached(&Ai[5],&u);
|
||||
ge_add(&t,&A2,&Ai[5]); ge_p1p1_to_p3(&u,&t); ge_p3_to_cached(&Ai[6],&u);
|
||||
ge_add(&t,&A2,&Ai[6]); ge_p1p1_to_p3(&u,&t); ge_p3_to_cached(&Ai[7],&u);
|
||||
|
||||
ge_p2_0(r);
|
||||
|
||||
for (i = 255;i >= 0;--i) {
|
||||
if (aslide[i] || bslide[i]) break;
|
||||
}
|
||||
|
||||
for (;i >= 0;--i) {
|
||||
ge_p2_dbl(&t,r);
|
||||
|
||||
if (aslide[i] > 0) {
|
||||
ge_p1p1_to_p3(&u,&t);
|
||||
ge_add(&t,&u,&Ai[aslide[i]/2]);
|
||||
} else if (aslide[i] < 0) {
|
||||
ge_p1p1_to_p3(&u,&t);
|
||||
ge_sub(&t,&u,&Ai[(-aslide[i])/2]);
|
||||
}
|
||||
|
||||
if (bslide[i] > 0) {
|
||||
ge_p1p1_to_p3(&u,&t);
|
||||
ge_madd(&t,&u,&Bi[bslide[i]/2]);
|
||||
} else if (bslide[i] < 0) {
|
||||
ge_p1p1_to_p3(&u,&t);
|
||||
ge_msub(&t,&u,&Bi[(-bslide[i])/2]);
|
||||
}
|
||||
|
||||
ge_p1p1_to_p2(r,&t);
|
||||
}
|
||||
}
|
50
vendor/MDBC/plugins/auth/ref10/ge_frombytes.c
vendored
Normal file
50
vendor/MDBC/plugins/auth/ref10/ge_frombytes.c
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
#include "ge.h"
|
||||
|
||||
static const fe d = {
|
||||
#include "d.h"
|
||||
} ;
|
||||
|
||||
static const fe sqrtm1 = {
|
||||
#include "sqrtm1.h"
|
||||
} ;
|
||||
|
||||
int ge_frombytes_negate_vartime(ge_p3 *h,const unsigned char *s)
|
||||
{
|
||||
fe u;
|
||||
fe v;
|
||||
fe v3;
|
||||
fe vxx;
|
||||
fe check;
|
||||
|
||||
fe_frombytes(h->Y,s);
|
||||
fe_1(h->Z);
|
||||
fe_sq(u,h->Y);
|
||||
fe_mul(v,u,d);
|
||||
fe_sub(u,u,h->Z); /* u = y^2-1 */
|
||||
fe_add(v,v,h->Z); /* v = dy^2+1 */
|
||||
|
||||
fe_sq(v3,v);
|
||||
fe_mul(v3,v3,v); /* v3 = v^3 */
|
||||
fe_sq(h->X,v3);
|
||||
fe_mul(h->X,h->X,v);
|
||||
fe_mul(h->X,h->X,u); /* x = uv^7 */
|
||||
|
||||
fe_pow22523(h->X,h->X); /* x = (uv^7)^((q-5)/8) */
|
||||
fe_mul(h->X,h->X,v3);
|
||||
fe_mul(h->X,h->X,u); /* x = uv^3(uv^7)^((q-5)/8) */
|
||||
|
||||
fe_sq(vxx,h->X);
|
||||
fe_mul(vxx,vxx,v);
|
||||
fe_sub(check,vxx,u); /* vx^2-u */
|
||||
if (fe_isnonzero(check)) {
|
||||
fe_add(check,vxx,u); /* vx^2+u */
|
||||
if (fe_isnonzero(check)) return -1;
|
||||
fe_mul(h->X,h->X,sqrtm1);
|
||||
}
|
||||
|
||||
if (fe_isnegative(h->X) == (s[31] >> 7))
|
||||
fe_neg(h->X,h->X);
|
||||
|
||||
fe_mul(h->T,h->X,h->Y);
|
||||
return 0;
|
||||
}
|
11
vendor/MDBC/plugins/auth/ref10/ge_madd.c
vendored
Normal file
11
vendor/MDBC/plugins/auth/ref10/ge_madd.c
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
#include "ge.h"
|
||||
|
||||
/*
|
||||
r = p + q
|
||||
*/
|
||||
|
||||
void ge_madd(ge_p1p1 *r,const ge_p3 *p,const ge_precomp *q)
|
||||
{
|
||||
fe t0;
|
||||
#include "ge_madd.h"
|
||||
}
|
88
vendor/MDBC/plugins/auth/ref10/ge_madd.h
vendored
Normal file
88
vendor/MDBC/plugins/auth/ref10/ge_madd.h
vendored
Normal file
@ -0,0 +1,88 @@
|
||||
|
||||
/* qhasm: enter ge_madd */
|
||||
|
||||
/* qhasm: fe X1 */
|
||||
|
||||
/* qhasm: fe Y1 */
|
||||
|
||||
/* qhasm: fe Z1 */
|
||||
|
||||
/* qhasm: fe T1 */
|
||||
|
||||
/* qhasm: fe ypx2 */
|
||||
|
||||
/* qhasm: fe ymx2 */
|
||||
|
||||
/* qhasm: fe xy2d2 */
|
||||
|
||||
/* qhasm: fe X3 */
|
||||
|
||||
/* qhasm: fe Y3 */
|
||||
|
||||
/* qhasm: fe Z3 */
|
||||
|
||||
/* qhasm: fe T3 */
|
||||
|
||||
/* qhasm: fe YpX1 */
|
||||
|
||||
/* qhasm: fe YmX1 */
|
||||
|
||||
/* qhasm: fe A */
|
||||
|
||||
/* qhasm: fe B */
|
||||
|
||||
/* qhasm: fe C */
|
||||
|
||||
/* qhasm: fe D */
|
||||
|
||||
/* qhasm: YpX1 = Y1+X1 */
|
||||
/* asm 1: fe_add(>YpX1=fe#1,<Y1=fe#12,<X1=fe#11); */
|
||||
/* asm 2: fe_add(>YpX1=r->X,<Y1=p->Y,<X1=p->X); */
|
||||
fe_add(r->X,p->Y,p->X);
|
||||
|
||||
/* qhasm: YmX1 = Y1-X1 */
|
||||
/* asm 1: fe_sub(>YmX1=fe#2,<Y1=fe#12,<X1=fe#11); */
|
||||
/* asm 2: fe_sub(>YmX1=r->Y,<Y1=p->Y,<X1=p->X); */
|
||||
fe_sub(r->Y,p->Y,p->X);
|
||||
|
||||
/* qhasm: A = YpX1*ypx2 */
|
||||
/* asm 1: fe_mul(>A=fe#3,<YpX1=fe#1,<ypx2=fe#15); */
|
||||
/* asm 2: fe_mul(>A=r->Z,<YpX1=r->X,<ypx2=q->yplusx); */
|
||||
fe_mul(r->Z,r->X,q->yplusx);
|
||||
|
||||
/* qhasm: B = YmX1*ymx2 */
|
||||
/* asm 1: fe_mul(>B=fe#2,<YmX1=fe#2,<ymx2=fe#16); */
|
||||
/* asm 2: fe_mul(>B=r->Y,<YmX1=r->Y,<ymx2=q->yminusx); */
|
||||
fe_mul(r->Y,r->Y,q->yminusx);
|
||||
|
||||
/* qhasm: C = xy2d2*T1 */
|
||||
/* asm 1: fe_mul(>C=fe#4,<xy2d2=fe#17,<T1=fe#14); */
|
||||
/* asm 2: fe_mul(>C=r->T,<xy2d2=q->xy2d,<T1=p->T); */
|
||||
fe_mul(r->T,q->xy2d,p->T);
|
||||
|
||||
/* qhasm: D = 2*Z1 */
|
||||
/* asm 1: fe_add(>D=fe#5,<Z1=fe#13,<Z1=fe#13); */
|
||||
/* asm 2: fe_add(>D=t0,<Z1=p->Z,<Z1=p->Z); */
|
||||
fe_add(t0,p->Z,p->Z);
|
||||
|
||||
/* qhasm: X3 = A-B */
|
||||
/* asm 1: fe_sub(>X3=fe#1,<A=fe#3,<B=fe#2); */
|
||||
/* asm 2: fe_sub(>X3=r->X,<A=r->Z,<B=r->Y); */
|
||||
fe_sub(r->X,r->Z,r->Y);
|
||||
|
||||
/* qhasm: Y3 = A+B */
|
||||
/* asm 1: fe_add(>Y3=fe#2,<A=fe#3,<B=fe#2); */
|
||||
/* asm 2: fe_add(>Y3=r->Y,<A=r->Z,<B=r->Y); */
|
||||
fe_add(r->Y,r->Z,r->Y);
|
||||
|
||||
/* qhasm: Z3 = D+C */
|
||||
/* asm 1: fe_add(>Z3=fe#3,<D=fe#5,<C=fe#4); */
|
||||
/* asm 2: fe_add(>Z3=r->Z,<D=t0,<C=r->T); */
|
||||
fe_add(r->Z,t0,r->T);
|
||||
|
||||
/* qhasm: T3 = D-C */
|
||||
/* asm 1: fe_sub(>T3=fe#4,<D=fe#5,<C=fe#4); */
|
||||
/* asm 2: fe_sub(>T3=r->T,<D=t0,<C=r->T); */
|
||||
fe_sub(r->T,t0,r->T);
|
||||
|
||||
/* qhasm: return */
|
11
vendor/MDBC/plugins/auth/ref10/ge_msub.c
vendored
Normal file
11
vendor/MDBC/plugins/auth/ref10/ge_msub.c
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
#include "ge.h"
|
||||
|
||||
/*
|
||||
r = p - q
|
||||
*/
|
||||
|
||||
void ge_msub(ge_p1p1 *r,const ge_p3 *p,const ge_precomp *q)
|
||||
{
|
||||
fe t0;
|
||||
#include "ge_msub.h"
|
||||
}
|
88
vendor/MDBC/plugins/auth/ref10/ge_msub.h
vendored
Normal file
88
vendor/MDBC/plugins/auth/ref10/ge_msub.h
vendored
Normal file
@ -0,0 +1,88 @@
|
||||
|
||||
/* qhasm: enter ge_msub */
|
||||
|
||||
/* qhasm: fe X1 */
|
||||
|
||||
/* qhasm: fe Y1 */
|
||||
|
||||
/* qhasm: fe Z1 */
|
||||
|
||||
/* qhasm: fe T1 */
|
||||
|
||||
/* qhasm: fe ypx2 */
|
||||
|
||||
/* qhasm: fe ymx2 */
|
||||
|
||||
/* qhasm: fe xy2d2 */
|
||||
|
||||
/* qhasm: fe X3 */
|
||||
|
||||
/* qhasm: fe Y3 */
|
||||
|
||||
/* qhasm: fe Z3 */
|
||||
|
||||
/* qhasm: fe T3 */
|
||||
|
||||
/* qhasm: fe YpX1 */
|
||||
|
||||
/* qhasm: fe YmX1 */
|
||||
|
||||
/* qhasm: fe A */
|
||||
|
||||
/* qhasm: fe B */
|
||||
|
||||
/* qhasm: fe C */
|
||||
|
||||
/* qhasm: fe D */
|
||||
|
||||
/* qhasm: YpX1 = Y1+X1 */
|
||||
/* asm 1: fe_add(>YpX1=fe#1,<Y1=fe#12,<X1=fe#11); */
|
||||
/* asm 2: fe_add(>YpX1=r->X,<Y1=p->Y,<X1=p->X); */
|
||||
fe_add(r->X,p->Y,p->X);
|
||||
|
||||
/* qhasm: YmX1 = Y1-X1 */
|
||||
/* asm 1: fe_sub(>YmX1=fe#2,<Y1=fe#12,<X1=fe#11); */
|
||||
/* asm 2: fe_sub(>YmX1=r->Y,<Y1=p->Y,<X1=p->X); */
|
||||
fe_sub(r->Y,p->Y,p->X);
|
||||
|
||||
/* qhasm: A = YpX1*ymx2 */
|
||||
/* asm 1: fe_mul(>A=fe#3,<YpX1=fe#1,<ymx2=fe#16); */
|
||||
/* asm 2: fe_mul(>A=r->Z,<YpX1=r->X,<ymx2=q->yminusx); */
|
||||
fe_mul(r->Z,r->X,q->yminusx);
|
||||
|
||||
/* qhasm: B = YmX1*ypx2 */
|
||||
/* asm 1: fe_mul(>B=fe#2,<YmX1=fe#2,<ypx2=fe#15); */
|
||||
/* asm 2: fe_mul(>B=r->Y,<YmX1=r->Y,<ypx2=q->yplusx); */
|
||||
fe_mul(r->Y,r->Y,q->yplusx);
|
||||
|
||||
/* qhasm: C = xy2d2*T1 */
|
||||
/* asm 1: fe_mul(>C=fe#4,<xy2d2=fe#17,<T1=fe#14); */
|
||||
/* asm 2: fe_mul(>C=r->T,<xy2d2=q->xy2d,<T1=p->T); */
|
||||
fe_mul(r->T,q->xy2d,p->T);
|
||||
|
||||
/* qhasm: D = 2*Z1 */
|
||||
/* asm 1: fe_add(>D=fe#5,<Z1=fe#13,<Z1=fe#13); */
|
||||
/* asm 2: fe_add(>D=t0,<Z1=p->Z,<Z1=p->Z); */
|
||||
fe_add(t0,p->Z,p->Z);
|
||||
|
||||
/* qhasm: X3 = A-B */
|
||||
/* asm 1: fe_sub(>X3=fe#1,<A=fe#3,<B=fe#2); */
|
||||
/* asm 2: fe_sub(>X3=r->X,<A=r->Z,<B=r->Y); */
|
||||
fe_sub(r->X,r->Z,r->Y);
|
||||
|
||||
/* qhasm: Y3 = A+B */
|
||||
/* asm 1: fe_add(>Y3=fe#2,<A=fe#3,<B=fe#2); */
|
||||
/* asm 2: fe_add(>Y3=r->Y,<A=r->Z,<B=r->Y); */
|
||||
fe_add(r->Y,r->Z,r->Y);
|
||||
|
||||
/* qhasm: Z3 = D-C */
|
||||
/* asm 1: fe_sub(>Z3=fe#3,<D=fe#5,<C=fe#4); */
|
||||
/* asm 2: fe_sub(>Z3=r->Z,<D=t0,<C=r->T); */
|
||||
fe_sub(r->Z,t0,r->T);
|
||||
|
||||
/* qhasm: T3 = D+C */
|
||||
/* asm 1: fe_add(>T3=fe#4,<D=fe#5,<C=fe#4); */
|
||||
/* asm 2: fe_add(>T3=r->T,<D=t0,<C=r->T); */
|
||||
fe_add(r->T,t0,r->T);
|
||||
|
||||
/* qhasm: return */
|
12
vendor/MDBC/plugins/auth/ref10/ge_p1p1_to_p2.c
vendored
Normal file
12
vendor/MDBC/plugins/auth/ref10/ge_p1p1_to_p2.c
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
#include "ge.h"
|
||||
|
||||
/*
|
||||
r = p
|
||||
*/
|
||||
|
||||
extern void ge_p1p1_to_p2(ge_p2 *r,const ge_p1p1 *p)
|
||||
{
|
||||
fe_mul(r->X,p->X,p->T);
|
||||
fe_mul(r->Y,p->Y,p->Z);
|
||||
fe_mul(r->Z,p->Z,p->T);
|
||||
}
|
13
vendor/MDBC/plugins/auth/ref10/ge_p1p1_to_p3.c
vendored
Normal file
13
vendor/MDBC/plugins/auth/ref10/ge_p1p1_to_p3.c
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
#include "ge.h"
|
||||
|
||||
/*
|
||||
r = p
|
||||
*/
|
||||
|
||||
extern void ge_p1p1_to_p3(ge_p3 *r,const ge_p1p1 *p)
|
||||
{
|
||||
fe_mul(r->X,p->X,p->T);
|
||||
fe_mul(r->Y,p->Y,p->Z);
|
||||
fe_mul(r->Z,p->Z,p->T);
|
||||
fe_mul(r->T,p->X,p->Y);
|
||||
}
|
8
vendor/MDBC/plugins/auth/ref10/ge_p2_0.c
vendored
Normal file
8
vendor/MDBC/plugins/auth/ref10/ge_p2_0.c
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
#include "ge.h"
|
||||
|
||||
void ge_p2_0(ge_p2 *h)
|
||||
{
|
||||
fe_0(h->X);
|
||||
fe_1(h->Y);
|
||||
fe_1(h->Z);
|
||||
}
|
11
vendor/MDBC/plugins/auth/ref10/ge_p2_dbl.c
vendored
Normal file
11
vendor/MDBC/plugins/auth/ref10/ge_p2_dbl.c
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
#include "ge.h"
|
||||
|
||||
/*
|
||||
r = 2 * p
|
||||
*/
|
||||
|
||||
void ge_p2_dbl(ge_p1p1 *r,const ge_p2 *p)
|
||||
{
|
||||
fe t0;
|
||||
#include "ge_p2_dbl.h"
|
||||
}
|
73
vendor/MDBC/plugins/auth/ref10/ge_p2_dbl.h
vendored
Normal file
73
vendor/MDBC/plugins/auth/ref10/ge_p2_dbl.h
vendored
Normal file
@ -0,0 +1,73 @@
|
||||
|
||||
/* qhasm: enter ge_p2_dbl */
|
||||
|
||||
/* qhasm: fe X1 */
|
||||
|
||||
/* qhasm: fe Y1 */
|
||||
|
||||
/* qhasm: fe Z1 */
|
||||
|
||||
/* qhasm: fe A */
|
||||
|
||||
/* qhasm: fe AA */
|
||||
|
||||
/* qhasm: fe XX */
|
||||
|
||||
/* qhasm: fe YY */
|
||||
|
||||
/* qhasm: fe B */
|
||||
|
||||
/* qhasm: fe X3 */
|
||||
|
||||
/* qhasm: fe Y3 */
|
||||
|
||||
/* qhasm: fe Z3 */
|
||||
|
||||
/* qhasm: fe T3 */
|
||||
|
||||
/* qhasm: XX=X1^2 */
|
||||
/* asm 1: fe_sq(>XX=fe#1,<X1=fe#11); */
|
||||
/* asm 2: fe_sq(>XX=r->X,<X1=p->X); */
|
||||
fe_sq(r->X,p->X);
|
||||
|
||||
/* qhasm: YY=Y1^2 */
|
||||
/* asm 1: fe_sq(>YY=fe#3,<Y1=fe#12); */
|
||||
/* asm 2: fe_sq(>YY=r->Z,<Y1=p->Y); */
|
||||
fe_sq(r->Z,p->Y);
|
||||
|
||||
/* qhasm: B=2*Z1^2 */
|
||||
/* asm 1: fe_sq2(>B=fe#4,<Z1=fe#13); */
|
||||
/* asm 2: fe_sq2(>B=r->T,<Z1=p->Z); */
|
||||
fe_sq2(r->T,p->Z);
|
||||
|
||||
/* qhasm: A=X1+Y1 */
|
||||
/* asm 1: fe_add(>A=fe#2,<X1=fe#11,<Y1=fe#12); */
|
||||
/* asm 2: fe_add(>A=r->Y,<X1=p->X,<Y1=p->Y); */
|
||||
fe_add(r->Y,p->X,p->Y);
|
||||
|
||||
/* qhasm: AA=A^2 */
|
||||
/* asm 1: fe_sq(>AA=fe#5,<A=fe#2); */
|
||||
/* asm 2: fe_sq(>AA=t0,<A=r->Y); */
|
||||
fe_sq(t0,r->Y);
|
||||
|
||||
/* qhasm: Y3=YY+XX */
|
||||
/* asm 1: fe_add(>Y3=fe#2,<YY=fe#3,<XX=fe#1); */
|
||||
/* asm 2: fe_add(>Y3=r->Y,<YY=r->Z,<XX=r->X); */
|
||||
fe_add(r->Y,r->Z,r->X);
|
||||
|
||||
/* qhasm: Z3=YY-XX */
|
||||
/* asm 1: fe_sub(>Z3=fe#3,<YY=fe#3,<XX=fe#1); */
|
||||
/* asm 2: fe_sub(>Z3=r->Z,<YY=r->Z,<XX=r->X); */
|
||||
fe_sub(r->Z,r->Z,r->X);
|
||||
|
||||
/* qhasm: X3=AA-Y3 */
|
||||
/* asm 1: fe_sub(>X3=fe#1,<AA=fe#5,<Y3=fe#2); */
|
||||
/* asm 2: fe_sub(>X3=r->X,<AA=t0,<Y3=r->Y); */
|
||||
fe_sub(r->X,t0,r->Y);
|
||||
|
||||
/* qhasm: T3=B-Z3 */
|
||||
/* asm 1: fe_sub(>T3=fe#4,<B=fe#4,<Z3=fe#3); */
|
||||
/* asm 2: fe_sub(>T3=r->T,<B=r->T,<Z3=r->Z); */
|
||||
fe_sub(r->T,r->T,r->Z);
|
||||
|
||||
/* qhasm: return */
|
9
vendor/MDBC/plugins/auth/ref10/ge_p3_0.c
vendored
Normal file
9
vendor/MDBC/plugins/auth/ref10/ge_p3_0.c
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
#include "ge.h"
|
||||
|
||||
void ge_p3_0(ge_p3 *h)
|
||||
{
|
||||
fe_0(h->X);
|
||||
fe_1(h->Y);
|
||||
fe_1(h->Z);
|
||||
fe_0(h->T);
|
||||
}
|
12
vendor/MDBC/plugins/auth/ref10/ge_p3_dbl.c
vendored
Normal file
12
vendor/MDBC/plugins/auth/ref10/ge_p3_dbl.c
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
#include "ge.h"
|
||||
|
||||
/*
|
||||
r = 2 * p
|
||||
*/
|
||||
|
||||
void ge_p3_dbl(ge_p1p1 *r,const ge_p3 *p)
|
||||
{
|
||||
ge_p2 q;
|
||||
ge_p3_to_p2(&q,p);
|
||||
ge_p2_dbl(r,&q);
|
||||
}
|
17
vendor/MDBC/plugins/auth/ref10/ge_p3_to_cached.c
vendored
Normal file
17
vendor/MDBC/plugins/auth/ref10/ge_p3_to_cached.c
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
#include "ge.h"
|
||||
|
||||
/*
|
||||
r = p
|
||||
*/
|
||||
|
||||
static const fe d2 = {
|
||||
#include "d2.h"
|
||||
} ;
|
||||
|
||||
extern void ge_p3_to_cached(ge_cached *r,const ge_p3 *p)
|
||||
{
|
||||
fe_add(r->YplusX,p->Y,p->X);
|
||||
fe_sub(r->YminusX,p->Y,p->X);
|
||||
fe_copy(r->Z,p->Z);
|
||||
fe_mul(r->T2d,p->T,d2);
|
||||
}
|
12
vendor/MDBC/plugins/auth/ref10/ge_p3_to_p2.c
vendored
Normal file
12
vendor/MDBC/plugins/auth/ref10/ge_p3_to_p2.c
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
#include "ge.h"
|
||||
|
||||
/*
|
||||
r = p
|
||||
*/
|
||||
|
||||
extern void ge_p3_to_p2(ge_p2 *r,const ge_p3 *p)
|
||||
{
|
||||
fe_copy(r->X,p->X);
|
||||
fe_copy(r->Y,p->Y);
|
||||
fe_copy(r->Z,p->Z);
|
||||
}
|
14
vendor/MDBC/plugins/auth/ref10/ge_p3_tobytes.c
vendored
Normal file
14
vendor/MDBC/plugins/auth/ref10/ge_p3_tobytes.c
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
#include "ge.h"
|
||||
|
||||
void ge_p3_tobytes(unsigned char *s,const ge_p3 *h)
|
||||
{
|
||||
fe recip;
|
||||
fe x;
|
||||
fe y;
|
||||
|
||||
fe_invert(recip,h->Z);
|
||||
fe_mul(x,h->X,recip);
|
||||
fe_mul(y,h->Y,recip);
|
||||
fe_tobytes(s,y);
|
||||
s[31] ^= fe_isnegative(x) << 7;
|
||||
}
|
8
vendor/MDBC/plugins/auth/ref10/ge_precomp_0.c
vendored
Normal file
8
vendor/MDBC/plugins/auth/ref10/ge_precomp_0.c
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
#include "ge.h"
|
||||
|
||||
void ge_precomp_0(ge_precomp *h)
|
||||
{
|
||||
fe_1(h->yplusx);
|
||||
fe_1(h->yminusx);
|
||||
fe_0(h->xy2d);
|
||||
}
|
105
vendor/MDBC/plugins/auth/ref10/ge_scalarmult_base.c
vendored
Normal file
105
vendor/MDBC/plugins/auth/ref10/ge_scalarmult_base.c
vendored
Normal file
@ -0,0 +1,105 @@
|
||||
#include "ge.h"
|
||||
#include "crypto_uint32.h"
|
||||
|
||||
static unsigned char equal(signed char b,signed char c)
|
||||
{
|
||||
unsigned char ub = b;
|
||||
unsigned char uc = c;
|
||||
unsigned char x = ub ^ uc; /* 0: yes; 1..255: no */
|
||||
crypto_uint32 y = x; /* 0: yes; 1..255: no */
|
||||
y -= 1; /* 4294967295: yes; 0..254: no */
|
||||
y >>= 31; /* 1: yes; 0: no */
|
||||
return y;
|
||||
}
|
||||
|
||||
static unsigned char negative(signed char b)
|
||||
{
|
||||
unsigned long long x = b; /* 18446744073709551361..18446744073709551615: yes; 0..255: no */
|
||||
x >>= 63; /* 1: yes; 0: no */
|
||||
return x;
|
||||
}
|
||||
|
||||
static void cmov(ge_precomp *t,ge_precomp *u,unsigned char b)
|
||||
{
|
||||
fe_cmov(t->yplusx,u->yplusx,b);
|
||||
fe_cmov(t->yminusx,u->yminusx,b);
|
||||
fe_cmov(t->xy2d,u->xy2d,b);
|
||||
}
|
||||
|
||||
/* base[i][j] = (j+1)*256^i*B */
|
||||
static ge_precomp base[32][8] = {
|
||||
#include "base.h"
|
||||
} ;
|
||||
|
||||
static void select(ge_precomp *t,int pos,signed char b)
|
||||
{
|
||||
ge_precomp minust;
|
||||
unsigned char bnegative = negative(b);
|
||||
unsigned char babs = b - (((-bnegative) & b) << 1);
|
||||
|
||||
ge_precomp_0(t);
|
||||
cmov(t,&base[pos][0],equal(babs,1));
|
||||
cmov(t,&base[pos][1],equal(babs,2));
|
||||
cmov(t,&base[pos][2],equal(babs,3));
|
||||
cmov(t,&base[pos][3],equal(babs,4));
|
||||
cmov(t,&base[pos][4],equal(babs,5));
|
||||
cmov(t,&base[pos][5],equal(babs,6));
|
||||
cmov(t,&base[pos][6],equal(babs,7));
|
||||
cmov(t,&base[pos][7],equal(babs,8));
|
||||
fe_copy(minust.yplusx,t->yminusx);
|
||||
fe_copy(minust.yminusx,t->yplusx);
|
||||
fe_neg(minust.xy2d,t->xy2d);
|
||||
cmov(t,&minust,bnegative);
|
||||
}
|
||||
|
||||
/*
|
||||
h = a * B
|
||||
where a = a[0]+256*a[1]+...+256^31 a[31]
|
||||
B is the Ed25519 base point (x,4/5) with x positive.
|
||||
|
||||
Preconditions:
|
||||
a[31] <= 127
|
||||
*/
|
||||
|
||||
void ge_scalarmult_base(ge_p3 *h,const unsigned char *a)
|
||||
{
|
||||
signed char e[64];
|
||||
signed char carry;
|
||||
ge_p1p1 r;
|
||||
ge_p2 s;
|
||||
ge_precomp t;
|
||||
int i;
|
||||
|
||||
for (i = 0;i < 32;++i) {
|
||||
e[2 * i + 0] = (a[i] >> 0) & 15;
|
||||
e[2 * i + 1] = (a[i] >> 4) & 15;
|
||||
}
|
||||
/* each e[i] is between 0 and 15 */
|
||||
/* e[63] is between 0 and 7 */
|
||||
|
||||
carry = 0;
|
||||
for (i = 0;i < 63;++i) {
|
||||
e[i] += carry;
|
||||
carry = e[i] + 8;
|
||||
carry >>= 4;
|
||||
e[i] -= carry << 4;
|
||||
}
|
||||
e[63] += carry;
|
||||
/* each e[i] is between -8 and 8 */
|
||||
|
||||
ge_p3_0(h);
|
||||
for (i = 1;i < 64;i += 2) {
|
||||
select(&t,i / 2,e[i]);
|
||||
ge_madd(&r,h,&t); ge_p1p1_to_p3(h,&r);
|
||||
}
|
||||
|
||||
ge_p3_dbl(&r,h); ge_p1p1_to_p2(&s,&r);
|
||||
ge_p2_dbl(&r,&s); ge_p1p1_to_p2(&s,&r);
|
||||
ge_p2_dbl(&r,&s); ge_p1p1_to_p2(&s,&r);
|
||||
ge_p2_dbl(&r,&s); ge_p1p1_to_p3(h,&r);
|
||||
|
||||
for (i = 0;i < 64;i += 2) {
|
||||
select(&t,i / 2,e[i]);
|
||||
ge_madd(&r,h,&t); ge_p1p1_to_p3(h,&r);
|
||||
}
|
||||
}
|
11
vendor/MDBC/plugins/auth/ref10/ge_sub.c
vendored
Normal file
11
vendor/MDBC/plugins/auth/ref10/ge_sub.c
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
#include "ge.h"
|
||||
|
||||
/*
|
||||
r = p - q
|
||||
*/
|
||||
|
||||
void ge_sub(ge_p1p1 *r,const ge_p3 *p,const ge_cached *q)
|
||||
{
|
||||
fe t0;
|
||||
#include "ge_sub.h"
|
||||
}
|
97
vendor/MDBC/plugins/auth/ref10/ge_sub.h
vendored
Normal file
97
vendor/MDBC/plugins/auth/ref10/ge_sub.h
vendored
Normal file
@ -0,0 +1,97 @@
|
||||
|
||||
/* qhasm: enter ge_sub */
|
||||
|
||||
/* qhasm: fe X1 */
|
||||
|
||||
/* qhasm: fe Y1 */
|
||||
|
||||
/* qhasm: fe Z1 */
|
||||
|
||||
/* qhasm: fe Z2 */
|
||||
|
||||
/* qhasm: fe T1 */
|
||||
|
||||
/* qhasm: fe ZZ */
|
||||
|
||||
/* qhasm: fe YpX2 */
|
||||
|
||||
/* qhasm: fe YmX2 */
|
||||
|
||||
/* qhasm: fe T2d2 */
|
||||
|
||||
/* qhasm: fe X3 */
|
||||
|
||||
/* qhasm: fe Y3 */
|
||||
|
||||
/* qhasm: fe Z3 */
|
||||
|
||||
/* qhasm: fe T3 */
|
||||
|
||||
/* qhasm: fe YpX1 */
|
||||
|
||||
/* qhasm: fe YmX1 */
|
||||
|
||||
/* qhasm: fe A */
|
||||
|
||||
/* qhasm: fe B */
|
||||
|
||||
/* qhasm: fe C */
|
||||
|
||||
/* qhasm: fe D */
|
||||
|
||||
/* qhasm: YpX1 = Y1+X1 */
|
||||
/* asm 1: fe_add(>YpX1=fe#1,<Y1=fe#12,<X1=fe#11); */
|
||||
/* asm 2: fe_add(>YpX1=r->X,<Y1=p->Y,<X1=p->X); */
|
||||
fe_add(r->X,p->Y,p->X);
|
||||
|
||||
/* qhasm: YmX1 = Y1-X1 */
|
||||
/* asm 1: fe_sub(>YmX1=fe#2,<Y1=fe#12,<X1=fe#11); */
|
||||
/* asm 2: fe_sub(>YmX1=r->Y,<Y1=p->Y,<X1=p->X); */
|
||||
fe_sub(r->Y,p->Y,p->X);
|
||||
|
||||
/* qhasm: A = YpX1*YmX2 */
|
||||
/* asm 1: fe_mul(>A=fe#3,<YpX1=fe#1,<YmX2=fe#16); */
|
||||
/* asm 2: fe_mul(>A=r->Z,<YpX1=r->X,<YmX2=q->YminusX); */
|
||||
fe_mul(r->Z,r->X,q->YminusX);
|
||||
|
||||
/* qhasm: B = YmX1*YpX2 */
|
||||
/* asm 1: fe_mul(>B=fe#2,<YmX1=fe#2,<YpX2=fe#15); */
|
||||
/* asm 2: fe_mul(>B=r->Y,<YmX1=r->Y,<YpX2=q->YplusX); */
|
||||
fe_mul(r->Y,r->Y,q->YplusX);
|
||||
|
||||
/* qhasm: C = T2d2*T1 */
|
||||
/* asm 1: fe_mul(>C=fe#4,<T2d2=fe#18,<T1=fe#14); */
|
||||
/* asm 2: fe_mul(>C=r->T,<T2d2=q->T2d,<T1=p->T); */
|
||||
fe_mul(r->T,q->T2d,p->T);
|
||||
|
||||
/* qhasm: ZZ = Z1*Z2 */
|
||||
/* asm 1: fe_mul(>ZZ=fe#1,<Z1=fe#13,<Z2=fe#17); */
|
||||
/* asm 2: fe_mul(>ZZ=r->X,<Z1=p->Z,<Z2=q->Z); */
|
||||
fe_mul(r->X,p->Z,q->Z);
|
||||
|
||||
/* qhasm: D = 2*ZZ */
|
||||
/* asm 1: fe_add(>D=fe#5,<ZZ=fe#1,<ZZ=fe#1); */
|
||||
/* asm 2: fe_add(>D=t0,<ZZ=r->X,<ZZ=r->X); */
|
||||
fe_add(t0,r->X,r->X);
|
||||
|
||||
/* qhasm: X3 = A-B */
|
||||
/* asm 1: fe_sub(>X3=fe#1,<A=fe#3,<B=fe#2); */
|
||||
/* asm 2: fe_sub(>X3=r->X,<A=r->Z,<B=r->Y); */
|
||||
fe_sub(r->X,r->Z,r->Y);
|
||||
|
||||
/* qhasm: Y3 = A+B */
|
||||
/* asm 1: fe_add(>Y3=fe#2,<A=fe#3,<B=fe#2); */
|
||||
/* asm 2: fe_add(>Y3=r->Y,<A=r->Z,<B=r->Y); */
|
||||
fe_add(r->Y,r->Z,r->Y);
|
||||
|
||||
/* qhasm: Z3 = D-C */
|
||||
/* asm 1: fe_sub(>Z3=fe#3,<D=fe#5,<C=fe#4); */
|
||||
/* asm 2: fe_sub(>Z3=r->Z,<D=t0,<C=r->T); */
|
||||
fe_sub(r->Z,t0,r->T);
|
||||
|
||||
/* qhasm: T3 = D+C */
|
||||
/* asm 1: fe_add(>T3=fe#4,<D=fe#5,<C=fe#4); */
|
||||
/* asm 2: fe_add(>T3=r->T,<D=t0,<C=r->T); */
|
||||
fe_add(r->T,t0,r->T);
|
||||
|
||||
/* qhasm: return */
|
14
vendor/MDBC/plugins/auth/ref10/ge_tobytes.c
vendored
Normal file
14
vendor/MDBC/plugins/auth/ref10/ge_tobytes.c
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
#include "ge.h"
|
||||
|
||||
void ge_tobytes(unsigned char *s,const ge_p2 *h)
|
||||
{
|
||||
fe recip;
|
||||
fe x;
|
||||
fe y;
|
||||
|
||||
fe_invert(recip,h->Z);
|
||||
fe_mul(x,h->X,recip);
|
||||
fe_mul(y,h->Y,recip);
|
||||
fe_tobytes(s,y);
|
||||
s[31] ^= fe_isnegative(x) << 7;
|
||||
}
|
23
vendor/MDBC/plugins/auth/ref10/keypair.c
vendored
Normal file
23
vendor/MDBC/plugins/auth/ref10/keypair.c
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
#include <string.h>
|
||||
#include "crypto_sign.h"
|
||||
#include "crypto_hash_sha512.h"
|
||||
#include "ge.h"
|
||||
|
||||
int crypto_sign_keypair(
|
||||
unsigned char *pk,
|
||||
unsigned char *pw, unsigned long long pwlen
|
||||
)
|
||||
{
|
||||
unsigned char az[64];
|
||||
ge_p3 A;
|
||||
|
||||
crypto_hash_sha512(az,pw,pwlen);
|
||||
az[0] &= 248;
|
||||
az[31] &= 63;
|
||||
az[31] |= 64;
|
||||
|
||||
ge_scalarmult_base(&A,az);
|
||||
ge_p3_tobytes(pk,&A);
|
||||
|
||||
return 0;
|
||||
}
|
36
vendor/MDBC/plugins/auth/ref10/open.c
vendored
Normal file
36
vendor/MDBC/plugins/auth/ref10/open.c
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
#include <string.h>
|
||||
#include "crypto_sign.h"
|
||||
#include "crypto_hash_sha512.h"
|
||||
#include "crypto_verify_32.h"
|
||||
#include "ge.h"
|
||||
#include "sc.h"
|
||||
|
||||
int crypto_sign_open(
|
||||
unsigned char *sm, unsigned long long smlen,
|
||||
const unsigned char *pk
|
||||
)
|
||||
{
|
||||
unsigned char scopy[32];
|
||||
unsigned char h[64];
|
||||
unsigned char rcheck[32];
|
||||
ge_p3 A;
|
||||
ge_p2 R;
|
||||
|
||||
if (smlen < 64) goto badsig;
|
||||
if (sm[63] & 224) goto badsig;
|
||||
if (ge_frombytes_negate_vartime(&A,pk) != 0) goto badsig;
|
||||
|
||||
memmove(scopy,sm + 32,32);
|
||||
|
||||
memmove(sm + 32,pk,32);
|
||||
crypto_hash_sha512(h,sm,smlen);
|
||||
sc_reduce(h);
|
||||
|
||||
ge_double_scalarmult_vartime(&R,h,&A,scopy);
|
||||
ge_tobytes(rcheck,&R);
|
||||
if (crypto_verify_32(rcheck,sm) == 0)
|
||||
return 0;
|
||||
|
||||
badsig:
|
||||
return -1;
|
||||
}
|
168
vendor/MDBC/plugins/auth/ref10/pow22523.h
vendored
Normal file
168
vendor/MDBC/plugins/auth/ref10/pow22523.h
vendored
Normal file
@ -0,0 +1,168 @@
|
||||
|
||||
/* qhasm: fe z1 */
|
||||
|
||||
/* qhasm: fe z2 */
|
||||
|
||||
/* qhasm: fe z8 */
|
||||
|
||||
/* qhasm: fe z9 */
|
||||
|
||||
/* qhasm: fe z11 */
|
||||
|
||||
/* qhasm: fe z22 */
|
||||
|
||||
/* qhasm: fe z_5_0 */
|
||||
|
||||
/* qhasm: fe z_10_5 */
|
||||
|
||||
/* qhasm: fe z_10_0 */
|
||||
|
||||
/* qhasm: fe z_20_10 */
|
||||
|
||||
/* qhasm: fe z_20_0 */
|
||||
|
||||
/* qhasm: fe z_40_20 */
|
||||
|
||||
/* qhasm: fe z_40_0 */
|
||||
|
||||
/* qhasm: fe z_50_10 */
|
||||
|
||||
/* qhasm: fe z_50_0 */
|
||||
|
||||
/* qhasm: fe z_100_50 */
|
||||
|
||||
/* qhasm: fe z_100_0 */
|
||||
|
||||
/* qhasm: fe z_200_100 */
|
||||
|
||||
/* qhasm: fe z_200_0 */
|
||||
|
||||
/* qhasm: fe z_250_50 */
|
||||
|
||||
/* qhasm: fe z_250_0 */
|
||||
|
||||
/* qhasm: fe z_252_2 */
|
||||
|
||||
/* qhasm: fe z_252_3 */
|
||||
|
||||
/* qhasm: enter pow22523 */
|
||||
|
||||
/* qhasm: z2 = z1^2^1 */
|
||||
/* asm 1: fe_sq(>z2=fe#1,<z1=fe#11); for (i = 1;i < 1;++i) fe_sq(>z2=fe#1,>z2=fe#1); */
|
||||
/* asm 2: fe_sq(>z2=t0,<z1=z); for (i = 1;i < 1;++i) fe_sq(>z2=t0,>z2=t0); */
|
||||
fe_sq(t0,z);
|
||||
|
||||
/* covscan CWE-561 dead code: variable i can't be < 1
|
||||
for (i = 1;i < 1;++i) fe_sq(t0,t0);
|
||||
*/
|
||||
|
||||
/* qhasm: z8 = z2^2^2 */
|
||||
/* asm 1: fe_sq(>z8=fe#2,<z2=fe#1); for (i = 1;i < 2;++i) fe_sq(>z8=fe#2,>z8=fe#2); */
|
||||
/* asm 2: fe_sq(>z8=t1,<z2=t0); for (i = 1;i < 2;++i) fe_sq(>z8=t1,>z8=t1); */
|
||||
fe_sq(t1,t0); for (i = 1;i < 2;++i) fe_sq(t1,t1);
|
||||
|
||||
/* qhasm: z9 = z1*z8 */
|
||||
/* asm 1: fe_mul(>z9=fe#2,<z1=fe#11,<z8=fe#2); */
|
||||
/* asm 2: fe_mul(>z9=t1,<z1=z,<z8=t1); */
|
||||
fe_mul(t1,z,t1);
|
||||
|
||||
/* qhasm: z11 = z2*z9 */
|
||||
/* asm 1: fe_mul(>z11=fe#1,<z2=fe#1,<z9=fe#2); */
|
||||
/* asm 2: fe_mul(>z11=t0,<z2=t0,<z9=t1); */
|
||||
fe_mul(t0,t0,t1);
|
||||
|
||||
/* qhasm: z22 = z11^2^1 */
|
||||
/* asm 1: fe_sq(>z22=fe#1,<z11=fe#1); for (i = 1;i < 1;++i) fe_sq(>z22=fe#1,>z22=fe#1); */
|
||||
/* asm 2: fe_sq(>z22=t0,<z11=t0); for (i = 1;i < 1;++i) fe_sq(>z22=t0,>z22=t0); */
|
||||
fe_sq(t0,t0);
|
||||
|
||||
/* covscan CWE-561 dead code: variable i can't be < 1
|
||||
for (i = 1;i < 1;++i) fe_sq(t0,t0);
|
||||
*/
|
||||
|
||||
/* qhasm: z_5_0 = z9*z22 */
|
||||
/* asm 1: fe_mul(>z_5_0=fe#1,<z9=fe#2,<z22=fe#1); */
|
||||
/* asm 2: fe_mul(>z_5_0=t0,<z9=t1,<z22=t0); */
|
||||
fe_mul(t0,t1,t0);
|
||||
|
||||
/* qhasm: z_10_5 = z_5_0^2^5 */
|
||||
/* asm 1: fe_sq(>z_10_5=fe#2,<z_5_0=fe#1); for (i = 1;i < 5;++i) fe_sq(>z_10_5=fe#2,>z_10_5=fe#2); */
|
||||
/* asm 2: fe_sq(>z_10_5=t1,<z_5_0=t0); for (i = 1;i < 5;++i) fe_sq(>z_10_5=t1,>z_10_5=t1); */
|
||||
fe_sq(t1,t0); for (i = 1;i < 5;++i) fe_sq(t1,t1);
|
||||
|
||||
/* qhasm: z_10_0 = z_10_5*z_5_0 */
|
||||
/* asm 1: fe_mul(>z_10_0=fe#1,<z_10_5=fe#2,<z_5_0=fe#1); */
|
||||
/* asm 2: fe_mul(>z_10_0=t0,<z_10_5=t1,<z_5_0=t0); */
|
||||
fe_mul(t0,t1,t0);
|
||||
|
||||
/* qhasm: z_20_10 = z_10_0^2^10 */
|
||||
/* asm 1: fe_sq(>z_20_10=fe#2,<z_10_0=fe#1); for (i = 1;i < 10;++i) fe_sq(>z_20_10=fe#2,>z_20_10=fe#2); */
|
||||
/* asm 2: fe_sq(>z_20_10=t1,<z_10_0=t0); for (i = 1;i < 10;++i) fe_sq(>z_20_10=t1,>z_20_10=t1); */
|
||||
fe_sq(t1,t0); for (i = 1;i < 10;++i) fe_sq(t1,t1);
|
||||
|
||||
/* qhasm: z_20_0 = z_20_10*z_10_0 */
|
||||
/* asm 1: fe_mul(>z_20_0=fe#2,<z_20_10=fe#2,<z_10_0=fe#1); */
|
||||
/* asm 2: fe_mul(>z_20_0=t1,<z_20_10=t1,<z_10_0=t0); */
|
||||
fe_mul(t1,t1,t0);
|
||||
|
||||
/* qhasm: z_40_20 = z_20_0^2^20 */
|
||||
/* asm 1: fe_sq(>z_40_20=fe#3,<z_20_0=fe#2); for (i = 1;i < 20;++i) fe_sq(>z_40_20=fe#3,>z_40_20=fe#3); */
|
||||
/* asm 2: fe_sq(>z_40_20=t2,<z_20_0=t1); for (i = 1;i < 20;++i) fe_sq(>z_40_20=t2,>z_40_20=t2); */
|
||||
fe_sq(t2,t1); for (i = 1;i < 20;++i) fe_sq(t2,t2);
|
||||
|
||||
/* qhasm: z_40_0 = z_40_20*z_20_0 */
|
||||
/* asm 1: fe_mul(>z_40_0=fe#2,<z_40_20=fe#3,<z_20_0=fe#2); */
|
||||
/* asm 2: fe_mul(>z_40_0=t1,<z_40_20=t2,<z_20_0=t1); */
|
||||
fe_mul(t1,t2,t1);
|
||||
|
||||
/* qhasm: z_50_10 = z_40_0^2^10 */
|
||||
/* asm 1: fe_sq(>z_50_10=fe#2,<z_40_0=fe#2); for (i = 1;i < 10;++i) fe_sq(>z_50_10=fe#2,>z_50_10=fe#2); */
|
||||
/* asm 2: fe_sq(>z_50_10=t1,<z_40_0=t1); for (i = 1;i < 10;++i) fe_sq(>z_50_10=t1,>z_50_10=t1); */
|
||||
fe_sq(t1,t1); for (i = 1;i < 10;++i) fe_sq(t1,t1);
|
||||
|
||||
/* qhasm: z_50_0 = z_50_10*z_10_0 */
|
||||
/* asm 1: fe_mul(>z_50_0=fe#1,<z_50_10=fe#2,<z_10_0=fe#1); */
|
||||
/* asm 2: fe_mul(>z_50_0=t0,<z_50_10=t1,<z_10_0=t0); */
|
||||
fe_mul(t0,t1,t0);
|
||||
|
||||
/* qhasm: z_100_50 = z_50_0^2^50 */
|
||||
/* asm 1: fe_sq(>z_100_50=fe#2,<z_50_0=fe#1); for (i = 1;i < 50;++i) fe_sq(>z_100_50=fe#2,>z_100_50=fe#2); */
|
||||
/* asm 2: fe_sq(>z_100_50=t1,<z_50_0=t0); for (i = 1;i < 50;++i) fe_sq(>z_100_50=t1,>z_100_50=t1); */
|
||||
fe_sq(t1,t0); for (i = 1;i < 50;++i) fe_sq(t1,t1);
|
||||
|
||||
/* qhasm: z_100_0 = z_100_50*z_50_0 */
|
||||
/* asm 1: fe_mul(>z_100_0=fe#2,<z_100_50=fe#2,<z_50_0=fe#1); */
|
||||
/* asm 2: fe_mul(>z_100_0=t1,<z_100_50=t1,<z_50_0=t0); */
|
||||
fe_mul(t1,t1,t0);
|
||||
|
||||
/* qhasm: z_200_100 = z_100_0^2^100 */
|
||||
/* asm 1: fe_sq(>z_200_100=fe#3,<z_100_0=fe#2); for (i = 1;i < 100;++i) fe_sq(>z_200_100=fe#3,>z_200_100=fe#3); */
|
||||
/* asm 2: fe_sq(>z_200_100=t2,<z_100_0=t1); for (i = 1;i < 100;++i) fe_sq(>z_200_100=t2,>z_200_100=t2); */
|
||||
fe_sq(t2,t1); for (i = 1;i < 100;++i) fe_sq(t2,t2);
|
||||
|
||||
/* qhasm: z_200_0 = z_200_100*z_100_0 */
|
||||
/* asm 1: fe_mul(>z_200_0=fe#2,<z_200_100=fe#3,<z_100_0=fe#2); */
|
||||
/* asm 2: fe_mul(>z_200_0=t1,<z_200_100=t2,<z_100_0=t1); */
|
||||
fe_mul(t1,t2,t1);
|
||||
|
||||
/* qhasm: z_250_50 = z_200_0^2^50 */
|
||||
/* asm 1: fe_sq(>z_250_50=fe#2,<z_200_0=fe#2); for (i = 1;i < 50;++i) fe_sq(>z_250_50=fe#2,>z_250_50=fe#2); */
|
||||
/* asm 2: fe_sq(>z_250_50=t1,<z_200_0=t1); for (i = 1;i < 50;++i) fe_sq(>z_250_50=t1,>z_250_50=t1); */
|
||||
fe_sq(t1,t1); for (i = 1;i < 50;++i) fe_sq(t1,t1);
|
||||
|
||||
/* qhasm: z_250_0 = z_250_50*z_50_0 */
|
||||
/* asm 1: fe_mul(>z_250_0=fe#1,<z_250_50=fe#2,<z_50_0=fe#1); */
|
||||
/* asm 2: fe_mul(>z_250_0=t0,<z_250_50=t1,<z_50_0=t0); */
|
||||
fe_mul(t0,t1,t0);
|
||||
|
||||
/* qhasm: z_252_2 = z_250_0^2^2 */
|
||||
/* asm 1: fe_sq(>z_252_2=fe#1,<z_250_0=fe#1); for (i = 1;i < 2;++i) fe_sq(>z_252_2=fe#1,>z_252_2=fe#1); */
|
||||
/* asm 2: fe_sq(>z_252_2=t0,<z_250_0=t0); for (i = 1;i < 2;++i) fe_sq(>z_252_2=t0,>z_252_2=t0); */
|
||||
fe_sq(t0,t0); for (i = 1;i < 2;++i) fe_sq(t0,t0);
|
||||
|
||||
/* qhasm: z_252_3 = z_252_2*z1 */
|
||||
/* asm 1: fe_mul(>z_252_3=fe#12,<z_252_2=fe#1,<z1=fe#11); */
|
||||
/* asm 2: fe_mul(>z_252_3=out,<z_252_2=t0,<z1=z); */
|
||||
fe_mul(out,t0,z);
|
||||
|
||||
/* qhasm: return */
|
166
vendor/MDBC/plugins/auth/ref10/pow225521.h
vendored
Normal file
166
vendor/MDBC/plugins/auth/ref10/pow225521.h
vendored
Normal file
@ -0,0 +1,166 @@
|
||||
|
||||
/* qhasm: fe z1 */
|
||||
|
||||
/* qhasm: fe z2 */
|
||||
|
||||
/* qhasm: fe z8 */
|
||||
|
||||
/* qhasm: fe z9 */
|
||||
|
||||
/* qhasm: fe z11 */
|
||||
|
||||
/* qhasm: fe z22 */
|
||||
|
||||
/* qhasm: fe z_5_0 */
|
||||
|
||||
/* qhasm: fe z_10_5 */
|
||||
|
||||
/* qhasm: fe z_10_0 */
|
||||
|
||||
/* qhasm: fe z_20_10 */
|
||||
|
||||
/* qhasm: fe z_20_0 */
|
||||
|
||||
/* qhasm: fe z_40_20 */
|
||||
|
||||
/* qhasm: fe z_40_0 */
|
||||
|
||||
/* qhasm: fe z_50_10 */
|
||||
|
||||
/* qhasm: fe z_50_0 */
|
||||
|
||||
/* qhasm: fe z_100_50 */
|
||||
|
||||
/* qhasm: fe z_100_0 */
|
||||
|
||||
/* qhasm: fe z_200_100 */
|
||||
|
||||
/* qhasm: fe z_200_0 */
|
||||
|
||||
/* qhasm: fe z_250_50 */
|
||||
|
||||
/* qhasm: fe z_250_0 */
|
||||
|
||||
/* qhasm: fe z_255_5 */
|
||||
|
||||
/* qhasm: fe z_255_21 */
|
||||
|
||||
/* qhasm: enter pow225521 */
|
||||
|
||||
/* qhasm: z2 = z1^2^1 */
|
||||
/* asm 1: fe_sq(>z2=fe#1,<z1=fe#11); for (i = 1;i < 1;++i) fe_sq(>z2=fe#1,>z2=fe#1); */
|
||||
/* asm 2: fe_sq(>z2=t0,<z1=z); for (i = 1;i < 1;++i) fe_sq(>z2=t0,>z2=t0); */
|
||||
fe_sq(t0,z);
|
||||
/* covscan CWE-561 dead code: variable i can't be < 1
|
||||
for (i = 1;i < 1;++i) fe_sq(t0,t0);
|
||||
*/
|
||||
|
||||
/* qhasm: z8 = z2^2^2 */
|
||||
/* asm 1: fe_sq(>z8=fe#2,<z2=fe#1); for (i = 1;i < 2;++i) fe_sq(>z8=fe#2,>z8=fe#2); */
|
||||
/* asm 2: fe_sq(>z8=t1,<z2=t0); for (i = 1;i < 2;++i) fe_sq(>z8=t1,>z8=t1); */
|
||||
fe_sq(t1,t0); for (i = 1;i < 2;++i) fe_sq(t1,t1);
|
||||
|
||||
/* qhasm: z9 = z1*z8 */
|
||||
/* asm 1: fe_mul(>z9=fe#2,<z1=fe#11,<z8=fe#2); */
|
||||
/* asm 2: fe_mul(>z9=t1,<z1=z,<z8=t1); */
|
||||
fe_mul(t1,z,t1);
|
||||
|
||||
/* qhasm: z11 = z2*z9 */
|
||||
/* asm 1: fe_mul(>z11=fe#1,<z2=fe#1,<z9=fe#2); */
|
||||
/* asm 2: fe_mul(>z11=t0,<z2=t0,<z9=t1); */
|
||||
fe_mul(t0,t0,t1);
|
||||
|
||||
/* qhasm: z22 = z11^2^1 */
|
||||
/* asm 1: fe_sq(>z22=fe#3,<z11=fe#1); for (i = 1;i < 1;++i) fe_sq(>z22=fe#3,>z22=fe#3); */
|
||||
/* asm 2: fe_sq(>z22=t2,<z11=t0); for (i = 1;i < 1;++i) fe_sq(>z22=t2,>z22=t2); */
|
||||
fe_sq(t2,t0);
|
||||
/* covscan CWE-561 dead code: variable i can't be < 1
|
||||
for (i = 1;i < 1;++i) fe_sq(t2,t2);
|
||||
*/
|
||||
|
||||
/* qhasm: z_5_0 = z9*z22 */
|
||||
/* asm 1: fe_mul(>z_5_0=fe#2,<z9=fe#2,<z22=fe#3); */
|
||||
/* asm 2: fe_mul(>z_5_0=t1,<z9=t1,<z22=t2); */
|
||||
fe_mul(t1,t1,t2);
|
||||
|
||||
/* qhasm: z_10_5 = z_5_0^2^5 */
|
||||
/* asm 1: fe_sq(>z_10_5=fe#3,<z_5_0=fe#2); for (i = 1;i < 5;++i) fe_sq(>z_10_5=fe#3,>z_10_5=fe#3); */
|
||||
/* asm 2: fe_sq(>z_10_5=t2,<z_5_0=t1); for (i = 1;i < 5;++i) fe_sq(>z_10_5=t2,>z_10_5=t2); */
|
||||
fe_sq(t2,t1); for (i = 1;i < 5;++i) fe_sq(t2,t2);
|
||||
|
||||
/* qhasm: z_10_0 = z_10_5*z_5_0 */
|
||||
/* asm 1: fe_mul(>z_10_0=fe#2,<z_10_5=fe#3,<z_5_0=fe#2); */
|
||||
/* asm 2: fe_mul(>z_10_0=t1,<z_10_5=t2,<z_5_0=t1); */
|
||||
fe_mul(t1,t2,t1);
|
||||
|
||||
/* qhasm: z_20_10 = z_10_0^2^10 */
|
||||
/* asm 1: fe_sq(>z_20_10=fe#3,<z_10_0=fe#2); for (i = 1;i < 10;++i) fe_sq(>z_20_10=fe#3,>z_20_10=fe#3); */
|
||||
/* asm 2: fe_sq(>z_20_10=t2,<z_10_0=t1); for (i = 1;i < 10;++i) fe_sq(>z_20_10=t2,>z_20_10=t2); */
|
||||
fe_sq(t2,t1); for (i = 1;i < 10;++i) fe_sq(t2,t2);
|
||||
|
||||
/* qhasm: z_20_0 = z_20_10*z_10_0 */
|
||||
/* asm 1: fe_mul(>z_20_0=fe#3,<z_20_10=fe#3,<z_10_0=fe#2); */
|
||||
/* asm 2: fe_mul(>z_20_0=t2,<z_20_10=t2,<z_10_0=t1); */
|
||||
fe_mul(t2,t2,t1);
|
||||
|
||||
/* qhasm: z_40_20 = z_20_0^2^20 */
|
||||
/* asm 1: fe_sq(>z_40_20=fe#4,<z_20_0=fe#3); for (i = 1;i < 20;++i) fe_sq(>z_40_20=fe#4,>z_40_20=fe#4); */
|
||||
/* asm 2: fe_sq(>z_40_20=t3,<z_20_0=t2); for (i = 1;i < 20;++i) fe_sq(>z_40_20=t3,>z_40_20=t3); */
|
||||
fe_sq(t3,t2); for (i = 1;i < 20;++i) fe_sq(t3,t3);
|
||||
|
||||
/* qhasm: z_40_0 = z_40_20*z_20_0 */
|
||||
/* asm 1: fe_mul(>z_40_0=fe#3,<z_40_20=fe#4,<z_20_0=fe#3); */
|
||||
/* asm 2: fe_mul(>z_40_0=t2,<z_40_20=t3,<z_20_0=t2); */
|
||||
fe_mul(t2,t3,t2);
|
||||
|
||||
/* qhasm: z_50_10 = z_40_0^2^10 */
|
||||
/* asm 1: fe_sq(>z_50_10=fe#3,<z_40_0=fe#3); for (i = 1;i < 10;++i) fe_sq(>z_50_10=fe#3,>z_50_10=fe#3); */
|
||||
/* asm 2: fe_sq(>z_50_10=t2,<z_40_0=t2); for (i = 1;i < 10;++i) fe_sq(>z_50_10=t2,>z_50_10=t2); */
|
||||
fe_sq(t2,t2); for (i = 1;i < 10;++i) fe_sq(t2,t2);
|
||||
|
||||
/* qhasm: z_50_0 = z_50_10*z_10_0 */
|
||||
/* asm 1: fe_mul(>z_50_0=fe#2,<z_50_10=fe#3,<z_10_0=fe#2); */
|
||||
/* asm 2: fe_mul(>z_50_0=t1,<z_50_10=t2,<z_10_0=t1); */
|
||||
fe_mul(t1,t2,t1);
|
||||
|
||||
/* qhasm: z_100_50 = z_50_0^2^50 */
|
||||
/* asm 1: fe_sq(>z_100_50=fe#3,<z_50_0=fe#2); for (i = 1;i < 50;++i) fe_sq(>z_100_50=fe#3,>z_100_50=fe#3); */
|
||||
/* asm 2: fe_sq(>z_100_50=t2,<z_50_0=t1); for (i = 1;i < 50;++i) fe_sq(>z_100_50=t2,>z_100_50=t2); */
|
||||
fe_sq(t2,t1); for (i = 1;i < 50;++i) fe_sq(t2,t2);
|
||||
|
||||
/* qhasm: z_100_0 = z_100_50*z_50_0 */
|
||||
/* asm 1: fe_mul(>z_100_0=fe#3,<z_100_50=fe#3,<z_50_0=fe#2); */
|
||||
/* asm 2: fe_mul(>z_100_0=t2,<z_100_50=t2,<z_50_0=t1); */
|
||||
fe_mul(t2,t2,t1);
|
||||
|
||||
/* qhasm: z_200_100 = z_100_0^2^100 */
|
||||
/* asm 1: fe_sq(>z_200_100=fe#4,<z_100_0=fe#3); for (i = 1;i < 100;++i) fe_sq(>z_200_100=fe#4,>z_200_100=fe#4); */
|
||||
/* asm 2: fe_sq(>z_200_100=t3,<z_100_0=t2); for (i = 1;i < 100;++i) fe_sq(>z_200_100=t3,>z_200_100=t3); */
|
||||
fe_sq(t3,t2); for (i = 1;i < 100;++i) fe_sq(t3,t3);
|
||||
|
||||
/* qhasm: z_200_0 = z_200_100*z_100_0 */
|
||||
/* asm 1: fe_mul(>z_200_0=fe#3,<z_200_100=fe#4,<z_100_0=fe#3); */
|
||||
/* asm 2: fe_mul(>z_200_0=t2,<z_200_100=t3,<z_100_0=t2); */
|
||||
fe_mul(t2,t3,t2);
|
||||
|
||||
/* qhasm: z_250_50 = z_200_0^2^50 */
|
||||
/* asm 1: fe_sq(>z_250_50=fe#3,<z_200_0=fe#3); for (i = 1;i < 50;++i) fe_sq(>z_250_50=fe#3,>z_250_50=fe#3); */
|
||||
/* asm 2: fe_sq(>z_250_50=t2,<z_200_0=t2); for (i = 1;i < 50;++i) fe_sq(>z_250_50=t2,>z_250_50=t2); */
|
||||
fe_sq(t2,t2); for (i = 1;i < 50;++i) fe_sq(t2,t2);
|
||||
|
||||
/* qhasm: z_250_0 = z_250_50*z_50_0 */
|
||||
/* asm 1: fe_mul(>z_250_0=fe#2,<z_250_50=fe#3,<z_50_0=fe#2); */
|
||||
/* asm 2: fe_mul(>z_250_0=t1,<z_250_50=t2,<z_50_0=t1); */
|
||||
fe_mul(t1,t2,t1);
|
||||
|
||||
/* qhasm: z_255_5 = z_250_0^2^5 */
|
||||
/* asm 1: fe_sq(>z_255_5=fe#2,<z_250_0=fe#2); for (i = 1;i < 5;++i) fe_sq(>z_255_5=fe#2,>z_255_5=fe#2); */
|
||||
/* asm 2: fe_sq(>z_255_5=t1,<z_250_0=t1); for (i = 1;i < 5;++i) fe_sq(>z_255_5=t1,>z_255_5=t1); */
|
||||
fe_sq(t1,t1); for (i = 1;i < 5;++i) fe_sq(t1,t1);
|
||||
|
||||
/* qhasm: z_255_21 = z_255_5*z11 */
|
||||
/* asm 1: fe_mul(>z_255_21=fe#12,<z_255_5=fe#2,<z11=fe#1); */
|
||||
/* asm 2: fe_mul(>z_255_21=out,<z_255_5=t1,<z11=t0); */
|
||||
fe_mul(out,t1,t0);
|
||||
|
||||
/* qhasm: return */
|
15
vendor/MDBC/plugins/auth/ref10/sc.h
vendored
Normal file
15
vendor/MDBC/plugins/auth/ref10/sc.h
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
#ifndef SC_H
|
||||
#define SC_H
|
||||
|
||||
/*
|
||||
The set of scalars is \Z/l
|
||||
where l = 2^252 + 27742317777372353535851937790883648493.
|
||||
*/
|
||||
|
||||
#define sc_reduce crypto_sign_ed25519_ref10_sc_reduce
|
||||
#define sc_muladd crypto_sign_ed25519_ref10_sc_muladd
|
||||
|
||||
extern void sc_reduce(unsigned char *);
|
||||
extern void sc_muladd(unsigned char *,const unsigned char *,const unsigned char *,const unsigned char *);
|
||||
|
||||
#endif
|
368
vendor/MDBC/plugins/auth/ref10/sc_muladd.c
vendored
Normal file
368
vendor/MDBC/plugins/auth/ref10/sc_muladd.c
vendored
Normal file
@ -0,0 +1,368 @@
|
||||
#include "sc.h"
|
||||
#include "crypto_int64.h"
|
||||
#include "crypto_uint32.h"
|
||||
#include "crypto_uint64.h"
|
||||
|
||||
static crypto_uint64 load_3(const unsigned char *in)
|
||||
{
|
||||
crypto_uint64 result;
|
||||
result = (crypto_uint64) in[0];
|
||||
result |= ((crypto_uint64) in[1]) << 8;
|
||||
result |= ((crypto_uint64) in[2]) << 16;
|
||||
return result;
|
||||
}
|
||||
|
||||
static crypto_uint64 load_4(const unsigned char *in)
|
||||
{
|
||||
crypto_uint64 result;
|
||||
result = (crypto_uint64) in[0];
|
||||
result |= ((crypto_uint64) in[1]) << 8;
|
||||
result |= ((crypto_uint64) in[2]) << 16;
|
||||
result |= ((crypto_uint64) in[3]) << 24;
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
Input:
|
||||
a[0]+256*a[1]+...+256^31*a[31] = a
|
||||
b[0]+256*b[1]+...+256^31*b[31] = b
|
||||
c[0]+256*c[1]+...+256^31*c[31] = c
|
||||
|
||||
Output:
|
||||
s[0]+256*s[1]+...+256^31*s[31] = (ab+c) mod l
|
||||
where l = 2^252 + 27742317777372353535851937790883648493.
|
||||
*/
|
||||
|
||||
void sc_muladd(unsigned char *s,const unsigned char *a,const unsigned char *b,const unsigned char *c)
|
||||
{
|
||||
crypto_int64 a0 = 2097151 & load_3(a);
|
||||
crypto_int64 a1 = 2097151 & (load_4(a + 2) >> 5);
|
||||
crypto_int64 a2 = 2097151 & (load_3(a + 5) >> 2);
|
||||
crypto_int64 a3 = 2097151 & (load_4(a + 7) >> 7);
|
||||
crypto_int64 a4 = 2097151 & (load_4(a + 10) >> 4);
|
||||
crypto_int64 a5 = 2097151 & (load_3(a + 13) >> 1);
|
||||
crypto_int64 a6 = 2097151 & (load_4(a + 15) >> 6);
|
||||
crypto_int64 a7 = 2097151 & (load_3(a + 18) >> 3);
|
||||
crypto_int64 a8 = 2097151 & load_3(a + 21);
|
||||
crypto_int64 a9 = 2097151 & (load_4(a + 23) >> 5);
|
||||
crypto_int64 a10 = 2097151 & (load_3(a + 26) >> 2);
|
||||
crypto_int64 a11 = (load_4(a + 28) >> 7);
|
||||
crypto_int64 b0 = 2097151 & load_3(b);
|
||||
crypto_int64 b1 = 2097151 & (load_4(b + 2) >> 5);
|
||||
crypto_int64 b2 = 2097151 & (load_3(b + 5) >> 2);
|
||||
crypto_int64 b3 = 2097151 & (load_4(b + 7) >> 7);
|
||||
crypto_int64 b4 = 2097151 & (load_4(b + 10) >> 4);
|
||||
crypto_int64 b5 = 2097151 & (load_3(b + 13) >> 1);
|
||||
crypto_int64 b6 = 2097151 & (load_4(b + 15) >> 6);
|
||||
crypto_int64 b7 = 2097151 & (load_3(b + 18) >> 3);
|
||||
crypto_int64 b8 = 2097151 & load_3(b + 21);
|
||||
crypto_int64 b9 = 2097151 & (load_4(b + 23) >> 5);
|
||||
crypto_int64 b10 = 2097151 & (load_3(b + 26) >> 2);
|
||||
crypto_int64 b11 = (load_4(b + 28) >> 7);
|
||||
crypto_int64 c0 = 2097151 & load_3(c);
|
||||
crypto_int64 c1 = 2097151 & (load_4(c + 2) >> 5);
|
||||
crypto_int64 c2 = 2097151 & (load_3(c + 5) >> 2);
|
||||
crypto_int64 c3 = 2097151 & (load_4(c + 7) >> 7);
|
||||
crypto_int64 c4 = 2097151 & (load_4(c + 10) >> 4);
|
||||
crypto_int64 c5 = 2097151 & (load_3(c + 13) >> 1);
|
||||
crypto_int64 c6 = 2097151 & (load_4(c + 15) >> 6);
|
||||
crypto_int64 c7 = 2097151 & (load_3(c + 18) >> 3);
|
||||
crypto_int64 c8 = 2097151 & load_3(c + 21);
|
||||
crypto_int64 c9 = 2097151 & (load_4(c + 23) >> 5);
|
||||
crypto_int64 c10 = 2097151 & (load_3(c + 26) >> 2);
|
||||
crypto_int64 c11 = (load_4(c + 28) >> 7);
|
||||
crypto_int64 s0;
|
||||
crypto_int64 s1;
|
||||
crypto_int64 s2;
|
||||
crypto_int64 s3;
|
||||
crypto_int64 s4;
|
||||
crypto_int64 s5;
|
||||
crypto_int64 s6;
|
||||
crypto_int64 s7;
|
||||
crypto_int64 s8;
|
||||
crypto_int64 s9;
|
||||
crypto_int64 s10;
|
||||
crypto_int64 s11;
|
||||
crypto_int64 s12;
|
||||
crypto_int64 s13;
|
||||
crypto_int64 s14;
|
||||
crypto_int64 s15;
|
||||
crypto_int64 s16;
|
||||
crypto_int64 s17;
|
||||
crypto_int64 s18;
|
||||
crypto_int64 s19;
|
||||
crypto_int64 s20;
|
||||
crypto_int64 s21;
|
||||
crypto_int64 s22;
|
||||
crypto_int64 s23;
|
||||
crypto_int64 carry0;
|
||||
crypto_int64 carry1;
|
||||
crypto_int64 carry2;
|
||||
crypto_int64 carry3;
|
||||
crypto_int64 carry4;
|
||||
crypto_int64 carry5;
|
||||
crypto_int64 carry6;
|
||||
crypto_int64 carry7;
|
||||
crypto_int64 carry8;
|
||||
crypto_int64 carry9;
|
||||
crypto_int64 carry10;
|
||||
crypto_int64 carry11;
|
||||
crypto_int64 carry12;
|
||||
crypto_int64 carry13;
|
||||
crypto_int64 carry14;
|
||||
crypto_int64 carry15;
|
||||
crypto_int64 carry16;
|
||||
crypto_int64 carry17;
|
||||
crypto_int64 carry18;
|
||||
crypto_int64 carry19;
|
||||
crypto_int64 carry20;
|
||||
crypto_int64 carry21;
|
||||
crypto_int64 carry22;
|
||||
|
||||
s0 = c0 + a0*b0;
|
||||
s1 = c1 + a0*b1 + a1*b0;
|
||||
s2 = c2 + a0*b2 + a1*b1 + a2*b0;
|
||||
s3 = c3 + a0*b3 + a1*b2 + a2*b1 + a3*b0;
|
||||
s4 = c4 + a0*b4 + a1*b3 + a2*b2 + a3*b1 + a4*b0;
|
||||
s5 = c5 + a0*b5 + a1*b4 + a2*b3 + a3*b2 + a4*b1 + a5*b0;
|
||||
s6 = c6 + a0*b6 + a1*b5 + a2*b4 + a3*b3 + a4*b2 + a5*b1 + a6*b0;
|
||||
s7 = c7 + a0*b7 + a1*b6 + a2*b5 + a3*b4 + a4*b3 + a5*b2 + a6*b1 + a7*b0;
|
||||
s8 = c8 + a0*b8 + a1*b7 + a2*b6 + a3*b5 + a4*b4 + a5*b3 + a6*b2 + a7*b1 + a8*b0;
|
||||
s9 = c9 + a0*b9 + a1*b8 + a2*b7 + a3*b6 + a4*b5 + a5*b4 + a6*b3 + a7*b2 + a8*b1 + a9*b0;
|
||||
s10 = c10 + a0*b10 + a1*b9 + a2*b8 + a3*b7 + a4*b6 + a5*b5 + a6*b4 + a7*b3 + a8*b2 + a9*b1 + a10*b0;
|
||||
s11 = c11 + a0*b11 + a1*b10 + a2*b9 + a3*b8 + a4*b7 + a5*b6 + a6*b5 + a7*b4 + a8*b3 + a9*b2 + a10*b1 + a11*b0;
|
||||
s12 = a1*b11 + a2*b10 + a3*b9 + a4*b8 + a5*b7 + a6*b6 + a7*b5 + a8*b4 + a9*b3 + a10*b2 + a11*b1;
|
||||
s13 = a2*b11 + a3*b10 + a4*b9 + a5*b8 + a6*b7 + a7*b6 + a8*b5 + a9*b4 + a10*b3 + a11*b2;
|
||||
s14 = a3*b11 + a4*b10 + a5*b9 + a6*b8 + a7*b7 + a8*b6 + a9*b5 + a10*b4 + a11*b3;
|
||||
s15 = a4*b11 + a5*b10 + a6*b9 + a7*b8 + a8*b7 + a9*b6 + a10*b5 + a11*b4;
|
||||
s16 = a5*b11 + a6*b10 + a7*b9 + a8*b8 + a9*b7 + a10*b6 + a11*b5;
|
||||
s17 = a6*b11 + a7*b10 + a8*b9 + a9*b8 + a10*b7 + a11*b6;
|
||||
s18 = a7*b11 + a8*b10 + a9*b9 + a10*b8 + a11*b7;
|
||||
s19 = a8*b11 + a9*b10 + a10*b9 + a11*b8;
|
||||
s20 = a9*b11 + a10*b10 + a11*b9;
|
||||
s21 = a10*b11 + a11*b10;
|
||||
s22 = a11*b11;
|
||||
s23 = 0;
|
||||
|
||||
carry0 = (s0 + (1<<20)) >> 21; s1 += carry0; s0 -= carry0 << 21;
|
||||
carry2 = (s2 + (1<<20)) >> 21; s3 += carry2; s2 -= carry2 << 21;
|
||||
carry4 = (s4 + (1<<20)) >> 21; s5 += carry4; s4 -= carry4 << 21;
|
||||
carry6 = (s6 + (1<<20)) >> 21; s7 += carry6; s6 -= carry6 << 21;
|
||||
carry8 = (s8 + (1<<20)) >> 21; s9 += carry8; s8 -= carry8 << 21;
|
||||
carry10 = (s10 + (1<<20)) >> 21; s11 += carry10; s10 -= carry10 << 21;
|
||||
carry12 = (s12 + (1<<20)) >> 21; s13 += carry12; s12 -= carry12 << 21;
|
||||
carry14 = (s14 + (1<<20)) >> 21; s15 += carry14; s14 -= carry14 << 21;
|
||||
carry16 = (s16 + (1<<20)) >> 21; s17 += carry16; s16 -= carry16 << 21;
|
||||
carry18 = (s18 + (1<<20)) >> 21; s19 += carry18; s18 -= carry18 << 21;
|
||||
carry20 = (s20 + (1<<20)) >> 21; s21 += carry20; s20 -= carry20 << 21;
|
||||
carry22 = (s22 + (1<<20)) >> 21; s23 += carry22; s22 -= carry22 << 21;
|
||||
|
||||
carry1 = (s1 + (1<<20)) >> 21; s2 += carry1; s1 -= carry1 << 21;
|
||||
carry3 = (s3 + (1<<20)) >> 21; s4 += carry3; s3 -= carry3 << 21;
|
||||
carry5 = (s5 + (1<<20)) >> 21; s6 += carry5; s5 -= carry5 << 21;
|
||||
carry7 = (s7 + (1<<20)) >> 21; s8 += carry7; s7 -= carry7 << 21;
|
||||
carry9 = (s9 + (1<<20)) >> 21; s10 += carry9; s9 -= carry9 << 21;
|
||||
carry11 = (s11 + (1<<20)) >> 21; s12 += carry11; s11 -= carry11 << 21;
|
||||
carry13 = (s13 + (1<<20)) >> 21; s14 += carry13; s13 -= carry13 << 21;
|
||||
carry15 = (s15 + (1<<20)) >> 21; s16 += carry15; s15 -= carry15 << 21;
|
||||
carry17 = (s17 + (1<<20)) >> 21; s18 += carry17; s17 -= carry17 << 21;
|
||||
carry19 = (s19 + (1<<20)) >> 21; s20 += carry19; s19 -= carry19 << 21;
|
||||
carry21 = (s21 + (1<<20)) >> 21; s22 += carry21; s21 -= carry21 << 21;
|
||||
|
||||
s11 += s23 * 666643;
|
||||
s12 += s23 * 470296;
|
||||
s13 += s23 * 654183;
|
||||
s14 -= s23 * 997805;
|
||||
s15 += s23 * 136657;
|
||||
s16 -= s23 * 683901;
|
||||
s23 = 0;
|
||||
|
||||
s10 += s22 * 666643;
|
||||
s11 += s22 * 470296;
|
||||
s12 += s22 * 654183;
|
||||
s13 -= s22 * 997805;
|
||||
s14 += s22 * 136657;
|
||||
s15 -= s22 * 683901;
|
||||
s22 = 0;
|
||||
|
||||
s9 += s21 * 666643;
|
||||
s10 += s21 * 470296;
|
||||
s11 += s21 * 654183;
|
||||
s12 -= s21 * 997805;
|
||||
s13 += s21 * 136657;
|
||||
s14 -= s21 * 683901;
|
||||
s21 = 0;
|
||||
|
||||
s8 += s20 * 666643;
|
||||
s9 += s20 * 470296;
|
||||
s10 += s20 * 654183;
|
||||
s11 -= s20 * 997805;
|
||||
s12 += s20 * 136657;
|
||||
s13 -= s20 * 683901;
|
||||
s20 = 0;
|
||||
|
||||
s7 += s19 * 666643;
|
||||
s8 += s19 * 470296;
|
||||
s9 += s19 * 654183;
|
||||
s10 -= s19 * 997805;
|
||||
s11 += s19 * 136657;
|
||||
s12 -= s19 * 683901;
|
||||
s19 = 0;
|
||||
|
||||
s6 += s18 * 666643;
|
||||
s7 += s18 * 470296;
|
||||
s8 += s18 * 654183;
|
||||
s9 -= s18 * 997805;
|
||||
s10 += s18 * 136657;
|
||||
s11 -= s18 * 683901;
|
||||
s18 = 0;
|
||||
|
||||
carry6 = (s6 + (1<<20)) >> 21; s7 += carry6; s6 -= carry6 << 21;
|
||||
carry8 = (s8 + (1<<20)) >> 21; s9 += carry8; s8 -= carry8 << 21;
|
||||
carry10 = (s10 + (1<<20)) >> 21; s11 += carry10; s10 -= carry10 << 21;
|
||||
carry12 = (s12 + (1<<20)) >> 21; s13 += carry12; s12 -= carry12 << 21;
|
||||
carry14 = (s14 + (1<<20)) >> 21; s15 += carry14; s14 -= carry14 << 21;
|
||||
carry16 = (s16 + (1<<20)) >> 21; s17 += carry16; s16 -= carry16 << 21;
|
||||
|
||||
carry7 = (s7 + (1<<20)) >> 21; s8 += carry7; s7 -= carry7 << 21;
|
||||
carry9 = (s9 + (1<<20)) >> 21; s10 += carry9; s9 -= carry9 << 21;
|
||||
carry11 = (s11 + (1<<20)) >> 21; s12 += carry11; s11 -= carry11 << 21;
|
||||
carry13 = (s13 + (1<<20)) >> 21; s14 += carry13; s13 -= carry13 << 21;
|
||||
carry15 = (s15 + (1<<20)) >> 21; s16 += carry15; s15 -= carry15 << 21;
|
||||
|
||||
s5 += s17 * 666643;
|
||||
s6 += s17 * 470296;
|
||||
s7 += s17 * 654183;
|
||||
s8 -= s17 * 997805;
|
||||
s9 += s17 * 136657;
|
||||
s10 -= s17 * 683901;
|
||||
s17 = 0;
|
||||
|
||||
s4 += s16 * 666643;
|
||||
s5 += s16 * 470296;
|
||||
s6 += s16 * 654183;
|
||||
s7 -= s16 * 997805;
|
||||
s8 += s16 * 136657;
|
||||
s9 -= s16 * 683901;
|
||||
s16 = 0;
|
||||
|
||||
s3 += s15 * 666643;
|
||||
s4 += s15 * 470296;
|
||||
s5 += s15 * 654183;
|
||||
s6 -= s15 * 997805;
|
||||
s7 += s15 * 136657;
|
||||
s8 -= s15 * 683901;
|
||||
s15 = 0;
|
||||
|
||||
s2 += s14 * 666643;
|
||||
s3 += s14 * 470296;
|
||||
s4 += s14 * 654183;
|
||||
s5 -= s14 * 997805;
|
||||
s6 += s14 * 136657;
|
||||
s7 -= s14 * 683901;
|
||||
s14 = 0;
|
||||
|
||||
s1 += s13 * 666643;
|
||||
s2 += s13 * 470296;
|
||||
s3 += s13 * 654183;
|
||||
s4 -= s13 * 997805;
|
||||
s5 += s13 * 136657;
|
||||
s6 -= s13 * 683901;
|
||||
s13 = 0;
|
||||
|
||||
s0 += s12 * 666643;
|
||||
s1 += s12 * 470296;
|
||||
s2 += s12 * 654183;
|
||||
s3 -= s12 * 997805;
|
||||
s4 += s12 * 136657;
|
||||
s5 -= s12 * 683901;
|
||||
s12 = 0;
|
||||
|
||||
carry0 = (s0 + (1<<20)) >> 21; s1 += carry0; s0 -= carry0 << 21;
|
||||
carry2 = (s2 + (1<<20)) >> 21; s3 += carry2; s2 -= carry2 << 21;
|
||||
carry4 = (s4 + (1<<20)) >> 21; s5 += carry4; s4 -= carry4 << 21;
|
||||
carry6 = (s6 + (1<<20)) >> 21; s7 += carry6; s6 -= carry6 << 21;
|
||||
carry8 = (s8 + (1<<20)) >> 21; s9 += carry8; s8 -= carry8 << 21;
|
||||
carry10 = (s10 + (1<<20)) >> 21; s11 += carry10; s10 -= carry10 << 21;
|
||||
|
||||
carry1 = (s1 + (1<<20)) >> 21; s2 += carry1; s1 -= carry1 << 21;
|
||||
carry3 = (s3 + (1<<20)) >> 21; s4 += carry3; s3 -= carry3 << 21;
|
||||
carry5 = (s5 + (1<<20)) >> 21; s6 += carry5; s5 -= carry5 << 21;
|
||||
carry7 = (s7 + (1<<20)) >> 21; s8 += carry7; s7 -= carry7 << 21;
|
||||
carry9 = (s9 + (1<<20)) >> 21; s10 += carry9; s9 -= carry9 << 21;
|
||||
carry11 = (s11 + (1<<20)) >> 21; s12 += carry11; s11 -= carry11 << 21;
|
||||
|
||||
s0 += s12 * 666643;
|
||||
s1 += s12 * 470296;
|
||||
s2 += s12 * 654183;
|
||||
s3 -= s12 * 997805;
|
||||
s4 += s12 * 136657;
|
||||
s5 -= s12 * 683901;
|
||||
s12 = 0;
|
||||
|
||||
carry0 = s0 >> 21; s1 += carry0; s0 -= carry0 << 21;
|
||||
carry1 = s1 >> 21; s2 += carry1; s1 -= carry1 << 21;
|
||||
carry2 = s2 >> 21; s3 += carry2; s2 -= carry2 << 21;
|
||||
carry3 = s3 >> 21; s4 += carry3; s3 -= carry3 << 21;
|
||||
carry4 = s4 >> 21; s5 += carry4; s4 -= carry4 << 21;
|
||||
carry5 = s5 >> 21; s6 += carry5; s5 -= carry5 << 21;
|
||||
carry6 = s6 >> 21; s7 += carry6; s6 -= carry6 << 21;
|
||||
carry7 = s7 >> 21; s8 += carry7; s7 -= carry7 << 21;
|
||||
carry8 = s8 >> 21; s9 += carry8; s8 -= carry8 << 21;
|
||||
carry9 = s9 >> 21; s10 += carry9; s9 -= carry9 << 21;
|
||||
carry10 = s10 >> 21; s11 += carry10; s10 -= carry10 << 21;
|
||||
carry11 = s11 >> 21; s12 += carry11; s11 -= carry11 << 21;
|
||||
|
||||
s0 += s12 * 666643;
|
||||
s1 += s12 * 470296;
|
||||
s2 += s12 * 654183;
|
||||
s3 -= s12 * 997805;
|
||||
s4 += s12 * 136657;
|
||||
s5 -= s12 * 683901;
|
||||
s12 = 0;
|
||||
|
||||
carry0 = s0 >> 21; s1 += carry0; s0 -= carry0 << 21;
|
||||
carry1 = s1 >> 21; s2 += carry1; s1 -= carry1 << 21;
|
||||
carry2 = s2 >> 21; s3 += carry2; s2 -= carry2 << 21;
|
||||
carry3 = s3 >> 21; s4 += carry3; s3 -= carry3 << 21;
|
||||
carry4 = s4 >> 21; s5 += carry4; s4 -= carry4 << 21;
|
||||
carry5 = s5 >> 21; s6 += carry5; s5 -= carry5 << 21;
|
||||
carry6 = s6 >> 21; s7 += carry6; s6 -= carry6 << 21;
|
||||
carry7 = s7 >> 21; s8 += carry7; s7 -= carry7 << 21;
|
||||
carry8 = s8 >> 21; s9 += carry8; s8 -= carry8 << 21;
|
||||
carry9 = s9 >> 21; s10 += carry9; s9 -= carry9 << 21;
|
||||
carry10 = s10 >> 21; s11 += carry10; s10 -= carry10 << 21;
|
||||
|
||||
s[0] = s0 >> 0;
|
||||
s[1] = s0 >> 8;
|
||||
s[2] = (s0 >> 16) | (s1 << 5);
|
||||
s[3] = s1 >> 3;
|
||||
s[4] = s1 >> 11;
|
||||
s[5] = (s1 >> 19) | (s2 << 2);
|
||||
s[6] = s2 >> 6;
|
||||
s[7] = (s2 >> 14) | (s3 << 7);
|
||||
s[8] = s3 >> 1;
|
||||
s[9] = s3 >> 9;
|
||||
s[10] = (s3 >> 17) | (s4 << 4);
|
||||
s[11] = s4 >> 4;
|
||||
s[12] = s4 >> 12;
|
||||
s[13] = (s4 >> 20) | (s5 << 1);
|
||||
s[14] = s5 >> 7;
|
||||
s[15] = (s5 >> 15) | (s6 << 6);
|
||||
s[16] = s6 >> 2;
|
||||
s[17] = s6 >> 10;
|
||||
s[18] = (s6 >> 18) | (s7 << 3);
|
||||
s[19] = s7 >> 5;
|
||||
s[20] = s7 >> 13;
|
||||
s[21] = s8 >> 0;
|
||||
s[22] = s8 >> 8;
|
||||
s[23] = (s8 >> 16) | (s9 << 5);
|
||||
s[24] = s9 >> 3;
|
||||
s[25] = s9 >> 11;
|
||||
s[26] = (s9 >> 19) | (s10 << 2);
|
||||
s[27] = s10 >> 6;
|
||||
s[28] = (s10 >> 14) | (s11 << 7);
|
||||
s[29] = s11 >> 1;
|
||||
s[30] = s11 >> 9;
|
||||
s[31] = s11 >> 17;
|
||||
}
|
275
vendor/MDBC/plugins/auth/ref10/sc_reduce.c
vendored
Normal file
275
vendor/MDBC/plugins/auth/ref10/sc_reduce.c
vendored
Normal file
@ -0,0 +1,275 @@
|
||||
#include "sc.h"
|
||||
#include "crypto_int64.h"
|
||||
#include "crypto_uint32.h"
|
||||
#include "crypto_uint64.h"
|
||||
|
||||
static crypto_uint64 load_3(const unsigned char *in)
|
||||
{
|
||||
crypto_uint64 result;
|
||||
result = (crypto_uint64) in[0];
|
||||
result |= ((crypto_uint64) in[1]) << 8;
|
||||
result |= ((crypto_uint64) in[2]) << 16;
|
||||
return result;
|
||||
}
|
||||
|
||||
static crypto_uint64 load_4(const unsigned char *in)
|
||||
{
|
||||
crypto_uint64 result;
|
||||
result = (crypto_uint64) in[0];
|
||||
result |= ((crypto_uint64) in[1]) << 8;
|
||||
result |= ((crypto_uint64) in[2]) << 16;
|
||||
result |= ((crypto_uint64) in[3]) << 24;
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
Input:
|
||||
s[0]+256*s[1]+...+256^63*s[63] = s
|
||||
|
||||
Output:
|
||||
s[0]+256*s[1]+...+256^31*s[31] = s mod l
|
||||
where l = 2^252 + 27742317777372353535851937790883648493.
|
||||
Overwrites s in place.
|
||||
*/
|
||||
|
||||
void sc_reduce(unsigned char *s)
|
||||
{
|
||||
crypto_int64 s0 = 2097151 & load_3(s);
|
||||
crypto_int64 s1 = 2097151 & (load_4(s + 2) >> 5);
|
||||
crypto_int64 s2 = 2097151 & (load_3(s + 5) >> 2);
|
||||
crypto_int64 s3 = 2097151 & (load_4(s + 7) >> 7);
|
||||
crypto_int64 s4 = 2097151 & (load_4(s + 10) >> 4);
|
||||
crypto_int64 s5 = 2097151 & (load_3(s + 13) >> 1);
|
||||
crypto_int64 s6 = 2097151 & (load_4(s + 15) >> 6);
|
||||
crypto_int64 s7 = 2097151 & (load_3(s + 18) >> 3);
|
||||
crypto_int64 s8 = 2097151 & load_3(s + 21);
|
||||
crypto_int64 s9 = 2097151 & (load_4(s + 23) >> 5);
|
||||
crypto_int64 s10 = 2097151 & (load_3(s + 26) >> 2);
|
||||
crypto_int64 s11 = 2097151 & (load_4(s + 28) >> 7);
|
||||
crypto_int64 s12 = 2097151 & (load_4(s + 31) >> 4);
|
||||
crypto_int64 s13 = 2097151 & (load_3(s + 34) >> 1);
|
||||
crypto_int64 s14 = 2097151 & (load_4(s + 36) >> 6);
|
||||
crypto_int64 s15 = 2097151 & (load_3(s + 39) >> 3);
|
||||
crypto_int64 s16 = 2097151 & load_3(s + 42);
|
||||
crypto_int64 s17 = 2097151 & (load_4(s + 44) >> 5);
|
||||
crypto_int64 s18 = 2097151 & (load_3(s + 47) >> 2);
|
||||
crypto_int64 s19 = 2097151 & (load_4(s + 49) >> 7);
|
||||
crypto_int64 s20 = 2097151 & (load_4(s + 52) >> 4);
|
||||
crypto_int64 s21 = 2097151 & (load_3(s + 55) >> 1);
|
||||
crypto_int64 s22 = 2097151 & (load_4(s + 57) >> 6);
|
||||
crypto_int64 s23 = (load_4(s + 60) >> 3);
|
||||
crypto_int64 carry0;
|
||||
crypto_int64 carry1;
|
||||
crypto_int64 carry2;
|
||||
crypto_int64 carry3;
|
||||
crypto_int64 carry4;
|
||||
crypto_int64 carry5;
|
||||
crypto_int64 carry6;
|
||||
crypto_int64 carry7;
|
||||
crypto_int64 carry8;
|
||||
crypto_int64 carry9;
|
||||
crypto_int64 carry10;
|
||||
crypto_int64 carry11;
|
||||
crypto_int64 carry12;
|
||||
crypto_int64 carry13;
|
||||
crypto_int64 carry14;
|
||||
crypto_int64 carry15;
|
||||
crypto_int64 carry16;
|
||||
|
||||
s11 += s23 * 666643;
|
||||
s12 += s23 * 470296;
|
||||
s13 += s23 * 654183;
|
||||
s14 -= s23 * 997805;
|
||||
s15 += s23 * 136657;
|
||||
s16 -= s23 * 683901;
|
||||
s23 = 0;
|
||||
|
||||
s10 += s22 * 666643;
|
||||
s11 += s22 * 470296;
|
||||
s12 += s22 * 654183;
|
||||
s13 -= s22 * 997805;
|
||||
s14 += s22 * 136657;
|
||||
s15 -= s22 * 683901;
|
||||
s22 = 0;
|
||||
|
||||
s9 += s21 * 666643;
|
||||
s10 += s21 * 470296;
|
||||
s11 += s21 * 654183;
|
||||
s12 -= s21 * 997805;
|
||||
s13 += s21 * 136657;
|
||||
s14 -= s21 * 683901;
|
||||
s21 = 0;
|
||||
|
||||
s8 += s20 * 666643;
|
||||
s9 += s20 * 470296;
|
||||
s10 += s20 * 654183;
|
||||
s11 -= s20 * 997805;
|
||||
s12 += s20 * 136657;
|
||||
s13 -= s20 * 683901;
|
||||
s20 = 0;
|
||||
|
||||
s7 += s19 * 666643;
|
||||
s8 += s19 * 470296;
|
||||
s9 += s19 * 654183;
|
||||
s10 -= s19 * 997805;
|
||||
s11 += s19 * 136657;
|
||||
s12 -= s19 * 683901;
|
||||
s19 = 0;
|
||||
|
||||
s6 += s18 * 666643;
|
||||
s7 += s18 * 470296;
|
||||
s8 += s18 * 654183;
|
||||
s9 -= s18 * 997805;
|
||||
s10 += s18 * 136657;
|
||||
s11 -= s18 * 683901;
|
||||
s18 = 0;
|
||||
|
||||
carry6 = (s6 + (1<<20)) >> 21; s7 += carry6; s6 -= carry6 << 21;
|
||||
carry8 = (s8 + (1<<20)) >> 21; s9 += carry8; s8 -= carry8 << 21;
|
||||
carry10 = (s10 + (1<<20)) >> 21; s11 += carry10; s10 -= carry10 << 21;
|
||||
carry12 = (s12 + (1<<20)) >> 21; s13 += carry12; s12 -= carry12 << 21;
|
||||
carry14 = (s14 + (1<<20)) >> 21; s15 += carry14; s14 -= carry14 << 21;
|
||||
carry16 = (s16 + (1<<20)) >> 21; s17 += carry16; s16 -= carry16 << 21;
|
||||
|
||||
carry7 = (s7 + (1<<20)) >> 21; s8 += carry7; s7 -= carry7 << 21;
|
||||
carry9 = (s9 + (1<<20)) >> 21; s10 += carry9; s9 -= carry9 << 21;
|
||||
carry11 = (s11 + (1<<20)) >> 21; s12 += carry11; s11 -= carry11 << 21;
|
||||
carry13 = (s13 + (1<<20)) >> 21; s14 += carry13; s13 -= carry13 << 21;
|
||||
carry15 = (s15 + (1<<20)) >> 21; s16 += carry15; s15 -= carry15 << 21;
|
||||
|
||||
s5 += s17 * 666643;
|
||||
s6 += s17 * 470296;
|
||||
s7 += s17 * 654183;
|
||||
s8 -= s17 * 997805;
|
||||
s9 += s17 * 136657;
|
||||
s10 -= s17 * 683901;
|
||||
s17 = 0;
|
||||
|
||||
s4 += s16 * 666643;
|
||||
s5 += s16 * 470296;
|
||||
s6 += s16 * 654183;
|
||||
s7 -= s16 * 997805;
|
||||
s8 += s16 * 136657;
|
||||
s9 -= s16 * 683901;
|
||||
s16 = 0;
|
||||
|
||||
s3 += s15 * 666643;
|
||||
s4 += s15 * 470296;
|
||||
s5 += s15 * 654183;
|
||||
s6 -= s15 * 997805;
|
||||
s7 += s15 * 136657;
|
||||
s8 -= s15 * 683901;
|
||||
s15 = 0;
|
||||
|
||||
s2 += s14 * 666643;
|
||||
s3 += s14 * 470296;
|
||||
s4 += s14 * 654183;
|
||||
s5 -= s14 * 997805;
|
||||
s6 += s14 * 136657;
|
||||
s7 -= s14 * 683901;
|
||||
s14 = 0;
|
||||
|
||||
s1 += s13 * 666643;
|
||||
s2 += s13 * 470296;
|
||||
s3 += s13 * 654183;
|
||||
s4 -= s13 * 997805;
|
||||
s5 += s13 * 136657;
|
||||
s6 -= s13 * 683901;
|
||||
s13 = 0;
|
||||
|
||||
s0 += s12 * 666643;
|
||||
s1 += s12 * 470296;
|
||||
s2 += s12 * 654183;
|
||||
s3 -= s12 * 997805;
|
||||
s4 += s12 * 136657;
|
||||
s5 -= s12 * 683901;
|
||||
s12 = 0;
|
||||
|
||||
carry0 = (s0 + (1<<20)) >> 21; s1 += carry0; s0 -= carry0 << 21;
|
||||
carry2 = (s2 + (1<<20)) >> 21; s3 += carry2; s2 -= carry2 << 21;
|
||||
carry4 = (s4 + (1<<20)) >> 21; s5 += carry4; s4 -= carry4 << 21;
|
||||
carry6 = (s6 + (1<<20)) >> 21; s7 += carry6; s6 -= carry6 << 21;
|
||||
carry8 = (s8 + (1<<20)) >> 21; s9 += carry8; s8 -= carry8 << 21;
|
||||
carry10 = (s10 + (1<<20)) >> 21; s11 += carry10; s10 -= carry10 << 21;
|
||||
|
||||
carry1 = (s1 + (1<<20)) >> 21; s2 += carry1; s1 -= carry1 << 21;
|
||||
carry3 = (s3 + (1<<20)) >> 21; s4 += carry3; s3 -= carry3 << 21;
|
||||
carry5 = (s5 + (1<<20)) >> 21; s6 += carry5; s5 -= carry5 << 21;
|
||||
carry7 = (s7 + (1<<20)) >> 21; s8 += carry7; s7 -= carry7 << 21;
|
||||
carry9 = (s9 + (1<<20)) >> 21; s10 += carry9; s9 -= carry9 << 21;
|
||||
carry11 = (s11 + (1<<20)) >> 21; s12 += carry11; s11 -= carry11 << 21;
|
||||
|
||||
s0 += s12 * 666643;
|
||||
s1 += s12 * 470296;
|
||||
s2 += s12 * 654183;
|
||||
s3 -= s12 * 997805;
|
||||
s4 += s12 * 136657;
|
||||
s5 -= s12 * 683901;
|
||||
s12 = 0;
|
||||
|
||||
carry0 = s0 >> 21; s1 += carry0; s0 -= carry0 << 21;
|
||||
carry1 = s1 >> 21; s2 += carry1; s1 -= carry1 << 21;
|
||||
carry2 = s2 >> 21; s3 += carry2; s2 -= carry2 << 21;
|
||||
carry3 = s3 >> 21; s4 += carry3; s3 -= carry3 << 21;
|
||||
carry4 = s4 >> 21; s5 += carry4; s4 -= carry4 << 21;
|
||||
carry5 = s5 >> 21; s6 += carry5; s5 -= carry5 << 21;
|
||||
carry6 = s6 >> 21; s7 += carry6; s6 -= carry6 << 21;
|
||||
carry7 = s7 >> 21; s8 += carry7; s7 -= carry7 << 21;
|
||||
carry8 = s8 >> 21; s9 += carry8; s8 -= carry8 << 21;
|
||||
carry9 = s9 >> 21; s10 += carry9; s9 -= carry9 << 21;
|
||||
carry10 = s10 >> 21; s11 += carry10; s10 -= carry10 << 21;
|
||||
carry11 = s11 >> 21; s12 += carry11; s11 -= carry11 << 21;
|
||||
|
||||
s0 += s12 * 666643;
|
||||
s1 += s12 * 470296;
|
||||
s2 += s12 * 654183;
|
||||
s3 -= s12 * 997805;
|
||||
s4 += s12 * 136657;
|
||||
s5 -= s12 * 683901;
|
||||
s12 = 0;
|
||||
|
||||
carry0 = s0 >> 21; s1 += carry0; s0 -= carry0 << 21;
|
||||
carry1 = s1 >> 21; s2 += carry1; s1 -= carry1 << 21;
|
||||
carry2 = s2 >> 21; s3 += carry2; s2 -= carry2 << 21;
|
||||
carry3 = s3 >> 21; s4 += carry3; s3 -= carry3 << 21;
|
||||
carry4 = s4 >> 21; s5 += carry4; s4 -= carry4 << 21;
|
||||
carry5 = s5 >> 21; s6 += carry5; s5 -= carry5 << 21;
|
||||
carry6 = s6 >> 21; s7 += carry6; s6 -= carry6 << 21;
|
||||
carry7 = s7 >> 21; s8 += carry7; s7 -= carry7 << 21;
|
||||
carry8 = s8 >> 21; s9 += carry8; s8 -= carry8 << 21;
|
||||
carry9 = s9 >> 21; s10 += carry9; s9 -= carry9 << 21;
|
||||
carry10 = s10 >> 21; s11 += carry10; s10 -= carry10 << 21;
|
||||
|
||||
s[0] = s0 >> 0;
|
||||
s[1] = s0 >> 8;
|
||||
s[2] = (s0 >> 16) | (s1 << 5);
|
||||
s[3] = s1 >> 3;
|
||||
s[4] = s1 >> 11;
|
||||
s[5] = (s1 >> 19) | (s2 << 2);
|
||||
s[6] = s2 >> 6;
|
||||
s[7] = (s2 >> 14) | (s3 << 7);
|
||||
s[8] = s3 >> 1;
|
||||
s[9] = s3 >> 9;
|
||||
s[10] = (s3 >> 17) | (s4 << 4);
|
||||
s[11] = s4 >> 4;
|
||||
s[12] = s4 >> 12;
|
||||
s[13] = (s4 >> 20) | (s5 << 1);
|
||||
s[14] = s5 >> 7;
|
||||
s[15] = (s5 >> 15) | (s6 << 6);
|
||||
s[16] = s6 >> 2;
|
||||
s[17] = s6 >> 10;
|
||||
s[18] = (s6 >> 18) | (s7 << 3);
|
||||
s[19] = s7 >> 5;
|
||||
s[20] = s7 >> 13;
|
||||
s[21] = s8 >> 0;
|
||||
s[22] = s8 >> 8;
|
||||
s[23] = (s8 >> 16) | (s9 << 5);
|
||||
s[24] = s9 >> 3;
|
||||
s[25] = s9 >> 11;
|
||||
s[26] = (s9 >> 19) | (s10 << 2);
|
||||
s[27] = s10 >> 6;
|
||||
s[28] = (s10 >> 14) | (s11 << 7);
|
||||
s[29] = s11 >> 1;
|
||||
s[30] = s11 >> 9;
|
||||
s[31] = s11 >> 17;
|
||||
}
|
39
vendor/MDBC/plugins/auth/ref10/sign.c
vendored
Normal file
39
vendor/MDBC/plugins/auth/ref10/sign.c
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
#include <string.h>
|
||||
#include "crypto_sign.h"
|
||||
#include "crypto_hash_sha512.h"
|
||||
#include "ge.h"
|
||||
#include "sc.h"
|
||||
|
||||
int ma_crypto_sign(
|
||||
unsigned char *sm,
|
||||
const unsigned char *m,unsigned long long mlen,
|
||||
const unsigned char *pw,unsigned long long pwlen
|
||||
)
|
||||
{
|
||||
unsigned char az[64];
|
||||
unsigned char nonce[64];
|
||||
unsigned char hram[64];
|
||||
ge_p3 A, R;
|
||||
|
||||
crypto_hash_sha512(az,pw,pwlen);
|
||||
az[0] &= 248;
|
||||
az[31] &= 63;
|
||||
az[31] |= 64;
|
||||
|
||||
memmove(sm + 64,m,mlen);
|
||||
memmove(sm + 32,az + 32,32);
|
||||
crypto_hash_sha512(nonce,sm + 32,mlen + 32);
|
||||
|
||||
ge_scalarmult_base(&A,az);
|
||||
ge_p3_tobytes(sm + 32,&A);
|
||||
|
||||
sc_reduce(nonce);
|
||||
ge_scalarmult_base(&R,nonce);
|
||||
ge_p3_tobytes(sm,&R);
|
||||
|
||||
crypto_hash_sha512(hram,sm,mlen + 64);
|
||||
sc_reduce(hram);
|
||||
sc_muladd(sm + 32,hram,az,nonce);
|
||||
|
||||
return 0;
|
||||
}
|
1
vendor/MDBC/plugins/auth/ref10/sqrtm1.h
vendored
Normal file
1
vendor/MDBC/plugins/auth/ref10/sqrtm1.h
vendored
Normal file
@ -0,0 +1 @@
|
||||
-32595792,-7943725,9377950,3500415,12389472,-272473,-25146209,-2005654,326686,11406482
|
40
vendor/MDBC/plugins/auth/ref10/verify.c
vendored
Normal file
40
vendor/MDBC/plugins/auth/ref10/verify.c
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
#include "crypto_verify.h"
|
||||
|
||||
int crypto_verify(const unsigned char *x,const unsigned char *y)
|
||||
{
|
||||
unsigned int differentbits = 0;
|
||||
#define F(i) differentbits |= x[i] ^ y[i];
|
||||
F(0)
|
||||
F(1)
|
||||
F(2)
|
||||
F(3)
|
||||
F(4)
|
||||
F(5)
|
||||
F(6)
|
||||
F(7)
|
||||
F(8)
|
||||
F(9)
|
||||
F(10)
|
||||
F(11)
|
||||
F(12)
|
||||
F(13)
|
||||
F(14)
|
||||
F(15)
|
||||
F(16)
|
||||
F(17)
|
||||
F(18)
|
||||
F(19)
|
||||
F(20)
|
||||
F(21)
|
||||
F(22)
|
||||
F(23)
|
||||
F(24)
|
||||
F(25)
|
||||
F(26)
|
||||
F(27)
|
||||
F(28)
|
||||
F(29)
|
||||
F(30)
|
||||
F(31)
|
||||
return (1 & ((differentbits - 1) >> 8)) - 1;
|
||||
}
|
51
vendor/MDBC/plugins/auth/server_plugin.h
vendored
Normal file
51
vendor/MDBC/plugins/auth/server_plugin.h
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
/* Copyright (c) 2015, Shuang Qiu, Robbie Harwood,
|
||||
Vladislav Vaintroub & MariaDB Corporation
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/* Plugin variables*/
|
||||
#include <mysql/plugin_auth.h>
|
||||
typedef enum
|
||||
{
|
||||
PLUGIN_MECH_KERBEROS = 0,
|
||||
PLUGIN_MECH_SPNEGO = 1,
|
||||
PLUGIN_MECH_DEFAULT = 2
|
||||
}PLUGIN_MECH;
|
||||
|
||||
extern unsigned long srv_mech;
|
||||
extern char *srv_principal_name;
|
||||
extern char *srv_mech_name;
|
||||
extern char *srv_keytab_path;
|
||||
/*
|
||||
Check, with GSSAPI/SSPI username of logged on user.
|
||||
|
||||
Depending on use_full_name parameter, compare either full name
|
||||
(principal name like user@real), or local name (first component)
|
||||
*/
|
||||
int plugin_init();
|
||||
int plugin_deinit();
|
||||
|
||||
int auth_server(MYSQL_PLUGIN_VIO *vio, const char *username, size_t username_len, int use_full_name);
|
358
vendor/MDBC/plugins/auth/sha256_pw.c
vendored
Normal file
358
vendor/MDBC/plugins/auth/sha256_pw.c
vendored
Normal file
@ -0,0 +1,358 @@
|
||||
/************************************************************************************
|
||||
Copyright (C) 2017 MariaDB Corporation AB
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not see <http://www.gnu.org/licenses>
|
||||
or write to the Free Software Foundation, Inc.,
|
||||
51 Franklin St., Fifth Floor, Boston, MA 02110, USA
|
||||
*************************************************************************************/
|
||||
#ifndef _WIN32
|
||||
#define _GNU_SOURCE 1
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#undef HAVE_GNUTLS
|
||||
#undef HAVE_OPENSSL
|
||||
#define HAVE_WINCRYPT
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_OPENSSL) || defined(HAVE_WINCRYPT)
|
||||
|
||||
#include <ma_global.h>
|
||||
#include <mysql.h>
|
||||
#include <mysql/client_plugin.h>
|
||||
#include <string.h>
|
||||
#include <memory.h>
|
||||
#include <errmsg.h>
|
||||
#include <ma_global.h>
|
||||
#include <ma_sys.h>
|
||||
#include <ma_common.h>
|
||||
|
||||
#ifndef WIN32
|
||||
#include <dlfcn.h>
|
||||
#endif
|
||||
|
||||
#if defined(WIN32)
|
||||
#include <wincrypt.h>
|
||||
#elif defined(HAVE_OPENSSL)
|
||||
#include <openssl/rsa.h>
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/err.h>
|
||||
#endif
|
||||
|
||||
#define MAX_PW_LEN 1024
|
||||
|
||||
/* function prototypes */
|
||||
static int auth_sha256_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql);
|
||||
static int auth_sha256_init(char *unused1,
|
||||
size_t unused2,
|
||||
int unused3,
|
||||
va_list);
|
||||
|
||||
|
||||
#ifndef PLUGIN_DYNAMIC
|
||||
struct st_mysql_client_plugin_AUTHENTICATION sha256_password_client_plugin=
|
||||
#else
|
||||
struct st_mysql_client_plugin_AUTHENTICATION _mysql_client_plugin_declaration_ =
|
||||
#endif
|
||||
{
|
||||
MYSQL_CLIENT_AUTHENTICATION_PLUGIN,
|
||||
MYSQL_CLIENT_AUTHENTICATION_PLUGIN_INTERFACE_VERSION,
|
||||
"sha256_password",
|
||||
"Georg Richter",
|
||||
"SHA256 Authentication Plugin",
|
||||
{0,1,0},
|
||||
"LGPL",
|
||||
NULL,
|
||||
auth_sha256_init,
|
||||
NULL,
|
||||
NULL,
|
||||
auth_sha256_client
|
||||
};
|
||||
|
||||
#ifdef HAVE_WINCRYPT
|
||||
static LPBYTE ma_load_pem(const char *buffer, DWORD *buffer_len)
|
||||
{
|
||||
LPBYTE der_buffer= NULL;
|
||||
DWORD der_buffer_length= 0;
|
||||
|
||||
if (buffer_len == NULL || *buffer_len == 0)
|
||||
return NULL;
|
||||
/* calculate the length of DER binary */
|
||||
if (!CryptStringToBinaryA(buffer, *buffer_len, CRYPT_STRING_BASE64HEADER,
|
||||
NULL, &der_buffer_length, NULL, NULL))
|
||||
goto end;
|
||||
/* allocate DER binary buffer */
|
||||
if (!(der_buffer= (LPBYTE)LocalAlloc(0, der_buffer_length)))
|
||||
goto end;
|
||||
/* convert to DER binary */
|
||||
if (!CryptStringToBinaryA(buffer, *buffer_len, CRYPT_STRING_BASE64HEADER,
|
||||
der_buffer, &der_buffer_length, NULL, NULL))
|
||||
goto end;
|
||||
|
||||
*buffer_len= der_buffer_length;
|
||||
|
||||
return der_buffer;
|
||||
|
||||
end:
|
||||
if (der_buffer)
|
||||
LocalFree(der_buffer);
|
||||
*buffer_len= 0;
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
static char *load_pub_key_file(const char *filename, int *pub_key_size)
|
||||
{
|
||||
FILE *fp= NULL;
|
||||
char *buffer= NULL;
|
||||
unsigned char error= 1;
|
||||
size_t bytes_read= 0;
|
||||
long fsize= 0;
|
||||
|
||||
if (!pub_key_size)
|
||||
return NULL;
|
||||
|
||||
if (!(fp= fopen(filename, "r")))
|
||||
goto end;
|
||||
|
||||
if (fseek(fp, 0, SEEK_END))
|
||||
goto end;
|
||||
|
||||
fsize= ftell(fp);
|
||||
if (fsize < 0)
|
||||
goto end;
|
||||
|
||||
rewind(fp);
|
||||
|
||||
if (!(buffer= malloc(fsize + 1)))
|
||||
goto end;
|
||||
|
||||
bytes_read= fread(buffer, 1, (size_t)fsize, fp);
|
||||
if (bytes_read < (size_t)fsize)
|
||||
goto end;
|
||||
|
||||
*pub_key_size= (int)bytes_read;
|
||||
|
||||
error= 0;
|
||||
|
||||
end:
|
||||
if (fp)
|
||||
fclose(fp);
|
||||
if (error && buffer)
|
||||
{
|
||||
free(buffer);
|
||||
buffer= NULL;
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
||||
static int auth_sha256_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql)
|
||||
{
|
||||
unsigned char *packet;
|
||||
int packet_length;
|
||||
int rc= CR_ERROR;
|
||||
char passwd[MAX_PW_LEN];
|
||||
unsigned int rsa_size;
|
||||
unsigned int pwlen, i;
|
||||
|
||||
#if defined(HAVE_OPENSSL)
|
||||
EVP_PKEY *pubkey= NULL;
|
||||
EVP_PKEY_CTX *ctx= NULL;
|
||||
size_t outlen= 0;
|
||||
unsigned char *rsa_enc_pw= NULL;
|
||||
BIO *bio;
|
||||
#elif defined(HAVE_WINCRYPT)
|
||||
unsigned char rsa_enc_pw[MAX_PW_LEN];
|
||||
HCRYPTKEY pubkey= 0;
|
||||
HCRYPTPROV hProv= 0;
|
||||
LPBYTE der_buffer= NULL;
|
||||
DWORD der_buffer_len= 0;
|
||||
CERT_PUBLIC_KEY_INFO *publicKeyInfo= NULL;
|
||||
DWORD ParamSize= sizeof(DWORD);
|
||||
int publicKeyInfoLen= 0;
|
||||
#endif
|
||||
char *filebuffer= NULL;
|
||||
|
||||
/* read error */
|
||||
if ((packet_length= vio->read_packet(vio, &packet)) < 0)
|
||||
return CR_ERROR;
|
||||
|
||||
if (packet_length != SCRAMBLE_LENGTH + 1)
|
||||
return CR_SERVER_HANDSHAKE_ERR;
|
||||
|
||||
memmove(mysql->scramble_buff, packet, SCRAMBLE_LENGTH);
|
||||
mysql->scramble_buff[SCRAMBLE_LENGTH]= 0;
|
||||
|
||||
/* if a tls session is active we need to send plain password */
|
||||
if (mysql->client_flag & CLIENT_SSL)
|
||||
{
|
||||
if (vio->write_packet(vio, (unsigned char *)mysql->passwd, (int)strlen(mysql->passwd) + 1))
|
||||
return CR_ERROR;
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
/* send empty packet if no password was provided */
|
||||
if (!mysql->passwd || !mysql->passwd[0])
|
||||
{
|
||||
if (vio->write_packet(vio, 0, 0))
|
||||
return CR_ERROR;
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
/* read public key file (if specified) */
|
||||
if (mysql->options.extension &&
|
||||
mysql->options.extension->server_public_key)
|
||||
{
|
||||
filebuffer= load_pub_key_file(mysql->options.extension->server_public_key,
|
||||
&packet_length);
|
||||
}
|
||||
|
||||
/* if no public key file was specified or if we couldn't read the file,
|
||||
we ask server to send public key */
|
||||
if (!filebuffer)
|
||||
{
|
||||
unsigned char buf= 1;
|
||||
if (vio->write_packet(vio, &buf, 1))
|
||||
return CR_ERROR;
|
||||
if ((packet_length=vio->read_packet(vio, &packet)) == -1)
|
||||
return CR_ERROR;
|
||||
}
|
||||
#if defined(HAVE_OPENSSL)
|
||||
bio= BIO_new_mem_buf(filebuffer ? (unsigned char *)filebuffer : packet,
|
||||
packet_length);
|
||||
if ((pubkey= PEM_read_bio_PUBKEY(bio, NULL, NULL, NULL)))
|
||||
{
|
||||
if (!(ctx= EVP_PKEY_CTX_new(pubkey, NULL)))
|
||||
goto error;
|
||||
if (EVP_PKEY_encrypt_init(ctx) <= 0)
|
||||
goto error;
|
||||
if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_OAEP_PADDING) <= 0)
|
||||
goto error;
|
||||
rsa_size= EVP_PKEY_size(pubkey);
|
||||
}
|
||||
BIO_free(bio);
|
||||
bio= NULL;
|
||||
ERR_clear_error();
|
||||
#elif defined(HAVE_WINCRYPT)
|
||||
der_buffer_len= packet_length;
|
||||
/* Load pem and convert it to binary object. New length will be returned
|
||||
in der_buffer_len */
|
||||
if (!(der_buffer= ma_load_pem(filebuffer ? filebuffer : (char *)packet, &der_buffer_len)))
|
||||
goto error;
|
||||
|
||||
/* Create context and load public key */
|
||||
if (!CryptDecodeObjectEx(X509_ASN_ENCODING, X509_PUBLIC_KEY_INFO,
|
||||
der_buffer, der_buffer_len,
|
||||
CRYPT_DECODE_ALLOC_FLAG, NULL,
|
||||
&publicKeyInfo, (DWORD *)&publicKeyInfoLen))
|
||||
goto error;
|
||||
LocalFree(der_buffer);
|
||||
|
||||
if (!CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL,
|
||||
CRYPT_VERIFYCONTEXT))
|
||||
goto error;
|
||||
if (!CryptImportPublicKeyInfo(hProv, X509_ASN_ENCODING,
|
||||
publicKeyInfo, &pubkey))
|
||||
goto error;
|
||||
|
||||
/* Get rsa_size */
|
||||
CryptGetKeyParam(pubkey, KP_KEYLEN, (BYTE *)&rsa_size, &ParamSize, 0);
|
||||
rsa_size /= 8;
|
||||
#endif
|
||||
if (!pubkey)
|
||||
return CR_ERROR;
|
||||
|
||||
pwlen= (unsigned int)strlen(mysql->passwd) + 1; /* include terminating zero */
|
||||
if (pwlen > MAX_PW_LEN)
|
||||
goto error;
|
||||
memcpy(passwd, mysql->passwd, pwlen);
|
||||
|
||||
/* xor password with scramble */
|
||||
for (i=0; i < pwlen; i++)
|
||||
passwd[i]^= *(mysql->scramble_buff + i % SCRAMBLE_LENGTH);
|
||||
|
||||
/* encrypt scrambled password */
|
||||
#if defined(HAVE_OPENSSL)
|
||||
if (EVP_PKEY_encrypt(ctx, NULL, &outlen, (unsigned char *)passwd, pwlen) <= 0)
|
||||
goto error;
|
||||
if (!(rsa_enc_pw= malloc(outlen)))
|
||||
goto error;
|
||||
if (EVP_PKEY_encrypt(ctx, rsa_enc_pw, &outlen, (unsigned char *)passwd, pwlen) <= 0)
|
||||
goto error;
|
||||
#elif defined(HAVE_WINCRYPT)
|
||||
if (!CryptEncrypt(pubkey, 0, TRUE, CRYPT_OAEP, (BYTE *)passwd, (DWORD *)&pwlen, MAX_PW_LEN))
|
||||
goto error;
|
||||
/* Windows encrypts as little-endian, while server (openssl) expects
|
||||
big-endian, so we have to revert the string */
|
||||
for (i= 0; i < rsa_size / 2; i++)
|
||||
{
|
||||
rsa_enc_pw[i]= passwd[rsa_size - 1 - i];
|
||||
rsa_enc_pw[rsa_size - 1 - i]= passwd[i];
|
||||
}
|
||||
#endif
|
||||
if (vio->write_packet(vio, rsa_enc_pw, rsa_size))
|
||||
goto error;
|
||||
|
||||
rc= CR_OK;
|
||||
error:
|
||||
#if defined(HAVE_OPENSSL)
|
||||
if (pubkey)
|
||||
EVP_PKEY_free(pubkey);
|
||||
if (bio)
|
||||
BIO_free(bio);
|
||||
if (ctx)
|
||||
EVP_PKEY_CTX_free(ctx);
|
||||
if (rsa_enc_pw)
|
||||
free(rsa_enc_pw);
|
||||
#elif defined(HAVE_WINCRYPT)
|
||||
CryptReleaseContext(hProv, 0);
|
||||
if (publicKeyInfo)
|
||||
LocalFree(publicKeyInfo);
|
||||
#endif
|
||||
free(filebuffer);
|
||||
return rc;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ static int auth_sha256_init */
|
||||
/*
|
||||
Initialization routine
|
||||
|
||||
SYNOPSIS
|
||||
auth_sha256_init
|
||||
unused1
|
||||
unused2
|
||||
unused3
|
||||
unused4
|
||||
|
||||
DESCRIPTION
|
||||
Init function checks if the caller provides own dialog function.
|
||||
The function name must be mariadb_auth_dialog or
|
||||
mysql_authentication_dialog_ask. If the function cannot be found,
|
||||
we will use owr own simple command line input.
|
||||
|
||||
RETURN
|
||||
0 success
|
||||
*/
|
||||
static int auth_sha256_init(char *unused1 __attribute__((unused)),
|
||||
size_t unused2 __attribute__((unused)),
|
||||
int unused3 __attribute__((unused)),
|
||||
va_list unused4 __attribute__((unused)))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
#endif /* defined(HAVE_OPENSSL) || defined(HAVE_WINCRYPT) */
|
184
vendor/MDBC/plugins/auth/sspi_client.c
vendored
Normal file
184
vendor/MDBC/plugins/auth/sspi_client.c
vendored
Normal file
@ -0,0 +1,184 @@
|
||||
/* Copyright (c) 2015, Shuang Qiu, Robbie Harwood,
|
||||
Vladislav Vaintroub & MariaDB Corporation
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#define SECURITY_WIN32
|
||||
#include <windows.h>
|
||||
#include <sspi.h>
|
||||
#include <secext.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <mysql/plugin_auth.h>
|
||||
#include <mysql.h>
|
||||
#include <ma_server_error.h>
|
||||
|
||||
#include "sspi_common.h"
|
||||
|
||||
extern void log_client_error(MYSQL *mysql, const char *fmt, ...);
|
||||
static void log_error(MYSQL *mysql, SECURITY_STATUS err, const char *msg)
|
||||
{
|
||||
if (err)
|
||||
{
|
||||
char buf[1024];
|
||||
sspi_errmsg(err, buf, sizeof(buf));
|
||||
log_client_error(mysql, "SSPI client error 0x%x - %s - %s", err, msg, buf);
|
||||
}
|
||||
else
|
||||
{
|
||||
log_client_error(mysql, "SSPI client error %s", msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Client side authentication*/
|
||||
int auth_client(char *principal_name, char *mech, MYSQL *mysql, MYSQL_PLUGIN_VIO *vio)
|
||||
{
|
||||
|
||||
int ret;
|
||||
CredHandle cred;
|
||||
CtxtHandle ctxt;
|
||||
ULONG attribs = 0;
|
||||
TimeStamp lifetime;
|
||||
SECURITY_STATUS sspi_err;
|
||||
|
||||
SecBufferDesc inbuf_desc;
|
||||
SecBuffer inbuf;
|
||||
SecBufferDesc outbuf_desc;
|
||||
SecBuffer outbuf;
|
||||
PBYTE out = NULL;
|
||||
|
||||
ret= CR_ERROR;
|
||||
SecInvalidateHandle(&ctxt);
|
||||
SecInvalidateHandle(&cred);
|
||||
|
||||
if (!mech || strcmp(mech, "Negotiate") != 0)
|
||||
{
|
||||
mech= (char *)"Kerberos";
|
||||
}
|
||||
|
||||
sspi_err = AcquireCredentialsHandle(
|
||||
NULL,
|
||||
mech,
|
||||
SECPKG_CRED_OUTBOUND,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
&cred,
|
||||
&lifetime);
|
||||
|
||||
if (SEC_ERROR(sspi_err))
|
||||
{
|
||||
log_error(mysql, sspi_err, "AcquireCredentialsHandle");
|
||||
return CR_ERROR;
|
||||
}
|
||||
|
||||
out = (PBYTE)malloc(SSPI_MAX_TOKEN_SIZE);
|
||||
if (!out)
|
||||
{
|
||||
log_error(mysql, SEC_E_OK, "memory allocation error");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* Prepare buffers */
|
||||
inbuf_desc.ulVersion = SECBUFFER_VERSION;
|
||||
inbuf_desc.cBuffers = 1;
|
||||
inbuf_desc.pBuffers = &inbuf;
|
||||
inbuf.BufferType = SECBUFFER_TOKEN;
|
||||
inbuf.cbBuffer = 0;
|
||||
inbuf.pvBuffer = NULL;
|
||||
|
||||
outbuf_desc.ulVersion = SECBUFFER_VERSION;
|
||||
outbuf_desc.cBuffers = 1;
|
||||
outbuf_desc.pBuffers = &outbuf;
|
||||
outbuf.BufferType = SECBUFFER_TOKEN;
|
||||
outbuf.pvBuffer = out;
|
||||
|
||||
do
|
||||
{
|
||||
outbuf.cbBuffer= SSPI_MAX_TOKEN_SIZE;
|
||||
sspi_err= InitializeSecurityContext(
|
||||
&cred,
|
||||
SecIsValidHandle(&ctxt) ? &ctxt : NULL,
|
||||
principal_name,
|
||||
0,
|
||||
0,
|
||||
SECURITY_NATIVE_DREP,
|
||||
inbuf.cbBuffer ? &inbuf_desc : NULL,
|
||||
0,
|
||||
&ctxt,
|
||||
&outbuf_desc,
|
||||
&attribs,
|
||||
&lifetime);
|
||||
if (SEC_ERROR(sspi_err))
|
||||
{
|
||||
log_error(mysql, sspi_err, "InitializeSecurityContext");
|
||||
goto cleanup;
|
||||
}
|
||||
if (sspi_err != SEC_E_OK && sspi_err != SEC_I_CONTINUE_NEEDED)
|
||||
{
|
||||
log_error(mysql, sspi_err, "Unexpected response from InitializeSecurityContext");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (outbuf.cbBuffer)
|
||||
{
|
||||
/* send credential to server */
|
||||
if (vio->write_packet(vio, (unsigned char *)outbuf.pvBuffer, outbuf.cbBuffer))
|
||||
{
|
||||
/* Server error packet contains detailed message. */
|
||||
ret= CR_OK_HANDSHAKE_COMPLETE;
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
if (sspi_err == SEC_I_CONTINUE_NEEDED)
|
||||
{
|
||||
int len= vio->read_packet(vio, (unsigned char **)&inbuf.pvBuffer);
|
||||
if (len <= 0)
|
||||
{
|
||||
/* Server side error is in the last server packet. */
|
||||
ret= CR_OK_HANDSHAKE_COMPLETE;
|
||||
goto cleanup;
|
||||
}
|
||||
inbuf.cbBuffer= len;
|
||||
}
|
||||
} while (sspi_err == SEC_I_CONTINUE_NEEDED);
|
||||
|
||||
ret= CR_OK;
|
||||
|
||||
cleanup:
|
||||
|
||||
if (SecIsValidHandle(&ctxt))
|
||||
DeleteSecurityContext(&ctxt);
|
||||
if (SecIsValidHandle(&cred))
|
||||
FreeCredentialsHandle(&cred);
|
||||
free(out);
|
||||
return ret;
|
||||
}
|
38
vendor/MDBC/plugins/auth/sspi_common.h
vendored
Normal file
38
vendor/MDBC/plugins/auth/sspi_common.h
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
/* Copyright (c) 2015, Shuang Qiu, Robbie Harwood,
|
||||
Vladislav Vaintroub & MariaDB Corporation
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#define SECURITY_WIN32
|
||||
#include <windows.h>
|
||||
#include <sspi.h>
|
||||
#include <secext.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define SSPI_MAX_TOKEN_SIZE 50000
|
||||
#define SEC_ERROR(err) ((err) < 0)
|
||||
extern void sspi_errmsg(int err, char *buf, size_t size);
|
169
vendor/MDBC/plugins/auth/sspi_errmsg.c
vendored
Normal file
169
vendor/MDBC/plugins/auth/sspi_errmsg.c
vendored
Normal file
@ -0,0 +1,169 @@
|
||||
/* Copyright (c) 2015, Shuang Qiu, Robbie Harwood,
|
||||
Vladislav Vaintroub & MariaDB Corporation
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifndef SEC_E_INVALID_PARAMETER
|
||||
#define SEC_E_INVALID_PARAMETER _HRESULT_TYPEDEF_(0x8009035D)
|
||||
#endif
|
||||
#ifndef SEC_E_DELEGATION_POLICY
|
||||
#define SEC_E_DELEGATION_POLICY _HRESULT_TYPEDEF_(0x8009035E)
|
||||
#endif
|
||||
#ifndef SEC_E_POLICY_NLTM_ONLY
|
||||
#define SEC_E_POLICY_NLTM_ONLY _HRESULT_TYPEDEF_(0x8009035F)
|
||||
#endif
|
||||
#ifndef SEC_E_NO_CONTEXT
|
||||
#define SEC_E_NO_CONTEXT _HRESULT_TYPEDEF_(0x80090361)
|
||||
#endif
|
||||
#ifndef SEC_E_PKU2U_CERT_FAILURE
|
||||
#define SEC_E_PKU2U_CERT_FAILURE _HRESULT_TYPEDEF_(0x80090362)
|
||||
#endif
|
||||
#ifndef SEC_E_MUTUAL_AUTH_FAILED
|
||||
#define SEC_E_MUTUAL_AUTH_FAILED _HRESULT_TYPEDEF_(0x80090363)
|
||||
#endif
|
||||
|
||||
#define ERRSYM(x) {x, #x}
|
||||
static struct {
|
||||
int error;
|
||||
const char *sym;
|
||||
} error_symbols[] =
|
||||
{
|
||||
ERRSYM(SEC_E_OK),
|
||||
ERRSYM(SEC_E_INSUFFICIENT_MEMORY),
|
||||
ERRSYM(SEC_E_INVALID_HANDLE),
|
||||
ERRSYM(SEC_E_UNSUPPORTED_FUNCTION),
|
||||
ERRSYM(SEC_E_TARGET_UNKNOWN),
|
||||
ERRSYM(SEC_E_INTERNAL_ERROR),
|
||||
ERRSYM(SEC_E_SECPKG_NOT_FOUND),
|
||||
ERRSYM(SEC_E_NOT_OWNER),
|
||||
ERRSYM(SEC_E_CANNOT_INSTALL),
|
||||
ERRSYM(SEC_E_INVALID_TOKEN),
|
||||
ERRSYM(SEC_E_CANNOT_PACK),
|
||||
ERRSYM(SEC_E_QOP_NOT_SUPPORTED),
|
||||
ERRSYM(SEC_E_NO_IMPERSONATION),
|
||||
ERRSYM(SEC_E_LOGON_DENIED),
|
||||
ERRSYM(SEC_E_UNKNOWN_CREDENTIALS),
|
||||
ERRSYM(SEC_E_NO_CREDENTIALS),
|
||||
ERRSYM(SEC_E_MESSAGE_ALTERED),
|
||||
ERRSYM(SEC_E_OUT_OF_SEQUENCE),
|
||||
ERRSYM(SEC_E_NO_AUTHENTICATING_AUTHORITY),
|
||||
ERRSYM(SEC_E_BAD_PKGID),
|
||||
ERRSYM(SEC_E_CONTEXT_EXPIRED),
|
||||
ERRSYM(SEC_E_INCOMPLETE_MESSAGE),
|
||||
ERRSYM(SEC_E_INCOMPLETE_CREDENTIALS),
|
||||
ERRSYM(SEC_E_BUFFER_TOO_SMALL),
|
||||
ERRSYM(SEC_E_WRONG_PRINCIPAL),
|
||||
ERRSYM(SEC_E_TIME_SKEW),
|
||||
ERRSYM(SEC_E_UNTRUSTED_ROOT),
|
||||
ERRSYM(SEC_E_ILLEGAL_MESSAGE),
|
||||
ERRSYM(SEC_E_CERT_UNKNOWN),
|
||||
ERRSYM(SEC_E_CERT_EXPIRED),
|
||||
ERRSYM(SEC_E_ENCRYPT_FAILURE),
|
||||
ERRSYM(SEC_E_DECRYPT_FAILURE),
|
||||
ERRSYM(SEC_E_ALGORITHM_MISMATCH),
|
||||
ERRSYM(SEC_E_SECURITY_QOS_FAILED),
|
||||
ERRSYM(SEC_E_UNFINISHED_CONTEXT_DELETED),
|
||||
ERRSYM(SEC_E_NO_TGT_REPLY),
|
||||
ERRSYM(SEC_E_NO_IP_ADDRESSES),
|
||||
ERRSYM(SEC_E_WRONG_CREDENTIAL_HANDLE),
|
||||
ERRSYM(SEC_E_CRYPTO_SYSTEM_INVALID),
|
||||
ERRSYM(SEC_E_MAX_REFERRALS_EXCEEDED),
|
||||
ERRSYM(SEC_E_MUST_BE_KDC),
|
||||
ERRSYM(SEC_E_STRONG_CRYPTO_NOT_SUPPORTED),
|
||||
ERRSYM(SEC_E_TOO_MANY_PRINCIPALS),
|
||||
ERRSYM(SEC_E_NO_PA_DATA),
|
||||
ERRSYM(SEC_E_PKINIT_NAME_MISMATCH),
|
||||
ERRSYM(SEC_E_SMARTCARD_LOGON_REQUIRED),
|
||||
ERRSYM(SEC_E_SHUTDOWN_IN_PROGRESS),
|
||||
ERRSYM(SEC_E_KDC_INVALID_REQUEST),
|
||||
ERRSYM(SEC_E_KDC_UNABLE_TO_REFER),
|
||||
ERRSYM(SEC_E_KDC_UNKNOWN_ETYPE),
|
||||
ERRSYM(SEC_E_UNSUPPORTED_PREAUTH),
|
||||
ERRSYM(SEC_E_DELEGATION_REQUIRED),
|
||||
ERRSYM(SEC_E_BAD_BINDINGS),
|
||||
ERRSYM(SEC_E_MULTIPLE_ACCOUNTS),
|
||||
ERRSYM(SEC_E_NO_KERB_KEY),
|
||||
ERRSYM(SEC_E_CERT_WRONG_USAGE),
|
||||
ERRSYM(SEC_E_DOWNGRADE_DETECTED),
|
||||
ERRSYM(SEC_E_SMARTCARD_CERT_REVOKED),
|
||||
ERRSYM(SEC_E_ISSUING_CA_UNTRUSTED),
|
||||
ERRSYM(SEC_E_REVOCATION_OFFLINE_C),
|
||||
ERRSYM(SEC_E_PKINIT_CLIENT_FAILURE),
|
||||
ERRSYM(SEC_E_SMARTCARD_CERT_EXPIRED),
|
||||
ERRSYM(SEC_E_NO_S4U_PROT_SUPPORT),
|
||||
ERRSYM(SEC_E_CROSSREALM_DELEGATION_FAILURE),
|
||||
ERRSYM(SEC_E_REVOCATION_OFFLINE_KDC),
|
||||
ERRSYM(SEC_E_ISSUING_CA_UNTRUSTED_KDC),
|
||||
ERRSYM(SEC_E_KDC_CERT_EXPIRED),
|
||||
ERRSYM(SEC_E_KDC_CERT_REVOKED),
|
||||
ERRSYM(SEC_E_INVALID_PARAMETER),
|
||||
ERRSYM(SEC_E_DELEGATION_POLICY),
|
||||
ERRSYM(SEC_E_POLICY_NLTM_ONLY),
|
||||
ERRSYM(SEC_E_NO_CONTEXT),
|
||||
ERRSYM(SEC_E_PKU2U_CERT_FAILURE),
|
||||
ERRSYM(SEC_E_MUTUAL_AUTH_FAILED),
|
||||
ERRSYM(SEC_E_NO_SPM),
|
||||
ERRSYM(SEC_E_NOT_SUPPORTED),
|
||||
{0,0}
|
||||
};
|
||||
|
||||
void sspi_errmsg(int err, char *buf, size_t size)
|
||||
{
|
||||
size_t len,i;
|
||||
|
||||
buf[size - 1] = 0;
|
||||
for (i= 0; error_symbols[i].sym; i++)
|
||||
{
|
||||
if (error_symbols[i].error == err)
|
||||
{
|
||||
size_t len= strlen(error_symbols[i].sym);
|
||||
if (len + 2 < size)
|
||||
{
|
||||
memcpy(buf, error_symbols[i].sym, len);
|
||||
buf[len]= ' ';
|
||||
buf += len + 1;
|
||||
size-= len + 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
len = FormatMessageA(
|
||||
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
|
||||
err, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
|
||||
buf, (DWORD)size, NULL);
|
||||
|
||||
if(len > 0)
|
||||
{
|
||||
/* Trim trailing \n\r*/
|
||||
char *p;
|
||||
for(p= buf + len;p > buf && (*p == '\n' || *p=='\r' || *p == 0);p--)
|
||||
*p= 0;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user