/*
 * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
 *
 * Created on: Oct 15, 2018
 * Author: Zhongyue Li <zhongyue.li@samsung.com>
 * Brief: Session management.
 */

#ifndef TIGER_SESSION_H
#define TIGER_SESSION_H

#include "TigerTci.h"
#include "TzwAuth.h"
#include "TzwHash.h"
#include "TzwCommon.h"
/**
 * Session context.
 */


typedef struct {
    uint64_t            sessionId;
    TciKeyAlias_t       alias;
    uint32_t            uid;
    TciChallenge_t      challenge;
    uint64_t            genTime;
#if defined(TIGER_TZ_MODEL_BLOWFISH)
    uint8_t             authKey[AUTH_KEY_LENGTH]; // Auth key is symetric SHA256 key which always will be 32 bytes.
#endif
} TigerSessionContext;

uint64_t tigerGetCurrTime();
TigerSessionContext* tigerAllocateSessionContext();
void tigerFreeSessionContext(TigerSessionContext* session);
uint64_t tigerGenerateSessionId(TciKeyAlias_t alias, TciChallenge_t challenge, uint32_t uid);
TEE_Result tigerLoadSessionContext(TigerSessionContext* session);
TEE_Result tigerSaveSessionContext(TigerSessionContext* session);
TEE_Result tigerRemoveSessionObject();
bool tigerCompareSessionContext(TigerSessionContext* session, TciKeyAlias_t alias,
                                      TciChallenge_t challenge, uint32_t uid);
bool tigerIsSessionTimout(TigerSessionContext* session);


#endif //TIGER_SESSION_H
