summaryrefslogtreecommitdiffstats
path: root/3rd_party/libsrp6a-sha512
diff options
context:
space:
mode:
Diffstat (limited to '3rd_party/libsrp6a-sha512')
-rw-r--r--3rd_party/libsrp6a-sha512/Makefile.am3
-rw-r--r--3rd_party/libsrp6a-sha512/cstr.c62
-rw-r--r--3rd_party/libsrp6a-sha512/cstr.h14
-rw-r--r--3rd_party/libsrp6a-sha512/t_defines.h4
-rw-r--r--3rd_party/libsrp6a-sha512/t_misc.c17
-rw-r--r--3rd_party/libsrp6a-sha512/t_truerand.c8
6 files changed, 30 insertions, 78 deletions
diff --git a/3rd_party/libsrp6a-sha512/Makefile.am b/3rd_party/libsrp6a-sha512/Makefile.am
index 2acd582..bdacb5f 100644
--- a/3rd_party/libsrp6a-sha512/Makefile.am
+++ b/3rd_party/libsrp6a-sha512/Makefile.am
@@ -25,7 +25,8 @@ libsrp6a_sha512_la_SOURCES = \
25 t_truerand.c cstr.c \ 25 t_truerand.c cstr.c \
26 srp.c srp6a_sha512_client.c \ 26 srp.c srp6a_sha512_client.c \
27 srp.h srp_aux.h cstr.h \ 27 srp.h srp_aux.h cstr.h \
28 t_sha.c 28 t_defines.h t_pwd.h \
29 t_sha.c t_sha.h
29#if !HAVE_OPENSSL 30#if !HAVE_OPENSSL
30#libsrp6a_sha512_la_SOURCES += t_sha.c 31#libsrp6a_sha512_la_SOURCES += t_sha.c
31#endif 32#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 @@
8#define MINSIZE 4 /* Absolute minimum - one word */ 8#define MINSIZE 4 /* Absolute minimum - one word */
9 9
10static char cstr_empty_string[] = { '\0' }; 10static char cstr_empty_string[] = { '\0' };
11static cstr_allocator * default_alloc = NULL;
12
13/*
14 * It is assumed, for efficiency, that it is okay to pass more arguments
15 * to a function than are called for, as long as the required arguments
16 * are in proper form. If extra arguments to malloc() and free() cause
17 * problems, define PEDANTIC_ARGS below.
18 */
19#ifdef PEDANTIC_ARGS
20static void * Cmalloc(int n, void * heap) { return malloc(n); }
21static void Cfree(void * p, void * heap) { free(p); }
22static cstr_allocator malloc_allocator = { Cmalloc, Cfree, NULL };
23#else
24static cstr_allocator malloc_allocator = { malloc, free, NULL };
25#endif
26
27_TYPE( void )
28cstr_set_allocator(cstr_allocator * alloc)
29{
30 default_alloc = alloc;
31}
32 11
33_TYPE( cstr * ) 12_TYPE( cstr * )
34cstr_new_alloc(cstr_allocator * alloc) 13cstr_new()
35{ 14{
36 cstr * str; 15 cstr * str;
37 16
38 if(alloc == NULL) { 17 str = (cstr *) malloc(sizeof(cstr));
39 if(default_alloc == NULL) {
40 default_alloc = &malloc_allocator;
41 }
42 alloc = default_alloc;
43 }
44
45 str = (cstr *) (*alloc->alloc)(sizeof(cstr), alloc->heap);
46 if(str) { 18 if(str) {
47 str->data = cstr_empty_string; 19 str->data = cstr_empty_string;
48 str->length = str->cap = 0; 20 str->length = str->cap = 0;
49 str->ref = 1; 21 str->ref = 1;
50 str->allocator = alloc;
51 } 22 }
52 return str; 23 return str;
53} 24}
54 25
55_TYPE( cstr * ) 26_TYPE( cstr * )
56cstr_new() 27cstr_dup(const cstr * str)
57{
58 return cstr_new_alloc(NULL);
59}
60
61_TYPE( cstr * )
62cstr_dup_alloc(const cstr * str, cstr_allocator * alloc)
63{ 28{
64 cstr * nstr = cstr_new_alloc(alloc); 29 cstr * nstr = cstr_new();
65 if(nstr) 30 if(nstr)
66 cstr_setn(nstr, str->data, str->length); 31 cstr_setn(nstr, str->data, str->length);
67 return nstr; 32 return nstr;
68} 33}
69 34
70_TYPE( cstr * ) 35_TYPE( cstr * )
71cstr_dup(const cstr * str)
72{
73 return cstr_dup_alloc(str, NULL);
74}
75
76_TYPE( cstr * )
77cstr_create(const char * s) 36cstr_create(const char * s)
78{ 37{
79 return cstr_createn(s, strlen(s)); 38 return cstr_createn(s, strlen(s));
@@ -101,9 +60,9 @@ cstr_clear_free(cstr * str)
101 if(--str->ref == 0) { 60 if(--str->ref == 0) {
102 if(str->cap > 0) { 61 if(str->cap > 0) {
103 memset(str->data, 0, str->cap); 62 memset(str->data, 0, str->cap);
104 (*str->allocator->free)(str->data, str->allocator->heap); 63 free(str->data);
105 } 64 }
106 (*str->allocator->free)(str, str->allocator->heap); 65 free(str);
107 } 66 }
108} 67}
109 68
@@ -112,8 +71,8 @@ cstr_free(cstr * str)
112{ 71{
113 if(--str->ref == 0) { 72 if(--str->ref == 0) {
114 if(str->cap > 0) 73 if(str->cap > 0)
115 (*str->allocator->free)(str->data, str->allocator->heap); 74 free(str->data);
116 (*str->allocator->free)(str, str->allocator->heap); 75 free(str);
117 } 76 }
118} 77}
119 78
@@ -121,7 +80,7 @@ _TYPE( void )
121cstr_empty(cstr * str) 80cstr_empty(cstr * str)
122{ 81{
123 if(str->cap > 0) 82 if(str->cap > 0)
124 (*str->allocator->free)(str->data, str->allocator->heap); 83 free(str->data);
125 str->data = cstr_empty_string; 84 str->data = cstr_empty_string;
126 str->length = str->cap = 0; 85 str->length = str->cap = 0;
127} 86}
@@ -137,8 +96,7 @@ cstr_alloc(cstr * str, int len)
137 if(len < MINSIZE) 96 if(len < MINSIZE)
138 len = MINSIZE; 97 len = MINSIZE;
139 98
140 t = (char *) (*str->allocator->alloc)(len * sizeof(char), 99 t = (char *) malloc(len * sizeof(char));
141 str->allocator->heap);
142 if(t) { 100 if(t) {
143 if(str->data) { 101 if(str->data) {
144 t[str->length] = 0; 102 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 @@
38#define _MSVC15DEXPORT 38#define _MSVC15DEXPORT
39#define _MSVC20EXPORT 39#define _MSVC20EXPORT
40#define _DLLAPI 40#define _DLLAPI
41#if defined(WINDOWS) || defined(WIN32) 41#if defined(WINDOWS) || defined(_WIN32)
42#define _CDECL _cdecl 42#define _CDECL _cdecl
43#else 43#else
44#define _CDECL 44#define _CDECL
@@ -51,27 +51,15 @@
51extern "C" { 51extern "C" {
52#endif /* __cplusplus */ 52#endif /* __cplusplus */
53 53
54/* Arguments to allocator methods ordered this way for compatibility */
55typedef struct cstr_alloc_st {
56 void * (_CDECL * alloc)(size_t n, void * heap);
57 void (_CDECL * free)(void * p, void * heap);
58 void * heap;
59} cstr_allocator;
60
61typedef struct cstr_st { 54typedef struct cstr_st {
62 char * data; /* Okay to access data and length fields directly */ 55 char * data; /* Okay to access data and length fields directly */
63 int length; 56 int length;
64 int cap; 57 int cap;
65 int ref; /* Simple reference counter */ 58 int ref; /* Simple reference counter */
66 cstr_allocator * allocator;
67} cstr; 59} cstr;
68 60
69_TYPE( void ) cstr_set_allocator P((cstr_allocator * alloc));
70
71_TYPE( cstr * ) cstr_new P((void)); 61_TYPE( cstr * ) cstr_new P((void));
72_TYPE( cstr * ) cstr_new_alloc P((cstr_allocator * alloc));
73_TYPE( cstr * ) cstr_dup P((const cstr * str)); 62_TYPE( cstr * ) cstr_dup P((const cstr * str));
74_TYPE( cstr * ) cstr_dup_alloc P((const cstr * str, cstr_allocator * alloc));
75_TYPE( cstr * ) cstr_create P((const char * s)); 63_TYPE( cstr * ) cstr_create P((const char * s));
76_TYPE( cstr * ) cstr_createn P((const char * s, int len)); 64_TYPE( cstr * ) cstr_createn P((const char * s, int len));
77 65
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 @@
65#define _MSVC15DEXPORT 65#define _MSVC15DEXPORT
66#define _MSVC20EXPORT 66#define _MSVC20EXPORT
67#define _DLLAPI 67#define _DLLAPI
68#if defined(WINDOWS) || defined(WIN32) 68#if defined(WINDOWS) || defined(_WIN32)
69#define _CDECL _cdecl 69#define _CDECL _cdecl
70#else 70#else
71#define _CDECL 71#define _CDECL
@@ -122,7 +122,7 @@ char *strchr(), *strrchr(), *strtok();
122#define USE_SGTTY 122#define USE_SGTTY
123#endif 123#endif
124 124
125#ifdef WIN32 125#ifdef _WIN32
126#define USE_FTIME 1 126#define USE_FTIME 1
127#define USE_RENAME 1 127#define USE_RENAME 1
128#define NO_FCHMOD 1 128#define NO_FCHMOD 1
diff --git a/3rd_party/libsrp6a-sha512/t_misc.c b/3rd_party/libsrp6a-sha512/t_misc.c
index 3a2cda1..34b9509 100644
--- a/3rd_party/libsrp6a-sha512/t_misc.c
+++ b/3rd_party/libsrp6a-sha512/t_misc.c
@@ -38,7 +38,7 @@
38#include <sys/stat.h> 38#include <sys/stat.h>
39#include <fcntl.h> 39#include <fcntl.h>
40 40
41#ifdef WIN32 41#ifdef _WIN32
42#include <process.h> 42#include <process.h>
43#include <io.h> 43#include <io.h>
44#endif 44#endif
@@ -77,7 +77,12 @@ SHA1_CTX randctxt;
77 * tricks with variable ordering and sometimes define quirky 77 * tricks with variable ordering and sometimes define quirky
78 * environment variables like $WINDOWID or $_. 78 * environment variables like $WINDOWID or $_.
79 */ 79 */
80#ifdef __APPLE__
81#include <crt_externs.h>
82#define environ (*_NSGetEnviron())
83#else
80extern char ** environ; 84extern char ** environ;
85#endif
81 86
82static void 87static void
83t_envhash(unsigned char * out) 88t_envhash(unsigned char * out)
@@ -207,7 +212,7 @@ t_initrand()
207#if defined(OPENSSL) /* OpenSSL has nifty win32 entropy-gathering code */ 212#if defined(OPENSSL) /* OpenSSL has nifty win32 entropy-gathering code */
208#if OPENSSL_VERSION_NUMBER >= 0x00905100 213#if OPENSSL_VERSION_NUMBER >= 0x00905100
209 r = RAND_status(); 214 r = RAND_status();
210#if defined(WINDOWS) || defined(WIN32) 215#if defined(WINDOWS) || defined(_WIN32)
211 if(r) /* Don't do the Unix-y stuff on Windows if possible */ 216 if(r) /* Don't do the Unix-y stuff on Windows if possible */
212 return; 217 return;
213#else 218#else
@@ -220,7 +225,7 @@ t_initrand()
220 if(r > 0) { 225 if(r > 0) {
221 yarrow_add_entropy(entropy, r, &g_rng); 226 yarrow_add_entropy(entropy, r, &g_rng);
222 memset(entropy, 0, sizeof(entropy)); 227 memset(entropy, 0, sizeof(entropy));
223# if defined(WINDOWS) || defined(WIN32) 228# if defined(WINDOWS) || defined(_WIN32)
224 /* Don't do the Unix-y stuff on Windows if possible */ 229 /* Don't do the Unix-y stuff on Windows if possible */
225 yarrow_ready(&g_rng); 230 yarrow_ready(&g_rng);
226 return; 231 return;
@@ -228,13 +233,13 @@ t_initrand()
228 } 233 }
229#endif 234#endif
230 235
231#if !defined(WINDOWS) && !defined(WIN32) 236#if !defined(WINDOWS) && !defined(_WIN32)
232 i = open("/dev/urandom", O_RDONLY); 237 i = open("/dev/urandom", O_RDONLY);
233 if(i > 0) { 238 if(i > 0) {
234 r += read(i, preseed.devrand, sizeof(preseed.devrand)); 239 r += read(i, preseed.devrand, sizeof(preseed.devrand));
235 close(i); 240 close(i);
236 } 241 }
237#endif /* !WINDOWS && !WIN32 */ 242#endif /* !WINDOWS && !_WIN32 */
238 243
239 /* Resort to truerand only if desperate for some Real entropy */ 244 /* Resort to truerand only if desperate for some Real entropy */
240 if(r == 0) 245 if(r == 0)
@@ -250,7 +255,7 @@ t_initrand()
250 preseed.subsec = t.tv_usec; 255 preseed.subsec = t.tv_usec;
251#endif 256#endif
252 preseed.pid = getpid(); 257 preseed.pid = getpid();
253#ifndef WIN32 258#ifndef _WIN32
254 preseed.ppid = getppid(); 259 preseed.ppid = getppid();
255#endif 260#endif
256 t_envhash(preseed.envh); 261 t_envhash(preseed.envh);
diff --git a/3rd_party/libsrp6a-sha512/t_truerand.c b/3rd_party/libsrp6a-sha512/t_truerand.c
index f995ed7..cd27d0d 100644
--- a/3rd_party/libsrp6a-sha512/t_truerand.c
+++ b/3rd_party/libsrp6a-sha512/t_truerand.c
@@ -54,7 +54,7 @@
54 54
55#include "t_defines.h" 55#include "t_defines.h"
56 56
57#ifdef WIN32 57#ifdef _WIN32
58 58
59# ifdef CRYPTOLIB 59# ifdef CRYPTOLIB
60 60
@@ -69,7 +69,7 @@ raw_truerand()
69 return truerand(); 69 return truerand();
70} 70}
71 71
72# else /* !CRYPTOLIB && WIN32 */ 72# else /* !CRYPTOLIB && _WIN32 */
73 73
74#include <windows.h> 74#include <windows.h>
75#include <wtypes.h> 75#include <wtypes.h>
@@ -128,7 +128,7 @@ raw_truerand() {
128 128
129# endif /* CRYPTOLIB */ 129# endif /* CRYPTOLIB */
130 130
131#else /* !WIN32 */ 131#else /* !_WIN32 */
132 132
133#include <signal.h> 133#include <signal.h>
134#include <setjmp.h> 134#include <setjmp.h>
@@ -238,4 +238,4 @@ raw_n_truerand(int n)
238 return v % n; 238 return v % n;
239} 239}
240 240
241#endif /* !CRYPTOLIB || !WIN32 */ 241#endif /* !CRYPTOLIB || !_WIN32 */