SEcube open-source SDK
L1_base.h
Go to the documentation of this file.
1 
10 #ifndef _L1_BASE_H
11 #define _L1_BASE_H
12 
13 #include "../../L0/L0 Base/L0_base.h"
14 #include "../Crypto Libraries/aes256.h"
15 #include "../../L0/L0_error_manager.h"
16 #include "../Crypto Libraries/pbkdf2.h"
17 #include "../L1_error_manager.h"
18 
19 #include "../L1_enumerations.h"
20 
21 //AES
22 #define B5_AES_256 32
23 //SHA
24 #ifndef B5_SHA256_DIGEST_SIZE
25 #define B5_SHA256_DIGEST_SIZE 32
26 #endif
27 
28 #define B5_AES256_CBC_ENC 4
29 #define B5_AES256_CBC_DEC 5
30 #ifndef B5_AES_BLK_SIZE
31 #define B5_AES_BLK_SIZE 16
32 #endif
33 
34 enum{
35  FIND_KEY_NUM = 50
36 };
37 
38 typedef enum se3_access_type_ {
39  SE3_ACCESS_NONE = 0,
40  SE3_ACCESS_USER = 100,
41  SE3_ACCESS_ADMIN = 1000,
42  SE3_ACCESS_MAX = 0xFFFF
43 } se3_access_type;
44 
45 typedef struct se3PayloadCryptoctx_ {
46  B5_tAesCtx aesenc;
47  B5_tAesCtx aesdec;
48  B5_tHmacSha256Ctx hmac;
49  uint8_t hmacKey[B5_AES_256];
50  uint8_t auth[B5_SHA256_DIGEST_SIZE];
51 } se3PayloadCryptoctx;
52 
54 typedef struct se3Session_ {
55  //se3Device device;
56  uint8_t token[L1Parameters::Size::TOKEN];
57  uint8_t key[L1Parameters::Size::KEY];
58  uint8_t buf[L0Communication::Parameter::COMM_N * L0Communication::Parameter::COMM_BLOCK];
59  bool locked;
60  bool logged_in;
61  uint32_t timeout;
62  se3File hfile;
63  se3PayloadCryptoctx cryptoctx;
64  bool cryptoctx_initialized;
65  se3_access_type access_type;
66 } se3Session;
67 
69 typedef struct se3Algo_ {
70  uint8_t name[L1Crypto::AlgorithmInfoSize::NAME_SIZE];
71  uint16_t type;
72  uint16_t blockSize;
73  uint16_t keySize;
74 } se3Algo;
75 
77 typedef struct se3Key_ {
78  uint32_t id;
79  uint32_t validity;
80  uint16_t dataSize;
81  uint16_t nameSize;
82  uint8_t* data;
83  uint8_t name[L1Key::Size::MAX_NAME];
84 } se3Key;
85 
86 class L1Base {
87 private:
88  std::vector<se3Session> s;
89  //se3Session s;
90  uint8_t ptr;
91 public:
92  L1Base();
93  ~L1Base();
94 
95  void SwitchToSession(uint8_t sPtr);
96  //fills the list of sessions (one session for each device connected)
97  void InitializeSession(uint8_t nSessions);
98  //fill the session buffer with tha data passed as parameter
99  void FillSessionBuffer(uint8_t* data, size_t offset, size_t len);
100  //fill the session buffer with 0
101  void FillSessionBuffer(size_t offset, size_t len);
102  uint8_t* GetSessionBuffer();
103  bool GetSessionLoggedIn();
104  void SetSessionLoggedIn(bool logged);
105  se3_access_type GetSessionAccessType();
106  void SetSessionAccessType(se3_access_type access);
107  bool GetSessionCryptoInitialized();
108  B5_tAesCtx* GetSessionCryptoctxAesenc();
109  B5_tAesCtx* GetSessionCryptoctxAesdec();
110  void SetSessionCryptoctxHmacKey(uint8_t* keys, size_t offset, size_t len);
111  uint8_t* GetSessionCryptoctxHmacKey();
112  B5_tHmacSha256Ctx* GetSessionCryptoctxHmac();
113  void SetCryptoctxInizialized(bool init);
114  uint8_t* GetSessionKey();
115  uint8_t* GetSessionToken();
116  void SetSessionToken(size_t offset, size_t len);
117  uint8_t* GetSessionCryptoctxAuth();
118  void ReadSessionBuffer(uint8_t* retData, size_t offset, size_t len);
119  bool CompareSessionBuf(uint8_t* cmpData, size_t offset, size_t len);
120  // @matteo: added to support SEfile
121  se3Session *GetCurrentSession();
122 };
123 
124 #endif
se3Key
struct se3Key_ se3Key
SEcube Key structure.
B5_AES_256
#define B5_AES_256
Definition: aes256.h:42
se3Session
struct se3Session_ se3Session
SEcube Communication session structure.
se3Algo_
SEcube Algorithm structure.
Definition: L1_base.h:69
se3Session_
SEcube Communication session structure.
Definition: L1_base.h:54
se3Key_
SEcube Key structure.
Definition: L1_base.h:77
se3Algo
struct se3Algo_ se3Algo
SEcube Algorithm structure.
B5_AES_256
#define B5_AES_256
Definition: L1_base.h:22
L1_base.h
Prototypes of the L1Base library.