nettleif

An encryption/decryption-Application using the nettle library
git clone git://xatko.vsos.ethz.ch/nettleif.git
Log | Files | Refs

commit 42c072b20fbddf113f3d9f93439aacd171993030
parent d8ac7f4ec965c2f8b05dd1d3f5f5843fb72d8905
Author: Dominik Schmidt <dominik@schm1dt.ch>
Date:   Sun,  6 Jan 2019 19:02:31 +0100

Implement "blowfish" and "arcfour" with variable key length

Diffstat:
nettle.c | 55++++++++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 46 insertions(+), 9 deletions(-)

diff --git a/nettle.c b/nettle.c @@ -170,7 +170,29 @@ const struct nettle_cipher nettle_arcfour128={ .decrypt=&arcfour_crypt }; -const struct nettle_cipher *own_list[]={&nettle_tea, &nettle_blowfish128, &nettle_arcfour128, NULL}; +const struct nettle_cipher nettle_blowfish={ + .name="blowfish", + .context_size=sizeof(struct blowfish_ctx), + .block_size=BLOWFISH_BLOCK_SIZE, + .key_size=BLOWFISH_KEY_SIZE, + .set_encrypt_key=&blowfish128_set_key, + .set_decrypt_key=&blowfish128_set_key, + .encrypt=&blowfish_encrypt, + .decrypt=&blowfish_decrypt +}; + +const struct nettle_cipher nettle_arcfour={ + .name="arcfour", + .context_size=sizeof(struct arcfour_ctx), + .block_size=1, + .key_size=16, + .set_encrypt_key=&arcfour128_set_key, + .set_decrypt_key=&arcfour128_set_key, + .encrypt=&arcfour_crypt, + .decrypt=&arcfour_crypt +}; + +const struct nettle_cipher *own_list[]={&nettle_tea, &nettle_blowfish128, &nettle_arcfour128, &nettle_blowfish, &nettle_arcfour, NULL}; /* void ecb(void *ctx, nettle_cipher_func f, size_t blocklen, size_t len, uint8_t *dst, uint8_t *src){ @@ -413,14 +435,29 @@ int execute(struct EncStage *es){ void *ctx=malloc(ctx_s); memset(ctx, 0, ctx_s); - - switch(es->dir){ - case ENCRYPT: - es->cipher->set_encrypt_key(ctx, es->key.str); - break; - case DECRYPT: - es->cipher->set_decrypt_key(ctx, es->key.str); - break; + if(es->cipher->name=="arcfour"){ + if(es->key.len < ARCFOUR_MIN_KEY_SIZE || es->key.len > ARCFOUR_MAX_KEY_SIZE){ + fprintf(stderr, "Key length %ld not suited for arcfour", es->key.len); + return 1; + } + arcfour_set_key((struct arcfour_ctx *)ctx, es->key.len, es->key.str); + } + else if(es->cipher->name == "blowfish"){ + if(es->key.len < BLOWFISH_MIN_KEY_SIZE || es->key.len > BLOWFISH_MAX_KEY_SIZE){ + fprintf(stderr, "Key length %ld not suited for blowfish", es->key.len); + return 1; + } + blowfish_set_key((struct blowfish_ctx *)ctx, es->key.len, es->key.str); + } + else{ + switch(es->dir){ + case ENCRYPT: + es->cipher->set_encrypt_key(ctx, es->key.str); + break; + case DECRYPT: + es->cipher->set_decrypt_key(ctx, es->key.str); + break; + } } switch(es->mode){