001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /**
019: * @author Vera Y. Petrashkova
020: * @version $Revision$
021: */package javax.crypto;
022:
023: import java.security.Key;
024: import java.security.InvalidKeyException;
025: import java.security.InvalidAlgorithmParameterException;
026: import java.security.spec.AlgorithmParameterSpec;
027: import java.nio.ByteBuffer;
028:
029: /**
030: * @com.intel.drl.spec_ref
031: *
032: */
033:
034: public abstract class MacSpi {
035: /**
036: * @com.intel.drl.spec_ref
037: *
038: */
039: public MacSpi() {
040: }
041:
042: /**
043: * @com.intel.drl.spec_ref
044: *
045: */
046: protected abstract int engineGetMacLength();
047:
048: /**
049: * @com.intel.drl.spec_ref
050: *
051: */
052: protected abstract void engineInit(Key key,
053: AlgorithmParameterSpec params) throws InvalidKeyException,
054: InvalidAlgorithmParameterException;
055:
056: /**
057: * @com.intel.drl.spec_ref
058: *
059: */
060: protected abstract void engineUpdate(byte input);
061:
062: /**
063: * @com.intel.drl.spec_ref
064: *
065: */
066: protected abstract void engineUpdate(byte[] input, int offset,
067: int len);
068:
069: /**
070: * @com.intel.drl.spec_ref
071: *
072: */
073: protected void engineUpdate(ByteBuffer input) {
074: if (!input.hasRemaining()) {
075: return;
076: }
077: byte[] bInput;
078: if (input.hasArray()) {
079: bInput = input.array();
080: int offset = input.arrayOffset();
081: int position = input.position();
082: int limit = input.limit();
083: engineUpdate(bInput, offset + position, limit - position);
084: input.position(limit);
085: } else {
086: bInput = new byte[input.limit() - input.position()];
087: input.get(bInput);
088: engineUpdate(bInput, 0, bInput.length);
089: }
090: }
091:
092: /**
093: * @com.intel.drl.spec_ref
094: *
095: */
096: protected abstract byte[] engineDoFinal();
097:
098: /**
099: * @com.intel.drl.spec_ref
100: *
101: */
102: protected abstract void engineReset();
103:
104: /**
105: * @com.intel.drl.spec_ref
106: *
107: */
108: @Override
109: public Object clone() throws CloneNotSupportedException {
110: return super.clone();
111: }
112: }
|