14f389fd200fee9e055d3f28b20bee3132329a056Alex Klyubin/*
24f389fd200fee9e055d3f28b20bee3132329a056Alex Klyubin * Copyright (C) 2015 The Android Open Source Project
34f389fd200fee9e055d3f28b20bee3132329a056Alex Klyubin *
44f389fd200fee9e055d3f28b20bee3132329a056Alex Klyubin * Licensed under the Apache License, Version 2.0 (the "License");
54f389fd200fee9e055d3f28b20bee3132329a056Alex Klyubin * you may not use this file except in compliance with the License.
64f389fd200fee9e055d3f28b20bee3132329a056Alex Klyubin * You may obtain a copy of the License at
74f389fd200fee9e055d3f28b20bee3132329a056Alex Klyubin *
84f389fd200fee9e055d3f28b20bee3132329a056Alex Klyubin *      http://www.apache.org/licenses/LICENSE-2.0
94f389fd200fee9e055d3f28b20bee3132329a056Alex Klyubin *
104f389fd200fee9e055d3f28b20bee3132329a056Alex Klyubin * Unless required by applicable law or agreed to in writing, software
114f389fd200fee9e055d3f28b20bee3132329a056Alex Klyubin * distributed under the License is distributed on an "AS IS" BASIS,
124f389fd200fee9e055d3f28b20bee3132329a056Alex Klyubin * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
134f389fd200fee9e055d3f28b20bee3132329a056Alex Klyubin * See the License for the specific language governing permissions and
144f389fd200fee9e055d3f28b20bee3132329a056Alex Klyubin * limitations under the License.
154f389fd200fee9e055d3f28b20bee3132329a056Alex Klyubin */
164f389fd200fee9e055d3f28b20bee3132329a056Alex Klyubin
174f389fd200fee9e055d3f28b20bee3132329a056Alex Klyubinpackage android.security.keystore;
184f389fd200fee9e055d3f28b20bee3132329a056Alex Klyubin
194f389fd200fee9e055d3f28b20bee3132329a056Alex Klyubinimport android.security.KeyStore;
204f389fd200fee9e055d3f28b20bee3132329a056Alex Klyubinimport android.security.KeyStoreException;
214f389fd200fee9e055d3f28b20bee3132329a056Alex Klyubin
224f389fd200fee9e055d3f28b20bee3132329a056Alex Klyubin/**
234f389fd200fee9e055d3f28b20bee3132329a056Alex Klyubin * Helper for streaming a crypto operation's input and output via {@link KeyStore} service's
244f389fd200fee9e055d3f28b20bee3132329a056Alex Klyubin * {@code update} and {@code finish} operations.
254f389fd200fee9e055d3f28b20bee3132329a056Alex Klyubin *
264f389fd200fee9e055d3f28b20bee3132329a056Alex Klyubin * <p>The helper abstracts away to issues that need to be solved in most code that uses KeyStore's
274f389fd200fee9e055d3f28b20bee3132329a056Alex Klyubin * update and finish operations. Firstly, KeyStore's update operation can consume only a limited
284f389fd200fee9e055d3f28b20bee3132329a056Alex Klyubin * amount of data in one go because the operations are marshalled via Binder. Secondly, the update
294f389fd200fee9e055d3f28b20bee3132329a056Alex Klyubin * operation may consume less data than provided, in which case the caller has to buffer the
304f389fd200fee9e055d3f28b20bee3132329a056Alex Klyubin * remainder for next time. The helper exposes {@link #update(byte[], int, int) update} and
31d23dc502b0a1952887d4453cba98aa2e3d2f5009Alex Klyubin * {@link #doFinal(byte[], int, int, byte[], byte[]) doFinal} operations which can be used to
32d23dc502b0a1952887d4453cba98aa2e3d2f5009Alex Klyubin * conveniently implement various JCA crypto primitives.
334f389fd200fee9e055d3f28b20bee3132329a056Alex Klyubin *
344f389fd200fee9e055d3f28b20bee3132329a056Alex Klyubin * @hide
354f389fd200fee9e055d3f28b20bee3132329a056Alex Klyubin */
364f389fd200fee9e055d3f28b20bee3132329a056Alex Klyubininterface KeyStoreCryptoOperationStreamer {
374f389fd200fee9e055d3f28b20bee3132329a056Alex Klyubin    byte[] update(byte[] input, int inputOffset, int inputLength) throws KeyStoreException;
38d23dc502b0a1952887d4453cba98aa2e3d2f5009Alex Klyubin    byte[] doFinal(byte[] input, int inputOffset, int inputLength, byte[] signature,
39d23dc502b0a1952887d4453cba98aa2e3d2f5009Alex Klyubin            byte[] additionalEntropy) throws KeyStoreException;
4000af27b7d9010eb41e45959dab7c4ff6de119897Alex Klyubin    long getConsumedInputSizeBytes();
4100af27b7d9010eb41e45959dab7c4ff6de119897Alex Klyubin    long getProducedOutputSizeBytes();
424f389fd200fee9e055d3f28b20bee3132329a056Alex Klyubin}
43