1 /*
2  * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.  Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle in the LICENSE file that accompanied this code.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  */
25 
26 package com.sun.crypto.provider;
27 
28 import java.io.*;
29 import java.security.AlgorithmParametersSpi;
30 import java.security.spec.AlgorithmParameterSpec;
31 import java.security.spec.InvalidParameterSpecException;
32 
33 /**
34  * This class implements the parameter (IV) used with the DES algorithm in
35  * feedback-mode. IV is defined in the standards as follows:
36  *
37  * <pre>
38  * IV ::= OCTET STRING  -- 8 octets
39  * </pre>
40  *
41  * @author Jan Luehe
42  *
43  */
44 
45 public final class DESParameters extends AlgorithmParametersSpi {
46 
47     private BlockCipherParamsCore core;
48 
DESParameters()49     public DESParameters() {
50         core = new BlockCipherParamsCore(DESConstants.DES_BLOCK_SIZE);
51     }
52 
engineInit(AlgorithmParameterSpec paramSpec)53     protected void engineInit(AlgorithmParameterSpec paramSpec)
54         throws InvalidParameterSpecException {
55         core.init(paramSpec);
56     }
57 
engineInit(byte[] encoded)58     protected void engineInit(byte[] encoded)
59         throws IOException {
60         core.init(encoded);
61     }
62 
engineInit(byte[] encoded, String decodingMethod)63     protected void engineInit(byte[] encoded, String decodingMethod)
64         throws IOException {
65         core.init(encoded, decodingMethod);
66     }
67 
68     protected <T extends AlgorithmParameterSpec>
engineGetParameterSpec(Class<T> paramSpec)69         T engineGetParameterSpec(Class<T> paramSpec)
70         throws InvalidParameterSpecException {
71         if (AlgorithmParameterSpec.class.isAssignableFrom(paramSpec)) {
72             return core.getParameterSpec(paramSpec);
73         } else {
74             throw new InvalidParameterSpecException
75                 ("Inappropriate parameter Specification");
76         }
77     }
78 
engineGetEncoded()79     protected byte[] engineGetEncoded() throws IOException {
80         return core.getEncoded();
81     }
82 
engineGetEncoded(String encodingMethod)83     protected byte[] engineGetEncoded(String encodingMethod)
84         throws IOException {
85         return core.getEncoded();
86     }
87 
engineToString()88     protected String engineToString() {
89         return core.toString();
90     }
91 }
92