Skip to content

Commit 70a56d5

Browse files
committed
3rd_party/libsrp6a-sha512: Replace/Remove OpenSSL-3.0-deprecated API
1 parent 52ab7b7 commit 70a56d5

File tree

3 files changed

+44
-38
lines changed

3 files changed

+44
-38
lines changed

3rd_party/libsrp6a-sha512/t_math.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,13 @@ typedef BIGNUM * BigInteger;
3939
typedef BN_CTX * BigIntegerCtx;
4040
typedef BN_MONT_CTX * BigIntegerModAccel;
4141
#include <limits.h>
42+
#if OPENSSL_VERSION_NUMBER < 0x30000000L
4243
# ifndef OPENSSL_NO_ENGINE
4344
# define OPENSSL_ENGINE
4445
# include "openssl/engine.h"
4546
static ENGINE * default_engine = NULL;
4647
# endif /* OPENSSL_ENGINE */
48+
#endif
4749
typedef int (*modexp_meth)(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
4850
const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *mctx);
4951
static modexp_meth default_modexp = NULL;
@@ -758,7 +760,11 @@ BigIntegerCheckPrime(BigInteger n, BigIntegerCtx c)
758760
if(c == NULL)
759761
c = ctx = BN_CTX_new();
760762
#if OPENSSL_VERSION_NUMBER >= 0x00908000
761-
rv = BN_is_prime_ex(n, 25, c, NULL);
763+
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
764+
rv = BN_check_prime(n, c, NULL);
765+
#else
766+
rv = BN_is_prime_ex(n, 25, c, NULL);
767+
#endif
762768
#else
763769
rv = BN_is_prime(n, 25, NULL, c, NULL);
764770
#endif

3rd_party/libsrp6a-sha512/t_misc.c

+36-36
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ static unsigned char crpool[64];
6363
static unsigned char randpool[SHA_DIGESTSIZE], randout[SHA_DIGESTSIZE];
6464
static unsigned long randcnt = 0;
6565
static unsigned int outpos = 0;
66-
SHA1_CTX randctxt;
66+
SHA512_CTX randctxt;
6767
#endif /* OPENSSL */
6868

6969
/*
@@ -84,15 +84,15 @@ t_envhash(unsigned char * out)
8484
{
8585
char ** ptr;
8686
char ebuf[256];
87-
SHA1_CTX ctxt;
87+
SHA512_CTX ctxt;
8888

89-
SHA1Init(&ctxt);
89+
SHA512Init(&ctxt);
9090
for(ptr = environ; *ptr; ++ptr) {
9191
strncpy(ebuf, *ptr, 255);
9292
ebuf[255] = '\0';
93-
SHA1Update(&ctxt, ebuf, strlen(ebuf));
93+
SHA512Update(&ctxt, ebuf, strlen(ebuf));
9494
}
95-
SHA1Final(out, &ctxt);
95+
SHA512Final(out, &ctxt);
9696
}
9797

9898
/*
@@ -118,13 +118,13 @@ t_fshash(unsigned char * out)
118118
{
119119
char dotpath[128];
120120
struct stat st;
121-
SHA1_CTX ctxt;
121+
SHA512_CTX ctxt;
122122
int i, pinode;
123123
dev_t pdev;
124124

125-
SHA1Init(&ctxt);
125+
SHA512Init(&ctxt);
126126
if(stat(".", &st) >= 0) {
127-
SHA1Update(&ctxt, (unsigned char *) &st, sizeof(st));
127+
SHA512Update(&ctxt, (unsigned char *) &st, sizeof(st));
128128
pinode = st.st_ino;
129129
pdev = st.st_dev;
130130
strcpy(dotpath, "..");
@@ -133,22 +133,22 @@ t_fshash(unsigned char * out)
133133
break;
134134
if(st.st_ino == pinode && st.st_dev == pdev)
135135
break;
136-
SHA1Update(&ctxt, (unsigned char *) &st, sizeof(st));
136+
SHA512Update(&ctxt, (unsigned char *) &st, sizeof(st));
137137
pinode = st.st_ino;
138138
pdev = st.st_dev;
139139
strcat(dotpath, "/..");
140140
}
141141
}
142142

143143
if(fstat(0, &st) >= 0)
144-
SHA1Update(&ctxt, (unsigned char *) &st, sizeof(st));
144+
SHA512Update(&ctxt, (unsigned char *) &st, sizeof(st));
145145

146146
sprintf(dotpath, "/tmp/rnd.%d", getpid());
147147
if(creat(dotpath, 0600) >= 0 && stat(dotpath, &st) >= 0)
148-
SHA1Update(&ctxt, (unsigned char *) &st, sizeof(st));
148+
SHA512Update(&ctxt, (unsigned char *) &st, sizeof(st));
149149
unlink(dotpath);
150150

151-
SHA1Final(out, &ctxt);
151+
SHA512Final(out, &ctxt);
152152
}
153153

154154
/*
@@ -191,7 +191,6 @@ unsigned long raw_truerand();
191191
static void
192192
t_initrand()
193193
{
194-
SHA1_CTX ctxt;
195194
#ifdef USE_FTIME
196195
struct timeb t;
197196
#else
@@ -271,9 +270,10 @@ t_initrand()
271270
#elif defined(GCRYPT)
272271
gcry_random_add_bytes((unsigned char *)&preseed, sizeof(preseed), -1);
273272
#else
274-
SHA1Init(&ctxt);
275-
SHA1Update(&ctxt, (unsigned char *) &preseed, sizeof(preseed));
276-
SHA1Final(randpool, &ctxt);
273+
SHA512_CTX ctxt;
274+
SHA512Init(&ctxt);
275+
SHA512Update(&ctxt, (unsigned char *) &preseed, sizeof(preseed));
276+
SHA512Final(randpool, &ctxt);
277277
memset((unsigned char *) &ctxt, 0, sizeof(ctxt));
278278
outpos = 0;
279279
#endif /* OPENSSL */
@@ -340,13 +340,13 @@ t_random(unsigned char * data, unsigned size)
340340
}
341341

