⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cast5.java

📁 linux下建立JAVA虚拟机的源码KAFFE
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* Cast5.java --    Copyright (C) 2003, 2006 Free Software Foundation, Inc.This file is a part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2 of the License, or (atyour option) any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; if not, write to the Free SoftwareFoundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301USALinking this library statically or dynamically with other modules ismaking a combined work based on this library.  Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule.  An independent module is a module which is not derived fromor based on this library.  If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so.  If you do not wish to do so, delete thisexception statement from your version.  */package gnu.javax.crypto.cipher;import gnu.java.security.Registry;import gnu.java.security.util.Util;import java.security.InvalidKeyException;import java.util.ArrayList;import java.util.Collections;import java.util.Iterator;/** * <p>An implmenetation of the <code>CAST5</code> (a.k.a. CAST-128) algorithm, * as per <i>RFC-2144</i>, dated May 1997.</p> * * <p>In this RFC, <i>Carlisle Adams</i> (the CA in CAST, ST stands for * <i>Stafford Tavares</i>) describes CAST5 as:</p> * * <blockquote> *    "...a DES-like Substitution-Permutation Network (SPN) cryptosystem which *    appears to have good resistance to differential cryptanalysis, linear *    cryptanalysis, and related-key cryptanalysis. This cipher also possesses *    a number of other desirable cryptographic properties, including avalanche, *    Strict Avalanche Criterion (SAC), Bit Independence Criterion (BIC), no *    complementation property, and an absence of weak and semi-weak keys." * </blockquote> * * <p><code>CAST5</code> is a symmetric block cipher with a block-size of 8 * bytes and a variable key-size of up to 128 bits. Its authors, and their * employer (Entrust Technologies, a Nortel majority-owned company), made it * available worldwide on a royalty-free basis for commercial and non-commercial * uses.</p> * * <p>The <code>CAST5</code> encryption algorithm has been designed to allow a * key size that can vary from <code>40</code> bits to <code>128</code> bits, * in 8-bit increments (that is, the allowable key sizes are <code>40, 48, 56, * 64, ..., 112, 120,</code> and <code>128</code> bits. For variable keysize * operation, the specification is as follows:</p> * * <ol> *   <li>For key sizes up to and including <code>80</code> bits (i.e., *    <code>40, 48, 56, 64, 72,</code> and <code>80</code> bits), the algorithm *    is exactly as specified but uses <code>12</code> rounds instead of *    <code>16</code>;</li> *   <li>For key sizes greater than <code>80</code> bits, the algorithm uses *    the full <code>16</code> rounds;</li> *   <li>For key sizes less than <code>128</code> bits, the key is padded with *    zero bytes (in the rightmost, or least significant, positions) out to *    <code>128</code> bits (since the <code>CAST5</code> key schedule assumes *    an input key of <code>128</code> bits).</li> * </ol> * * <p>References:</p> * * <ol> *    <li><a href="http://www.ietf.org/rfc/rfc2144.txt">The CAST-128 Encryption *    Algorithm</a>.<br> *    <a href="mailto:cadams@entrust.com">Carlisle Adams</a>.</li> * </ol> */public class Cast5 extends BaseCipher{  // Constants and variables  // -------------------------------------------------------------------------  private static final int DEFAULT_BLOCK_SIZE = 8; // in bytes  private static final int DEFAULT_KEY_SIZE = 5; // in bytes  /**   * KAT vector (from rfc-2144):   * 40-bit  key         = 01 23 45 67 12   *                     = 01 23 45 67 12 00 00 00 00 00 00 00 00 00 00 00   *         plaintext   = 01 23 45 67 89 AB CD EF   *         ciphertext  = 7A C8 16 D1 6E 9B 30 2E   */  private static final byte[] KAT_KEY = Util.toBytesFromString("0123456712");  private static final byte[] KAT_PT = Util.toBytesFromString("0123456789ABCDEF");  private static final byte[] KAT_CT = Util.toBytesFromString("7AC816D16E9B302E");  /** caches the result of the correctness test, once executed. */  private static Boolean valid;  // CAST5 S-boxes  private static final int[] S1 = { 0x30FB40D4, 0x9FA0FF0B, 0x6BECCD2F,                                   0x3F258C7A, 0x1E213F2F, 0x9C004DD3,                                   0x6003E540, 0xCF9FC949, 0xBFD4AF27,                                   0x88BBBDB5, 0xE2034090, 0x98D09675,                                   0x6E63A0E0, 0x15C361D2, 0xC2E7661D,                                   0x22D4FF8E, 0x28683B6F, 0xC07FD059,                                   0xFF2379C8, 0x775F50E2, 0x43C340D3,                                   0xDF2F8656, 0x887CA41A, 0xA2D2BD2D,                                   0xA1C9E0D6, 0x346C4819, 0x61B76D87,                                   0x22540F2F, 0x2ABE32E1, 0xAA54166B,                                   0x22568E3A, 0xA2D341D0, 0x66DB40C8,                                   0xA784392F, 0x004DFF2F, 0x2DB9D2DE,                                   0x97943FAC, 0x4A97C1D8, 0x527644B7,                                   0xB5F437A7, 0xB82CBAEF, 0xD751D159,                                   0x6FF7F0ED, 0x5A097A1F, 0x827B68D0,                                   0x90ECF52E, 0x22B0C054, 0xBC8E5935,                                   0x4B6D2F7F, 0x50BB64A2, 0xD2664910,                                   0xBEE5812D, 0xB7332290, 0xE93B159F,                                   0xB48EE411, 0x4BFF345D, 0xFD45C240,                                   0xAD31973F, 0xC4F6D02E, 0x55FC8165,                                   0xD5B1CAAD, 0xA1AC2DAE, 0xA2D4B76D,                                   0xC19B0C50, 0x882240F2, 0x0C6E4F38,                                   0xA4E4BFD7, 0x4F5BA272, 0x564C1D2F,                                   0xC59C5319, 0xB949E354, 0xB04669FE,                                   0xB1B6AB8A, 0xC71358DD, 0x6385C545,                                   0x110F935D, 0x57538AD5, 0x6A390493,                                   0xE63D37E0, 0x2A54F6B3, 0x3A787D5F,                                   0x6276A0B5, 0x19A6FCDF, 0x7A42206A,                                   0x29F9D4D5, 0xF61B1891, 0xBB72275E,                                   0xAA508167, 0x38901091, 0xC6B505EB,                                   0x84C7CB8C, 0x2AD75A0F, 0x874A1427,                                   0xA2D1936B, 0x2AD286AF, 0xAA56D291,                                   0xD7894360, 0x425C750D, 0x93B39E26,                                   0x187184C9, 0x6C00B32D, 0x73E2BB14,                                   0xA0BEBC3C, 0x54623779, 0x64459EAB,                                   0x3F328B82, 0x7718CF82, 0x59A2CEA6,                                   0x04EE002E, 0x89FE78E6, 0x3FAB0950,                                   0x325FF6C2, 0x81383F05, 0x6963C5C8,                                   0x76CB5AD6, 0xD49974C9, 0xCA180DCF,                                   0x380782D5, 0xC7FA5CF6, 0x8AC31511,                                   0x35E79E13, 0x47DA91D0, 0xF40F9086,                                   0xA7E2419E, 0x31366241, 0x051EF495,                                   0xAA573B04, 0x4A805D8D, 0x548300D0,                                   0x00322A3C, 0xBF64CDDF, 0xBA57A68E,                                   0x75C6372B, 0x50AFD341, 0xA7C13275,                                   0x915A0BF5, 0x6B54BFAB, 0x2B0B1426,                                   0xAB4CC9D7, 0x449CCD82, 0xF7FBF265,                                   0xAB85C5F3, 0x1B55DB94, 0xAAD4E324,                                   0xCFA4BD3F, 0x2DEAA3E2, 0x9E204D02,                                   0xC8BD25AC, 0xEADF55B3, 0xD5BD9E98,                                   0xE31231B2, 0x2AD5AD6C, 0x954329DE,                                   0xADBE4528, 0xD8710F69, 0xAA51C90F,                                   0xAA786BF6, 0x22513F1E, 0xAA51A79B,                                   0x2AD344CC, 0x7B5A41F0, 0xD37CFBAD,                                   0x1B069505, 0x41ECE491, 0xB4C332E6,                                   0x032268D4, 0xC9600ACC, 0xCE387E6D,                                   0xBF6BB16C, 0x6A70FB78, 0x0D03D9C9,                                   0xD4DF39DE, 0xE01063DA, 0x4736F464,                                   0x5AD328D8, 0xB347CC96, 0x75BB0FC3,                                   0x98511BFB, 0x4FFBCC35, 0xB58BCF6A,                                   0xE11F0ABC, 0xBFC5FE4A, 0xA70AEC10,                                   0xAC39570A, 0x3F04442F, 0x6188B153,                                   0xE0397A2E, 0x5727CB79, 0x9CEB418F,                                   0x1CACD68D, 0x2AD37C96, 0x0175CB9D,                                   0xC69DFF09, 0xC75B65F0, 0xD9DB40D8,                                   0xEC0E7779, 0x4744EAD4, 0xB11C3274,                                   0xDD24CB9E, 0x7E1C54BD, 0xF01144F9,                                   0xD2240EB1, 0x9675B3FD, 0xA3AC3755,                                   0xD47C27AF, 0x51C85F4D, 0x56907596,                                   0xA5BB15E6, 0x580304F0, 0xCA042CF1,                                   0x011A37EA, 0x8DBFAADB, 0x35BA3E4A,                                   0x3526FFA0, 0xC37B4D09, 0xBC306ED9,                                   0x98A52666, 0x5648F725, 0xFF5E569D,                                   0x0CED63D0, 0x7C63B2CF, 0x700B45E1,                                   0xD5EA50F1, 0x85A92872, 0xAF1FBDA7,                                   0xD4234870, 0xA7870BF3, 0x2D3B4D79,                                   0x42E04198, 0x0CD0EDE7, 0x26470DB8,                                   0xF881814C, 0x474D6AD7, 0x7C0C5E5C,                                   0xD1231959, 0x381B7298, 0xF5D2F4DB,                                   0xAB838653, 0x6E2F1E23, 0x83719C9E,                                   0xBD91E046, 0x9A56456E, 0xDC39200C,                                   0x20C8C571, 0x962BDA1C, 0xE1E696FF,                                   0xB141AB08, 0x7CCA89B9, 0x1A69E783,                                   0x02CC4843, 0xA2F7C579, 0x429EF47D,                                   0x427B169C, 0x5AC9F049, 0xDD8F0F00,                                   0x5C8165BF };  private static final int[] S2 = { 0x1F201094, 0xEF0BA75B, 0x69E3CF7E,                                   0x393F4380, 0xFE61CF7A, 0xEEC5207A,                                   0x55889C94, 0x72FC0651, 0xADA7EF79,                                   0x4E1D7235, 0xD55A63CE, 0xDE0436BA,                                   0x99C430EF, 0x5F0C0794, 0x18DCDB7D,                                   0xA1D6EFF3, 0xA0B52F7B, 0x59E83605,                                   0xEE15B094, 0xE9FFD909, 0xDC440086,                                   0xEF944459, 0xBA83CCB3, 0xE0C3CDFB,                                   0xD1DA4181, 0x3B092AB1, 0xF997F1C1,                                   0xA5E6CF7B, 0x01420DDB, 0xE4E7EF5B,                                   0x25A1FF41, 0xE180F806, 0x1FC41080,                                   0x179BEE7A, 0xD37AC6A9, 0xFE5830A4,                                   0x98DE8B7F, 0x77E83F4E, 0x79929269,                                   0x24FA9F7B, 0xE113C85B, 0xACC40083,                                   0xD7503525, 0xF7EA615F, 0x62143154,                                   0x0D554B63, 0x5D681121, 0xC866C359,                                   0x3D63CF73, 0xCEE234C0, 0xD4D87E87,                                   0x5C672B21, 0x071F6181, 0x39F7627F,                                   0x361E3084, 0xE4EB573B, 0x602F64A4,                                   0xD63ACD9C, 0x1BBC4635, 0x9E81032D,                                   0x2701F50C, 0x99847AB4, 0xA0E3DF79,                                   0xBA6CF38C, 0x10843094, 0x2537A95E,                                   0xF46F6FFE, 0xA1FF3B1F, 0x208CFB6A,                                   0x8F458C74, 0xD9E0A227, 0x4EC73A34,                                   0xFC884F69, 0x3E4DE8DF, 0xEF0E0088,                                   0x3559648D, 0x8A45388C, 0x1D804366,                                   0x721D9BFD, 0xA58684BB, 0xE8256333,                                   0x844E8212, 0x128D8098, 0xFED33FB4,                                   0xCE280AE1, 0x27E19BA5, 0xD5A6C252,                                   0xE49754BD, 0xC5D655DD, 0xEB667064,                                   0x77840B4D, 0xA1B6A801, 0x84DB26A9,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -