yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f65d756bf
master
1/* 2* MD5 implementation is based on: 3* http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5 4* Original file header is at the bottom of this file. 5* 6* SHA1 implementation is based on: 7* https://github.com/983/SHA1 8* Original LICENSE is at the bottom of this file. 9*/ 10 11#include "slang-crypto.h" 12 13#include "../core/slang-char-util.h" 14 15namespace Slang 16{ 17 18// DigestUtil 19 20/*static*/ String DigestUtil ::digestToString (const void * digest ,SlangInt digestSize ) 21{ 22SLANG_ASSERT (digest && digestSize >=0 ); 23 24static const char * hex = "0123456789abcdef" ; 25 26String str ; 27const uint8_t * data = reinterpret_cast < const uint8_t *> (digest ); 28for (SlangInt i = 0 ;i < digestSize ;++ i ) 29 { 30str .append (hex [data [i ] >>4 ]); 31str .append (hex [data [i ]& 0xf ]); 32 } 33return str ; 34} 35 36/*static*/ bool DigestUtil ::stringToDigest ( 37const char * str , 38SlangInt strLength , 39void * digest , 40SlangInt digestSize ) 41{ 42SLANG_ASSERT (str && strLength >=0 && digest && digestSize >=0 ); 43 44if (strLength != digestSize * 2 ) 45 { 46 ::memset (digest ,0 ,digestSize ); 47return false; 48 } 49 50uint8_t * data = reinterpret_cast < uint8_t *> (digest ); 51for (SlangInt i = 0 ;i < digestSize ;++ i ) 52 { 53int upper = CharUtil ::getHexDigitValue (str [i * 2 ]); 54int lower = CharUtil ::getHexDigitValue (str [i * 2 + 1 ]); 55if (upper == -1 || lower == -1 ) 56 { 57 ::memset (digest ,0 ,digestSize ); 58return false; 59 } 60data [i ]= uint8_t (lower |upper <<4 ); 61 ; 62 } 63 64return true; 65} 66 67// MD5 68 69MD5 ::MD5 () 70{ 71init (); 72} 73 74void MD5 ::init () 75{ 76m_lo = 0 ; 77m_hi = 0 ; 78m_a = 0x67452301 ; 79m_b = 0xefcdab89 ; 80m_c = 0x98badcfe ; 81m_d = 0x10325476 ; 82} 83 84void MD5 ::update (const void * data ,SlangSizeT size ) 85{ 86uint32_t saved_lo ; 87uint32_t used ; 88uint32_t available ; 89 90saved_lo = m_lo ; 91if ((m_lo = (saved_lo + size )& 0x1fffffff )< saved_lo ) 92 { 93m_hi ++ ; 94 } 95m_hi += (uint32_t )size >>29 ; 96 97used = saved_lo & 0x3f ; 98 99if (used ) 100 { 101available = 64 - used ; 102 103if (size < available ) 104 { 105 ::memcpy (& m_buffer [used ],data ,size ); 106return ; 107 } 108 109 ::memcpy (& m_buffer [used ],data ,available ); 110data = reinterpret_cast < const uint8_t *> (data )+ available ; 111size -= available ; 112processBlock (m_buffer ,64 ); 113 } 114 115if (size >=64 ) 116 { 117data = processBlock (data ,size & ~(SlangInt )0x3f ); 118size &=0x3f ; 119 } 120 121 ::memcpy (m_buffer ,data ,size ); 122} 123 124MD5 ::Digest MD5 ::finalize () 125{ 126uint32_t used ,available ; 127 128used = m_lo & 0x3f ; 129 130m_buffer [used ++ ]= 0x80 ; 131 132available = 64 - used ; 133 134if (available < 8 ) 135 { 136 ::memset (& m_buffer [used ],0 ,available ); 137processBlock (m_buffer ,64 ); 138used = 0 ; 139available = 64 ; 140 } 141 142 ::memset (& m_buffer [used ],0 ,available - 8 ); 143 144m_lo <<=3 ; 145 146m_buffer [56 ]= uint8_t (m_lo ); 147m_buffer [57 ]= uint8_t (m_lo >>8 ); 148m_buffer [58 ]= uint8_t (m_lo >>16 ); 149m_buffer [59 ]= uint8_t (m_lo >>24 ); 150m_buffer [60 ]= uint8_t (m_hi ); 151m_buffer [61 ]= uint8_t (m_hi >>8 ); 152m_buffer [62 ]= uint8_t (m_hi >>16 ); 153m_buffer [63 ]= uint8_t (m_hi >>24 ); 154 155processBlock (m_buffer ,64 ); 156 157Digest digest ; 158digest .data [0 ]= m_a ; 159digest .data [1 ]= m_b ; 160digest .data [2 ]= m_c ; 161digest .data [3 ]= m_d ; 162 163return digest ; 164} 165 166/* 167* The basic MD5 functions. 168* 169* F and G are optimized compared to their RFC 1321 definitions for 170* architectures that lack an AND-NOT instruction, just like in Colin Plumb's 171* implementation. 172*/ 173#define F (x ,y ,z ) ((z) ^ ((x) & ((y) ^ (z)))) 174#define G (x ,y ,z ) ((y) ^ ((z) & ((x) ^ (y)))) 175#define H (x ,y ,z ) (((x) ^ (y)) ^ (z)) 176#define H2 (x ,y ,z ) ((x) ^ ((y) ^ (z))) 177#define I (x ,y ,z ) ((y) ^ ((x) | ~(z))) 178 179/* 180* The MD5 transformation for all four rounds. 181*/ 182#define STEP (f ,a ,b ,c ,d ,x ,t ,s ) \ 183 (a) += f((b), (c), (d)) + (x) + (t); \ 184 (a) = (((a) << (s)) | (((a) & 0xffffffff) >> (32 - (s)))); \ 185 (a) += (b); 186 187/* 188* SET reads 4 input bytes in little-endian byte order and stores them in a 189* properly aligned word in host byte order. 190*/ 191#define SET (n ) \ 192 (m_block[(n)] = (uint32_t)ptr[(n) * 4] | ((uint32_t)ptr[(n) * 4 + 1] << 8) | \ 193 ((uint32_t)ptr[(n) * 4 + 2] << 16) | ((uint32_t)ptr[(n) * 4 + 3] << 24)) 194#define GET (n ) (m_block[(n)]) 195 196const void * MD5 ::processBlock (const void * data ,SlangInt size ) 197{ 198const unsigned char * ptr ; 199ptr = (const unsigned char * )data ; 200 201uint32_t a = m_a ; 202uint32_t b = m_b ; 203uint32_t c = m_c ; 204uint32_t d = m_d ; 205 206do 207 { 208uint32_t saved_a = a ; 209uint32_t saved_b = b ; 210uint32_t saved_c = c ; 211uint32_t saved_d = d ; 212 213/* Round 1 */ 214STEP (F ,a ,b ,c ,d ,SET (0 ),0xd76aa478 ,7 ) 215STEP (F ,d ,a ,b ,c ,SET (1 ),0xe8c7b756 ,12 ) 216STEP (F ,c ,d ,a ,b ,SET (2 ),0x242070db ,17 ) 217STEP (F ,b ,c ,d ,a ,SET (3 ),0xc1bdceee ,22 ) 218STEP (F ,a ,b ,c ,d ,SET (4 ),0xf57c0faf ,7 ) 219STEP (F ,d ,a ,b ,c ,SET (5 ),0x4787c62a ,12 ) 220STEP (F ,c ,d ,a ,b ,SET (6 ),0xa8304613 ,17 ) 221STEP (F ,b ,c ,d ,a ,SET (7 ),0xfd469501 ,22 ) 222STEP (F ,a ,b ,c ,d ,SET (8 ),0x698098d8 ,7 ) 223STEP (F ,d ,a ,b ,c ,SET (9 ),0x8b44f7af ,12 ) 224STEP (F ,c ,d ,a ,b ,SET (10 ),0xffff5bb1 ,17 ) 225STEP (F ,b ,c ,d ,a ,SET (11 ),0x895cd7be ,22 ) 226STEP (F ,a ,b ,c ,d ,SET (12 ),0x6b901122 ,7 ) 227STEP (F ,d ,a ,b ,c ,SET (13 ),0xfd987193 ,12 ) 228STEP (F ,c ,d ,a ,b ,SET (14 ),0xa679438e ,17 ) 229STEP (F ,b ,c ,d ,a ,SET (15 ),0x49b40821 ,22 ) 230 231/* Round 2 */ 232STEP (G ,a ,b ,c ,d ,GET (1 ),0xf61e2562 ,5 ) 233STEP (G ,d ,a ,b ,c ,GET (6 ),0xc040b340 ,9 ) 234STEP (G ,c ,d ,a ,b ,GET (11 ),0x265e5a51 ,14 ) 235STEP (G ,b ,c ,d ,a ,GET (0 ),0xe9b6c7aa ,20 ) 236STEP (G ,a ,b ,c ,d ,GET (5 ),0xd62f105d ,5 ) 237STEP (G ,d ,a ,b ,c ,GET (10 ),0x02441453 ,9 ) 238STEP (G ,c ,d ,a ,b ,GET (15 ),0xd8a1e681 ,14 ) 239STEP (G ,b ,c ,d ,a ,GET (4 ),0xe7d3fbc8 ,20 ) 240STEP (G ,a ,b ,c ,d ,GET (9 ),0x21e1cde6 ,5 ) 241STEP (G ,d ,a ,b ,c ,GET (14 ),0xc33707d6 ,9 ) 242STEP (G ,c ,d ,a ,b ,GET (3 ),0xf4d50d87 ,14 ) 243STEP (G ,b ,c ,d ,a ,GET (8 ),0x455a14ed ,20 ) 244STEP (G ,a ,b ,c ,d ,GET (13 ),0xa9e3e905 ,5 ) 245STEP (G ,d ,a ,b ,c ,GET (2 ),0xfcefa3f8 ,9 ) 246STEP (G ,c ,d ,a ,b ,GET (7 ),0x676f02d9 ,14 ) 247STEP (G ,b ,c ,d ,a ,GET (12 ),0x8d2a4c8a ,20 ) 248 249/* Round 3 */ 250STEP (H ,a ,b ,c ,d ,GET (5 ),0xfffa3942 ,4 ) 251STEP (H2 ,d ,a ,b ,c ,GET (8 ),0x8771f681 ,11 ) 252STEP (H ,c ,d ,a ,b ,GET (11 ),0x6d9d6122 ,16 ) 253STEP (H2 ,b ,c ,d ,a ,GET (14 ),0xfde5380c ,23 ) 254STEP (H ,a ,b ,c ,d ,GET (1 ),0xa4beea44 ,4 ) 255STEP (H2 ,d ,a ,b ,c ,GET (4 ),0x4bdecfa9 ,11 ) 256STEP (H ,c ,d ,a ,b ,GET (7 ),0xf6bb4b60 ,16 ) 257STEP (H2 ,b ,c ,d ,a ,GET (10 ),0xbebfbc70 ,23 ) 258STEP (H ,a ,b ,c ,d ,GET (13 ),0x289b7ec6 ,4 ) 259STEP (H2 ,d ,a ,b ,c ,GET (0 ),0xeaa127fa ,11 ) 260STEP (H ,c ,d ,a ,b ,GET (3 ),0xd4ef3085 ,16 ) 261STEP (H2 ,b ,c ,d ,a ,GET (6 ),0x04881d05 ,23 ) 262STEP (H ,a ,b ,c ,d ,GET (9 ),0xd9d4d039 ,4 ) 263STEP (H2 ,d ,a ,b ,c ,GET (12 ),0xe6db99e5 ,11 ) 264STEP (H ,c ,d ,a ,b ,GET (15 ),0x1fa27cf8 ,16 ) 265STEP (H2 ,b ,c ,d ,a ,GET (2 ),0xc4ac5665 ,23 ) 266 267/* Round 4 */ 268STEP (I ,a ,b ,c ,d ,GET (0 ),0xf4292244 ,6 ) 269STEP (I ,d ,a ,b ,c ,GET (7 ),0x432aff97 ,10 ) 270STEP (I ,c ,d ,a ,b ,GET (14 ),0xab9423a7 ,15 ) 271STEP (I ,b ,c ,d ,a ,GET (5 ),0xfc93a039 ,21 ) 272STEP (I ,a ,b ,c ,d ,GET (12 ),0x655b59c3 ,6 ) 273STEP (I ,d ,a ,b ,c ,GET (3 ),0x8f0ccc92 ,10 ) 274STEP (I ,c ,d ,a ,b ,GET (10 ),0xffeff47d ,15 ) 275STEP (I ,b ,c ,d ,a ,GET (1 ),0x85845dd1 ,21 ) 276STEP (I ,a ,b ,c ,d ,GET (8 ),0x6fa87e4f ,6 ) 277STEP (I ,d ,a ,b ,c ,GET (15 ),0xfe2ce6e0 ,10 ) 278STEP (I ,c ,d ,a ,b ,GET (6 ),0xa3014314 ,15 ) 279STEP (I ,b ,c ,d ,a ,GET (13 ),0x4e0811a1 ,21 ) 280STEP (I ,a ,b ,c ,d ,GET (4 ),0xf7537e82 ,6 ) 281STEP (I ,d ,a ,b ,c ,GET (11 ),0xbd3af235 ,10 ) 282STEP (I ,c ,d ,a ,b ,GET (2 ),0x2ad7d2bb ,15 ) 283STEP (I ,b ,c ,d ,a ,GET (9 ),0xeb86d391 ,21 ) 284 285a += saved_a ; 286b += saved_b ; 287c += saved_c ; 288d += saved_d ; 289 290ptr += 64 ; 291 }while (size -= 64 ); 292 293m_a = a ; 294m_b = b ; 295m_c = c ; 296m_d = d ; 297 298return ptr ; 299} 300 301#undef F 302#undef G 303#undef H 304#undef H2 305#undef I 306#undef STEP 307#undef SET 308#undef GET 309 310/*static*/ MD5 ::Digest MD5 ::compute (const void * data ,SlangInt size ) 311{ 312MD5 md5 ; 313md5 .update (data ,size ); 314return md5 .finalize (); 315} 316 317// SHA1 318 319SHA1 ::SHA1 () 320{ 321init (); 322} 323 324void SHA1 ::init () 325{ 326m_index = 0 ; 327m_bits = 0 ; 328m_state [0 ]= 0x67452301 ; 329m_state [1 ]= 0xefcdab89 ; 330m_state [2 ]= 0x98badcfe ; 331m_state [3 ]= 0x10325476 ; 332m_state [4 ]= 0xc3d2e1f0 ; 333} 334 335void SHA1 ::update (const void * data ,SlangSizeT len ) 336{ 337if (!data || len <=0 ) 338 { 339return ; 340 } 341 342const uint8_t * ptr = reinterpret_cast < const uint8_t *> (data ); 343 344// Fill up buffer if not full. 345while (len > 0 && m_index != 0 ) 346 { 347addByte (* ptr ++ ); 348m_bits += 8 ; 349len -- ; 350 } 351 352// Process full blocks. 353while (len >=sizeof (m_buf )) 354 { 355processBlock (ptr ); 356ptr += sizeof (m_buf ); 357len -= sizeof (m_buf ); 358m_bits += sizeof (m_buf )* 8 ; 359 } 360 361// Process remaining bytes. 362while (len > 0 ) 363 { 364addByte (* ptr ++ ); 365m_bits += 8 ; 366len -- ; 367 } 368} 369 370SHA1 ::Digest SHA1 ::finalize () 371{ 372// Finalize with 0x80, some zero padding and the length in bits. 373addByte (0x80 ); 374while (m_index %64 != 56 ) 375 { 376addByte (0 ); 377 } 378for (int i = 7 ;i >=0 ;-- i ) 379 { 380addByte (uint8_t (m_bits >>i * 8 )); 381 } 382 383Digest digest ; 384uint8_t * data = reinterpret_cast < uint8_t *> (digest .data ); 385for (int i = 0 ;i < 5 ;i ++ ) 386 { 387for (int j = 3 ;j >=0 ;j -- ) 388 { 389data [i * 4 + j ]= (m_state [i ] >> ((3 - j )* 8 ))& 0xff ; 390 } 391 } 392 393return digest ; 394} 395 396void SHA1 ::addByte (uint8_t byte ) 397{ 398m_buf [m_index ++ ]= byte ; 399 400if (m_index >=sizeof (m_buf )) 401 { 402m_index = 0 ; 403processBlock (m_buf ); 404 } 405} 406 407void SHA1 ::processBlock (const uint8_t * ptr ) 408{ 409auto rol32 = [](uint32_t x ,uint32_t n ) {return (x <<n ) | (x >> (32 - n )); }; 410 411auto makeWord = [](const uint8_t * p ) 412 { 413return ((uint32_t )p [0 ] <<24 ) | ((uint32_t )p [1 ] <<16 ) | ((uint32_t )p [2 ] <<8 ) | 414 (uint32_t )p [3 ]; 415 }; 416 417const uint32_t c0 = 0x5a827999 ; 418const uint32_t c1 = 0x6ed9eba1 ; 419const uint32_t c2 = 0x8f1bbcdc ; 420const uint32_t c3 = 0xca62c1d6 ; 421 422uint32_t a = m_state [0 ]; 423uint32_t b = m_state [1 ]; 424uint32_t c = m_state [2 ]; 425uint32_t d = m_state [3 ]; 426uint32_t e = m_state [4 ]; 427 428uint32_t w [16 ]; 429 430for (size_t i = 0 ;i < 16 ;i ++ ) 431 { 432w [i ]= makeWord (ptr + i * 4 ); 433 } 434 435#define SHA1_LOAD (i ) \ 436 w[i & 15] = rol32(w[(i + 13) & 15] ^ w[(i + 8) & 15] ^ w[(i + 2) & 15] ^ w[i & 15], 1); 437#define SHA1_ROUND_0 (v ,u ,x ,y ,z ,i ) \ 438 z += ((u & (x ^ y)) ^ y) + w[i & 15] + c0 + rol32(v, 5); \ 439 u = rol32(u, 30); 440#define SHA1_ROUND_1 (v ,u ,x ,y ,z ,i ) \ 441 SHA1_LOAD(i) z += ((u & (x ^ y)) ^ y) + w[i & 15] + c0 + rol32(v, 5); \ 442 u = rol32(u, 30); 443#define SHA1_ROUND_2 (v ,u ,x ,y ,z ,i ) \ 444 SHA1_LOAD(i) z += (u ^ x ^ y) + w[i & 15] + c1 + rol32(v, 5); \ 445 u = rol32(u, 30); 446#define SHA1_ROUND_3 (v ,u ,x ,y ,z ,i ) \ 447 SHA1_LOAD(i) z += (((u | x) & y) | (u & x)) + w[i & 15] + c2 + rol32(v, 5); \ 448 u = rol32(u, 30); 449#define SHA1_ROUND_4 (v ,u ,x ,y ,z ,i ) \ 450 SHA1_LOAD(i) z += (u ^ x ^ y) + w[i & 15] + c3 + rol32(v, 5); \ 451 u = rol32(u, 30); 452 453SHA1_ROUND_0 (a ,b ,c ,d ,e ,0 ); 454SHA1_ROUND_0 (e ,a ,b ,c ,d ,1 ); 455SHA1_ROUND_0 (d ,e ,a ,b ,c ,2 ); 456SHA1_ROUND_0 (c ,d ,e ,a ,b ,3 ); 457SHA1_ROUND_0 (b ,c ,d ,e ,a ,4 ); 458SHA1_ROUND_0 (a ,b ,c ,d ,e ,5 ); 459SHA1_ROUND_0 (e ,a ,b ,c ,d ,6 ); 460SHA1_ROUND_0 (d ,e ,a ,b ,c ,7 ); 461SHA1_ROUND_0 (c ,d ,e ,a ,b ,8 ); 462SHA1_ROUND_0 (b ,c ,d ,e ,a ,9 ); 463SHA1_ROUND_0 (a ,b ,c ,d ,e ,10 ); 464SHA1_ROUND_0 (e ,a ,b ,c ,d ,11 ); 465SHA1_ROUND_0 (d ,e ,a ,b ,c ,12 ); 466SHA1_ROUND_0 (c ,d ,e ,a ,b ,13 ); 467SHA1_ROUND_0 (b ,c ,d ,e ,a ,14 ); 468SHA1_ROUND_0 (a ,b ,c ,d ,e ,15 ); 469SHA1_ROUND_1 (e ,a ,b ,c ,d ,16 ); 470SHA1_ROUND_1 (d ,e ,a ,b ,c ,17 ); 471SHA1_ROUND_1 (c ,d ,e ,a ,b ,18 ); 472SHA1_ROUND_1 (b ,c ,d ,e ,a ,19 ); 473SHA1_ROUND_2 (a ,b ,c ,d ,e ,20 ); 474SHA1_ROUND_2 (e ,a ,b ,c ,d ,21 ); 475SHA1_ROUND_2 (d ,e ,a ,b ,c ,22 ); 476SHA1_ROUND_2 (c ,d ,e ,a ,b ,23 ); 477SHA1_ROUND_2 (b ,c ,d ,e ,a ,24 ); 478SHA1_ROUND_2 (a ,b ,c ,d ,e ,25 ); 479SHA1_ROUND_2 (e ,a ,b ,c ,d ,26 ); 480SHA1_ROUND_2 (d ,e ,a ,b ,c ,27 ); 481SHA1_ROUND_2 (c ,d ,e ,a ,b ,28 ); 482SHA1_ROUND_2 (b ,c ,d ,e ,a ,29 ); 483SHA1_ROUND_2 (a ,b ,c ,d ,e ,30 ); 484SHA1_ROUND_2 (e ,a ,b ,c ,d ,31 ); 485SHA1_ROUND_2 (d ,e ,a ,b ,c ,32 ); 486SHA1_ROUND_2 (c ,d ,e ,a ,b ,33 ); 487SHA1_ROUND_2 (b ,c ,d ,e ,a ,34 ); 488SHA1_ROUND_2 (a ,b ,c ,d ,e ,35 ); 489SHA1_ROUND_2 (e ,a ,b ,c ,d ,36 ); 490SHA1_ROUND_2 (d ,e ,a ,b ,c ,37 ); 491SHA1_ROUND_2 (c ,d ,e ,a ,b ,38 ); 492SHA1_ROUND_2 (b ,c ,d ,e ,a ,39 ); 493SHA1_ROUND_3 (a ,b ,c ,d ,e ,40 ); 494SHA1_ROUND_3 (e ,a ,b ,c ,d ,41 ); 495SHA1_ROUND_3 (d ,e ,a ,b ,c ,42 ); 496SHA1_ROUND_3 (c ,d ,e ,a ,b ,43 ); 497SHA1_ROUND_3 (b ,c ,d ,e ,a ,44 ); 498SHA1_ROUND_3 (a ,b ,c ,d ,e ,45 ); 499SHA1_ROUND_3 (e ,a ,b ,c ,d ,46 ); 500SHA1_ROUND_3 (d ,e ,a ,b ,c ,47 ); 501SHA1_ROUND_3 (c ,d ,e ,a ,b ,48 ); 502SHA1_ROUND_3 (b ,c ,d ,e ,a ,49 ); 503SHA1_ROUND_3 (a ,b ,c ,d ,e ,50 ); 504SHA1_ROUND_3 (e ,a ,b ,c ,d ,51 ); 505SHA1_ROUND_3 (d ,e ,a ,b ,c ,52 ); 506SHA1_ROUND_3 (c ,d ,e ,a ,b ,53 ); 507SHA1_ROUND_3 (b ,c ,d ,e ,a ,54 ); 508SHA1_ROUND_3 (a ,b ,c ,d ,e ,55 ); 509SHA1_ROUND_3 (e ,a ,b ,c ,d ,56 ); 510SHA1_ROUND_3 (d ,e ,a ,b ,c ,57 ); 511SHA1_ROUND_3 (c ,d ,e ,a ,b ,58 ); 512SHA1_ROUND_3 (b ,c ,d ,e ,a ,59 ); 513SHA1_ROUND_4 (a ,b ,c ,d ,e ,60 ); 514SHA1_ROUND_4 (e ,a ,b ,c ,d ,61 ); 515SHA1_ROUND_4 (d ,e ,a ,b ,c ,62 ); 516SHA1_ROUND_4 (c ,d ,e ,a ,b ,63 ); 517SHA1_ROUND_4 (b ,c ,d ,e ,a ,64 ); 518SHA1_ROUND_4 (a ,b ,c ,d ,e ,65 ); 519SHA1_ROUND_4 (e ,a ,b ,c ,d ,66 ); 520SHA1_ROUND_4 (d ,e ,a ,b ,c ,67 ); 521SHA1_ROUND_4 (c ,d ,e ,a ,b ,68 ); 522SHA1_ROUND_4 (b ,c ,d ,e ,a ,69 ); 523SHA1_ROUND_4 (a ,b ,c ,d ,e ,70 ); 524SHA1_ROUND_4 (e ,a ,b ,c ,d ,71 ); 525SHA1_ROUND_4 (d ,e ,a ,b ,c ,72 ); 526SHA1_ROUND_4 (c ,d ,e ,a ,b ,73 ); 527SHA1_ROUND_4 (b ,c ,d ,e ,a ,74 ); 528SHA1_ROUND_4 (a ,b ,c ,d ,e ,75 ); 529SHA1_ROUND_4 (e ,a ,b ,c ,d ,76 ); 530SHA1_ROUND_4 (d ,e ,a ,b ,c ,77 ); 531SHA1_ROUND_4 (c ,d ,e ,a ,b ,78 ); 532SHA1_ROUND_4 (b ,c ,d ,e ,a ,79 ); 533 534#undef SHA1_LOAD 535#undef SHA1_ROUND_0 536#undef SHA1_ROUND_1 537#undef SHA1_ROUND_2 538#undef SHA1_ROUND_3 539#undef SHA1_ROUND_4 540 541m_state [0 ]+= a ; 542m_state [1 ]+= b ; 543m_state [2 ]+= c ; 544m_state [3 ]+= d ; 545m_state [4 ]+= e ; 546} 547 548/* static */ SHA1 ::Digest SHA1 ::compute (const void * data ,SlangInt size ) 549{ 550SHA1 sha1 ; 551sha1 .update (data ,size ); 552return sha1 .finalize (); 553} 554 555}// namespace Slang 556 557 558/* 559* This is an OpenSSL-compatible implementation of the RSA Data Security, Inc. 560* MD5 Message-Digest Algorithm (RFC 1321). 561* 562* Homepage: 563* http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5 564* 565* Author: 566* Alexander Peslyak, better known as Solar Designer <solar at openwall.com> 567* 568* This software was written by Alexander Peslyak in 2001. No copyright is 569* claimed, and the software is hereby placed in the public domain. 570* In case this attempt to disclaim copyright and place the software in the 571* public domain is deemed null and void, then the software is 572* Copyright (c) 2001 Alexander Peslyak and it is hereby released to the 573* general public under the following terms: 574* 575* Redistribution and use in source and binary forms, with or without 576* modification, are permitted. 577* 578* There's ABSOLUTELY NO WARRANTY, express or implied. 579* 580* (This is a heavily cut-down "BSD license".) 581* 582* This differs from Colin Plumb's older public domain implementation in that 583* no exactly 32-bit integer data type is required (any 32-bit or wider 584* unsigned integer data type will do), there's no compile-time endianness 585* configuration, and the function prototypes match OpenSSL's. No code from 586* Colin Plumb's implementation has been reused; this comment merely compares 587* the properties of the two independent implementations. 588* 589* The primary goals of this implementation are portability and ease of use. 590* It is meant to be fast, but not as fast as possible. Some known 591* optimizations are not included to reduce source code size and avoid 592* compile-time configuration. 593*/ 594 595/* 596* This is free and unencumbered software released into the public domain. 597* 598* Anyone is free to copy, modify, publish, use, compile, sell, or 599* distribute this software, either in source code form or as a compiled 600* binary, for any purpose, commercial or non-commercial, and by any 601* means. 602* 603* In jurisdictions that recognize copyright laws, the author or authors 604* of this software dedicate any and all copyright interest in the 605* software to the public domain. We make this dedication for the benefit 606* of the public at large and to the detriment of our heirs and 607* successors. We intend this dedication to be an overt act of 608* relinquishment in perpetuity of all present and future rights to this 609* software under copyright law. 610* 611* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 612* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 613* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 614* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 615* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 616* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 617* OTHER DEALINGS IN THE SOFTWARE. 618* 619* For more information, please refer to <http://unlicense.org> 620*/