keystore.h revision 822c3a99d930e9299e2fad2fb3e0ff91b119b95a
1a91203b08350b2fc7efda5b1eab39e7541476b3aKenny Root/*
2a91203b08350b2fc7efda5b1eab39e7541476b3aKenny Root * Copyright (C) 2009 The Android Open Source Project
3a91203b08350b2fc7efda5b1eab39e7541476b3aKenny Root *
4a91203b08350b2fc7efda5b1eab39e7541476b3aKenny Root * Licensed under the Apache License, Version 2.0 (the "License");
5a91203b08350b2fc7efda5b1eab39e7541476b3aKenny Root * you may not use this file except in compliance with the License.
6a91203b08350b2fc7efda5b1eab39e7541476b3aKenny Root * You may obtain a copy of the License at
7a91203b08350b2fc7efda5b1eab39e7541476b3aKenny Root *
8a91203b08350b2fc7efda5b1eab39e7541476b3aKenny Root *      http://www.apache.org/licenses/LICENSE-2.0
9a91203b08350b2fc7efda5b1eab39e7541476b3aKenny Root *
10a91203b08350b2fc7efda5b1eab39e7541476b3aKenny Root * Unless required by applicable law or agreed to in writing, software
11a91203b08350b2fc7efda5b1eab39e7541476b3aKenny Root * distributed under the License is distributed on an "AS IS" BASIS,
12a91203b08350b2fc7efda5b1eab39e7541476b3aKenny Root * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13a91203b08350b2fc7efda5b1eab39e7541476b3aKenny Root * See the License for the specific language governing permissions and
14a91203b08350b2fc7efda5b1eab39e7541476b3aKenny Root * limitations under the License.
15a91203b08350b2fc7efda5b1eab39e7541476b3aKenny Root */
16a91203b08350b2fc7efda5b1eab39e7541476b3aKenny Root
17a91203b08350b2fc7efda5b1eab39e7541476b3aKenny Root#ifndef __KEYSTORE_H__
18a91203b08350b2fc7efda5b1eab39e7541476b3aKenny Root#define __KEYSTORE_H__
19a91203b08350b2fc7efda5b1eab39e7541476b3aKenny Root
205187818895c4c5f650a611c40531b1dff7764c18Kenny Root#include <stdint.h>
215187818895c4c5f650a611c40531b1dff7764c18Kenny Root
22a91203b08350b2fc7efda5b1eab39e7541476b3aKenny Root// note state values overlap with ResponseCode for the purposes of the state() API
23a91203b08350b2fc7efda5b1eab39e7541476b3aKenny Rootenum State {
24a91203b08350b2fc7efda5b1eab39e7541476b3aKenny Root    STATE_NO_ERROR      = 1,
25a91203b08350b2fc7efda5b1eab39e7541476b3aKenny Root    STATE_LOCKED        = 2,
26a91203b08350b2fc7efda5b1eab39e7541476b3aKenny Root    STATE_UNINITIALIZED = 3,
27a91203b08350b2fc7efda5b1eab39e7541476b3aKenny Root};
28a91203b08350b2fc7efda5b1eab39e7541476b3aKenny Root
29a91203b08350b2fc7efda5b1eab39e7541476b3aKenny Rootenum ResponseCode {
30a91203b08350b2fc7efda5b1eab39e7541476b3aKenny Root    NO_ERROR          =  STATE_NO_ERROR, // 1
31a91203b08350b2fc7efda5b1eab39e7541476b3aKenny Root    LOCKED            =  STATE_LOCKED, // 2
32a91203b08350b2fc7efda5b1eab39e7541476b3aKenny Root    UNINITIALIZED     =  STATE_UNINITIALIZED, // 3
33a91203b08350b2fc7efda5b1eab39e7541476b3aKenny Root    SYSTEM_ERROR      =  4,
34a91203b08350b2fc7efda5b1eab39e7541476b3aKenny Root    PROTOCOL_ERROR    =  5,
35a91203b08350b2fc7efda5b1eab39e7541476b3aKenny Root    PERMISSION_DENIED =  6,
36a91203b08350b2fc7efda5b1eab39e7541476b3aKenny Root    KEY_NOT_FOUND     =  7,
37a91203b08350b2fc7efda5b1eab39e7541476b3aKenny Root    VALUE_CORRUPTED   =  8,
38a91203b08350b2fc7efda5b1eab39e7541476b3aKenny Root    UNDEFINED_ACTION  =  9,
39a91203b08350b2fc7efda5b1eab39e7541476b3aKenny Root    WRONG_PASSWORD_0  = 10,
40a91203b08350b2fc7efda5b1eab39e7541476b3aKenny Root    WRONG_PASSWORD_1  = 11,
41a91203b08350b2fc7efda5b1eab39e7541476b3aKenny Root    WRONG_PASSWORD_2  = 12,
42a91203b08350b2fc7efda5b1eab39e7541476b3aKenny Root    WRONG_PASSWORD_3  = 13, // MAX_RETRY = 4
4370e3a86abd2c412d602a018967c01c177eb6cf4eKenny Root    SIGNATURE_INVALID = 14,
44a91203b08350b2fc7efda5b1eab39e7541476b3aKenny Root};
45a91203b08350b2fc7efda5b1eab39e7541476b3aKenny Root
465187818895c4c5f650a611c40531b1dff7764c18Kenny Rootenum CommandNames {
475187818895c4c5f650a611c40531b1dff7764c18Kenny Root    TEST = 0,
485187818895c4c5f650a611c40531b1dff7764c18Kenny Root    GET = 1,
495187818895c4c5f650a611c40531b1dff7764c18Kenny Root    INSERT = 2,
505187818895c4c5f650a611c40531b1dff7764c18Kenny Root    DELETE = 3,
515187818895c4c5f650a611c40531b1dff7764c18Kenny Root    EXIST = 4,
525187818895c4c5f650a611c40531b1dff7764c18Kenny Root    SAW = 5,
535187818895c4c5f650a611c40531b1dff7764c18Kenny Root    RESET = 6,
545187818895c4c5f650a611c40531b1dff7764c18Kenny Root    PASSWORD = 7,
555187818895c4c5f650a611c40531b1dff7764c18Kenny Root    LOCK = 8,
565187818895c4c5f650a611c40531b1dff7764c18Kenny Root    UNLOCK = 9,
575187818895c4c5f650a611c40531b1dff7764c18Kenny Root    ZERO = 10,
5870e3a86abd2c412d602a018967c01c177eb6cf4eKenny Root    GENERATE = 11,
5970e3a86abd2c412d602a018967c01c177eb6cf4eKenny Root    IMPORT = 12,
6070e3a86abd2c412d602a018967c01c177eb6cf4eKenny Root    SIGN = 13,
6170e3a86abd2c412d602a018967c01c177eb6cf4eKenny Root    VERIFY = 14,
6270e3a86abd2c412d602a018967c01c177eb6cf4eKenny Root    GET_PUBKEY = 15,
6370e3a86abd2c412d602a018967c01c177eb6cf4eKenny Root    DEL_KEY = 16,
6470e3a86abd2c412d602a018967c01c177eb6cf4eKenny Root    GRANT = 17,
6570e3a86abd2c412d602a018967c01c177eb6cf4eKenny Root    UNGRANT = 18,
665187818895c4c5f650a611c40531b1dff7764c18Kenny Root};
675187818895c4c5f650a611c40531b1dff7764c18Kenny Root
685187818895c4c5f650a611c40531b1dff7764c18Kenny Roottypedef uint8_t command_code_t;
695187818895c4c5f650a611c40531b1dff7764c18Kenny Root
7070e3a86abd2c412d602a018967c01c177eb6cf4eKenny Root// Taken: a b c d e f g h i j k l m n o p q r s t u v w x y z
7170e3a86abd2c412d602a018967c01c177eb6cf4eKenny Root//        * *   * *   *   *   * * * *   *   * * * * *   *   *
725187818895c4c5f650a611c40531b1dff7764c18Kenny Rootcommand_code_t CommandCodes[] = {
735187818895c4c5f650a611c40531b1dff7764c18Kenny Root    't', // TEST
745187818895c4c5f650a611c40531b1dff7764c18Kenny Root    'g', // GET
755187818895c4c5f650a611c40531b1dff7764c18Kenny Root    'i', // INSERT
765187818895c4c5f650a611c40531b1dff7764c18Kenny Root    'd', // DELETE
775187818895c4c5f650a611c40531b1dff7764c18Kenny Root    'e', // EXIST
785187818895c4c5f650a611c40531b1dff7764c18Kenny Root    's', // SAW
795187818895c4c5f650a611c40531b1dff7764c18Kenny Root    'r', // RESET
805187818895c4c5f650a611c40531b1dff7764c18Kenny Root    'p', // PASSWORD
815187818895c4c5f650a611c40531b1dff7764c18Kenny Root    'l', // LOCK
825187818895c4c5f650a611c40531b1dff7764c18Kenny Root    'u', // UNLOCK
835187818895c4c5f650a611c40531b1dff7764c18Kenny Root    'z', // ZERO
8470e3a86abd2c412d602a018967c01c177eb6cf4eKenny Root    'a', // GENERATE
8570e3a86abd2c412d602a018967c01c177eb6cf4eKenny Root    'm', // IMPORT
8670e3a86abd2c412d602a018967c01c177eb6cf4eKenny Root    'n', // SIGN
8770e3a86abd2c412d602a018967c01c177eb6cf4eKenny Root    'v', // VERIFY
8870e3a86abd2c412d602a018967c01c177eb6cf4eKenny Root    'b', // GET_PUBKEY
8970e3a86abd2c412d602a018967c01c177eb6cf4eKenny Root    'k', // DEL_KEY
9070e3a86abd2c412d602a018967c01c177eb6cf4eKenny Root    'x', // GRANT
9170e3a86abd2c412d602a018967c01c177eb6cf4eKenny Root    'y', // UNGRANT
925187818895c4c5f650a611c40531b1dff7764c18Kenny Root};
935187818895c4c5f650a611c40531b1dff7764c18Kenny Root
94822c3a99d930e9299e2fad2fb3e0ff91b119b95aKenny Root/**
95822c3a99d930e9299e2fad2fb3e0ff91b119b95aKenny Root * Returns the size of the softkey magic header value for measuring
96822c3a99d930e9299e2fad2fb3e0ff91b119b95aKenny Root * and allocating purposes.
97822c3a99d930e9299e2fad2fb3e0ff91b119b95aKenny Root */
98822c3a99d930e9299e2fad2fb3e0ff91b119b95aKenny Rootsize_t get_softkey_header_size();
99822c3a99d930e9299e2fad2fb3e0ff91b119b95aKenny Root
100822c3a99d930e9299e2fad2fb3e0ff91b119b95aKenny Root/**
101822c3a99d930e9299e2fad2fb3e0ff91b119b95aKenny Root * Adds the magic softkey header to a key blob.
102822c3a99d930e9299e2fad2fb3e0ff91b119b95aKenny Root *
103822c3a99d930e9299e2fad2fb3e0ff91b119b95aKenny Root * Returns NULL if the destination array is too small. Otherwise it
104822c3a99d930e9299e2fad2fb3e0ff91b119b95aKenny Root * returns the offset directly after the magic value.
105822c3a99d930e9299e2fad2fb3e0ff91b119b95aKenny Root */
106822c3a99d930e9299e2fad2fb3e0ff91b119b95aKenny Rootuint8_t* add_softkey_header(uint8_t* key_blob, size_t key_blob_length);
107822c3a99d930e9299e2fad2fb3e0ff91b119b95aKenny Root
108822c3a99d930e9299e2fad2fb3e0ff91b119b95aKenny Root/**
109822c3a99d930e9299e2fad2fb3e0ff91b119b95aKenny Root * Returns true if the key blob has a magic softkey header at the beginning.
110822c3a99d930e9299e2fad2fb3e0ff91b119b95aKenny Root */
111822c3a99d930e9299e2fad2fb3e0ff91b119b95aKenny Rootbool is_softkey(const uint8_t* key_blob, const size_t key_blob_length);
112822c3a99d930e9299e2fad2fb3e0ff91b119b95aKenny Root
113a91203b08350b2fc7efda5b1eab39e7541476b3aKenny Root#endif
114