Skip to content

Commit

Permalink
3rd_party/libsrp6a-sha512: Update function definitions to modern style
Browse files Browse the repository at this point in the history
  • Loading branch information
nikias committed Jun 30, 2023
1 parent f4c30d5 commit 52ab7b7
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 122 deletions.
35 changes: 8 additions & 27 deletions 3rd_party/libsrp6a-sha512/t_conv.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
#include "cstr.h"

static int
hexDigitToInt(c)
char c;
hexDigitToInt(char c)
{
if(c >= '0' && c <= '9')
return c - '0';
Expand All @@ -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);
Expand All @@ -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;

Expand All @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
103 changes: 26 additions & 77 deletions 3rd_party/libsrp6a-sha512/t_math.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ typedef void * BigIntegerModAccel;
/* Math library interface stubs */

BigInteger
BigIntegerFromInt(n)
unsigned int n;
BigIntegerFromInt(unsigned int n)
{
#ifdef OPENSSL
BIGNUM * a = BN_new();
Expand Down Expand Up @@ -136,9 +135,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();
Expand Down Expand Up @@ -206,10 +203,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);
Expand Down Expand Up @@ -290,10 +284,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);
Expand All @@ -317,11 +308,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;
Expand All @@ -345,8 +332,7 @@ BigIntegerToString(src, dest, destlen, radix)
}

int
BigIntegerBitLen(b)
BigInteger b;
BigIntegerBitLen(BigInteger b)
{
#ifdef OPENSSL
return BN_num_bits(b);
Expand All @@ -364,8 +350,7 @@ BigIntegerBitLen(b)
}

int
BigIntegerCmp(c1, c2)
BigInteger c1, c2;
BigIntegerCmp(BigInteger c1, BigInteger c2)
{
#ifdef OPENSSL
return BN_cmp(c1, c2);
Expand All @@ -383,9 +368,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);
Expand Down Expand Up @@ -414,9 +397,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);
Expand All @@ -436,8 +417,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);
Expand All @@ -456,9 +436,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)
Expand All @@ -483,8 +461,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);
Expand All @@ -503,9 +480,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)
Expand All @@ -530,9 +505,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;
Expand All @@ -556,10 +529,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)
Expand All @@ -584,10 +554,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)
Expand Down Expand Up @@ -624,9 +591,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;
Expand All @@ -650,10 +615,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);
Expand Down Expand Up @@ -711,9 +673,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;
Expand Down Expand Up @@ -743,10 +703,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
Expand Down Expand Up @@ -793,9 +750,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;
Expand Down Expand Up @@ -846,8 +801,7 @@ BigIntegerCheckPrime(n, c)
}

BigIntegerResult
BigIntegerFree(b)
BigInteger b;
BigIntegerFree(BigInteger b)
{
#ifdef OPENSSL
BN_free(b);
Expand All @@ -869,8 +823,7 @@ BigIntegerFree(b)
}

BigIntegerResult
BigIntegerClearFree(b)
BigInteger b;
BigIntegerClearFree(BigInteger b)
{
#ifdef OPENSSL
BN_clear_free(b);
Expand Down Expand Up @@ -906,8 +859,7 @@ BigIntegerCtxNew()
}

BigIntegerResult
BigIntegerCtxFree(ctx)
BigIntegerCtx ctx;
BigIntegerCtxFree(BigIntegerCtx ctx)
{
#ifdef OPENSSL
if(ctx)
Expand All @@ -917,9 +869,7 @@ BigIntegerCtxFree(ctx)
}

BigIntegerModAccel
BigIntegerModAccelNew(m, c)
BigInteger m;
BigIntegerCtx c;
BigIntegerModAccelNew(BigInteger m, BigIntegerCtx c)
{
#ifdef OPENSSL
BN_CTX * ctx = NULL;
Expand All @@ -939,8 +889,7 @@ BigIntegerModAccelNew(m, c)
}

BigIntegerResult
BigIntegerModAccelFree(accel)
BigIntegerModAccel accel;
BigIntegerModAccelFree(BigIntegerModAccel accel)
{
#ifdef OPENSSL
if(accel)
Expand Down
Loading

0 comments on commit 52ab7b7

Please sign in to comment.