1/* 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * 4 * This code is free software; you can redistribute it and/or modify it 5 * under the terms of the GNU General Public License version 2 only, as 6 * published by the Free Software Foundation. Oracle designates this 7 * particular file as subject to the "Classpath" exception as provided 8 * by Oracle in the LICENSE file that accompanied this code. 9 * 10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 */ 24 25/* 26 * 27 * (C) Copyright IBM Corp. 1999 All Rights Reserved. 28 * Copyright 1997 The Open Group Research Institute. All rights reserved. 29 */ 30 31package sun.security.krb5.internal.crypto; 32 33import sun.security.krb5.Checksum; 34import sun.security.krb5.EncryptedData; 35import sun.security.krb5.KrbCryptoException; 36import sun.security.krb5.internal.*; 37 38public class DesCbcCrcEType extends DesCbcEType { 39 40 public DesCbcCrcEType() { 41 } 42 43 public int eType() { 44 return EncryptedData.ETYPE_DES_CBC_CRC; 45 } 46 47 public int minimumPadSize() { 48 return 4; 49 } 50 51 public int confounderSize() { 52 return 8; 53 } 54 55 public int checksumType() { 56 return Checksum.CKSUMTYPE_CRC32; 57 } 58 59 public int checksumSize() { 60 return 4; 61 } 62 63 /** 64 * Encrypts data using DES in CBC mode with CRC32. 65 * @param data the data to be encrypted. 66 * @param key the secret key to encrypt the data. It is also used as initialization vector during cipher block chaining. 67 * @return the buffer for cipher text. 68 * 69 * @written by Yanni Zhang, Dec 10, 1999 70 */ 71 public byte[] encrypt(byte[] data, byte[] key, int usage) 72 throws KrbCryptoException { 73 return encrypt(data, key, key, usage); 74 } 75 76 /** 77 * Decrypts data with provided key using DES in CBC mode with CRC32. 78 * @param cipher the cipher text to be decrypted. 79 * @param key the secret key to decrypt the data. 80 * 81 * @written by Yanni Zhang, Dec 10, 1999 82 */ 83 public byte[] decrypt(byte[] cipher, byte[] key, int usage) 84 throws KrbApErrException, KrbCryptoException{ 85 return decrypt(cipher, key, key, usage); 86 } 87 88 protected byte[] calculateChecksum(byte[] data, int size) { 89 return crc32.byte2crc32sum_bytes(data, size); 90 } 91 92} 93