Skip to content

Commit 52ab7b7

Browse files
committed
3rd_party/libsrp6a-sha512: Update function definitions to modern style
1 parent f4c30d5 commit 52ab7b7

File tree

4 files changed

+40
-122
lines changed

4 files changed

+40
-122
lines changed

3rd_party/libsrp6a-sha512/t_conv.c

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@
3333
#include "cstr.h"
3434

3535
static int
36-
hexDigitToInt(c)
37-
char c;
36+
hexDigitToInt(char c)
3837
{
3938
if(c >= '0' && c <= '9')
4039
return c - '0';
@@ -50,9 +49,7 @@ hexDigitToInt(c)
5049
* Convert a hex string to a string of bytes; return size of dst
5150
*/
5251
_TYPE( int )
53-
t_fromhex(dst, src)
54-
char * dst;
55-
const char * src;
52+
t_fromhex(char *dst, const char *src)
5653
{
5754
register char *chp = dst;
5855
register unsigned size = strlen(src);
@@ -76,10 +73,7 @@ t_fromhex(dst, src)
7673
* Convert a string of bytes to their hex representation
7774
*/
7875
_TYPE( char * )
79-
t_tohex(dst, src, size)
80-
char * dst;
81-
const char * src;
82-
unsigned size;
76+
t_tohex(char *dst, const char *src, unsigned size)
8377
{
8478
int notleading = 0;
8579

@@ -103,10 +97,7 @@ t_tohex(dst, src, size)
10397
}
10498

10599
_TYPE( char * )
106-
t_tohexcstr(dst, src, size)
107-
cstr * dst;
108-
const char * src;
109-
unsigned size;
100+
t_tohexcstr(cstr *dst, const char *src, unsigned size)
110101
{
111102
cstr_set_length(dst, 2 * size + 1);
112103
return t_tohex(dst->data, src, size);
@@ -119,9 +110,7 @@ static char b64table[] =
119110
* Convert a base64 string into raw byte array representation.
120111
*/
121112
_TYPE( int )
122-
t_fromb64(dst, src)
123-
char * dst;
124-
const char * src;
113+
t_fromb64(char *dst, const char *src)
125114
{
126115
unsigned char *a;
127116
char *loc;
@@ -179,9 +168,7 @@ t_fromb64(dst, src)
179168
}
180169

181170
_TYPE( int )
182-
t_cstrfromb64(dst, src)
183-
cstr * dst;
184-
const char * src;
171+
t_cstrfromb64(cstr *dst, const char *src)
185172
{
186173
int len;
187174
cstr_set_length(dst, (strlen(src) * 6 + 7) / 8);
@@ -194,10 +181,7 @@ t_cstrfromb64(dst, src)
194181
* Convert a raw byte string into a null-terminated base64 ASCII string.
195182
*/
196183
_TYPE( char * )
197-
t_tob64(dst, src, size)
198-
char * dst;
199-
const char * src;
200-
unsigned size;
184+
t_tob64(char *dst, const char *src, unsigned size)
201185
{
202186
int c, pos = size % 3;
203187
unsigned char b0 = 0, b1 = 0, b2 = 0, notleading = 0;
@@ -248,10 +232,7 @@ t_tob64(dst, src, size)
248232
}
249233

250234
_TYPE( char * )
251-
t_tob64cstr(dst, src, sz)
252-
cstr * dst;
253-
const char * src;
254-
unsigned int sz;
235+
t_tob64cstr(cstr *dst, const char *src, unsigned int sz)
255236
{
256237
cstr_set_length(dst, (sz * 8 + 5) / 6 + 1);
257238
return t_tob64(dst->data, src, sz);

3rd_party/libsrp6a-sha512/t_math.c

Lines changed: 26 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ typedef void * BigIntegerModAccel;
9999
/* Math library interface stubs */
100100

101101
BigInteger
102-
BigIntegerFromInt(n)
103-
unsigned int n;
102+
BigIntegerFromInt(unsigned int n)
104103
{
105104
#ifdef OPENSSL
106105
BIGNUM * a = BN_new();
@@ -136,9 +135,7 @@ BigIntegerFromInt(n)
136135
}
137136

138137
BigInteger
139-
BigIntegerFromBytes(bytes, length)
140-
const unsigned char * bytes;
141-
int length;
138+
BigIntegerFromBytes(const unsigned char *bytes, int length)
142139
{
143140
#ifdef OPENSSL
144141
BIGNUM * a = BN_new();
@@ -206,10 +203,7 @@ BigIntegerFromBytes(bytes, length)
206203
}
207204

208205
int
209-
BigIntegerToBytes(src, dest, destlen)
210-
BigInteger src;
211-
unsigned char * dest;
212-
int destlen;
206+
BigIntegerToBytes(BigInteger src, unsigned char *dest, int destlen)
213207
{
214208
#ifdef OPENSSL
215209
return BN_bn2bin(src, dest);
@@ -290,10 +284,7 @@ BigIntegerToCstrEx(BigInteger x, cstr * out, int len)
290284
}
291285

292286
BigIntegerResult
293-
BigIntegerToHex(src, dest, destlen)
294-
BigInteger src;
295-
char * dest;
296-
int destlen;
287+
BigIntegerToHex(BigInteger src, char *dest, int destlen)
297288
{
298289
#ifdef OPENSSL
299290
strncpy(dest, BN_bn2hex(src), destlen);
@@ -317,11 +308,7 @@ static char b64table[] =
317308
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz./";
318309

319310
BigIntegerResult
320-
BigIntegerToString(src, dest, destlen, radix)
321-
BigInteger src;
322-
char * dest;
323-
int destlen;
324-
unsigned int radix;
311+
BigIntegerToString(BigInteger src, char *dest, int destlen, unsigned int radix)
325312
{
326313
BigInteger t = BigIntegerFromInt(0);
327314
char * p = dest;
@@ -345,8 +332,7 @@ BigIntegerToString(src, dest, destlen, radix)
345332
}
346333

347334
int
348-
BigIntegerBitLen(b)
349-
BigInteger b;
335+
BigIntegerBitLen(BigInteger b)
350336
{
351337
#ifdef OPENSSL
352338
return BN_num_bits(b);
@@ -364,8 +350,7 @@ BigIntegerBitLen(b)
364350
}
365351

366352
int
367-
BigIntegerCmp(c1, c2)
368-
BigInteger c1, c2;
353+
BigIntegerCmp(BigInteger c1, BigInteger c2)
369354
{
370355
#ifdef OPENSSL
371356
return BN_cmp(c1, c2);
@@ -383,9 +368,7 @@ BigIntegerCmp(c1, c2)
383368
}
384369

385370
int
386-
BigIntegerCmpInt(c1, c2)
387-
BigInteger c1;
388-
unsigned int c2;
371+
BigIntegerCmpInt(BigInteger c1, unsigned int c2)
389372
{
390373
#ifdef OPENSSL
391374
BigInteger bc2 = BigIntegerFromInt(c2);
@@ -414,9 +397,7 @@ BigIntegerCmpInt(c1, c2)
414397
}
415398

416399
BigIntegerResult
417-
BigIntegerLShift(result, x, bits)
418-
BigInteger result, x;
419-
unsigned int bits;
400+
BigIntegerLShift(BigInteger result, BigInteger x, unsigned int bits)
420401
{
421402
#ifdef OPENSSL
422403
BN_lshift(result, x, bits);
@@ -436,8 +417,7 @@ BigIntegerLShift(result, x, bits)
436417
}
437418

438419
BigIntegerResult
439-
BigIntegerAdd(result, a1, a2)
440-
BigInteger result, a1, a2;
420+
BigIntegerAdd(BigInteger result, BigInteger a1, BigInteger a2)
441421
{
442422
#ifdef OPENSSL
443423
BN_add(result, a1, a2);
@@ -456,9 +436,7 @@ BigIntegerAdd(result, a1, a2)
456436
}
457437

458438
BigIntegerResult
459-
BigIntegerAddInt(result, a1, a2)
460-
BigInteger result, a1;
461-
unsigned int a2;
439+
BigIntegerAddInt(BigInteger result, BigInteger a1, unsigned int a2)
462440
{
463441
#ifdef OPENSSL
464442
if(result != a1)
@@ -483,8 +461,7 @@ BigIntegerAddInt(result, a1, a2)
483461
}
484462

485463
BigIntegerResult
486-
BigIntegerSub(result, s1, s2)
487-
BigInteger result, s1, s2;
464+
BigIntegerSub(BigInteger result, BigInteger s1, BigInteger s2)
488465
{
489466
#ifdef OPENSSL
490467
BN_sub(result, s1, s2);
@@ -503,9 +480,7 @@ BigIntegerSub(result, s1, s2)
503480
}
504481

505482
BigIntegerResult
506-
BigIntegerSubInt(result, s1, s2)
507-
BigInteger result, s1;
508-
unsigned int s2;
483+
BigIntegerSubInt(BigInteger result, BigInteger s1, unsigned int s2)
509484
{
510485
#ifdef OPENSSL
511486
if(result != s1)
@@ -530,9 +505,7 @@ BigIntegerSubInt(result, s1, s2)
530505
}
531506

532507
BigIntegerResult
533-
BigIntegerMul(result, m1, m2, c)
534-
BigInteger result, m1, m2;
535-
BigIntegerCtx c;
508+
BigIntegerMul(BigInteger result, BigInteger m1, BigInteger m2, BigIntegerCtx c)
536509
{
537510
#ifdef OPENSSL
538511
BN_CTX * ctx = NULL;
@@ -556,10 +529,7 @@ BigIntegerMul(result, m1, m2, c)
556529
}
557530

558531
BigIntegerResult
559-
BigIntegerMulInt(result, m1, m2, c)
560-
BigInteger result, m1;
561-
unsigned int m2;
562-
BigIntegerCtx c;
532+
BigIntegerMulInt(BigInteger result, BigInteger m1, unsigned int m2, BigIntegerCtx c)
563533
{
564534
#ifdef OPENSSL
565535
if(result != m1)
@@ -584,10 +554,7 @@ BigIntegerMulInt(result, m1, m2, c)
584554
}
585555

586556
BigIntegerResult
587-
BigIntegerDivInt(result, d, m, c)
588-
BigInteger result, d;
589-
unsigned int m;
590-
BigIntegerCtx c;
557+
BigIntegerDivInt(BigInteger result, BigInteger d, unsigned int m, BigIntegerCtx c)
591558
{
592559
#ifdef OPENSSL
593560
if(result != d)
@@ -624,9 +591,7 @@ BigIntegerDivInt(result, d, m, c)
624591
}
625592

626593
BigIntegerResult
627-
BigIntegerMod(result, d, m, c)
628-
BigInteger result, d, m;
629-
BigIntegerCtx c;
594+
BigIntegerMod(BigInteger result, BigInteger d, BigInteger m, BigIntegerCtx c)
630595
{
631596
#ifdef OPENSSL
632597
BN_CTX * ctx = NULL;
@@ -650,10 +615,7 @@ BigIntegerMod(result, d, m, c)
650615
}
651616

652617
unsigned int
653-
BigIntegerModInt(d, m, c)
654-
BigInteger d;
655-
unsigned int m;
656-
BigIntegerCtx c;
618+
BigIntegerModInt(BigInteger d, unsigned int m, BigIntegerCtx c)
657619
{
658620
#ifdef OPENSSL
659621
return BN_mod_word(d, m);
@@ -711,9 +673,7 @@ BigIntegerModInt(d, m, c)
711673
}
712674

713675
BigIntegerResult
714-
BigIntegerModMul(r, m1, m2, modulus, c)
715-
BigInteger r, m1, m2, modulus;
716-
BigIntegerCtx c;
676+
BigIntegerModMul(BigInteger r, BigInteger m1, BigInteger m2, BigInteger modulus, BigIntegerCtx c)
717677
{
718678
#ifdef OPENSSL
719679
BN_CTX * ctx = NULL;
@@ -743,10 +703,7 @@ BigIntegerModMul(r, m1, m2, modulus, c)
743703
}
744704

745705
BigIntegerResult
746-
BigIntegerModExp(r, b, e, m, c, a)
747-
BigInteger r, b, e, m;
748-
BigIntegerCtx c;
749-
BigIntegerModAccel a;
706+
BigIntegerModExp(BigInteger r, BigInteger b, BigInteger e, BigInteger m, BigIntegerCtx c, BigIntegerModAccel a)
750707
{
751708
#ifdef OPENSSL
752709
#if OPENSSL_VERSION_NUMBER >= 0x00906000
@@ -793,9 +750,7 @@ int _mbedtls_f_rng(void* unused, unsigned char *buf, size_t size)
793750
#endif
794751

795752
int
796-
BigIntegerCheckPrime(n, c)
797-
BigInteger n;
798-
BigIntegerCtx c;
753+
BigIntegerCheckPrime(BigInteger n, BigIntegerCtx c)
799754
{
800755
#ifdef OPENSSL
801756
int rv;
@@ -846,8 +801,7 @@ BigIntegerCheckPrime(n, c)
846801
}
847802

848803
BigIntegerResult
849-
BigIntegerFree(b)
850-
BigInteger b;
804+
BigIntegerFree(BigInteger b)
851805
{
852806
#ifdef OPENSSL
853807
BN_free(b);
@@ -869,8 +823,7 @@ BigIntegerFree(b)
869823
}
870824

871825
BigIntegerResult
872-
BigIntegerClearFree(b)
873-
BigInteger b;
826+
BigIntegerClearFree(BigInteger b)
874827
{
875828
#ifdef OPENSSL
876829
BN_clear_free(b);
@@ -906,8 +859,7 @@ BigIntegerCtxNew()
906859
}
907860

908861
BigIntegerResult
909-
BigIntegerCtxFree(ctx)
910-
BigIntegerCtx ctx;
862+
BigIntegerCtxFree(BigIntegerCtx ctx)
911863
{
912864
#ifdef OPENSSL
913865
if(ctx)
@@ -917,9 +869,7 @@ BigIntegerCtxFree(ctx)
917869
}
918870

919871
BigIntegerModAccel
920-
BigIntegerModAccelNew(m, c)
921-
BigInteger m;
922-
BigIntegerCtx c;
872+
BigIntegerModAccelNew(BigInteger m, BigIntegerCtx c)
923873
{
924874
#ifdef OPENSSL
925875
BN_CTX * ctx = NULL;
@@ -939,8 +889,7 @@ BigIntegerModAccelNew(m, c)
939889
}
940890

941891
BigIntegerResult
942-
BigIntegerModAccelFree(accel)
943-
BigIntegerModAccel accel;
892+
BigIntegerModAccelFree(BigIntegerModAccel accel)
944893
{
945894
#ifdef OPENSSL
946895
if(accel)

0 commit comments

Comments
 (0)