Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: FXAS21002 FXOS8700Q
pal_Crypto.c
00001 /******************************************************************************* 00002 * Copyright 2016, 2017 ARM Ltd. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 *******************************************************************************/ 00016 #include "pal.h" 00017 #include "pal_plat_Crypto.h" 00018 00019 #define TRACE_GROUP "PAL" 00020 00021 palStatus_t pal_initAes(palAesHandle_t *aes) 00022 { 00023 palStatus_t status = PAL_SUCCESS; 00024 PAL_VALIDATE_ARGUMENTS((NULLPTR == aes)) 00025 00026 status = pal_plat_initAes(aes); 00027 return status; 00028 } 00029 00030 palStatus_t pal_freeAes(palAesHandle_t *aes) 00031 { 00032 palStatus_t status = PAL_SUCCESS; 00033 PAL_VALIDATE_ARGUMENTS((NULL == aes || (uintptr_t)NULL == *aes)) 00034 00035 status = pal_plat_freeAes(aes); 00036 return status; 00037 } 00038 00039 palStatus_t pal_setAesKey(palAesHandle_t aes, const unsigned char* key, uint32_t keybits, palAesKeyType_t keyTarget) 00040 { 00041 palStatus_t status = PAL_SUCCESS; 00042 PAL_VALIDATE_ARGUMENTS((NULLPTR == aes || NULL == key)) 00043 00044 status = pal_plat_setAesKey(aes, key, keybits, keyTarget); 00045 return status; 00046 } 00047 00048 palStatus_t pal_aesCTR(palAesHandle_t aes, const unsigned char* input, unsigned char* output, size_t inLen, unsigned char iv[16]) 00049 { 00050 palStatus_t status = PAL_SUCCESS; 00051 PAL_VALIDATE_ARGUMENTS((NULLPTR == aes || NULL == input || NULL == output || NULL == iv)) 00052 00053 status = pal_plat_aesCTR(aes, input, output, inLen, iv, false); 00054 return status; 00055 } 00056 00057 palStatus_t pal_aesCTRWithZeroOffset(palAesHandle_t aes, const unsigned char* input, unsigned char* output, size_t inLen, unsigned char iv[16]) 00058 { 00059 palStatus_t status = PAL_SUCCESS; 00060 PAL_VALIDATE_ARGUMENTS((NULLPTR == aes || NULL == input || NULL == output || NULL == iv)) 00061 00062 status = pal_plat_aesCTR(aes, input, output, inLen, iv, true); 00063 return status; 00064 } 00065 00066 palStatus_t pal_aesECB(palAesHandle_t aes, const unsigned char input[PAL_CRYPT_BLOCK_SIZE], unsigned char output[PAL_CRYPT_BLOCK_SIZE], palAesMode_t mode) 00067 { 00068 palStatus_t status = PAL_SUCCESS; 00069 PAL_VALIDATE_ARGUMENTS((NULLPTR == aes || NULL == input || NULL == output)) 00070 00071 status = pal_plat_aesECB(aes, input, output, mode); 00072 return status; 00073 } 00074 00075 palStatus_t pal_sha256(const unsigned char* input, size_t inLen, unsigned char* output) 00076 { 00077 palStatus_t status = PAL_SUCCESS; 00078 PAL_VALIDATE_ARGUMENTS((NULL == input || NULL == output)) 00079 00080 status = pal_plat_sha256(input, inLen, output); 00081 return status; 00082 } 00083 00084 palStatus_t pal_x509Initiate(palX509Handle_t* x509Cert) 00085 { 00086 #if (PAL_ENABLE_X509 == 1) 00087 palStatus_t status = PAL_SUCCESS; 00088 PAL_VALIDATE_ARGUMENTS( (NULL == x509Cert)) 00089 00090 status = pal_plat_x509Initiate(x509Cert); 00091 return status; 00092 #else 00093 return PAL_ERR_NOT_SUPPORTED ; 00094 #endif 00095 } 00096 00097 palStatus_t pal_x509CertParse(palX509Handle_t x509Cert, const unsigned char* input, size_t inLen) 00098 { 00099 #if (PAL_ENABLE_X509 == 1) 00100 palStatus_t status = PAL_SUCCESS; 00101 PAL_VALIDATE_ARGUMENTS((NULLPTR == x509Cert || NULL == input)) 00102 00103 status = pal_plat_x509CertParse(x509Cert, input, inLen); 00104 return status; 00105 #else 00106 return PAL_ERR_NOT_SUPPORTED ; 00107 #endif 00108 } 00109 00110 palStatus_t pal_x509CertGetAttribute(palX509Handle_t x509Cert, palX509Attr_t attr, void* output, size_t outLenBytes, size_t* actualOutLenBytes) 00111 { 00112 #if (PAL_ENABLE_X509 == 1) 00113 palStatus_t status = PAL_SUCCESS; 00114 PAL_VALIDATE_ARGUMENTS((NULLPTR == x509Cert || NULL == output || NULL == actualOutLenBytes)) 00115 00116 status = pal_plat_x509CertGetAttribute(x509Cert, attr, output, outLenBytes, actualOutLenBytes); 00117 return status; 00118 #else 00119 return PAL_ERR_NOT_SUPPORTED ; 00120 #endif 00121 } 00122 00123 palStatus_t pal_x509CertVerifyExtended(palX509Handle_t x509Cert, palX509Handle_t x509CertChain, int32_t* verifyResult) 00124 { 00125 palStatus_t status = PAL_SUCCESS; 00126 PAL_VALIDATE_ARGUMENTS((NULLPTR == x509Cert) || (NULL == verifyResult)) 00127 *verifyResult = 0; 00128 #if (PAL_ENABLE_X509 == 1) 00129 status = pal_plat_x509CertVerifyExtended(x509Cert, x509CertChain, verifyResult); 00130 if (0 != *verifyResult) 00131 { 00132 status = PAL_ERR_X509_CERT_VERIFY_FAILED; 00133 *verifyResult = *verifyResult ^ PAL_ERR_MODULE_BITMASK_BASE; //! in order to turn off the MSB bit. 00134 } 00135 #endif 00136 return status; 00137 } 00138 00139 palStatus_t pal_x509CertVerify(palX509Handle_t x509Cert, palX509Handle_t x509CertChain) 00140 { 00141 #if (PAL_ENABLE_X509 == 1) 00142 palStatus_t status = PAL_SUCCESS; 00143 int32_t verifyResult = 0; 00144 00145 PAL_VALIDATE_ARGUMENTS((NULLPTR == x509Cert)) 00146 00147 status = pal_plat_x509CertVerifyExtended(x509Cert, x509CertChain, &verifyResult); 00148 return status; 00149 #else 00150 return PAL_ERR_NOT_SUPPORTED ; 00151 #endif 00152 } 00153 00154 palStatus_t pal_x509Free(palX509Handle_t* x509Cert) 00155 { 00156 #if (PAL_ENABLE_X509 == 1) 00157 palStatus_t status = PAL_SUCCESS; 00158 PAL_VALIDATE_ARGUMENTS((NULLPTR == x509Cert || NULLPTR == *x509Cert)) 00159 00160 status = pal_plat_x509Free(x509Cert); 00161 return status; 00162 #else 00163 return PAL_ERR_NOT_SUPPORTED ; 00164 #endif 00165 } 00166 00167 palStatus_t pal_mdInit(palMDHandle_t* md, palMDType_t mdType) 00168 { 00169 palStatus_t status = PAL_SUCCESS; 00170 PAL_VALIDATE_ARGUMENTS((NULLPTR == md)) 00171 00172 status = pal_plat_mdInit(md, mdType); 00173 return status; 00174 } 00175 00176 palStatus_t pal_mdUpdate(palMDHandle_t md, const unsigned char* input, size_t inLen) 00177 { 00178 palStatus_t status = PAL_SUCCESS; 00179 PAL_VALIDATE_ARGUMENTS((NULLPTR == md || NULL == input)) 00180 00181 status = pal_plat_mdUpdate(md, input, inLen); 00182 return status; 00183 } 00184 00185 palStatus_t pal_mdGetOutputSize(palMDHandle_t md, size_t* bufferSize) 00186 { 00187 palStatus_t status = PAL_SUCCESS; 00188 PAL_VALIDATE_ARGUMENTS((NULLPTR == md || NULL == bufferSize)) 00189 00190 status = pal_plat_mdGetOutputSize(md, bufferSize); 00191 return status; 00192 } 00193 00194 palStatus_t pal_mdFinal(palMDHandle_t md, unsigned char* output) 00195 { 00196 palStatus_t status = PAL_SUCCESS; 00197 PAL_VALIDATE_ARGUMENTS((NULLPTR == md || NULL == output)) 00198 00199 status = pal_plat_mdFinal(md, output); 00200 return status; 00201 } 00202 00203 palStatus_t pal_mdFree(palMDHandle_t* md) 00204 { 00205 palStatus_t status = PAL_SUCCESS; 00206 PAL_VALIDATE_ARGUMENTS((NULLPTR == md || NULLPTR == *md)) 00207 00208 status = pal_plat_mdFree(md); 00209 return status; 00210 } 00211 00212 palStatus_t pal_verifySignature(palX509Handle_t x509, palMDType_t mdType, const unsigned char *hash, size_t hashLen, const unsigned char *sig, size_t sigLen) 00213 { 00214 #if (PAL_ENABLE_X509 == 1) 00215 palStatus_t status = PAL_SUCCESS; 00216 PAL_VALIDATE_ARGUMENTS((NULLPTR == x509 || NULL == hash || NULL == sig)) 00217 00218 status = pal_plat_verifySignature(x509, mdType, hash, hashLen, sig, sigLen); 00219 return status; 00220 #else 00221 return PAL_ERR_NOT_SUPPORTED ; 00222 #endif 00223 } 00224 00225 palStatus_t pal_ASN1GetTag(unsigned char **position, const unsigned char *end, size_t *len, uint8_t tag ) 00226 { 00227 palStatus_t status = PAL_SUCCESS; 00228 PAL_VALIDATE_ARGUMENTS((NULL == position || NULL == end || NULL == len)) 00229 00230 status = pal_plat_ASN1GetTag(position, end, len, tag); 00231 return status; 00232 } 00233 00234 palStatus_t pal_CCMInit(palCCMHandle_t* ctx) 00235 { 00236 palStatus_t status = PAL_SUCCESS; 00237 PAL_VALIDATE_ARGUMENTS((NULL == ctx)) 00238 00239 status = pal_plat_CCMInit(ctx); 00240 return status; 00241 } 00242 00243 palStatus_t pal_CCMFree(palCCMHandle_t* ctx) 00244 { 00245 palStatus_t status = PAL_SUCCESS; 00246 PAL_VALIDATE_ARGUMENTS((NULL == ctx || NULLPTR == *ctx)) 00247 00248 status = pal_plat_CCMFree(ctx); 00249 return status; 00250 } 00251 00252 palStatus_t pal_CCMSetKey(palCCMHandle_t ctx, const unsigned char *key, uint32_t keybits, palCipherID_t id) 00253 { 00254 palStatus_t status = PAL_SUCCESS; 00255 PAL_VALIDATE_ARGUMENTS((NULLPTR == ctx || NULL == key)) 00256 00257 status = pal_plat_CCMSetKey(ctx, id, key, keybits); 00258 return status; 00259 } 00260 00261 palStatus_t pal_CCMDecrypt(palCCMHandle_t ctx, unsigned char* input, size_t inLen, 00262 unsigned char* iv, size_t ivLen, unsigned char* add, 00263 size_t addLen, unsigned char* tag, size_t tagLen, 00264 unsigned char* output) 00265 { 00266 palStatus_t status = PAL_SUCCESS; 00267 PAL_VALIDATE_ARGUMENTS((NULLPTR == ctx || NULL == input || NULL == iv || NULL == add || NULL == tag || NULL == output)) 00268 00269 status = pal_plat_CCMDecrypt(ctx, input, inLen, iv, ivLen, add, addLen, tag, tagLen, output); 00270 return status; 00271 } 00272 00273 palStatus_t pal_CCMEncrypt(palCCMHandle_t ctx, unsigned char* input, 00274 size_t inLen, unsigned char* iv, size_t ivLen, 00275 unsigned char* add, size_t addLen, unsigned char* output, 00276 unsigned char* tag, size_t tagLen) 00277 { 00278 palStatus_t status = PAL_SUCCESS; 00279 PAL_VALIDATE_ARGUMENTS((NULLPTR == ctx || NULL == input || NULL == iv || NULL == add || NULL == tag || NULL == output)) 00280 00281 status = pal_plat_CCMEncrypt(ctx, input, inLen, iv, ivLen, add, addLen, output, tag, tagLen); 00282 return status; 00283 } 00284 00285 palStatus_t pal_CtrDRBGInit(palCtrDrbgCtxHandle_t* ctx, const void* seed, size_t len) 00286 { 00287 palStatus_t status = PAL_SUCCESS; 00288 00289 PAL_VALIDATE_ARGUMENTS((NULL == ctx || NULL == seed)) 00290 00291 status = pal_plat_CtrDRBGInit(ctx); 00292 if (PAL_SUCCESS == status) 00293 { 00294 status = pal_plat_CtrDRBGSeed(*ctx, seed, len); 00295 if (PAL_SUCCESS != status) 00296 { 00297 palStatus_t tmpStatus = PAL_SUCCESS; 00298 tmpStatus = pal_CtrDRBGFree(ctx); 00299 if (PAL_SUCCESS != tmpStatus) 00300 { 00301 PAL_LOG_ERR("Failed to release CTR-DRBG context %" PRId32 ".", tmpStatus); 00302 } 00303 } 00304 } 00305 00306 return status; 00307 } 00308 00309 palStatus_t pal_CtrDRBGIsSeeded(palCtrDrbgCtxHandle_t ctx) 00310 { 00311 palStatus_t status = PAL_SUCCESS; 00312 00313 PAL_VALIDATE_ARGUMENTS(NULLPTR == ctx) 00314 00315 status = pal_plat_CtrDRBGIsSeeded(ctx); 00316 return status; 00317 } 00318 00319 palStatus_t pal_CtrDRBGGenerate(palCtrDrbgCtxHandle_t ctx, unsigned char* out, size_t len) 00320 { 00321 palStatus_t status = PAL_SUCCESS; 00322 00323 PAL_VALIDATE_ARGUMENTS((NULLPTR == ctx || NULL == out)) 00324 00325 status = pal_plat_CtrDRBGGenerate(ctx, out, len); 00326 return status; 00327 } 00328 00329 palStatus_t pal_CtrDRBGFree(palCtrDrbgCtxHandle_t* ctx) 00330 { 00331 palStatus_t status = PAL_SUCCESS; 00332 PAL_VALIDATE_ARGUMENTS((NULL == ctx || NULLPTR == *ctx)) 00333 00334 status = pal_plat_CtrDRBGFree(ctx); 00335 return status; 00336 } 00337 00338 palStatus_t pal_cipherCMAC(const unsigned char *key, size_t keyLenInBits, const unsigned char *input, size_t inputLenInBytes, unsigned char *output) 00339 { 00340 palStatus_t status = PAL_SUCCESS; 00341 PAL_VALIDATE_ARGUMENTS((NULL == key || NULL == input || NULL == output)) 00342 #if PAL_CMAC_SUPPORT 00343 status = pal_plat_cipherCMAC(key, keyLenInBits, input, inputLenInBytes, output); 00344 #else // no CMAC support 00345 status = PAL_ERR_NOT_SUPPORTED ; 00346 PAL_LOG_ERR("CMAC support in PAL is disabled"); 00347 #endif 00348 return status; 00349 } 00350 00351 palStatus_t pal_CMACStart(palCMACHandle_t *ctx, const unsigned char *key, size_t keyLenBits, palCipherID_t cipherID) 00352 { 00353 palStatus_t status = PAL_SUCCESS; 00354 PAL_VALIDATE_ARGUMENTS((NULLPTR == ctx || NULL == key)) 00355 #if PAL_CMAC_SUPPORT 00356 status = pal_plat_CMACStart(ctx, key, keyLenBits, cipherID); 00357 #else // no CMAC support 00358 status = PAL_ERR_NOT_SUPPORTED ; 00359 PAL_LOG_ERR("CMAC support in PAL is disabled"); 00360 #endif 00361 return status; 00362 } 00363 00364 palStatus_t pal_CMACUpdate(palCMACHandle_t ctx, const unsigned char *input, size_t inLen) 00365 { 00366 #if PAL_CMAC_SUPPORT 00367 palStatus_t status = PAL_SUCCESS; 00368 PAL_VALIDATE_ARGUMENTS((NULLPTR == ctx || NULL == input)) 00369 00370 status = pal_plat_CMACUpdate(ctx, input, inLen); 00371 #else // no CMAC support 00372 palStatus_t status = PAL_ERR_NOT_SUPPORTED ; 00373 PAL_LOG_ERR("CMAC support in PAL is disabled"); 00374 #endif 00375 return status; 00376 } 00377 00378 palStatus_t pal_CMACFinish(palCMACHandle_t *ctx, unsigned char *output, size_t* outLen) 00379 { 00380 #if PAL_CMAC_SUPPORT 00381 palStatus_t status = PAL_SUCCESS; 00382 PAL_VALIDATE_ARGUMENTS(NULLPTR == ctx || NULLPTR == *ctx || NULL == output || NULL == outLen) 00383 00384 status = pal_plat_CMACFinish(ctx, output, outLen); 00385 #else // no CMAC support 00386 palStatus_t status = PAL_ERR_NOT_SUPPORTED ; 00387 PAL_LOG_ERR("CMAC support in PAL is disabled"); 00388 #endif 00389 return status; 00390 } 00391 00392 palStatus_t pal_mdHmacSha256(const unsigned char *key, size_t keyLenInBytes, const unsigned char *input, size_t inputLenInBytes, unsigned char *output, size_t* outputLenInBytes) 00393 { 00394 palStatus_t status = PAL_SUCCESS; 00395 PAL_VALIDATE_ARGUMENTS((NULL == key || NULL == input || NULL == output)) 00396 00397 status = pal_plat_mdHmacSha256(key, keyLenInBytes, input, inputLenInBytes, output, outputLenInBytes); 00398 return status; 00399 } 00400 00401 palStatus_t pal_ECCheckKey(palCurveHandle_t grp, palECKeyHandle_t key, uint32_t type, bool *verified) 00402 { 00403 palStatus_t status = PAL_SUCCESS; 00404 PAL_VALIDATE_ARGUMENTS((NULLPTR == grp || NULLPTR == key || NULL == verified)) 00405 00406 status = pal_plat_ECCheckKey(grp, key, type, verified); 00407 return status; 00408 } 00409 00410 palStatus_t pal_ECKeyNew(palECKeyHandle_t* key) 00411 { 00412 palStatus_t status = PAL_SUCCESS; 00413 PAL_VALIDATE_ARGUMENTS((NULL == key)) 00414 00415 status = pal_plat_ECKeyNew(key); 00416 return status; 00417 } 00418 00419 palStatus_t pal_ECKeyFree(palECKeyHandle_t* key) 00420 { 00421 palStatus_t status = PAL_SUCCESS; 00422 PAL_VALIDATE_ARGUMENTS((NULL == key || NULLPTR == *key)) 00423 00424 status = pal_plat_ECKeyFree(key); 00425 return status; 00426 } 00427 00428 palStatus_t pal_parseECPrivateKeyFromDER(const unsigned char* prvDERKey, size_t keyLen, palECKeyHandle_t key) 00429 { 00430 palStatus_t status = PAL_SUCCESS; 00431 PAL_VALIDATE_ARGUMENTS((NULL == prvDERKey || NULLPTR == key)) 00432 00433 status = pal_plat_parseECPrivateKeyFromDER(prvDERKey, keyLen, key); 00434 return status; 00435 } 00436 00437 palStatus_t pal_parseECPublicKeyFromDER(const unsigned char* pubDERKey, size_t keyLen, palECKeyHandle_t key) 00438 { 00439 palStatus_t status = PAL_SUCCESS; 00440 PAL_VALIDATE_ARGUMENTS((NULL == pubDERKey || NULLPTR == key)) 00441 00442 status = pal_plat_parseECPublicKeyFromDER(pubDERKey, keyLen, key); 00443 return status; 00444 } 00445 00446 palStatus_t pal_writePrivateKeyToDer(palECKeyHandle_t key, unsigned char* derBuffer, size_t bufferSize, size_t* actualSize) 00447 { 00448 palStatus_t status = PAL_SUCCESS; 00449 PAL_VALIDATE_ARGUMENTS((NULLPTR == key || NULL == derBuffer || NULL == actualSize)) 00450 00451 status = pal_plat_writePrivateKeyToDer(key, derBuffer, bufferSize, actualSize); 00452 return status; 00453 } 00454 00455 palStatus_t pal_writePublicKeyToDer(palECKeyHandle_t key, unsigned char* derBuffer, size_t bufferSize, size_t* actualSize) 00456 { 00457 palStatus_t status = PAL_SUCCESS; 00458 PAL_VALIDATE_ARGUMENTS((NULLPTR == key || NULL == derBuffer || NULL == actualSize)) 00459 00460 status = pal_plat_writePublicKeyToDer(key, derBuffer, bufferSize, actualSize); 00461 return status; 00462 } 00463 palStatus_t pal_ECGroupInitAndLoad(palCurveHandle_t* grp, palGroupIndex_t index) 00464 { 00465 palStatus_t status = PAL_SUCCESS; 00466 PAL_VALIDATE_ARGUMENTS((NULLPTR == grp)) 00467 00468 status = pal_plat_ECGroupInitAndLoad(grp, index); 00469 return status; 00470 } 00471 00472 palStatus_t pal_ECGroupFree(palCurveHandle_t* grp) 00473 { 00474 palStatus_t status = PAL_SUCCESS; 00475 PAL_VALIDATE_ARGUMENTS((NULL == grp || NULLPTR == *grp)) 00476 00477 status = pal_plat_ECGroupFree(grp); 00478 return status; 00479 } 00480 00481 palStatus_t pal_ECKeyGenerateKey(palGroupIndex_t grpID, palECKeyHandle_t key) 00482 { 00483 palStatus_t status = PAL_SUCCESS; 00484 PAL_VALIDATE_ARGUMENTS((NULLPTR == key)) 00485 00486 status = pal_plat_ECKeyGenerateKey(grpID, key); 00487 return status; 00488 } 00489 00490 palStatus_t pal_ECKeyGetCurve(palECKeyHandle_t key, palGroupIndex_t* grpID) 00491 { 00492 palStatus_t status = PAL_SUCCESS; 00493 PAL_VALIDATE_ARGUMENTS((NULLPTR == key || NULL == grpID)) 00494 00495 status = pal_plat_ECKeyGetCurve(key, grpID); 00496 return status; 00497 } 00498 00499 palStatus_t pal_x509CSRInit(palx509CSRHandle_t *x509CSR) 00500 { 00501 #if (PAL_ENABLE_X509 == 1) 00502 palStatus_t status = PAL_SUCCESS; 00503 PAL_VALIDATE_ARGUMENTS((NULL == x509CSR)) 00504 00505 status = pal_plat_x509CSRInit(x509CSR); 00506 return status; 00507 #else 00508 return PAL_ERR_NOT_SUPPORTED ; 00509 #endif 00510 } 00511 00512 palStatus_t pal_x509CSRSetSubject(palx509CSRHandle_t x509CSR, const char* subjectName) 00513 { 00514 #if (PAL_ENABLE_X509 == 1) 00515 palStatus_t status = PAL_SUCCESS; 00516 PAL_VALIDATE_ARGUMENTS((NULLPTR == x509CSR || NULL == subjectName)) 00517 00518 status = pal_plat_x509CSRSetSubject(x509CSR, subjectName); 00519 return status; 00520 #else 00521 return PAL_ERR_NOT_SUPPORTED ; 00522 #endif 00523 } 00524 00525 palStatus_t pal_x509CSRSetKey(palx509CSRHandle_t x509CSR, palECKeyHandle_t pubKey, palECKeyHandle_t prvKey) 00526 { 00527 #if (PAL_ENABLE_X509 == 1) 00528 palStatus_t status = PAL_SUCCESS; 00529 PAL_VALIDATE_ARGUMENTS((NULLPTR == x509CSR || NULLPTR == pubKey)) 00530 00531 status = pal_plat_x509CSRSetKey(x509CSR, pubKey, prvKey); 00532 return status; 00533 #else 00534 return PAL_ERR_NOT_SUPPORTED ; 00535 #endif 00536 } 00537 00538 palStatus_t pal_x509CSRSetMD(palx509CSRHandle_t x509CSR, palMDType_t mdType) 00539 { 00540 #if (PAL_ENABLE_X509 == 1) 00541 palStatus_t status = PAL_SUCCESS; 00542 PAL_VALIDATE_ARGUMENTS((NULLPTR == x509CSR)) 00543 00544 status = pal_plat_x509CSRSetMD(x509CSR, mdType); 00545 return status; 00546 #else 00547 return PAL_ERR_NOT_SUPPORTED ; 00548 #endif 00549 } 00550 00551 palStatus_t pal_x509CSRSetKeyUsage(palx509CSRHandle_t x509CSR, uint32_t keyUsage) 00552 { 00553 #if (PAL_ENABLE_X509 == 1) 00554 palStatus_t status = PAL_SUCCESS; 00555 PAL_VALIDATE_ARGUMENTS((NULLPTR == x509CSR)) 00556 00557 status = pal_plat_x509CSRSetKeyUsage(x509CSR, keyUsage); 00558 return status; 00559 #else 00560 return PAL_ERR_NOT_SUPPORTED ; 00561 #endif 00562 } 00563 00564 palStatus_t pal_x509CSRSetExtendedKeyUsage(palx509CSRHandle_t x509CSR, uint32_t extKeyUsage) 00565 { 00566 #if (PAL_ENABLE_X509 == 1) 00567 palStatus_t status = PAL_SUCCESS; 00568 PAL_VALIDATE_ARGUMENTS((NULLPTR == x509CSR)) 00569 00570 status = pal_plat_x509CSRSetExtendedKeyUsage(x509CSR, extKeyUsage); 00571 return status; 00572 #else 00573 return PAL_ERR_NOT_SUPPORTED ; 00574 #endif 00575 } 00576 00577 palStatus_t pal_x509CSRSetExtension(palx509CSRHandle_t x509CSR,const char* oid, size_t oidLen, const unsigned char* value, size_t valueLen) 00578 { 00579 #if (PAL_ENABLE_X509 == 1) 00580 palStatus_t status = PAL_SUCCESS; 00581 PAL_VALIDATE_ARGUMENTS((NULLPTR == x509CSR || NULL == oid || NULL == value)) 00582 00583 status = pal_plat_x509CSRSetExtension(x509CSR, oid, oidLen, value, valueLen); 00584 return status; 00585 #else 00586 return PAL_ERR_NOT_SUPPORTED ; 00587 #endif 00588 } 00589 00590 palStatus_t pal_x509CSRWriteDER(palx509CSRHandle_t x509CSR, unsigned char* derBuf, size_t derBufLen, size_t* actualDerLen) 00591 { 00592 #if (PAL_ENABLE_X509 == 1) 00593 palStatus_t status = PAL_SUCCESS; 00594 PAL_VALIDATE_ARGUMENTS((NULLPTR == x509CSR || NULL == derBuf)) 00595 00596 status = pal_plat_x509CSRWriteDER(x509CSR, derBuf, derBufLen, actualDerLen); 00597 return status; 00598 #else 00599 return PAL_ERR_NOT_SUPPORTED ; 00600 #endif 00601 } 00602 00603 palStatus_t pal_x509CSRFromCertWriteDER(palX509Handle_t x509Cert, palx509CSRHandle_t x509CSR, unsigned char* derBuf, size_t derBufLen, size_t* actualDerBufLen) 00604 { 00605 #if (PAL_ENABLE_X509 == 1) 00606 palStatus_t status = PAL_SUCCESS; 00607 PAL_VALIDATE_ARGUMENTS((0 == x509Cert || 0 == x509CSR || NULL == derBuf || NULL == actualDerBufLen)) 00608 00609 status = pal_plat_x509CSRFromCertWriteDER(x509Cert, x509CSR, derBuf, derBufLen, actualDerBufLen); 00610 return status; 00611 #else 00612 return PAL_ERR_NOT_SUPPORTED ; 00613 #endif 00614 } 00615 00616 palStatus_t pal_x509CSRFree(palx509CSRHandle_t *x509CSR) 00617 { 00618 #if (PAL_ENABLE_X509 == 1) 00619 palStatus_t status = PAL_SUCCESS; 00620 PAL_VALIDATE_ARGUMENTS((NULL == x509CSR || NULLPTR == *x509CSR)) 00621 00622 status = pal_plat_x509CSRFree(x509CSR); 00623 return status; 00624 #else 00625 return PAL_ERR_NOT_SUPPORTED ; 00626 #endif 00627 } 00628 00629 palStatus_t pal_ECDHComputeKey(const palCurveHandle_t grp, const palECKeyHandle_t peerPublicKey, 00630 const palECKeyHandle_t privateKey, palECKeyHandle_t outKey) 00631 { 00632 palStatus_t status = PAL_SUCCESS; 00633 PAL_VALIDATE_ARGUMENTS((NULLPTR == grp || NULLPTR == peerPublicKey || NULLPTR == privateKey || NULLPTR == outKey)) 00634 00635 status = pal_plat_ECDHComputeKey(grp, peerPublicKey, privateKey, outKey); 00636 return status; 00637 } 00638 00639 palStatus_t pal_ECDSASign(palCurveHandle_t grp, palMDType_t mdType, palECKeyHandle_t prvKey, unsigned char* dgst, 00640 uint32_t dgstLen, unsigned char *sig, size_t *sigLen) 00641 { 00642 palStatus_t status = PAL_SUCCESS; 00643 PAL_VALIDATE_ARGUMENTS((NULLPTR == grp || NULLPTR == prvKey || NULL == dgst || NULL == sig || NULL == sigLen)) 00644 00645 status = pal_plat_ECDSASign(grp, mdType, prvKey, dgst, dgstLen, sig, sigLen); 00646 return status; 00647 } 00648 00649 palStatus_t pal_ECDSAVerify(palECKeyHandle_t pubKey, unsigned char* dgst, uint32_t dgstLen, 00650 unsigned char* sig, size_t sigLen, bool* verified) 00651 { 00652 palStatus_t status = PAL_SUCCESS; 00653 PAL_VALIDATE_ARGUMENTS((NULLPTR == pubKey || NULL == dgst || NULL == sig || NULL == verified)) 00654 00655 status = pal_plat_ECDSAVerify(pubKey, dgst, dgstLen, sig, sigLen, verified); 00656 return status; 00657 } 00658 00659 palStatus_t pal_x509CertGetHTBS(palX509Handle_t x509Cert, palMDType_t hash_type, unsigned char *output, size_t outLenBytes, size_t* actualOutLenBytes) 00660 { 00661 palStatus_t status = PAL_SUCCESS; 00662 PAL_VALIDATE_ARGUMENTS((NULL == output || NULL == actualOutLenBytes || NULLPTR == x509Cert)); 00663 00664 status = pal_plat_x509CertGetHTBS(x509Cert, hash_type, output, outLenBytes, actualOutLenBytes); 00665 return status; 00666 }
Generated on Tue Jul 12 2022 20:21:01 by
