forked from Xilinx/bootgen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauthkeys-versal.h
executable file
·137 lines (116 loc) · 4.42 KB
/
authkeys-versal.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/******************************************************************************
* Copyright 2015-2020 Xilinx, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
#ifndef _AUTH_KEYS_VERSAL_H_
#define _AUTH_KEYS_VERSAL_H_
/*
-------------------------------------------------------------------------------
************************************************************ HEADER FILES *****
-------------------------------------------------------------------------------
*/
#include <stdint.h>
#include <string>
#include "logger.h"
#include <openssl/bn.h>
#include <openssl/rsa.h>
#include <openssl/evp.h>
#include <openssl/pem.h>
#include <openssl/ec.h>
#include "authkeys.h"
/*
-------------------------------------------------------------------------------
*********************************************************** PREPROCESSORS *****
-------------------------------------------------------------------------------
*/
//AC key related defines
#define RSA_4096_N 0x0
#define RSA_4096_N_EXT 0x200
#define RSA_4096_E 0x400
#define VERSAL_ACKEY_STRUCT_SIZE 1028
#define RSA_4096_N_SIZE 512
#define RSA_4096_N_EXT_SIZE 512
#define RSA_4096_E_SIZE 4
/*
-------------------------------------------------------------------------------
************************************************************** STRUCTURES *****
-------------------------------------------------------------------------------
*/
typedef struct
{
uint8_t N[RSA_4096_KEY_LENGTH]; // Modulus
uint8_t N_extension[RSA_4096_KEY_LENGTH]; // Montgomery Modulus extension
uint8_t E[4]; // Exponent
} ACKey4096Sha3Padding;
typedef struct
{
uint8_t x[EC_P384_KEY_LENGTH]; // x co-ordinate
uint8_t y[EC_P384_KEY_LENGTH]; // y co-ordinate
uint8_t pad[932]; // Padding
} ACKeyECDSA;
typedef struct
{
uint8_t x[EC_P521_KEY_LENGTH2]; // x co-ordinate
uint8_t y[EC_P521_KEY_LENGTH2]; // y co-ordinate
uint8_t pad[896]; // Padding
} ACKeyECDSAP521;
typedef struct
{
uint8_t Signature[SIGN_LENGTH_VERSAL];
} ACSignatureECDSA;
/*
-------------------------------------------------------------------------------
***************************************************************** CLASSES *****
-------------------------------------------------------------------------------
*/
class VersalKey : public Key
{
public:
VersalKey(const std::string& name0);
VersalKey(const Key& otherKey);
~VersalKey();
void Parse(const std::string& filename, bool isSecret0);
uint8_t ParseECDSAOpenSSLKey(FILE* f);
EC_KEY *eckey;
uint8_t *x; // x co-ordinate (384 bits)
uint8_t *y; // y co-ordinate (384 bits)
};
/******************************************************************************/
class Key4096Sha3Padding : public VersalKey
{
public:
Key4096Sha3Padding(const std::string& name0) : VersalKey(name0) { }
Key4096Sha3Padding(const Key4096Sha3Padding& otherKey) : VersalKey(otherKey) { }
void Export(void* dst);
void Import(const void* acKey, const std::string& name0);
};
/******************************************************************************/
class KeyECDSA : public VersalKey
{
public:
KeyECDSA(const std::string& name0) : VersalKey(name0) { }
KeyECDSA(const KeyECDSA& otherKey) : VersalKey(otherKey) { }
void Export(void* dst);
void Import(const void* acKey, const std::string& name0);
};
/******************************************************************************/
class KeyECDSAp521 : public VersalKey
{
public:
KeyECDSAp521(const std::string& name0) : VersalKey(name0) { }
KeyECDSAp521(const KeyECDSAp521& otherKey) : VersalKey(otherKey) { }
void Export(void* dst);
void Import(const void* acKey, const std::string& name0);
};
#endif