122d14131edf5101379fc3bb16268920df3913599Andrew Scull/* 222d14131edf5101379fc3bb16268920df3913599Andrew Scull * Copyright (C) 2017 The Android Open Source Project 322d14131edf5101379fc3bb16268920df3913599Andrew Scull * 422d14131edf5101379fc3bb16268920df3913599Andrew Scull * Licensed under the Apache License, Version 2.0 (the "License"); 522d14131edf5101379fc3bb16268920df3913599Andrew Scull * you may not use this file except in compliance with the License. 622d14131edf5101379fc3bb16268920df3913599Andrew Scull * You may obtain a copy of the License at 722d14131edf5101379fc3bb16268920df3913599Andrew Scull * 822d14131edf5101379fc3bb16268920df3913599Andrew Scull * http://www.apache.org/licenses/LICENSE-2.0 922d14131edf5101379fc3bb16268920df3913599Andrew Scull * 1022d14131edf5101379fc3bb16268920df3913599Andrew Scull * Unless required by applicable law or agreed to in writing, software 1122d14131edf5101379fc3bb16268920df3913599Andrew Scull * distributed under the License is distributed on an "AS IS" BASIS, 1222d14131edf5101379fc3bb16268920df3913599Andrew Scull * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1322d14131edf5101379fc3bb16268920df3913599Andrew Scull * See the License for the specific language governing permissions and 1422d14131edf5101379fc3bb16268920df3913599Andrew Scull * limitations under the License. 1522d14131edf5101379fc3bb16268920df3913599Andrew Scull */ 1622d14131edf5101379fc3bb16268920df3913599Andrew Scull 1722d14131edf5101379fc3bb16268920df3913599Andrew Scullpackage com.android.weaver; 1822d14131edf5101379fc3bb16268920df3913599Andrew Scull 1922d14131edf5101379fc3bb16268920df3913599Andrew Scullpublic interface Slots extends javacard.framework.Shareable { 2022d14131edf5101379fc3bb16268920df3913599Andrew Scull /** @return The number of slots available. */ 2122d14131edf5101379fc3bb16268920df3913599Andrew Scull short getNumSlots(); 2222d14131edf5101379fc3bb16268920df3913599Andrew Scull 2322d14131edf5101379fc3bb16268920df3913599Andrew Scull /** 2422d14131edf5101379fc3bb16268920df3913599Andrew Scull * Write the key and value to the identified slot. 2522d14131edf5101379fc3bb16268920df3913599Andrew Scull * 2622d14131edf5101379fc3bb16268920df3913599Andrew Scull * @param slotId ID of the slot to write to. 2722d14131edf5101379fc3bb16268920df3913599Andrew Scull * @param key Buffer containing the key. 2822d14131edf5101379fc3bb16268920df3913599Andrew Scull * @param keyOffset Offset of the key in the buffer. 2922d14131edf5101379fc3bb16268920df3913599Andrew Scull * @param value Buffer containing the value. 3022d14131edf5101379fc3bb16268920df3913599Andrew Scull * @param valueOffset Offset of the value in the buffer. 3122d14131edf5101379fc3bb16268920df3913599Andrew Scull */ 3222d14131edf5101379fc3bb16268920df3913599Andrew Scull void write(short slotId, byte[] key, short keyOffset, byte[] value, short valueOffset); 3322d14131edf5101379fc3bb16268920df3913599Andrew Scull 3422d14131edf5101379fc3bb16268920df3913599Andrew Scull /** 3522d14131edf5101379fc3bb16268920df3913599Andrew Scull * Read the value from the identified slot. 3622d14131edf5101379fc3bb16268920df3913599Andrew Scull * 3722d14131edf5101379fc3bb16268920df3913599Andrew Scull * This is only successful if the key matches that stored in the slot. 3822d14131edf5101379fc3bb16268920df3913599Andrew Scull * 3922d14131edf5101379fc3bb16268920df3913599Andrew Scull * @param slotId ID of the slot to write to. 4022d14131edf5101379fc3bb16268920df3913599Andrew Scull * @param key Buffer containing the key. 4122d14131edf5101379fc3bb16268920df3913599Andrew Scull * @param keyOffset Offset of the key in the buffer. 4222d14131edf5101379fc3bb16268920df3913599Andrew Scull * @param value Buffer to receive the value. 4322d14131edf5101379fc3bb16268920df3913599Andrew Scull * @param valueOffset Offset into the buffer to write the value. 4422d14131edf5101379fc3bb16268920df3913599Andrew Scull * @return Status byte indicating the success or otherwise of the read. 4522d14131edf5101379fc3bb16268920df3913599Andrew Scull */ 4622d14131edf5101379fc3bb16268920df3913599Andrew Scull byte read(short slotId, byte[] key, short keyOffset, byte[] value, short valueOffset); 4722d14131edf5101379fc3bb16268920df3913599Andrew Scull 485b8f7923540000d8861746a930c46e402821d89dAndrew Scull /** 495b8f7923540000d8861746a930c46e402821d89dAndrew Scull * Set the value of the identified slot to all zeros whilst leaving the key untouched. 505b8f7923540000d8861746a930c46e402821d89dAndrew Scull * 515b8f7923540000d8861746a930c46e402821d89dAndrew Scull * This is used to destroy the secret stored in the slot but retain the ability to authenticate 525b8f7923540000d8861746a930c46e402821d89dAndrew Scull * by comparing a challenege with the slot's key. 535b8f7923540000d8861746a930c46e402821d89dAndrew Scull * 545b8f7923540000d8861746a930c46e402821d89dAndrew Scull * @param slotId ID of the slot of which to erase the value. 555b8f7923540000d8861746a930c46e402821d89dAndrew Scull */ 565b8f7923540000d8861746a930c46e402821d89dAndrew Scull void eraseValue(short slotId); 575b8f7923540000d8861746a930c46e402821d89dAndrew Scull 585b8f7923540000d8861746a930c46e402821d89dAndrew Scull /** Erases the key and value of all slots. */ 5922d14131edf5101379fc3bb16268920df3913599Andrew Scull void eraseAll(); 6022d14131edf5101379fc3bb16268920df3913599Andrew Scull} 61