1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.security.keystore;
18 
19 import android.security.KeyStore;
20 import android.security.KeyStoreException;
21 
22 /**
23  * Helper for streaming a crypto operation's input and output via {@link KeyStore} service's
24  * {@code update} and {@code finish} operations.
25  *
26  * <p>The helper abstracts away to issues that need to be solved in most code that uses KeyStore's
27  * update and finish operations. Firstly, KeyStore's update operation can consume only a limited
28  * amount of data in one go because the operations are marshalled via Binder. Secondly, the update
29  * operation may consume less data than provided, in which case the caller has to buffer the
30  * remainder for next time. The helper exposes {@link #update(byte[], int, int) update} and
31  * {@link #doFinal(byte[], int, int, byte[], byte[]) doFinal} operations which can be used to
32  * conveniently implement various JCA crypto primitives.
33  *
34  * @hide
35  */
36 interface KeyStoreCryptoOperationStreamer {
update(byte[] input, int inputOffset, int inputLength)37     byte[] update(byte[] input, int inputOffset, int inputLength) throws KeyStoreException;
doFinal(byte[] input, int inputOffset, int inputLength, byte[] signature, byte[] additionalEntropy)38     byte[] doFinal(byte[] input, int inputOffset, int inputLength, byte[] signature,
39             byte[] additionalEntropy) throws KeyStoreException;
getConsumedInputSizeBytes()40     long getConsumedInputSizeBytes();
getProducedOutputSizeBytes()41     long getProducedOutputSizeBytes();
42 }
43