Simulated product dispenser

Dependencies:   HTS221

Fork of mbed-cloud-workshop-connect-HTS221 by Jim Carver

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers pal_Crypto.c Source File

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