diff options
Diffstat (limited to '3rd_party')
| -rw-r--r-- | 3rd_party/ed25519/Makefile.am | 9 | ||||
| -rw-r--r-- | 3rd_party/ed25519/seed.c | 2 | ||||
| -rw-r--r-- | 3rd_party/libsrp6a-sha512/Makefile.am | 15 | ||||
| -rw-r--r-- | 3rd_party/libsrp6a-sha512/cstr.c | 62 | ||||
| -rw-r--r-- | 3rd_party/libsrp6a-sha512/cstr.h | 14 | ||||
| -rw-r--r-- | 3rd_party/libsrp6a-sha512/t_conv.c | 35 | ||||
| -rw-r--r-- | 3rd_party/libsrp6a-sha512/t_defines.h | 4 | ||||
| -rw-r--r-- | 3rd_party/libsrp6a-sha512/t_math.c | 122 | ||||
| -rw-r--r-- | 3rd_party/libsrp6a-sha512/t_misc.c | 33 | ||||
| -rw-r--r-- | 3rd_party/libsrp6a-sha512/t_sha.c | 40 | ||||
| -rw-r--r-- | 3rd_party/libsrp6a-sha512/t_sha.h | 24 | ||||
| -rw-r--r-- | 3rd_party/libsrp6a-sha512/t_truerand.c | 11 | 
12 files changed, 157 insertions, 214 deletions
| diff --git a/3rd_party/ed25519/Makefile.am b/3rd_party/ed25519/Makefile.am index c475331..438cb53 100644 --- a/3rd_party/ed25519/Makefile.am +++ b/3rd_party/ed25519/Makefile.am @@ -6,7 +6,7 @@ AM_CPPFLAGS = \  AM_CFLAGS = \  	$(GLOBAL_CFLAGS) \ -	$(openssl_CFLAGS) +	$(ssl_lib_CFLAGS)  AM_LDFLAGS = @@ -15,12 +15,19 @@ libed25519_la_LIBADD =  libed25519_la_LDFLAGS = $(AM_LDFLAGS) -no-undefined  libed25519_la_SOURCES = \  	add_scalar.c \ +	ed25519.h \  	fe.c \ +	fe.h \ +	fixedint.h \  	ge.c \ +	ge.h \  	keypair.c \  	key_exchange.c \ +	precomp_data.h \  	sc.c \ +	sc.h \  	seed.c \  	sign.c \          sha512.c \ +	sha512.h \  	verify.c diff --git a/3rd_party/ed25519/seed.c b/3rd_party/ed25519/seed.c index 11a2e3e..cf252b8 100644 --- a/3rd_party/ed25519/seed.c +++ b/3rd_party/ed25519/seed.c @@ -30,7 +30,7 @@ int ed25519_create_seed(unsigned char *seed) {          return 1;      } -    fread(seed, 1, 32, f); +    if(fread(seed, 1, 32, f)){}      fclose(f);  #endif diff --git a/3rd_party/libsrp6a-sha512/Makefile.am b/3rd_party/libsrp6a-sha512/Makefile.am index 8c6e2f5..bdacb5f 100644 --- a/3rd_party/libsrp6a-sha512/Makefile.am +++ b/3rd_party/libsrp6a-sha512/Makefile.am @@ -5,11 +5,9 @@ AM_CPPFLAGS = \          -I$(top_srcdir) \          -Wno-incompatible-pointer-types -include_HEADERS = srp.h srp_aux.h cstr.h -  AM_CFLAGS = -DHAVE_CONFIG_H  if HAVE_OPENSSL -AM_CFLAGS += -DOPENSSL=1 -DOPENSSL_ENGINE=1 $(openssl_CFLAGS) +AM_CFLAGS += -DOPENSSL=1 $(openssl_CFLAGS)  else  if HAVE_GCRYPT  AM_CFLAGS += -DGCRYPT=1 $(libgcrypt_CFLAGS) @@ -25,7 +23,10 @@ noinst_LTLIBRARIES = libsrp6a-sha512.la  libsrp6a_sha512_la_SOURCES = \    t_conv.c t_math.c t_misc.c \    t_truerand.c cstr.c \ -  srp.c srp6a_sha512_client.c -if !HAVE_OPENSSL -libsrp6a_sha512_la_SOURCES += t_sha.c -endif +  srp.c srp6a_sha512_client.c \ +  srp.h srp_aux.h cstr.h \ +  t_defines.h t_pwd.h \ +  t_sha.c t_sha.h +#if !HAVE_OPENSSL +#libsrp6a_sha512_la_SOURCES += t_sha.c +#endif diff --git a/3rd_party/libsrp6a-sha512/cstr.c b/3rd_party/libsrp6a-sha512/cstr.c index 9856f46..58a5638 100644 --- a/3rd_party/libsrp6a-sha512/cstr.c +++ b/3rd_party/libsrp6a-sha512/cstr.c @@ -8,72 +8,31 @@  #define MINSIZE		4		/* Absolute minimum - one word */  static char cstr_empty_string[] = { '\0' }; -static cstr_allocator * default_alloc = NULL; - -/* - * It is assumed, for efficiency, that it is okay to pass more arguments - * to a function than are called for, as long as the required arguments - * are in proper form.  If extra arguments to malloc() and free() cause - * problems, define PEDANTIC_ARGS below. - */ -#ifdef PEDANTIC_ARGS -static void * Cmalloc(int n, void * heap) { return malloc(n); } -static void Cfree(void * p, void * heap) { free(p); } -static cstr_allocator malloc_allocator = { Cmalloc, Cfree, NULL }; -#else -static cstr_allocator malloc_allocator = { malloc, free, NULL }; -#endif - -_TYPE( void ) -cstr_set_allocator(cstr_allocator * alloc) -{ -  default_alloc = alloc; -}  _TYPE( cstr * ) -cstr_new_alloc(cstr_allocator * alloc) +cstr_new()  {    cstr * str; -  if(alloc == NULL) { -    if(default_alloc == NULL) { -      default_alloc = &malloc_allocator; -    } -    alloc = default_alloc; -  } - -  str = (cstr *) (*alloc->alloc)(sizeof(cstr), alloc->heap); +  str = (cstr *) malloc(sizeof(cstr));    if(str) {      str->data = cstr_empty_string;      str->length = str->cap = 0;      str->ref = 1; -    str->allocator = alloc;    }    return str;  }  _TYPE( cstr * ) -cstr_new() -{ -  return cstr_new_alloc(NULL); -} - -_TYPE( cstr * ) -cstr_dup_alloc(const cstr * str, cstr_allocator * alloc) +cstr_dup(const cstr * str)  { -  cstr * nstr = cstr_new_alloc(alloc); +  cstr * nstr = cstr_new();    if(nstr)      cstr_setn(nstr, str->data, str->length);    return nstr;  }  _TYPE( cstr * ) -cstr_dup(const cstr * str) -{ -  return cstr_dup_alloc(str, NULL); -} - -_TYPE( cstr * )  cstr_create(const char * s)  {    return cstr_createn(s, strlen(s)); @@ -101,9 +60,9 @@ cstr_clear_free(cstr * str)    if(--str->ref == 0) {      if(str->cap > 0) {        memset(str->data, 0, str->cap); -      (*str->allocator->free)(str->data, str->allocator->heap); +      free(str->data);      } -    (*str->allocator->free)(str, str->allocator->heap); +    free(str);    }  } @@ -112,8 +71,8 @@ cstr_free(cstr * str)  {    if(--str->ref == 0) {      if(str->cap > 0) -      (*str->allocator->free)(str->data, str->allocator->heap); -    (*str->allocator->free)(str, str->allocator->heap); +      free(str->data); +    free(str);    }  } @@ -121,7 +80,7 @@ _TYPE( void )  cstr_empty(cstr * str)  {    if(str->cap > 0) -    (*str->allocator->free)(str->data, str->allocator->heap); +    free(str->data);    str->data = cstr_empty_string;    str->length = str->cap = 0;  } @@ -137,8 +96,7 @@ cstr_alloc(cstr * str, int len)      if(len < MINSIZE)        len = MINSIZE; -    t = (char *) (*str->allocator->alloc)(len * sizeof(char), -					  str->allocator->heap); +    t = (char *) malloc(len * sizeof(char));      if(t) {        if(str->data) {  	t[str->length] = 0; diff --git a/3rd_party/libsrp6a-sha512/cstr.h b/3rd_party/libsrp6a-sha512/cstr.h index 7cc019a..29afea7 100644 --- a/3rd_party/libsrp6a-sha512/cstr.h +++ b/3rd_party/libsrp6a-sha512/cstr.h @@ -38,7 +38,7 @@  #define _MSVC15DEXPORT  #define _MSVC20EXPORT  #define _DLLAPI -#if defined(WINDOWS) || defined(WIN32) +#if defined(WINDOWS) || defined(_WIN32)  #define _CDECL _cdecl  #else  #define _CDECL @@ -51,27 +51,15 @@  extern "C" {  #endif /* __cplusplus */ -/* Arguments to allocator methods ordered this way for compatibility */ -typedef struct cstr_alloc_st { -  void * (_CDECL * alloc)(size_t n, void * heap); -  void (_CDECL * free)(void * p, void * heap); -  void * heap; -} cstr_allocator; -  typedef struct cstr_st {    char * data;	/* Okay to access data and length fields directly */    int length;    int cap;    int ref;	/* Simple reference counter */ -  cstr_allocator * allocator;  } cstr; -_TYPE( void ) cstr_set_allocator P((cstr_allocator * alloc)); -  _TYPE( cstr * ) cstr_new P((void)); -_TYPE( cstr * ) cstr_new_alloc P((cstr_allocator * alloc));  _TYPE( cstr * ) cstr_dup P((const cstr * str)); -_TYPE( cstr * ) cstr_dup_alloc P((const cstr * str, cstr_allocator * alloc));  _TYPE( cstr * ) cstr_create P((const char * s));  _TYPE( cstr * ) cstr_createn P((const char * s, int len)); diff --git a/3rd_party/libsrp6a-sha512/t_conv.c b/3rd_party/libsrp6a-sha512/t_conv.c index f7f50e2..76d4e58 100644 --- a/3rd_party/libsrp6a-sha512/t_conv.c +++ b/3rd_party/libsrp6a-sha512/t_conv.c @@ -33,8 +33,7 @@  #include "cstr.h"  static int -hexDigitToInt(c) -     char c; +hexDigitToInt(char c)  {    if(c >= '0' && c <= '9')      return c - '0'; @@ -50,9 +49,7 @@ hexDigitToInt(c)   * Convert a hex string to a string of bytes; return size of dst   */  _TYPE( int ) -t_fromhex(dst, src) -     char * dst; -     const char * src; +t_fromhex(char *dst, const char *src)  {    register char *chp = dst;    register unsigned size = strlen(src); @@ -76,10 +73,7 @@ t_fromhex(dst, src)   * Convert a string of bytes to their hex representation   */  _TYPE( char * ) -t_tohex(dst, src, size) -     char * dst; -     const char * src; -     unsigned size; +t_tohex(char *dst, const char *src, unsigned size)  {     int notleading = 0; @@ -103,10 +97,7 @@ t_tohex(dst, src, size)  }  _TYPE( char * ) -t_tohexcstr(dst, src, size) -     cstr * dst; -     const char * src; -     unsigned size; +t_tohexcstr(cstr *dst, const char *src, unsigned size)  {    cstr_set_length(dst, 2 * size + 1);    return t_tohex(dst->data, src, size); @@ -119,9 +110,7 @@ static char b64table[] =   * Convert a base64 string into raw byte array representation.   */  _TYPE( int ) -t_fromb64(dst, src) -     char * dst; -     const char * src; +t_fromb64(char *dst, const char *src)  {    unsigned char *a;    char *loc; @@ -179,9 +168,7 @@ t_fromb64(dst, src)  }  _TYPE( int ) -t_cstrfromb64(dst, src) -     cstr * dst; -     const char * src; +t_cstrfromb64(cstr *dst, const char *src)  {    int len;    cstr_set_length(dst, (strlen(src) * 6 + 7) / 8); @@ -194,10 +181,7 @@ t_cstrfromb64(dst, src)   * Convert a raw byte string into a null-terminated base64 ASCII string.   */  _TYPE( char * ) -t_tob64(dst, src, size) -     char * dst; -     const char * src; -     unsigned size; +t_tob64(char *dst, const char *src, unsigned size)  {    int c, pos = size % 3;    unsigned char b0 = 0, b1 = 0, b2 = 0, notleading = 0; @@ -248,10 +232,7 @@ t_tob64(dst, src, size)  }  _TYPE( char * ) -t_tob64cstr(dst, src, sz) -     cstr * dst; -     const char * src; -     unsigned int sz; +t_tob64cstr(cstr *dst, const char *src, unsigned int sz)  {    cstr_set_length(dst, (sz * 8 + 5) / 6 + 1);    return t_tob64(dst->data, src, sz); diff --git a/3rd_party/libsrp6a-sha512/t_defines.h b/3rd_party/libsrp6a-sha512/t_defines.h index 447263f..a2a5fe5 100644 --- a/3rd_party/libsrp6a-sha512/t_defines.h +++ b/3rd_party/libsrp6a-sha512/t_defines.h @@ -65,7 +65,7 @@  #define _MSVC15DEXPORT  #define _MSVC20EXPORT  #define _DLLAPI -#if defined(WINDOWS) || defined(WIN32) +#if defined(WINDOWS) || defined(_WIN32)  #define _CDECL _cdecl  #else  #define _CDECL @@ -122,7 +122,7 @@ char *strchr(), *strrchr(), *strtok();  #define USE_SGTTY  #endif -#ifdef WIN32 +#ifdef _WIN32  #define USE_FTIME 1  #define USE_RENAME 1  #define NO_FCHMOD 1 diff --git a/3rd_party/libsrp6a-sha512/t_math.c b/3rd_party/libsrp6a-sha512/t_math.c index 88ae12f..dac19ec 100644 --- a/3rd_party/libsrp6a-sha512/t_math.c +++ b/3rd_party/libsrp6a-sha512/t_math.c @@ -39,10 +39,13 @@ typedef BIGNUM * BigInteger;  typedef BN_CTX * BigIntegerCtx;  typedef BN_MONT_CTX * BigIntegerModAccel;  #include <limits.h> -# ifdef OPENSSL_ENGINE +#if OPENSSL_VERSION_NUMBER < 0x30000000L +# ifndef OPENSSL_NO_ENGINE +#  define OPENSSL_ENGINE  #  include "openssl/engine.h"  static ENGINE * default_engine = NULL;  # endif /* OPENSSL_ENGINE */ +#endif  typedef int (*modexp_meth)(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,  			   const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *mctx);  static modexp_meth default_modexp = NULL; @@ -98,8 +101,7 @@ typedef void * BigIntegerModAccel;  /* Math library interface stubs */  BigInteger -BigIntegerFromInt(n) -     unsigned int n; +BigIntegerFromInt(unsigned int n)  {  #ifdef OPENSSL    BIGNUM * a = BN_new(); @@ -135,9 +137,7 @@ BigIntegerFromInt(n)  }  BigInteger -BigIntegerFromBytes(bytes, length) -     const unsigned char * bytes; -     int length; +BigIntegerFromBytes(const unsigned char *bytes, int length)  {  #ifdef OPENSSL    BIGNUM * a = BN_new(); @@ -205,10 +205,7 @@ BigIntegerFromBytes(bytes, length)  }  int -BigIntegerToBytes(src, dest, destlen) -     BigInteger src; -     unsigned char * dest; -     int destlen; +BigIntegerToBytes(BigInteger src, unsigned char *dest, int destlen)  {  #ifdef OPENSSL    return BN_bn2bin(src, dest); @@ -289,10 +286,7 @@ BigIntegerToCstrEx(BigInteger x, cstr * out, int len)  }  BigIntegerResult -BigIntegerToHex(src, dest, destlen) -     BigInteger src; -     char * dest; -     int destlen; +BigIntegerToHex(BigInteger src, char *dest, int destlen)  {  #ifdef OPENSSL    strncpy(dest, BN_bn2hex(src), destlen); @@ -316,11 +310,7 @@ static char b64table[] =    "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz./";  BigIntegerResult -BigIntegerToString(src, dest, destlen, radix) -     BigInteger src; -     char * dest; -     int destlen; -     unsigned int radix; +BigIntegerToString(BigInteger src, char *dest, int destlen, unsigned int radix)  {    BigInteger t = BigIntegerFromInt(0);    char * p = dest; @@ -344,8 +334,7 @@ BigIntegerToString(src, dest, destlen, radix)  }  int -BigIntegerBitLen(b) -     BigInteger b; +BigIntegerBitLen(BigInteger b)  {  #ifdef OPENSSL    return BN_num_bits(b); @@ -363,8 +352,7 @@ BigIntegerBitLen(b)  }  int -BigIntegerCmp(c1, c2) -     BigInteger c1, c2; +BigIntegerCmp(BigInteger c1, BigInteger c2)  {  #ifdef OPENSSL    return BN_cmp(c1, c2); @@ -382,9 +370,7 @@ BigIntegerCmp(c1, c2)  }  int -BigIntegerCmpInt(c1, c2) -     BigInteger c1; -     unsigned int c2; +BigIntegerCmpInt(BigInteger c1, unsigned int c2)  {  #ifdef OPENSSL    BigInteger bc2 = BigIntegerFromInt(c2); @@ -413,9 +399,7 @@ BigIntegerCmpInt(c1, c2)  }  BigIntegerResult -BigIntegerLShift(result, x, bits) -     BigInteger result, x; -     unsigned int bits; +BigIntegerLShift(BigInteger result, BigInteger x, unsigned int bits)  {  #ifdef OPENSSL    BN_lshift(result, x, bits); @@ -435,8 +419,7 @@ BigIntegerLShift(result, x, bits)  }  BigIntegerResult -BigIntegerAdd(result, a1, a2) -     BigInteger result, a1, a2; +BigIntegerAdd(BigInteger result, BigInteger a1, BigInteger a2)  {  #ifdef OPENSSL    BN_add(result, a1, a2); @@ -455,9 +438,7 @@ BigIntegerAdd(result, a1, a2)  }  BigIntegerResult -BigIntegerAddInt(result, a1, a2) -     BigInteger result, a1; -     unsigned int a2; +BigIntegerAddInt(BigInteger result, BigInteger a1, unsigned int a2)  {  #ifdef OPENSSL    if(result != a1) @@ -482,8 +463,7 @@ BigIntegerAddInt(result, a1, a2)  }  BigIntegerResult -BigIntegerSub(result, s1, s2) -     BigInteger result, s1, s2; +BigIntegerSub(BigInteger result, BigInteger s1, BigInteger s2)  {  #ifdef OPENSSL    BN_sub(result, s1, s2); @@ -502,9 +482,7 @@ BigIntegerSub(result, s1, s2)  }  BigIntegerResult -BigIntegerSubInt(result, s1, s2) -     BigInteger result, s1; -     unsigned int s2; +BigIntegerSubInt(BigInteger result, BigInteger s1, unsigned int s2)  {  #ifdef OPENSSL    if(result != s1) @@ -529,9 +507,7 @@ BigIntegerSubInt(result, s1, s2)  }  BigIntegerResult -BigIntegerMul(result, m1, m2, c) -     BigInteger result, m1, m2; -     BigIntegerCtx c; +BigIntegerMul(BigInteger result, BigInteger m1, BigInteger m2, BigIntegerCtx c)  {  #ifdef OPENSSL    BN_CTX * ctx = NULL; @@ -555,10 +531,7 @@ BigIntegerMul(result, m1, m2, c)  }  BigIntegerResult -BigIntegerMulInt(result, m1, m2, c) -     BigInteger result, m1; -     unsigned int m2; -     BigIntegerCtx c; +BigIntegerMulInt(BigInteger result, BigInteger m1, unsigned int m2, BigIntegerCtx c)  {  #ifdef OPENSSL    if(result != m1) @@ -583,10 +556,7 @@ BigIntegerMulInt(result, m1, m2, c)  }  BigIntegerResult -BigIntegerDivInt(result, d, m, c) -     BigInteger result, d; -     unsigned int m; -     BigIntegerCtx c; +BigIntegerDivInt(BigInteger result, BigInteger d, unsigned int m, BigIntegerCtx c)  {  #ifdef OPENSSL    if(result != d) @@ -623,9 +593,7 @@ BigIntegerDivInt(result, d, m, c)  }  BigIntegerResult -BigIntegerMod(result, d, m, c) -     BigInteger result, d, m; -     BigIntegerCtx c; +BigIntegerMod(BigInteger result, BigInteger d, BigInteger m, BigIntegerCtx c)  {  #ifdef OPENSSL    BN_CTX * ctx = NULL; @@ -649,10 +617,7 @@ BigIntegerMod(result, d, m, c)  }  unsigned int -BigIntegerModInt(d, m, c) -     BigInteger d; -     unsigned int m; -     BigIntegerCtx c; +BigIntegerModInt(BigInteger d, unsigned int m, BigIntegerCtx c)  {  #ifdef OPENSSL    return BN_mod_word(d, m); @@ -710,9 +675,7 @@ BigIntegerModInt(d, m, c)  }  BigIntegerResult -BigIntegerModMul(r, m1, m2, modulus, c) -     BigInteger r, m1, m2, modulus; -     BigIntegerCtx c; +BigIntegerModMul(BigInteger r, BigInteger m1, BigInteger m2, BigInteger modulus, BigIntegerCtx c)  {  #ifdef OPENSSL    BN_CTX * ctx = NULL; @@ -742,10 +705,7 @@ BigIntegerModMul(r, m1, m2, modulus, c)  }  BigIntegerResult -BigIntegerModExp(r, b, e, m, c, a) -     BigInteger r, b, e, m; -     BigIntegerCtx c; -     BigIntegerModAccel a; +BigIntegerModExp(BigInteger r, BigInteger b, BigInteger e, BigInteger m, BigIntegerCtx c, BigIntegerModAccel a)  {  #ifdef OPENSSL  #if OPENSSL_VERSION_NUMBER >= 0x00906000 @@ -760,7 +720,11 @@ BigIntegerModExp(r, b, e, m, c, a)    else if(a == NULL) {      BN_mod_exp(r, b, e, m, c);    } -#if OPENSSL_VERSION_NUMBER >= 0x00906000 +/* + * In LibreSSL BN_mod_exp_mont_word() is not a public symbol where BN_mod_exp() + * and BN_mod_exp_mont() will use the word optimization when appropriate. + */ +#if OPENSSL_VERSION_NUMBER >= 0x00906000 && !defined(LIBRESSL_VERSION_NUMBER)    else if(B > 0 && B < ULONG_MAX) {  /* 0.9.6 and above has mont_word optimization */      BN_mod_exp_mont_word(r, B, e, m, c, a);    } @@ -792,9 +756,7 @@ int _mbedtls_f_rng(void* unused, unsigned char *buf, size_t size)  #endif  int -BigIntegerCheckPrime(n, c) -     BigInteger n; -     BigIntegerCtx c; +BigIntegerCheckPrime(BigInteger n, BigIntegerCtx c)  {  #ifdef OPENSSL    int rv; @@ -802,7 +764,11 @@ BigIntegerCheckPrime(n, c)    if(c == NULL)      c = ctx = BN_CTX_new();  #if OPENSSL_VERSION_NUMBER >= 0x00908000 -  rv = BN_is_prime_ex(n, 25, c, NULL); +  #if OPENSSL_VERSION_NUMBER >= 0x30000000L +    rv = BN_check_prime(n, c, NULL); +  #else +    rv = BN_is_prime_ex(n, 25, c, NULL); +  #endif  #else    rv = BN_is_prime(n, 25, NULL, c, NULL);  #endif @@ -845,8 +811,7 @@ BigIntegerCheckPrime(n, c)  }  BigIntegerResult -BigIntegerFree(b) -     BigInteger b; +BigIntegerFree(BigInteger b)  {  #ifdef OPENSSL    BN_free(b); @@ -868,8 +833,7 @@ BigIntegerFree(b)  }  BigIntegerResult -BigIntegerClearFree(b) -     BigInteger b; +BigIntegerClearFree(BigInteger b)  {  #ifdef OPENSSL    BN_clear_free(b); @@ -905,8 +869,7 @@ BigIntegerCtxNew()  }  BigIntegerResult -BigIntegerCtxFree(ctx) -     BigIntegerCtx ctx; +BigIntegerCtxFree(BigIntegerCtx ctx)  {  #ifdef OPENSSL    if(ctx) @@ -916,9 +879,7 @@ BigIntegerCtxFree(ctx)  }  BigIntegerModAccel -BigIntegerModAccelNew(m, c) -     BigInteger m; -     BigIntegerCtx c; +BigIntegerModAccelNew(BigInteger m, BigIntegerCtx c)  {  #ifdef OPENSSL    BN_CTX * ctx = NULL; @@ -938,8 +899,7 @@ BigIntegerModAccelNew(m, c)  }  BigIntegerResult -BigIntegerModAccelFree(accel) -     BigIntegerModAccel accel; +BigIntegerModAccelFree(BigIntegerModAccel accel)  {  #ifdef OPENSSL    if(accel) @@ -951,7 +911,7 @@ BigIntegerModAccelFree(accel)  BigIntegerResult  BigIntegerInitialize()  { -#if OPENSSL_VERSION_NUMBER >= 0x00907000 +#if OPENSSL_VERSION_NUMBER >= 0x00907000 && defined(OPENSSL_ENGINE)    ENGINE_load_builtin_engines();  #endif    return BIG_INTEGER_SUCCESS; diff --git a/3rd_party/libsrp6a-sha512/t_misc.c b/3rd_party/libsrp6a-sha512/t_misc.c index 3053358..abd8e55 100644 --- a/3rd_party/libsrp6a-sha512/t_misc.c +++ b/3rd_party/libsrp6a-sha512/t_misc.c @@ -38,7 +38,7 @@  #include <sys/stat.h>  #include <fcntl.h> -#ifdef WIN32 +#ifdef _WIN32  #include <process.h>  #include <io.h>  #endif @@ -80,8 +80,7 @@ SHA1_CTX randctxt;  extern char ** environ;  static void -t_envhash(out) -     unsigned char * out; +t_envhash(unsigned char * out)  {    char ** ptr;    char ebuf[256]; @@ -115,8 +114,7 @@ t_envhash(out)   * The entire buffer is run once through SHA to obtain the final result.   */  static void -t_fshash(out) -     unsigned char * out; +t_fshash(unsigned char * out)  {    char dotpath[128];    struct stat st; @@ -209,7 +207,7 @@ t_initrand()  #if defined(OPENSSL)	/* OpenSSL has nifty win32 entropy-gathering code */  #if OPENSSL_VERSION_NUMBER >= 0x00905100    r = RAND_status(); -#if defined(WINDOWS) || defined(WIN32) +#if defined(WINDOWS) || defined(_WIN32)    if(r)		/* Don't do the Unix-y stuff on Windows if possible */      return;  #else @@ -222,7 +220,7 @@ t_initrand()    if(r > 0) {      yarrow_add_entropy(entropy, r, &g_rng);      memset(entropy, 0, sizeof(entropy)); -# if defined(WINDOWS) || defined(WIN32) +# if defined(WINDOWS) || defined(_WIN32)      /* Don't do the Unix-y stuff on Windows if possible */      yarrow_ready(&g_rng);      return; @@ -230,13 +228,13 @@ t_initrand()    }  #endif -#if !defined(WINDOWS) && !defined(WIN32) +#if !defined(WINDOWS) && !defined(_WIN32)    i = open("/dev/urandom", O_RDONLY);    if(i > 0) {      r += read(i, preseed.devrand, sizeof(preseed.devrand));      close(i);    } -#endif /* !WINDOWS && !WIN32 */ +#endif /* !WINDOWS && !_WIN32 */    /* Resort to truerand only if desperate for some Real entropy */    if(r == 0) @@ -252,7 +250,7 @@ t_initrand()    preseed.subsec = t.tv_usec;  #endif    preseed.pid = getpid(); -#ifndef WIN32 +#ifndef _WIN32    preseed.ppid = getppid();  #endif    t_envhash(preseed.envh); @@ -317,9 +315,7 @@ t_stronginitrand()   * Each cycle generates 20 bytes of new output.   */  _TYPE( void ) -t_random(data, size) -     unsigned char * data; -     unsigned size; +t_random(unsigned char * data, unsigned size)  {    if(!initialized)      t_initrand(); @@ -369,10 +365,7 @@ t_random(data, size)   * single 320-bit value.   */  _TYPE( unsigned char * ) -t_sessionkey(key, sk, sklen) -     unsigned char * key; -     unsigned char * sk; -     unsigned sklen; +t_sessionkey(unsigned char * key, unsigned char * sk, unsigned sklen)  {    unsigned i, klen;    unsigned char * hbuf; @@ -411,11 +404,7 @@ t_sessionkey(key, sk, sklen)  }  _TYPE( void ) -t_mgf1(mask, masklen, seed, seedlen) -     unsigned char * mask; -     unsigned masklen; -     const unsigned char * seed; -     unsigned seedlen; +t_mgf1(unsigned char * mask, unsigned masklen, const unsigned char * seed, unsigned seedlen)  {    SHA1_CTX ctxt;    unsigned i = 0; diff --git a/3rd_party/libsrp6a-sha512/t_sha.c b/3rd_party/libsrp6a-sha512/t_sha.c index 4029de8..8e54cb6 100644 --- a/3rd_party/libsrp6a-sha512/t_sha.c +++ b/3rd_party/libsrp6a-sha512/t_sha.c @@ -107,6 +107,44 @@ SHA512Final_mbed(unsigned char digest[64], SHA512_CTX * ctx)    mbedtls_md_free(ctx);  } +#elif defined(OPENSSL_SHA) +#if OPENSSL_VERSION_NUMBER >= 0x30000000L +void +SHA1Init_openssl(SHA1_CTX *ctx) +{ +  *ctx = EVP_MD_CTX_new(); +  EVP_DigestInit(*ctx, EVP_sha1()); +} + +void SHA1Update_openssl(SHA1_CTX *ctx, const void *data, unsigned int len) +{ +  EVP_DigestUpdate(*ctx, data, (size_t)len); +} + +void SHA1Final_openssl(unsigned char digest[20], SHA1_CTX *ctx) +{ +  EVP_DigestFinal(*ctx, digest, NULL); +  EVP_MD_CTX_destroy(*ctx); +} + +void +SHA512Init_openssl(SHA512_CTX *ctx) +{ +  *ctx = EVP_MD_CTX_new(); +  EVP_DigestInit(*ctx, EVP_sha512()); +} + +void SHA512Update_openssl(SHA512_CTX *ctx, const void *data, unsigned int len) +{ +  EVP_DigestUpdate(*ctx, data, (size_t)len); +} + +void SHA512Final_openssl(unsigned char digest[64], SHA512_CTX *ctx) +{ +  EVP_DigestFinal(*ctx, digest, NULL); +  EVP_MD_CTX_destroy(*ctx); +} +#endif  #elif !defined(OPENSSL_SHA) && !defined(TOMCRYPT_SHA)  /* Use the free SHA1 if the library doesn't have it */ @@ -273,4 +311,4 @@ unsigned char finalcount[8];      SHA1Transform(context->state, context->buffer);  #endif  } -#endif /* OPENSSL */ +#endif diff --git a/3rd_party/libsrp6a-sha512/t_sha.h b/3rd_party/libsrp6a-sha512/t_sha.h index 18deec5..2e38067 100644 --- a/3rd_party/libsrp6a-sha512/t_sha.h +++ b/3rd_party/libsrp6a-sha512/t_sha.h @@ -38,6 +38,28 @@  #endif  #ifdef OPENSSL_SHA +#include <openssl/err.h> +#if OPENSSL_VERSION_NUMBER >= 0x30000000L +#include <openssl/evp.h> + +typedef EVP_MD_CTX* SHA1_CTX; +#define SHA1Init SHA1Init_openssl +#define SHA1Update SHA1Update_openssl +#define SHA1Final SHA1Final_openssl + +typedef EVP_MD_CTX* SHA512_CTX; +#define SHA512Init SHA512Init_openssl +#define SHA512Update SHA512Update_openssl +#define SHA512Final SHA512Final_openssl + +void SHA1Init_openssl(SHA1_CTX *ctx); +void SHA1Update_openssl(SHA1_CTX *ctx, const void *data, unsigned int len); +void SHA1Final_openssl(unsigned char digest[20], SHA1_CTX *ctx); + +void SHA512Init_openssl(SHA512_CTX *ctx); +void SHA512Update_openssl(SHA512_CTX *ctx, const void *data, unsigned int len); +void SHA512Final_openssl(unsigned char digest[64], SHA1_CTX *ctx); +#else /* for OpenSSL < 3.0 */  #include <openssl/sha.h>  typedef SHA_CTX SHA1_CTX; @@ -48,7 +70,7 @@ typedef SHA_CTX SHA1_CTX;  #define SHA512Init SHA512_Init  #define SHA512Update SHA512_Update  #define SHA512Final SHA512_Final - +#endif /* for OpenSSL < 3.0 */  #elif defined(TOMCRYPT_SHA)  /* mycrypt.h already included above */ diff --git a/3rd_party/libsrp6a-sha512/t_truerand.c b/3rd_party/libsrp6a-sha512/t_truerand.c index 4a4c3d2..cd27d0d 100644 --- a/3rd_party/libsrp6a-sha512/t_truerand.c +++ b/3rd_party/libsrp6a-sha512/t_truerand.c @@ -54,7 +54,7 @@  #include "t_defines.h" -#ifdef WIN32 +#ifdef _WIN32  # ifdef CRYPTOLIB @@ -69,7 +69,7 @@ raw_truerand()  	return truerand();  } -# else /* !CRYPTOLIB && WIN32 */ +# else /* !CRYPTOLIB && _WIN32 */  #include <windows.h>  #include <wtypes.h> @@ -128,7 +128,7 @@ raw_truerand() {  # endif /* CRYPTOLIB */ -#else /* !WIN32 */ +#else /* !_WIN32 */  #include <signal.h>  #include <setjmp.h> @@ -227,8 +227,7 @@ raw_truerand()  }  int -raw_n_truerand(n) -int n; +raw_n_truerand(int n)  {  	int slop, v; @@ -239,4 +238,4 @@ int n;  	return v % n;  } -#endif /* !CRYPTOLIB || !WIN32 */ +#endif /* !CRYPTOLIB || !_WIN32 */ | 
