Home | History | Annotate | Download | only in libatap
      1 /*
      2  * Copyright 2017 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 #ifndef ATAP_TYPES_H_
     18 #define ATAP_TYPES_H_
     19 
     20 #ifdef __cplusplus
     21 extern "C" {
     22 #endif
     23 
     24 #include "atap_sysdeps.h"
     25 
     26 struct AtapOps;
     27 typedef struct AtapOps AtapOps;
     28 
     29 /* Return codes used for all operations.
     30  *
     31  * ATAP_RESULT_OK is returned if the requested operation was
     32  * successful.
     33  *
     34  * ATAP_RESULT_ERROR_IO is returned if the underlying hardware (disk
     35  * or other subsystem) encountered an I/O error.
     36  *
     37  * ATAP_RESULT_ERROR_OOM is returned if unable to allocate memory.
     38  *
     39  * ATAP_RESULT_ERROR_INVALID_INPUT is returned if inputs are invalid.
     40  *
     41  * ATAP_RESULT_ERROR_UNSUPPORTED_ALGORITHM is returned if the device does
     42  * not support the requested algorithm.
     43  *
     44  * ATAP_RESULT_ERROR_UNSUPPORTED_OPERATION is returned if the device does
     45  * not support the requested operation.
     46  *
     47  * ATAP_RESULT_ERROR_CRYPTO is returned if a crypto operation failed.
     48  */
     49 typedef enum {
     50   ATAP_RESULT_OK,
     51   ATAP_RESULT_ERROR_IO,
     52   ATAP_RESULT_ERROR_OOM,
     53   ATAP_RESULT_ERROR_INVALID_INPUT,
     54   ATAP_RESULT_ERROR_UNSUPPORTED_ALGORITHM,
     55   ATAP_RESULT_ERROR_UNSUPPORTED_OPERATION,
     56   ATAP_RESULT_ERROR_CRYPTO,
     57   ATAP_RESULT_ERROR_STORAGE,
     58 } AtapResult;
     59 
     60 typedef enum {
     61   ATAP_KEY_TYPE_NONE = 0,
     62   ATAP_KEY_TYPE_RSA = 1,
     63   ATAP_KEY_TYPE_ECDSA = 2,
     64   ATAP_KEY_TYPE_edDSA = 3,
     65   ATAP_KEY_TYPE_EPID = 4,
     66   ATAP_KEY_TYPE_SPECIAL = 5 /* in protocol v1, this is always the "cast" key
     67                              * persisted by the TEE */
     68 } AtapKeyType;
     69 
     70 typedef enum {
     71   ATAP_CURVE_TYPE_NONE = 0,
     72   ATAP_CURVE_TYPE_P256 = 1,
     73   ATAP_CURVE_TYPE_X25519 = 2,
     74 } AtapCurveType;
     75 
     76 typedef enum {
     77   ATAP_OPERATION_NONE = 0,
     78   ATAP_OPERATION_CERTIFY = 1,
     79   ATAP_OPERATION_ISSUE = 2,
     80   ATAP_OPERATION_ISSUE_ENCRYPTED = 3
     81 } AtapOperation;
     82 
     83 #define ATAP_PROTOCOL_VERSION 1
     84 #define ATAP_HEADER_LEN 8
     85 #define ATAP_ECDH_KEY_LEN 33
     86 #define ATAP_ECDH_SHARED_SECRET_LEN 32
     87 #define ATAP_OPERATION_START_LEN (ATAP_HEADER_LEN + 2 + ATAP_ECDH_KEY_LEN)
     88 #define ATAP_AES_128_KEY_LEN 16
     89 #define ATAP_GCM_IV_LEN 12
     90 #define ATAP_GCM_TAG_LEN 16
     91 #define ATAP_SHA256_DIGEST_LEN 32
     92 #define ATAP_PRODUCT_ID_LEN 16
     93 #define ATAP_NONCE_LEN 16
     94 #define ATAP_KEY_LEN_MAX 2048
     95 #define ATAP_CERT_LEN_MAX 2048
     96 #define ATAP_CERT_CHAIN_LEN_MAX 8192
     97 #define ATAP_CERT_CHAIN_ENTRIES_MAX 8
     98 #define ATAP_BLOB_LEN_MAX ATAP_CERT_CHAIN_LEN_MAX
     99 #define ATAP_SIGNATURE_LEN_MAX 512
    100 #define ATAP_HEX_UUID_LEN 32
    101 #define ATAP_INNER_CA_RESPONSE_FIELDS 10
    102 
    103 typedef struct {
    104   uint8_t* data;
    105   uint32_t data_length;
    106 } AtapBlob;
    107 
    108 typedef struct {
    109   AtapBlob entries[ATAP_CERT_CHAIN_ENTRIES_MAX];
    110   uint32_t entry_count;
    111 } AtapCertChain;
    112 
    113 typedef struct {
    114   uint8_t header[ATAP_HEADER_LEN];
    115   AtapCertChain auth_key_cert_chain;
    116   AtapBlob signature;
    117   uint8_t product_id_hash[ATAP_SHA256_DIGEST_LEN];
    118   AtapBlob RSA_pubkey;
    119   AtapBlob ECDSA_pubkey;
    120   AtapBlob edDSA_pubkey;
    121 } AtapInnerCaRequest;
    122 
    123 typedef struct {
    124   uint8_t header[ATAP_HEADER_LEN];
    125   uint8_t device_pubkey[ATAP_ECDH_KEY_LEN];
    126   uint8_t iv[ATAP_GCM_IV_LEN];
    127   AtapBlob encrypted_inner_ca_request;
    128   uint8_t tag[ATAP_GCM_TAG_LEN];
    129 } AtapCaRequest;
    130 
    131 typedef struct {
    132   uint8_t header[ATAP_HEADER_LEN];
    133   uint8_t iv[ATAP_GCM_IV_LEN];
    134   AtapBlob encrypted;
    135   uint8_t tag[ATAP_GCM_TAG_LEN];
    136 } AtapEncryptedMessage;
    137 
    138 #ifdef __cplusplus
    139 }
    140 #endif
    141 
    142 #endif /* ATAP_TYPES_H_ */
    143