|
1 | 1 | /* crypto.c |
2 | 2 | * |
3 | | - * Copyright (C) 2006-2019 wolfSSL Inc. |
| 3 | + * Copyright (C) 2006-2024 wolfSSL Inc. |
4 | 4 | * |
5 | 5 | * This file is part of wolfSSL. |
6 | 6 | * |
@@ -101,38 +101,44 @@ static int GetKey(Crypto_JobType* job, uint32 eId, uint8 **key, uint32 *keySz) |
101 | 101 | } |
102 | 102 |
|
103 | 103 | // @TODO sanity checks on setup... uint8 redirectionConfig; |
104 | | - if (eId == job->jobRedirectionInfoRef->inputKeyElementId) { |
105 | | - if (job->jobRedirectionInfoRef->inputKeyId >= MAX_KEYSTORE) { |
106 | | - WOLFSSL_MSG("Bogus input key ID redirection (too large)"); |
107 | | - ret = -1; |
108 | | - } |
109 | | - else { |
110 | | - i = job->jobRedirectionInfoRef->inputKeyId; |
111 | | - *key = keyStore[i].key; |
112 | | - *keySz = keyStore[i].keyLen; |
113 | | - } |
114 | | - } |
115 | | - if (eId == job->jobRedirectionInfoRef->secondaryInputKeyElementId) { |
116 | | - if (job->jobRedirectionInfoRef->secondaryInputKeyId >= MAX_KEYSTORE) { |
117 | | - WOLFSSL_MSG("Bogus input key ID redirection (too large)"); |
118 | | - ret = -1; |
119 | | - } |
120 | | - else { |
121 | | - i = job->jobRedirectionInfoRef->secondaryInputKeyId; |
122 | | - *key = keyStore[i].key; |
123 | | - *keySz = keyStore[i].keyLen; |
124 | | - } |
125 | | - } |
126 | | - if (eId == job->jobRedirectionInfoRef->tertiaryInputKeyElementId) { |
127 | | - if (job->jobRedirectionInfoRef->tertiaryInputKeyId >= MAX_KEYSTORE) { |
128 | | - WOLFSSL_MSG("Bogus input key ID redirection (too large)"); |
| 104 | + switch (eid) { |
| 105 | + case job->jobRedirectionInfoRef->inputKeyElementId: |
| 106 | + if (job->jobRedirectionInfoRef->inputKeyId >= MAX_KEYSTORE) { |
| 107 | + WOLFSSL_MSG("Bogus input key ID redirection (too large)"); |
| 108 | + ret = -1; |
| 109 | + } |
| 110 | + else { |
| 111 | + i = job->jobRedirectionInfoRef->inputKeyId; |
| 112 | + *key = keyStore[i].key; |
| 113 | + *keySz = keyStore[i].keyLen; |
| 114 | + } |
| 115 | + break; |
| 116 | + case job->jobRedirectionInfoRef->secondaryInputKeyElementId: |
| 117 | + if (job->jobRedirectionInfoRef->secondaryInputKeyId >= MAX_KEYSTORE) { |
| 118 | + WOLFSSL_MSG("Bogus input key ID redirection (too large)"); |
| 119 | + ret = -1; |
| 120 | + } |
| 121 | + else { |
| 122 | + i = job->jobRedirectionInfoRef->secondaryInputKeyId; |
| 123 | + *key = keyStore[i].key; |
| 124 | + *keySz = keyStore[i].keyLen; |
| 125 | + } |
| 126 | + break; |
| 127 | + case job->jobRedirectionInfoRef->tertiaryInputKeyElementId: |
| 128 | + if (job->jobRedirectionInfoRef->tertiaryInputKeyId >= MAX_KEYSTORE) { |
| 129 | + WOLFSSL_MSG("Bogus input key ID redirection (too large)"); |
| 130 | + ret = -1; |
| 131 | + } |
| 132 | + else { |
| 133 | + i = job->jobRedirectionInfoRef->tertiaryInputKeyId; |
| 134 | + *key = keyStore[i].key; |
| 135 | + *keySz = keyStore[i].keyLen; |
| 136 | + } |
| 137 | + break; |
| 138 | + default: |
| 139 | + WOLFSSL_MSG("Unknown key element ID"); |
129 | 140 | ret = -1; |
130 | | - } |
131 | | - else { |
132 | | - i = job->jobRedirectionInfoRef->tertiaryInputKeyId; |
133 | | - *key = keyStore[i].key; |
134 | | - *keySz = keyStore[i].keyLen; |
135 | | - } |
| 141 | + break; |
136 | 142 | } |
137 | 143 | #else |
138 | 144 | /* find first key of key element type */ |
@@ -180,8 +186,15 @@ static Aes* NewAesStruct(Crypto_JobType* job) |
180 | 186 |
|
181 | 187 | for (i = 0; i < MAX_JOBS; i++) { |
182 | 188 | if (activeJobs[i].inUse == 0) { |
| 189 | + int ret; |
| 190 | + |
183 | 191 | activeJobs[i].inUse = 1; |
184 | 192 | activeJobs[i].jobId = job->jobId; |
| 193 | + ret = wc_AesInit(&activeJobs[i].aes, NULL, INVALID_DEVID); |
| 194 | + if (ret != 0) { |
| 195 | + WOLFSSL_MSG("Error initializing AES structure"); |
| 196 | + return NULL; |
| 197 | + } |
185 | 198 | return &activeJobs[i].aes; |
186 | 199 | } |
187 | 200 | } |
@@ -252,7 +265,7 @@ Std_ReturnType wolfSSL_Crypto_CBC(Crypto_JobType* job) |
252 | 265 | WOLFSSL_MSG("Crypto error setting up AES key"); |
253 | 266 | return E_NOT_OK; |
254 | 267 | } |
255 | | - /* ForceZero(key, keySz); Do not keep raw key in memory */ |
| 268 | + ForceZero(key, keySz); |
256 | 269 | } |
257 | 270 |
|
258 | 271 | if ((job->jobPrimitiveInputOutput.mode & CRYPTO_OPERATIONMODE_UPDATE) |
|
0 commit comments