Changeset 914 for trunk/CrypPlugins/Trivium
 Timestamp:
 Nov 29, 2009, 1:50:40 PM (12 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/CrypPlugins/Trivium/Trivium.cs
r860 r914 43 43 public List<uint> b = new List<uint>(new uint[84]); 44 44 public List<uint> c = new List<uint>(new uint[111]); 45 public uint t1, t2, t3;45 //public uint t1, t2, t3; 46 46 public int masterSlaveRounds = 0; 47 47 #endregion … … 377 377 int[] IV = new int[IV_string.Length * 4]; 378 378 int[] key = new int[key_string.Length * 4]; 379 379 380 380 IV = hextobin(IV_string.ToCharArray()); 381 381 key = hextobin(key_string.ToCharArray()); … … 425 425 keystream = keystreamTrivium(settings.KeystreamLength); 426 426 } 427 427 428 428 DateTime stopTime = DateTime.Now; 429 429 TimeSpan duration = stopTime  startTime; … … 463 463 public void initTrivium(int[] IV, int[] key) 464 464 { 465 int i; //,j; 466 465 int i; 467 466 if (settings.UseByteSwapping) 468 467 { … … 476 475 key[(l * 8) + k] = buffer[k]; 477 476 } 478 479 477 // ByteSwapping IV 480 478 for (int l = 0; l < 10; l++) … … 486 484 } 487 485 } 488 489 for (i = 0; i < 80; i++) 490 { 491 a[i] = (uint)key[i]; // hier key rein als binär 486 for (i = 0; i < 80; i++) 487 { 488 a[i] = (uint)key[i]; // hier key rein als binär 492 489 b[i] = (uint)IV[i]; // hier IV rein als binär 493 490 c[i] = 0; 494 491 } 495 while (i < 84){ 496 a[i] = 0; 497 b[i] = 0; 498 c[i] = 0; 499 i++; 500 } 501 while (i < 93){ 502 a[i] = 0; 503 c[i] = 0; 504 i++; 505 } 506 while (i < 108){ 507 c[i] = 0; 508 i++; 509 } 510 while (i < 111){ 511 c[i] = 1; 512 i++; 513 } 514 515 // belegung fertig, jetzt takten ohne output 516 // anzahl der takte laut settings oder lut master/slave 492 while (i < 84) 493 { 494 a[i] = 0; 495 b[i] = 0; 496 c[i] = 0; 497 i++; 498 } 499 while (i < 93) 500 { 501 a[i] = 0; 502 c[i] = 0; 503 i++; 504 } 505 while (i < 108) 506 { 507 c[i] = 0; 508 i++; 509 } 510 while (i < 111) 511 { 512 c[i] = 1; 513 i++; 514 } 517 515 int myRounds; 518 519 516 if (masterSlaveRounds != 0) 520 517 myRounds = masterSlaveRounds; 521 518 else 522 519 myRounds = settings.InitRounds; 523 524 520 for (i = 0; i < myRounds; i++) // default 1152 = 4 * 288 525 521 { 526 t1 = a[65] ^ (a[90] & a[91]) ^ a[92] ^ b[77]; 527 t2 = b[68] ^ (b[81] & b[82]) ^ b[83] ^ c[86]; 528 t3 = c[65] ^ (c[108] & c[109]) ^ c[110] ^ a[68]; 529 /*for (j = 92; j > 0; j) 530 a[j] = a[j  1]; 531 for (j = 83; j > 0; j) 532 b[j] = b[j  1]; 533 for (j = 110; j > 0; j) 534 c[j] = c[j  1]; 535 a[0] = t3; 536 b[0] = t1; 537 c[0] = t2; */ 538 a.Insert(0, t3); 539 b.Insert(0, t1); 540 c.Insert(0, t2); 541 a.RemoveAt(a.Count  1); 542 b.RemoveAt(b.Count  1); 543 c.RemoveAt(c.Count  1); 522 a.Insert(0, c[65] ^ (c[108] & c[109]) ^ c[110] ^ a[68]); 523 b.Insert(0, a[66] ^ (a[91] & a[92]) ^ a[93] ^ b[77]); 524 c.Insert(0, b[69] ^ (b[82] & b[83]) ^ b[84] ^ c[86]); 525 a.RemoveAt(93); 526 b.RemoveAt(84); 527 c.RemoveAt(111); 544 528 } 545 529 } … … 547 531 public string keystreamTrivium(int nBits) 548 532 { 549 int i; //, j; 550 uint z; 551 552 string keystreamZ = null; 553 List<int> keyOutput = new List<int>(); 554 555 for (i = 0; i < nBits; i++) 556 { 557 /*t1 = a[65] ^ a[92]; 558 t2 = b[68] ^ b[83]; 559 t3 = c[65] ^ c[110]; 560 z = t1 ^ t2 ^ t3; */ 561 z = a[65] ^ a[92] ^ b[68] ^ b[83] ^ c[65] ^ c[110]; 562 563 if (!settings.UseByteSwapping) 564 keystreamZ += z; 565 else 566 keyOutput.Add((int)z); 567 568 t1 = t1 ^ (a[90] & a[91]) ^ b[77]; 569 t2 = t2 ^ (b[81] & b[82]) ^ c[86]; 570 t3 = t3 ^ (c[108] & c[109]) ^ a[68]; 571 /*for (j = 92; j > 0; j) 572 a[j] = a[j  1]; 573 for (j = 83; j > 0; j) 574 b[j] = b[j  1]; 575 for (j = 110; j > 0; j) 576 c[j] = c[j  1]; 577 a[0] = t3; 578 b[0] = t1; 579 c[0] = t2;*/ 580 a.Insert(0, t3); 581 b.Insert(0, t1); 582 c.Insert(0, t2); 583 a.RemoveAt(a.Count  1); 584 b.RemoveAt(b.Count  1); 585 c.RemoveAt(c.Count  1); 586 } 587 533 StringBuilder builder = new StringBuilder(); 534 for (int i = 0; i < nBits; i++) 535 { 536 builder.Append((int)(a[65] ^ a[92] ^ b[68] ^ b[83] ^ c[65] ^ c[110])); 537 a.Insert(0, c[65] ^ (c[108] & c[109]) ^ c[110] ^ a[68] ^ (c[108] & c[109]) ^ a[68]); 538 b.Insert(0, a[66] ^ (a[91] & a[92]) ^ a[93] ^ b[77] ^ (a[91] & a[92]) ^ b[77]); 539 c.Insert(0, b[69] ^ (b[82] & b[83]) ^ b[84] ^ c[86] ^ (b[82] & b[83]) ^ c[86]); 540 a.RemoveAt(93); 541 b.RemoveAt(84); 542 c.RemoveAt(111); 543 } 588 544 if (settings.UseByteSwapping) 589 545 { … … 592 548 // LittleEndian für den Keystream 593 549 for (int k = 0; k < nBits; k++) 594 temp[k] = keyOutput[k];550 temp[k] = builder[k]; 595 551 for (int l = 0; l < nBits / 32; l++) 596 552 { 597 553 for (int k = 0; k < 8; k++) 598 554 { 599 keyOutput[(l * 32) + k] = (char)temp[(l * 32) + 24 + k];600 keyOutput[(l * 32) + 8 + k] = (char)temp[(l * 32) + 16 + k];601 keyOutput[(l * 32) + 16 + k] = (char)temp[(l * 32) + 8 + k];602 keyOutput[(l * 32) + 24 + k] = (char)temp[(l * 32) + k];555 builder[(l * 32) + k] = (char)temp[(l * 32) + 24 + k]; 556 builder[(l * 32) + 8 + k] = (char)temp[(l * 32) + 16 + k]; 557 builder[(l * 32) + 16 + k] = (char)temp[(l * 32) + 8 + k]; 558 builder[(l * 32) + 24 + k] = (char)temp[(l * 32) + k]; 603 559 } 604 560 } 605 GuiLogMessage(keyOutput.Count.ToString(), NotificationLevel.Info); 606 foreach (int k in keyOutput) 607 { 608 keystreamZ += k.ToString(); 609 } 610 } 611 return keystreamZ; 561 } 562 return builder.ToString(); 612 563 } 613 564
Note: See TracChangeset
for help on using the changeset viewer.