| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
|
|
||
| option(ENABLE_SYSTEM_GMP "Use GMP from system" TRUE) | ||
| mark_as_advanced(GMP_LIBRARY GMP_INCLUDE_DIR) | ||
| set(USE_SYSTEM_GMP FALSE) | ||
|
|
||
| if(ENABLE_SYSTEM_GMP) | ||
| find_library(GMP_LIBRARY NAMES libgmp.so) | ||
| find_path(GMP_INCLUDE_DIR NAMES gmp.h) | ||
|
|
||
| if(GMP_LIBRARY AND GMP_INCLUDE_DIR) | ||
| message (STATUS "Using GMP provided by system.") | ||
| set(USE_SYSTEM_GMP TRUE) | ||
| else() | ||
| message (STATUS "Detecting GMP from system failed.") | ||
| endif() | ||
| else() | ||
| message (STATUS "Detecting GMP from system disabled! (ENABLE_SYSTEM_GMP=0)") | ||
| endif() | ||
|
|
||
| if(NOT USE_SYSTEM_GMP) | ||
| message(STATUS "Using bundled mini-gmp library.") | ||
| set(GMP_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/gmp) | ||
| set(GMP_LIBRARY gmp) | ||
| add_subdirectory(gmp) | ||
| endif() | ||
|
|
||
| include(FindPackageHandleStandardArgs) | ||
| find_package_handle_standard_args(GMP DEFAULT_MSG GMP_LIBRARY GMP_INCLUDE_DIR) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,10 +22,12 @@ with this program; if not, write to the Free Software Foundation, Inc., | |
| #include <sstream> | ||
| #include <IFileSystem.h> | ||
| #include "jthread/jmutexautolock.h" | ||
| #include "util/auth.h" | ||
| #include "util/directiontables.h" | ||
| #include "util/pointedthing.h" | ||
| #include "util/serialize.h" | ||
| #include "util/string.h" | ||
| #include "util/srp.h" | ||
| #include "client.h" | ||
| #include "network/clientopcodes.h" | ||
| #include "filesys.h" | ||
|
|
@@ -255,6 +257,8 @@ Client::Client( | |
| m_highlighted_pos(0,0,0), | ||
| m_map_seed(0), | ||
| m_password(password), | ||
| m_chosen_auth_mech(AUTH_MECHANISM_NONE), | ||
| m_auth_data(NULL), | ||
| m_access_denied(false), | ||
| m_itemdef_received(false), | ||
| m_nodedef_received(false), | ||
|
|
@@ -404,10 +408,13 @@ void Client::step(float dtime) | |
| memset(pName, 0, PLAYERNAME_SIZE * sizeof(char)); | ||
| memset(pPassword, 0, PASSWORD_SIZE * sizeof(char)); | ||
|
|
||
| std::string hashed_password = translatePassword(myplayer->getName(), m_password); | ||
| snprintf(pName, PLAYERNAME_SIZE, "%s", myplayer->getName()); | ||
| snprintf(pPassword, PASSWORD_SIZE, "%s", hashed_password.c_str()); | ||
|
|
||
| sendLegacyInit(pName, pPassword); | ||
| if (LATEST_PROTOCOL_VERSION >= 25) | ||
| sendInit(myplayer->getName()); | ||
| } | ||
|
|
||
| // Not connected, return | ||
|
|
@@ -943,6 +950,39 @@ void Client::interact(u8 action, const PointedThing& pointed) | |
| Send(&pkt); | ||
| } | ||
|
|
||
| void Client::deleteAuthData() | ||
| { | ||
| if (!m_auth_data) | ||
| return; | ||
|
|
||
| switch (m_chosen_auth_mech) { | ||
| case AUTH_MECHANISM_FIRST_SRP: | ||
| break; | ||
| case AUTH_MECHANISM_SRP: | ||
| case AUTH_MECHANISM_LEGACY_PASSWORD: | ||
| srp_user_delete((SRPUser *) m_auth_data); | ||
|
There was a problem hiding this comment. The rest of the code has no spaces between the cast and the expression being casted. |
||
| m_auth_data = NULL; | ||
| break; | ||
| case AUTH_MECHANISM_NONE: | ||
| break; | ||
| } | ||
| } | ||
|
|
||
|
|
||
| AuthMechanism Client::choseAuthMech(const u32 mechs) | ||
| { | ||
| if (mechs & AUTH_MECHANISM_SRP) | ||
| return AUTH_MECHANISM_SRP; | ||
|
|
||
| if (mechs & AUTH_MECHANISM_FIRST_SRP) | ||
| return AUTH_MECHANISM_FIRST_SRP; | ||
|
|
||
| if (mechs & AUTH_MECHANISM_LEGACY_PASSWORD) | ||
| return AUTH_MECHANISM_LEGACY_PASSWORD; | ||
|
|
||
| return AUTH_MECHANISM_NONE; | ||
| } | ||
|
|
||
| void Client::sendLegacyInit(const char* playerName, const char* playerPassword) | ||
| { | ||
| NetworkPacket pkt(TOSERVER_INIT_LEGACY, | ||
|
|
@@ -956,6 +996,70 @@ void Client::sendLegacyInit(const char* playerName, const char* playerPassword) | |
| Send(&pkt); | ||
| } | ||
|
|
||
| void Client::sendInit(const std::string &playerName) | ||
| { | ||
| NetworkPacket pkt(TOSERVER_INIT, 1 + 2 + 2 + (1 + playerName.size())); | ||
|
|
||
| // TODO (later) actually send supported compression modes | ||
| pkt << (u8) SER_FMT_VER_HIGHEST_READ << (u8) 42; | ||
| pkt << (u16) CLIENT_PROTOCOL_VERSION_MIN << (u16) CLIENT_PROTOCOL_VERSION_MAX; | ||
| pkt << playerName; | ||
|
|
||
| Send(&pkt); | ||
| } | ||
|
|
||
| void Client::startAuth(AuthMechanism chosen_auth_mechanism) | ||
| { | ||
| m_chosen_auth_mech = chosen_auth_mechanism; | ||
|
|
||
| switch (chosen_auth_mechanism) { | ||
| case AUTH_MECHANISM_FIRST_SRP: { | ||
| // send srp verifier to server | ||
| NetworkPacket resp_pkt(TOSERVER_FIRST_SRP, 0); | ||
| char *salt, *bytes_v; | ||
| std::size_t len_salt, len_v; | ||
| salt = NULL; | ||
| getSRPVerifier(getPlayerName(), m_password, | ||
| &salt, &len_salt, &bytes_v, &len_v); | ||
| resp_pkt | ||
| << std::string((char*)salt, len_salt) | ||
| << std::string((char*)bytes_v, len_v) | ||
| << (u8)((m_password == "") ? 1 : 0); | ||
| free(salt); | ||
| free(bytes_v); | ||
| Send(&resp_pkt); | ||
| break; | ||
| } | ||
| case AUTH_MECHANISM_SRP: | ||
| case AUTH_MECHANISM_LEGACY_PASSWORD: { | ||
| u8 based_on = 1; | ||
|
There was a problem hiding this comment. what does based_on do and why is it = 1? There was a problem hiding this comment. Consult networkprotocol.h. It includes documentation of all packets ever used by minetest. |
||
|
|
||
| if (chosen_auth_mechanism == AUTH_MECHANISM_LEGACY_PASSWORD) { | ||
| m_password = translatePassword(getPlayerName(), m_password); | ||
| based_on = 0; | ||
| } | ||
|
|
||
| std::string playername_u = lowercase(getPlayerName()); | ||
| m_auth_data = srp_user_new(SRP_SHA256, SRP_NG_2048, | ||
| getPlayerName().c_str(), playername_u.c_str(), | ||
| (const unsigned char *) m_password.c_str(), | ||
| m_password.length(), NULL, NULL); | ||
| char *bytes_A = 0; | ||
| size_t len_A = 0; | ||
| srp_user_start_authentication((struct SRPUser *) m_auth_data, | ||
| NULL, NULL, 0, (unsigned char **) &bytes_A, &len_A); | ||
|
|
||
| NetworkPacket resp_pkt(TOSERVER_SRP_BYTES_A, 0); | ||
| resp_pkt << std::string(bytes_A, len_A) << based_on; | ||
| free(bytes_A); | ||
| Send(&resp_pkt); | ||
| break; | ||
| } | ||
| case AUTH_MECHANISM_NONE: | ||
| break; // not handled in this method | ||
| } | ||
| } | ||
|
|
||
| void Client::sendDeletedBlocks(std::vector<v3s16> &blocks) | ||
| { | ||
| NetworkPacket pkt(TOSERVER_DELETEDBLOCKS, 1 + sizeof(v3s16) * blocks.size()); | ||
|
|
@@ -1066,24 +1170,30 @@ void Client::sendChangePassword(const std::string &oldpassword, | |
| const std::string &newpassword) | ||
| { | ||
| Player *player = m_env.getLocalPlayer(); | ||
| if (player == NULL) | ||
| return; | ||
|
|
||
| std::string playername = player->getName(); | ||
| if (m_proto_ver >= 25) { | ||
| // get into sudo mode and then send new password to server | ||
| m_password = oldpassword; | ||
| m_new_password = newpassword; | ||
| startAuth(choseAuthMech(m_sudo_auth_methods)); | ||
| } else { | ||
| std::string oldpwd = translatePassword(playername, oldpassword); | ||
| std::string newpwd = translatePassword(playername, newpassword); | ||
|
|
||
| NetworkPacket pkt(TOSERVER_PASSWORD_LEGACY, 2 * PASSWORD_SIZE); | ||
|
|
||
| for (u8 i = 0; i < PASSWORD_SIZE; i++) { | ||
| pkt << (u8) (i < oldpwd.length() ? oldpwd[i] : 0); | ||
| } | ||
|
|
||
| for (u8 i = 0; i < PASSWORD_SIZE; i++) { | ||
| pkt << (u8) (i < newpwd.length() ? newpwd[i] : 0); | ||
| } | ||
| Send(&pkt); | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| add_library(gmp mini-gmp.c) | ||
|
|
||
| target_link_libraries(gmp) | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,256 @@ | ||
| /* mini-gmp, a minimalistic implementation of a GNU GMP subset. | ||
| Copyright 2011, 2012, 2013 Free Software Foundation, Inc. | ||
| This file is part of the GNU MP Library. | ||
| The GNU MP Library is free software; you can redistribute it and/or modify | ||
| it under the terms of the GNU Lesser General Public License as published by | ||
| the Free Software Foundation; either version 3 of the License, or (at your | ||
| option) any later version. | ||
| The GNU MP 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 Lesser General Public | ||
| License for more details. | ||
| You should have received a copy of the GNU Lesser General Public License | ||
| along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ | ||
|
|
||
| /* About mini-gmp: This is a minimal implementation of a subset of the | ||
| GMP interface. It is intended for inclusion into applications which | ||
| have modest bignums needs, as a fallback when the real GMP library | ||
| is not installed. | ||
| This file defines the public interface. */ | ||
|
|
||
| #ifndef __MINI_GMP_H__ | ||
| #define __MINI_GMP_H__ | ||
|
|
||
| /* For size_t */ | ||
| #include <stddef.h> | ||
|
|
||
| #if defined (__cplusplus) | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| void mp_set_memory_functions (void *(*) (size_t), | ||
| void *(*) (void *, size_t, size_t), | ||
| void (*) (void *, size_t)); | ||
|
|
||
| void mp_get_memory_functions (void *(**) (size_t), | ||
| void *(**) (void *, size_t, size_t), | ||
| void (**) (void *, size_t)); | ||
|
|
||
| typedef unsigned long mp_limb_t; | ||
| typedef long mp_size_t; | ||
| typedef unsigned long mp_bitcnt_t; | ||
|
|
||
| typedef mp_limb_t *mp_ptr; | ||
| typedef const mp_limb_t *mp_srcptr; | ||
|
|
||
| typedef struct | ||
| { | ||
| int _mp_alloc; /* Number of *limbs* allocated and pointed | ||
| to by the _mp_d field. */ | ||
| int _mp_size; /* abs(_mp_size) is the number of limbs the | ||
| last field points to. If _mp_size is | ||
| negative this is a negative number. */ | ||
| mp_limb_t *_mp_d; /* Pointer to the limbs. */ | ||
| } __mpz_struct; | ||
|
|
||
| typedef __mpz_struct mpz_t[1]; | ||
|
|
||
| typedef __mpz_struct *mpz_ptr; | ||
| typedef const __mpz_struct *mpz_srcptr; | ||
|
|
||
| void mpn_copyi (mp_ptr, mp_srcptr, mp_size_t); | ||
| void mpn_copyd (mp_ptr, mp_srcptr, mp_size_t); | ||
|
|
||
| int mpn_cmp (mp_srcptr, mp_srcptr, mp_size_t); | ||
|
|
||
| mp_limb_t mpn_add_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t); | ||
| mp_limb_t mpn_add_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t); | ||
| mp_limb_t mpn_add (mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t); | ||
|
|
||
| mp_limb_t mpn_sub_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t); | ||
| mp_limb_t mpn_sub_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t); | ||
| mp_limb_t mpn_sub (mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t); | ||
|
|
||
| mp_limb_t mpn_mul_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t); | ||
| mp_limb_t mpn_addmul_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t); | ||
| mp_limb_t mpn_submul_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t); | ||
|
|
||
| mp_limb_t mpn_mul (mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t); | ||
| void mpn_mul_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t); | ||
| void mpn_sqr (mp_ptr, mp_srcptr, mp_size_t); | ||
|
|
||
| mp_limb_t mpn_lshift (mp_ptr, mp_srcptr, mp_size_t, unsigned int); | ||
| mp_limb_t mpn_rshift (mp_ptr, mp_srcptr, mp_size_t, unsigned int); | ||
|
|
||
| mp_limb_t mpn_invert_3by2 (mp_limb_t, mp_limb_t); | ||
| #define mpn_invert_limb(x) mpn_invert_3by2 ((x), 0) | ||
|
|
||
| size_t mpn_get_str (unsigned char *, int, mp_ptr, mp_size_t); | ||
| mp_size_t mpn_set_str (mp_ptr, const unsigned char *, size_t, int); | ||
|
|
||
| void mpz_init (mpz_t); | ||
| void mpz_init2 (mpz_t, mp_bitcnt_t); | ||
| void mpz_clear (mpz_t); | ||
|
|
||
| #define mpz_odd_p(z) (((z)->_mp_size != 0) & (int) (z)->_mp_d[0]) | ||
| #define mpz_even_p(z) (! mpz_odd_p (z)) | ||
|
|
||
| int mpz_sgn (const mpz_t); | ||
| int mpz_cmp_si (const mpz_t, long); | ||
| int mpz_cmp_ui (const mpz_t, unsigned long); | ||
| int mpz_cmp (const mpz_t, const mpz_t); | ||
| int mpz_cmpabs_ui (const mpz_t, unsigned long); | ||
| int mpz_cmpabs (const mpz_t, const mpz_t); | ||
| int mpz_cmp_d (const mpz_t, double); | ||
| int mpz_cmpabs_d (const mpz_t, double); | ||
|
|
||
| void mpz_abs (mpz_t, const mpz_t); | ||
| void mpz_neg (mpz_t, const mpz_t); | ||
| void mpz_swap (mpz_t, mpz_t); | ||
|
|
||
| void mpz_add_ui (mpz_t, const mpz_t, unsigned long); | ||
| void mpz_add (mpz_t, const mpz_t, const mpz_t); | ||
| void mpz_sub_ui (mpz_t, const mpz_t, unsigned long); | ||
| void mpz_ui_sub (mpz_t, unsigned long, const mpz_t); | ||
| void mpz_sub (mpz_t, const mpz_t, const mpz_t); | ||
|
|
||
| void mpz_mul_si (mpz_t, const mpz_t, long int); | ||
| void mpz_mul_ui (mpz_t, const mpz_t, unsigned long int); | ||
| void mpz_mul (mpz_t, const mpz_t, const mpz_t); | ||
| void mpz_mul_2exp (mpz_t, const mpz_t, mp_bitcnt_t); | ||
|
|
||
| void mpz_cdiv_qr (mpz_t, mpz_t, const mpz_t, const mpz_t); | ||
| void mpz_fdiv_qr (mpz_t, mpz_t, const mpz_t, const mpz_t); | ||
| void mpz_tdiv_qr (mpz_t, mpz_t, const mpz_t, const mpz_t); | ||
| void mpz_cdiv_q (mpz_t, const mpz_t, const mpz_t); | ||
| void mpz_fdiv_q (mpz_t, const mpz_t, const mpz_t); | ||
| void mpz_tdiv_q (mpz_t, const mpz_t, const mpz_t); | ||
| void mpz_cdiv_r (mpz_t, const mpz_t, const mpz_t); | ||
| void mpz_fdiv_r (mpz_t, const mpz_t, const mpz_t); | ||
| void mpz_tdiv_r (mpz_t, const mpz_t, const mpz_t); | ||
|
|
||
| void mpz_cdiv_q_2exp (mpz_t, const mpz_t, mp_bitcnt_t); | ||
| void mpz_fdiv_q_2exp (mpz_t, const mpz_t, mp_bitcnt_t); | ||
| void mpz_tdiv_q_2exp (mpz_t, const mpz_t, mp_bitcnt_t); | ||
| void mpz_cdiv_r_2exp (mpz_t, const mpz_t, mp_bitcnt_t); | ||
| void mpz_fdiv_r_2exp (mpz_t, const mpz_t, mp_bitcnt_t); | ||
| void mpz_tdiv_r_2exp (mpz_t, const mpz_t, mp_bitcnt_t); | ||
|
|
||
| void mpz_mod (mpz_t, const mpz_t, const mpz_t); | ||
|
|
||
| void mpz_divexact (mpz_t, const mpz_t, const mpz_t); | ||
|
|
||
| int mpz_divisible_p (const mpz_t, const mpz_t); | ||
|
|
||
| unsigned long mpz_cdiv_qr_ui (mpz_t, mpz_t, const mpz_t, unsigned long); | ||
| unsigned long mpz_fdiv_qr_ui (mpz_t, mpz_t, const mpz_t, unsigned long); | ||
| unsigned long mpz_tdiv_qr_ui (mpz_t, mpz_t, const mpz_t, unsigned long); | ||
| unsigned long mpz_cdiv_q_ui (mpz_t, const mpz_t, unsigned long); | ||
| unsigned long mpz_fdiv_q_ui (mpz_t, const mpz_t, unsigned long); | ||
| unsigned long mpz_tdiv_q_ui (mpz_t, const mpz_t, unsigned long); | ||
| unsigned long mpz_cdiv_r_ui (mpz_t, const mpz_t, unsigned long); | ||
| unsigned long mpz_fdiv_r_ui (mpz_t, const mpz_t, unsigned long); | ||
| unsigned long mpz_tdiv_r_ui (mpz_t, const mpz_t, unsigned long); | ||
| unsigned long mpz_cdiv_ui (const mpz_t, unsigned long); | ||
| unsigned long mpz_fdiv_ui (const mpz_t, unsigned long); | ||
| unsigned long mpz_tdiv_ui (const mpz_t, unsigned long); | ||
|
|
||
| unsigned long mpz_mod_ui (mpz_t, const mpz_t, unsigned long); | ||
|
|
||
| void mpz_divexact_ui (mpz_t, const mpz_t, unsigned long); | ||
|
|
||
| int mpz_divisible_ui_p (const mpz_t, unsigned long); | ||
|
|
||
| unsigned long mpz_gcd_ui (mpz_t, const mpz_t, unsigned long); | ||
| void mpz_gcd (mpz_t, const mpz_t, const mpz_t); | ||
| void mpz_gcdext (mpz_t, mpz_t, mpz_t, const mpz_t, const mpz_t); | ||
| void mpz_lcm_ui (mpz_t, const mpz_t, unsigned long); | ||
| void mpz_lcm (mpz_t, const mpz_t, const mpz_t); | ||
| int mpz_invert (mpz_t, const mpz_t, const mpz_t); | ||
|
|
||
| void mpz_sqrtrem (mpz_t, mpz_t, const mpz_t); | ||
| void mpz_sqrt (mpz_t, const mpz_t); | ||
|
|
||
| void mpz_pow_ui (mpz_t, const mpz_t, unsigned long); | ||
| void mpz_ui_pow_ui (mpz_t, unsigned long, unsigned long); | ||
| void mpz_powm (mpz_t, const mpz_t, const mpz_t, const mpz_t); | ||
| void mpz_powm_ui (mpz_t, const mpz_t, unsigned long, const mpz_t); | ||
|
|
||
| void mpz_rootrem (mpz_t, mpz_t, const mpz_t, unsigned long); | ||
| int mpz_root (mpz_t, const mpz_t, unsigned long); | ||
|
|
||
| void mpz_fac_ui (mpz_t, unsigned long); | ||
| void mpz_bin_uiui (mpz_t, unsigned long, unsigned long); | ||
|
|
||
| int mpz_tstbit (const mpz_t, mp_bitcnt_t); | ||
| void mpz_setbit (mpz_t, mp_bitcnt_t); | ||
| void mpz_clrbit (mpz_t, mp_bitcnt_t); | ||
| void mpz_combit (mpz_t, mp_bitcnt_t); | ||
|
|
||
| void mpz_com (mpz_t, const mpz_t); | ||
| void mpz_and (mpz_t, const mpz_t, const mpz_t); | ||
| void mpz_ior (mpz_t, const mpz_t, const mpz_t); | ||
| void mpz_xor (mpz_t, const mpz_t, const mpz_t); | ||
|
|
||
| mp_bitcnt_t mpz_popcount (const mpz_t); | ||
| mp_bitcnt_t mpz_hamdist (const mpz_t, const mpz_t); | ||
| mp_bitcnt_t mpz_scan0 (const mpz_t, mp_bitcnt_t); | ||
| mp_bitcnt_t mpz_scan1 (const mpz_t, mp_bitcnt_t); | ||
|
|
||
| int mpz_fits_slong_p (const mpz_t); | ||
| int mpz_fits_ulong_p (const mpz_t); | ||
| long int mpz_get_si (const mpz_t); | ||
| unsigned long int mpz_get_ui (const mpz_t); | ||
| double mpz_get_d (const mpz_t); | ||
| size_t mpz_size (const mpz_t); | ||
| mp_limb_t mpz_getlimbn (const mpz_t, mp_size_t); | ||
|
|
||
| void mpz_set_si (mpz_t, signed long int); | ||
| void mpz_set_ui (mpz_t, unsigned long int); | ||
| void mpz_set (mpz_t, const mpz_t); | ||
| void mpz_set_d (mpz_t, double); | ||
|
|
||
| void mpz_init_set_si (mpz_t, signed long int); | ||
| void mpz_init_set_ui (mpz_t, unsigned long int); | ||
| void mpz_init_set (mpz_t, const mpz_t); | ||
| void mpz_init_set_d (mpz_t, double); | ||
|
|
||
| size_t mpz_sizeinbase (const mpz_t, int); | ||
| char *mpz_get_str (char *, int, const mpz_t); | ||
| int mpz_set_str (mpz_t, const char *, int); | ||
| int mpz_init_set_str (mpz_t, const char *, int); | ||
|
|
||
| /* This long list taken from gmp.h. */ | ||
| /* For reference, "defined(EOF)" cannot be used here. In g++ 2.95.4, | ||
| <iostream> defines EOF but not FILE. */ | ||
| #if defined (FILE) \ | ||
| || defined (H_STDIO) \ | ||
| || defined (_H_STDIO) /* AIX */ \ | ||
| || defined (_STDIO_H) /* glibc, Sun, SCO */ \ | ||
| || defined (_STDIO_H_) /* BSD, OSF */ \ | ||
| || defined (__STDIO_H) /* Borland */ \ | ||
| || defined (__STDIO_H__) /* IRIX */ \ | ||
| || defined (_STDIO_INCLUDED) /* HPUX */ \ | ||
| || defined (__dj_include_stdio_h_) /* DJGPP */ \ | ||
| || defined (_FILE_DEFINED) /* Microsoft */ \ | ||
| || defined (__STDIO__) /* Apple MPW MrC */ \ | ||
| || defined (_MSL_STDIO_H) /* Metrowerks */ \ | ||
| || defined (_STDIO_H_INCLUDED) /* QNX4 */ \ | ||
| || defined (_ISO_STDIO_ISO_H) /* Sun C++ */ \ | ||
| || defined (__STDIO_LOADED) /* VMS */ | ||
| size_t mpz_out_str (FILE *, int, const mpz_t); | ||
| #endif | ||
|
|
||
| void mpz_import (mpz_t, size_t, int, size_t, int, size_t, const void *); | ||
| void *mpz_export (void *, size_t *, int, size_t, int, size_t, const mpz_t); | ||
|
|
||
| #if defined (__cplusplus) | ||
| } | ||
| #endif | ||
| #endif /* __MINI_GMP_H__ */ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,14 @@ | ||
| set(UTIL_SRCS | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/auth.cpp | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/base64.cpp | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/directiontables.cpp | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/numeric.cpp | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/pointedthing.cpp | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/serialize.cpp | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/sha1.cpp | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/sha256.c | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/string.cpp | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/srp.cpp | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/timetaker.cpp | ||
| PARENT_SCOPE) | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| /* | ||
| Minetest | ||
| Copyright (C) 2015 est31 <MTest31@outlook.com> | ||
| This program is free software; you can redistribute it and/or modify | ||
| it under the terms of the GNU Lesser General Public License as published by | ||
| the Free Software Foundation; either version 2.1 of the License, or | ||
| (at your option) any later version. | ||
| 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 Lesser General Public License for more details. | ||
| You should have received a copy of the GNU Lesser General Public License along | ||
| with this program; if not, write to the Free Software Foundation, Inc., | ||
| 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| */ | ||
|
|
||
| #include <algorithm> | ||
| #include <string> | ||
| #include "auth.h" | ||
| #include "base64.h" | ||
| #include "sha1.h" | ||
| #include "srp.h" | ||
| #include "string.h" | ||
|
|
||
| // Get an sha-1 hash of the player's name combined with | ||
| // the password entered. That's what the server uses as | ||
| // their password. (Exception : if the password field is | ||
| // blank, we send a blank password - this is for backwards | ||
| // compatibility with password-less players). | ||
| std::string translatePassword(const std::string &name, | ||
| const std::string &password) | ||
| { | ||
| if (password.length() == 0) | ||
| return ""; | ||
|
|
||
| std::string slt = name + password; | ||
| SHA1 sha1; | ||
| sha1.addBytes(slt.c_str(), slt.length()); | ||
| unsigned char *digest = sha1.getDigest(); | ||
| std::string pwd = base64_encode(digest, 20); | ||
| free(digest); | ||
| return pwd; | ||
| } | ||
|
|
||
| void getSRPVerifier(const std::string &name, | ||
| const std::string &password, char **salt, size_t *salt_len, | ||
| char **bytes_v, size_t *len_v) | ||
| { | ||
| std::string n_name = lowercase(name); | ||
| srp_create_salted_verification_key(SRP_SHA256, SRP_NG_2048, | ||
| n_name.c_str(), (const unsigned char *)password.c_str(), | ||
| password.size(), (unsigned char **)salt, salt_len, | ||
| (unsigned char **)bytes_v, len_v, NULL, NULL); | ||
| } | ||
|
|
||
| // Get a db-ready SRP verifier | ||
| // The salt param is only modifyable by this method so that you can free it | ||
| // if it was allocated. You shouldn't use it for other purposes, as you will | ||
| // need the contents of salt_len too. | ||
| inline static std::string getSRPVerifier(const std::string &name, | ||
| const std::string &password, char ** salt, size_t salt_len) | ||
| { | ||
| char * bytes_v = NULL; | ||
| size_t len_v; | ||
| getSRPVerifier(name, password, salt, &salt_len, | ||
| &bytes_v, &len_v); | ||
| std::string ret_val = encodeSRPVerifier(std::string(bytes_v, len_v), | ||
| std::string(*salt, salt_len)); | ||
| free(bytes_v); | ||
| return ret_val; | ||
| } | ||
|
|
||
| // Get a db-ready SRP verifier | ||
| std::string getSRPVerifier(const std::string &name, | ||
| const std::string &password) | ||
| { | ||
| char * salt = NULL; | ||
| std::string ret_val = getSRPVerifier(name, | ||
| password, &salt, 0); | ||
| free(salt); | ||
| return ret_val; | ||
| } | ||
|
|
||
| // Get a db-ready SRP verifier | ||
| std::string getSRPVerifier(const std::string &name, | ||
| const std::string &password, const std::string &salt) | ||
| { | ||
| // The implementation won't change the salt if its set, | ||
| // therefore we can cast. | ||
| char *salt_cstr = (char *)salt.c_str(); | ||
| return getSRPVerifier(name, password, | ||
| &salt_cstr, salt.size()); | ||
| } | ||
|
|
||
| // Make a SRP verifier db-ready | ||
| std::string encodeSRPVerifier(const std::string &verifier, | ||
| const std::string &salt) | ||
| { | ||
| std::ostringstream ret_str; | ||
| ret_str << "#1#" | ||
| << base64_encode((unsigned char*) salt.c_str(), salt.size()) << "#" | ||
| << base64_encode((unsigned char*) verifier.c_str(), verifier.size()); | ||
| return ret_str.str(); | ||
| } | ||
|
|
||
| bool decodeSRPVerifier(const std::string &enc_pwd, | ||
| std::string *salt, std::string *bytes_v) | ||
| { | ||
| std::vector<std::string> pwd_components = str_split(enc_pwd, '#'); | ||
|
|
||
| if ((pwd_components.size() != 4) | ||
| || (pwd_components[1] != "1") // 1 means srp | ||
| || !base64_is_valid(pwd_components[2]) | ||
| || !base64_is_valid(pwd_components[3])) | ||
| return false; | ||
|
|
||
| std::string salt_str = base64_decode(pwd_components[2]); | ||
| std::string bytes_v_str = base64_decode(pwd_components[3]); | ||
| *salt = salt_str; | ||
| *bytes_v = bytes_v_str; | ||
| return true; | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| /* | ||
| Minetest | ||
| Copyright (C) 2015 est31 <MTest31@outlook.com> | ||
| This program is free software; you can redistribute it and/or modify | ||
| it under the terms of the GNU Lesser General Public License as published by | ||
| the Free Software Foundation; either version 2.1 of the License, or | ||
| (at your option) any later version. | ||
| 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 Lesser General Public License for more details. | ||
| You should have received a copy of the GNU Lesser General Public License along | ||
| with this program; if not, write to the Free Software Foundation, Inc., | ||
| 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| */ | ||
|
|
||
| #ifndef AUTH_H | ||
| #define AUTH_H | ||
|
|
||
| std::string translatePassword(const std::string &name, | ||
| const std::string &password); | ||
| void getSRPVerifier(const std::string &name, | ||
| const std::string &password, char **salt, size_t *salt_len, | ||
| char **bytes_v, size_t *len_v); | ||
| std::string getSRPVerifier(const std::string &name, | ||
| const std::string &password); | ||
| std::string getSRPVerifier(const std::string &name, | ||
| const std::string &password, const std::string &salt); | ||
| std::string encodeSRPVerifier(const std::string &verifier, | ||
| const std::string &salt); | ||
| bool decodeSRPVerifier(const std::string &enc_pwd, | ||
| std::string *salt, std::string *bytes_v); | ||
|
|
||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| /* crypto/sha/sha.h */ | ||
| /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| * All rights reserved. | ||
| * | ||
| * This package is an SSL implementation written | ||
| * by Eric Young (eay@cryptsoft.com). | ||
| * The implementation was written so as to conform with Netscapes SSL. | ||
| * | ||
| * This library is free for commercial and non-commercial use as long as | ||
| * the following conditions are aheared to. The following conditions | ||
| * apply to all code found in this distribution, be it the RC4, RSA, | ||
| * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| * included with this distribution is covered by the same copyright terms | ||
| * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| * | ||
| * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| * the code are not to be removed. | ||
| * If this package is used in a product, Eric Young should be given attribution | ||
| * as the author of the parts of the library used. | ||
| * This can be in the form of a textual message at program startup or | ||
| * in documentation (online or textual) provided with the package. | ||
| * | ||
| * 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 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. | ||
| * 3. All advertising materials mentioning features or use of this software | ||
| * must display the following acknowledgement: | ||
| * "This product includes cryptographic software written by | ||
| * Eric Young (eay@cryptsoft.com)" | ||
| * The word 'cryptographic' can be left out if the rouines from the library | ||
| * being used are not cryptographic related :-). | ||
| * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| * the apps directory (application code) you must include an acknowledgement: | ||
| * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| * | ||
| * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``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 AUTHOR 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. | ||
| * | ||
| * The licence and distribution terms for any publically available version or | ||
| * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| * copied and put under another distribution licence | ||
| * [including the GNU Public Licence.] | ||
| */ | ||
|
|
||
| #ifndef HEADER_SHA_H | ||
| # define HEADER_SHA_H | ||
|
|
||
| # include <stddef.h> | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| # if defined(OPENSSL_NO_SHA) || (defined(OPENSSL_NO_SHA0) && defined(OPENSSL_NO_SHA1)) | ||
| # error SHA is disabled. | ||
| # endif | ||
|
|
||
| # if defined(OPENSSL_FIPS) | ||
| # define FIPS_SHA_SIZE_T size_t | ||
| # endif | ||
|
|
||
| /* | ||
| Compat stuff from OpenSSL land | ||
| */ | ||
|
|
||
| /* crypto.h */ | ||
|
|
||
| # define fips_md_init(alg) fips_md_init_ctx(alg, alg) | ||
|
|
||
| # define fips_md_init_ctx(alg, cx) \ | ||
| int alg##_Init(cx##_CTX *c) | ||
| # define fips_cipher_abort(alg) while(0) | ||
|
|
||
| /*- | ||
| * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| * ! SHA_LONG has to be at least 32 bits wide. If it's wider, then ! | ||
| * ! SHA_LONG_LOG2 has to be defined along. ! | ||
| * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| */ | ||
|
|
||
| # if defined(__LP32__) | ||
| # define SHA_LONG unsigned long | ||
| # elif defined(__ILP64__) | ||
| # define SHA_LONG unsigned long | ||
| # define SHA_LONG_LOG2 3 | ||
| # else | ||
| # define SHA_LONG unsigned int | ||
| # endif | ||
|
|
||
| # define SHA_LBLOCK 16 | ||
| # define SHA_CBLOCK (SHA_LBLOCK*4)/* SHA treats input data as a | ||
| * contiguous array of 32 bit wide | ||
| * big-endian values. */ | ||
| # define SHA_LAST_BLOCK (SHA_CBLOCK-8) | ||
| # define SHA_DIGEST_LENGTH 20 | ||
|
|
||
| typedef struct SHAstate_st { | ||
| SHA_LONG h0, h1, h2, h3, h4; | ||
| SHA_LONG Nl, Nh; | ||
| SHA_LONG data[SHA_LBLOCK]; | ||
| unsigned int num; | ||
| } SHA_CTX; | ||
|
|
||
| # define SHA256_CBLOCK (SHA_LBLOCK*4)/* SHA-256 treats input data as a | ||
| * contiguous array of 32 bit wide | ||
| * big-endian values. */ | ||
| # define SHA224_DIGEST_LENGTH 28 | ||
| # define SHA256_DIGEST_LENGTH 32 | ||
|
|
||
| typedef struct SHA256state_st { | ||
| SHA_LONG h[8]; | ||
| SHA_LONG Nl, Nh; | ||
| SHA_LONG data[SHA_LBLOCK]; | ||
| unsigned int num, md_len; | ||
| } SHA256_CTX; | ||
|
|
||
| # ifndef OPENSSL_NO_SHA256 | ||
| # ifdef OPENSSL_FIPS | ||
| int private_SHA224_Init(SHA256_CTX *c); | ||
| int private_SHA256_Init(SHA256_CTX *c); | ||
| # endif | ||
| int SHA224_Init(SHA256_CTX *c); | ||
| int SHA224_Update(SHA256_CTX *c, const void *data, size_t len); | ||
| int SHA224_Final(unsigned char *md, SHA256_CTX *c); | ||
| unsigned char *SHA224(const unsigned char *d, size_t n, unsigned char *md); | ||
| int SHA256_Init(SHA256_CTX *c); | ||
| int SHA256_Update(SHA256_CTX *c, const void *data, size_t len); | ||
| int SHA256_Final(unsigned char *md, SHA256_CTX *c); | ||
| unsigned char *SHA256(const unsigned char *d, size_t n, unsigned char *md); | ||
| void SHA256_Transform(SHA256_CTX *c, const unsigned char *data); | ||
| # endif | ||
|
|
||
| # define SHA384_DIGEST_LENGTH 48 | ||
| # define SHA512_DIGEST_LENGTH 64 | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,171 @@ | ||
| /* | ||
| * Secure Remote Password 6a implementation | ||
| * https://github.com/est31/csrp-gmp | ||
| * | ||
| * The MIT License (MIT) | ||
| * | ||
| * Copyright (c) 2010, 2013 Tom Cocagne, 2015 est31 <MTest31@outlook.com> | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
| * this software and associated documentation files (the "Software"), to deal in | ||
| * the Software without restriction, including without limitation the rights to | ||
| * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
| * of the Software, and to permit persons to whom the Software is furnished to do | ||
| * so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in all | ||
| * copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| * SOFTWARE. | ||
| * | ||
| */ | ||
|
|
||
| /* | ||
| * | ||
| * Purpose: This is a direct implementation of the Secure Remote Password | ||
| * Protocol version 6a as described by | ||
| * http://srp.stanford.edu/design.html | ||
| * | ||
| * Author: tom.cocagne@gmail.com (Tom Cocagne) | ||
| * | ||
| * Dependencies: LibGMP | ||
| * | ||
| * Usage: Refer to test_srp.c for a demonstration | ||
| * | ||
| * Notes: | ||
| * This library allows multiple combinations of hashing algorithms and | ||
| * prime number constants. For authentication to succeed, the hash and | ||
| * prime number constants must match between | ||
| * srp_create_salted_verification_key(), srp_user_new(), | ||
| * and srp_verifier_new(). A recommended approach is to determine the | ||
| * desired level of security for an application and globally define the | ||
| * hash and prime number constants to the predetermined values. | ||
| * | ||
| * As one might suspect, more bits means more security. As one might also | ||
| * suspect, more bits also means more processing time. The test_srp.c | ||
| * program can be easily modified to profile various combinations of | ||
| * hash & prime number pairings. | ||
| */ | ||
|
|
||
| #ifndef SRP_H | ||
| #define SRP_H | ||
|
|
||
|
|
||
| struct SRPVerifier; | ||
| struct SRPUser; | ||
|
|
||
| typedef enum | ||
| { | ||
| SRP_NG_1024, | ||
| SRP_NG_2048, | ||
| SRP_NG_4096, | ||
| SRP_NG_8192, | ||
| SRP_NG_CUSTOM | ||
| } SRP_NGType; | ||
|
|
||
| typedef enum | ||
| { | ||
| /*SRP_SHA1,*/ | ||
| /*SRP_SHA224,*/ | ||
| SRP_SHA256, | ||
| /*SRP_SHA384, | ||
| SRP_SHA512*/ | ||
| } SRP_HashAlgorithm; | ||
|
|
||
| /* Out: bytes_v, len_v | ||
| * | ||
| * The caller is responsible for freeing the memory allocated for bytes_v | ||
| * | ||
| * The n_hex and g_hex parameters should be 0 unless SRP_NG_CUSTOM is used for ng_type. | ||
| * If provided, they must contain ASCII text of the hexidecimal notation. | ||
| * | ||
| * If bytes_s == NULL, it is filled with random data. The caller is responsible for freeing. | ||
| */ | ||
| void srp_create_salted_verification_key( SRP_HashAlgorithm alg, | ||
| SRP_NGType ng_type, const char *username_for_verifier, | ||
| const unsigned char *password, size_t len_password, | ||
| unsigned char **bytes_s, size_t *len_s, | ||
| unsigned char **bytes_v, size_t *len_v, | ||
| const char * n_hex, const char *g_hex ); | ||
|
|
||
| /* Out: bytes_B, len_B. | ||
| * | ||
| * On failure, bytes_B will be set to NULL and len_B will be set to 0 | ||
| * | ||
| * The n_hex and g_hex parameters should be 0 unless SRP_NG_CUSTOM is used for ng_type | ||
| * | ||
| * If bytes_b == NULL, random data is used for b. | ||
| */ | ||
| struct SRPVerifier* srp_verifier_new(SRP_HashAlgorithm alg, SRP_NGType ng_type, | ||
| const char *username, | ||
| const unsigned char *bytes_s, size_t len_s, | ||
| const unsigned char *bytes_v, size_t len_v, | ||
| const unsigned char *bytes_A, size_t len_A, | ||
| const unsigned char *bytes_b, size_t len_b, | ||
| unsigned char** bytes_B, size_t *len_B, | ||
| const char* n_hex, const char* g_hex); | ||
|
|
||
|
|
||
| void srp_verifier_delete( struct SRPVerifier* ver ); | ||
|
|
||
|
|
||
| int srp_verifier_is_authenticated( struct SRPVerifier* ver ); | ||
|
|
||
|
|
||
| const char * srp_verifier_get_username( struct SRPVerifier* ver ); | ||
|
|
||
| /* key_length may be null */ | ||
| const unsigned char* srp_verifier_get_session_key( struct SRPVerifier* ver, | ||
| size_t *key_length ); | ||
|
|
||
|
|
||
| size_t srp_verifier_get_session_key_length(struct SRPVerifier* ver); | ||
|
|
||
|
|
||
| /* user_M must be exactly srp_verifier_get_session_key_length() bytes in size */ | ||
| void srp_verifier_verify_session( struct SRPVerifier* ver, | ||
| const unsigned char* user_M, unsigned char** bytes_HAMK ); | ||
|
|
||
| /*******************************************************************************/ | ||
|
|
||
| /* The n_hex and g_hex parameters should be 0 unless SRP_NG_CUSTOM is used for ng_type */ | ||
| struct SRPUser *srp_user_new(SRP_HashAlgorithm alg, SRP_NGType ng_type, | ||
| const char *username, const char *username_for_verifier, | ||
| const unsigned char *bytes_password, size_t len_password, | ||
| const char *n_hex, const char *g_hex); | ||
|
|
||
| void srp_user_delete(struct SRPUser * usr); | ||
|
|
||
| int srp_user_is_authenticated(struct SRPUser * usr); | ||
|
|
||
|
|
||
| const char* srp_user_get_username(struct SRPUser * usr); | ||
|
|
||
| /* key_length may be null */ | ||
| const unsigned char* srp_user_get_session_key(struct SRPUser* usr, size_t* key_length); | ||
|
|
||
| size_t srp_user_get_session_key_length(struct SRPUser* usr); | ||
|
|
||
| /* Output: username, bytes_A, len_A. If you don't want it get written, set username to NULL. | ||
| * If bytes_a == NULL, random data is used for a. */ | ||
| void srp_user_start_authentication(struct SRPUser* usr, char** username, | ||
| const unsigned char* bytes_a, size_t len_a, | ||
| unsigned char** bytes_A, size_t* len_A); | ||
|
|
||
| /* Output: bytes_M, len_M (len_M may be null and will always be | ||
| * srp_user_get_session_key_length() bytes in size) */ | ||
| void srp_user_process_challenge(struct SRPUser *usr, | ||
| const unsigned char *bytes_s, size_t len_s, | ||
| const unsigned char *bytes_B, size_t len_B, | ||
| unsigned char **bytes_M, size_t *len_M); | ||
|
|
||
| /* bytes_HAMK must be exactly srp_user_get_session_key_length() bytes in size */ | ||
| void srp_user_verify_session(struct SRPUser* usr, const unsigned char* bytes_HAMK); | ||
|
|
||
| #endif /* Include Guard */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should auth.cpp/h and srp.c/h really be in util?? They do take on larger roles than utility functions, you know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so you mean in src itself? Its so cramped there..., and the file is also included by l_util.cpp. network isn't good either because its not low level network related (like networkpacket) nor spanning a wide range of topics (like clientpackethandler).