summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2023-06-30 23:30:13 +0200
committerGravatar Nikias Bassen2023-06-30 23:30:13 +0200
commit52ab7b76f76ee0464fd150ec881ce50fbf2dc001 (patch)
tree3b2ee64ea5f8a42ed64c01f59b2fd752b23fd546
parentf4c30d501eaf5a2c1a386af6a2295dd0029304e9 (diff)
downloadlibimobiledevice-52ab7b76f76ee0464fd150ec881ce50fbf2dc001.tar.gz
libimobiledevice-52ab7b76f76ee0464fd150ec881ce50fbf2dc001.tar.bz2
3rd_party/libsrp6a-sha512: Update function definitions to modern style
-rw-r--r--3rd_party/libsrp6a-sha512/t_conv.c35
-rw-r--r--3rd_party/libsrp6a-sha512/t_math.c103
-rw-r--r--3rd_party/libsrp6a-sha512/t_misc.c21
-rw-r--r--3rd_party/libsrp6a-sha512/t_truerand.c3
4 files changed, 40 insertions, 122 deletions
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 @@
33#include "cstr.h" 33#include "cstr.h"
34 34
35static int 35static int
36hexDigitToInt(c) 36hexDigitToInt(char c)
37 char c;
38{ 37{
39 if(c >= '0' && c <= '9') 38 if(c >= '0' && c <= '9')
40 return c - '0'; 39 return c - '0';
@@ -50,9 +49,7 @@ hexDigitToInt(c)
50 * Convert a hex string to a string of bytes; return size of dst 49 * Convert a hex string to a string of bytes; return size of dst
51 */ 50 */
52_TYPE( int ) 51_TYPE( int )
53t_fromhex(dst, src) 52t_fromhex(char *dst, const char *src)
54 char * dst;
55 const char * src;
56{ 53{
57 register char *chp = dst; 54 register char *chp = dst;
58 register unsigned size = strlen(src); 55 register unsigned size = strlen(src);
@@ -76,10 +73,7 @@ t_fromhex(dst, src)
76 * Convert a string of bytes to their hex representation 73 * Convert a string of bytes to their hex representation
77 */ 74 */
78_TYPE( char * ) 75_TYPE( char * )
79t_tohex(dst, src, size) 76t_tohex(char *dst, const char *src, unsigned size)
80 char * dst;
81 const char * src;
82 unsigned size;
83{ 77{
84 int notleading = 0; 78 int notleading = 0;
85 79
@@ -103,10 +97,7 @@ t_tohex(dst, src, size)
103} 97}
104 98
105_TYPE( char * ) 99_TYPE( char * )
106t_tohexcstr(dst, src, size) 100t_tohexcstr(cstr *dst, const char *src, unsigned size)
107 cstr * dst;
108 const char * src;
109 unsigned size;
110{ 101{
111 cstr_set_length(dst, 2 * size + 1); 102 cstr_set_length(dst, 2 * size + 1);
112 return t_tohex(dst->data, src, size); 103 return t_tohex(dst->data, src, size);
@@ -119,9 +110,7 @@ static char b64table[] =
119 * Convert a base64 string into raw byte array representation. 110 * Convert a base64 string into raw byte array representation.
120 */ 111 */
121_TYPE( int ) 112_TYPE( int )
122t_fromb64(dst, src) 113t_fromb64(char *dst, const char *src)
123 char * dst;
124 const char * src;
125{ 114{
126 unsigned char *a; 115 unsigned char *a;
127 char *loc; 116 char *loc;
@@ -179,9 +168,7 @@ t_fromb64(dst, src)
179} 168}
180 169
181_TYPE( int ) 170_TYPE( int )
182t_cstrfromb64(dst, src) 171t_cstrfromb64(cstr *dst, const char *src)
183 cstr * dst;
184 const char * src;
185{ 172{
186 int len; 173 int len;
187 cstr_set_length(dst, (strlen(src) * 6 + 7) / 8); 174 cstr_set_length(dst, (strlen(src) * 6 + 7) / 8);
@@ -194,10 +181,7 @@ t_cstrfromb64(dst, src)
194 * Convert a raw byte string into a null-terminated base64 ASCII string. 181 * Convert a raw byte string into a null-terminated base64 ASCII string.
195 */ 182 */
196_TYPE( char * ) 183_TYPE( char * )
197t_tob64(dst, src, size) 184t_tob64(char *dst, const char *src, unsigned size)
198 char * dst;
199 const char * src;
200 unsigned size;
201{ 185{
202 int c, pos = size % 3; 186 int c, pos = size % 3;
203 unsigned char b0 = 0, b1 = 0, b2 = 0, notleading = 0; 187 unsigned char b0 = 0, b1 = 0, b2 = 0, notleading = 0;
@@ -248,10 +232,7 @@ t_tob64(dst, src, size)
248} 232}
249 233
250_TYPE( char * ) 234_TYPE( char * )
251t_tob64cstr(dst, src, sz) 235t_tob64cstr(cstr *dst, const char *src, unsigned int sz)
252 cstr * dst;
253 const char * src;
254 unsigned int sz;
255{ 236{
256 cstr_set_length(dst, (sz * 8 + 5) / 6 + 1); 237 cstr_set_length(dst, (sz * 8 + 5) / 6 + 1);
257 return t_tob64(dst->data, src, sz); 238 return t_tob64(dst->data, src, sz);
diff --git a/3rd_party/libsrp6a-sha512/t_math.c b/3rd_party/libsrp6a-sha512/t_math.c
index e655daa..166ee4c 100644
--- a/3rd_party/libsrp6a-sha512/t_math.c
+++ b/3rd_party/libsrp6a-sha512/t_math.c
@@ -99,8 +99,7 @@ typedef void * BigIntegerModAccel;
99/* Math library interface stubs */ 99/* Math library interface stubs */
100 100
101BigInteger 101BigInteger
102BigIntegerFromInt(n) 102BigIntegerFromInt(unsigned int n)
103 unsigned int n;
104{ 103{
105#ifdef OPENSSL 104#ifdef OPENSSL
106 BIGNUM * a = BN_new(); 105 BIGNUM * a = BN_new();
@@ -136,9 +135,7 @@ BigIntegerFromInt(n)
136} 135}
137 136
138BigInteger 137BigInteger
139BigIntegerFromBytes(bytes, length) 138BigIntegerFromBytes(const unsigned char *bytes, int length)
140 const unsigned char * bytes;
141 int length;
142{ 139{
143#ifdef OPENSSL 140#ifdef OPENSSL
144 BIGNUM * a = BN_new(); 141 BIGNUM * a = BN_new();
@@ -206,10 +203,7 @@ BigIntegerFromBytes(bytes, length)
206} 203}
207 204
208int 205int
209BigIntegerToBytes(src, dest, destlen) 206BigIntegerToBytes(BigInteger src, unsigned char *dest, int destlen)
210 BigInteger src;
211 unsigned char * dest;
212 int destlen;
213{ 207{
214#ifdef OPENSSL 208#ifdef OPENSSL
215 return BN_bn2bin(src, dest); 209 return BN_bn2bin(src, dest);
@@ -290,10 +284,7 @@ BigIntegerToCstrEx(BigInteger x, cstr * out, int len)
290} 284}
291 285
292BigIntegerResult 286BigIntegerResult
293BigIntegerToHex(src, dest, destlen) 287BigIntegerToHex(BigInteger src, char *dest, int destlen)
294 BigInteger src;
295 char * dest;
296 int destlen;
297{ 288{
298#ifdef OPENSSL 289#ifdef OPENSSL
299 strncpy(dest, BN_bn2hex(src), destlen); 290 strncpy(dest, BN_bn2hex(src), destlen);
@@ -317,11 +308,7 @@ static char b64table[] =
317 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz./"; 308 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz./";
318 309
319BigIntegerResult 310BigIntegerResult
320BigIntegerToString(src, dest, destlen, radix) 311BigIntegerToString(BigInteger src, char *dest, int destlen, unsigned int radix)
321 BigInteger src;
322 char * dest;
323 int destlen;
324 unsigned int radix;
325{ 312{
326 BigInteger t = BigIntegerFromInt(0); 313 BigInteger t = BigIntegerFromInt(0);
327 char * p = dest; 314 char * p = dest;
@@ -345,8 +332,7 @@ BigIntegerToString(src, dest, destlen, radix)
345} 332}
346 333
347int 334int
348BigIntegerBitLen(b) 335BigIntegerBitLen(BigInteger b)
349 BigInteger b;
350{ 336{
351#ifdef OPENSSL 337#ifdef OPENSSL
352 return BN_num_bits(b); 338 return BN_num_bits(b);
@@ -364,8 +350,7 @@ BigIntegerBitLen(b)
364} 350}
365 351
366int 352int
367BigIntegerCmp(c1, c2) 353BigIntegerCmp(BigInteger c1, BigInteger c2)
368 BigInteger c1, c2;
369{ 354{
370#ifdef OPENSSL 355#ifdef OPENSSL
371 return BN_cmp(c1, c2); 356 return BN_cmp(c1, c2);
@@ -383,9 +368,7 @@ BigIntegerCmp(c1, c2)
383} 368}
384 369
385int 370int
386BigIntegerCmpInt(c1, c2) 371BigIntegerCmpInt(BigInteger c1, unsigned int c2)
387 BigInteger c1;
388 unsigned int c2;
389{ 372{
390#ifdef OPENSSL 373#ifdef OPENSSL
391 BigInteger bc2 = BigIntegerFromInt(c2); 374 BigInteger bc2 = BigIntegerFromInt(c2);
@@ -414,9 +397,7 @@ BigIntegerCmpInt(c1, c2)
414} 397}
415 398
416BigIntegerResult 399BigIntegerResult
417BigIntegerLShift(result, x, bits) 400BigIntegerLShift(BigInteger result, BigInteger x, unsigned int bits)
418 BigInteger result, x;
419 unsigned int bits;
420{ 401{
421#ifdef OPENSSL 402#ifdef OPENSSL
422 BN_lshift(result, x, bits); 403 BN_lshift(result, x, bits);
@@ -436,8 +417,7 @@ BigIntegerLShift(result, x, bits)
436} 417}
437 418
438BigIntegerResult 419BigIntegerResult
439BigIntegerAdd(result, a1, a2) 420BigIntegerAdd(BigInteger result, BigInteger a1, BigInteger a2)
440 BigInteger result, a1, a2;
441{ 421{
442#ifdef OPENSSL 422#ifdef OPENSSL
443 BN_add(result, a1, a2); 423 BN_add(result, a1, a2);
@@ -456,9 +436,7 @@ BigIntegerAdd(result, a1, a2)
456} 436}
457 437
458BigIntegerResult 438BigIntegerResult
459BigIntegerAddInt(result, a1, a2) 439BigIntegerAddInt(BigInteger result, BigInteger a1, unsigned int a2)
460 BigInteger result, a1;
461 unsigned int a2;
462{ 440{
463#ifdef OPENSSL 441#ifdef OPENSSL
464 if(result != a1) 442 if(result != a1)
@@ -483,8 +461,7 @@ BigIntegerAddInt(result, a1, a2)
483} 461}
484 462
485BigIntegerResult 463BigIntegerResult
486BigIntegerSub(result, s1, s2) 464BigIntegerSub(BigInteger result, BigInteger s1, BigInteger s2)
487 BigInteger result, s1, s2;
488{ 465{
489#ifdef OPENSSL 466#ifdef OPENSSL
490 BN_sub(result, s1, s2); 467 BN_sub(result, s1, s2);
@@ -503,9 +480,7 @@ BigIntegerSub(result, s1, s2)
503} 480}
504 481
505BigIntegerResult 482BigIntegerResult
506BigIntegerSubInt(result, s1, s2) 483BigIntegerSubInt(BigInteger result, BigInteger s1, unsigned int s2)
507 BigInteger result, s1;
508 unsigned int s2;
509{ 484{
510#ifdef OPENSSL 485#ifdef OPENSSL
511 if(result != s1) 486 if(result != s1)
@@ -530,9 +505,7 @@ BigIntegerSubInt(result, s1, s2)
530} 505}
531 506
532BigIntegerResult 507BigIntegerResult
533BigIntegerMul(result, m1, m2, c) 508BigIntegerMul(BigInteger result, BigInteger m1, BigInteger m2, BigIntegerCtx c)
534 BigInteger result, m1, m2;
535 BigIntegerCtx c;
536{ 509{
537#ifdef OPENSSL 510#ifdef OPENSSL
538 BN_CTX * ctx = NULL; 511 BN_CTX * ctx = NULL;
@@ -556,10 +529,7 @@ BigIntegerMul(result, m1, m2, c)
556} 529}
557 530
558BigIntegerResult 531BigIntegerResult
559BigIntegerMulInt(result, m1, m2, c) 532BigIntegerMulInt(BigInteger result, BigInteger m1, unsigned int m2, BigIntegerCtx c)
560 BigInteger result, m1;
561 unsigned int m2;
562 BigIntegerCtx c;
563{ 533{
564#ifdef OPENSSL 534#ifdef OPENSSL
565 if(result != m1) 535 if(result != m1)
@@ -584,10 +554,7 @@ BigIntegerMulInt(result, m1, m2, c)
584} 554}
585 555
586BigIntegerResult 556BigIntegerResult
587BigIntegerDivInt(result, d, m, c) 557BigIntegerDivInt(BigInteger result, BigInteger d, unsigned int m, BigIntegerCtx c)
588 BigInteger result, d;
589 unsigned int m;
590 BigIntegerCtx c;
591{ 558{
592#ifdef OPENSSL 559#ifdef OPENSSL
593 if(result != d) 560 if(result != d)
@@ -624,9 +591,7 @@ BigIntegerDivInt(result, d, m, c)
624} 591}
625 592
626BigIntegerResult 593BigIntegerResult
627BigIntegerMod(result, d, m, c) 594BigIntegerMod(BigInteger result, BigInteger d, BigInteger m, BigIntegerCtx c)
628 BigInteger result, d, m;
629 BigIntegerCtx c;
630{ 595{
631#ifdef OPENSSL 596#ifdef OPENSSL
632 BN_CTX * ctx = NULL; 597 BN_CTX * ctx = NULL;
@@ -650,10 +615,7 @@ BigIntegerMod(result, d, m, c)
650} 615}
651 616
652unsigned int 617unsigned int
653BigIntegerModInt(d, m, c) 618BigIntegerModInt(BigInteger d, unsigned int m, BigIntegerCtx c)
654 BigInteger d;
655 unsigned int m;
656 BigIntegerCtx c;
657{ 619{
658#ifdef OPENSSL 620#ifdef OPENSSL
659 return BN_mod_word(d, m); 621 return BN_mod_word(d, m);
@@ -711,9 +673,7 @@ BigIntegerModInt(d, m, c)
711} 673}
712 674
713BigIntegerResult 675BigIntegerResult
714BigIntegerModMul(r, m1, m2, modulus, c) 676BigIntegerModMul(BigInteger r, BigInteger m1, BigInteger m2, BigInteger modulus, BigIntegerCtx c)
715 BigInteger r, m1, m2, modulus;
716 BigIntegerCtx c;
717{ 677{
718#ifdef OPENSSL 678#ifdef OPENSSL
719 BN_CTX * ctx = NULL; 679 BN_CTX * ctx = NULL;
@@ -743,10 +703,7 @@ BigIntegerModMul(r, m1, m2, modulus, c)
743} 703}
744 704
745BigIntegerResult 705BigIntegerResult
746BigIntegerModExp(r, b, e, m, c, a) 706BigIntegerModExp(BigInteger r, BigInteger b, BigInteger e, BigInteger m, BigIntegerCtx c, BigIntegerModAccel a)
747 BigInteger r, b, e, m;
748 BigIntegerCtx c;
749 BigIntegerModAccel a;
750{ 707{
751#ifdef OPENSSL 708#ifdef OPENSSL
752#if OPENSSL_VERSION_NUMBER >= 0x00906000 709#if OPENSSL_VERSION_NUMBER >= 0x00906000
@@ -793,9 +750,7 @@ int _mbedtls_f_rng(void* unused, unsigned char *buf, size_t size)
793#endif 750#endif
794 751
795int 752int
796BigIntegerCheckPrime(n, c) 753BigIntegerCheckPrime(BigInteger n, BigIntegerCtx c)
797 BigInteger n;
798 BigIntegerCtx c;
799{ 754{
800#ifdef OPENSSL 755#ifdef OPENSSL
801 int rv; 756 int rv;
@@ -846,8 +801,7 @@ BigIntegerCheckPrime(n, c)
846} 801}
847 802
848BigIntegerResult 803BigIntegerResult
849BigIntegerFree(b) 804BigIntegerFree(BigInteger b)
850 BigInteger b;
851{ 805{
852#ifdef OPENSSL 806#ifdef OPENSSL
853 BN_free(b); 807 BN_free(b);
@@ -869,8 +823,7 @@ BigIntegerFree(b)
869} 823}
870 824
871BigIntegerResult 825BigIntegerResult
872BigIntegerClearFree(b) 826BigIntegerClearFree(BigInteger b)
873 BigInteger b;
874{ 827{
875#ifdef OPENSSL 828#ifdef OPENSSL
876 BN_clear_free(b); 829 BN_clear_free(b);
@@ -906,8 +859,7 @@ BigIntegerCtxNew()
906} 859}
907 860
908BigIntegerResult 861BigIntegerResult
909BigIntegerCtxFree(ctx) 862BigIntegerCtxFree(BigIntegerCtx ctx)
910 BigIntegerCtx ctx;
911{ 863{
912#ifdef OPENSSL 864#ifdef OPENSSL
913 if(ctx) 865 if(ctx)
@@ -917,9 +869,7 @@ BigIntegerCtxFree(ctx)
917} 869}
918 870
919BigIntegerModAccel 871BigIntegerModAccel
920BigIntegerModAccelNew(m, c) 872BigIntegerModAccelNew(BigInteger m, BigIntegerCtx c)
921 BigInteger m;
922 BigIntegerCtx c;
923{ 873{
924#ifdef OPENSSL 874#ifdef OPENSSL
925 BN_CTX * ctx = NULL; 875 BN_CTX * ctx = NULL;
@@ -939,8 +889,7 @@ BigIntegerModAccelNew(m, c)
939} 889}
940 890
941BigIntegerResult 891BigIntegerResult
942BigIntegerModAccelFree(accel) 892BigIntegerModAccelFree(BigIntegerModAccel accel)
943 BigIntegerModAccel accel;
944{ 893{
945#ifdef OPENSSL 894#ifdef OPENSSL
946 if(accel) 895 if(accel)
diff --git a/3rd_party/libsrp6a-sha512/t_misc.c b/3rd_party/libsrp6a-sha512/t_misc.c
index 3053358..3a2cda1 100644
--- a/3rd_party/libsrp6a-sha512/t_misc.c
+++ b/3rd_party/libsrp6a-sha512/t_misc.c
@@ -80,8 +80,7 @@ SHA1_CTX randctxt;
80extern char ** environ; 80extern char ** environ;
81 81
82static void 82static void
83t_envhash(out) 83t_envhash(unsigned char * out)
84 unsigned char * out;
85{ 84{
86 char ** ptr; 85 char ** ptr;
87 char ebuf[256]; 86 char ebuf[256];
@@ -115,8 +114,7 @@ t_envhash(out)
115 * The entire buffer is run once through SHA to obtain the final result. 114 * The entire buffer is run once through SHA to obtain the final result.
116 */ 115 */
117static void 116static void
118t_fshash(out) 117t_fshash(unsigned char * out)
119 unsigned char * out;
120{ 118{
121 char dotpath[128]; 119 char dotpath[128];
122 struct stat st; 120 struct stat st;
@@ -317,9 +315,7 @@ t_stronginitrand()
317 * Each cycle generates 20 bytes of new output. 315 * Each cycle generates 20 bytes of new output.
318 */ 316 */
319_TYPE( void ) 317_TYPE( void )
320t_random(data, size) 318t_random(unsigned char * data, unsigned size)
321 unsigned char * data;
322 unsigned size;
323{ 319{
324 if(!initialized) 320 if(!initialized)
325 t_initrand(); 321 t_initrand();
@@ -369,10 +365,7 @@ t_random(data, size)
369 * single 320-bit value. 365 * single 320-bit value.
370 */ 366 */
371_TYPE( unsigned char * ) 367_TYPE( unsigned char * )
372t_sessionkey(key, sk, sklen) 368t_sessionkey(unsigned char * key, unsigned char * sk, unsigned sklen)
373 unsigned char * key;
374 unsigned char * sk;
375 unsigned sklen;
376{ 369{
377 unsigned i, klen; 370 unsigned i, klen;
378 unsigned char * hbuf; 371 unsigned char * hbuf;
@@ -411,11 +404,7 @@ t_sessionkey(key, sk, sklen)
411} 404}
412 405
413_TYPE( void ) 406_TYPE( void )
414t_mgf1(mask, masklen, seed, seedlen) 407t_mgf1(unsigned char * mask, unsigned masklen, const unsigned char * seed, unsigned seedlen)
415 unsigned char * mask;
416 unsigned masklen;
417 const unsigned char * seed;
418 unsigned seedlen;
419{ 408{
420 SHA1_CTX ctxt; 409 SHA1_CTX ctxt;
421 unsigned i = 0; 410 unsigned i = 0;
diff --git a/3rd_party/libsrp6a-sha512/t_truerand.c b/3rd_party/libsrp6a-sha512/t_truerand.c
index 4a4c3d2..f995ed7 100644
--- a/3rd_party/libsrp6a-sha512/t_truerand.c
+++ b/3rd_party/libsrp6a-sha512/t_truerand.c
@@ -227,8 +227,7 @@ raw_truerand()
227} 227}
228 228
229int 229int
230raw_n_truerand(n) 230raw_n_truerand(int n)
231int n;
232{ 231{
233 int slop, v; 232 int slop, v;
234 233