Sergey Pastor / 1

Dependents:   Nucleo

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers crypto.h Source File

crypto.h

Go to the documentation of this file.
00001 /**
00002  * @file crypto.h
00003  * @brief General definitions for cryptographic algorithms
00004  *
00005  * @section License
00006  *
00007  * Copyright (C) 2010-2017 Oryx Embedded SARL. All rights reserved.
00008  *
00009  * This file is part of CycloneCrypto Open.
00010  *
00011  * This program is free software; you can redistribute it and/or
00012  * modify it under the terms of the GNU General Public License
00013  * as published by the Free Software Foundation; either version 2
00014  * of the License, or (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software Foundation,
00023  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00024  *
00025  * @author Oryx Embedded SARL (www.oryx-embedded.com)
00026  * @version 1.7.6
00027  **/
00028 
00029 #ifndef _CRYPTO_H
00030 #define _CRYPTO_H
00031 
00032 //Dependencies
00033 #include "os_port.h"
00034 #include "crypto_config.h"
00035 #include "cpu_endian.h"
00036 #include "error.h"
00037 
00038 //Multiple precision integer support
00039 #ifndef MPI_SUPPORT
00040    #define MPI_SUPPORT ENABLED
00041 #elif (MPI_SUPPORT != ENABLED && MPI_SUPPORT != DISABLED)
00042    #error MPI_SUPPORT parameter is not valid
00043 #endif
00044 
00045 //Assembly optimizations for time-critical routines
00046 #ifndef MPI_ASM_SUPPORT
00047    #define MPI_ASM_SUPPORT DISABLED
00048 #elif (MPI_ASM_SUPPORT != ENABLED && MPI_ASM_SUPPORT != DISABLED)
00049    #error MPI_ASM_SUPPORT parameter is not valid
00050 #endif
00051 
00052 //Base64 encoding support
00053 #ifndef BASE64_SUPPORT
00054    #define BASE64_SUPPORT ENABLED
00055 #elif (BASE64_SUPPORT != ENABLED && BASE64_SUPPORT != DISABLED)
00056    #error BASE64_SUPPORT parameter is not valid
00057 #endif
00058 
00059 //MD2 hash support
00060 #ifndef MD2_SUPPORT
00061    #define MD2_SUPPORT ENABLED
00062 #elif (MD2_SUPPORT != ENABLED && MD2_SUPPORT != DISABLED)
00063    #error MD2_SUPPORT parameter is not valid
00064 #endif
00065 
00066 //MD4 hash support
00067 #ifndef MD4_SUPPORT
00068    #define MD4_SUPPORT ENABLED
00069 #elif (MD4_SUPPORT != ENABLED && MD4_SUPPORT != DISABLED)
00070    #error MD4_SUPPORT parameter is not valid
00071 #endif
00072 
00073 //MD5 hash support
00074 #ifndef MD5_SUPPORT
00075    #define MD5_SUPPORT ENABLED
00076 #elif (MD5_SUPPORT != ENABLED && MD5_SUPPORT != DISABLED)
00077    #error MD5_SUPPORT parameter is not valid
00078 #endif
00079 
00080 //RIPEMD-128 hash support
00081 #ifndef RIPEMD128_SUPPORT
00082    #define RIPEMD128_SUPPORT ENABLED
00083 #elif (RIPEMD128_SUPPORT != ENABLED && RIPEMD128_SUPPORT != DISABLED)
00084    #error RIPEMD128_SUPPORT parameter is not valid
00085 #endif
00086 
00087 //RIPEMD-160 hash support
00088 #ifndef RIPEMD160_SUPPORT
00089    #define RIPEMD160_SUPPORT ENABLED
00090 #elif (RIPEMD160_SUPPORT != ENABLED && RIPEMD160_SUPPORT != DISABLED)
00091    #error RIPEMD160_SUPPORT parameter is not valid
00092 #endif
00093 
00094 //SHA-1 hash support
00095 #ifndef SHA1_SUPPORT
00096    #define SHA1_SUPPORT ENABLED
00097 #elif (SHA1_SUPPORT != ENABLED && SHA1_SUPPORT != DISABLED)
00098    #error SHA1_SUPPORT parameter is not valid
00099 #endif
00100 
00101 //SHA-224 hash support
00102 #ifndef SHA224_SUPPORT
00103    #define SHA224_SUPPORT ENABLED
00104 #elif (SHA224_SUPPORT != ENABLED && SHA224_SUPPORT != DISABLED)
00105    #error SHA224_SUPPORT parameter is not valid
00106 #endif
00107 
00108 //SHA-256 hash support
00109 #ifndef SHA256_SUPPORT
00110    #define SHA256_SUPPORT ENABLED
00111 #elif (SHA256_SUPPORT != ENABLED && SHA256_SUPPORT != DISABLED)
00112    #error SHA256_SUPPORT parameter is not valid
00113 #endif
00114 
00115 //SHA-384 hash support
00116 #ifndef SHA384_SUPPORT
00117    #define SHA384_SUPPORT ENABLED
00118 #elif (SHA384_SUPPORT != ENABLED && SHA384_SUPPORT != DISABLED)
00119    #error SHA384_SUPPORT parameter is not valid
00120 #endif
00121 
00122 //SHA-512 hash support
00123 #ifndef SHA512_SUPPORT
00124    #define SHA512_SUPPORT ENABLED
00125 #elif (SHA512_SUPPORT != ENABLED && SHA512_SUPPORT != DISABLED)
00126    #error SHA512_SUPPORT parameter is not valid
00127 #endif
00128 
00129 //SHA-512/224 hash support
00130 #ifndef SHA512_224_SUPPORT
00131    #define SHA512_224_SUPPORT ENABLED
00132 #elif (SHA512_224_SUPPORT != ENABLED && SHA512_224_SUPPORT != DISABLED)
00133    #error SHA512_224_SUPPORT parameter is not valid
00134 #endif
00135 
00136 //SHA-512/256 hash support
00137 #ifndef SHA512_256_SUPPORT
00138    #define SHA512_256_SUPPORT ENABLED
00139 #elif (SHA512_256_SUPPORT != ENABLED && SHA512_256_SUPPORT != DISABLED)
00140    #error SHA512_256_SUPPORT parameter is not valid
00141 #endif
00142 
00143 //SHA3-224 hash support
00144 #ifndef SHA3_224_SUPPORT
00145    #define SHA3_224_SUPPORT DISABLED
00146 #elif (SHA3_224_SUPPORT != ENABLED && SHA3_224_SUPPORT != DISABLED)
00147    #error SHA3_224_SUPPORT parameter is not valid
00148 #endif
00149 
00150 //SHA3-256 hash support
00151 #ifndef SHA3_256_SUPPORT
00152    #define SHA3_256_SUPPORT DISABLED
00153 #elif (SHA3_256_SUPPORT != ENABLED && SHA3_256_SUPPORT != DISABLED)
00154    #error SHA3_256_SUPPORT parameter is not valid
00155 #endif
00156 
00157 //SHA3-384 hash support
00158 #ifndef SHA3_384_SUPPORT
00159    #define SHA3_384_SUPPORT DISABLED
00160 #elif (SHA3_384_SUPPORT != ENABLED && SHA3_384_SUPPORT != DISABLED)
00161    #error SHA3_384_SUPPORT parameter is not valid
00162 #endif
00163 
00164 //SHA3-512 hash support
00165 #ifndef SHA3_512_SUPPORT
00166    #define SHA3_512_SUPPORT DISABLED
00167 #elif (SHA3_512_SUPPORT != ENABLED && SHA3_512_SUPPORT != DISABLED)
00168    #error SHA3_512_SUPPORT parameter is not valid
00169 #endif
00170 
00171 //Keccak support
00172 #ifndef KECCAK_SUPPORT
00173    #define KECCAK_SUPPORT DISABLED
00174 #elif (KECCAK_SUPPORT != ENABLED && KECCAK_SUPPORT != DISABLED)
00175    #error KECCAK_SUPPORT parameter is not valid
00176 #endif
00177 
00178 //Tiger hash support
00179 #ifndef TIGER_SUPPORT
00180    #define TIGER_SUPPORT ENABLED
00181 #elif (TIGER_SUPPORT != ENABLED && TIGER_SUPPORT != DISABLED)
00182    #error TIGER_SUPPORT parameter is not valid
00183 #endif
00184 
00185 //Whirlpool hash support
00186 #ifndef WHIRLPOOL_SUPPORT
00187    #define WHIRLPOOL_SUPPORT ENABLED
00188 #elif (WHIRLPOOL_SUPPORT != ENABLED && WHIRLPOOL_SUPPORT != DISABLED)
00189    #error WHIRLPOOL_SUPPORT parameter is not valid
00190 #endif
00191 
00192 //HMAC support
00193 #ifndef HMAC_SUPPORT
00194    #define HMAC_SUPPORT ENABLED
00195 #elif (HMAC_SUPPORT != ENABLED && HMAC_SUPPORT != DISABLED)
00196    #error HMAC_SUPPORT parameter is not valid
00197 #endif
00198 
00199 //RC4 encryption support
00200 #ifndef RC4_SUPPORT
00201    #define RC4_SUPPORT ENABLED
00202 #elif (RC4_SUPPORT != ENABLED && RC4_SUPPORT != DISABLED)
00203    #error RC4_SUPPORT parameter is not valid
00204 #endif
00205 
00206 //RC6 encryption support
00207 #ifndef RC6_SUPPORT
00208    #define RC6_SUPPORT ENABLED
00209 #elif (RC6_SUPPORT != ENABLED && RC6_SUPPORT != DISABLED)
00210    #error RC6_SUPPORT parameter is not valid
00211 #endif
00212 
00213 //IDEA encryption support
00214 #ifndef IDEA_SUPPORT
00215    #define IDEA_SUPPORT ENABLED
00216 #elif (IDEA_SUPPORT != ENABLED && IDEA_SUPPORT != DISABLED)
00217    #error IDEA_SUPPORT parameter is not valid
00218 #endif
00219 
00220 //DES encryption support
00221 #ifndef DES_SUPPORT
00222    #define DES_SUPPORT ENABLED
00223 #elif (DES_SUPPORT != ENABLED && DES_SUPPORT != DISABLED)
00224    #error DES_SUPPORT parameter is not valid
00225 #endif
00226 
00227 //Triple DES encryption support
00228 #ifndef DES3_SUPPORT
00229    #define DES3_SUPPORT ENABLED
00230 #elif (DES3_SUPPORT != ENABLED && DES3_SUPPORT != DISABLED)
00231    #error DES3_SUPPORT parameter is not valid
00232 #endif
00233 
00234 //AES encryption support
00235 #ifndef AES_SUPPORT
00236    #define AES_SUPPORT ENABLED
00237 #elif (AES_SUPPORT != ENABLED && AES_SUPPORT != DISABLED)
00238    #error AES_SUPPORT parameter is not valid
00239 #endif
00240 
00241 //Camellia encryption support
00242 #ifndef CAMELLIA_SUPPORT
00243    #define CAMELLIA_SUPPORT ENABLED
00244 #elif (CAMELLIA_SUPPORT != ENABLED && CAMELLIA_SUPPORT != DISABLED)
00245    #error CAMELLIA_SUPPORT parameter is not valid
00246 #endif
00247 
00248 //SEED encryption support
00249 #ifndef SEED_SUPPORT
00250    #define SEED_SUPPORT ENABLED
00251 #elif (SEED_SUPPORT != ENABLED && SEED_SUPPORT != DISABLED)
00252    #error SEED_SUPPORT parameter is not valid
00253 #endif
00254 
00255 //ARIA encryption support
00256 #ifndef ARIA_SUPPORT
00257    #define ARIA_SUPPORT ENABLED
00258 #elif (ARIA_SUPPORT != ENABLED && ARIA_SUPPORT != DISABLED)
00259    #error ARIA_SUPPORT parameter is not valid
00260 #endif
00261 
00262 //ECB mode support
00263 #ifndef ECB_SUPPORT
00264    #define ECB_SUPPORT ENABLED
00265 #elif (ECB_SUPPORT != ENABLED && ECB_SUPPORT != DISABLED)
00266    #error ECB_SUPPORT parameter is not valid
00267 #endif
00268 
00269 //CBC mode support
00270 #ifndef CBC_SUPPORT
00271    #define CBC_SUPPORT ENABLED
00272 #elif (CBC_SUPPORT != ENABLED && CBC_SUPPORT != DISABLED)
00273    #error CBC_SUPPORT parameter is not valid
00274 #endif
00275 
00276 //CFB mode support
00277 #ifndef CFB_SUPPORT
00278    #define CFB_SUPPORT ENABLED
00279 #elif (CFB_SUPPORT != ENABLED && CFB_SUPPORT != DISABLED)
00280    #error CFB_SUPPORT parameter is not valid
00281 #endif
00282 
00283 //OFB mode support
00284 #ifndef OFB_SUPPORT
00285    #define OFB_SUPPORT ENABLED
00286 #elif (OFB_SUPPORT != ENABLED && OFB_SUPPORT != DISABLED)
00287    #error OFB_SUPPORT parameter is not valid
00288 #endif
00289 
00290 //CTR mode support
00291 #ifndef CTR_SUPPORT
00292    #define CTR_SUPPORT ENABLED
00293 #elif (CTR_SUPPORT != ENABLED && CTR_SUPPORT != DISABLED)
00294    #error CTR_SUPPORT parameter is not valid
00295 #endif
00296 
00297 //CCM mode support
00298 #ifndef CCM_SUPPORT
00299    #define CCM_SUPPORT ENABLED
00300 #elif (CCM_SUPPORT != ENABLED && CCM_SUPPORT != DISABLED)
00301    #error CCM_SUPPORT parameter is not valid
00302 #endif
00303 
00304 //GCM mode support
00305 #ifndef GCM_SUPPORT
00306    #define GCM_SUPPORT ENABLED
00307 #elif (GCM_SUPPORT != ENABLED && GCM_SUPPORT != DISABLED)
00308    #error GCM_SUPPORT parameter is not valid
00309 #endif
00310 
00311 //Chacha support
00312 #ifndef CHACHA_SUPPORT
00313    #define CHACHA_SUPPORT DISABLED
00314 #elif (CHACHA_SUPPORT != ENABLED && CHACHA_SUPPORT != DISABLED)
00315    #error CHACHA_SUPPORT parameter is not valid
00316 #endif
00317 
00318 //Poly1305 support
00319 #ifndef POLY1305_SUPPORT
00320    #define POLY1305_SUPPORT DISABLED
00321 #elif (POLY1305_SUPPORT != ENABLED && POLY1305_SUPPORT != DISABLED)
00322    #error POLY1305_SUPPORT parameter is not valid
00323 #endif
00324 
00325 //Chacha20Poly1305 support
00326 #ifndef CHACHA20_POLY1305_SUPPORT
00327    #define CHACHA20_POLY1305_SUPPORT DISABLED
00328 #elif (CHACHA20_POLY1305_SUPPORT != ENABLED && CHACHA20_POLY1305_SUPPORT != DISABLED)
00329    #error CHACHA20_POLY1305_SUPPORT parameter is not valid
00330 #endif
00331 
00332 //Diffie-Hellman support
00333 #ifndef DH_SUPPORT
00334    #define DH_SUPPORT ENABLED
00335 #elif (DH_SUPPORT != ENABLED && DH_SUPPORT != DISABLED)
00336    #error DH_SUPPORT parameter is not valid
00337 #endif
00338 
00339 //RSA support
00340 #ifndef RSA_SUPPORT
00341    #define RSA_SUPPORT ENABLED
00342 #elif (RSA_SUPPORT != ENABLED && RSA_SUPPORT != DISABLED)
00343    #error RSA_SUPPORT parameter is not valid
00344 #endif
00345 
00346 //DSA support
00347 #ifndef DSA_SUPPORT
00348    #define DSA_SUPPORT ENABLED
00349 #elif (DSA_SUPPORT != ENABLED && DSA_SUPPORT != DISABLED)
00350    #error DSA_SUPPORT parameter is not valid
00351 #endif
00352 
00353 //Elliptic curve cryptography support
00354 #ifndef EC_SUPPORT
00355    #define EC_SUPPORT ENABLED
00356 #elif (EC_SUPPORT != ENABLED && EC_SUPPORT != DISABLED)
00357    #error EC_SUPPORT parameter is not valid
00358 #endif
00359 
00360 //ECDH support
00361 #ifndef ECDH_SUPPORT
00362    #define ECDH_SUPPORT ENABLED
00363 #elif (ECDH_SUPPORT != ENABLED && ECDH_SUPPORT != DISABLED)
00364    #error ECDH_SUPPORT parameter is not valid
00365 #endif
00366 
00367 //ECDSA support
00368 #ifndef ECDSA_SUPPORT
00369    #define ECDSA_SUPPORT ENABLED
00370 #elif (ECDSA_SUPPORT != ENABLED && ECDSA_SUPPORT != DISABLED)
00371    #error ECDSA_SUPPORT parameter is not valid
00372 #endif
00373 
00374 //PKCS #5 support
00375 #ifndef PKCS5_SUPPORT
00376    #define PKCS5_SUPPORT ENABLED
00377 #elif (PKCS5_SUPPORT != ENABLED && PKCS5_SUPPORT != DISABLED)
00378    #error PKCS5_SUPPORT parameter is not valid
00379 #endif
00380 
00381 //Yarrow PRNG support
00382 #ifndef YARROW_SUPPORT
00383    #define YARROW_SUPPORT ENABLED
00384 #elif (YARROW_SUPPORT != ENABLED && YARROW_SUPPORT != DISABLED)
00385    #error YARROW_SUPPORT parameter is not valid
00386 #endif
00387 
00388 //Object identifier support
00389 #ifndef OID_SUPPORT
00390    #define OID_SUPPORT ENABLED
00391 #elif (OID_SUPPORT != ENABLED && OID_SUPPORT != DISABLED)
00392    #error OID_SUPPORT parameter is not valid
00393 #endif
00394 
00395 //ASN.1 syntax support
00396 #ifndef ASN1_SUPPORT
00397    #define ASN1_SUPPORT ENABLED
00398 #elif (ASN1_SUPPORT != ENABLED && ASN1_SUPPORT != DISABLED)
00399    #error ASN1_SUPPORT parameter is not valid
00400 #endif
00401 
00402 //PEM file support
00403 #ifndef PEM_SUPPORT
00404    #define PEM_SUPPORT ENABLED
00405 #elif (PEM_SUPPORT != ENABLED && PEM_SUPPORT != DISABLED)
00406    #error PEM_SUPPORT parameter is not valid
00407 #endif
00408 
00409 //X.509 certificate support
00410 #ifndef X509_SUPPORT
00411    #define X509_SUPPORT ENABLED
00412 #elif (X509_SUPPORT != ENABLED && X509_SUPPORT != DISABLED)
00413    #error X509_SUPPORT parameter is not valid
00414 #endif
00415 
00416 //Memory allocation
00417 #ifndef cryptoAllocMem
00418    #define cryptoAllocMem(size) osAllocMem(size)
00419 #endif
00420 
00421 //Memory deallocation
00422 #ifndef cryptoFreeMem
00423    #define cryptoFreeMem(p) osFreeMem(p)
00424 #endif
00425 
00426 //Maximum context size (hash algorithms)
00427 #if (SHA3_512_SUPPORT == ENABLED)
00428    #define MAX_HASH_CONTEXT_SIZE sizeof(Sha3_512Context)
00429 #elif (SHA3_384_SUPPORT == ENABLED)
00430    #define MAX_HASH_CONTEXT_SIZE sizeof(Sha3_384Context)
00431 #elif (SHA3_256_SUPPORT == ENABLED)
00432    #define MAX_HASH_CONTEXT_SIZE sizeof(Sha3_256Context)
00433 #elif (SHA3_224_SUPPORT == ENABLED)
00434    #define MAX_HASH_CONTEXT_SIZE sizeof(Sha3_224Context)
00435 #elif (WHIRLPOOL_SUPPORT == ENABLED)
00436    #define MAX_HASH_CONTEXT_SIZE sizeof(WhirlpoolContext)
00437 #elif (SHA512_SUPPORT == ENABLED)
00438    #define MAX_HASH_CONTEXT_SIZE sizeof(Sha512Context)
00439 #elif (SHA384_SUPPORT == ENABLED)
00440    #define MAX_HASH_CONTEXT_SIZE sizeof(Sha384Context)
00441 #elif (SHA512_256_SUPPORT == ENABLED)
00442    #define MAX_HASH_CONTEXT_SIZE sizeof(Sha512_256Context)
00443 #elif (SHA512_224_SUPPORT == ENABLED)
00444    #define MAX_HASH_CONTEXT_SIZE sizeof(Sha512_224Context)
00445 #elif (SHA256_SUPPORT == ENABLED)
00446    #define MAX_HASH_CONTEXT_SIZE sizeof(Sha256Context)
00447 #elif (SHA224_SUPPORT == ENABLED)
00448    #define MAX_HASH_CONTEXT_SIZE sizeof(Sha224Context)
00449 #elif (TIGER_SUPPORT == ENABLED)
00450    #define MAX_HASH_CONTEXT_SIZE sizeof(TigerContext)
00451 #elif (SHA1_SUPPORT == ENABLED)
00452    #define MAX_HASH_CONTEXT_SIZE sizeof(Sha1Context)
00453 #elif (RIPEMD160_SUPPORT == ENABLED)
00454    #define MAX_HASH_CONTEXT_SIZE sizeof(Ripemd160Context)
00455 #elif (RIPEMD128_SUPPORT == ENABLED)
00456    #define MAX_HASH_CONTEXT_SIZE sizeof(Ripemd128Context)
00457 #elif (MD5_SUPPORT == ENABLED)
00458    #define MAX_HASH_CONTEXT_SIZE sizeof(Md5Context)
00459 #elif (MD4_SUPPORT == ENABLED)
00460    #define MAX_HASH_CONTEXT_SIZE sizeof(Md4Context)
00461 #elif (MD2_SUPPORT == ENABLED)
00462    #define MAX_HASH_CONTEXT_SIZE sizeof(Md2Context)
00463 #endif
00464 
00465 //Maximum block size (hash algorithms)
00466 #if (SHA3_224_SUPPORT == ENABLED)
00467    #define MAX_HASH_BLOCK_SIZE SHA3_224_BLOCK_SIZE
00468 #elif (SHA3_256_SUPPORT == ENABLED)
00469    #define MAX_HASH_BLOCK_SIZE SHA3_256_BLOCK_SIZE
00470 #elif (SHA512_SUPPORT == ENABLED)
00471    #define MAX_HASH_BLOCK_SIZE SHA512_BLOCK_SIZE
00472 #elif (SHA384_SUPPORT == ENABLED)
00473    #define MAX_HASH_BLOCK_SIZE SHA384_BLOCK_SIZE
00474 #elif (SHA512_256_SUPPORT == ENABLED)
00475    #define MAX_HASH_BLOCK_SIZE SHA512_256_BLOCK_SIZE
00476 #elif (SHA512_224_SUPPORT == ENABLED)
00477    #define MAX_HASH_BLOCK_SIZE SHA512_224_BLOCK_SIZE
00478 #elif (SHA3_384_SUPPORT == ENABLED)
00479    #define MAX_HASH_BLOCK_SIZE SHA3_384_BLOCK_SIZE
00480 #elif (SHA3_512_SUPPORT == ENABLED)
00481    #define MAX_HASH_BLOCK_SIZE SHA3_512_BLOCK_SIZE
00482 #elif (SHA256_SUPPORT == ENABLED)
00483    #define MAX_HASH_BLOCK_SIZE SHA256_BLOCK_SIZE
00484 #elif (SHA224_SUPPORT == ENABLED)
00485    #define MAX_HASH_BLOCK_SIZE SHA224_BLOCK_SIZE
00486 #elif (SHA1_SUPPORT == ENABLED)
00487    #define MAX_HASH_BLOCK_SIZE SHA1_BLOCK_SIZE
00488 #elif (WHIRLPOOL_SUPPORT == ENABLED)
00489    #define MAX_HASH_BLOCK_SIZE WHIRLPOOL_BLOCK_SIZE
00490 #elif (TIGER_SUPPORT == ENABLED)
00491    #define MAX_HASH_BLOCK_SIZE TIGER_BLOCK_SIZE
00492 #elif (RIPEMD160_SUPPORT == ENABLED)
00493    #define MAX_HASH_BLOCK_SIZE RIPEMD160_BLOCK_SIZE
00494 #elif (RIPEMD128_SUPPORT == ENABLED)
00495    #define MAX_HASH_BLOCK_SIZE RIPEMD128_BLOCK_SIZE
00496 #elif (MD5_SUPPORT == ENABLED)
00497    #define MAX_HASH_BLOCK_SIZE MD5_BLOCK_SIZE
00498 #elif (MD4_SUPPORT == ENABLED)
00499    #define MAX_HASH_BLOCK_SIZE MD4_BLOCK_SIZE
00500 #elif (MD2_SUPPORT == ENABLED)
00501    #define MAX_HASH_BLOCK_SIZE MD2_BLOCK_SIZE
00502 #endif
00503 
00504 //Maximum digest size (hash algorithms)
00505 #if (WHIRLPOOL_SUPPORT == ENABLED)
00506    #define MAX_HASH_DIGEST_SIZE WHIRLPOOL_DIGEST_SIZE
00507 #elif (SHA3_512_SUPPORT == ENABLED)
00508    #define MAX_HASH_DIGEST_SIZE SHA3_512_DIGEST_SIZE
00509 #elif (SHA512_SUPPORT == ENABLED)
00510    #define MAX_HASH_DIGEST_SIZE SHA512_DIGEST_SIZE
00511 #elif (SHA3_384_SUPPORT == ENABLED)
00512    #define MAX_HASH_DIGEST_SIZE SHA3_384_DIGEST_SIZE
00513 #elif (SHA384_SUPPORT == ENABLED)
00514    #define MAX_HASH_DIGEST_SIZE SHA384_DIGEST_SIZE
00515 #elif (SHA3_256_SUPPORT == ENABLED)
00516    #define MAX_HASH_DIGEST_SIZE SHA3_256_DIGEST_SIZE
00517 #elif (SHA512_256_SUPPORT == ENABLED)
00518    #define MAX_HASH_DIGEST_SIZE SHA512_256_DIGEST_SIZE
00519 #elif (SHA256_SUPPORT == ENABLED)
00520    #define MAX_HASH_DIGEST_SIZE SHA256_DIGEST_SIZE
00521 #elif (SHA3_224_SUPPORT == ENABLED)
00522    #define MAX_HASH_DIGEST_SIZE SHA3_224_DIGEST_SIZE
00523 #elif (SHA512_224_SUPPORT == ENABLED)
00524    #define MAX_HASH_DIGEST_SIZE SHA512_224_DIGEST_SIZE
00525 #elif (SHA224_SUPPORT == ENABLED)
00526    #define MAX_HASH_DIGEST_SIZE SHA224_DIGEST_SIZE
00527 #elif (TIGER_SUPPORT == ENABLED)
00528    #define MAX_HASH_DIGEST_SIZE TIGER_DIGEST_SIZE
00529 #elif (SHA1_SUPPORT == ENABLED)
00530    #define MAX_HASH_DIGEST_SIZE SHA1_DIGEST_SIZE
00531 #elif (RIPEMD160_SUPPORT == ENABLED)
00532    #define MAX_HASH_DIGEST_SIZE RIPEMD160_DIGEST_SIZE
00533 #elif (RIPEMD128_SUPPORT == ENABLED)
00534    #define MAX_HASH_DIGEST_SIZE RIPEMD128_DIGEST_SIZE
00535 #elif (MD5_SUPPORT == ENABLED)
00536    #define MAX_HASH_DIGEST_SIZE MD5_DIGEST_SIZE
00537 #elif (MD4_SUPPORT == ENABLED)
00538    #define MAX_HASH_DIGEST_SIZE MD4_DIGEST_SIZE
00539 #elif (MD2_SUPPORT == ENABLED)
00540    #define MAX_HASH_DIGEST_SIZE MD2_DIGEST_SIZE
00541 #endif
00542 
00543 //Maximum context size (cipher algorithms)
00544 #if (ARIA_SUPPORT == ENABLED)
00545    #define MAX_CIPHER_CONTEXT_SIZE sizeof(AriaContext)
00546 #elif (AES_SUPPORT == ENABLED)
00547    #define MAX_CIPHER_CONTEXT_SIZE sizeof(AesContext)
00548 #elif (DES3_SUPPORT == ENABLED)
00549    #define MAX_CIPHER_CONTEXT_SIZE sizeof(Des3Context)
00550 #elif (CAMELLIA_SUPPORT == ENABLED)
00551    #define MAX_CIPHER_CONTEXT_SIZE sizeof(CamelliaContext)
00552 #elif (RC4_SUPPORT == ENABLED)
00553    #define MAX_CIPHER_CONTEXT_SIZE sizeof(Rc4Context)
00554 #elif (RC6_SUPPORT == ENABLED)
00555    #define MAX_CIPHER_CONTEXT_SIZE sizeof(Rc6Context)
00556 #elif (IDEA_SUPPORT == ENABLED)
00557    #define MAX_CIPHER_CONTEXT_SIZE sizeof(IdeaContext)
00558 #elif (DES_SUPPORT == ENABLED)
00559    #define MAX_CIPHER_CONTEXT_SIZE sizeof(DesContext)
00560 #elif (SEED_SUPPORT == ENABLED)
00561    #define MAX_CIPHER_CONTEXT_SIZE sizeof(SeedContext)
00562 #endif
00563 
00564 //Maximum block size (cipher algorithms)
00565 #if (CAMELLIA_SUPPORT == ENABLED)
00566    #define MAX_CIPHER_BLOCK_SIZE CAMELLIA_BLOCK_SIZE
00567 #elif (AES_SUPPORT == ENABLED)
00568    #define MAX_CIPHER_BLOCK_SIZE AES_BLOCK_SIZE
00569 #elif (ARIA_SUPPORT == ENABLED)
00570    #define MAX_CIPHER_BLOCK_SIZE ARIA_BLOCK_SIZE
00571 #elif (SEED_SUPPORT == ENABLED)
00572    #define MAX_CIPHER_BLOCK_SIZE SEED_BLOCK_SIZE
00573 #elif (RC6_SUPPORT == ENABLED)
00574    #define MAX_CIPHER_BLOCK_SIZE RC6_BLOCK_SIZE
00575 #elif (DES3_SUPPORT == ENABLED)
00576    #define MAX_CIPHER_BLOCK_SIZE DES3_BLOCK_SIZE
00577 #elif (DES_SUPPORT == ENABLED)
00578    #define MAX_CIPHER_BLOCK_SIZE DES_BLOCK_SIZE
00579 #elif (IDEA_SUPPORT == ENABLED)
00580    #define MAX_CIPHER_BLOCK_SIZE IDEA_BLOCK_SIZE
00581 #endif
00582 
00583 //Rotate left operation
00584 #define ROL8(a, n) (((a) << (n)) | ((a) >> (8 - (n))))
00585 #define ROL16(a, n) (((a) << (n)) | ((a) >> (16 - (n))))
00586 #define ROL32(a, n) (((a) << (n)) | ((a) >> (32 - (n))))
00587 #define ROL64(a, n) (((a) << (n)) | ((a) >> (64 - (n))))
00588 
00589 //Rotate right operation
00590 #define ROR8(a, n) (((a) >> (n)) | ((a) << (8 - (n))))
00591 #define ROR16(a, n) (((a) >> (n)) | ((a) << (16 - (n))))
00592 #define ROR32(a, n) (((a) >> (n)) | ((a) << (32 - (n))))
00593 #define ROR64(a, n) (((a) >> (n)) | ((a) << (64 - (n))))
00594 
00595 //Shift left operation
00596 #define SHL8(a, n) ((a) << (n))
00597 #define SHL16(a, n) ((a) << (n))
00598 #define SHL32(a, n) ((a) << (n))
00599 #define SHL64(a, n) ((a) << (n))
00600 
00601 //Shift right operation
00602 #define SHR8(a, n) ((a) >> (n))
00603 #define SHR16(a, n) ((a) >> (n))
00604 #define SHR32(a, n) ((a) >> (n))
00605 #define SHR64(a, n) ((a) >> (n))
00606 
00607 
00608 /**
00609  * @brief Encryption algorithm type
00610  **/
00611 
00612 typedef enum
00613 {
00614    CIPHER_ALGO_TYPE_STREAM = 0,
00615    CIPHER_ALGO_TYPE_BLOCK  = 1
00616 } CipherAlgoType;
00617 
00618 
00619 /**
00620  * @brief Cipher operation modes
00621  **/
00622 
00623 typedef enum
00624 {
00625    CIPHER_MODE_NULL              = 0,
00626    CIPHER_MODE_STREAM            = 1,
00627    CIPHER_MODE_ECB               = 2,
00628    CIPHER_MODE_CBC               = 3,
00629    CIPHER_MODE_CFB               = 4,
00630    CIPHER_MODE_OFB               = 5,
00631    CIPHER_MODE_CTR               = 6,
00632    CIPHER_MODE_CCM               = 7,
00633    CIPHER_MODE_GCM               = 8,
00634    CIPHER_MODE_CHACHA20_POLY1305 = 9,
00635 } CipherMode;
00636 
00637 
00638 //Common API for hash algorithms
00639 typedef error_t (*HashAlgoCompute)(const void *data, size_t length, uint8_t *digest);
00640 typedef void (*HashAlgoInit)(void *context);
00641 typedef void (*HashAlgoUpdate)(void *context, const void *data, size_t length);
00642 typedef void (*HashAlgoFinal)(void *context, uint8_t *digest);
00643 
00644 //Common API for encryption algorithms
00645 typedef error_t (*CipherAlgoInit)(void *context, const uint8_t *key, size_t keyLength);
00646 typedef void (*CipherAlgoEncryptStream)(void *context, const uint8_t *input, uint8_t *output, size_t length);
00647 typedef void (*CipherAlgoDecryptStream)(void *context, const uint8_t *input, uint8_t *output, size_t length);
00648 typedef void (*CipherAlgoEncryptBlock)(void *context, const uint8_t *input, uint8_t *output);
00649 typedef void (*CipherAlgoDecryptBlock)(void *context, const uint8_t *input, uint8_t *output);
00650 
00651 //Common API for pseudo-random number generators
00652 typedef error_t (*PrngAlgoInit)(void *context);
00653 typedef void (*PrngAlgoRelease)(void *context);
00654 typedef error_t (*PrngAlgoSeed)(void *context, const uint8_t *input, size_t length);
00655 typedef error_t (*PrngAlgoAddEntropy)(void *context, uint_t source, const uint8_t *input, size_t length, size_t entropy);
00656 typedef error_t (*PrngAlgoRead)(void *context, uint8_t *output, size_t length);
00657 
00658 
00659 /**
00660  * @brief Generic hash algorithm context
00661  **/
00662 
00663 typedef struct
00664 {
00665    uint8_t digest[1];
00666 } HashContext;
00667 
00668 
00669 /**
00670  * @brief Common interface for hash algorithms
00671  **/
00672 
00673 typedef struct
00674 {
00675    const char_t *name;
00676    const uint8_t *oid;
00677    size_t oidSize;
00678    size_t contextSize;
00679    size_t blockSize;
00680    size_t digestSize;
00681    HashAlgoCompute compute;
00682    HashAlgoInit init;
00683    HashAlgoUpdate update;
00684    HashAlgoFinal final;
00685 } HashAlgo;
00686 
00687 
00688 /**
00689  * @brief Common interface for encryption algorithms
00690  **/
00691 
00692 typedef struct
00693 {
00694    const char_t *name;
00695    size_t contextSize;
00696    CipherAlgoType type;
00697    size_t blockSize;
00698    CipherAlgoInit init;
00699    CipherAlgoEncryptStream encryptStream;
00700    CipherAlgoDecryptStream decryptStream;
00701    CipherAlgoEncryptBlock encryptBlock;
00702    CipherAlgoDecryptBlock decryptBlock;
00703 } CipherAlgo;
00704 
00705 
00706 /**
00707  * @brief Common interface for pseudo-random number generators
00708  **/
00709 
00710 typedef struct
00711 {
00712    const char_t *name;
00713    size_t contextSize;
00714    PrngAlgoInit init;
00715    PrngAlgoRelease release;
00716    PrngAlgoSeed seed;
00717    PrngAlgoAddEntropy addEntropy;
00718    PrngAlgoRead read;
00719 } PrngAlgo;
00720 
00721 #endif
00722