123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406 |
- /**
- * \file cipher_wrap.c
- *
- * \brief Generic cipher wrapper for mbed TLS
- *
- * \author Adriaan de Jong <dejong@fox-it.com>
- *
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * 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.
- */
- #include "common.h"
- #if defined(MBEDTLS_CIPHER_C)
- #include "mbedtls/cipher_internal.h"
- #include "mbedtls/error.h"
- #if defined(MBEDTLS_CHACHAPOLY_C)
- #include "mbedtls/chachapoly.h"
- #endif
- #if defined(MBEDTLS_AES_C)
- #include "mbedtls/aes.h"
- #endif
- #if defined(MBEDTLS_ARC4_C)
- #include "mbedtls/arc4.h"
- #endif
- #if defined(MBEDTLS_CAMELLIA_C)
- #include "mbedtls/camellia.h"
- #endif
- #if defined(MBEDTLS_ARIA_C)
- #include "mbedtls/aria.h"
- #endif
- #if defined(MBEDTLS_DES_C)
- #include "mbedtls/des.h"
- #endif
- #if defined(MBEDTLS_BLOWFISH_C)
- #include "mbedtls/blowfish.h"
- #endif
- #if defined(MBEDTLS_CHACHA20_C)
- #include "mbedtls/chacha20.h"
- #endif
- #if defined(MBEDTLS_GCM_C)
- #include "mbedtls/gcm.h"
- #endif
- #if defined(MBEDTLS_CCM_C)
- #include "mbedtls/ccm.h"
- #endif
- #if defined(MBEDTLS_NIST_KW_C)
- #include "mbedtls/nist_kw.h"
- #endif
- #if defined(MBEDTLS_CIPHER_NULL_CIPHER)
- #include <string.h>
- #endif
- #if defined(MBEDTLS_PLATFORM_C)
- #include "mbedtls/platform.h"
- #else
- #include <stdlib.h>
- #define mbedtls_calloc calloc
- #define mbedtls_free free
- #endif
- #if defined(MBEDTLS_GCM_C)
- /* shared by all GCM ciphers */
- static void *gcm_ctx_alloc( void )
- {
- void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_gcm_context ) );
- if( ctx != NULL )
- mbedtls_gcm_init( (mbedtls_gcm_context *) ctx );
- return( ctx );
- }
- static void gcm_ctx_free( void *ctx )
- {
- mbedtls_gcm_free( ctx );
- mbedtls_free( ctx );
- }
- #endif /* MBEDTLS_GCM_C */
- #if defined(MBEDTLS_CCM_C)
- /* shared by all CCM ciphers */
- static void *ccm_ctx_alloc( void )
- {
- void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ccm_context ) );
- if( ctx != NULL )
- mbedtls_ccm_init( (mbedtls_ccm_context *) ctx );
- return( ctx );
- }
- static void ccm_ctx_free( void *ctx )
- {
- mbedtls_ccm_free( ctx );
- mbedtls_free( ctx );
- }
- #endif /* MBEDTLS_CCM_C */
- #if defined(MBEDTLS_AES_C)
- static int aes_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
- const unsigned char *input, unsigned char *output )
- {
- return mbedtls_aes_crypt_ecb( (mbedtls_aes_context *) ctx, operation, input, output );
- }
- #if defined(MBEDTLS_CIPHER_MODE_CBC)
- static int aes_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
- unsigned char *iv, const unsigned char *input, unsigned char *output )
- {
- return mbedtls_aes_crypt_cbc( (mbedtls_aes_context *) ctx, operation, length, iv, input,
- output );
- }
- #endif /* MBEDTLS_CIPHER_MODE_CBC */
- #if defined(MBEDTLS_CIPHER_MODE_CFB)
- static int aes_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
- size_t length, size_t *iv_off, unsigned char *iv,
- const unsigned char *input, unsigned char *output )
- {
- return mbedtls_aes_crypt_cfb128( (mbedtls_aes_context *) ctx, operation, length, iv_off, iv,
- input, output );
- }
- #endif /* MBEDTLS_CIPHER_MODE_CFB */
- #if defined(MBEDTLS_CIPHER_MODE_OFB)
- static int aes_crypt_ofb_wrap( void *ctx, size_t length, size_t *iv_off,
- unsigned char *iv, const unsigned char *input, unsigned char *output )
- {
- return mbedtls_aes_crypt_ofb( (mbedtls_aes_context *) ctx, length, iv_off,
- iv, input, output );
- }
- #endif /* MBEDTLS_CIPHER_MODE_OFB */
- #if defined(MBEDTLS_CIPHER_MODE_CTR)
- static int aes_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
- unsigned char *nonce_counter, unsigned char *stream_block,
- const unsigned char *input, unsigned char *output )
- {
- return mbedtls_aes_crypt_ctr( (mbedtls_aes_context *) ctx, length, nc_off, nonce_counter,
- stream_block, input, output );
- }
- #endif /* MBEDTLS_CIPHER_MODE_CTR */
- #if defined(MBEDTLS_CIPHER_MODE_XTS)
- static int aes_crypt_xts_wrap( void *ctx, mbedtls_operation_t operation,
- size_t length,
- const unsigned char data_unit[16],
- const unsigned char *input,
- unsigned char *output )
- {
- mbedtls_aes_xts_context *xts_ctx = ctx;
- int mode;
- switch( operation )
- {
- case MBEDTLS_ENCRYPT:
- mode = MBEDTLS_AES_ENCRYPT;
- break;
- case MBEDTLS_DECRYPT:
- mode = MBEDTLS_AES_DECRYPT;
- break;
- default:
- return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
- }
- return mbedtls_aes_crypt_xts( xts_ctx, mode, length,
- data_unit, input, output );
- }
- #endif /* MBEDTLS_CIPHER_MODE_XTS */
- static int aes_setkey_dec_wrap( void *ctx, const unsigned char *key,
- unsigned int key_bitlen )
- {
- return mbedtls_aes_setkey_dec( (mbedtls_aes_context *) ctx, key, key_bitlen );
- }
- static int aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
- unsigned int key_bitlen )
- {
- return mbedtls_aes_setkey_enc( (mbedtls_aes_context *) ctx, key, key_bitlen );
- }
- static void * aes_ctx_alloc( void )
- {
- mbedtls_aes_context *aes = mbedtls_calloc( 1, sizeof( mbedtls_aes_context ) );
- if( aes == NULL )
- return( NULL );
- mbedtls_aes_init( aes );
- return( aes );
- }
- static void aes_ctx_free( void *ctx )
- {
- mbedtls_aes_free( (mbedtls_aes_context *) ctx );
- mbedtls_free( ctx );
- }
- static const mbedtls_cipher_base_t aes_info = {
- MBEDTLS_CIPHER_ID_AES,
- aes_crypt_ecb_wrap,
- #if defined(MBEDTLS_CIPHER_MODE_CBC)
- aes_crypt_cbc_wrap,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CFB)
- aes_crypt_cfb128_wrap,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_OFB)
- aes_crypt_ofb_wrap,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CTR)
- aes_crypt_ctr_wrap,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_XTS)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_STREAM)
- NULL,
- #endif
- aes_setkey_enc_wrap,
- aes_setkey_dec_wrap,
- aes_ctx_alloc,
- aes_ctx_free
- };
- static const mbedtls_cipher_info_t aes_128_ecb_info = {
- MBEDTLS_CIPHER_AES_128_ECB,
- MBEDTLS_MODE_ECB,
- 128,
- "AES-128-ECB",
- 0,
- 0,
- 16,
- &aes_info
- };
- static const mbedtls_cipher_info_t aes_192_ecb_info = {
- MBEDTLS_CIPHER_AES_192_ECB,
- MBEDTLS_MODE_ECB,
- 192,
- "AES-192-ECB",
- 0,
- 0,
- 16,
- &aes_info
- };
- static const mbedtls_cipher_info_t aes_256_ecb_info = {
- MBEDTLS_CIPHER_AES_256_ECB,
- MBEDTLS_MODE_ECB,
- 256,
- "AES-256-ECB",
- 0,
- 0,
- 16,
- &aes_info
- };
- #if defined(MBEDTLS_CIPHER_MODE_CBC)
- static const mbedtls_cipher_info_t aes_128_cbc_info = {
- MBEDTLS_CIPHER_AES_128_CBC,
- MBEDTLS_MODE_CBC,
- 128,
- "AES-128-CBC",
- 16,
- 0,
- 16,
- &aes_info
- };
- static const mbedtls_cipher_info_t aes_192_cbc_info = {
- MBEDTLS_CIPHER_AES_192_CBC,
- MBEDTLS_MODE_CBC,
- 192,
- "AES-192-CBC",
- 16,
- 0,
- 16,
- &aes_info
- };
- static const mbedtls_cipher_info_t aes_256_cbc_info = {
- MBEDTLS_CIPHER_AES_256_CBC,
- MBEDTLS_MODE_CBC,
- 256,
- "AES-256-CBC",
- 16,
- 0,
- 16,
- &aes_info
- };
- #endif /* MBEDTLS_CIPHER_MODE_CBC */
- #if defined(MBEDTLS_CIPHER_MODE_CFB)
- static const mbedtls_cipher_info_t aes_128_cfb128_info = {
- MBEDTLS_CIPHER_AES_128_CFB128,
- MBEDTLS_MODE_CFB,
- 128,
- "AES-128-CFB128",
- 16,
- 0,
- 16,
- &aes_info
- };
- static const mbedtls_cipher_info_t aes_192_cfb128_info = {
- MBEDTLS_CIPHER_AES_192_CFB128,
- MBEDTLS_MODE_CFB,
- 192,
- "AES-192-CFB128",
- 16,
- 0,
- 16,
- &aes_info
- };
- static const mbedtls_cipher_info_t aes_256_cfb128_info = {
- MBEDTLS_CIPHER_AES_256_CFB128,
- MBEDTLS_MODE_CFB,
- 256,
- "AES-256-CFB128",
- 16,
- 0,
- 16,
- &aes_info
- };
- #endif /* MBEDTLS_CIPHER_MODE_CFB */
- #if defined(MBEDTLS_CIPHER_MODE_OFB)
- static const mbedtls_cipher_info_t aes_128_ofb_info = {
- MBEDTLS_CIPHER_AES_128_OFB,
- MBEDTLS_MODE_OFB,
- 128,
- "AES-128-OFB",
- 16,
- 0,
- 16,
- &aes_info
- };
- static const mbedtls_cipher_info_t aes_192_ofb_info = {
- MBEDTLS_CIPHER_AES_192_OFB,
- MBEDTLS_MODE_OFB,
- 192,
- "AES-192-OFB",
- 16,
- 0,
- 16,
- &aes_info
- };
- static const mbedtls_cipher_info_t aes_256_ofb_info = {
- MBEDTLS_CIPHER_AES_256_OFB,
- MBEDTLS_MODE_OFB,
- 256,
- "AES-256-OFB",
- 16,
- 0,
- 16,
- &aes_info
- };
- #endif /* MBEDTLS_CIPHER_MODE_OFB */
- #if defined(MBEDTLS_CIPHER_MODE_CTR)
- static const mbedtls_cipher_info_t aes_128_ctr_info = {
- MBEDTLS_CIPHER_AES_128_CTR,
- MBEDTLS_MODE_CTR,
- 128,
- "AES-128-CTR",
- 16,
- 0,
- 16,
- &aes_info
- };
- static const mbedtls_cipher_info_t aes_192_ctr_info = {
- MBEDTLS_CIPHER_AES_192_CTR,
- MBEDTLS_MODE_CTR,
- 192,
- "AES-192-CTR",
- 16,
- 0,
- 16,
- &aes_info
- };
- static const mbedtls_cipher_info_t aes_256_ctr_info = {
- MBEDTLS_CIPHER_AES_256_CTR,
- MBEDTLS_MODE_CTR,
- 256,
- "AES-256-CTR",
- 16,
- 0,
- 16,
- &aes_info
- };
- #endif /* MBEDTLS_CIPHER_MODE_CTR */
- #if defined(MBEDTLS_CIPHER_MODE_XTS)
- static int xts_aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
- unsigned int key_bitlen )
- {
- mbedtls_aes_xts_context *xts_ctx = ctx;
- return( mbedtls_aes_xts_setkey_enc( xts_ctx, key, key_bitlen ) );
- }
- static int xts_aes_setkey_dec_wrap( void *ctx, const unsigned char *key,
- unsigned int key_bitlen )
- {
- mbedtls_aes_xts_context *xts_ctx = ctx;
- return( mbedtls_aes_xts_setkey_dec( xts_ctx, key, key_bitlen ) );
- }
- static void *xts_aes_ctx_alloc( void )
- {
- mbedtls_aes_xts_context *xts_ctx = mbedtls_calloc( 1, sizeof( *xts_ctx ) );
- if( xts_ctx != NULL )
- mbedtls_aes_xts_init( xts_ctx );
- return( xts_ctx );
- }
- static void xts_aes_ctx_free( void *ctx )
- {
- mbedtls_aes_xts_context *xts_ctx = ctx;
- if( xts_ctx == NULL )
- return;
- mbedtls_aes_xts_free( xts_ctx );
- mbedtls_free( xts_ctx );
- }
- static const mbedtls_cipher_base_t xts_aes_info = {
- MBEDTLS_CIPHER_ID_AES,
- NULL,
- #if defined(MBEDTLS_CIPHER_MODE_CBC)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CFB)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_OFB)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CTR)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_XTS)
- aes_crypt_xts_wrap,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_STREAM)
- NULL,
- #endif
- xts_aes_setkey_enc_wrap,
- xts_aes_setkey_dec_wrap,
- xts_aes_ctx_alloc,
- xts_aes_ctx_free
- };
- static const mbedtls_cipher_info_t aes_128_xts_info = {
- MBEDTLS_CIPHER_AES_128_XTS,
- MBEDTLS_MODE_XTS,
- 256,
- "AES-128-XTS",
- 16,
- 0,
- 16,
- &xts_aes_info
- };
- static const mbedtls_cipher_info_t aes_256_xts_info = {
- MBEDTLS_CIPHER_AES_256_XTS,
- MBEDTLS_MODE_XTS,
- 512,
- "AES-256-XTS",
- 16,
- 0,
- 16,
- &xts_aes_info
- };
- #endif /* MBEDTLS_CIPHER_MODE_XTS */
- #if defined(MBEDTLS_GCM_C)
- static int gcm_aes_setkey_wrap( void *ctx, const unsigned char *key,
- unsigned int key_bitlen )
- {
- return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
- key, key_bitlen );
- }
- static const mbedtls_cipher_base_t gcm_aes_info = {
- MBEDTLS_CIPHER_ID_AES,
- NULL,
- #if defined(MBEDTLS_CIPHER_MODE_CBC)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CFB)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_OFB)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CTR)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_XTS)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_STREAM)
- NULL,
- #endif
- gcm_aes_setkey_wrap,
- gcm_aes_setkey_wrap,
- gcm_ctx_alloc,
- gcm_ctx_free,
- };
- static const mbedtls_cipher_info_t aes_128_gcm_info = {
- MBEDTLS_CIPHER_AES_128_GCM,
- MBEDTLS_MODE_GCM,
- 128,
- "AES-128-GCM",
- 12,
- MBEDTLS_CIPHER_VARIABLE_IV_LEN,
- 16,
- &gcm_aes_info
- };
- static const mbedtls_cipher_info_t aes_192_gcm_info = {
- MBEDTLS_CIPHER_AES_192_GCM,
- MBEDTLS_MODE_GCM,
- 192,
- "AES-192-GCM",
- 12,
- MBEDTLS_CIPHER_VARIABLE_IV_LEN,
- 16,
- &gcm_aes_info
- };
- static const mbedtls_cipher_info_t aes_256_gcm_info = {
- MBEDTLS_CIPHER_AES_256_GCM,
- MBEDTLS_MODE_GCM,
- 256,
- "AES-256-GCM",
- 12,
- MBEDTLS_CIPHER_VARIABLE_IV_LEN,
- 16,
- &gcm_aes_info
- };
- #endif /* MBEDTLS_GCM_C */
- #if defined(MBEDTLS_CCM_C)
- static int ccm_aes_setkey_wrap( void *ctx, const unsigned char *key,
- unsigned int key_bitlen )
- {
- return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
- key, key_bitlen );
- }
- static const mbedtls_cipher_base_t ccm_aes_info = {
- MBEDTLS_CIPHER_ID_AES,
- NULL,
- #if defined(MBEDTLS_CIPHER_MODE_CBC)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CFB)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_OFB)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CTR)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_XTS)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_STREAM)
- NULL,
- #endif
- ccm_aes_setkey_wrap,
- ccm_aes_setkey_wrap,
- ccm_ctx_alloc,
- ccm_ctx_free,
- };
- static const mbedtls_cipher_info_t aes_128_ccm_info = {
- MBEDTLS_CIPHER_AES_128_CCM,
- MBEDTLS_MODE_CCM,
- 128,
- "AES-128-CCM",
- 12,
- MBEDTLS_CIPHER_VARIABLE_IV_LEN,
- 16,
- &ccm_aes_info
- };
- static const mbedtls_cipher_info_t aes_192_ccm_info = {
- MBEDTLS_CIPHER_AES_192_CCM,
- MBEDTLS_MODE_CCM,
- 192,
- "AES-192-CCM",
- 12,
- MBEDTLS_CIPHER_VARIABLE_IV_LEN,
- 16,
- &ccm_aes_info
- };
- static const mbedtls_cipher_info_t aes_256_ccm_info = {
- MBEDTLS_CIPHER_AES_256_CCM,
- MBEDTLS_MODE_CCM,
- 256,
- "AES-256-CCM",
- 12,
- MBEDTLS_CIPHER_VARIABLE_IV_LEN,
- 16,
- &ccm_aes_info
- };
- #endif /* MBEDTLS_CCM_C */
- #endif /* MBEDTLS_AES_C */
- #if defined(MBEDTLS_CAMELLIA_C)
- static int camellia_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
- const unsigned char *input, unsigned char *output )
- {
- return mbedtls_camellia_crypt_ecb( (mbedtls_camellia_context *) ctx, operation, input,
- output );
- }
- #if defined(MBEDTLS_CIPHER_MODE_CBC)
- static int camellia_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
- size_t length, unsigned char *iv,
- const unsigned char *input, unsigned char *output )
- {
- return mbedtls_camellia_crypt_cbc( (mbedtls_camellia_context *) ctx, operation, length, iv,
- input, output );
- }
- #endif /* MBEDTLS_CIPHER_MODE_CBC */
- #if defined(MBEDTLS_CIPHER_MODE_CFB)
- static int camellia_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
- size_t length, size_t *iv_off, unsigned char *iv,
- const unsigned char *input, unsigned char *output )
- {
- return mbedtls_camellia_crypt_cfb128( (mbedtls_camellia_context *) ctx, operation, length,
- iv_off, iv, input, output );
- }
- #endif /* MBEDTLS_CIPHER_MODE_CFB */
- #if defined(MBEDTLS_CIPHER_MODE_CTR)
- static int camellia_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
- unsigned char *nonce_counter, unsigned char *stream_block,
- const unsigned char *input, unsigned char *output )
- {
- return mbedtls_camellia_crypt_ctr( (mbedtls_camellia_context *) ctx, length, nc_off,
- nonce_counter, stream_block, input, output );
- }
- #endif /* MBEDTLS_CIPHER_MODE_CTR */
- static int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key,
- unsigned int key_bitlen )
- {
- return mbedtls_camellia_setkey_dec( (mbedtls_camellia_context *) ctx, key, key_bitlen );
- }
- static int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key,
- unsigned int key_bitlen )
- {
- return mbedtls_camellia_setkey_enc( (mbedtls_camellia_context *) ctx, key, key_bitlen );
- }
- static void * camellia_ctx_alloc( void )
- {
- mbedtls_camellia_context *ctx;
- ctx = mbedtls_calloc( 1, sizeof( mbedtls_camellia_context ) );
- if( ctx == NULL )
- return( NULL );
- mbedtls_camellia_init( ctx );
- return( ctx );
- }
- static void camellia_ctx_free( void *ctx )
- {
- mbedtls_camellia_free( (mbedtls_camellia_context *) ctx );
- mbedtls_free( ctx );
- }
- static const mbedtls_cipher_base_t camellia_info = {
- MBEDTLS_CIPHER_ID_CAMELLIA,
- camellia_crypt_ecb_wrap,
- #if defined(MBEDTLS_CIPHER_MODE_CBC)
- camellia_crypt_cbc_wrap,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CFB)
- camellia_crypt_cfb128_wrap,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_OFB)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CTR)
- camellia_crypt_ctr_wrap,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_XTS)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_STREAM)
- NULL,
- #endif
- camellia_setkey_enc_wrap,
- camellia_setkey_dec_wrap,
- camellia_ctx_alloc,
- camellia_ctx_free
- };
- static const mbedtls_cipher_info_t camellia_128_ecb_info = {
- MBEDTLS_CIPHER_CAMELLIA_128_ECB,
- MBEDTLS_MODE_ECB,
- 128,
- "CAMELLIA-128-ECB",
- 0,
- 0,
- 16,
- &camellia_info
- };
- static const mbedtls_cipher_info_t camellia_192_ecb_info = {
- MBEDTLS_CIPHER_CAMELLIA_192_ECB,
- MBEDTLS_MODE_ECB,
- 192,
- "CAMELLIA-192-ECB",
- 0,
- 0,
- 16,
- &camellia_info
- };
- static const mbedtls_cipher_info_t camellia_256_ecb_info = {
- MBEDTLS_CIPHER_CAMELLIA_256_ECB,
- MBEDTLS_MODE_ECB,
- 256,
- "CAMELLIA-256-ECB",
- 0,
- 0,
- 16,
- &camellia_info
- };
- #if defined(MBEDTLS_CIPHER_MODE_CBC)
- static const mbedtls_cipher_info_t camellia_128_cbc_info = {
- MBEDTLS_CIPHER_CAMELLIA_128_CBC,
- MBEDTLS_MODE_CBC,
- 128,
- "CAMELLIA-128-CBC",
- 16,
- 0,
- 16,
- &camellia_info
- };
- static const mbedtls_cipher_info_t camellia_192_cbc_info = {
- MBEDTLS_CIPHER_CAMELLIA_192_CBC,
- MBEDTLS_MODE_CBC,
- 192,
- "CAMELLIA-192-CBC",
- 16,
- 0,
- 16,
- &camellia_info
- };
- static const mbedtls_cipher_info_t camellia_256_cbc_info = {
- MBEDTLS_CIPHER_CAMELLIA_256_CBC,
- MBEDTLS_MODE_CBC,
- 256,
- "CAMELLIA-256-CBC",
- 16,
- 0,
- 16,
- &camellia_info
- };
- #endif /* MBEDTLS_CIPHER_MODE_CBC */
- #if defined(MBEDTLS_CIPHER_MODE_CFB)
- static const mbedtls_cipher_info_t camellia_128_cfb128_info = {
- MBEDTLS_CIPHER_CAMELLIA_128_CFB128,
- MBEDTLS_MODE_CFB,
- 128,
- "CAMELLIA-128-CFB128",
- 16,
- 0,
- 16,
- &camellia_info
- };
- static const mbedtls_cipher_info_t camellia_192_cfb128_info = {
- MBEDTLS_CIPHER_CAMELLIA_192_CFB128,
- MBEDTLS_MODE_CFB,
- 192,
- "CAMELLIA-192-CFB128",
- 16,
- 0,
- 16,
- &camellia_info
- };
- static const mbedtls_cipher_info_t camellia_256_cfb128_info = {
- MBEDTLS_CIPHER_CAMELLIA_256_CFB128,
- MBEDTLS_MODE_CFB,
- 256,
- "CAMELLIA-256-CFB128",
- 16,
- 0,
- 16,
- &camellia_info
- };
- #endif /* MBEDTLS_CIPHER_MODE_CFB */
- #if defined(MBEDTLS_CIPHER_MODE_CTR)
- static const mbedtls_cipher_info_t camellia_128_ctr_info = {
- MBEDTLS_CIPHER_CAMELLIA_128_CTR,
- MBEDTLS_MODE_CTR,
- 128,
- "CAMELLIA-128-CTR",
- 16,
- 0,
- 16,
- &camellia_info
- };
- static const mbedtls_cipher_info_t camellia_192_ctr_info = {
- MBEDTLS_CIPHER_CAMELLIA_192_CTR,
- MBEDTLS_MODE_CTR,
- 192,
- "CAMELLIA-192-CTR",
- 16,
- 0,
- 16,
- &camellia_info
- };
- static const mbedtls_cipher_info_t camellia_256_ctr_info = {
- MBEDTLS_CIPHER_CAMELLIA_256_CTR,
- MBEDTLS_MODE_CTR,
- 256,
- "CAMELLIA-256-CTR",
- 16,
- 0,
- 16,
- &camellia_info
- };
- #endif /* MBEDTLS_CIPHER_MODE_CTR */
- #if defined(MBEDTLS_GCM_C)
- static int gcm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
- unsigned int key_bitlen )
- {
- return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
- key, key_bitlen );
- }
- static const mbedtls_cipher_base_t gcm_camellia_info = {
- MBEDTLS_CIPHER_ID_CAMELLIA,
- NULL,
- #if defined(MBEDTLS_CIPHER_MODE_CBC)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CFB)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_OFB)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CTR)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_XTS)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_STREAM)
- NULL,
- #endif
- gcm_camellia_setkey_wrap,
- gcm_camellia_setkey_wrap,
- gcm_ctx_alloc,
- gcm_ctx_free,
- };
- static const mbedtls_cipher_info_t camellia_128_gcm_info = {
- MBEDTLS_CIPHER_CAMELLIA_128_GCM,
- MBEDTLS_MODE_GCM,
- 128,
- "CAMELLIA-128-GCM",
- 12,
- MBEDTLS_CIPHER_VARIABLE_IV_LEN,
- 16,
- &gcm_camellia_info
- };
- static const mbedtls_cipher_info_t camellia_192_gcm_info = {
- MBEDTLS_CIPHER_CAMELLIA_192_GCM,
- MBEDTLS_MODE_GCM,
- 192,
- "CAMELLIA-192-GCM",
- 12,
- MBEDTLS_CIPHER_VARIABLE_IV_LEN,
- 16,
- &gcm_camellia_info
- };
- static const mbedtls_cipher_info_t camellia_256_gcm_info = {
- MBEDTLS_CIPHER_CAMELLIA_256_GCM,
- MBEDTLS_MODE_GCM,
- 256,
- "CAMELLIA-256-GCM",
- 12,
- MBEDTLS_CIPHER_VARIABLE_IV_LEN,
- 16,
- &gcm_camellia_info
- };
- #endif /* MBEDTLS_GCM_C */
- #if defined(MBEDTLS_CCM_C)
- static int ccm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
- unsigned int key_bitlen )
- {
- return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
- key, key_bitlen );
- }
- static const mbedtls_cipher_base_t ccm_camellia_info = {
- MBEDTLS_CIPHER_ID_CAMELLIA,
- NULL,
- #if defined(MBEDTLS_CIPHER_MODE_CBC)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CFB)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_OFB)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CTR)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_XTS)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_STREAM)
- NULL,
- #endif
- ccm_camellia_setkey_wrap,
- ccm_camellia_setkey_wrap,
- ccm_ctx_alloc,
- ccm_ctx_free,
- };
- static const mbedtls_cipher_info_t camellia_128_ccm_info = {
- MBEDTLS_CIPHER_CAMELLIA_128_CCM,
- MBEDTLS_MODE_CCM,
- 128,
- "CAMELLIA-128-CCM",
- 12,
- MBEDTLS_CIPHER_VARIABLE_IV_LEN,
- 16,
- &ccm_camellia_info
- };
- static const mbedtls_cipher_info_t camellia_192_ccm_info = {
- MBEDTLS_CIPHER_CAMELLIA_192_CCM,
- MBEDTLS_MODE_CCM,
- 192,
- "CAMELLIA-192-CCM",
- 12,
- MBEDTLS_CIPHER_VARIABLE_IV_LEN,
- 16,
- &ccm_camellia_info
- };
- static const mbedtls_cipher_info_t camellia_256_ccm_info = {
- MBEDTLS_CIPHER_CAMELLIA_256_CCM,
- MBEDTLS_MODE_CCM,
- 256,
- "CAMELLIA-256-CCM",
- 12,
- MBEDTLS_CIPHER_VARIABLE_IV_LEN,
- 16,
- &ccm_camellia_info
- };
- #endif /* MBEDTLS_CCM_C */
- #endif /* MBEDTLS_CAMELLIA_C */
- #if defined(MBEDTLS_ARIA_C)
- static int aria_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
- const unsigned char *input, unsigned char *output )
- {
- (void) operation;
- return mbedtls_aria_crypt_ecb( (mbedtls_aria_context *) ctx, input,
- output );
- }
- #if defined(MBEDTLS_CIPHER_MODE_CBC)
- static int aria_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
- size_t length, unsigned char *iv,
- const unsigned char *input, unsigned char *output )
- {
- return mbedtls_aria_crypt_cbc( (mbedtls_aria_context *) ctx, operation, length, iv,
- input, output );
- }
- #endif /* MBEDTLS_CIPHER_MODE_CBC */
- #if defined(MBEDTLS_CIPHER_MODE_CFB)
- static int aria_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
- size_t length, size_t *iv_off, unsigned char *iv,
- const unsigned char *input, unsigned char *output )
- {
- return mbedtls_aria_crypt_cfb128( (mbedtls_aria_context *) ctx, operation, length,
- iv_off, iv, input, output );
- }
- #endif /* MBEDTLS_CIPHER_MODE_CFB */
- #if defined(MBEDTLS_CIPHER_MODE_CTR)
- static int aria_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
- unsigned char *nonce_counter, unsigned char *stream_block,
- const unsigned char *input, unsigned char *output )
- {
- return mbedtls_aria_crypt_ctr( (mbedtls_aria_context *) ctx, length, nc_off,
- nonce_counter, stream_block, input, output );
- }
- #endif /* MBEDTLS_CIPHER_MODE_CTR */
- static int aria_setkey_dec_wrap( void *ctx, const unsigned char *key,
- unsigned int key_bitlen )
- {
- return mbedtls_aria_setkey_dec( (mbedtls_aria_context *) ctx, key, key_bitlen );
- }
- static int aria_setkey_enc_wrap( void *ctx, const unsigned char *key,
- unsigned int key_bitlen )
- {
- return mbedtls_aria_setkey_enc( (mbedtls_aria_context *) ctx, key, key_bitlen );
- }
- static void * aria_ctx_alloc( void )
- {
- mbedtls_aria_context *ctx;
- ctx = mbedtls_calloc( 1, sizeof( mbedtls_aria_context ) );
- if( ctx == NULL )
- return( NULL );
- mbedtls_aria_init( ctx );
- return( ctx );
- }
- static void aria_ctx_free( void *ctx )
- {
- mbedtls_aria_free( (mbedtls_aria_context *) ctx );
- mbedtls_free( ctx );
- }
- static const mbedtls_cipher_base_t aria_info = {
- MBEDTLS_CIPHER_ID_ARIA,
- aria_crypt_ecb_wrap,
- #if defined(MBEDTLS_CIPHER_MODE_CBC)
- aria_crypt_cbc_wrap,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CFB)
- aria_crypt_cfb128_wrap,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_OFB)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CTR)
- aria_crypt_ctr_wrap,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_XTS)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_STREAM)
- NULL,
- #endif
- aria_setkey_enc_wrap,
- aria_setkey_dec_wrap,
- aria_ctx_alloc,
- aria_ctx_free
- };
- static const mbedtls_cipher_info_t aria_128_ecb_info = {
- MBEDTLS_CIPHER_ARIA_128_ECB,
- MBEDTLS_MODE_ECB,
- 128,
- "ARIA-128-ECB",
- 0,
- 0,
- 16,
- &aria_info
- };
- static const mbedtls_cipher_info_t aria_192_ecb_info = {
- MBEDTLS_CIPHER_ARIA_192_ECB,
- MBEDTLS_MODE_ECB,
- 192,
- "ARIA-192-ECB",
- 0,
- 0,
- 16,
- &aria_info
- };
- static const mbedtls_cipher_info_t aria_256_ecb_info = {
- MBEDTLS_CIPHER_ARIA_256_ECB,
- MBEDTLS_MODE_ECB,
- 256,
- "ARIA-256-ECB",
- 0,
- 0,
- 16,
- &aria_info
- };
- #if defined(MBEDTLS_CIPHER_MODE_CBC)
- static const mbedtls_cipher_info_t aria_128_cbc_info = {
- MBEDTLS_CIPHER_ARIA_128_CBC,
- MBEDTLS_MODE_CBC,
- 128,
- "ARIA-128-CBC",
- 16,
- 0,
- 16,
- &aria_info
- };
- static const mbedtls_cipher_info_t aria_192_cbc_info = {
- MBEDTLS_CIPHER_ARIA_192_CBC,
- MBEDTLS_MODE_CBC,
- 192,
- "ARIA-192-CBC",
- 16,
- 0,
- 16,
- &aria_info
- };
- static const mbedtls_cipher_info_t aria_256_cbc_info = {
- MBEDTLS_CIPHER_ARIA_256_CBC,
- MBEDTLS_MODE_CBC,
- 256,
- "ARIA-256-CBC",
- 16,
- 0,
- 16,
- &aria_info
- };
- #endif /* MBEDTLS_CIPHER_MODE_CBC */
- #if defined(MBEDTLS_CIPHER_MODE_CFB)
- static const mbedtls_cipher_info_t aria_128_cfb128_info = {
- MBEDTLS_CIPHER_ARIA_128_CFB128,
- MBEDTLS_MODE_CFB,
- 128,
- "ARIA-128-CFB128",
- 16,
- 0,
- 16,
- &aria_info
- };
- static const mbedtls_cipher_info_t aria_192_cfb128_info = {
- MBEDTLS_CIPHER_ARIA_192_CFB128,
- MBEDTLS_MODE_CFB,
- 192,
- "ARIA-192-CFB128",
- 16,
- 0,
- 16,
- &aria_info
- };
- static const mbedtls_cipher_info_t aria_256_cfb128_info = {
- MBEDTLS_CIPHER_ARIA_256_CFB128,
- MBEDTLS_MODE_CFB,
- 256,
- "ARIA-256-CFB128",
- 16,
- 0,
- 16,
- &aria_info
- };
- #endif /* MBEDTLS_CIPHER_MODE_CFB */
- #if defined(MBEDTLS_CIPHER_MODE_CTR)
- static const mbedtls_cipher_info_t aria_128_ctr_info = {
- MBEDTLS_CIPHER_ARIA_128_CTR,
- MBEDTLS_MODE_CTR,
- 128,
- "ARIA-128-CTR",
- 16,
- 0,
- 16,
- &aria_info
- };
- static const mbedtls_cipher_info_t aria_192_ctr_info = {
- MBEDTLS_CIPHER_ARIA_192_CTR,
- MBEDTLS_MODE_CTR,
- 192,
- "ARIA-192-CTR",
- 16,
- 0,
- 16,
- &aria_info
- };
- static const mbedtls_cipher_info_t aria_256_ctr_info = {
- MBEDTLS_CIPHER_ARIA_256_CTR,
- MBEDTLS_MODE_CTR,
- 256,
- "ARIA-256-CTR",
- 16,
- 0,
- 16,
- &aria_info
- };
- #endif /* MBEDTLS_CIPHER_MODE_CTR */
- #if defined(MBEDTLS_GCM_C)
- static int gcm_aria_setkey_wrap( void *ctx, const unsigned char *key,
- unsigned int key_bitlen )
- {
- return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_ARIA,
- key, key_bitlen );
- }
- static const mbedtls_cipher_base_t gcm_aria_info = {
- MBEDTLS_CIPHER_ID_ARIA,
- NULL,
- #if defined(MBEDTLS_CIPHER_MODE_CBC)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CFB)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_OFB)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CTR)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_XTS)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_STREAM)
- NULL,
- #endif
- gcm_aria_setkey_wrap,
- gcm_aria_setkey_wrap,
- gcm_ctx_alloc,
- gcm_ctx_free,
- };
- static const mbedtls_cipher_info_t aria_128_gcm_info = {
- MBEDTLS_CIPHER_ARIA_128_GCM,
- MBEDTLS_MODE_GCM,
- 128,
- "ARIA-128-GCM",
- 12,
- MBEDTLS_CIPHER_VARIABLE_IV_LEN,
- 16,
- &gcm_aria_info
- };
- static const mbedtls_cipher_info_t aria_192_gcm_info = {
- MBEDTLS_CIPHER_ARIA_192_GCM,
- MBEDTLS_MODE_GCM,
- 192,
- "ARIA-192-GCM",
- 12,
- MBEDTLS_CIPHER_VARIABLE_IV_LEN,
- 16,
- &gcm_aria_info
- };
- static const mbedtls_cipher_info_t aria_256_gcm_info = {
- MBEDTLS_CIPHER_ARIA_256_GCM,
- MBEDTLS_MODE_GCM,
- 256,
- "ARIA-256-GCM",
- 12,
- MBEDTLS_CIPHER_VARIABLE_IV_LEN,
- 16,
- &gcm_aria_info
- };
- #endif /* MBEDTLS_GCM_C */
- #if defined(MBEDTLS_CCM_C)
- static int ccm_aria_setkey_wrap( void *ctx, const unsigned char *key,
- unsigned int key_bitlen )
- {
- return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_ARIA,
- key, key_bitlen );
- }
- static const mbedtls_cipher_base_t ccm_aria_info = {
- MBEDTLS_CIPHER_ID_ARIA,
- NULL,
- #if defined(MBEDTLS_CIPHER_MODE_CBC)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CFB)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_OFB)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CTR)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_XTS)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_STREAM)
- NULL,
- #endif
- ccm_aria_setkey_wrap,
- ccm_aria_setkey_wrap,
- ccm_ctx_alloc,
- ccm_ctx_free,
- };
- static const mbedtls_cipher_info_t aria_128_ccm_info = {
- MBEDTLS_CIPHER_ARIA_128_CCM,
- MBEDTLS_MODE_CCM,
- 128,
- "ARIA-128-CCM",
- 12,
- MBEDTLS_CIPHER_VARIABLE_IV_LEN,
- 16,
- &ccm_aria_info
- };
- static const mbedtls_cipher_info_t aria_192_ccm_info = {
- MBEDTLS_CIPHER_ARIA_192_CCM,
- MBEDTLS_MODE_CCM,
- 192,
- "ARIA-192-CCM",
- 12,
- MBEDTLS_CIPHER_VARIABLE_IV_LEN,
- 16,
- &ccm_aria_info
- };
- static const mbedtls_cipher_info_t aria_256_ccm_info = {
- MBEDTLS_CIPHER_ARIA_256_CCM,
- MBEDTLS_MODE_CCM,
- 256,
- "ARIA-256-CCM",
- 12,
- MBEDTLS_CIPHER_VARIABLE_IV_LEN,
- 16,
- &ccm_aria_info
- };
- #endif /* MBEDTLS_CCM_C */
- #endif /* MBEDTLS_ARIA_C */
- #if defined(MBEDTLS_DES_C)
- static int des_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
- const unsigned char *input, unsigned char *output )
- {
- ((void) operation);
- return mbedtls_des_crypt_ecb( (mbedtls_des_context *) ctx, input, output );
- }
- static int des3_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
- const unsigned char *input, unsigned char *output )
- {
- ((void) operation);
- return mbedtls_des3_crypt_ecb( (mbedtls_des3_context *) ctx, input, output );
- }
- #if defined(MBEDTLS_CIPHER_MODE_CBC)
- static int des_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
- unsigned char *iv, const unsigned char *input, unsigned char *output )
- {
- return mbedtls_des_crypt_cbc( (mbedtls_des_context *) ctx, operation, length, iv, input,
- output );
- }
- #endif /* MBEDTLS_CIPHER_MODE_CBC */
- #if defined(MBEDTLS_CIPHER_MODE_CBC)
- static int des3_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
- unsigned char *iv, const unsigned char *input, unsigned char *output )
- {
- return mbedtls_des3_crypt_cbc( (mbedtls_des3_context *) ctx, operation, length, iv, input,
- output );
- }
- #endif /* MBEDTLS_CIPHER_MODE_CBC */
- static int des_setkey_dec_wrap( void *ctx, const unsigned char *key,
- unsigned int key_bitlen )
- {
- ((void) key_bitlen);
- return mbedtls_des_setkey_dec( (mbedtls_des_context *) ctx, key );
- }
- static int des_setkey_enc_wrap( void *ctx, const unsigned char *key,
- unsigned int key_bitlen )
- {
- ((void) key_bitlen);
- return mbedtls_des_setkey_enc( (mbedtls_des_context *) ctx, key );
- }
- static int des3_set2key_dec_wrap( void *ctx, const unsigned char *key,
- unsigned int key_bitlen )
- {
- ((void) key_bitlen);
- return mbedtls_des3_set2key_dec( (mbedtls_des3_context *) ctx, key );
- }
- static int des3_set2key_enc_wrap( void *ctx, const unsigned char *key,
- unsigned int key_bitlen )
- {
- ((void) key_bitlen);
- return mbedtls_des3_set2key_enc( (mbedtls_des3_context *) ctx, key );
- }
- static int des3_set3key_dec_wrap( void *ctx, const unsigned char *key,
- unsigned int key_bitlen )
- {
- ((void) key_bitlen);
- return mbedtls_des3_set3key_dec( (mbedtls_des3_context *) ctx, key );
- }
- static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key,
- unsigned int key_bitlen )
- {
- ((void) key_bitlen);
- return mbedtls_des3_set3key_enc( (mbedtls_des3_context *) ctx, key );
- }
- static void * des_ctx_alloc( void )
- {
- mbedtls_des_context *des = mbedtls_calloc( 1, sizeof( mbedtls_des_context ) );
- if( des == NULL )
- return( NULL );
- mbedtls_des_init( des );
- return( des );
- }
- static void des_ctx_free( void *ctx )
- {
- mbedtls_des_free( (mbedtls_des_context *) ctx );
- mbedtls_free( ctx );
- }
- static void * des3_ctx_alloc( void )
- {
- mbedtls_des3_context *des3;
- des3 = mbedtls_calloc( 1, sizeof( mbedtls_des3_context ) );
- if( des3 == NULL )
- return( NULL );
- mbedtls_des3_init( des3 );
- return( des3 );
- }
- static void des3_ctx_free( void *ctx )
- {
- mbedtls_des3_free( (mbedtls_des3_context *) ctx );
- mbedtls_free( ctx );
- }
- static const mbedtls_cipher_base_t des_info = {
- MBEDTLS_CIPHER_ID_DES,
- des_crypt_ecb_wrap,
- #if defined(MBEDTLS_CIPHER_MODE_CBC)
- des_crypt_cbc_wrap,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CFB)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_OFB)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CTR)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_XTS)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_STREAM)
- NULL,
- #endif
- des_setkey_enc_wrap,
- des_setkey_dec_wrap,
- des_ctx_alloc,
- des_ctx_free
- };
- static const mbedtls_cipher_info_t des_ecb_info = {
- MBEDTLS_CIPHER_DES_ECB,
- MBEDTLS_MODE_ECB,
- MBEDTLS_KEY_LENGTH_DES,
- "DES-ECB",
- 0,
- 0,
- 8,
- &des_info
- };
- #if defined(MBEDTLS_CIPHER_MODE_CBC)
- static const mbedtls_cipher_info_t des_cbc_info = {
- MBEDTLS_CIPHER_DES_CBC,
- MBEDTLS_MODE_CBC,
- MBEDTLS_KEY_LENGTH_DES,
- "DES-CBC",
- 8,
- 0,
- 8,
- &des_info
- };
- #endif /* MBEDTLS_CIPHER_MODE_CBC */
- static const mbedtls_cipher_base_t des_ede_info = {
- MBEDTLS_CIPHER_ID_DES,
- des3_crypt_ecb_wrap,
- #if defined(MBEDTLS_CIPHER_MODE_CBC)
- des3_crypt_cbc_wrap,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CFB)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_OFB)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CTR)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_XTS)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_STREAM)
- NULL,
- #endif
- des3_set2key_enc_wrap,
- des3_set2key_dec_wrap,
- des3_ctx_alloc,
- des3_ctx_free
- };
- static const mbedtls_cipher_info_t des_ede_ecb_info = {
- MBEDTLS_CIPHER_DES_EDE_ECB,
- MBEDTLS_MODE_ECB,
- MBEDTLS_KEY_LENGTH_DES_EDE,
- "DES-EDE-ECB",
- 0,
- 0,
- 8,
- &des_ede_info
- };
- #if defined(MBEDTLS_CIPHER_MODE_CBC)
- static const mbedtls_cipher_info_t des_ede_cbc_info = {
- MBEDTLS_CIPHER_DES_EDE_CBC,
- MBEDTLS_MODE_CBC,
- MBEDTLS_KEY_LENGTH_DES_EDE,
- "DES-EDE-CBC",
- 8,
- 0,
- 8,
- &des_ede_info
- };
- #endif /* MBEDTLS_CIPHER_MODE_CBC */
- static const mbedtls_cipher_base_t des_ede3_info = {
- MBEDTLS_CIPHER_ID_3DES,
- des3_crypt_ecb_wrap,
- #if defined(MBEDTLS_CIPHER_MODE_CBC)
- des3_crypt_cbc_wrap,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CFB)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_OFB)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CTR)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_XTS)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_STREAM)
- NULL,
- #endif
- des3_set3key_enc_wrap,
- des3_set3key_dec_wrap,
- des3_ctx_alloc,
- des3_ctx_free
- };
- static const mbedtls_cipher_info_t des_ede3_ecb_info = {
- MBEDTLS_CIPHER_DES_EDE3_ECB,
- MBEDTLS_MODE_ECB,
- MBEDTLS_KEY_LENGTH_DES_EDE3,
- "DES-EDE3-ECB",
- 0,
- 0,
- 8,
- &des_ede3_info
- };
- #if defined(MBEDTLS_CIPHER_MODE_CBC)
- static const mbedtls_cipher_info_t des_ede3_cbc_info = {
- MBEDTLS_CIPHER_DES_EDE3_CBC,
- MBEDTLS_MODE_CBC,
- MBEDTLS_KEY_LENGTH_DES_EDE3,
- "DES-EDE3-CBC",
- 8,
- 0,
- 8,
- &des_ede3_info
- };
- #endif /* MBEDTLS_CIPHER_MODE_CBC */
- #endif /* MBEDTLS_DES_C */
- #if defined(MBEDTLS_BLOWFISH_C)
- static int blowfish_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
- const unsigned char *input, unsigned char *output )
- {
- return mbedtls_blowfish_crypt_ecb( (mbedtls_blowfish_context *) ctx, operation, input,
- output );
- }
- #if defined(MBEDTLS_CIPHER_MODE_CBC)
- static int blowfish_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
- size_t length, unsigned char *iv, const unsigned char *input,
- unsigned char *output )
- {
- return mbedtls_blowfish_crypt_cbc( (mbedtls_blowfish_context *) ctx, operation, length, iv,
- input, output );
- }
- #endif /* MBEDTLS_CIPHER_MODE_CBC */
- #if defined(MBEDTLS_CIPHER_MODE_CFB)
- static int blowfish_crypt_cfb64_wrap( void *ctx, mbedtls_operation_t operation,
- size_t length, size_t *iv_off, unsigned char *iv,
- const unsigned char *input, unsigned char *output )
- {
- return mbedtls_blowfish_crypt_cfb64( (mbedtls_blowfish_context *) ctx, operation, length,
- iv_off, iv, input, output );
- }
- #endif /* MBEDTLS_CIPHER_MODE_CFB */
- #if defined(MBEDTLS_CIPHER_MODE_CTR)
- static int blowfish_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
- unsigned char *nonce_counter, unsigned char *stream_block,
- const unsigned char *input, unsigned char *output )
- {
- return mbedtls_blowfish_crypt_ctr( (mbedtls_blowfish_context *) ctx, length, nc_off,
- nonce_counter, stream_block, input, output );
- }
- #endif /* MBEDTLS_CIPHER_MODE_CTR */
- static int blowfish_setkey_wrap( void *ctx, const unsigned char *key,
- unsigned int key_bitlen )
- {
- return mbedtls_blowfish_setkey( (mbedtls_blowfish_context *) ctx, key, key_bitlen );
- }
- static void * blowfish_ctx_alloc( void )
- {
- mbedtls_blowfish_context *ctx;
- ctx = mbedtls_calloc( 1, sizeof( mbedtls_blowfish_context ) );
- if( ctx == NULL )
- return( NULL );
- mbedtls_blowfish_init( ctx );
- return( ctx );
- }
- static void blowfish_ctx_free( void *ctx )
- {
- mbedtls_blowfish_free( (mbedtls_blowfish_context *) ctx );
- mbedtls_free( ctx );
- }
- static const mbedtls_cipher_base_t blowfish_info = {
- MBEDTLS_CIPHER_ID_BLOWFISH,
- blowfish_crypt_ecb_wrap,
- #if defined(MBEDTLS_CIPHER_MODE_CBC)
- blowfish_crypt_cbc_wrap,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CFB)
- blowfish_crypt_cfb64_wrap,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_OFB)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CTR)
- blowfish_crypt_ctr_wrap,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_XTS)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_STREAM)
- NULL,
- #endif
- blowfish_setkey_wrap,
- blowfish_setkey_wrap,
- blowfish_ctx_alloc,
- blowfish_ctx_free
- };
- static const mbedtls_cipher_info_t blowfish_ecb_info = {
- MBEDTLS_CIPHER_BLOWFISH_ECB,
- MBEDTLS_MODE_ECB,
- 128,
- "BLOWFISH-ECB",
- 0,
- MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
- 8,
- &blowfish_info
- };
- #if defined(MBEDTLS_CIPHER_MODE_CBC)
- static const mbedtls_cipher_info_t blowfish_cbc_info = {
- MBEDTLS_CIPHER_BLOWFISH_CBC,
- MBEDTLS_MODE_CBC,
- 128,
- "BLOWFISH-CBC",
- 8,
- MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
- 8,
- &blowfish_info
- };
- #endif /* MBEDTLS_CIPHER_MODE_CBC */
- #if defined(MBEDTLS_CIPHER_MODE_CFB)
- static const mbedtls_cipher_info_t blowfish_cfb64_info = {
- MBEDTLS_CIPHER_BLOWFISH_CFB64,
- MBEDTLS_MODE_CFB,
- 128,
- "BLOWFISH-CFB64",
- 8,
- MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
- 8,
- &blowfish_info
- };
- #endif /* MBEDTLS_CIPHER_MODE_CFB */
- #if defined(MBEDTLS_CIPHER_MODE_CTR)
- static const mbedtls_cipher_info_t blowfish_ctr_info = {
- MBEDTLS_CIPHER_BLOWFISH_CTR,
- MBEDTLS_MODE_CTR,
- 128,
- "BLOWFISH-CTR",
- 8,
- MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
- 8,
- &blowfish_info
- };
- #endif /* MBEDTLS_CIPHER_MODE_CTR */
- #endif /* MBEDTLS_BLOWFISH_C */
- #if defined(MBEDTLS_ARC4_C)
- static int arc4_crypt_stream_wrap( void *ctx, size_t length,
- const unsigned char *input,
- unsigned char *output )
- {
- return( mbedtls_arc4_crypt( (mbedtls_arc4_context *) ctx, length, input, output ) );
- }
- static int arc4_setkey_wrap( void *ctx, const unsigned char *key,
- unsigned int key_bitlen )
- {
- /* we get key_bitlen in bits, arc4 expects it in bytes */
- if( key_bitlen % 8 != 0 )
- return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
- mbedtls_arc4_setup( (mbedtls_arc4_context *) ctx, key, key_bitlen / 8 );
- return( 0 );
- }
- static void * arc4_ctx_alloc( void )
- {
- mbedtls_arc4_context *ctx;
- ctx = mbedtls_calloc( 1, sizeof( mbedtls_arc4_context ) );
- if( ctx == NULL )
- return( NULL );
- mbedtls_arc4_init( ctx );
- return( ctx );
- }
- static void arc4_ctx_free( void *ctx )
- {
- mbedtls_arc4_free( (mbedtls_arc4_context *) ctx );
- mbedtls_free( ctx );
- }
- static const mbedtls_cipher_base_t arc4_base_info = {
- MBEDTLS_CIPHER_ID_ARC4,
- NULL,
- #if defined(MBEDTLS_CIPHER_MODE_CBC)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CFB)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_OFB)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CTR)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_XTS)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_STREAM)
- arc4_crypt_stream_wrap,
- #endif
- arc4_setkey_wrap,
- arc4_setkey_wrap,
- arc4_ctx_alloc,
- arc4_ctx_free
- };
- static const mbedtls_cipher_info_t arc4_128_info = {
- MBEDTLS_CIPHER_ARC4_128,
- MBEDTLS_MODE_STREAM,
- 128,
- "ARC4-128",
- 0,
- 0,
- 1,
- &arc4_base_info
- };
- #endif /* MBEDTLS_ARC4_C */
- #if defined(MBEDTLS_CHACHA20_C)
- static int chacha20_setkey_wrap( void *ctx, const unsigned char *key,
- unsigned int key_bitlen )
- {
- if( key_bitlen != 256U )
- return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
- if ( 0 != mbedtls_chacha20_setkey( (mbedtls_chacha20_context*)ctx, key ) )
- return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
- return( 0 );
- }
- static int chacha20_stream_wrap( void *ctx, size_t length,
- const unsigned char *input,
- unsigned char *output )
- {
- int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
- ret = mbedtls_chacha20_update( ctx, length, input, output );
- if( ret == MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA )
- return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
- return( ret );
- }
- static void * chacha20_ctx_alloc( void )
- {
- mbedtls_chacha20_context *ctx;
- ctx = mbedtls_calloc( 1, sizeof( mbedtls_chacha20_context ) );
- if( ctx == NULL )
- return( NULL );
- mbedtls_chacha20_init( ctx );
- return( ctx );
- }
- static void chacha20_ctx_free( void *ctx )
- {
- mbedtls_chacha20_free( (mbedtls_chacha20_context *) ctx );
- mbedtls_free( ctx );
- }
- static const mbedtls_cipher_base_t chacha20_base_info = {
- MBEDTLS_CIPHER_ID_CHACHA20,
- NULL,
- #if defined(MBEDTLS_CIPHER_MODE_CBC)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CFB)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_OFB)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CTR)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_XTS)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_STREAM)
- chacha20_stream_wrap,
- #endif
- chacha20_setkey_wrap,
- chacha20_setkey_wrap,
- chacha20_ctx_alloc,
- chacha20_ctx_free
- };
- static const mbedtls_cipher_info_t chacha20_info = {
- MBEDTLS_CIPHER_CHACHA20,
- MBEDTLS_MODE_STREAM,
- 256,
- "CHACHA20",
- 12,
- 0,
- 1,
- &chacha20_base_info
- };
- #endif /* MBEDTLS_CHACHA20_C */
- #if defined(MBEDTLS_CHACHAPOLY_C)
- static int chachapoly_setkey_wrap( void *ctx,
- const unsigned char *key,
- unsigned int key_bitlen )
- {
- if( key_bitlen != 256U )
- return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
- if ( 0 != mbedtls_chachapoly_setkey( (mbedtls_chachapoly_context*)ctx, key ) )
- return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
- return( 0 );
- }
- static void * chachapoly_ctx_alloc( void )
- {
- mbedtls_chachapoly_context *ctx;
- ctx = mbedtls_calloc( 1, sizeof( mbedtls_chachapoly_context ) );
- if( ctx == NULL )
- return( NULL );
- mbedtls_chachapoly_init( ctx );
- return( ctx );
- }
- static void chachapoly_ctx_free( void *ctx )
- {
- mbedtls_chachapoly_free( (mbedtls_chachapoly_context *) ctx );
- mbedtls_free( ctx );
- }
- static const mbedtls_cipher_base_t chachapoly_base_info = {
- MBEDTLS_CIPHER_ID_CHACHA20,
- NULL,
- #if defined(MBEDTLS_CIPHER_MODE_CBC)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CFB)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_OFB)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CTR)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_XTS)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_STREAM)
- NULL,
- #endif
- chachapoly_setkey_wrap,
- chachapoly_setkey_wrap,
- chachapoly_ctx_alloc,
- chachapoly_ctx_free
- };
- static const mbedtls_cipher_info_t chachapoly_info = {
- MBEDTLS_CIPHER_CHACHA20_POLY1305,
- MBEDTLS_MODE_CHACHAPOLY,
- 256,
- "CHACHA20-POLY1305",
- 12,
- 0,
- 1,
- &chachapoly_base_info
- };
- #endif /* MBEDTLS_CHACHAPOLY_C */
- #if defined(MBEDTLS_CIPHER_NULL_CIPHER)
- static int null_crypt_stream( void *ctx, size_t length,
- const unsigned char *input,
- unsigned char *output )
- {
- ((void) ctx);
- memmove( output, input, length );
- return( 0 );
- }
- static int null_setkey( void *ctx, const unsigned char *key,
- unsigned int key_bitlen )
- {
- ((void) ctx);
- ((void) key);
- ((void) key_bitlen);
- return( 0 );
- }
- static void * null_ctx_alloc( void )
- {
- return( (void *) 1 );
- }
- static void null_ctx_free( void *ctx )
- {
- ((void) ctx);
- }
- static const mbedtls_cipher_base_t null_base_info = {
- MBEDTLS_CIPHER_ID_NULL,
- NULL,
- #if defined(MBEDTLS_CIPHER_MODE_CBC)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CFB)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_OFB)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CTR)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_XTS)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_STREAM)
- null_crypt_stream,
- #endif
- null_setkey,
- null_setkey,
- null_ctx_alloc,
- null_ctx_free
- };
- static const mbedtls_cipher_info_t null_cipher_info = {
- MBEDTLS_CIPHER_NULL,
- MBEDTLS_MODE_STREAM,
- 0,
- "NULL",
- 0,
- 0,
- 1,
- &null_base_info
- };
- #endif /* defined(MBEDTLS_CIPHER_NULL_CIPHER) */
- #if defined(MBEDTLS_NIST_KW_C)
- static void *kw_ctx_alloc( void )
- {
- void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_nist_kw_context ) );
- if( ctx != NULL )
- mbedtls_nist_kw_init( (mbedtls_nist_kw_context *) ctx );
- return( ctx );
- }
- static void kw_ctx_free( void *ctx )
- {
- mbedtls_nist_kw_free( ctx );
- mbedtls_free( ctx );
- }
- static int kw_aes_setkey_wrap( void *ctx, const unsigned char *key,
- unsigned int key_bitlen )
- {
- return mbedtls_nist_kw_setkey( (mbedtls_nist_kw_context *) ctx,
- MBEDTLS_CIPHER_ID_AES, key, key_bitlen, 1 );
- }
- static int kw_aes_setkey_unwrap( void *ctx, const unsigned char *key,
- unsigned int key_bitlen )
- {
- return mbedtls_nist_kw_setkey( (mbedtls_nist_kw_context *) ctx,
- MBEDTLS_CIPHER_ID_AES, key, key_bitlen, 0 );
- }
- static const mbedtls_cipher_base_t kw_aes_info = {
- MBEDTLS_CIPHER_ID_AES,
- NULL,
- #if defined(MBEDTLS_CIPHER_MODE_CBC)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CFB)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_OFB)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CTR)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_XTS)
- NULL,
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_STREAM)
- NULL,
- #endif
- kw_aes_setkey_wrap,
- kw_aes_setkey_unwrap,
- kw_ctx_alloc,
- kw_ctx_free,
- };
- static const mbedtls_cipher_info_t aes_128_nist_kw_info = {
- MBEDTLS_CIPHER_AES_128_KW,
- MBEDTLS_MODE_KW,
- 128,
- "AES-128-KW",
- 0,
- 0,
- 16,
- &kw_aes_info
- };
- static const mbedtls_cipher_info_t aes_192_nist_kw_info = {
- MBEDTLS_CIPHER_AES_192_KW,
- MBEDTLS_MODE_KW,
- 192,
- "AES-192-KW",
- 0,
- 0,
- 16,
- &kw_aes_info
- };
- static const mbedtls_cipher_info_t aes_256_nist_kw_info = {
- MBEDTLS_CIPHER_AES_256_KW,
- MBEDTLS_MODE_KW,
- 256,
- "AES-256-KW",
- 0,
- 0,
- 16,
- &kw_aes_info
- };
- static const mbedtls_cipher_info_t aes_128_nist_kwp_info = {
- MBEDTLS_CIPHER_AES_128_KWP,
- MBEDTLS_MODE_KWP,
- 128,
- "AES-128-KWP",
- 0,
- 0,
- 16,
- &kw_aes_info
- };
- static const mbedtls_cipher_info_t aes_192_nist_kwp_info = {
- MBEDTLS_CIPHER_AES_192_KWP,
- MBEDTLS_MODE_KWP,
- 192,
- "AES-192-KWP",
- 0,
- 0,
- 16,
- &kw_aes_info
- };
- static const mbedtls_cipher_info_t aes_256_nist_kwp_info = {
- MBEDTLS_CIPHER_AES_256_KWP,
- MBEDTLS_MODE_KWP,
- 256,
- "AES-256-KWP",
- 0,
- 0,
- 16,
- &kw_aes_info
- };
- #endif /* MBEDTLS_NIST_KW_C */
- const mbedtls_cipher_definition_t mbedtls_cipher_definitions[] =
- {
- #if defined(MBEDTLS_AES_C)
- { MBEDTLS_CIPHER_AES_128_ECB, &aes_128_ecb_info },
- { MBEDTLS_CIPHER_AES_192_ECB, &aes_192_ecb_info },
- { MBEDTLS_CIPHER_AES_256_ECB, &aes_256_ecb_info },
- #if defined(MBEDTLS_CIPHER_MODE_CBC)
- { MBEDTLS_CIPHER_AES_128_CBC, &aes_128_cbc_info },
- { MBEDTLS_CIPHER_AES_192_CBC, &aes_192_cbc_info },
- { MBEDTLS_CIPHER_AES_256_CBC, &aes_256_cbc_info },
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CFB)
- { MBEDTLS_CIPHER_AES_128_CFB128, &aes_128_cfb128_info },
- { MBEDTLS_CIPHER_AES_192_CFB128, &aes_192_cfb128_info },
- { MBEDTLS_CIPHER_AES_256_CFB128, &aes_256_cfb128_info },
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_OFB)
- { MBEDTLS_CIPHER_AES_128_OFB, &aes_128_ofb_info },
- { MBEDTLS_CIPHER_AES_192_OFB, &aes_192_ofb_info },
- { MBEDTLS_CIPHER_AES_256_OFB, &aes_256_ofb_info },
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CTR)
- { MBEDTLS_CIPHER_AES_128_CTR, &aes_128_ctr_info },
- { MBEDTLS_CIPHER_AES_192_CTR, &aes_192_ctr_info },
- { MBEDTLS_CIPHER_AES_256_CTR, &aes_256_ctr_info },
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_XTS)
- { MBEDTLS_CIPHER_AES_128_XTS, &aes_128_xts_info },
- { MBEDTLS_CIPHER_AES_256_XTS, &aes_256_xts_info },
- #endif
- #if defined(MBEDTLS_GCM_C)
- { MBEDTLS_CIPHER_AES_128_GCM, &aes_128_gcm_info },
- { MBEDTLS_CIPHER_AES_192_GCM, &aes_192_gcm_info },
- { MBEDTLS_CIPHER_AES_256_GCM, &aes_256_gcm_info },
- #endif
- #if defined(MBEDTLS_CCM_C)
- { MBEDTLS_CIPHER_AES_128_CCM, &aes_128_ccm_info },
- { MBEDTLS_CIPHER_AES_192_CCM, &aes_192_ccm_info },
- { MBEDTLS_CIPHER_AES_256_CCM, &aes_256_ccm_info },
- #endif
- #endif /* MBEDTLS_AES_C */
- #if defined(MBEDTLS_ARC4_C)
- { MBEDTLS_CIPHER_ARC4_128, &arc4_128_info },
- #endif
- #if defined(MBEDTLS_BLOWFISH_C)
- { MBEDTLS_CIPHER_BLOWFISH_ECB, &blowfish_ecb_info },
- #if defined(MBEDTLS_CIPHER_MODE_CBC)
- { MBEDTLS_CIPHER_BLOWFISH_CBC, &blowfish_cbc_info },
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CFB)
- { MBEDTLS_CIPHER_BLOWFISH_CFB64, &blowfish_cfb64_info },
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CTR)
- { MBEDTLS_CIPHER_BLOWFISH_CTR, &blowfish_ctr_info },
- #endif
- #endif /* MBEDTLS_BLOWFISH_C */
- #if defined(MBEDTLS_CAMELLIA_C)
- { MBEDTLS_CIPHER_CAMELLIA_128_ECB, &camellia_128_ecb_info },
- { MBEDTLS_CIPHER_CAMELLIA_192_ECB, &camellia_192_ecb_info },
- { MBEDTLS_CIPHER_CAMELLIA_256_ECB, &camellia_256_ecb_info },
- #if defined(MBEDTLS_CIPHER_MODE_CBC)
- { MBEDTLS_CIPHER_CAMELLIA_128_CBC, &camellia_128_cbc_info },
- { MBEDTLS_CIPHER_CAMELLIA_192_CBC, &camellia_192_cbc_info },
- { MBEDTLS_CIPHER_CAMELLIA_256_CBC, &camellia_256_cbc_info },
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CFB)
- { MBEDTLS_CIPHER_CAMELLIA_128_CFB128, &camellia_128_cfb128_info },
- { MBEDTLS_CIPHER_CAMELLIA_192_CFB128, &camellia_192_cfb128_info },
- { MBEDTLS_CIPHER_CAMELLIA_256_CFB128, &camellia_256_cfb128_info },
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CTR)
- { MBEDTLS_CIPHER_CAMELLIA_128_CTR, &camellia_128_ctr_info },
- { MBEDTLS_CIPHER_CAMELLIA_192_CTR, &camellia_192_ctr_info },
- { MBEDTLS_CIPHER_CAMELLIA_256_CTR, &camellia_256_ctr_info },
- #endif
- #if defined(MBEDTLS_GCM_C)
- { MBEDTLS_CIPHER_CAMELLIA_128_GCM, &camellia_128_gcm_info },
- { MBEDTLS_CIPHER_CAMELLIA_192_GCM, &camellia_192_gcm_info },
- { MBEDTLS_CIPHER_CAMELLIA_256_GCM, &camellia_256_gcm_info },
- #endif
- #if defined(MBEDTLS_CCM_C)
- { MBEDTLS_CIPHER_CAMELLIA_128_CCM, &camellia_128_ccm_info },
- { MBEDTLS_CIPHER_CAMELLIA_192_CCM, &camellia_192_ccm_info },
- { MBEDTLS_CIPHER_CAMELLIA_256_CCM, &camellia_256_ccm_info },
- #endif
- #endif /* MBEDTLS_CAMELLIA_C */
- #if defined(MBEDTLS_ARIA_C)
- { MBEDTLS_CIPHER_ARIA_128_ECB, &aria_128_ecb_info },
- { MBEDTLS_CIPHER_ARIA_192_ECB, &aria_192_ecb_info },
- { MBEDTLS_CIPHER_ARIA_256_ECB, &aria_256_ecb_info },
- #if defined(MBEDTLS_CIPHER_MODE_CBC)
- { MBEDTLS_CIPHER_ARIA_128_CBC, &aria_128_cbc_info },
- { MBEDTLS_CIPHER_ARIA_192_CBC, &aria_192_cbc_info },
- { MBEDTLS_CIPHER_ARIA_256_CBC, &aria_256_cbc_info },
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CFB)
- { MBEDTLS_CIPHER_ARIA_128_CFB128, &aria_128_cfb128_info },
- { MBEDTLS_CIPHER_ARIA_192_CFB128, &aria_192_cfb128_info },
- { MBEDTLS_CIPHER_ARIA_256_CFB128, &aria_256_cfb128_info },
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CTR)
- { MBEDTLS_CIPHER_ARIA_128_CTR, &aria_128_ctr_info },
- { MBEDTLS_CIPHER_ARIA_192_CTR, &aria_192_ctr_info },
- { MBEDTLS_CIPHER_ARIA_256_CTR, &aria_256_ctr_info },
- #endif
- #if defined(MBEDTLS_GCM_C)
- { MBEDTLS_CIPHER_ARIA_128_GCM, &aria_128_gcm_info },
- { MBEDTLS_CIPHER_ARIA_192_GCM, &aria_192_gcm_info },
- { MBEDTLS_CIPHER_ARIA_256_GCM, &aria_256_gcm_info },
- #endif
- #if defined(MBEDTLS_CCM_C)
- { MBEDTLS_CIPHER_ARIA_128_CCM, &aria_128_ccm_info },
- { MBEDTLS_CIPHER_ARIA_192_CCM, &aria_192_ccm_info },
- { MBEDTLS_CIPHER_ARIA_256_CCM, &aria_256_ccm_info },
- #endif
- #endif /* MBEDTLS_ARIA_C */
- #if defined(MBEDTLS_DES_C)
- { MBEDTLS_CIPHER_DES_ECB, &des_ecb_info },
- { MBEDTLS_CIPHER_DES_EDE_ECB, &des_ede_ecb_info },
- { MBEDTLS_CIPHER_DES_EDE3_ECB, &des_ede3_ecb_info },
- #if defined(MBEDTLS_CIPHER_MODE_CBC)
- { MBEDTLS_CIPHER_DES_CBC, &des_cbc_info },
- { MBEDTLS_CIPHER_DES_EDE_CBC, &des_ede_cbc_info },
- { MBEDTLS_CIPHER_DES_EDE3_CBC, &des_ede3_cbc_info },
- #endif
- #endif /* MBEDTLS_DES_C */
- #if defined(MBEDTLS_CHACHA20_C)
- { MBEDTLS_CIPHER_CHACHA20, &chacha20_info },
- #endif
- #if defined(MBEDTLS_CHACHAPOLY_C)
- { MBEDTLS_CIPHER_CHACHA20_POLY1305, &chachapoly_info },
- #endif
- #if defined(MBEDTLS_NIST_KW_C)
- { MBEDTLS_CIPHER_AES_128_KW, &aes_128_nist_kw_info },
- { MBEDTLS_CIPHER_AES_192_KW, &aes_192_nist_kw_info },
- { MBEDTLS_CIPHER_AES_256_KW, &aes_256_nist_kw_info },
- { MBEDTLS_CIPHER_AES_128_KWP, &aes_128_nist_kwp_info },
- { MBEDTLS_CIPHER_AES_192_KWP, &aes_192_nist_kwp_info },
- { MBEDTLS_CIPHER_AES_256_KWP, &aes_256_nist_kwp_info },
- #endif
- #if defined(MBEDTLS_CIPHER_NULL_CIPHER)
- { MBEDTLS_CIPHER_NULL, &null_cipher_info },
- #endif /* MBEDTLS_CIPHER_NULL_CIPHER */
- { MBEDTLS_CIPHER_NONE, NULL }
- };
- #define NUM_CIPHERS ( sizeof(mbedtls_cipher_definitions) / \
- sizeof(mbedtls_cipher_definitions[0]) )
- int mbedtls_cipher_supported[NUM_CIPHERS];
- #endif /* MBEDTLS_CIPHER_C */
|