@@ -254,7 +254,7 @@ static uint32_t blk0(union char64long16 *block, int i) {
254
254
z += (w ^ x ^ y) + blk(i) + 0xCA62C1D6 + rol(v, 5); \
255
255
w = rol(w, 30);
256
256
257
- void SHA1Transform (uint32_t state [5 ], const unsigned char buffer [64 ]) {
257
+ void cs_sha1_transform (uint32_t state [5 ], const unsigned char buffer [64 ]) {
258
258
uint32_t a , b , c , d , e ;
259
259
union char64long16 block [1 ];
260
260
@@ -360,7 +360,7 @@ void SHA1Transform(uint32_t state[5], const unsigned char buffer[64]) {
360
360
(void ) e ;
361
361
}
362
362
363
- void SHA1Init ( SHA1_CTX * context ) {
363
+ void cs_sha1_init ( cs_sha1_ctx * context ) {
364
364
context -> state [0 ] = 0x67452301 ;
365
365
context -> state [1 ] = 0xEFCDAB89 ;
366
366
context -> state [2 ] = 0x98BADCFE ;
@@ -369,7 +369,7 @@ void SHA1Init(SHA1_CTX *context) {
369
369
context -> count [0 ] = context -> count [1 ] = 0 ;
370
370
}
371
371
372
- void SHA1Update ( SHA1_CTX * context , const unsigned char * data , uint32_t len ) {
372
+ void cs_sha1_update ( cs_sha1_ctx * context , const unsigned char * data , uint32_t len ) {
373
373
uint32_t i , j ;
374
374
375
375
j = context -> count [0 ];
@@ -378,17 +378,17 @@ void SHA1Update(SHA1_CTX *context, const unsigned char *data, uint32_t len) {
378
378
j = (j >> 3 ) & 63 ;
379
379
if ((j + len ) > 63 ) {
380
380
memcpy (& context -> buffer [j ], data , (i = 64 - j ));
381
- SHA1Transform (context -> state , context -> buffer );
381
+ cs_sha1_transform (context -> state , context -> buffer );
382
382
for (; i + 63 < len ; i += 64 ) {
383
- SHA1Transform (context -> state , & data [i ]);
383
+ cs_sha1_transform (context -> state , & data [i ]);
384
384
}
385
385
j = 0 ;
386
386
} else
387
387
i = 0 ;
388
388
memcpy (& context -> buffer [j ], & data [i ], len - i );
389
389
}
390
390
391
- void SHA1Final (unsigned char digest [20 ], SHA1_CTX * context ) {
391
+ void cs_sha1_final (unsigned char digest [20 ], cs_sha1_ctx * context ) {
392
392
unsigned i ;
393
393
unsigned char finalcount [8 ], c ;
394
394
@@ -398,12 +398,12 @@ void SHA1Final(unsigned char digest[20], SHA1_CTX *context) {
398
398
255 );
399
399
}
400
400
c = 0200 ;
401
- SHA1Update (context , & c , 1 );
401
+ cs_sha1_update (context , & c , 1 );
402
402
while ((context -> count [0 ] & 504 ) != 448 ) {
403
403
c = 0000 ;
404
- SHA1Update (context , & c , 1 );
404
+ cs_sha1_update (context , & c , 1 );
405
405
}
406
- SHA1Update (context , finalcount , 8 );
406
+ cs_sha1_update (context , finalcount , 8 );
407
407
for (i = 0 ; i < 20 ; i ++ ) {
408
408
digest [i ] =
409
409
(unsigned char ) ((context -> state [i >> 2 ] >> ((3 - (i & 3 )) * 8 )) & 255 );
@@ -415,13 +415,13 @@ void SHA1Final(unsigned char digest[20], SHA1_CTX *context) {
415
415
void hmac_sha1 (const unsigned char * key , size_t keylen ,
416
416
const unsigned char * data , size_t datalen ,
417
417
unsigned char out [20 ]) {
418
- SHA1_CTX ctx ;
418
+ cs_sha1_ctx ctx ;
419
419
unsigned char buf1 [64 ], buf2 [64 ], tmp_key [20 ], i ;
420
420
421
421
if (keylen > sizeof (buf1 )) {
422
- SHA1Init (& ctx );
423
- SHA1Update (& ctx , key , keylen );
424
- SHA1Final (tmp_key , & ctx );
422
+ cs_sha1_init (& ctx );
423
+ cs_sha1_update (& ctx , key , keylen );
424
+ cs_sha1_final (tmp_key , & ctx );
425
425
key = tmp_key ;
426
426
keylen = sizeof (tmp_key );
427
427
}
@@ -436,15 +436,15 @@ void hmac_sha1(const unsigned char *key, size_t keylen,
436
436
buf2 [i ] ^= 0x5c ;
437
437
}
438
438
439
- SHA1Init (& ctx );
440
- SHA1Update (& ctx , buf1 , sizeof (buf1 ));
441
- SHA1Update (& ctx , data , datalen );
442
- SHA1Final (out , & ctx );
439
+ cs_sha1_init (& ctx );
440
+ cs_sha1_update (& ctx , buf1 , sizeof (buf1 ));
441
+ cs_sha1_update (& ctx , data , datalen );
442
+ cs_sha1_final (out , & ctx );
443
443
444
- SHA1Init (& ctx );
445
- SHA1Update (& ctx , buf2 , sizeof (buf2 ));
446
- SHA1Update (& ctx , out , 20 );
447
- SHA1Final (out , & ctx );
444
+ cs_sha1_init (& ctx );
445
+ cs_sha1_update (& ctx , buf2 , sizeof (buf2 ));
446
+ cs_sha1_update (& ctx , out , 20 );
447
+ cs_sha1_final (out , & ctx );
448
448
}
449
449
450
450
#endif /* EXCLUDE_COMMON */
@@ -3592,13 +3592,13 @@ static void websocket_handler(struct ns_connection *nc, int ev, void *ev_data) {
3592
3592
static void ws_handshake (struct ns_connection * nc , const struct ns_str * key ) {
3593
3593
static const char * magic = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11" ;
3594
3594
char buf [500 ], sha [20 ], b64_sha [sizeof (sha ) * 2 ];
3595
- SHA1_CTX sha_ctx ;
3595
+ cs_sha1_ctx sha_ctx ;
3596
3596
3597
3597
snprintf (buf , sizeof (buf ), "%.*s%s" , (int ) key -> len , key -> p , magic );
3598
3598
3599
- SHA1Init (& sha_ctx );
3600
- SHA1Update (& sha_ctx , (unsigned char * ) buf , strlen (buf ));
3601
- SHA1Final ((unsigned char * ) sha , & sha_ctx );
3599
+ cs_sha1_init (& sha_ctx );
3600
+ cs_sha1_update (& sha_ctx , (unsigned char * ) buf , strlen (buf ));
3601
+ cs_sha1_final ((unsigned char * ) sha , & sha_ctx );
3602
3602
3603
3603
ns_base64_encode ((unsigned char * ) sha , sizeof (sha ), b64_sha );
3604
3604
ns_printf (nc , "%s%s%s" ,
0 commit comments