342342
/* Recycle */
343-
SHA1Init(&randctxt);
344-
SHA1Update(&randctxt, randpool, sizeof(randpool));
345-
SHA1Final(randout, &randctxt);
346-
SHA1Init(&randctxt);
347-
SHA1Update(&randctxt, (unsigned char *) &randcnt, sizeof(randcnt));
348-
SHA1Update(&randctxt, randpool, sizeof(randpool));
349-
SHA1Final(randpool, &randctxt);
343+
SHA512Init(&randctxt);
344+
SHA512Update(&randctxt, randpool, sizeof(randpool));
345+
SHA512Final(randout, &randctxt);
346+
SHA512Init(&randctxt);
347+
SHA512Update(&randctxt, (unsigned char *) &randcnt, sizeof(randcnt));
348+
SHA512Update(&randctxt, randpool, sizeof(randpool));
349+
SHA512Final(randpool, &randctxt);
350350
++randcnt;
351351
outpos = sizeof(randout);
352352
}
@@ -370,7 +370,7 @@ t_sessionkey(unsigned char * key, unsigned char * sk, unsigned sklen)
370370
unsigned i, klen;
371371
unsigned char * hbuf;
372372
unsigned char hout[SHA_DIGESTSIZE];
373-
SHA1_CTX ctxt;
373+
SHA512_CTX ctxt;
374374

375375
while(sklen > 0 && *sk == 0) { /* Skip leading 0's */
376376
--sklen;
@@ -383,17 +383,17 @@ t_sessionkey(unsigned char * key, unsigned char * sk, unsigned sklen)
383383

384384
for(i = 0; i < klen; ++i)
385385
hbuf[i] = sk[sklen - 2 * i - 1];
386-
SHA1Init(&ctxt);
387-
SHA1Update(&ctxt, hbuf, klen);
388-
SHA1Final(hout, &ctxt);
386+
SHA512Init(&ctxt);
387+
SHA512Update(&ctxt, hbuf, klen);
388+
SHA512Final(hout, &ctxt);
389389
for(i = 0; i < sizeof(hout); ++i)
390390
key[2 * i] = hout[i];
391391

392392
for(i = 0; i < klen; ++i)
393393
hbuf[i] = sk[sklen - 2 * i - 2];
394-
SHA1Init(&ctxt);
395-
SHA1Update(&ctxt, hbuf, klen);
396-
SHA1Final(hout, &ctxt);
394+
SHA512Init(&ctxt);
395+
SHA512Update(&ctxt, hbuf, klen);
396+
SHA512Final(hout, &ctxt);
397397
for(i = 0; i < sizeof(hout); ++i)
398398
key[2 * i + 1] = hout[i];
399399

@@ -406,7 +406,7 @@ t_sessionkey(unsigned char * key, unsigned char * sk, unsigned sklen)
406406
_TYPE( void )
407407
t_mgf1(unsigned char * mask, unsigned masklen, const unsigned char * seed, unsigned seedlen)
408408
{
409-
SHA1_CTX ctxt;
409+
SHA512_CTX ctxt;
410410
unsigned i = 0;
411411
unsigned pos = 0;
412412
unsigned char cnt[4];
@@ -417,17 +417,17 @@ t_mgf1(unsigned char * mask, unsigned masklen, const unsigned char * seed, unsig
417417
cnt[1] = (i >> 16) & 0xFF;
418418
cnt[2] = (i >> 8) & 0xFF;
419419
cnt[3] = i & 0xFF;
420-
SHA1Init(&ctxt);
421-
SHA1Update(&ctxt, seed, seedlen);
422-
SHA1Update(&ctxt, cnt, 4);
420+
SHA512Init(&ctxt);
421+
SHA512Update(&ctxt, seed, seedlen);
422+
SHA512Update(&ctxt, cnt, 4);
423423

424424
if(pos + SHA_DIGESTSIZE > masklen) {
425-
SHA1Final(hout, &ctxt);
425+
SHA512Final(hout, &ctxt);
426426
memcpy(mask + pos, hout, masklen - pos);
427427
pos = masklen;
428428
}
429429
else {
430-
SHA1Final(mask + pos, &ctxt);
430+
SHA512Final(mask + pos, &ctxt);
431431
pos += SHA_DIGESTSIZE;
432432
}
433433

3rd_party/libsrp6a-sha512/t_sha.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#endif
1010
#endif
1111

12-
#define SHA_DIGESTSIZE 20
12+
#define SHA_DIGESTSIZE 64
1313

1414
#ifdef OPENSSL
1515
#define OPENSSL_SHA 1

0 commit comments

Comments
 (0)