1 /*
2  * Copyright 2021, 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 #if !defined(EIC_INSIDE_LIBEIC_H) && !defined(EIC_COMPILATION)
18 #error "Never include this file directly, include libeic.h instead."
19 #endif
20 
21 #ifndef ANDROID_HARDWARE_IDENTITY_EIC_SESSION_H
22 #define ANDROID_HARDWARE_IDENTITY_EIC_SESSION_H
23 
24 #include "EicOps.h"
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 typedef struct {
31     // A non-zero number unique for this EicSession instance
32     uint32_t id;
33 
34     // Set to true iff eicSessionGetEphemeralKeyPair() has been called.
35     bool getEphemeralKeyPairCalled;
36 
37     // The challenge generated at construction time by eicSessionInit().
38     uint64_t authChallenge;
39 
40     uint8_t ephemeralPrivateKey[EIC_P256_PRIV_KEY_SIZE];
41     uint8_t ephemeralPublicKey[EIC_P256_PUB_KEY_SIZE];
42 
43     uint8_t readerEphemeralPublicKey[EIC_P256_PUB_KEY_SIZE];
44 
45     uint8_t sessionTranscriptSha256[EIC_SHA256_DIGEST_SIZE];
46 
47     size_t readerEphemeralPublicKeySize;
48 } EicSession;
49 
50 bool eicSessionInit(EicSession* ctx);
51 
52 bool eicSessionShutdown(EicSession* ctx);
53 
54 bool eicSessionGetId(EicSession* ctx, uint32_t* outId);
55 
56 bool eicSessionGetAuthChallenge(EicSession* ctx, uint64_t* outAuthChallenge);
57 
58 bool eicSessionGetEphemeralKeyPair(EicSession* ctx,
59                                    uint8_t ephemeralPrivateKey[EIC_P256_PRIV_KEY_SIZE]);
60 
61 bool eicSessionSetReaderEphemeralPublicKey(
62         EicSession* ctx, const uint8_t readerEphemeralPublicKey[EIC_P256_PUB_KEY_SIZE]);
63 
64 bool eicSessionSetSessionTranscript(EicSession* ctx, const uint8_t* sessionTranscript,
65                                     size_t sessionTranscriptSize);
66 
67 // Looks up an active session with the given id.
68 //
69 // Returns NULL if no active session with the given id is found.
70 //
71 EicSession* eicSessionGetForId(uint32_t sessionId);
72 
73 #ifdef __cplusplus
74 }
75 #endif
76 
77 #endif  // ANDROID_HARDWARE_IDENTITY_EIC_PRESENTATION_H
78