📄 serpent_8cpp-source.html
字号:
00366 <span class="preprocessor"> r3 ^= r1; \</span>00367 <span class="preprocessor"> r4 ^= r0; \</span>00368 <span class="preprocessor"> }</span>00369 <span class="preprocessor"></span>00370 <span class="preprocessor">#define S7(i, r0, r1, r2, r3, r4) \</span>00371 <span class="preprocessor"> { \</span>00372 <span class="preprocessor"> r4 = r2; \</span>00373 <span class="preprocessor"> r2 &= r1; \</span>00374 <span class="preprocessor"> r2 ^= r3; \</span>00375 <span class="preprocessor"> r3 &= r1; \</span>00376 <span class="preprocessor"> r4 ^= r2; \</span>00377 <span class="preprocessor"> r2 ^= r1; \</span>00378 <span class="preprocessor"> r1 ^= r0; \</span>00379 <span class="preprocessor"> r0 |= r4; \</span>00380 <span class="preprocessor"> r0 ^= r2; \</span>00381 <span class="preprocessor"> r3 ^= r1; \</span>00382 <span class="preprocessor"> r2 ^= r3; \</span>00383 <span class="preprocessor"> r3 &= r0; \</span>00384 <span class="preprocessor"> r3 ^= r4; \</span>00385 <span class="preprocessor"> r4 ^= r2; \</span>00386 <span class="preprocessor"> r2 &= r0; \</span>00387 <span class="preprocessor"> r4 = ~r4; \</span>00388 <span class="preprocessor"> r2 ^= r4; \</span>00389 <span class="preprocessor"> r4 &= r0; \</span>00390 <span class="preprocessor"> r1 ^= r3; \</span>00391 <span class="preprocessor"> r4 ^= r1; \</span>00392 <span class="preprocessor"> }</span>00393 <span class="preprocessor"></span>00394 <span class="preprocessor">#define I7(i, r0, r1, r2, r3, r4) \</span>00395 <span class="preprocessor"> { \</span>00396 <span class="preprocessor"> r4 = r2; \</span>00397 <span class="preprocessor"> r2 ^= r0; \</span>00398 <span class="preprocessor"> r0 &= r3; \</span>00399 <span class="preprocessor"> r2 = ~r2; \</span>00400 <span class="preprocessor"> r4 |= r3; \</span>00401 <span class="preprocessor"> r3 ^= r1; \</span>00402 <span class="preprocessor"> r1 |= r0; \</span>00403 <span class="preprocessor"> r0 ^= r2; \</span>00404 <span class="preprocessor"> r2 &= r4; \</span>00405 <span class="preprocessor"> r1 ^= r2; \</span>00406 <span class="preprocessor"> r2 ^= r0; \</span>00407 <span class="preprocessor"> r0 |= r2; \</span>00408 <span class="preprocessor"> r3 &= r4; \</span>00409 <span class="preprocessor"> r0 ^= r3; \</span>00410 <span class="preprocessor"> r4 ^= r1; \</span>00411 <span class="preprocessor"> r3 ^= r4; \</span>00412 <span class="preprocessor"> r4 |= r0; \</span>00413 <span class="preprocessor"> r3 ^= r2; \</span>00414 <span class="preprocessor"> r4 ^= r2; \</span>00415 <span class="preprocessor"> }</span>00416 <span class="preprocessor"></span>00417 <span class="comment">// key xor</span>00418 <span class="preprocessor">#define KX(r, a, b, c, d, e) {\</span>00419 <span class="preprocessor"> a ^= k[4 * r + 0]; \</span>00420 <span class="preprocessor"> b ^= k[4 * r + 1]; \</span>00421 <span class="preprocessor"> c ^= k[4 * r + 2]; \</span>00422 <span class="preprocessor"> d ^= k[4 * r + 3];}</span>00423 <span class="preprocessor"></span>00424 <span class="keywordtype">void</span> Serpent::Base::UncheckedSetKey(CipherDir direction, <span class="keyword">const</span> byte *userKey, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> keylen)00425 {00426 AssertValidKeyLength(keylen);00427 00428 word32 *k = m_key;00429 GetUserKey(LITTLE_ENDIAN_ORDER, k, 8, userKey, keylen);00430 00431 word32 i,a,b,c,d,e;00432 00433 <span class="keywordflow">if</span> (keylen < 32)00434 k[keylen/4] |= word32(1) << ((keylen%4)*8);00435 00436 k += 8;00437 word32 t = k[-1];00438 <span class="keywordflow">for</span> (i = 0; i < 132; ++i)00439 k[i] = t = rotlFixed(k[i-8] ^ k[i-5] ^ k[i-3] ^ t ^ 0x9e3779b9 ^ i, 11);00440 k -= 20;00441 00442 <span class="preprocessor">#define LK(r, a, b, c, d, e) {\</span>00443 <span class="preprocessor"> a = k[(8-r)*4 + 0]; \</span>00444 <span class="preprocessor"> b = k[(8-r)*4 + 1]; \</span>00445 <span class="preprocessor"> c = k[(8-r)*4 + 2]; \</span>00446 <span class="preprocessor"> d = k[(8-r)*4 + 3];}</span>00447 <span class="preprocessor"></span>00448 <span class="preprocessor">#define SK(r, a, b, c, d, e) {\</span>00449 <span class="preprocessor"> k[(8-r)*4 + 4] = a; \</span>00450 <span class="preprocessor"> k[(8-r)*4 + 5] = b; \</span>00451 <span class="preprocessor"> k[(8-r)*4 + 6] = c; \</span>00452 <span class="preprocessor"> k[(8-r)*4 + 7] = d;} \</span>00453 <span class="preprocessor"></span>00454 <span class="preprocessor"></span> <span class="keywordflow">for</span> (i=0; i<4; i++)00455 {00456 afterS2(LK); afterS2(S3); afterS3(SK);00457 afterS1(LK); afterS1(S2); afterS2(SK);00458 afterS0(LK); afterS0(S1); afterS1(SK);00459 beforeS0(LK); beforeS0(S0); afterS0(SK);00460 k += 8*4;00461 afterS6(LK); afterS6(S7); afterS7(SK);00462 afterS5(LK); afterS5(S6); afterS6(SK);00463 afterS4(LK); afterS4(S5); afterS5(SK);00464 afterS3(LK); afterS3(S4); afterS4(SK);00465 }00466 afterS2(LK); afterS2(S3); afterS3(SK);00467 }00468 00469 <span class="keyword">typedef</span> BlockGetAndPut<word32, LittleEndian> Block;00470 00471 <span class="keywordtype">void</span> Serpent::Enc::ProcessAndXorBlock(<span class="keyword">const</span> byte *inBlock, <span class="keyword">const</span> byte *xorBlock, byte *outBlock)<span class="keyword"> const</span>00472 <span class="keyword"></span>{00473 word32 a, b, c, d, e;00474 00475 Block::Get(inBlock)(a)(b)(c)(d);00476 00477 <span class="keyword">const</span> word32 *k = m_key + 8;00478 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i=1;00479 00480 <span class="keywordflow">do</span>00481 {00482 beforeS0(KX); beforeS0(S0); afterS0(LT);00483 afterS0(KX); afterS0(S1); afterS1(LT);00484 afterS1(KX); afterS1(S2); afterS2(LT);00485 afterS2(KX); afterS2(S3); afterS3(LT);00486 afterS3(KX); afterS3(S4); afterS4(LT);00487 afterS4(KX); afterS4(S5); afterS5(LT);00488 afterS5(KX); afterS5(S6); afterS6(LT);00489 afterS6(KX); afterS6(S7);00490 00491 <span class="keywordflow">if</span> (i == 4)00492 <span class="keywordflow">break</span>;00493 00494 ++i;00495 c = b;00496 b = e;00497 e = d;00498 d = a;00499 a = e;00500 k += 32;00501 beforeS0(LT);00502 }00503 <span class="keywordflow">while</span> (<span class="keyword">true</span>);00504 00505 afterS7(KX);00506 00507 Block::Put(xorBlock, outBlock)(d)(e)(b)(a);00508 }00509 00510 <span class="keywordtype">void</span> Serpent::Dec::ProcessAndXorBlock(<span class="keyword">const</span> byte *inBlock, <span class="keyword">const</span> byte *xorBlock, byte *outBlock)<span class="keyword"> const</span>00511 <span class="keyword"></span>{00512 word32 a, b, c, d, e;00513 00514 Block::Get(inBlock)(a)(b)(c)(d);00515 00516 <span class="keyword">const</span> word32 *k = m_key + 104;00517 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i=4;00518 00519 beforeI7(KX);00520 <span class="keywordflow">goto</span> start;00521 00522 <span class="keywordflow">do</span>00523 {00524 c = b;00525 b = d;00526 d = e;00527 k -= 32;00528 beforeI7(ILT);00529 start:00530 beforeI7(I7); afterI7(KX); 00531 afterI7(ILT); afterI7(I6); afterI6(KX); 00532 afterI6(ILT); afterI6(I5); afterI5(KX); 00533 afterI5(ILT); afterI5(I4); afterI4(KX); 00534 afterI4(ILT); afterI4(I3); afterI3(KX); 00535 afterI3(ILT); afterI3(I2); afterI2(KX); 00536 afterI2(ILT); afterI2(I1); afterI1(KX); 00537 afterI1(ILT); afterI1(I0); afterI0(KX);00538 }00539 <span class="keywordflow">while</span> (--i != 0);00540 00541 Block::Put(xorBlock, outBlock)(a)(d)(b)(e);00542 }00543 00544 NAMESPACE_END</pre></div><hr size="1"><address style="align: right;"><small>Generated on Tue Jul 8 23:34:25 2003 for Crypto++ by<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border=0 > </a>1.3.2 </small></address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -